cryptofun/shamirsecretsharing/shamirsecretsharing_test.go
shamirsecretsharing/shamirsecretsharing_test.goRaw
1package shamirsecretsharing
2
3import (
4 "crypto/rand"
5 "math/big"
6 "testing"
7
8 "github.com/stretchr/testify/assert"
9)
10
11func TestCreate(t *testing.T) {
12 k := 123456789
13 p, err := rand.Prime(rand.Reader, bits/2)
14 assert.Nil(t, err)
15
16 nNeededSecrets := big.NewInt(int64(3))
17 nShares := big.NewInt(int64(6))
18 shares, err := Create(
19 nNeededSecrets,
20 nShares,
21 p,
22 big.NewInt(int64(k)))
23 assert.Nil(t, err)
24
25 //generate sharesToUse
26 var sharesToUse [][]*big.Int
27 sharesToUse = append(sharesToUse, shares[2])
28 sharesToUse = append(sharesToUse, shares[1])
29 sharesToUse = append(sharesToUse, shares[0])
30 secr := LagrangeInterpolation(sharesToUse, p)
31
32 // fmt.Print("original secret: ")
33 // fmt.Println(k)
34 // fmt.Print("p: ")
35 // fmt.Println(p)
36 // fmt.Print("shares: ")
37 // fmt.Println(shares)
38 // fmt.Print("secret result: ")
39 // fmt.Println(secr)
40 if int64(k) != secr.Int64() {
41 t.Errorf("reconstructed secret not correspond to original secret")
42 }
43}