{"id":507,"date":"2026-11-13T13:39:59","date_gmt":"2026-11-13T05:39:59","guid":{"rendered":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-shamir-sharing-reconstructs-a-secret-by-interpolation\/"},"modified":"2026-11-13T21:59:23","modified_gmt":"2026-11-13T13:59:23","slug":"how-shamir-sharing-reconstructs-a-secret-by-interpolation","status":"publish","type":"post","link":"https:\/\/hoho.live\/luda\/index.php\/2026\/11\/13\/how-shamir-sharing-reconstructs-a-secret-by-interpolation\/","title":{"rendered":"How Shamir sharing reconstructs a secret by interpolation"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Short answer:<\/strong> <strong>Shamir secret sharing<\/strong> splits a secret into points on a polynomial over a prime field. A polynomial of degree 2 is fixed by any 3 points. The fragment uses the field modulo 101 and the polynomial <code>42 + 7x + 3x^2<\/code>. The shares at <code>x = 1<\/code>, <code>x = 2<\/code>, and <code>x = 4<\/code> reconstruct 42 by Lagrange interpolation at <code>x = 0<\/code>. The coefficients are written in the fragment so the arithmetic can be checked. A deployment draws the higher coefficients at random and does not publish them.<\/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\">The problem is to hand out shares so that any 3 of them rebuild the secret and, when the higher coefficients are random and secret, any 2 of them leave it undetermined. Interpolation at zero is the rebuild step. Publishing the coefficients, as this worked example does, lets a reader recompute every share. That publication is the opposite of a deployment. With secret random coefficients, fewer shares than the degree plus one are consistent with many secrets.<\/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 this published polynomial, the three shares interpolate to 42. The arithmetic is exact in the field modulo 101, including the division by the Lagrange denominators, which is multiplication by a modular inverse. The same interpolation works for any three distinct x-coordinates in the field. The example does not claim that two of these published shares hide 42, because the coefficients are on the page.<\/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>Choose a prime and a polynomial whose constant term is the secret.<\/li>\n<li>Evaluate the polynomial at distinct nonzero points and hand out those points.<\/li>\n<li>To rebuild, form the Lagrange basis at <code>x = 0<\/code> for the collected shares.<\/li>\n<li>Sum <code>share value<\/code> times <code>basis weight<\/code> over the field.<\/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 coefficients are published or the points repeat<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Publish the polynomial and also expect two shares to hide the secret<\/td>\n<td>The published coefficients determine the polynomial. A deployment keeps them secret.<\/td>\n<\/tr>\n<tr>\n<td>Issue two shares at the same x-coordinate<\/td>\n<td>Interpolation needs distinct x-coordinates. A repeated x-coordinate is not a new point.<\/td>\n<\/tr>\n<tr>\n<td>Interpolate with ordinary integer division<\/td>\n<td>The weights are field elements. Division is multiplication by the modular inverse.<\/td>\n<\/tr>\n<tr>\n<td>Add the shares and call the sum the secret<\/td>\n<td>The secret is the constant term, which is the interpolation at zero, not the sum of the y-values.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n\n\n<p class=\"wp-block-paragraph\">The arithmetic is Lagrange interpolation. The secrecy is the unpublished random coefficients, which this checked example deliberately prints.<\/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 evaluates a degree-2 polynomial over the field modulo 101 and interpolates the secret. It prints <code>42<\/code>.<\/p>\n\n<pre><code class=\"language-python\">def shamir_share(secret: int, prime: int, xs: list[int]) -&gt; list[tuple[int, int]]:\n    # f(x) = secret + 7x + 3x^2  over the field. Degree 2 needs any 3 shares.\n    def f(x: int) -&gt; int:\n        return (secret + 7 * x + 3 * x * x) % prime\n\n    return [(x, f(x)) for x in xs]\n\ndef shamir_reconstruct(shares: list[tuple[int, int]], prime: int) -&gt; int:\n    total = 0\n    for i, (x, y) in enumerate(shares):\n        num = den = 1\n        for j, (xo, _) in enumerate(shares):\n            if i == j:\n                continue\n            num = num * (-xo) % prime\n            den = den * (x - xo) % prime\n        total = (total + y * num * pow(den, -1, prime)) % prime\n    return total\n\nshares = shamir_share(42, 101, [1, 2, 4])\nassert shamir_reconstruct(shares, 101) == 42\nprint(shamir_reconstruct(shares, 101))\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>HashiCorp Vault<\/strong> unseals with Shamir sharing: the master key is split, and a threshold of key holders reconstructs it. Backup schemes that split a key among people use the same interpolation. The shares in the worked example publish their coefficients; a deployment does not.<\/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 a sharing whose coefficients are written down beside the shares. Keep Shamir sharing where the higher coefficients are random, the prime is large, and the reconstruction threshold is the number of shares the application can require.<\/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 Shamir secret sharing returns the polynomial, the threshold, and the interpolation at zero. <strong>Shamir sharing evaluates a polynomial whose constant term is the secret, and any enough shares rebuild that constant by interpolation at zero.<\/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: Shamir secret sharing splits a secret into points on a polynomial over a prime field. A polynomial of degree 2 is fixed by any 3 points. The fragment uses the field modulo 101 and the polynomial 42 + 7x + 3x^2. The shares at x = 1,&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-507","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\/507","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=507"}],"version-history":[{"count":1,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":719,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/posts\/507\/revisions\/719"}],"wp:attachment":[{"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/media?parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/categories?post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hoho.live\/luda\/index.php\/wp-json\/wp\/v2\/tags?post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}