CSS411 Cryptography

Digital Signatures

Slide deck 15. Signature model, requirements, ElGamal, DSA and DSS sign/verify formulas.

29 min read

Signature basicsSearch on YouTube

Why digital signaturesSearch on YouTube

Message authentication protects a message against changes and a false origin. But it does not address the lack of trust between the two parties. Digital signatures give the ability to:

  • Verify the author, the date and the time of the signature.
  • Authenticate the message contents.
  • Be verified by third parties to resolve disputes.

Thus a digital signature includes the authentication function, with additional capabilities.

Signature modelSearch on YouTube

The slides show two figures of the model. Bob signs a message MM, and Alice verifies it.

  • Generation: Bob puts MM and his private key into the digital signature generation algorithm. The output is Bob's signature SS for MM.
  • Transmission: Bob sends MM together with SS.
  • Verification: Alice puts MM, SS and Bob's public key into the verification algorithm. The algorithm returns "signature valid" or "not valid".

The second figure shows the inside of the two algorithms:

  1. Bob hashes MM to get hh, and encrypts hh with his private key. The result is SS.
  2. Alice hashes the received MM to get hh.
  3. Alice decrypts SS with Bob's public key to get h′h'.
  4. Alice compares hh and h′h'. If they are equal, the signature is valid.

A signature is like a wax seal with a unique pattern. Anyone can see and check the pattern. Only the owner of the stamp can make it.

RequirementsSearch on YouTube

  1. The signature must depend on the message that is signed.
  2. It must use information unique to the sender, to prevent both forgery and denial.
  3. It must be relatively easy to produce.
  4. It must be relatively easy to recognize and verify.
  5. It must be computationally infeasible to forge:
    • with a new message for an existing digital signature, or
    • with a fraudulent digital signature for a given message.
  6. It must be practical to save the digital signature in storage.

Requirements 1 and 2 work together. If a signature does not depend on the message, an attacker can copy it to a different message. If it does not use sender-unique information, anyone can make it.

Direct digital signaturesSearch on YouTube

Direct signatures involve only the sender and the receiver. We assume that the receiver has the sender's public key.

  • The sender makes the signature. The sender signs the entire message, or its hash, with the sender's private key.
  • The sender can encrypt the message and the signature with the receiver's public key.
  • Always sign first, then encrypt the message and the signature. The receiver decrypts first, then verifies the signature.
  • The security depends on the sender's private key.

If the sender's private key is lost or stolen, an attacker can sign in the sender's name. Also, the sender can claim that the key was stolen and deny a valid signature.

ElGamal signaturesSearch on YouTube

KeysSearch on YouTube

The ElGamal signature is a signature variant of ElGamal, related to Diffie-Hellman (D-H).

  • It uses exponentiation in a finite (Galois) field.
  • Its security is based on the difficulty of computing discrete logarithms, as in D-H.
  • The global elements are a prime number qq and aa, a primitive root of qq.
  • It uses the private key for encryption (signing) and the public key for decryption (verification).
PhaseComputationConditions
Global parametersPrime qq and aa, a primitive root of qqKnown to all users
Private key of user AxAx_A1<xA<q−11 < x_A < q-1
Public key of user AyA=axA mod qy_A = a^{x_A} \bmod qPublished

SigningSearch on YouTube

Alice signs a message MM to Bob:

  1. Compute the hash m=H(M)m = H(M), with 0≤m≤q−10 \le m \le q-1.
  2. Choose a random integer KK with 1≤K≤q−11 \le K \le q-1 and gcd⁡(K, q−1)=1\gcd(K,\, q-1) = 1.
  3. Compute the temporary key S1=aK mod qS_1 = a^{K} \bmod q.
  4. Compute K−1K^{-1}, the inverse of KK mod (q−1)(q-1).
  5. Compute S2=K−1(m−xAS1) mod (q−1)S_2 = K^{-1} \left( m - x_A S_1 \right) \bmod (q-1).
  6. The signature is the pair (S1,S2)(S_1, S_2).

S1S_1 uses only the random KK. S2S_2 mixes the hash, the private key and S1S_1. Use a new KK for each message. If two messages use the same KK, an observer can calculate xAx_A.

VerificationSearch on YouTube

Any user B can verify the signature with public values only:

V1=am mod qV_1 = a^{m} \bmod q

V2=yAS1⋅S1S2 mod qV_2 = y_A^{S_1} \cdot S_1^{S_2} \bmod q

The signature is valid if V1=V2V_1 = V_2.

Proof. With yA=axAy_A = a^{x_A} and S1=aKS_1 = a^{K}:

