-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrypto_ecc_test.go
More file actions
38 lines (35 loc) · 809 Bytes
/
crypto_ecc_test.go
File metadata and controls
38 lines (35 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"crypto/ecdsa"
"crypto/ed25519"
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"testing"
)
func TestECDSA(t *testing.T) {
pk, err := ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
if err != nil {
t.Fatal(err)
}
msg := []byte("hello ecdsa")
hash := sha256.New().Sum(msg)
r, s, err := ecdsa.Sign(rand.Reader, pk, hash)
if err != nil {
t.Fatal(err)
}
t.Run("verify", func(t *testing.T) {
t.Logf("Verify result: %v", ecdsa.Verify(&pk.PublicKey, hash, r, s))
})
}
func TestED25519(t *testing.T) {
pubKey, priKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
t.Fatal(err)
}
msg := []byte("hello ed25519")
sign := ed25519.Sign(priKey, msg)
t.Run("verify", func(t *testing.T) {
t.Logf("Verify result: %v", ed25519.Verify(pubKey, msg, sign))
})
}