You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
950 B

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