V2=yAS1⋅S1S2=axAS1⋅aKS2=axAS1+KS2V_2 = y_A^{S_1} \cdot S_1^{S_2} = a^{x_A S_1} \cdot a^{K S_2} = a^{x_A S_1 + K S_2}

Also xAS1+KS2=xAS1+KK−1(m−xAS1)=mx_A S_1 + K S_2 = x_A S_1 + K K^{-1}(m - x_A S_1) = m modulo (q−1)(q-1). Thus V2=am mod q=V1V_2 = a^{m} \bmod q = V_1.

Worked exampleSearch on YouTube

The slide example uses the field GF(19)GF(19): q=19q = 19 and a=10a = 10.

StepSlide valueFormula
Alice chooses private keyxA=16x_A = 161<xA<181 < x_A < 18
Alice computes public keyyA=1016 mod 19=4y_A = 10^{16} \bmod 19 = 4yA=axA mod qy_A = a^{x_A} \bmod q
Message hashm=14m = 14m=H(M)m = H(M)
Random keyK=5K = 5gcd⁡(18,5)=1\gcd(18, 5) = 1
Temporary keyS1=105 mod 19=3S_1 = 10^{5} \bmod 19 = 3S1=aK mod qS_1 = a^{K} \bmod q
Inverse of KK5−1 mod 18=115^{-1} \bmod 18 = 115⋅11=55≡1(mod18)5 \cdot 11 = 55 \equiv 1 \pmod{18}
Second partS2=11(14−16⋅3) mod 18=4S_2 = 11(14 - 16 \cdot 3) \bmod 18 = 4S2=K−1(m−xAS1) mod (q−1)S_2 = K^{-1}(m - x_A S_1) \bmod (q-1)
Signature(3,4)(3, 4)(S1,S2)(S_1, S_2)

Verification by any user B:

Verification partValue
V1=1014 mod 19V_1 = 10^{14} \bmod 191616
V2=43⋅34=5184 mod 19V_2 = 4^{3} \cdot 3^{4} = 5184 \bmod 191616
V1=V2=16V_1 = V_2 = 16The signature is valid

ElGamal signing order: Hash, pick K, S1_1, Invert KK, S2_2 (H-K-S-I-S). Verification compares ama^{m} with yAS1S1S2y_A^{S_1} S_1^{S_2}.

DSS and DSASearch on YouTube

The standardSearch on YouTube

  • The Digital Signature Standard (DSS) is a US government approved signature scheme.
  • NIST and NSA designed it in the early 1990s.
  • The slides say that it was published as FIPS 186 in 1991 and revised in 1993, 1996 and then 2000.
  • It uses the SHA hash algorithm.
  • DSS is the standard. DSA is the algorithm.
  • FIPS 186-2 (2000) includes alternative RSA and elliptic curve signature variants.
  • DSA is a public-key technique for digital signatures only, unlike RSA.

Do not use DSS and DSA as the same term. DSS is the standard document (FIPS 186). DSA is the signature algorithm in that standard.

DSA propertiesSearch on YouTube

  • DSA creates a 320-bit signature, in two 160-bit parts rr and ss.
  • It is smaller and faster than RSA.
  • It is a digital signature scheme only. It gives no encryption or key exchange.
  • Its security depends on the difficulty of computing discrete logarithms.
  • It is a variant of the ElGamal and Schnorr schemes.

DSS versus RSASearch on YouTube

(a) RSA approach(b) DSS approach
SigningHash MM, then encrypt the hash with PRaPR_a: E(PRa,H(M))\mathrm{E}(PR_a, H(M))Function Sig takes H(M)H(M), a random kk, the global public key PUGPU_G and PRaPR_a
SentMM and E(PRa,H(M))\mathrm{E}(PR_a, H(M))MM and the pair (s,r)(s, r)
VerifyingDecrypt the signature with PUaPU_a and compare it with a new H(M)H(M)Function Ver takes H(M)H(M), ss, rr, PUGPU_G and PUaPU_a. Its output is compared with rr

In the RSA approach, decryption gives back the hash. In the DSS approach, verification gives no hash. It gives a value that must equal rr.

DSA algorithmSearch on YouTube

Key generationSearch on YouTube

The shared global public key values are (p,q,g)(p, q, g). Each user also has a private key xx and a public key yy.

