diff --git a/README.md b/README.md index f3513d4..164d971 100644 --- a/README.md +++ b/README.md @@ -7,14 +7,3 @@ leveraging Python's support for very long integers. - Ethan L. Miller (`coding@ethanmiller.com`) -## License - -Copyright 2023 Ethan L. Miller - -Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. - -1. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/gfalg.py b/gfalg.py index d741ca8..05e9b60 100644 --- a/gfalg.py +++ b/gfalg.py @@ -46,10 +46,13 @@ class SSS_Share: def __repr__ (self): return str(self) -def _lagrange_interpolate (x, shares): - pass - def sss_generate_shares (secret, min_shares, share_ids): + ''' + secret: secret value to share - must be of type Secret + min_shares: minimum number of shares to reconstruct secret + share_ids: list (iterable) of share identifiers + Returns a list of shares. + ''' if any ([not 1 <= x <= 254 for x in share_ids]): raise ValueError ("Share IDs must be between 1-254") coeff = list() @@ -68,18 +71,28 @@ def sss_generate_shares (secret, min_shares, share_ids): return shares -def sss_recover_secret (shares): +def sss_recover_secret (shares, share_id = 0): shrs = tuple (_gf_unpack (s.secret.value) for s in shares) ids = tuple (GN(x.share_id, gf) for x in shares) accum = [GN(0, gf)] * len(shares[0].secret) + sid = GN(share_id, gf) for (x, shr) in zip (ids, shrs): prod = GN(1, gf) for i in ids: if i != x: - prod *= i / (i - x) + prod *= (sid - i) / (i - x) accum = prod.mul_region (shr, accum) - return Secret (_gf_pack (accum)) + secret = Secret(_gf_pack (accum)) + if (share_id == 0): + return secret + else: + return SSS_Share (share_id, secret) + def sss_generate_new_share (shares, share_id): - pass + ''' + Generate a new share with the passed share_id, compatible with + the shares passed in. + ''' + return sss_recover_secret (shares, share_id)