-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathring_sign_test.go
88 lines (71 loc) · 2.25 KB
/
ring_sign_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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package sm2rsign
import (
"crypto/ecdsa"
"crypto/rand"
"testing"
"github.com/emmansun/gmsm/sm2"
)
func testRSignWithTwoKeys(t *testing.T, participantRandInt ParticipantRandInt) {
signer, _ := sm2.GenerateKey(rand.Reader)
participant, _ := sm2.GenerateKey((rand.Reader))
pubs := []*ecdsa.PublicKey{&signer.PublicKey, &participant.PublicKey}
msg := []byte("hello world")
sig, err := Sign(rand.Reader, participantRandInt, signer, pubs, msg)
if err != nil {
t.Fatal(err)
}
if !Verify(pubs, msg, sig) {
t.Errorf("failed to verify the signature")
}
pubs[0] = &participant.PublicKey
pubs[1] = &signer.PublicKey
sig, err = Sign(rand.Reader, participantRandInt, signer, pubs, msg)
if err != nil {
t.Fatal(err)
}
if !Verify(pubs, msg, sig) {
t.Errorf("failed to verify the signature")
}
}
func TestRSignWithTwoKeys(t *testing.T) {
testRSignWithTwoKeys(t, SimpleParticipantRandInt)
testRSignWithTwoKeys(t, SM2ParticipantRandInt)
}
func testRSignWithThreeKeys(t *testing.T, participantRandInt ParticipantRandInt) {
signer, _ := sm2.GenerateKey(rand.Reader)
participant1, _ := sm2.GenerateKey((rand.Reader))
participant2, _ := sm2.GenerateKey((rand.Reader))
pubs := []*ecdsa.PublicKey{&participant1.PublicKey, &signer.PublicKey, &participant2.PublicKey}
msg := []byte("hello world")
sig, err := Sign(rand.Reader, participantRandInt, signer, pubs, msg)
if err != nil {
t.Fatal(err)
}
if !Verify(pubs, msg, sig) {
t.Errorf("failed to verify the signature")
}
pubs[0] = &participant1.PublicKey
pubs[1] = &participant2.PublicKey
pubs[2] = &signer.PublicKey
sig, err = Sign(rand.Reader, participantRandInt, signer, pubs, msg)
if err != nil {
t.Fatal(err)
}
if !Verify(pubs, msg, sig) {
t.Errorf("failed to verify the signature")
}
pubs[0] = &signer.PublicKey
pubs[1] = &participant1.PublicKey
pubs[2] = &participant2.PublicKey
sig, err = Sign(rand.Reader, participantRandInt, signer, pubs, msg)
if err != nil {
t.Fatal(err)
}
if !Verify(pubs, msg, sig) {
t.Errorf("failed to verify the signature")
}
}
func TestRSignWithThreeKeys(t *testing.T) {
testRSignWithThreeKeys(t, SimpleParticipantRandInt)
testRSignWithThreeKeys(t, SM2ParticipantRandInt)
}