{"id":490,"date":"2026-11-13T13:39:29","date_gmt":"2026-11-13T05:39:29","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-dsa-signs-a-hash-in-a-prime-order-subgroup\/"},"modified":"2026-11-13T21:58:54","modified_gmt":"2026-11-13T13:58:54","slug":"how-dsa-signs-a-hash-in-a-prime-order-subgroup","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-dsa-signs-a-hash-in-a-prime-order-subgroup\/","title":{"rendered":"How DSA signs a hash in a prime-order subgroup"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>DSA<\/strong> signs a hash with an exponent in a prime-order subgroup. The public parameters are a prime <code>p<\/code>, a prime <code>q<\/code> dividing <code>p - 1<\/code>, and a base <code>g<\/code> of order <code>q<\/code>. The private key <code>x<\/code> is in <code>1<\/code> through <code>q - 1<\/code>, and the public key is <code>g^x mod p<\/code>. A signature is <code>r = (g^k mod p) mod q<\/code> and <code>s = k^(-1) (h + x r) mod q<\/code>. Verification recomputes <code>r<\/code>. The fragment uses <code>p = 23<\/code>, <code>q = 11<\/code>, <code>g = 4<\/code>, <code>x = 7<\/code>, <code>h = 6<\/code>, and <code>k = 2<\/code>, and the signature is <code>5 4<\/code>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the problem actually asks<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">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 <code>q<\/code>. The integer <code>h<\/code> stands in for a hash reduced modulo <code>q<\/code>. The group modulo 23 is small enough to read and far too small to deploy. A fresh <code>k<\/code> is part of the signature. Reusing <code>k<\/code> links two signatures. The fragment fixes <code>k<\/code> so the arithmetic can be checked.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>What the algorithm guarantees<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">For these parameters, <code>g<\/code> has order 11 modulo 23, <code>r<\/code> and <code>s<\/code> are nonzero, and the verification equation returns the same <code>r<\/code>. The check is <code>v = (g^(h w) y^(r w) mod p) mod q<\/code>, with <code>w<\/code> the inverse of <code>s<\/code> modulo <code>q<\/code>. The equality <code>v = r<\/code> is the acceptance test. It is not a proof that a 23-element group hides <code>x<\/code>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>The working steps<\/strong><\/h4>\n\n<ol class=\"wp-block-list\">\n<li>Publish <code>p<\/code>, <code>q<\/code>, <code>g<\/code>, and <code>y = g^x mod p<\/code>.<\/li>\n<li>Reduce the hash modulo <code>q<\/code> to obtain <code>h<\/code>, and draw <code>k<\/code> in <code>1<\/code> through <code>q - 1<\/code>.<\/li>\n<li>Set <code>r = (g^k mod p) mod q<\/code> and <code>s = k^(-1) (h + x r) mod q<\/code>. If either is zero, draw another <code>k<\/code>.<\/li>\n<li>Verify by computing <code>w = s^(-1) mod q<\/code> and checking that <code>(g^(h w) y^(r w) mod p) mod q<\/code> equals <code>r<\/code>.<\/li>\n<\/ol>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Approaches that look simpler and fail<\/strong><\/h4>\n\n<figure class=\"wp-block-table\">\n<table>\n<thead>\n<tr>\n<th>Approach<\/th>\n<th>Why it fails in a group this small, or with a repeated nonce<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Deploy <code>p = 23<\/code><\/td>\n<td>The subgroup has eleven elements. A deployment uses a large prime <code>q<\/code>.<\/td>\n<\/tr>\n<tr>\n<td>Reuse <code>k<\/code> for a second hash<\/td>\n<td>The ephemeral exponent is part of the secret. A repeated <code>k<\/code> links the signatures.<\/td>\n<\/tr>\n<tr>\n<td>Reduce <code>g^k<\/code> modulo <code>q<\/code> before reducing modulo <code>p<\/code><\/td>\n<td>The order of operations is modulo <code>p<\/code> first, then modulo <code>q<\/code>.<\/td>\n<\/tr>\n<tr>\n<td>Accept a signature with <code>r = 0<\/code> or <code>s = 0<\/code><\/td>\n<td>Either zero value is rejected and the signer draws a new <code>k<\/code>.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">ECDSA is this signature shape on an elliptic curve. DSA is the multiplicative-subgroup form.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>A working example<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">This Python fragment signs the integer 6 in a subgroup of the multiplicative group modulo 23 and checks the signature. It prints <code>5 4<\/code>.<\/p>\n\n<pre><code class=\"language-python\">\np, q, g = 23, 11, 4\nx = 7\ny = pow(g, x, p)\nh, k = 6, 2\nr = pow(g, k, p) % q\ns = (pow(k, -1, q) * (h + x * r)) % q\nw = pow(s, -1, q)\nu1, u2 = (h * w) % q, (r * w) % q\nv = (pow(g, u1, p) * pow(y, u2, p) % p) % q\nassert v == r and r != 0 and s != 0\nprint(r, s)\n<\/code><\/pre>\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Where it is used<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">DSA is the FIPS signature that older <strong>SSH<\/strong> <code>ssh-dss<\/code> host keys used. OpenSSH disabled those keys by default. New signatures are ECDSA, Ed25519, or RSA.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>When you can drop this algorithm<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">Drop the modulo-23 parameters for any signature. Keep the two-residue check where <code>q<\/code> is large, each signature draws a fresh <code>k<\/code>, and <code>h<\/code> is a collision-resistant hash reduced modulo <code>q<\/code>.<\/p>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n<h4 class=\"wp-block-heading\"><strong>Why this stays published<\/strong><\/h4>\n\n<p class=\"wp-block-paragraph\">We publish this so a search for DSA returns the subgroup signature and the verification that recomputes <code>r<\/code>. <strong>DSA publishes <code>g^x<\/code>, signs with a fresh exponent <code>k<\/code> as the pair <code>(r, s)<\/code> modulo <code>q<\/code>, and checks the signature by recomputing <code>r<\/code>.<\/strong><\/p>\n\n\n<p class=\"wp-block-paragraph\">\u672c\u6587\u7531 HoHo \u8207 AI \u5354\u4f5c\u6574\u7406\uff0c\u6700\u5f8c\u66f4\u65b0\u65bc 2026 \u5e74 11 \u6708 13 \u65e5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 &#8211; 1, and a base g of order q. The private key x is in 1 through q &#8211; 1, and the public key&hellip;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,49],"tags":[],"class_list":["post-490","post","type-post","status-publish","format-standard","hentry","category-algorithms","category-cryptography"],"_links":{"self":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/490","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/comments?post=490"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/490\/revisions"}],"predecessor-version":[{"id":702,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/490\/revisions\/702"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=490"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=490"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=490"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}