{"id":491,"date":"2026-11-13T13:39:30","date_gmt":"2026-11-13T05:39:30","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-ecdh-multiplies-a-shared-elliptic-curve-point\/"},"modified":"2026-11-13T21:58:55","modified_gmt":"2026-11-13T13:58:55","slug":"how-ecdh-multiplies-a-shared-elliptic-curve-point","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-ecdh-multiplies-a-shared-elliptic-curve-point\/","title":{"rendered":"How ECDH multiplies a shared elliptic-curve point"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>ECDH<\/strong> agrees on a shared point. Each side multiplies the public base point by its own scalar and publishes the result. Each side then multiplies the other side&#8217;s point by its own scalar. The two products are the same point, because scalar multiplication commutes. The fragment uses the curve <code>y^2 = x^3 + 2x + 2<\/code> over the field of 17 elements, the base point <code>(5, 1)<\/code>, and the scalars 3 and 5. The shared x-coordinate is 3.<\/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\">Two parties who have never shared a secret need a value that an observer of their published points cannot compute. Each keeps a scalar and publishes the matching point. The shared point is the base point multiplied by both scalars. The raw x-coordinate is not yet a symmetric key. A deployment feeds it through a key derivation function. The 17-element field is a demonstration of the commutation. X25519 is this agreement on Curve25519, with a clamped scalar and a Montgomery ladder.<\/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\">With these scalars, both orders of multiplication produce the point whose x-coordinate is 3. The identity used here is <code>(a b) G = a (b G) = b (a G)<\/code>. An observer who sees only the public points and can solve the discrete logarithm can compute the same point. In this group that logarithm is a short search. The fragment checks the equality, not the secrecy of a 17-element field.<\/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>Agree on a curve and a base point.<\/li>\n<li>Each side draws a scalar and publishes the base point times that scalar.<\/li>\n<li>Each side multiplies the received point by its own scalar.<\/li>\n<li>Use a key derivation function on the shared x-coordinate before using the result as a symmetric key.<\/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 when the raw point is used as a key<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Use the x-coordinate as an AES key<\/td>\n<td>The coordinate is a group element encoding. HKDF, or another labeled derivation, turns it into key bytes.<\/td>\n<\/tr>\n<tr>\n<td>Deploy the field of 17 elements<\/td>\n<td>Both scalars are recoverable by trying a handful of multiples.<\/td>\n<\/tr>\n<tr>\n<td>Skip the second multiplication and hash the published points<\/td>\n<td>The shared secret is the product of both scalars. The published points are public.<\/td>\n<\/tr>\n<tr>\n<td>Reuse one scalar for every peer and never rotate it<\/td>\n<td>A long-term scalar is a long-term key. The fragment only shows one agreement.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">X25519 is the Curve25519 form of this agreement. The toy curve is the commutation check.<\/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 agrees on a point of the same toy curve used for the ECDSA example. It prints <code>3<\/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\ndef ecdh_demo() -&gt; str:\n    p, a, _b, _n, g, _d = _curve_demo()\n    da, db = 3, 5\n    shared_a = _ec_mul(p, a, da, _ec_mul(p, a, db, g))\n    shared_b = _ec_mul(p, a, db, _ec_mul(p, a, da, g))\n    assert shared_a == shared_b\n    return str(shared_a[0])\n\nassert ecdh_demo() == &quot;3&quot;\nprint(ecdh_demo())\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\"><strong>TLS<\/strong> key agreement on NIST curve P-256 is elliptic-curve Diffie-Hellman. The client and the server each send a point and derive the shared point. X25519 is the Curve25519 form of the same agreement and is the usual choice in new handshakes.<\/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 shared secret. Keep ECDH where the curve is large, each side has a scalar the other does not see, and the shared coordinate passes through a key derivation function.<\/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 ECDH returns the two scalar multiplications and the shared point. <strong>ECDH publishes <code>aG<\/code> and <code>bG<\/code> and both sides compute <code>abG<\/code>, then derive symmetric keys from that point.<\/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: ECDH agrees on a shared point. Each side multiplies the public base point by its own scalar and publishes the result. Each side then multiplies the other side&#8217;s point by its own scalar. The two products are the same point, because scalar multiplication commutes. The fragment uses&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-491","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\/491","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=491"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":703,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/491\/revisions\/703"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}