-
Notifications
You must be signed in to change notification settings - Fork 1
/
eddsa_test.go
259 lines (227 loc) · 9 KB
/
eddsa_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
package ed448
import (
. "gopkg.in/check.v1"
)
func (s *Ed448Suite) Test_DSASign_generatesCorrectSignature(c *C) {
sym := [57]byte{
0x3f,
}
msg := []byte{
0x0A, 0x0C, 0x0B,
}
_, pub := deriveKeypair(sym)
sig := DSASign(sym, pub, msg)
c.Assert(sig[:], DeepEquals, []byte{
0x7F, 0x26, 0xB2, 0x6D, 0x92, 0xB8, 0xCB, 0x20,
0xD7, 0xA5, 0x59, 0x2D, 0xFE, 0x13, 0xC0, 0x15,
0x77, 0x1D, 0xA2, 0xB3, 0x87, 0x14, 0x2F, 0x85,
0x0D, 0xE7, 0x1C, 0x55, 0x03, 0xDB, 0xD7, 0x9D,
0x02, 0x17, 0x8C, 0x25, 0x72, 0x85, 0x7C, 0x25,
0x36, 0xE2, 0x06, 0xDF, 0xCA, 0xC5, 0x4B, 0x5A,
0xA4, 0xC3, 0x61, 0xA3, 0xA2, 0x78, 0x4C, 0x97,
0x00, 0x40, 0x07, 0xE3, 0x01, 0x85, 0xE8, 0xFB,
0xBE, 0x4E, 0xE1, 0xD2, 0x02, 0x40, 0x14, 0x65,
0x7F, 0x13, 0x29, 0x88, 0xA7, 0x62, 0xDF, 0x17,
0x02, 0x4A, 0x86, 0x01, 0x6D, 0x51, 0x22, 0x50,
0x1C, 0x58, 0xC4, 0x39, 0x67, 0x41, 0xEE, 0x67,
0x87, 0x5C, 0xB4, 0x38, 0xFE, 0xED, 0x1F, 0x71,
0x26, 0xE3, 0x3C, 0x8B, 0x6E, 0x7A, 0x26, 0xD0,
0x1C, 0x00,
})
}
func (s *Ed448Suite) Test_DSAVerify_verifiesACorrectSignature(c *C) {
sig := [114]byte{
0x7F, 0x26, 0xB2, 0x6D, 0x92, 0xB8, 0xCB, 0x20,
0xD7, 0xA5, 0x59, 0x2D, 0xFE, 0x13, 0xC0, 0x15,
0x77, 0x1D, 0xA2, 0xB3, 0x87, 0x14, 0x2F, 0x85,
0x0D, 0xE7, 0x1C, 0x55, 0x03, 0xDB, 0xD7, 0x9D,
0x02, 0x17, 0x8C, 0x25, 0x72, 0x85, 0x7C, 0x25,
0x36, 0xE2, 0x06, 0xDF, 0xCA, 0xC5, 0x4B, 0x5A,
0xA4, 0xC3, 0x61, 0xA3, 0xA2, 0x78, 0x4C, 0x97,
0x00, 0x40, 0x07, 0xE3, 0x01, 0x85, 0xE8, 0xFB,
0xBE, 0x4E, 0xE1, 0xD2, 0x02, 0x40, 0x14, 0x65,
0x7F, 0x13, 0x29, 0x88, 0xA7, 0x62, 0xDF, 0x17,
0x02, 0x4A, 0x86, 0x01, 0x6D, 0x51, 0x22, 0x50,
0x1C, 0x58, 0xC4, 0x39, 0x67, 0x41, 0xEE, 0x67,
0x87, 0x5C, 0xB4, 0x38, 0xFE, 0xED, 0x1F, 0x71,
0x26, 0xE3, 0x3C, 0x8B, 0x6E, 0x7A, 0x26, 0xD0,
0x1C, 0x00,
}
sym := [57]byte{
0x3f,
}
msg := []byte{
0x0A, 0x0C, 0x0B,
}
_, pub := deriveKeypair(sym)
c.Assert(DSAVerify(sig, pub, msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_doesntVerifyACorrectSignature_withWrongKey(c *C) {
sig := [114]byte{
0x7F, 0x26, 0xB2, 0x6D, 0x92, 0xB8, 0xCB, 0x20,
0xD7, 0xA5, 0x59, 0x2D, 0xFE, 0x13, 0xC0, 0x15,
0x77, 0x1D, 0xA2, 0xB3, 0x87, 0x14, 0x2F, 0x85,
0x0D, 0xE7, 0x1C, 0x55, 0x03, 0xDB, 0xD7, 0x9D,
0x02, 0x17, 0x8C, 0x25, 0x72, 0x85, 0x7C, 0x25,
0x36, 0xE2, 0x06, 0xDF, 0xCA, 0xC5, 0x4B, 0x5A,
0xA4, 0xC3, 0x61, 0xA3, 0xA2, 0x78, 0x4C, 0x97,
0x00, 0x40, 0x07, 0xE3, 0x01, 0x85, 0xE8, 0xFB,
0xBE, 0x4E, 0xE1, 0xD2, 0x02, 0x40, 0x14, 0x65,
0x7F, 0x13, 0x29, 0x88, 0xA7, 0x62, 0xDF, 0x17,
0x02, 0x4A, 0x86, 0x01, 0x6D, 0x51, 0x22, 0x50,
0x1C, 0x58, 0xC4, 0x39, 0x67, 0x41, 0xEE, 0x67,
0x87, 0x5C, 0xB4, 0x38, 0xFE, 0xED, 0x1F, 0x71,
0x26, 0xE3, 0x3C, 0x8B, 0x6E, 0x7A, 0x26, 0xD0,
0x1C, 0x00,
}
sym := [57]byte{
0x4f,
}
msg := []byte{
0x0A, 0x0C, 0x0B,
}
_, pub := deriveKeypair(sym)
c.Assert(DSAVerify(sig, pub, msg), Equals, false)
}
func (s *Ed448Suite) Test_DSAVerify_doesntVerifyACorrectSignature_withWrongMessage(c *C) {
sig := [114]byte{
0x7F, 0x26, 0xB2, 0x6D, 0x92, 0xB8, 0xCB, 0x20,
0xD7, 0xA5, 0x59, 0x2D, 0xFE, 0x13, 0xC0, 0x15,
0x77, 0x1D, 0xA2, 0xB3, 0x87, 0x14, 0x2F, 0x85,
0x0D, 0xE7, 0x1C, 0x55, 0x03, 0xDB, 0xD7, 0x9D,
0x02, 0x17, 0x8C, 0x25, 0x72, 0x85, 0x7C, 0x25,
0x36, 0xE2, 0x06, 0xDF, 0xCA, 0xC5, 0x4B, 0x5A,
0xA4, 0xC3, 0x61, 0xA3, 0xA2, 0x78, 0x4C, 0x97,
0x00, 0x40, 0x07, 0xE3, 0x01, 0x85, 0xE8, 0xFB,
0xBE, 0x4E, 0xE1, 0xD2, 0x02, 0x40, 0x14, 0x65,
0x7F, 0x13, 0x29, 0x88, 0xA7, 0x62, 0xDF, 0x17,
0x02, 0x4A, 0x86, 0x01, 0x6D, 0x51, 0x22, 0x50,
0x1C, 0x58, 0xC4, 0x39, 0x67, 0x41, 0xEE, 0x67,
0x87, 0x5C, 0xB4, 0x38, 0xFE, 0xED, 0x1F, 0x71,
0x26, 0xE3, 0x3C, 0x8B, 0x6E, 0x7A, 0x26, 0xD0,
0x1C, 0x00,
}
sym := [57]byte{
0x3f,
}
msg := []byte{
0x42, 0x0C, 0x0B,
}
_, pub := deriveKeypair(sym)
c.Assert(DSAVerify(sig, pub, msg), Equals, false)
}
func (s *Ed448Suite) Test_DSAVerify_doesntVerifyAnIncorrectSignature(c *C) {
sig := [114]byte{
0x42, 0x42, 0x42, 0x6D, 0x92, 0xB8, 0xCB, 0x20,
0x42, 0xA5, 0x59, 0x2D, 0xFE, 0x13, 0xC0, 0x15,
0x42, 0x1D, 0xA2, 0xB3, 0x87, 0x14, 0x2F, 0x85,
0x0D, 0xE7, 0x1C, 0x55, 0x03, 0xDB, 0xD7, 0x9D,
0x02, 0x17, 0x8C, 0x25, 0x72, 0x85, 0x7C, 0x25,
0x36, 0xE2, 0x06, 0xDF, 0xCA, 0xC5, 0x4B, 0x5A,
0xA4, 0xC3, 0x61, 0xA3, 0xA2, 0x78, 0x4C, 0x97,
0x00, 0x40, 0x07, 0xE3, 0x01, 0x85, 0xE8, 0xFB,
0xBE, 0x4E, 0xE1, 0xD2, 0x02, 0x40, 0x14, 0x65,
0x7F, 0x13, 0x29, 0x88, 0xA7, 0x62, 0xDF, 0x17,
0x02, 0x4A, 0x86, 0x01, 0x6D, 0x51, 0x22, 0x50,
0x1C, 0x58, 0xC4, 0x39, 0x67, 0x41, 0xEE, 0x67,
0x87, 0x5C, 0xB4, 0x38, 0xFE, 0xED, 0x1F, 0x71,
0x26, 0xE3, 0x3C, 0x8B, 0x6E, 0x7A, 0x26, 0xD0,
0x1C, 0x00,
}
sym := [57]byte{
0x3f,
}
msg := []byte{
0x0A, 0x0C, 0x0B,
}
_, pub := deriveKeypair(sym)
c.Assert(DSAVerify(sig, pub, msg), Equals, false)
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector1(c *C) {
_, pub := deriveKeypair(rfcTestVector1Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector1ExpectedPub[:])
sig := DSASign(rfcTestVector1Sym, pub, rfcTestVector1Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector1Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector2(c *C) {
_, pub := deriveKeypair(rfcTestVector2Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector2ExpectedPub[:])
sig := DSASign(rfcTestVector2Sym, pub, rfcTestVector2Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector2Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector4(c *C) {
_, pub := deriveKeypair(rfcTestVector4Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector4ExpectedPub[:])
sig := DSASign(rfcTestVector4Sym, pub, rfcTestVector4Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector4Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector5(c *C) {
_, pub := deriveKeypair(rfcTestVector5Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector5ExpectedPub[:])
sig := DSASign(rfcTestVector5Sym, pub, rfcTestVector5Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector5Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector6(c *C) {
_, pub := deriveKeypair(rfcTestVector6Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector6ExpectedPub[:])
sig := DSASign(rfcTestVector6Sym, pub, rfcTestVector6Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector6Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector7(c *C) {
_, pub := deriveKeypair(rfcTestVector7Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector7ExpectedPub[:])
sig := DSASign(rfcTestVector7Sym, pub, rfcTestVector7Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector7Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector8(c *C) {
_, pub := deriveKeypair(rfcTestVector8Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector8ExpectedPub[:])
sig := DSASign(rfcTestVector8Sym, pub, rfcTestVector8Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector8Sig[:])
}
func (s *Ed448Suite) Test_DSASign_rfcTestVector9(c *C) {
_, pub := deriveKeypair(rfcTestVector9Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector9ExpectedPub[:])
sig := DSASign(rfcTestVector9Sym, pub, rfcTestVector9Msg)
c.Assert(sig[:], DeepEquals, rfcTestVector9Sig[:])
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector1(c *C) {
_, pub := deriveKeypair(rfcTestVector1Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector1ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector1Sig, pub, rfcTestVector1Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector2(c *C) {
_, pub := deriveKeypair(rfcTestVector2Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector2ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector2Sig, pub, rfcTestVector2Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector4(c *C) {
_, pub := deriveKeypair(rfcTestVector4Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector4ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector4Sig, pub, rfcTestVector4Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector5(c *C) {
_, pub := deriveKeypair(rfcTestVector5Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector5ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector5Sig, pub, rfcTestVector5Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector6(c *C) {
_, pub := deriveKeypair(rfcTestVector6Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector6ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector6Sig, pub, rfcTestVector6Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector7(c *C) {
_, pub := deriveKeypair(rfcTestVector7Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector7ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector7Sig, pub, rfcTestVector7Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector8(c *C) {
_, pub := deriveKeypair(rfcTestVector8Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector8ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector8Sig, pub, rfcTestVector8Msg), Equals, true)
}
func (s *Ed448Suite) Test_DSAVerify_rfcTestVector9(c *C) {
_, pub := deriveKeypair(rfcTestVector9Sym)
c.Assert(pub.EdDSAEncode(), DeepEquals, rfcTestVector9ExpectedPub[:])
c.Assert(DSAVerify(rfcTestVector9Sig, pub, rfcTestVector9Msg), Equals, true)
}