From cccce548b3b04081f3bdc70ddc82e403ed611f45 Mon Sep 17 00:00:00 2001 From: arnaucube Date: Sat, 13 Apr 2019 02:23:37 +0200 Subject: [PATCH] shamirsecretsharing moved to it's own repository plus wasm compiled lib --- shamirsecretsharing/README.md | 48 +------- shamirsecretsharing/shamirsecretsharing.go | 115 ------------------ .../shamirsecretsharing_test.go | 44 ------- 3 files changed, 2 insertions(+), 205 deletions(-) delete mode 100644 shamirsecretsharing/shamirsecretsharing.go delete mode 100644 shamirsecretsharing/shamirsecretsharing_test.go diff --git a/shamirsecretsharing/README.md b/shamirsecretsharing/README.md index ff411d8..f19f793 100644 --- a/shamirsecretsharing/README.md +++ b/shamirsecretsharing/README.md @@ -1,48 +1,4 @@ ## Shamir Secret Sharing -- https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing +Implementation of the Shamir Secret Sharing in Go + WASM compiled lib -- [x] create secret sharing from number of secrets needed, number of shares, random point p, secret to share -- [x] Lagrange Interpolation to restore the secret from the shares - -#### Usage -```go -// define secret to share -k := 123456789 - -// define random prime -p, err := rand.Prime(rand.Reader, bits/2) -if err!=nil { - fmt.Println(err) -} - -// define how many shares want to generate -nShares := big.NewInt(int64(6)) - -// define how many shares are needed to recover the secret -nNeededShares := big.NewInt(int64(3)) - -// create the shares -shares, err := Create( - nNeededShares, - nShares, - p, - big.NewInt(int64(k))) -assert.Nil(t, err) -if err!=nil { - fmt.Println(err) -} - -// select shares to use -var sharesToUse [][]*big.Int -sharesToUse = append(sharesToUse, shares[2]) -sharesToUse = append(sharesToUse, shares[1]) -sharesToUse = append(sharesToUse, shares[0]) - -// recover the secret using Lagrange Interpolation -secr := LagrangeInterpolation(sharesToUse, p) - -// check that the restored secret matches the original secret -if !bytes.Equal(k.Bytes(), secr.Bytes()) { - fmt.Println("reconstructed secret not correspond to original secret") -} -``` +Code moved to https://github.com/arnaucube/shamirsecretsharing diff --git a/shamirsecretsharing/shamirsecretsharing.go b/shamirsecretsharing/shamirsecretsharing.go deleted file mode 100644 index f018aea..0000000 --- a/shamirsecretsharing/shamirsecretsharing.go +++ /dev/null @@ -1,115 +0,0 @@ -package shamirsecretsharing - -import ( - "crypto/rand" - "errors" - "math/big" -) - -const ( - // bits = 1024 - bits = 2048 -) - -// Create calculates the secrets to share from given parameters -// t: number of secrets needed -// n: number of shares -// p: random point -// k: secret to share -func Create(t, n, p, k *big.Int) (result [][]*big.Int, err error) { - if k.Cmp(p) > 0 { - return nil, errors.New("Error: need k