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.

44 lines
1.0 KiB

  1. package ecdsa
  2. import (
  3. "math/big"
  4. "testing"
  5. "github.com/arnaucube/cryptofun/ecc"
  6. "github.com/stretchr/testify/assert"
  7. )
  8. func TestNewECDSA(t *testing.T) {
  9. ec := ecc.NewEC(big.NewInt(int64(1)), big.NewInt(int64(18)), big.NewInt(int64(19)))
  10. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
  11. dsa, err := NewDSA(ec, g)
  12. assert.Nil(t, err)
  13. privK := big.NewInt(int64(5))
  14. pubK, err := dsa.PubK(privK)
  15. assert.Nil(t, err)
  16. if !pubK.Equal(ecc.Point{big.NewInt(int64(13)), big.NewInt(int64(9))}) {
  17. t.Errorf("pubK!=(13, 9)")
  18. }
  19. }
  20. func TestECDSASignAndVerify(t *testing.T) {
  21. ec := ecc.NewEC(big.NewInt(int64(1)), big.NewInt(int64(18)), big.NewInt(int64(19)))
  22. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
  23. dsa, err := NewDSA(ec, g)
  24. assert.Nil(t, err)
  25. privK := big.NewInt(int64(5))
  26. pubK, err := dsa.PubK(privK)
  27. assert.Nil(t, err)
  28. hashval := big.NewInt(int64(40))
  29. r := big.NewInt(int64(11))
  30. sig, err := dsa.Sign(hashval, privK, r)
  31. assert.Nil(t, err)
  32. verified, err := dsa.Verify(hashval, sig, pubK)
  33. assert.True(t, verified)
  34. }