-
Notifications
You must be signed in to change notification settings - Fork 4
/
signature_test.go
54 lines (43 loc) · 1.14 KB
/
signature_test.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package crypto
import (
"encoding/hex"
"testing"
)
func TestP256R1(t *testing.T) {
msg := "77e74f1786b1f97c3b14100325201cc890906d0164d001b9210d4d28e217198a"
kp, err := P256R1.New()
if err != nil {
t.Errorf("TestP256R1: New error: %v\n", err)
}
M, _ := hex.DecodeString(msg)
RS, err := kp.PrivateKey().Sign(M)
if err != nil {
t.Errorf("TestP256R1: Sign error, %v\n", err)
}
if err := kp.PublicKey().Verify(M, RS); err != nil {
t.Errorf("TestP256R1: verify error.\n")
}
M[1] = 0xFF
if err := kp.PublicKey().Verify(M, RS); err == nil {
t.Errorf("TestP256R1: verify error.\n")
}
}
func TestEd25519(t *testing.T) {
msg := "77e74f1786b1f97c3b14100325201cc890906d0164d001b9210d4d28e217198a"
kp, err := ED25519.New()
if err != nil {
t.Errorf("TestEd25519: New error: %v\n", err)
}
M, _ := hex.DecodeString(msg)
RS, err := kp.PrivateKey().Sign(M)
if err != nil {
t.Errorf("TestEd25519: Sign error, %v\n", err)
}
if err := kp.PublicKey().Verify(M, RS); err != nil {
t.Errorf("TestEd25519: verify error.\n")
}
M[1] = 0xFF
if err := kp.PublicKey().Verify(M, RS); err == nil {
t.Errorf("TestEd25519: verify error.\n")
}
}