ValueHow to chooseConstraint
qqA prime number160-bit prime
ppA large prime2L−1<p<2L2^{L-1} < p < 2^{L}, with L=512L = 512 to 10241024 bits and LL a multiple of 6464
qq and ppqq is a 160-bit prime divisor of (p−1)(p-1)q∣(p−1)q \mid (p-1)
ggg=h(p−1)/q mod pg = h^{(p-1)/q} \bmod p1<h<p−11 < h < p-1 and h(p−1)/q mod p>1h^{(p-1)/q} \bmod p > 1
xxRandom private keyx<qx < q
yyy=gx mod py = g^{x} \bmod pPublic key

g=h(p−1)/q mod py=gx mod pg = h^{(p-1)/q} \bmod p \qquad y = g^{x} \bmod p

The value gg has order qq modulo pp. The condition h(p−1)/q mod p>1h^{(p-1)/q} \bmod p > 1 prevents g=1g = 1.

Signature creationSearch on YouTube

To sign a message MM, the sender:

  1. Generates a random signature key kk, with k<qk < q. The key kk must be random, must be destroyed after use and must never be reused.
  2. Computes the signature pair:

r=(gk mod p) mod qr = (g^{k} \bmod p) \bmod q

s=k−1(H(M)+x⋅r) mod qs = k^{-1}\left(H(M) + x \cdot r\right) \bmod q

  1. Sends the signature (r,s)(r, s) with the message MM.

Never reuse kk. Two signatures with the same kk have the same rr. From the two ss values, an attacker can calculate kk and then the private key xx. The same rule applies to KK in ElGamal.

Signature verificationSearch on YouTube

The recipient receives MM and the signature (r,s)(r, s). To verify the signature, the recipient computes:

w=s−1 mod qw = s^{-1} \bmod q

u1=H(M)⋅w mod qu_1 = H(M) \cdot w \bmod q

u2=r⋅w mod qu_2 = r \cdot w \bmod q

v=[(gu1⋅yu2) mod p] mod qv = \left[ \left( g^{u_1} \cdot y^{u_2} \right) \bmod p \right] \bmod q

If v=rv = r, the signature is verified. The slides refer to Appendix A for the proof.

Verification builds gkg^{k} again from public values. Because w=s−1w = s^{-1} and y=gxy = g^{x}:

gu1yu2=gw(H(M)+xr)=gs−1⋅ks=gk(modp)g^{u_1} y^{u_2} = g^{w(H(M) + x r)} = g^{s^{-1} \cdot k s} = g^{k} \pmod p

Then gk mod pg^{k} \bmod p, reduced mod qq, gives rr.

DSS overviewSearch on YouTube

The DSS overview figure shows signing with two functions and verifying with two functions. The received values are M′M', s′s' and r′r'.

s=f1(H(M), k, x, r, q)=(k−1(H(M)+x r)) mod qs = f_1\left(H(M),\, k,\, x,\, r,\, q\right) = \left(k^{-1}\left(H(M) + x \, r\right)\right) \bmod q

r=f2(k, p, q, g)=(gk mod p) mod qr = f_2\left(k,\, p,\, q,\, g\right) = \left( g^{k} \bmod p \right) \bmod q

w=f3(s′, q)=(s′)−1 mod qw = f_3\left(s',\, q\right) = (s')^{-1} \bmod q

