Network Security and Cryptography
Total Page:16
File Type:pdf, Size:1020Kb
EE 418: Network Security and Cryptography Homework 5 Assigned: Wednesday, November 23, 2016, Due: Tuesday, December 6, 2016 Instructor: Tamara Bonaci Department of Electrical Engineering University of Washington, Seattle Problem 1 Consider the following modification of the Schnorr digital signature scheme. The keys are given by K = (q, ↵, a, β):β ↵a (mod p) where (q, ↵,β) comprise the public key and a is the private key. Given a message{ x, we compute⌘ the signature} of x to be γ = x ↵k (mod q) ⇥ δ = k + aγ (mod q) (1) where k is a randomly chosen number. In other words, we start with the standard Schnorr scheme and then use multiplication rather than a hash for γ. How is verification done using this revised scheme? Solution: To verify a signature generated using this Modified Schnorr Signature scheme, we exponentiate δ γ 1 ↵ , and check whether the obtained result is equal to β γ x− ,: · · δ γ 1 ↵ = β γ x− (2) · · Let’s analyze ↵δ, to show that the proposed verification scheme is indeed valid: δ k+↵ k aγ k a γ k γ 1 γ ↵ = ↵ = ↵ ↵ = ↵ (↵ ) = ↵ β = γ x− β (3) · · · · k 1 Expression ↵ = γ x− comes from equation (1), and is valid because q is a prime number. · Problem 2 Consider the following digital signature scheme. The public key is given by (q, ↵,β), where q is a prime number, ↵ is a primitive root of q, and β is an integer satisfying β<q. The private key is equal to a, for some positive integer a<qsatisfying β ↵a (mod q). To sign a message m, compute y = h(⌘m), the hash of the message. Assume that gcd(y, q 1) = 1 (if this is not the case, append a random string to m and recompute the hash. Repeat the process− until a message m is found satisfying gcd(y, q 1) = 1). Then calculate z such that yz a (mod (q 1)). The signature of the message is ↵z. To verify the− signature, a user verifies that β =(↵z)⌘y (mod q). − (a) Show that this scheme works. That is, show that the verification process produces an equality if the signature is valid. (b) Show that the scheme is unacceptable by describing a simple technique for forging a users signature on an arbitrary message. 1 Solution: (a) In order to show that the verification process in the proposed scheme produces an equality if the signature is valid, let’s analyze the expression (↵z)y: (↵z)y (mod q)=↵yz (mod q) a+λ(q 1) a λ(q 1) = ↵ − (mod q)=↵ ↵ − (mod q) (4) · a q 1 λ = ↵ ↵ − (mod q) a · = ↵ (modq)=β (5) Equation (4) comes from using the remainder theorem to express the fact that yz a (mod q 1) and equation (5) from using the Fermat’s Little theorem, which states that xφ(p) 1(mod⌘ p), where− p is a prime number. ⌘ (b) To show that the proposed signature scheme is not valid, we need to show that an attacker can forge a signature for some arbitrary messagem ˆ . After choosing a messagem ˆ , an attacker first computes the hash of such a messagey ˆ = h(ˆm). His 1 next step is to compute the multiplicative inverse of the obtained hashy ˆ− (mod q). Due to the fact 1 that q is a prime number, such an inverse will always exist. An attacker then outputs (m, ˆ βyˆ− ) as his message-signature pair. Obtained signature will pass the verification test, since: 1 yˆ 1 βyˆ− (mod q)=βyˆ− yˆ (mod q)=β (mod q) (6) ⇣ ⌘ Equation (6) proves that an attacker is able to forge a valid signature for an arbitrary message. Therefore, the proposed signature scheme is not valid. Problem 3 (Stinson 7.2) Suppose I implement the ElGamal Signature Scheme with p = 31847, ↵ = 5 and β = 26379. Write a computer program which does the following: (a) Verify the signature (20679, 11082) on the message x = 20543. (b) Determine my private key, a, by solving an instance of the Discrete Logarithm problem. (c) Then determine the random value k used in signing the message x, without solving an instance of the DiscreteLogarithm problem. 2 Solution: (a) A Matlab function that verifies the signature of some message x, signed using ElGamal Signature Scheme is called ElGamal signatureVerification, and its code is given below. Using the provided Matlab function, we verify the signature (γ,δ) = (20679, 11082) of the message x = 20543, signed with the ElGamal Signature Scheme with public keys given as p = 31847,↵ =5,β = 26379. We obtain ↵x = 20688, βγ = 12575, γδ = 21455 and finally βγ γδ = 20688. Therefore we conclude that a given signature is valid for the message x. · (b) Matlab function that computes a private key a, given a public key (p, ↵,β) is called shanks, and its code is given below. The provided function solves an instance of the discrete logarithm problem a = log↵ = β using the Shanks algorithm. For the public key (p = 31847,↵=5,β = 26379), we obtain a = 7973. (c) Function that finds a random number k, 1 k p 1, used in generating an ElGamal signa- ture of a message m without solving an instance of a− discrete logarithm problem is called ElGa- mal findRandom, and its code given below as well. Using the provided function on message x = 20543, whose signature is given as (γ,δ) = (20679, 11082), with parameters of the ElGamal Signature Scheme p = 31847, ↵ = 5, β = 26379 and private key a = 7973, we obtain k = 19387. 1 function [verified] = ElGamal signatureVerification(p, alpha , beta ,message, gamma ,delta) %ElGamal signatureVerification verifies the signature of the message , %signed using ElGamal Signature −Scheme %INPUTS : 6 %1. (p , alpha , beta) public key in the ElGama public key scheme %2. message − %3. (gamma , delta) signature of the message %OUTPUTS : − %1. verified returns ’ verified ’ if the signature is valid , ’ invalid − 11 %signature ’ otherwise verified = ’ Invalid signature ’ ; %%Verification 16 alpha x=squareand multiply(alpha , message , p) ; beta gamma = square and multiply(beta , gamma ,p); gamma delta = square and multiply(gamma ,delta,p); ver aux = mod(beta gamma gamma delta , p) ; ⇤ 21 if(ver aux == alpha x) verified = ’ Verified ’ ; end 1 function [a] = shanks(alpha, beta ,n) %Shanks solves a discrete logarithm a = log alpha( beta) (mod n ) problem %using shanks− algorithm . %INPUTS : %1. alpha basis − 6 %2. beta exponent %3. n = phi− ( p ) = (p 1) , where p is a prime number %OUTPUT : − %1. a solution of the discrete logarithm problem − 11 %%Initialization a=0; m= ceil( sqrt(n)) ; 16 %Auxiliary calculation : alphaˆm (mod n ) x=squareand multiply(alpha , (m), (n + 1)) ; 3 %First list for j=1:m 21 L1 unsorted(j , :) = [ j , square and multiply(x, j 1, (n + 1) ) ] ; end − L1 = sortrows ( L1 unsorted , 2) ; 26 for j=1:m L2 aux = square and multiply(alpha , j 1, (n + 1)) ; [r, inverse , t] = extendedEuclidean(L2− aux , (n + 1) ) ; L2 unsorted(j , :) = [ j , square and multiply(beta inverse , 1, (n + 1)) ]; end ⇤ 31 L2 = sortrows ( L2 unsorted , 2) ; %%Finding the pair with identical second coordinate for j=1:m 36 for i=1:m if(L1(j , 2) == L2(i , 2)) a=mod((m(L1(j , 1) 1) + (L2( i , 1) 1)) , n) ; break ; ⇤ − − end 41 end end function [k] = ElGamal findRandomK(p , alpha , beta ,a,message,gamma ,delta) %ElGamal findRandomK given private key , function finds random parameter k , used in signing − 3 %message x using ElGamal Signature Scheme without solving an instance of %Discrete Logarithm problem %INPTUS : %1. (p , alpha , beta) public key %2. a private key − − 8 %3. message signed message %4. (gamma , −delta) signature of message %OUTPUT : − %1. k random parameter k − 13 % m = a gamma k delta (mod (p 1)) > k = (m a gamma) deltaˆ( 1)(mod (p 1)⇤) − ⇤ − −− − ⇤ ⇤ − − k=0; aux = mod(( message a gamma), (p 1)) ; − ⇤ − 18 % Check gcd ( delta , (p 1)) if ( gcd(delta , (p 1)) ==− 1) [r, inverse delta− , t] = extendedEuclidean(delta , (p 1)) ; k=mod((aux inverse delta) , (p 1)) − ⇤ − 23 else d=gcd(delta , (p 1)) ; delta prime = delta/d;− p prime = (p 1)/d ; m prime = aux/d;− 28 [r, inverse , t] = extendedEuclidean(delta prime , p prime) ; k prime = mod((m prime inverse) , p prime) ; ⇤ for i=1:d 33 k=kprime + i p prime ; beta aux = square⇤ and multiply(alpha , k, p) if(beta aux == gamma) break ; end 38 end 4 end Problem 4 (Stinson, Problem 7.3) Suppose that Alice is using the ElGamal Signature Scheme. In order to save time in generating the random numbers k that are used in signing messages, Alice chooses an initial random value k0 and then signs the i-th message using the value ki = k0 +2i (mod (p 1)) (therefore ki = ki 1 +2 (mod(p 1)) for all i 1). − − − ≥ (a) Suppose that Bob observes two consecutive signed messages, say (xi, sig(xi,ki)) and xi+1,sig(xi+1,ki+1). Describe how Bob can easily compute Alice’s secret key, a, given this information, without solving an instance of the Discrete Logarithm problem. (Note that the value of i does not have to be known for the attack to succeed.) (b) Suppose that the parameters of the scheme are p = 28703, ↵ = 5 and β = 11339 and two messages observed by Bob are: xi = 12000, sig(xi,ki) = (26530, 19862) xi+1 = 24567, sig(xi+1,ki+1) = (3081, 7604) Find the value of a using the attack described in part (a). 5 Solution: (a) (a) To show how Bob can easily compute Alice’s private key a, let’s recall the ElGamal Signature Scheme: γ = ↵k (mod p) 1 δ =(m aγ)k− (mod (p 1)) (7) − − Since k = k +2 (mod(p 1)), using the remainder theorem, we can write: 2 1 − k = k +2+λ(p 1) (8) 2 1 − After receiving two consecutive pairs message-signature from Alice, Bob can therefore write: k1 γ1 = ↵ (mod p) 1 δ =(m aγ )k− (mod (p 1)) (9) 1 1 − 1 1 − λ k k +2+λ(p 1) 2 k (p 1) 2 k γ = ↵ 2 (mod p)=↵ 1 − (mod p)=↵ ↵ 1 ↵ − (mod p)=↵ ↵ 1 (mod p) 2 · · · 1 δ =(m aγ )k− (mod (p 1)) ⇣ ⌘ (10) 2 2 − 2 2 − From equation (9), after multiplication with k , it follows that aγ = m δ k .