Short answer: DSA signs a hash with an exponent in a prime-order subgroup. The public parameters are a prime p, a prime q dividing p - 1, and a base g of order q. The private key x is in 1 through q - 1, and the public key is g^x mod p. A signature is r = (g^k mod p) mod q and s = k^(-1) (h + x r) mod q. Verification recomputes r. The fragment uses p = 23, q = 11, g = 4, x = 7, h = 6, and k = 2, and the signature is 5 4.
What the problem actually asks
A signature has to be checkable from public values and hard to forge from those values. DSA puts the secret in an exponent of a subgroup so the signature is two residues modulo q. The integer h stands in for a hash reduced modulo q. The group modulo 23 is small enough to read and far too small to deploy. A fresh k is part of the signature. Reusing k links two signatures. The fragment fixes k so the arithmetic can be checked.
What the algorithm guarantees
For these parameters, g has order 11 modulo 23, r and s are nonzero, and the verification equation returns the same r. The check is v = (g^(h w) y^(r w) mod p) mod q, with w the inverse of s modulo q. The equality v = r is the acceptance test. It is not a proof that a 23-element group hides x.
The working steps
- Publish
p,q,g, andy = g^x mod p. - Reduce the hash modulo
qto obtainh, and drawkin1throughq - 1. - Set
r = (g^k mod p) mod qands = k^(-1) (h + x r) mod q. If either is zero, draw anotherk. - Verify by computing
w = s^(-1) mod qand checking that(g^(h w) y^(r w) mod p) mod qequalsr.
Approaches that look simpler and fail
| Approach | Why it fails in a group this small, or with a repeated nonce |
|---|---|
Deploy p = 23 |
The subgroup has eleven elements. A deployment uses a large prime q. |
Reuse k for a second hash |
The ephemeral exponent is part of the secret. A repeated k links the signatures. |
Reduce g^k modulo q before reducing modulo p |
The order of operations is modulo p first, then modulo q. |
Accept a signature with r = 0 or s = 0 |
Either zero value is rejected and the signer draws a new k. |
ECDSA is this signature shape on an elliptic curve. DSA is the multiplicative-subgroup form.
A working example
This Python fragment signs the integer 6 in a subgroup of the multiplicative group modulo 23 and checks the signature. It prints 5 4.
p, q, g = 23, 11, 4
x = 7
y = pow(g, x, p)
h, k = 6, 2
r = pow(g, k, p) % q
s = (pow(k, -1, q) * (h + x * r)) % q
w = pow(s, -1, q)
u1, u2 = (h * w) % q, (r * w) % q
v = (pow(g, u1, p) * pow(y, u2, p) % p) % q
assert v == r and r != 0 and s != 0
print(r, s)
Where it is used
DSA is the FIPS signature that older SSH ssh-dss host keys used. OpenSSH disabled those keys by default. New signatures are ECDSA, Ed25519, or RSA.
When you can drop this algorithm
Drop the modulo-23 parameters for any signature. Keep the two-residue check where q is large, each signature draws a fresh k, and h is a collision-resistant hash reduced modulo q.
Why this stays published
We publish this so a search for DSA returns the subgroup signature and the verification that recomputes r. DSA publishes g^x, signs with a fresh exponent k as the pair (r, s) modulo q, and checks the signature by recomputing r.
本文由 HoHo 與 AI 協作整理,最後更新於 2026 年 11 月 13 日。
