{"id":492,"date":"2026-11-13T13:39:32","date_gmt":"2026-11-13T05:39:32","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-ecdsa-signs-a-hash-on-an-elliptic-curve\/"},"modified":"2026-11-13T21:58:56","modified_gmt":"2026-11-13T13:58:56","slug":"how-ecdsa-signs-a-hash-on-an-elliptic-curve","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-ecdsa-signs-a-hash-on-an-elliptic-curve\/","title":{"rendered":"How ECDSA signs a hash on an elliptic curve"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>ECDSA<\/strong> signs with the same two-value shape as DSA, on an elliptic curve. The fragment uses <code>y^2 = x^3 + 2x + 2<\/code> over the field of 17 elements. The point <code>(5, 1)<\/code> has order 19. The private scalar is 7, the message stand-in is 9, and the nonce scalar is 3. <code>r<\/code> is the x-coordinate of <code>kG<\/code>, reduced modulo 19. <code>s<\/code> is <code>k^(-1) (z + r d)<\/code> modulo 19. The signature is <code>10 1<\/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\">ECDSA replaces the multiplicative subgroup with the group of points on a curve. Addition uses the chord-and-tangent rule. The point at infinity is the identity, written here as <code>None<\/code>. The order of the base point is the modulus of the signature arithmetic, and it is not the field prime. Here the field prime is 17 and the order is 19. The curve is a demonstration. A deployment uses a named curve with a large prime order and a hash in place of the integer 9.<\/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\">Nineteen times the base point is the identity, so the order claim is checked. Verification multiplies the base point by <code>z s^(-1)<\/code> and the public point by <code>r s^(-1)<\/code>, adds those points, and compares the x-coordinate modulo the order with <code>r<\/code>. The fragment&#8217;s signature passes that check. A 17-element field does not hide the private scalar. The check shows the equations.<\/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 the curve, the base point <code>G<\/code>, its order <code>n<\/code>, and the public point <code>dG<\/code>.<\/li>\n<li>Draw a nonce scalar <code>k<\/code> and set <code>r<\/code> to the x-coordinate of <code>kG<\/code>, reduced modulo <code>n<\/code>.<\/li>\n<li>Set <code>s = k^(-1) (z + r d) mod n<\/code>.<\/li>\n<li>Verify by adding <code>(z s^(-1)) G<\/code> and <code>(r s^(-1))<\/code> times the public point, and compare the x-coordinate with <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 on a toy curve, or with a repeated nonce<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Deploy the field of 17 elements<\/td>\n<td>The group has nineteen points. A deployment uses a large prime order.<\/td>\n<\/tr>\n<tr>\n<td>Reduce the signature modulo the field prime<\/td>\n<td>The signature modulus is the order of the base point. Here that order is 19, not 17.<\/td>\n<\/tr>\n<tr>\n<td>Reuse the nonce scalar<\/td>\n<td>The ephemeral scalar is part of the secret. Each signature draws a new one.<\/td>\n<\/tr>\n<tr>\n<td>Hash after signing the raw message integer<\/td>\n<td><code>z<\/code> is a hash reduced modulo the order. The integer 9 only stands in for that hash.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">DSA is the same signature in a multiplicative subgroup. Ed25519 is a different signature scheme on a twisted Edwards curve.<\/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 9 on the curve <code>y^2 = x^3 + 2x + 2<\/code> over the field of 17 elements and checks the signature. It prints <code>10 1<\/code>.<\/p>\n\n<pre><code class=\"language-python\">def _curve_demo() -&gt; tuple[int, int, int, int, tuple[int, int], int]:\n    # y^2 = x^3 + 2x + 2 over F_17. Generator (5, 1) has order 19.\n    return 17, 2, 2, 19, (5, 1), 7\n\ndef _ec_add(p, a, P, Q):\n    if P is None:\n        return Q\n    if Q is None:\n        return P\n    x1, y1 = P\n    x2, y2 = Q\n    if x1 == x2 and (y1 + y2) % p == 0:\n        return None\n    if P == Q:\n        lam = (3 * x1 * x1 + a) * pow(2 * y1, -1, p) % p\n    else:\n        lam = (y2 - y1) * pow(x2 - x1, -1, p) % p\n    x3 = (lam * lam - x1 - x2) % p\n    y3 = (lam * (x1 - x3) - y1) % p\n    return x3, y3\n\ndef _ec_mul(p, a, k, point):\n    result = None\n    addend = point\n    while k:\n        if k &amp; 1:\n            result = _ec_add(p, a, result, addend)\n        addend = _ec_add(p, a, addend, addend)\n        k &gt;&gt;= 1\n    return result\n\np, a, _b, n, g, d = _curve_demo()\nz, k = 9, 3\nr = _ec_mul(p, a, k, g)[0] % n\ns = pow(k, -1, n) * (z + r * d) % n\npublic = _ec_mul(p, a, d, g)\nw = pow(s, -1, n)\npoint = _ec_add(p, a, _ec_mul(p, a, (z * w) % n, g), _ec_mul(p, a, (r * w) % n, public))\nassert point[0] % n == r and _ec_mul(p, a, n, g) is None\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\">*<em>ECDSA*<\/em> on secp256k1 signs Bitcoin transactions, and ECDSA on P-256 signs a large share of TLS certificates and SSH keys. The signed integer is a hash modulo the group order. Ed25519 is a different signature on an Edwards curve.<\/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 this curve for any signature. Keep ECDSA where the curve is a published large curve, each signature draws a fresh nonce, and the signed integer is a hash modulo the group order.<\/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 ECDSA returns the curve signature and the check on the x-coordinate. <strong>ECDSA signs with a fresh curve scalar and checks the signature by adding two scalar multiples and reading the x-coordinate.<\/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: ECDSA signs with the same two-value shape as DSA, on an elliptic curve. The fragment uses y^2 = x^3 + 2x + 2 over the field of 17 elements. The point (5, 1) has order 19. The private scalar is 7, the message stand-in is 9, and&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-492","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\/492","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=492"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/492\/revisions"}],"predecessor-version":[{"id":704,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/492\/revisions\/704"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=492"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=492"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=492"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}