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.

47 lines
1.3 KiB

6 years ago
  1. ## Schnorr signature
  2. - https://en.wikipedia.org/wiki/Schnorr_signature
  3. - [x] Hash[M || R] (where M is the msg bytes and R is a Point on the ECC, using sha256 hash function)
  4. - [x] Generate Schnorr scheme
  5. - [x] Sign
  6. - [x] Verify signature
  7. #### Usage
  8. ```go
  9. // define new elliptic curve
  10. ec := ecc.NewEC(big.NewInt(int64(0)), big.NewInt(int64(7)), big.NewInt(int64(11)))
  11. // define new point
  12. g := ecc.Point{big.NewInt(int64(11)), big.NewInt(int64(27))} // Generator
  13. // define new random r
  14. r := big.NewInt(int64(23)) // random r
  15. // define new Schnorr crypto system using the values
  16. schnorr, sk, err := Gen(ec, g, r)
  17. if err!=nil {
  18. fmt.println(err)
  19. }
  20. // define message to sign
  21. m := []byte("hola")
  22. // also we can hash the message, but it's not mandatory, as it will be done inside the schnorr.Sign, but we can perform it now, just to check the function
  23. h := Hash([]byte("hola"), c)
  24. if h.String() != "34719153732582497359642109898768696927847420320548121616059449972754491425079") {
  25. fmt.Println("not correctly hashed")
  26. }
  27. s, rPoint, err := schnorr.Sign(sk, m)
  28. if err!=nil {
  29. fmt.println(err)
  30. }
  31. // verify Schnorr signature
  32. verified, err := Verify(schnorr.EC, sk.PubK, m, s, rPoint)
  33. if err!=nil {
  34. fmt.println(err)
  35. }
  36. if verified {
  37. fmt.Println("Schnorr signature correctly verified")
  38. }
  39. ```