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
994 B

  1. package ecdsa
  2. import (
  3. "math/big"
  4. "testing"
  5. ecc "../ecc"
  6. )
  7. func TestNewECDSA(t *testing.T) {
  8. ec := ecc.NewEC(1, 18, 19)
  9. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
  10. dsa, err := NewDSA(ec, g)
  11. if err != nil {
  12. t.Errorf(err.Error())
  13. }
  14. privK := 5
  15. pubK, err := dsa.PubK(privK)
  16. if err != nil {
  17. t.Errorf(err.Error())
  18. }
  19. if !pubK.Equal(ecc.Point{big.NewInt(int64(13)), big.NewInt(int64(9))}) {
  20. t.Errorf("pubK!=(13, 9)")
  21. }
  22. }
  23. func TestECDSASignAndVerify(t *testing.T) {
  24. ec := ecc.NewEC(1, 18, 19)
  25. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
  26. dsa, err := NewDSA(ec, g)
  27. if err != nil {
  28. t.Errorf(err.Error())
  29. }
  30. privK := 5
  31. pubK, err := dsa.PubK(privK)
  32. if err != nil {
  33. t.Errorf(err.Error())
  34. }
  35. hashval := big.NewInt(int64(40))
  36. r := big.NewInt(int64(11))
  37. sig, err := dsa.Sign(hashval, privK, r)
  38. if err != nil {
  39. t.Errorf(err.Error())
  40. }
  41. verified, err := dsa.Verify(hashval, sig, pubK)
  42. if !verified {
  43. t.Errorf("verified == false")
  44. }
  45. }