docs updated

This commit is contained in:
arnaucube
2018-11-03 22:01:47 +01:00
parent d4433a1008
commit 3dfb1e5875
14 changed files with 1182 additions and 27 deletions

View File

@@ -0,0 +1,48 @@
## Shamir Secret Sharing
- https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing
- [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")
}
```

View File

@@ -15,10 +15,10 @@ func TestCreate(t *testing.T) {
p, err := rand.Prime(rand.Reader, bits/2)
assert.Nil(t, err)
nNeededSecrets := big.NewInt(int64(3))
nShares := big.NewInt(int64(6))
nNeededShares := big.NewInt(int64(3))
shares, err := Create(
nNeededSecrets,
nNeededShares,
nShares,
p,
k)