1
- package decaf_test
1
+ package decaf448_test
2
2
3
3
import (
4
4
"bytes"
9
9
"os"
10
10
"testing"
11
11
12
- "github.com/cloudflare/circl/ecc/decaf "
12
+ "github.com/cloudflare/circl/group/decaf448 "
13
13
"github.com/cloudflare/circl/internal/test"
14
14
fp "github.com/cloudflare/circl/math/fp448"
15
15
)
@@ -44,8 +44,8 @@ func (kat *testJSONFile) readFile(t *testing.T, fileName string) {
44
44
}
45
45
}
46
46
47
- func verify (t * testing.T , i int , gotkG * decaf .Elt , wantEnckG []byte ) {
48
- wantkG := & decaf .Elt {}
47
+ func verify (t * testing.T , i int , gotkG * decaf448 .Elt , wantEnckG []byte ) {
48
+ wantkG := & decaf448 .Elt {}
49
49
50
50
gotEnckG , err := gotkG .MarshalBinary ()
51
51
got := err == nil && bytes .Equal (gotEnckG , wantEnckG )
@@ -56,8 +56,8 @@ func verify(t *testing.T, i int, gotkG *decaf.Elt, wantEnckG []byte) {
56
56
57
57
err = wantkG .UnmarshalBinary (wantEnckG )
58
58
got = err == nil &&
59
- decaf .IsValid (gotkG ) &&
60
- decaf .IsValid (wantkG ) &&
59
+ decaf448 .IsValid (gotkG ) &&
60
+ decaf448 .IsValid (wantkG ) &&
61
61
gotkG .IsEqual (wantkG )
62
62
want = true
63
63
if got != want {
@@ -76,34 +76,34 @@ func TestDecafv1_0(t *testing.T) {
76
76
test .ReportError (t , got , want )
77
77
}
78
78
got = kat .Version
79
- want = decaf .Version
79
+ want = decaf448 .Version
80
80
if got != want {
81
81
test .ReportError (t , got , want )
82
82
}
83
- var scalar decaf .Scalar
84
- var P decaf .Elt
85
- G := decaf .Generator ()
83
+ var scalar decaf448 .Scalar
84
+ var P decaf448 .Elt
85
+ G := decaf448 .Generator ()
86
86
for i := range kat .Vectors {
87
87
k , _ := hex .DecodeString (kat .Vectors [i ].K )
88
88
wantEnckG , _ := hex .DecodeString (kat .Vectors [i ].KG )
89
89
wantEnckP , _ := hex .DecodeString (kat .Vectors [i ].KP )
90
90
scalar .FromBytes (k )
91
91
92
- decaf .MulGen (& P , & scalar )
92
+ decaf448 .MulGen (& P , & scalar )
93
93
verify (t , i , & P , wantEnckG )
94
94
95
- decaf .Mul (& P , & scalar , G )
95
+ decaf448 .Mul (& P , & scalar , G )
96
96
verify (t , i , & P , wantEnckG )
97
97
98
- decaf .Mul (& P , & scalar , & P )
98
+ decaf448 .Mul (& P , & scalar , & P )
99
99
verify (t , i , & P , wantEnckP )
100
100
}
101
101
}
102
102
103
103
func TestDecafRandom (t * testing.T ) {
104
104
const testTimes = 1 << 10
105
- var e decaf .Elt
106
- var enc [decaf .EncodingSize ]byte
105
+ var e decaf448 .Elt
106
+ var enc [decaf448 .EncodingSize ]byte
107
107
108
108
for i := 0 ; i < testTimes ; i ++ {
109
109
for found := false ; ! found ; {
@@ -119,44 +119,44 @@ func TestDecafRandom(t *testing.T) {
119
119
}
120
120
}
121
121
122
- func randomPoint () decaf .Elt {
123
- var k decaf .Scalar
122
+ func randomPoint () decaf448 .Elt {
123
+ var k decaf448 .Scalar
124
124
_ , _ = rand .Read (k [:])
125
- var P decaf .Elt
126
- decaf .MulGen (& P , & k )
125
+ var P decaf448 .Elt
126
+ decaf448 .MulGen (& P , & k )
127
127
return P
128
128
}
129
129
130
130
func TestPointAdd (t * testing.T ) {
131
131
const testTimes = 1 << 10
132
- Q := & decaf .Elt {}
132
+ Q := & decaf448 .Elt {}
133
133
for i := 0 ; i < testTimes ; i ++ {
134
134
P := randomPoint ()
135
135
// Q = 16P = 2^4P
136
- decaf .Double (Q , & P ) // 2P
137
- decaf .Double (Q , Q ) // 4P
138
- decaf .Double (Q , Q ) // 8P
139
- decaf .Double (Q , Q ) // 16P
136
+ decaf448 .Double (Q , & P ) // 2P
137
+ decaf448 .Double (Q , Q ) // 4P
138
+ decaf448 .Double (Q , Q ) // 8P
139
+ decaf448 .Double (Q , Q ) // 16P
140
140
got := Q
141
141
// R = 16P = P+P...+P
142
- R := decaf .Identity ()
142
+ R := decaf448 .Identity ()
143
143
for j := 0 ; j < 16 ; j ++ {
144
- decaf .Add (R , R , & P )
144
+ decaf448 .Add (R , R , & P )
145
145
}
146
146
want := R
147
- if ! decaf .IsValid (got ) || ! decaf .IsValid (want ) || ! got .IsEqual (want ) {
147
+ if ! decaf448 .IsValid (got ) || ! decaf448 .IsValid (want ) || ! got .IsEqual (want ) {
148
148
test .ReportError (t , got , want , P )
149
149
}
150
150
}
151
151
}
152
152
153
153
func TestPointNeg (t * testing.T ) {
154
154
const testTimes = 1 << 10
155
- Q := & decaf .Elt {}
155
+ Q := & decaf448 .Elt {}
156
156
for i := 0 ; i < testTimes ; i ++ {
157
157
P := randomPoint ()
158
- decaf .Neg (Q , & P )
159
- decaf .Add (Q , Q , & P )
158
+ decaf448 .Neg (Q , & P )
159
+ decaf448 .Add (Q , Q , & P )
160
160
got := Q .IsIdentity ()
161
161
want := true
162
162
if got != want {
@@ -167,12 +167,12 @@ func TestPointNeg(t *testing.T) {
167
167
168
168
func TestDecafOrder (t * testing.T ) {
169
169
const testTimes = 1 << 10
170
- Q := & decaf .Elt {}
171
- order := decaf .Order ()
170
+ Q := & decaf448 .Elt {}
171
+ order := decaf448 .Order ()
172
172
for i := 0 ; i < testTimes ; i ++ {
173
173
P := randomPoint ()
174
174
175
- decaf .Mul (Q , & order , & P )
175
+ decaf448 .Mul (Q , & order , & P )
176
176
got := Q .IsIdentity ()
177
177
want := true
178
178
if got != want {
@@ -193,37 +193,65 @@ func TestDecafInvalid(t *testing.T) {
193
193
nonQR [:], // s=4 and (a^2s^4 + (2a - 4d)*s^2 + 1) is non-QR.
194
194
}
195
195
196
- var e decaf .Elt
196
+ var e decaf448 .Elt
197
197
for _ , enc := range badEncodings {
198
198
got := e .UnmarshalBinary (enc )
199
- want := decaf .ErrInvalidDecoding
199
+ want := decaf448 .ErrInvalidDecoding
200
200
if got != want {
201
201
test .ReportError (t , got , want , enc )
202
202
}
203
203
}
204
204
}
205
205
206
206
func BenchmarkDecaf (b * testing.B ) {
207
- var k , l decaf .Scalar
207
+ var k , l decaf448 .Scalar
208
208
_ , _ = rand .Read (k [:])
209
209
_ , _ = rand .Read (l [:])
210
- G := decaf .Generator ()
211
- P := decaf .Generator ()
210
+ G := decaf448 .Generator ()
211
+ P := decaf448 .Generator ()
212
+ Z := decaf448 .Identity ()
212
213
enc , _ := G .MarshalBinary ()
213
214
215
+ x := & fp.Elt {}
216
+ y := & fp.Elt {}
217
+ _ , _ = rand .Read (y [:])
218
+ // p := fp.P()
219
+ // one := fp.One()
220
+ // fp.Sub(y, &p, &one)
221
+
214
222
b .Run ("Add" , func (b * testing.B ) {
215
223
for i := 0 ; i < b .N ; i ++ {
216
- decaf .Add (P , P , G )
224
+ decaf448 .Add (P , P , G )
225
+ }
226
+ })
227
+ b .Run ("IsZeroSub0" , func (b * testing.B ) {
228
+ for i := 0 ; i < b .N ; i ++ {
229
+ fp .IsZero (x )
230
+ }
231
+ })
232
+ b .Run ("IsZeroSub1" , func (b * testing.B ) {
233
+ for i := 0 ; i < b .N ; i ++ {
234
+ fp .IsZero (y )
235
+ }
236
+ })
237
+ b .Run ("IsZeroSi" , func (b * testing.B ) {
238
+ for i := 0 ; i < b .N ; i ++ {
239
+ _ = Z .IsIdentity ()
240
+ }
241
+ })
242
+ b .Run ("IsZero" , func (b * testing.B ) {
243
+ for i := 0 ; i < b .N ; i ++ {
244
+ _ = P .IsIdentity ()
217
245
}
218
246
})
219
247
b .Run ("Mul" , func (b * testing.B ) {
220
248
for i := 0 ; i < b .N ; i ++ {
221
- decaf .Mul (G , & k , G )
249
+ decaf448 .Mul (G , & k , G )
222
250
}
223
251
})
224
252
b .Run ("MulGen" , func (b * testing.B ) {
225
253
for i := 0 ; i < b .N ; i ++ {
226
- decaf .MulGen (P , & k )
254
+ decaf448 .MulGen (P , & k )
227
255
}
228
256
})
229
257
b .Run ("Marshal" , func (b * testing.B ) {
0 commit comments