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