arnaucube
arnaucube/cryptofunPublic Self-hosted repository
cryptofun/secrets/secrets_test.go
secrets/secrets_test.goRaw
 1package secrets
 2
 3import (
 4	"crypto/rand"
 5	"math/big"
 6	"testing"
 7)
 8
 9func TestCreate(t *testing.T) {
10	k := 123456789
11	p, err := rand.Prime(rand.Reader, bits/2)
12	if err != nil {
13		t.Errorf(err.Error())
14	}
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	if err != nil {
24		t.Errorf(err.Error())
25	}
26
27	//generate sharesToUse
28	var sharesToUse [][]*big.Int
29	sharesToUse = append(sharesToUse, shares[2])
30	sharesToUse = append(sharesToUse, shares[1])
31	sharesToUse = append(sharesToUse, shares[0])
32	secr := LagrangeInterpolation(sharesToUse, p)
33
34	// fmt.Print("original secret: ")
35	// fmt.Println(k)
36	// fmt.Print("p: ")
37	// fmt.Println(p)
38	// fmt.Print("shares: ")
39	// fmt.Println(shares)
40	// fmt.Print("secret result: ")
41	// fmt.Println(secr)
42	if int64(k) != secr.Int64() {
43		t.Errorf("reconstructed secret not correspond to original secret")
44	}
45}