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.

51 lines
1.4 KiB

  1. package schnorr
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/arnaucube/cryptofun/ecc"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestHash(t *testing.T) {
  9. c := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(8))} // Generator
  10. h := Hash([]byte("hola"), c)
  11. assert.Equal(t, h.String(), "34719153732582497359642109898768696927847420320548121616059449972754491425079")
  12. }
  13. func TestSign(t *testing.T) {
  14. ec := ecc.NewEC(big.NewInt(int64(0)), big.NewInt(int64(7)), big.NewInt(int64(11)))
  15. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(8))} // Generator
  16. r := big.NewInt(int64(7)) // random r
  17. schnorr, sk, err := Gen(ec, g, r)
  18. assert.Nil(t, err)
  19. m := []byte("hola")
  20. s, rPoint, err := schnorr.Sign(sk, m)
  21. assert.Nil(t, err)
  22. verified, err := Verify(schnorr.EC, sk.PubK, m, s, rPoint)
  23. assert.Nil(t, err)
  24. assert.True(t, verified)
  25. }
  26. func TestSign2(t *testing.T) {
  27. ec := ecc.NewEC(big.NewInt(int64(0)), big.NewInt(int64(7)), big.NewInt(int64(29)))
  28. g := ecc.Point{big.NewInt(int64(11)), big.NewInt(int64(27))} // Generator
  29. r := big.NewInt(int64(23)) // random r
  30. schnorr, sk, err := Gen(ec, g, r)
  31. assert.Nil(t, err)
  32. m := []byte("hola")
  33. s, rPoint, err := schnorr.Sign(sk, m)
  34. assert.Nil(t, err)
  35. verified, err := Verify(schnorr.EC, sk.PubK, m, s, rPoint)
  36. assert.Nil(t, err)
  37. assert.True(t, verified)
  38. }