• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*############################################################################
2 # Copyright 2017 Intel Corporation
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #     http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 ############################################################################*/
16 /// Unit tests of EFq2 implementation.
17 /*! \file */
18 
19 #include <gtest/gtest.h>
20 
21 #include "epid/member/tiny/math/unittests/cmp-testhelper.h"
22 
23 extern "C" {
24 #include "epid/member/tiny/math/efq2.h"
25 #include "epid/member/tiny/math/mathtypes.h"
26 }
27 
28 namespace {
29 
30 ////////////////////////////////////////////////////////////////////////
31 // EFq2IsInf
32 
TEST(TinyEFq2Test,EFq2IsInfAcceptsPointAtInfinity)33 TEST(TinyEFq2Test, EFq2IsInfAcceptsPointAtInfinity) {
34   const EccPointJacobiFq2 infinity = {
35       {{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
36         0x00000000, 0x00000000},
37        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
38         0x00000000, 0x00000000}},
39       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
40         0x00000000, 0x00000000},
41        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
42         0x00000000, 0x00000000}},
43       {{0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
44         0x00000000, 0x00000000},
45        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
46         0x00000000, 0x00000000}}};
47   EXPECT_TRUE(EFq2IsInf(&infinity));
48 }
49 
TEST(TinyEFq2Test,EFq2IsInfRejectsPointNotAtInfinity)50 TEST(TinyEFq2Test, EFq2IsInfRejectsPointNotAtInfinity) {
51   const EccPointJacobiFq2 left = {
52       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
53         0x679b2a8a, 0x06f54dd4},
54        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
55         0x534cd776, 0x4759d7f6}},
56       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
57         0x47c18e76, 0xf769c987},
58        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
59         0x4631956d, 0x477f610f}},
60       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
61         0x00000000, 0x00000000},
62        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
63         0x00000000, 0x00000000}}};
64   EXPECT_FALSE(EFq2IsInf(&left));
65 }
66 
67 ////////////////////////////////////////////////////////////////////////
68 // EFq2FromAffine
69 
TEST(TinyEFq2Test,EFq2FromAffineWorks)70 TEST(TinyEFq2Test, EFq2FromAffineWorks) {
71   const EccPointJacobiFq2 expected = {
72       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
73         0x679b2a8a, 0x06f54dd4},
74        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
75         0x534cd776, 0x4759d7f6}},
76       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
77         0x47c18e76, 0xf769c987},
78        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
79         0x4631956d, 0x477f610f}},
80       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
81         0x00000000, 0x00000000},
82        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
83         0x00000000, 0x00000000}}};
84   const EccPointFq2 left_affine = {
85       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
86         0x679b2a8a, 0x06f54dd4},
87        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
88         0x534cd776, 0x4759d7f6}},
89       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
90         0x47c18e76, 0xf769c987},
91        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
92         0x4631956d, 0x477f610f}}};
93   EccPointJacobiFq2 actual = {0};
94   EFq2FromAffine(&actual, &left_affine);
95   EXPECT_EQ(expected, actual);
96 }
97 
98 ////////////////////////////////////////////////////////////////////////
99 // EFq2ToAffine
100 
TEST(TinyEFq2Test,EFq2ToAffineWorks)101 TEST(TinyEFq2Test, EFq2ToAffineWorks) {
102   const EccPointFq2 expected = {
103       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
104         0x679b2a8a, 0x06f54dd4},
105        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
106         0x534cd776, 0x4759d7f6}},
107       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
108         0x47c18e76, 0xf769c987},
109        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
110         0x4631956d, 0x477f610f}}};
111   const EccPointJacobiFq2 left = {
112       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
113         0x679b2a8a, 0x06f54dd4},
114        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
115         0x534cd776, 0x4759d7f6}},
116       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
117         0x47c18e76, 0xf769c987},
118        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
119         0x4631956d, 0x477f610f}},
120       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
121         0x00000000, 0x00000000},
122        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
123         0x00000000, 0x00000000}}};
124   EccPointFq2 actual = {0};
125   EFq2ToAffine(&actual, &left);
126   EXPECT_EQ(expected, actual);
127 }
128 
129 ////////////////////////////////////////////////////////////////////////
130 // EFq2Dbl
131 
TEST(TinyEFq2Test,EFq2DblWorks)132 TEST(TinyEFq2Test, EFq2DblWorks) {
133   const EccPointJacobiFq2 expected = {
134       {{0xca2899c2, 0x38294bdb, 0xcf0b6b44, 0x270787b1, 0x28e6e40a, 0x2b848c15,
135         0x03729665, 0xd042f637},
136        {0xda226e33, 0x9e951b73, 0x7df4afb1, 0x4b44fcd5, 0x133d08f1, 0x703ec2c1,
137         0x93fe9a4c, 0x014c1d38}},
138       {{0xbd697392, 0x2bed001e, 0xde312107, 0x1c7a00ac, 0xc1c7c40e, 0xd720bece,
139         0x6e98a67e, 0xaac006b6},
140        {0x43a25c32, 0x51296e80, 0x318d99a6, 0xd60e60d3, 0xdb3084d0, 0x0625d792,
141         0x25f4ca7e, 0x0a310fe4}},
142       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
143         0x00000000, 0x00000000},
144        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
145         0x00000000, 0x00000000}}};
146   const EccPointJacobiFq2 left = {
147       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
148         0x679b2a8a, 0x06f54dd4},
149        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
150         0x534cd776, 0x4759d7f6}},
151       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
152         0x47c18e76, 0xf769c987},
153        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
154         0x4631956d, 0x477f610f}},
155       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
156         0x00000000, 0x00000000},
157        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
158         0x00000000, 0x00000000}}};
159   EccPointJacobiFq2 actual = {0};
160   EFq2Dbl(&actual, &left);
161   EXPECT_EQ(expected, actual);
162 }
163 
164 ////////////////////////////////////////////////////////////////////////
165 // EFq2Add
166 
TEST(TinyEFq2Test,EFq2AddWorks)167 TEST(TinyEFq2Test, EFq2AddWorks) {
168   const EccPointJacobiFq2 expected = {
169       {{0x39d576f0, 0x314c3e0a, 0xdc7933c4, 0xb93a1af7, 0xa0b903f1, 0xd5648523,
170         0x4745740d, 0xcd182581},
171        {0x32365bad, 0x8351f42f, 0xd587f58a, 0x46b5c664, 0x11a71e4f, 0x8fde4189,
172         0xa0dbb9b6, 0x35a921cf}},
173       {{0xb1d07f87, 0x27fca861, 0xeb87751b, 0x40dee15b, 0x7abc2d89, 0xde6431b7,
174         0x23bcc963, 0x79a7d75a},
175        {0x5adc76e4, 0xb6a78fa4, 0xb4e50dbd, 0xd503cacd, 0xf188a97f, 0xc89769d8,
176         0xd3da3cb0, 0x4e50dbe9}},
177       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
178         0x00000000, 0x00000000},
179        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
180         0x00000000, 0x00000000}}};
181   const EccPointJacobiFq2 left = {
182       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
183         0x679b2a8a, 0x06f54dd4},
184        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
185         0x534cd776, 0x4759d7f6}},
186       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
187         0x47c18e76, 0xf769c987},
188        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
189         0x4631956d, 0x477f610f}},
190       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
191         0x00000000, 0x00000000},
192        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
193         0x00000000, 0x00000000}}};
194   const EccPointJacobiFq2 right = {
195       {{0x4103138f, 0xfa13e67e, 0x6837bfdf, 0x00565944, 0x11264453, 0x23f40661,
196         0x673da0e0, 0xed12700d},
197        {0x98f68547, 0x9cb87218, 0xc5ec70e5, 0x0c893388, 0x21dd4d22, 0x53386c5c,
198         0x2b310753, 0xeca20f0e}},
199       {{0x17a5237e, 0x3f8bfc68, 0xfd8f3ccc, 0xa630561a, 0xbf57703a, 0x68135f32,
200         0xe230d781, 0xd544af99},
201        {0x92ebeb94, 0x99b0cff6, 0xeebac3e7, 0x7d7aa73f, 0x7064674d, 0x25d8834a,
202         0x7c64ff8b, 0x97e6a2ac}},
203       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
204         0x00000000, 0x00000000},
205        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
206         0x00000000, 0x00000000}}};
207   EccPointJacobiFq2 actual = {0};
208   EFq2Add(&actual, &left, &right);
209   EXPECT_EQ(expected, actual);
210 }
211 
212 ////////////////////////////////////////////////////////////////////////
213 // EFq2Neg
214 
TEST(TinyEFq2Test,EFq2NegWorks)215 TEST(TinyEFq2Test, EFq2NegWorks) {
216   const EccPointJacobiFq2 expected = {
217       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
218         0x679b2a8a, 0x06f54dd4},
219        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
220         0x534cd776, 0x4759d7f6}},
221       {{0x876cdaca, 0x1d7a77aa, 0x730fb243, 0x1817c20a, 0x66f6a147, 0x7a82f2b1,
222         0xb83b6256, 0x08963678},
223        {0xd6e605ff, 0x3585805b, 0x9ecba21a, 0x921d0bd7, 0x033c1324, 0x8b6f68a7,
224         0xb9cb5b5f, 0xb8809ef0}},
225       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
226         0x00000000, 0x00000000},
227        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
228         0x00000000, 0x00000000}}};
229   const EccPointJacobiFq2 left = {
230       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
231         0x679b2a8a, 0x06f54dd4},
232        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
233         0x534cd776, 0x4759d7f6}},
234       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
235         0x47c18e76, 0xf769c987},
236        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
237         0x4631956d, 0x477f610f}},
238       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
239         0x00000000, 0x00000000},
240        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
241         0x00000000, 0x00000000}}};
242   EccPointJacobiFq2 actual = {0};
243   EFq2Neg(&actual, &left);
244   EXPECT_EQ(expected, actual);
245 }
246 
247 ////////////////////////////////////////////////////////////////////////
248 // EFq2MulSSCM
249 
TEST(TinyEFq2Test,EFq2MultSSCMWorks)250 TEST(TinyEFq2Test, EFq2MultSSCMWorks) {
251   const EccPointJacobiFq2 expected = {
252       {{0x75e057c7, 0x324aeb39, 0x0246ce8a, 0xe467356d, 0x4fcae21a, 0xeb58c86e,
253         0x12447362, 0x1c02af0c},
254        {0xfc9e5806, 0x790f79e8, 0xeffb940f, 0x44b942aa, 0xce364572, 0x8f1d0b6d,
255         0xf2238fe0, 0x4c281551}},
256       {{0x8e525052, 0x840bf78d, 0xf0a1e53a, 0xd43b1688, 0x1566bee6, 0x715cb6d2,
257         0x27f8a10c, 0x62806aa5},
258        {0xfe573502, 0x1b24a341, 0xffab4d71, 0x445e2e0c, 0x7f3aa342, 0x3013d966,
259         0x69b239fa, 0x074a471c}},
260       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
261         0x00000000, 0x00000000},
262        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
263         0x00000000, 0x00000000}}};
264   const EccPointJacobiFq2 left = {
265       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
266         0x679b2a8a, 0x06f54dd4},
267        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
268         0x534cd776, 0x4759d7f6}},
269       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
270         0x47c18e76, 0xf769c987},
271        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
272         0x4631956d, 0x477f610f}},
273       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
274         0x00000000, 0x00000000},
275        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
276         0x00000000, 0x00000000}}};
277   const FpElem power = {0xeb515e82, 0xda641a2f, 0x642e3fdc, 0x242d1caf,
278                         0xfd1cd76b, 0x60558750, 0x13fd607c, 0xd4a85a40};
279   EccPointJacobiFq2 actual = {0};
280   EFq2MulSSCM(&actual, &left, &power);
281   EXPECT_EQ(expected, actual);
282 }
283 
TEST(TinyEFq2Test,EFq2MultSSCMWorksInPlace)284 TEST(TinyEFq2Test, EFq2MultSSCMWorksInPlace) {
285   const EccPointJacobiFq2 expected = {
286       {{0x75e057c7, 0x324aeb39, 0x0246ce8a, 0xe467356d, 0x4fcae21a, 0xeb58c86e,
287         0x12447362, 0x1c02af0c},
288        {0xfc9e5806, 0x790f79e8, 0xeffb940f, 0x44b942aa, 0xce364572, 0x8f1d0b6d,
289         0xf2238fe0, 0x4c281551}},
290       {{0x8e525052, 0x840bf78d, 0xf0a1e53a, 0xd43b1688, 0x1566bee6, 0x715cb6d2,
291         0x27f8a10c, 0x62806aa5},
292        {0xfe573502, 0x1b24a341, 0xffab4d71, 0x445e2e0c, 0x7f3aa342, 0x3013d966,
293         0x69b239fa, 0x074a471c}},
294       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
295         0x00000000, 0x00000000},
296        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
297         0x00000000, 0x00000000}}};
298   EccPointJacobiFq2 left = {{{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790,
299                               0x5303da83, 0x693bbb16, 0x679b2a8a, 0x06f54dd4},
300                              {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c,
301                               0xa7b61e37, 0x209517cf, 0x534cd776, 0x4759d7f6}},
302                             {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0,
303                               0x877b0357, 0xcc62ffad, 0x47c18e76, 0xf769c987},
304                              {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23,
305                               0xeb35917a, 0xbb7689b7, 0x4631956d, 0x477f610f}},
306                             {{0x00000001, 0x00000000, 0x00000000, 0x00000000,
307                               0x00000000, 0x00000000, 0x00000000, 0x00000000},
308                              {0x00000000, 0x00000000, 0x00000000, 0x00000000,
309                               0x00000000, 0x00000000, 0x00000000, 0x00000000}}};
310   const FpElem power = {0xeb515e82, 0xda641a2f, 0x642e3fdc, 0x242d1caf,
311                         0xfd1cd76b, 0x60558750, 0x13fd607c, 0xd4a85a40};
312   EFq2MulSSCM(&left, &left, &power);
313   EXPECT_EQ(expected, left);
314 }
315 ////////////////////////////////////////////////////////////////////////
316 // EFq2Eq
317 
TEST(TinyEFq2Test,EFq2EqConfirmsPointsAreEqual)318 TEST(TinyEFq2Test, EFq2EqConfirmsPointsAreEqual) {
319   const EccPointJacobiFq2 left = {
320       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
321         0x679b2a8a, 0x06f54dd4},
322        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
323         0x534cd776, 0x4759d7f6}},
324       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
325         0x47c18e76, 0xf769c987},
326        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
327         0x4631956d, 0x477f610f}},
328       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
329         0x00000000, 0x00000000},
330        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
331         0x00000000, 0x00000000}}};
332   const EccPointJacobiFq2 left_2 = {
333       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
334         0x679b2a8a, 0x06f54dd4},
335        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
336         0x534cd776, 0x4759d7f6}},
337       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
338         0x47c18e76, 0xf769c987},
339        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
340         0x4631956d, 0x477f610f}},
341       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
342         0x00000000, 0x00000000},
343        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
344         0x00000000, 0x00000000}}};
345   EXPECT_TRUE(EFq2Eq(&left, &left_2));
346 }
347 
TEST(TinyEFq2Test,EFq2EqDeniesPointsAreEqual)348 TEST(TinyEFq2Test, EFq2EqDeniesPointsAreEqual) {
349   const EccPointJacobiFq2 left = {
350       {{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790, 0x5303da83, 0x693bbb16,
351         0x679b2a8a, 0x06f54dd4},
352        {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c, 0xa7b61e37, 0x209517cf,
353         0x534cd776, 0x4759d7f6}},
354       {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0, 0x877b0357, 0xcc62ffad,
355         0x47c18e76, 0xf769c987},
356        {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23, 0xeb35917a, 0xbb7689b7,
357         0x4631956d, 0x477f610f}},
358       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
359         0x00000000, 0x00000000},
360        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
361         0x00000000, 0x00000000}}};
362   const EccPointJacobiFq2 right = {
363       {{0x4103138f, 0xfa13e67e, 0x6837bfdf, 0x00565944, 0x11264453, 0x23f40661,
364         0x673da0e0, 0xed12700d},
365        {0x98f68547, 0x9cb87218, 0xc5ec70e5, 0x0c893388, 0x21dd4d22, 0x53386c5c,
366         0x2b310753, 0xeca20f0e}},
367       {{0x17a5237e, 0x3f8bfc68, 0xfd8f3ccc, 0xa630561a, 0xbf57703a, 0x68135f32,
368         0xe230d781, 0xd544af99},
369        {0x92ebeb94, 0x99b0cff6, 0xeebac3e7, 0x7d7aa73f, 0x7064674d, 0x25d8834a,
370         0x7c64ff8b, 0x97e6a2ac}},
371       {{0x00000001, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
372         0x00000000, 0x00000000},
373        {0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000,
374         0x00000000, 0x00000000}}};
375   EXPECT_FALSE(EFq2Eq(&left, &right));
376 }
377 
378 ////////////////////////////////////////////////////////////////////////
379 // EFq2OnCurve
380 
TEST(TinyEFq2Test,EFq2OnCurveConfirmsPointOnCurve)381 TEST(TinyEFq2Test, EFq2OnCurveConfirmsPointOnCurve) {
382   const EccPointFq2 left = {{{0xbf501131, 0x84025734, 0xe72a81d4, 0x0a3da790,
383                               0x5303da83, 0x693bbb16, 0x679b2a8a, 0x06f54dd4},
384                              {0xa15aebed, 0x5eabe073, 0x5585c8aa, 0xc27f168c,
385                               0xa7b61e37, 0x209517cf, 0x534cd776, 0x4759d7f6}},
386                             {{0x27665549, 0xb5aeb631, 0x9f88583f, 0xf4c4a3f0,
387                               0x877b0357, 0xcc62ffad, 0x47c18e76, 0xf769c987},
388                              {0xd7ed2a14, 0x9da3ad7f, 0x73cc6868, 0x7abf5a23,
389                               0xeb35917a, 0xbb7689b7, 0x4631956d, 0x477f610f}}};
390   EXPECT_TRUE(EFq2OnCurve(&left));
391 }
392 
TEST(TinyEFq2Test,EFq2OnCurveRejectsPointOffCurve)393 TEST(TinyEFq2Test, EFq2OnCurveRejectsPointOffCurve) {
394   const EccPointFq2 invalid = {
395       {{0x705eb0a4, 0xf30863e3, 0x6127e751, 0x15adee42, 0xb00baac0, 0x194dee74,
396         0xb39bf2f3, 0x88b75019},
397        {0x60d7ec1d, 0xd80f96dd, 0x731c01d7, 0xbf697161, 0x087e5f87, 0x91f4fe08,
398         0xd1942d15, 0x62b03177}},
399       {{0x38f6d02a, 0xae5274db, 0xb7eddcf3, 0xcf4ff611, 0x589140a6, 0xcbacb49c,
400         0x48c50543, 0x1da802e9},
401        {0x45b0c6f3, 0x52393bf1, 0xc70746b0, 0xa08caeba, 0x5cb44254, 0x53ebeb2a,
402         0x620ea440, 0x2c3a40f1}}};
403   EXPECT_FALSE(EFq2OnCurve(&invalid));
404 }
405 
406 }  // namespace
407