v=f4(y, q, g, H(M′), w, r′)=((g H(M′) w mod q⋅y r′ w mod q) mod p) mod qv = f_4\left(y,\, q,\, g,\, H(M'),\, w,\, r'\right) = \left( \left( g^{\,H(M')\,w \bmod q} \cdot y^{\,r'\,w \bmod q} \right) \bmod p \right) \bmod q

FunctionSideInputs
f1f_1 (compute ss)SigningH(M)H(M), kk, private key xx, rr, qq
f2f_2 (compute rr)Signingkk and the public pp, qq, gg
f3f_3 (compute ww)Verifyings′s' and qq
f4f_4 (compute vv)VerifyingPublic key yy, qq, gg, H(M′)H(M'), ww, r′r'

Finally, the verifier compares vv with r′r'.

DSA verification order: w, u1u_1, u2u_2, v. Invert ss to get ww. Multiply ww by the hash and by rr. Do one combined exponentiation to get vv. Accept if v=rv = r.

Quick self-testSearch on YouTube

What three capabilities do digital signatures add to message authentication?

They verify the author, date and time of the signature. They authenticate the message contents. Third parties can verify them to resolve disputes.

List the six digital signature requirements from the slides.

Depend on the message. Use information unique to the sender, to prevent forgery and denial. Be relatively easy to produce. Be relatively easy to recognize and verify. Be computationally infeasible to forge, with a new message or with a fraudulent signature. Be practical to save in storage.

In a direct digital signature, in which order do you sign and encrypt?

Sign first, then encrypt the message and the signature with the receiver's public key. The receiver decrypts first, then verifies. The security depends on the sender's private key.

Describe the inside of the digital signature model.

Bob hashes MM to hh and encrypts hh with his private key to get SS. Alice hashes the received MM to get hh. She decrypts SS with Bob's public key to get h′h'. If h=h′h = h', the signature is valid.

Give the ElGamal signing and verification formulas.

Signing: m=H(M)m = H(M), choose KK with gcd⁡(K,q−1)=1\gcd(K, q-1) = 1, then S1=aK mod qS_1 = a^{K} \bmod q and S2=K−1(m−xAS1) mod (q−1)S_2 = K^{-1}(m - x_A S_1) \bmod (q-1). Verification: V1=am mod qV_1 = a^{m} \bmod q and V2=yAS1⋅S1S2 mod qV_2 = y_A^{S_1} \cdot S_1^{S_2} \bmod q. The signature is valid if V1=V2V_1 = V_2.

Do the slide example: GF(19), a=10a = 10, xA=16x_A = 16, m=14m = 14, K=5K = 5.

Key: yA=1016 mod 19=4y_A = 10^{16} \bmod 19 = 4. Signing: S1=105 mod 19=3S_1 = 10^{5} \bmod 19 = 3, 5−1 mod 18=115^{-1} \bmod 18 = 11, S2=11(14−16⋅3) mod 18=4S_2 = 11(14 - 16 \cdot 3) \bmod 18 = 4. The signature is (3,4)(3, 4). Verification: V1=1014 mod 19=16V_1 = 10^{14} \bmod 19 = 16 and V2=43⋅34=5184≡16V_2 = 4^{3} \cdot 3^{4} = 5184 \equiv 16. Thus the signature is valid.

DSS or DSA: which is the standard and which is the algorithm?

DSS is the standard, FIPS 186 (1991 on the slides), revised in 1993, 1996 and 2000. DSA is the algorithm. FIPS 186-2 (2000) also includes RSA and elliptic curve variants. DSS uses SHA.

Give the DSA global parameters and user keys, with the size constraints.

qq is a 160-bit prime divisor of p−1p-1. pp is a large prime with 2L−1<p<2L2^{L-1} < p < 2^{L}, where L=512L = 512 to 10241024 and LL is a multiple of 64. g=h(p−1)/q mod pg = h^{(p-1)/q} \bmod p, with 1<h<p−11 < h < p-1 and h(p−1)/q mod p>1h^{(p-1)/q} \bmod p > 1. The private key is x<qx < q and the public key is y=gx mod py = g^{x} \bmod p.

Give the DSA signing formulas and the rules for kk.

r=(gk mod p) mod qr = (g^{k} \bmod p) \bmod q and s=k−1(H(M)+xr) mod qs = k^{-1}(H(M) + x r) \bmod q. The key kk is random with k<qk < q. Destroy it after use and never reuse it. The signature (r,s)(r, s) has 320 bits.

Give the four DSA verification formulas and the final check.

w=s−1 mod qw = s^{-1} \bmod q, u1=H(M)w mod qu_1 = H(M) w \bmod q, u2=rw mod qu_2 = r w \bmod q and v=((gu1⋅yu2) mod p) mod qv = ((g^{u_1} \cdot y^{u_2}) \bmod p) \bmod q. The signature is verified if v=rv = r. In the DSS overview, these are f3f_3 and f4f_4.

  • Digital signatures verify the author, date, time and contents, and third parties can check them. The six requirements go from message dependence to practical storage.
  • In the model, the sender encrypts the hash with the private key. The receiver decrypts with the public key and compares with a new hash.
  • Direct signatures involve only the two parties. Sign first, then encrypt. The security depends on the sender's private key.
  • ElGamal: yA=axA mod qy_A = a^{x_A} \bmod q, S1=aK mod qS_1 = a^{K} \bmod q, S2=K−1(m−xAS1) mod (q−1)S_2 = K^{-1}(m - x_A S_1) \bmod (q-1). Compare ama^{m} with yAS1S1S2y_A^{S_1} S_1^{S_2}. In the slide example, the signature is (3,4)(3, 4) and both values are 1616.
  • DSS (FIPS 186, NIST and NSA) is the standard and DSA is the algorithm. DSA gives 320-bit signatures only, and its security depends on discrete logarithms.
  • DSA: r=(gk mod p) mod qr = (g^{k} \bmod p) \bmod q and s=k−1(H(M)+xr) mod qs = k^{-1}(H(M) + x r) \bmod q, with a new random kk. Verify through ww, u1u_1, u2u_2 and vv, and accept if v=rv = r.