@@ -26,14 +26,6 @@ func (zeroReader) Read(buf []byte) (int, error) {
26
26
return len (buf ), nil
27
27
}
28
28
29
- // signGenericWrapper is identical to Sign except that it unconditionally calls signGeneric directly
30
- // rather than going through the sign function that might call assembly code.
31
- func signGenericWrapper (privateKey PrivateKey , msg []byte ) []byte {
32
- sig := make ([]byte , SignatureSize )
33
- signGeneric (sig , privateKey , msg )
34
- return sig
35
- }
36
-
37
29
func TestUnmarshalMarshal (t * testing.T ) {
38
30
pub , _ , _ := GenerateKey (rand .Reader )
39
31
@@ -53,33 +45,22 @@ func TestUnmarshalMarshal(t *testing.T) {
53
45
}
54
46
55
47
func TestSignVerify (t * testing.T ) {
56
- t .Run ("Generic" , func (t * testing.T ) { testSignVerify (t , signGenericWrapper , verifyGeneric ) })
57
- t .Run ("Native" , func (t * testing.T ) { testSignVerify (t , Sign , Verify ) })
58
- }
59
-
60
- func testSignVerify (t * testing.T , signImpl func (privateKey PrivateKey , message []byte ) []byte ,
61
- verifyImpl func (publicKey PublicKey , message , sig []byte ) bool ) {
62
48
var zero zeroReader
63
49
public , private , _ := GenerateKey (zero )
64
50
65
51
message := []byte ("test message" )
66
- sig := signImpl (private , message )
67
- if ! verifyImpl (public , message , sig ) {
52
+ sig := Sign (private , message )
53
+ if ! Verify (public , message , sig ) {
68
54
t .Errorf ("valid signature rejected" )
69
55
}
70
56
71
57
wrongMessage := []byte ("wrong message" )
72
- if verifyImpl (public , wrongMessage , sig ) {
58
+ if Verify (public , wrongMessage , sig ) {
73
59
t .Errorf ("signature of different message accepted" )
74
60
}
75
61
}
76
62
77
63
func TestCryptoSigner (t * testing.T ) {
78
- t .Run ("Generic" , func (t * testing.T ) { testCryptoSigner (t , verifyGeneric ) })
79
- t .Run ("Native" , func (t * testing.T ) { testCryptoSigner (t , Verify ) })
80
- }
81
-
82
- func testCryptoSigner (t * testing.T , verifyImpl func (publicKey PublicKey , message , sig []byte ) bool ) {
83
64
var zero zeroReader
84
65
public , private , _ := GenerateKey (zero )
85
66
@@ -102,7 +83,7 @@ func testCryptoSigner(t *testing.T, verifyImpl func(publicKey PublicKey, message
102
83
t .Fatalf ("error from Sign(): %s" , err )
103
84
}
104
85
105
- if ! verifyImpl (public , message , signature ) {
86
+ if ! Verify (public , message , signature ) {
106
87
t .Errorf ("Verify failed on signature from Sign()" )
107
88
}
108
89
}
@@ -130,12 +111,6 @@ func TestEqual(t *testing.T) {
130
111
}
131
112
132
113
func TestGolden (t * testing.T ) {
133
- t .Run ("Generic" , func (t * testing.T ) { testGolden (t , signGenericWrapper , verifyGeneric ) })
134
- t .Run ("Native" , func (t * testing.T ) { testGolden (t , Sign , Verify ) })
135
- }
136
-
137
- func testGolden (t * testing.T , signImpl func (privateKey PrivateKey , message []byte ) []byte ,
138
- verifyImpl func (publicKey PublicKey , message , sig []byte ) bool ) {
139
114
// sign.input.gz is a selection of test cases from
140
115
// https://ed25519.cr.yp.to/python/sign.input
141
116
testDataZ , err := os .Open ("testdata/sign.input.gz" )
@@ -177,12 +152,12 @@ func testGolden(t *testing.T, signImpl func(privateKey PrivateKey, message []byt
177
152
copy (priv [:], privBytes )
178
153
copy (priv [32 :], pubKey )
179
154
180
- sig2 := signImpl (priv [:], msg )
155
+ sig2 := Sign (priv [:], msg )
181
156
if ! bytes .Equal (sig , sig2 [:]) {
182
157
t .Errorf ("different signature result on line %d: %x vs %x" , lineNo , sig , sig2 )
183
158
}
184
159
185
- if ! verifyImpl (pubKey , msg , sig2 ) {
160
+ if ! Verify (pubKey , msg , sig2 ) {
186
161
t .Errorf ("signature failed to verify on line %d" , lineNo )
187
162
}
188
163
@@ -206,11 +181,6 @@ func testGolden(t *testing.T, signImpl func(privateKey PrivateKey, message []byt
206
181
}
207
182
208
183
func TestMalleability (t * testing.T ) {
209
- t .Run ("Generic" , func (t * testing.T ) { testMalleability (t , verifyGeneric ) })
210
- t .Run ("Native" , func (t * testing.T ) { testMalleability (t , Verify ) })
211
- }
212
-
213
- func testMalleability (t * testing.T , verifyImpl func (publicKey PublicKey , message , sig []byte ) bool ) {
214
184
// https://tools.ietf.org/html/rfc8032#section-5.1.7 adds an additional test
215
185
// that s be in [0, order). This prevents someone from adding a multiple of
216
186
// order to s and obtaining a second valid signature for the same message.
@@ -229,7 +199,7 @@ func testMalleability(t *testing.T, verifyImpl func(publicKey PublicKey, message
229
199
0xb1 , 0x08 , 0xc3 , 0xbd , 0xae , 0x36 , 0x9e , 0xf5 , 0x49 , 0xfa ,
230
200
}
231
201
232
- if verifyImpl (publicKey , msg , sig ) {
202
+ if Verify (publicKey , msg , sig ) {
233
203
t .Fatal ("non-canonical signature accepted" )
234
204
}
235
205
}
0 commit comments