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.

49 lines
968 B

5 years ago
  1. ## ECC ECDSA
  2. - https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm
  3. - [x] define ECDSA data structure
  4. - [x] ECDSA Sign
  5. - [x] ECDSA Verify signature
  6. #### Usage
  7. ```go
  8. // define new elliptic curve
  9. ec := ecc.NewEC(big.NewInt(int64(1)), big.NewInt(int64(18)), big.NewInt(int64(19)))
  10. // define new point
  11. g := ecc.Point{big.NewInt(int64(7)), big.NewInt(int64(11))}
  12. // define new ECDSA system
  13. dsa, err := NewDSA(ec, g)
  14. if err!=nil {
  15. fmt.Println(err)
  16. }
  17. // define privK&pubK over the elliptic curve
  18. privK := big.NewInt(int64(5))
  19. pubK, err := dsa.PubK(privK)
  20. if err!=nil {
  21. fmt.Println(err)
  22. }
  23. // hash value to sign
  24. hashval := big.NewInt(int64(40))
  25. // define r
  26. r := big.NewInt(int64(11))
  27. // sign hashed value
  28. sig, err := dsa.Sign(hashval, privK, r)
  29. if err!=nil {
  30. fmt.Println(err)
  31. }
  32. // verify signature
  33. verified, err := dsa.Verify(hashval, sig, pubK)
  34. if err!=nil {
  35. fmt.Println(err)
  36. }
  37. if verified {
  38. fmt.Println("signature correctly verified")
  39. }
  40. ```