arnaucube
arnaucube/cryptofunPublic Self-hosted repository
cryptofun/schnorr/README.md
schnorr/README.mdRaw
 1## Schnorr signature
 2- https://en.wikipedia.org/wiki/Schnorr_signature
 3
 4- [x] Hash[M || R] (where M is the msg bytes and R is a Point on the ECC, using sha256 hash function)
 5- [x] Generate Schnorr scheme
 6- [x] Sign
 7- [x] Verify signature
 8
 9
10#### Usage
11```go
12// define new elliptic curve
13ec := ecc.NewEC(big.NewInt(int64(0)), big.NewInt(int64(7)), big.NewInt(int64(11)))
14// define new point
15g := ecc.Point{big.NewInt(int64(11)), big.NewInt(int64(27))} // Generator
16// define new random r
17r := big.NewInt(int64(23))                                   // random r
18
19// define new Schnorr crypto system using the values
20schnorr, sk, err := Gen(ec, g, r)
21if err!=nil {
22	fmt.println(err)
23}
24
25// define message to sign
26m := []byte("hola")
27
28// 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
29h := Hash([]byte("hola"), c)
30if h.String() != "34719153732582497359642109898768696927847420320548121616059449972754491425079") {
31	fmt.Println("not correctly hashed")
32}
33
34s, rPoint, err := schnorr.Sign(sk, m)
35if err!=nil {
36	fmt.println(err)
37}
38
39// verify Schnorr signature
40verified, err := Verify(schnorr.EC, sk.PubK, m, s, rPoint)
41if err!=nil {
42	fmt.println(err)
43}
44if verified {
45	fmt.Println("Schnorr signature correctly verified")
46}
47```