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 Fq12 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/fq12.h"
25 #include "epid/member/tiny/math/mathtypes.h"
26 }
27
28 namespace {
29
30 ////////////////////////////////////////////////////////////////////////
31 // Fq12Add
32
TEST(TinyFq12Test,Fq12AddWorks)33 TEST(TinyFq12Test, Fq12AddWorks) {
34 Fq12Elem expected = {{{{0xf8898202, 0xb45883e0, 0x8d18168d, 0xf67a4288,
35 0xec7c2a8a, 0xfa6f0441, 0xff5583e2, 0x32d88286},
36 {0x304722d5, 0x113e09d3, 0xeaf32297, 0x32d71c16,
37 0x1cb0685b, 0xe3315524, 0xafd38377, 0xfeae3272}},
38 {{0xc82d8518, 0x99cec06c, 0xe8d7d62b, 0x2f00d5c5,
39 0x0620146e, 0x2741e62b, 0x9e7557ca, 0xeb019297},
40 {0x15cfc66e, 0x55ba87c0, 0xf1060150, 0xb91180f6,
41 0xb0d77f5f, 0xc7fa8733, 0x7dc697f1, 0x1e6b8e24}},
42 {{0x1400db26, 0x0760a0b1, 0x1a64565f, 0x27b5641e,
43 0xd96484ed, 0x54b02297, 0xa2a57172, 0xc3a04c1c},
44 {0x17ff87fb, 0x6294fcdb, 0x8f7c4bc2, 0xd0802fe6,
45 0xee3d7f1b, 0xf19d63af, 0xdb1d00ae, 0x80df53e6}}},
46 {{{0xc8c6cded, 0x0a290583, 0xd4ab7f8b, 0x867f6ac5,
47 0x791662bb, 0x893f1baa, 0xfc911068, 0xe97be9e3},
48 {0xdb9666f2, 0x1ff150ee, 0xd8691261, 0x5efee8a7,
49 0x0c67c4e5, 0x1501f7e4, 0xde7e72d8, 0x01ab1a71}},
50 {{0x85a5659c, 0xcfd4464f, 0xea3b0e64, 0x4a85994f,
51 0x0e842121, 0x939ca516, 0x55e1a4b6, 0xb92af8fa},
52 {0xb2bfc7eb, 0x71e5dd9d, 0x16b23032, 0x8590e174,
53 0x88a246af, 0x7d317c63, 0xc8f3a39a, 0x903a091d}},
54 {{0xf0df5efe, 0x5a88ee12, 0xb0d81569, 0x70172a9f,
55 0xa330fbf2, 0x36a7ea66, 0x95287dc2, 0x99c6386b},
56 {0x875888c7, 0xa3fa338b, 0x52d41dbe, 0x36960893,
57 0xfdf09874, 0x3986d2ba, 0xa9eb891e, 0x5cf05c6f}}}};
58 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
59 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
60 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
61 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
62 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
63 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
64 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
65 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
66 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
67 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
68 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
69 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
70 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
71 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
72 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
73 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
74 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
75 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
76 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
77 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
78 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
79 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
80 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
81 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
82 Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6,
83 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161},
84 {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966,
85 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}},
86 {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337,
87 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f},
88 {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a,
89 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}},
90 {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156,
91 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d},
92 {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086,
93 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}},
94 {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2,
95 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23},
96 {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5,
97 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}},
98 {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6,
99 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd},
100 {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c,
101 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}},
102 {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57,
103 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f},
104 {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff,
105 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}};
106 Fq12Elem actual = {0};
107 Fq12Add(&actual, &left, &right);
108 EXPECT_EQ(expected, actual);
109 }
110
111 ////////////////////////////////////////////////////////////////////////
112 // Fq12Sub
113
TEST(TinyFq12Test,Fq12SubWorks)114 TEST(TinyFq12Test, Fq12SubWorks) {
115 Fq12Elem expected = {{{{0x4d162b42, 0x9377da5b, 0x1d041212, 0xda2d8e91,
116 0x72d07c24, 0x9491de97, 0x005d123b, 0x89efdfc3},
117 {0x69ff7029, 0x1ffd54c7, 0x2a986659, 0x3830a949,
118 0x4d0a4447, 0x5440929c, 0x8c6aff8a, 0x169a8577}},
119 {{0x970c6506, 0x259580a0, 0x4547416c, 0xbc76db4c,
120 0xb4522362, 0xea130cd9, 0xc0e74ff6, 0xeeace017},
121 {0x97b9f013, 0xc4ec0fd2, 0x1dcfb36c, 0x97f1207d,
122 0x00b72659, 0x218e308a, 0xc0c7c429, 0x093f2175}},
123 {{0x318f88cb, 0x503725ee, 0x5c9a3d68, 0xba67a76b,
124 0xf1bd2bc6, 0x6413020d, 0xa06fe769, 0xecbd7182},
125 {0xa54e2ad8, 0xd2613407, 0x5c778439, 0x2bd154d5,
126 0x4e0d6476, 0xe6ae1ad3, 0x18b00add, 0xaf4062dc}}},
127 {{{0x895b6360, 0xbad96b00, 0xb6c8d2df, 0xe15e273b,
128 0x3aab5ff8, 0x40f55dd1, 0xc9e3101d, 0x6e83119c},
129 {0x85987e44, 0xb3e77da4, 0x4c55cf1c, 0xf44ba4d2,
130 0xd099adc5, 0x4a2563a4, 0x4668136c, 0x78fc1bd7}},
131 {{0xcc1109f3, 0xcd8e61ad, 0x3ce74606, 0x0da593de,
132 0x3185c168, 0xc6f603ce, 0x698abd6c, 0xf89d797f},
133 {0xc63c954e, 0x656d3e55, 0x5250e94d, 0x1aa544b5,
134 0xe0591afd, 0x1defc6e8, 0xb2ee48c2, 0x3735901f}},
135 {{0x743f55f2, 0xb78d7ece, 0x96a97857, 0x660dcdf0,
136 0x691d005b, 0x5b550556, 0xe3dd962e, 0x357fc1eb},
137 {0xb403019e, 0xd85f7340, 0xc1d63b46, 0xde3f288e,
138 0x8154cdf8, 0xaa09925b, 0xdfba6822, 0x1f99db4d}}}};
139 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
140 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
141 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
142 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
143 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
144 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
145 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
146 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
147 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
148 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
149 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
150 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
151 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
152 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
153 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
154 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
155 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
156 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
157 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
158 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
159 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
160 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
161 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
162 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
163 Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6,
164 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161},
165 {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966,
166 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}},
167 {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337,
168 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f},
169 {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a,
170 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}},
171 {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156,
172 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d},
173 {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086,
174 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}},
175 {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2,
176 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23},
177 {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5,
178 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}},
179 {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6,
180 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd},
181 {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c,
182 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}},
183 {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57,
184 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f},
185 {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff,
186 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}};
187 Fq12Elem actual = {0};
188 Fq12Sub(&actual, &left, &right);
189 EXPECT_EQ(expected, actual);
190 }
191
192 ////////////////////////////////////////////////////////////////////////
193 // Fq12Square
194
TEST(TinyFq12Test,Fq12SquareWorks)195 TEST(TinyFq12Test, Fq12SquareWorks) {
196 Fq12Elem expected = {{{{0xb2718e2f, 0x5acdc81c, 0x00964828, 0x20087676,
197 0x5ae15b61, 0x4fd4da11, 0xe092dfeb, 0x58534fb6},
198 {0xccc9dc07, 0x1004c642, 0x4d95229d, 0x82350b1c,
199 0x9771ce95, 0xd9a24ede, 0xbd10467b, 0xc7ed3445}},
200 {{0xbde22884, 0x8354762f, 0x86ba1554, 0x63db32bb,
201 0x0bae02fd, 0x6d0d96e8, 0xcf9ffd11, 0xb8fe4b31},
202 {0x2d04f196, 0x23e1a987, 0x99e976e3, 0xa037f309,
203 0xe90221d9, 0x201fec2a, 0x46d79de9, 0xc93a6bd2}},
204 {{0x5c58af07, 0xd9343489, 0xb4f19136, 0xff508b82,
205 0xc14265f4, 0xa4d22c7b, 0x6e928f38, 0xe279749e},
206 {0xa1d790b2, 0xcf37602c, 0xc842e733, 0x72c2773a,
207 0xc4d0ad50, 0x707594fb, 0x969b8864, 0x0979561b}}},
208 {{{0x24a687fb, 0xfb396e79, 0xc34718eb, 0x2b491ee6,
209 0xba812deb, 0xc6dfa2d8, 0x4c2bd958, 0x692fc435},
210 {0x0b3d5a09, 0xb3310b79, 0xcb0179fe, 0x8e8a4e82,
211 0x79cf9278, 0x1b884773, 0xe7bfdc35, 0xb64b17bf}},
212 {{0x7928c472, 0xbc2fe39f, 0xa4eff880, 0xd700813f,
213 0x555725f0, 0x43a4f63e, 0x857b8b39, 0x96614e14},
214 {0x0ba1d9bb, 0x78f7e930, 0x13c1d603, 0xe2f9587b,
215 0x19c67a04, 0x3931bdf3, 0x3c6271ae, 0xdde60cd5}},
216 {{0xa376e35d, 0xd157352f, 0x040e0af6, 0x0e36afd1,
217 0x9cfbfb84, 0x9cd3d83a, 0x94b83ec5, 0x1de41161},
218 {0xf1424d67, 0x5ecaee6f, 0x25a809b2, 0x00abd96d,
219 0x2b2da6c7, 0xbcfeab22, 0x6072fb3a, 0x75474592}}}};
220 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
221 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
222 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
223 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
224 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
225 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
226 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
227 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
228 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
229 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
230 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
231 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
232 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
233 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
234 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
235 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
236 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
237 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
238 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
239 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
240 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
241 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
242 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
243 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
244
245 Fq12Elem actual = {0};
246 Fq12Square(&actual, &left);
247 EXPECT_EQ(expected, actual);
248 }
249
250 ////////////////////////////////////////////////////////////////////////
251 // Fq12Mul
252
TEST(TinyFq12Test,Fq12MultWorks)253 TEST(TinyFq12Test, Fq12MultWorks) {
254 Fq12Elem expected = {{{{0x054b2248, 0x40490d13, 0xa309fba1, 0xcda4a1ef,
255 0xe6efd6b9, 0x6dbdd131, 0xfde112e9, 0xaf90b12e},
256 {0x4e21c944, 0x03e20ec3, 0xed4543f5, 0x7a577659,
257 0x81d1fd42, 0xea9a8c1c, 0x791b36af, 0x870740ff}},
258 {{0x8d2c2a6e, 0xe8ce5ca0, 0xe528c957, 0x84cd9406,
259 0x34a3c63a, 0x2b928ab5, 0x66655119, 0x91ff61ee},
260 {0x4c30c782, 0x4fd5522a, 0xfd8d17f1, 0xa3a6f430,
261 0x37bf9b7b, 0x72928155, 0x66037689, 0x4c8e67bc}},
262 {{0x35a5ce87, 0x1b25e22e, 0x2313705b, 0x9e3e6eb6,
263 0x8675e450, 0x33d9cdc4, 0x569c1b3e, 0xd9027fce},
264 {0x4f74f503, 0xecbc164d, 0x48ce7250, 0x32b9fb72,
265 0x8b726b18, 0xc0872542, 0xcb8d6a0b, 0xfecc8ed3}}},
266 {{{0x1a907f78, 0x04356cb2, 0x03360ad2, 0xba867ae8,
267 0xa1d5266f, 0xb5896fcf, 0x7013d8a3, 0x587b138f},
268 {0x30de9fe0, 0xacde6ad3, 0xdb1dcd3d, 0x765f2eac,
269 0x7f665d4e, 0xedc431a0, 0xd9057e43, 0x1bd63b89}},
270 {{0x16e913c4, 0xdc0a393e, 0xa9780dac, 0xa0e35293,
271 0x99e4eb2f, 0x80654405, 0x9a51d4b9, 0x890d2fa3},
272 {0x7a415a23, 0x7252917f, 0xb05a73ac, 0xe8a7f092,
273 0x9e68afd0, 0xfe5b63d2, 0x68ecfa20, 0xe3a9f4e0}},
274 {{0x3a77ca45, 0x282422b7, 0x613276da, 0x5bc45097,
275 0x95ea8ee4, 0x4a7a7633, 0xc9bb3324, 0xe396b7b4},
276 {0xf37c26a1, 0x8009faaa, 0x0779b7c1, 0x6ef10242,
277 0xcd5a86eb, 0x2dd2897e, 0x2b5f0b01, 0x0b79178d}}}};
278 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
279 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
280 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
281 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
282 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
283 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
284 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
285 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
286 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
287 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
288 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
289 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
290 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
291 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
292 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
293 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
294 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
295 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
296 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
297 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
298 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
299 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
300 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
301 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
302 Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6,
303 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161},
304 {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966,
305 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}},
306 {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337,
307 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f},
308 {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a,
309 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}},
310 {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156,
311 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d},
312 {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086,
313 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}},
314 {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2,
315 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23},
316 {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5,
317 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}},
318 {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6,
319 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd},
320 {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c,
321 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}},
322 {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57,
323 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f},
324 {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff,
325 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}};
326 Fq12Elem actual = {0};
327 Fq12Mul(&actual, &left, &right);
328 EXPECT_EQ(expected, actual);
329 }
330
331 ////////////////////////////////////////////////////////////////////////
332 // Fq12Inv
333
TEST(TinyFq12Test,Fq12InvWorks)334 TEST(TinyFq12Test, Fq12InvWorks) {
335 Fq12Elem expected = {{{{0xcf7ba426, 0x4bb2c4c3, 0xfb50fa73, 0xb70c280d,
336 0xb5cf02c7, 0xb047bc29, 0x7cd8b4d1, 0xc238e14d},
337 {0xd1bc45de, 0xc113277d, 0x5189b836, 0x49694d5b,
338 0xc4084edb, 0xc837f717, 0xf65566eb, 0x519dad22}},
339 {{0x62b12d6e, 0xc2a49558, 0x0f36f3b8, 0x2274fc44,
340 0xd7ef63a2, 0x7a0f59da, 0xc4fa06c3, 0x812be980},
341 {0xc887fc84, 0xbeb1803c, 0x5ec3d49f, 0x7c32ae46,
342 0x97fb66b2, 0x470acb13, 0x2e9d2992, 0x88dd93d5}},
343 {{0x47087924, 0x143c1bba, 0x4fe23ddb, 0x6be4e322,
344 0x3cabd640, 0xdf2f66c9, 0x2d309380, 0xa244260f},
345 {0xf899db8a, 0xb5a83982, 0x264e1961, 0xe8a8ce8c,
346 0xe94ceacf, 0xd18bd271, 0x67f10894, 0xc82e0f88}}},
347 {{{0x61170257, 0x9740a14e, 0xdd90ec1f, 0xfc1a7d8b,
348 0x2a37d62c, 0xa6577bc2, 0xe610b5d6, 0xe0b70389},
349 {0x8192b447, 0x2fd37cbc, 0xc3f80c5b, 0x618f95a1,
350 0x21e22c0c, 0xf35bd82b, 0xbf635e7d, 0x990ac1f2}},
351 {{0x790d6584, 0xf40c0f6e, 0x83ca3d0f, 0x96f7c28d,
352 0x8a2662fa, 0xc83bfe45, 0x8be01843, 0x87a00b86},
353 {0x6020320a, 0x73199db4, 0x4d5dd850, 0x14cf247d,
354 0x34fb1d44, 0x8ababc0d, 0x7c849de5, 0x81226e85}},
355 {{0x6453b966, 0xbbd595ea, 0x704c45e2, 0x5d4cd2a1,
356 0x8ee6cc5e, 0x336a21d8, 0x87955196, 0xc9e0915a},
357 {0x83330d6a, 0x200dbac0, 0x6b9e8ee8, 0xe6a33cf8,
358 0x4dc48908, 0xd0a02fdb, 0x0f715987, 0x5f4b9d5b}}}};
359 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
360 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
361 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
362 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
363 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
364 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
365 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
366 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
367 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
368 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
369 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
370 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
371 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
372 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
373 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
374 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
375 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
376 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
377 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
378 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
379 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
380 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
381 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
382 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
383 Fq12Elem actual = {0};
384 Fq12Inv(&actual, &left);
385 EXPECT_EQ(expected, actual);
386 }
387
388 ////////////////////////////////////////////////////////////////////////
389 // Fq12Neg
390
TEST(TinyFq12Test,Fq12NegWorks)391 TEST(TinyFq12Test, Fq12NegWorks) {
392 Fq12Elem expected = {{{{0x8c035971, 0xaf40febd, 0x3d89f632, 0x24887d6e,
393 0x3ecb5147, 0xff6580f2, 0x0023a5bd, 0xa19bcedb},
394 {0x61afe694, 0xba8b7e8e, 0x07d2460a, 0xd758834b,
395 0xb9944e4d, 0x2b2cfe7e, 0xe1ddaf4c, 0x755ba40a}},
396 {{0xff363b04, 0xf3770d54, 0xfb887eb6, 0x97208d71,
397 0x913888b6, 0xbe3b78dc, 0x504e9cec, 0x1328c6a8},
398 {0x80a4bcc9, 0xdc414b24, 0x81e12ae2, 0xddece243,
399 0x9e717f72, 0x2eae9d50, 0xe0b74a59, 0x6c2aa832}},
400 {{0xe3749624, 0x90f1e179, 0xe064c5e0, 0xa23c1333,
401 0x80199e94, 0x0df7593b, 0x5e70bcc6, 0xa7d12130},
402 {0x2795eeb3, 0x2242ac58, 0xa5ea27c6, 0x9521d69a,
403 0xc7850525, 0x7e332c4c, 0x8614e36d, 0xe7f0249e}}},
404 {{{0x5d2baf76, 0xda3c8c87, 0xd629e68e, 0x5f5bcff7,
405 0x8bc99594, 0x053eaed0, 0x9cc158f1, 0xd400823f},
406 {0xfe3bbd78, 0xe93cc691, 0x003899c3, 0x63371f3e,
407 0x7ff0eb49, 0x1752449a, 0x6d89adab, 0xc2ac64db}},
408 {{0xdd619055, 0x6e0c70ca, 0x8852e58e, 0xe7350261,
409 0x45a585a9, 0x3d0f971c, 0x20453822, 0xa71bc6c3},
410 {0x1aeb696d, 0x7deb08f4, 0xd4ca7881, 0x36531fe8,
411 0x42bb2179, 0x55e25789, 0x420d8238, 0x1c483361}},
412 {{0xfc43d59b, 0x4a1df76a, 0xeed743a2, 0x21c9e9b2,
413 0x684aa678, 0xfde77a80, 0x4379e6d4, 0x985d02d4},
414 {0xb9bbd2d7, 0xab67c387, 0x7ef6d8be, 0xfc039a6c,
415 0x37961f18, 0x31aac6a4, 0x3b2b7fc6, 0x41bae421}}}};
416 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
417 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
418 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
419 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
420 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
421 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
422 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
423 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
424 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
425 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
426 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
427 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
428 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
429 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
430 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
431 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
432 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
433 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
434 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
435 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
436 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
437 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
438 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
439 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
440 Fq12Elem actual = {0};
441 Fq12Neg(&actual, &left);
442 EXPECT_EQ(expected, actual);
443 }
444
445 ////////////////////////////////////////////////////////////////////////
446 // Fq12Set
447
TEST(TinyFq12Test,Fq12SetWorks)448 TEST(TinyFq12Test, Fq12SetWorks) {
449 Fq12Elem result = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
450 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
451 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
452 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
453 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
454 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
455 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
456 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
457 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
458 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
459 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
460 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
461 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
462 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
463 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
464 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
465 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
466 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
467 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
468 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
469 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
470 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
471 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
472 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
473 Fq12Elem expected = {{{{0x00000010, 0}, {0}}}};
474 uint32_t val = 0x10;
475 Fq12Set(&result, val);
476 EXPECT_EQ(expected, result);
477 }
478
479 ////////////////////////////////////////////////////////////////////////
480 // Fq12Exp
481
TEST(TinyFq12Test,Fq12ExpWorks)482 TEST(TinyFq12Test, Fq12ExpWorks) {
483 Fq12Elem expected = {{{{0x07770c93, 0x5820d5a9, 0x65189432, 0x5f5d67ff,
484 0xe257644a, 0x41318fa0, 0x6ab6be96, 0xf104adf8},
485 {0x6d5cae3a, 0x2e43c14b, 0xede9dbfe, 0x6743d276,
486 0x35d13a61, 0xf25d3672, 0x6a36930c, 0x9bdbed9d}},
487 {{0x12fc551f, 0x9ff0f349, 0x4131b828, 0x50c353ed,
488 0x785d7e8b, 0xbb894c96, 0xee86c2d1, 0x8af21330},
489 {0x45a7337a, 0xb0f0d8c5, 0xacfb0dbd, 0x1f775366,
490 0x12303719, 0x6f7208bd, 0x68c1bf17, 0x14b60ae7}},
491 {{0xcdf00f9c, 0xbd6529d8, 0x693b8a51, 0xcb9eb968,
492 0x46c25f48, 0x39cbf307, 0xd7283cd4, 0x8cbb7dd9},
493 {0xb18b24c2, 0x5a98714f, 0x0782ea19, 0x8af18c94,
494 0x22373570, 0xe24e7fef, 0x0510369a, 0xc5399438}}},
495 {{{0x141a7578, 0x05e94e05, 0x08ec385f, 0x3a5ae1ef,
496 0xccd4f61a, 0x3291d9f6, 0xb7b07242, 0xb1742404},
497 {0xec5f69b1, 0x68fbad6b, 0x167e8ec8, 0x67c97e56,
498 0x1ac21584, 0x783e2b30, 0x8c2dd9dd, 0xd4ed7488}},
499 {{0xb591926f, 0x97f68a1f, 0xd3bccfb8, 0x9a58152b,
500 0x9e12cf14, 0x0a82dfd6, 0x8c246e88, 0x94bcbc8a},
501 {0xa95962fe, 0x342b7e99, 0xddc1c0d9, 0x15a4e0f8,
502 0x64475d29, 0xbce1bd39, 0xa79dd2ee, 0xee505176}},
503 {{0xdb49f8cf, 0x10cdb302, 0xf5c48053, 0x83ce1f18,
504 0x988d4d5c, 0xd305fb4e, 0xbb11f2bb, 0x2f391894},
505 {0x084c02ad, 0x26eae084, 0x4d81e78d, 0x9750454d,
506 0xdb062196, 0xae6ad23e, 0x18588c31, 0xb3d78420}}}};
507 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
508 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
509 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
510 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
511 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
512 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
513 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
514 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
515 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
516 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
517 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
518 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
519 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
520 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
521 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
522 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
523 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
524 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
525 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
526 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
527 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
528 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
529 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
530 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
531 VeryLargeInt exponent = {0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1,
532 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6};
533 Fq12Elem actual = {0};
534 Fq12Exp(&actual, &left, &exponent);
535 EXPECT_EQ(expected, actual);
536 }
537
538 ////////////////////////////////////////////////////////////////////////
539 // Fq12MultiExp
540
TEST(TinyFq12Test,Fq12MultiExpWorks)541 TEST(TinyFq12Test, Fq12MultiExpWorks) {
542 Fq12Elem expected = {{{{0x9b800ac0, 0x1fb360b8, 0x9af601c4, 0x4931f447,
543 0x31152f7c, 0x7f6b2489, 0x2fbeed91, 0xcc7a6ac0},
544 {0xb76c0d77, 0x5b09b4be, 0x4a8fc1d4, 0x2e5222d1,
545 0x6b6e41e6, 0x9ea53fff, 0x6daabae4, 0x591274a2}},
546 {{0xb669c611, 0xc8b0430b, 0xa7c054c3, 0x360bd4bc,
547 0xf09ef81c, 0x4d5bb8b1, 0x9333c78f, 0x32ff73b8},
548 {0x90ec74e4, 0xe1e77b28, 0xb453b94a, 0xf7bf242c,
549 0xdbee7487, 0x29b8c962, 0x31bcb2b5, 0x06737ced}},
550 {{0x26f4def9, 0xc706336d, 0x18aae9bf, 0x9b568de1,
551 0x4e0fa721, 0x10695d37, 0x44a446e4, 0x1f90fc31},
552 {0xec9525dc, 0x4f63a5d6, 0x07e9f19c, 0x982ac0b8,
553 0x818c07fc, 0x2603a2c4, 0x44e6a144, 0xb8a617a5}}},
554 {{{0x34f08dcb, 0x0afd33cc, 0x38921139, 0x10c707ef,
555 0x1bcd1d79, 0x1cee939a, 0x08831471, 0x2318f2b4},
556 {0x8e4f9261, 0x37304a70, 0xb24df55d, 0xd93a8a20,
557 0x32ff13b2, 0x342ce4a7, 0x25185cd0, 0xd974dca3}},
558 {{0x0a83a8aa, 0xf2e71e4e, 0x0e0af78b, 0x85363dfa,
559 0xf825e945, 0x01d733f5, 0xf54d7f42, 0x3c77fa71},
560 {0xb5a7931b, 0x25c5c577, 0x6d21b52e, 0xbc951e9b,
561 0x51dd45b9, 0x743e886f, 0x6bc839d4, 0xd7deccd5}},
562 {{0x947af194, 0xd0239f95, 0x1dde9421, 0x59369d3e,
563 0xd9863881, 0xb9c24b75, 0xcbdb4021, 0x4c940810},
564 {0x96070307, 0x4f68fbf2, 0x5a719a10, 0x73b7cc22,
565 0x4ef192e7, 0xbb5b635e, 0xdeb5746b, 0x89b5a530}}}};
566 Fq12Elem pairing_out = {{{{0x50ab7bc6, 0xd28d33ca, 0xa7de4ce1, 0x162996ed,
567 0xad5ee231, 0x4fc0a501, 0x468be932, 0xba101ff6},
568 {0x14d36207, 0x34c44c84, 0xdfa22b9e, 0x1f4d1fc0,
569 0xcb0454f2, 0xc4077c42, 0xebde30b6, 0x15eb79f4}},
570 {{0xf91d7519, 0xc456caad, 0xb908d0d3, 0x31b0be8c,
571 0x1c0def81, 0x80e14649, 0x4657b6e7, 0xf18b84d1},
572 {0xec73b557, 0xf8acbc05, 0x2e5f0a7e, 0xf485e0eb,
573 0x6fd516b6, 0xb7190100, 0xc1fa4e50, 0x3fee7c43}},
574 {{0xb3ebe0e5, 0xc572866a, 0xa10be392, 0x2d6f653d,
575 0x138bb1b6, 0x87cf70ba, 0xbbef8650, 0xe3b31829},
576 {0x4ba31303, 0x8d1afe6e, 0xe7138780, 0x36a08173,
577 0xcdc3182a, 0x1ecb0486, 0xd5a961a5, 0xda0e5787}}},
578 {{{0x0b13b454, 0xa62f5fbf, 0xa4bed641, 0xd3632805,
579 0xe8010941, 0x72cebb51, 0x8aaa0095, 0x669e804d},
580 {0xe49b7149, 0x8fc69d31, 0x956d88ab, 0x265c926b,
581 0x3bb2f1d4, 0xbfc206ea, 0x6f29d6da, 0x5b5065dc}},
582 {{0x0ff0848e, 0x1f3fdf5c, 0xb3533098, 0x1a434003,
583 0xc80d2a60, 0x4ac6aa4a, 0xc99fbca8, 0xe0ce978f},
584 {0x3357d172, 0xf5f8a018, 0x5908b3da, 0xe540395c,
585 0xb654a226, 0x89cef58e, 0x47786d9f, 0x5a5d41d2}},
586 {{0x788a3989, 0x49a5f719, 0x5a0042e3, 0x92f94303,
587 0x1bd0e6c8, 0x81c5ac15, 0xe8a05ec8, 0xbbba6ced},
588 {0x6d17dc8e, 0xaf351b75, 0xba6e2c36, 0x2a04ea26,
589 0x421e1737, 0x16fd0bfe, 0x4bb33376, 0x32aebf4d}}}};
590 Fq12Elem pairing_inv = {{{{0x50ab7bc6, 0xd28d33ca, 0xa7de4ce1, 0x162996ed,
591 0xad5ee231, 0x4fc0a501, 0x468be932, 0xba101ff6},
592 {0x14d36207, 0x34c44c84, 0xdfa22b9e, 0x1f4d1fc0,
593 0xcb0454f2, 0xc4077c42, 0xebde30b6, 0x15eb79f4}},
594 {{0xf91d7519, 0xc456caad, 0xb908d0d3, 0x31b0be8c,
595 0x1c0def81, 0x80e14649, 0x4657b6e7, 0xf18b84d1},
596 {0xec73b557, 0xf8acbc05, 0x2e5f0a7e, 0xf485e0eb,
597 0x6fd516b6, 0xb7190100, 0xc1fa4e50, 0x3fee7c43}},
598 {{0xb3ebe0e5, 0xc572866a, 0xa10be392, 0x2d6f653d,
599 0x138bb1b6, 0x87cf70ba, 0xbbef8650, 0xe3b31829},
600 {0x4ba31303, 0x8d1afe6e, 0xe7138780, 0x36a08173,
601 0xcdc3182a, 0x1ecb0486, 0xd5a961a5, 0xda0e5787}}},
602 {{{0xa3bf7bbf, 0x2cf9ce1c, 0x6dd93441, 0x39793df5,
603 0x06709b5d, 0xd417370d, 0x7552f037, 0x99617fb2},
604 {0xca37beca, 0x436290a9, 0x7d2a81d7, 0xe67fd38f,
605 0xb2beb2ca, 0x8723eb74, 0x90d319f2, 0xa4af9a23}},
606 {{0x9ee2ab85, 0xb3e94e7f, 0x5f44d9ea, 0xf29925f7,
607 0x26647a3e, 0xfc1f4814, 0x365d3424, 0x1f316870},
608 {0x7b7b5ea1, 0xdd308dc3, 0xb98f56a7, 0x279c2c9e,
609 0x381d0278, 0xbd16fcd0, 0xb884832d, 0xa5a2be2d}},
610 {{0x3648f68a, 0x898336c2, 0xb897c79f, 0x79e322f7,
611 0xd2a0bdd6, 0xc5204649, 0x175c9204, 0x44459312},
612 {0x41bb5385, 0x23f41266, 0x5829de4c, 0xe2d77bd4,
613 0xac538d67, 0x2fe8e660, 0xb449bd57, 0xcd5140b2}}}};
614 VeryLargeInt exponent = {0x76abb18a, 0x92c0f7b9, 0x2c1a37e0, 0x7fdf6ca1,
615 0xe3401760, 0x66eb7d52, 0x918d50a7, 0x12a65bd6};
616 Fq12Elem b1 = pairing_inv;
617 Fq12Elem b2 = pairing_out;
618 Fq12Elem b3 = pairing_out;
619 VeryLargeInt e1 = exponent;
620 VeryLargeInt e2 = {0};
621 VeryLargeInt e3 = exponent;
622 // pairing_out^exp * pairing_out^(-exp) * pairing_out^0 * pairing_out^exp ==
623 // pairing_out^exp
624 Fq12Elem actual = {0};
625 Fq12MultiExp(&actual, &pairing_out, &exponent, &b1, &e1, &b2, &e2, &b3, &e3);
626 EXPECT_EQ(expected, actual);
627 }
628
629 ////////////////////////////////////////////////////////////////////////
630 // Fq12Eq
631
TEST(TinyFq12Test,Fq12EqPasses)632 TEST(TinyFq12Test, Fq12EqPasses) {
633 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
634 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
635 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
636 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
637 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
638 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
639 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
640 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
641 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
642 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
643 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
644 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
645 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
646 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
647 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
648 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
649 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
650 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
651 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
652 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
653 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
654 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
655 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
656 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
657 Fq12Elem left2 = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
658 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
659 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
660 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
661 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
662 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
663 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
664 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
665 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
666 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
667 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
668 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
669 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
670 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
671 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
672 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
673 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
674 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
675 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
676 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
677 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
678 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
679 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
680 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
681 EXPECT_TRUE(Fq12Eq(&left, &left2));
682 }
683
TEST(TinyFq12Test,Fq12EqFails)684 TEST(TinyFq12Test, Fq12EqFails) {
685 Fq12Elem left = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
686 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
687 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
688 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
689 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
690 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
691 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
692 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
693 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
694 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
695 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
696 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
697 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
698 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
699 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
700 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
701 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
702 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
703 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
704 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
705 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
706 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
707 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
708 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
709 Fq12Elem right = {{{{0x848cdb73, 0x6399829e, 0xcaa20cc0, 0x1b02bff6,
710 0x2b477bd2, 0xf9d48534, 0xff7929a0, 0xd4745161},
711 {0xe323d956, 0xf8a05a85, 0xe02d5e1e, 0xfd533966,
712 0xe7d31209, 0xc7786143, 0x91b441f6, 0x7409d67d}},
713 {{0xc763c01c, 0x8d45cdc1, 0xe46054e2, 0xc6216337,
714 0x97589d24, 0xe57d5f07, 0xeec3f4b6, 0xfe2a593f},
715 {0x96748337, 0x31fbd2e4, 0x72e72c33, 0x96fe633a,
716 0x4f48fed2, 0xf6a92484, 0x5e7de24a, 0x8a963657}},
717 {{0x48a24137, 0xc529544f, 0xe83111bc, 0xbd151156,
718 0x6b0c7ee2, 0x1bc18974, 0x01193d6b, 0x6b716d4d},
719 {0x90c2469b, 0xb1ae7b57, 0x22ce6905, 0x58c5a086,
720 0xc750dfa2, 0x28ea9d9d, 0x6134f34f, 0x68cf7885}}},
721 {{{0x771f4d50, 0x113c642f, 0x983d5b97, 0xd8fed4c2,
722 0x166e53b0, 0x4797d81c, 0x9955788c, 0xbd7c6c23},
723 {0xd9d2246a, 0x092e1780, 0xd8a1ac25, 0xc23607e5,
724 0x8c58b02e, 0x2c543c7e, 0x4c082083, 0xc4577f4d}},
725 {{0xb433c5de, 0x6ab7893e, 0x5ff5e970, 0x24de35b6,
726 0x65b8022c, 0x89c649d3, 0x7629ec0b, 0x6046bfbd},
727 {0xcdab3158, 0xefd0e691, 0xeb7ca8b3, 0xbbe4015c,
728 0xcb5d6828, 0xd313d3ec, 0x0b0125d2, 0xac823c7f}},
729 {{0x3e500486, 0xd17db7a2, 0x8d174e88, 0x8504ae57,
730 0x1d09fdcb, 0xeda97288, 0xd8a573c9, 0x32233b3f},
731 {0x41145b9e, 0x4f61f713, 0xd1caf67d, 0x3299a2ff,
732 0x3586b78d, 0x6b31995f, 0xe51708e4, 0x9eab4090}}}};
733 EXPECT_FALSE(Fq12Eq(&left, &right));
734 }
735
736 ////////////////////////////////////////////////////////////////////////
737 // Fq12Conj
738
TEST(TinyFq12Test,Fq12ConjWorks)739 TEST(TinyFq12Test, Fq12ConjWorks) {
740 Fq12Elem expected = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
741 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
742 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
743 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
744 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
745 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
746 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
747 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
748 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
749 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
750 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
751 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
752 {{{0x5d2baf76, 0xda3c8c87, 0xd629e68e, 0x5f5bcff7,
753 0x8bc99594, 0x053eaed0, 0x9cc158f1, 0xd400823f},
754 {0xfe3bbd78, 0xe93cc691, 0x003899c3, 0x63371f3e,
755 0x7ff0eb49, 0x1752449a, 0x6d89adab, 0xc2ac64db}},
756 {{0xdd619055, 0x6e0c70ca, 0x8852e58e, 0xe7350261,
757 0x45a585a9, 0x3d0f971c, 0x20453822, 0xa71bc6c3},
758 {0x1aeb696d, 0x7deb08f4, 0xd4ca7881, 0x36531fe8,
759 0x42bb2179, 0x55e25789, 0x420d8238, 0x1c483361}},
760 {{0xfc43d59b, 0x4a1df76a, 0xeed743a2, 0x21c9e9b2,
761 0x684aa678, 0xfde77a80, 0x4379e6d4, 0x985d02d4},
762 {0xb9bbd2d7, 0xab67c387, 0x7ef6d8be, 0xfc039a6c,
763 0x37961f18, 0x31aac6a4, 0x3b2b7fc6, 0x41bae421}}}};
764 Fq12Elem input = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c,
765 0xafa65357, 0x4780716c, 0xffd94b0f, 0x5e643124},
766 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0,
767 0x34dd5651, 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
768 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889,
769 0x5d391be8, 0x88aa7982, 0xafae53e0, 0xecd73957},
770 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7,
771 0x5000252c, 0x1837550e, 0x1f45a674, 0x93d557cd}},
772 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7,
773 0x6e58060a, 0x38ee9923, 0xa18c3407, 0x582edecf},
774 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60,
775 0x26ec9f79, 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
776 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603,
777 0x62a80f0a, 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
778 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd,
779 0x6e80b955, 0x2f93adc4, 0x92734322, 0x3d539b24}},
780 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399,
781 0xa8cc1ef5, 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
782 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612,
783 0xabb68325, 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
784 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48,
785 0x8626fe26, 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
786 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e,
787 0xb6db8586, 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
788 Fq12Elem actual = {0};
789 Fq12Conj(&actual, &input);
790 EXPECT_EQ(expected, actual);
791 }
792
793 ////////////////////////////////////////////////////////////////////////
794 // Fq12ExpCyc
795
TEST(TinyFq12Test,Fq12ExpCycWorks)796 TEST(TinyFq12Test, Fq12ExpCycWorks) {
797 Fq12Elem expected = {{{{0x44415742, 0xce586503, 0xe5cc514f, 0x731d97a3,
798 0xe8c98357, 0xb1de361d, 0x15cf9bfc, 0x4ca54124},
799 {0x7decae5a, 0x572ae946, 0x4244f518, 0x1490b9e4,
800 0xbbbafdb2, 0xb2d13f3f, 0xae1de024, 0xe224dc2f}},
801 {{0x876377f0, 0x2c75d3ab, 0x5aa65a1d, 0x42ff41fa,
802 0x2729ff86, 0x8f76d40f, 0x2c224666, 0xce3d5926},
803 {0x4f0b47eb, 0xa45887d9, 0xf4407be2, 0xaaedbf4a,
804 0x9f8a426e, 0x809a601a, 0xea000edd, 0x4fe97056}},
805 {{0x7eb3ea97, 0xd6769b11, 0x2f2bed07, 0x6fbb5801,
806 0x1e67136e, 0x2fd1e9a3, 0x242559de, 0x5a018155},
807 {0xb66ad800, 0x51924848, 0xdecddaa8, 0x3eed0649,
808 0xcf7f3edb, 0x17dcaa6e, 0x27cd41c7, 0x055a6039}}},
809 {{{0x09d45f4f, 0x3d360f00, 0x7561c4fb, 0x70500d0f,
810 0x20851a64, 0x5c5ed2a6, 0x6118fe9e, 0xfa05dc75},
811 {0x57b872d1, 0x9a19e54d, 0x3395e069, 0x29d98c64,
812 0xcdbdda55, 0x001f07e7, 0x8aeaca7f, 0x747c1dc8}},
813 {{0x0c0cb22d, 0x75ca59be, 0x202684e4, 0xec1b56c5,
814 0x46434c3f, 0x55f52f7a, 0xfcb5686b, 0x0a1172be},
815 {0xf0b043af, 0xbb2ae039, 0xccbdac3c, 0x8f42a6f2,
816 0x06c264ab, 0xa47599b7, 0xc6a8c454, 0xa5b257e3}},
817 {{0x8700f8b7, 0x4090b69d, 0x20e35539, 0xfd30e911,
818 0xa08ecbf5, 0xb038eb7b, 0x6ea872c3, 0xdfa0f669},
819 {0x5600be7b, 0x43ec3905, 0xc830ae6e, 0xd9780bec,
820 0xe7d288c3, 0xcff72a6e, 0x059b9c31, 0x66ebb803}}}};
821 Fq12Elem input = {{{{0x4200e30a, 0xebf627b9, 0x607ebce6, 0x7848a894,
822 0xe1b736d1, 0x4c9dd307, 0x9e1301e3, 0x07256eb7},
823 {0xe17a0b54, 0x0e02f2d5, 0x3df772e0, 0x9155aaa2,
824 0x3c5ffcc6, 0x8427940b, 0x362f51ee, 0x331e0c73}},
825 {{0x954eecdb, 0x970bc820, 0x92d1776a, 0x02f81e51,
826 0x8a7a9216, 0x6172111f, 0x9bd29665, 0x9612d47d},
827 {0x8fceb2c7, 0xb3f7eced, 0xa3d0a21e, 0xd66c6583,
828 0xf273f385, 0x827df9e6, 0x503de81c, 0x5b2cae32}},
829 {{0xf08207ed, 0x7ab76686, 0xb681b701, 0x9d19d066,
830 0x81956e08, 0x2ca17f37, 0x65d1d24e, 0x0cff7cb8},
831 {0xf9cd6e9e, 0x4821363b, 0xb0bc2b8c, 0xa380ecbb,
832 0x7b04aea0, 0x396f0948, 0x93619efe, 0x42aa1fd4}}},
833 {{{0x805b8aa4, 0x23ab6f9a, 0x937ea209, 0x9dba1ab2,
834 0x426d02b7, 0x36782ff4, 0xe371d373, 0x66873347},
835 {0x51d27dea, 0xd40cd434, 0xd5627a4d, 0xbcc747de,
836 0xa54b31ec, 0x3e2c2fa4, 0x4f07b689, 0xb33b79bc}},
837 {{0xfeea300c, 0x26ab30d9, 0x92c098e9, 0x192c191b,
838 0xeefd498c, 0x3cd4e4ac, 0xe9a3f142, 0x00bdca46},
839 {0xeb1edad0, 0xd4c2439e, 0x51025e46, 0x006cfb7c,
840 0x04b6efda, 0x159f7c19, 0xa1085a5e, 0x459833d5}},
841 {{0xeb08632d, 0x3c4ecf58, 0x02624178, 0xf65dbcf5,
842 0xeb320af5, 0xce34c3db, 0x799ea805, 0x1f944aa2},
843 {0x6f488ba6, 0x07f9f8dc, 0x690e6d4b, 0xa45b11be,
844 0x8d39f017, 0x96619fec, 0x6100af71, 0x16201c36}}}};
845 VeryLargeInt pairing_t = {0x30b0a801, 0x6882f5c0, 0x00000000, 0x00000000,
846 0x00000000, 0x00000000, 0x00000000, 0x00000000};
847 Fq12Elem actual = {0};
848 Fq12ExpCyc(&actual, &input, &pairing_t);
849 EXPECT_EQ(expected, actual);
850 }
851
852 ////////////////////////////////////////////////////////////////////////
853 // Fq12SqCyc
854
TEST(TinyFq12Test,Fq12SqCycWorks)855 TEST(TinyFq12Test, Fq12SqCycWorks) {
856 const Fq12Elem a = {{{{0x4200e30a, 0xebf627b9, 0x607ebce6, 0x7848a894,
857 0xe1b736d1, 0x4c9dd307, 0x9e1301e3, 0x07256eb7},
858 {0xe17a0b54, 0x0e02f2d5, 0x3df772e0, 0x9155aaa2,
859 0x3c5ffcc6, 0x8427940b, 0x362f51ee, 0x331e0c73}},
860 {{0x954eecdb, 0x970bc820, 0x92d1776a, 0x02f81e51,
861 0x8a7a9216, 0x6172111f, 0x9bd29665, 0x9612d47d},
862 {0x8fceb2c7, 0xb3f7eced, 0xa3d0a21e, 0xd66c6583,
863 0xf273f385, 0x827df9e6, 0x503de81c, 0x5b2cae32}},
864 {{0xf08207ed, 0x7ab76686, 0xb681b701, 0x9d19d066,
865 0x81956e08, 0x2ca17f37, 0x65d1d24e, 0x0cff7cb8},
866 {0xf9cd6e9e, 0x4821363b, 0xb0bc2b8c, 0xa380ecbb,
867 0x7b04aea0, 0x396f0948, 0x93619efe, 0x42aa1fd4}}},
868 {{{0x805b8aa4, 0x23ab6f9a, 0x937ea209, 0x9dba1ab2,
869 0x426d02b7, 0x36782ff4, 0xe371d373, 0x66873347},
870 {0x51d27dea, 0xd40cd434, 0xd5627a4d, 0xbcc747de,
871 0xa54b31ec, 0x3e2c2fa4, 0x4f07b689, 0xb33b79bc}},
872 {{0xfeea300c, 0x26ab30d9, 0x92c098e9, 0x192c191b,
873 0xeefd498c, 0x3cd4e4ac, 0xe9a3f142, 0x00bdca46},
874 {0xeb1edad0, 0xd4c2439e, 0x51025e46, 0x006cfb7c,
875 0x04b6efda, 0x159f7c19, 0xa1085a5e, 0x459833d5}},
876 {{0xeb08632d, 0x3c4ecf58, 0x02624178, 0xf65dbcf5,
877 0xeb320af5, 0xce34c3db, 0x799ea805, 0x1f944aa2},
878 {0x6f488ba6, 0x07f9f8dc, 0x690e6d4b, 0xa45b11be,
879 0x8d39f017, 0x96619fec, 0x6100af71, 0x16201c36}}}};
880 const Fq12Elem expected = {
881 {{{0x526a44b5, 0x9ad9e0d5, 0x7fc8d87d, 0xdac7f569, 0xb7160629, 0xc5073804,
882 0x217aac0c, 0x71b7efa7},
883 {0xd0accd40, 0x66aed48f, 0x3e8cb003, 0x54d56ad9, 0x5f6d6996, 0x0be42117,
884 0xa36948ed, 0xbb155b11}},
885 {{0x806eec23, 0xf4e66785, 0xaffdc175, 0xa19e8e95, 0xa11edc9d, 0xfad5f701,
886 0x4bf831bc, 0xe743b59e},
887 {0xfc57a415, 0xb843987c, 0x3aabe4e3, 0xb23ed43d, 0xc418a1cd, 0xc46cc003,
888 0xb646c6b0, 0x32af93c9}},
889 {{0x20c76439, 0xc9915b9f, 0x34fae4ad, 0x952c702a, 0xf2edbbd9, 0x06aa03db,
890 0x10219f83, 0x905d0b4c},
891 {0xab64286e, 0xb368606d, 0xa469d731, 0xbc1f7604, 0xeae89f06, 0xd6d6b335,
892 0x68da2258, 0x4ab0021e}}},
893 {{{0xa69a08d7, 0xbac72f6e, 0xaf9c76c7, 0x67d54f71, 0x41aea080, 0x36129b92,
894 0xd25549e1, 0xa261f5ef},
895 {0xd663885e, 0xd0de96b5, 0x6631c5ab, 0x1826eea2, 0xab116580, 0xc41e9bd7,
896 0x935a4539, 0x1283ccf4}},
897 {{0xc279b3a5, 0x750dcbe7, 0x8f96e4ba, 0xd3321942, 0xf837f073, 0x11ed32b8,
898 0x26691990, 0x06c077da},
899 {0x4d690c41, 0x47d447a7, 0xb0ecd6ca, 0xbab6e94b, 0xb1984cb4, 0xb104eb7f,
900 0xd0b8e924, 0xe8c70bef}},
901 {{0x1c750b7c, 0x9923d34c, 0xc88a0dda, 0x2e14c6ca, 0x6748bad3, 0x50d05e2b,
902 0x14f32504, 0x2dc7a9d3},
903 {0xa1c4328d, 0x9e8f16d8, 0xd31d739a, 0x0c9da028, 0x613f8c91, 0x75fbf7f3,
904 0x78575301, 0x496c9a7b}}}};
905 Fq12Elem res;
906 Fq12SqCyc(&res, &a);
907 EXPECT_EQ(expected, res);
908 }
909
910 ////////////////////////////////////////////////////////////////////////
911 // Fq12MulSpecial
912
TEST(TinyFq12Test,Fq12MulSpecialWorks)913 TEST(TinyFq12Test, Fq12MulSpecialWorks) {
914 const Fq12Elem left = {{{{0xbee28a1d, 0x57d6402c, 0x61cd0458, 0x194e2452,
915 0x1c223de9, 0x6546ced9, 0xdcd0878f, 0xc55048e3},
916 {0x6a8d5fe2, 0xfcf17083, 0xb608693b, 0x981bd9fe,
917 0x54a9e8fa, 0x0e8250f4, 0x93430f47, 0xf862d9af}},
918 {{0x57975e42, 0xf57416a0, 0x08a35031, 0x9d28f11c,
919 0xa9467df1, 0x58159cfa, 0x48cb43f1, 0x7f6f1e63},
920 {0xb6199d76, 0xf0ee74eb, 0xc2413051, 0x5ee7af00,
921 0xed646e81, 0xa34adbc8, 0xb30cb947, 0xc256758a}},
922 {{0xd2100f2c, 0x34bef28c, 0xe6ffd998, 0x3f8de361,
923 0x711229db, 0x143ccdbf, 0x4fad6107, 0x35365f92},
924 {0xea2fbf36, 0x14a160b2, 0x5051bd0f, 0x6f056434,
925 0x2d53ef9f, 0x00d84656, 0xc8535c97, 0x23aaa4e4}}},
926 {{{0xfa291b36, 0xdff94440, 0xc016a92d, 0xe44a0e69,
927 0xdb2d97f6, 0xb1747475, 0x1cbc7fc4, 0x0e94ef53},
928 {0x0ea6037c, 0x9a639210, 0xd84404c5, 0x4b8c16ef,
929 0xfc9e6161, 0x3914ae4c, 0xd1b76423, 0x63ef638b}},
930 {{0xfbe030a1, 0x2a114147, 0x6639fbac, 0x0349a4a5,
931 0x5c7d47de, 0x63888f75, 0x7224cc85, 0x4c1bfeb3},
932 {0xb214f453, 0x403afc2f, 0xa61d5e45, 0x4392c48a,
933 0xc4f5aec3, 0xce77b85a, 0xc8d59c7e, 0xd0060196}},
934 {{0x00000000, 0x00000000, 0x00000000, 0x00000000,
935 0x00000000, 0x00000000, 0x00000000, 0x00000000},
936 {0x00000000, 0x00000000, 0x00000000, 0x00000000,
937 0x00000000, 0x00000000, 0x00000000, 0x00000000}}}};
938 const Fq12Elem right = {{{{0xd878f624, 0xb6e07457, 0x64c79fdf, 0x0b8cebe9,
939 0x97be762b, 0xbc4aea64, 0xf72d75cc, 0xdc8ed85d},
940 {0x65847e3a, 0x2a2ff0f3, 0x87af7204, 0xfb4cba91,
941 0x0df3d736, 0x77e1a4e0, 0x138efcca, 0xc427f6ab}},
942 {{0x00000000, 0x00000000, 0x00000000, 0x00000000,
943 0x00000000, 0x00000000, 0x00000000, 0x00000000},
944 {0x00000000, 0x00000000, 0x00000000, 0x00000000,
945 0x00000000, 0x00000000, 0x00000000, 0x00000000}},
946 {{0x00000000, 0x00000000, 0x00000000, 0x00000000,
947 0x00000000, 0x00000000, 0x00000000, 0x00000000},
948 {0x00000000, 0x00000000, 0x00000000, 0x00000000,
949 0x00000000, 0x00000000, 0x00000000, 0x00000000}}},
950 {{{0x163784b5, 0x2a7d4fd5, 0x1f5a1a18, 0xe89cba68,
951 0xc233b435, 0xa20456c0, 0x6397ae08, 0x7b76d157},
952 {0xb68f8337, 0x079302c1, 0x99e4326a, 0xc14686de,
953 0x866e7108, 0x685e797e, 0x3a4b03e5, 0x9aab4042}},
954 {{0x2cd4fe4d, 0xb4660e9a, 0xf99f415d, 0x627f9703,
955 0x902301e4, 0xcf3c4224, 0xaca9779d, 0x917a2609},
956 {0x9da1e8ac, 0xadb15382, 0x6d31577a, 0xcfd95901,
957 0xf4fdf69b, 0x8ebf8ef3, 0xc15f4a65, 0x0d6458ec}},
958 {{0x00000000, 0x00000000, 0x00000000, 0x00000000,
959 0x00000000, 0x00000000, 0x00000000, 0x00000000},
960 {0x00000000, 0x00000000, 0x00000000, 0x00000000,
961 0x00000000, 0x00000000, 0x00000000, 0x00000000}}}};
962 const Fq12Elem expected = {
963 {{{0x9f8d4cd8, 0x00fcb121, 0xb1383622, 0xff83d7d7, 0xa4b229fb, 0xcece9321,
964 0x81ef1f73, 0x05137d4e},
965 {0x9f6177a7, 0x050a266e, 0x73bb8d3b, 0xc99e1d33, 0x678d1f52, 0xc63568f1,
966 0x1920273f, 0x11a25307}},
967 {{0xcf70c64d, 0x99892381, 0xf6f6a6de, 0xfec24fa5, 0x8d18873e, 0x4f621aad,
968 0x7d3599d0, 0x128407fe},
969 {0x33e6c086, 0xa85bf06c, 0x2edfd568, 0xc2426dbe, 0xdbbd397c, 0x2b6e80b2,
970 0x63dd5f45, 0x98bc904e}},
971 {{0xb56c9e77, 0x84063128, 0x830da180, 0xa3d9be01, 0x7ec1cfe7, 0x817c7cc1,
972 0x409da3aa, 0xb05dcc43},
973 {0x356380bf, 0x72eb335a, 0xb6f2b26c, 0x080613dc, 0x67720d78, 0x488a988f,
974 0xee0e1bff, 0x0758479e}}},
975 {{{0xa640a57d, 0xc171805c, 0xd1c81064, 0xef2644a8, 0xe28b6e89, 0xd031ff2f,
976 0xf734a21b, 0x0d8e465e},
977 {0x609de07b, 0x1d248226, 0x19fed7c8, 0x2b378e3d, 0xd55d1461, 0x719d0037,
978 0x6fe515b8, 0x34f03c08}},
979 {{0xdcdcb9d0, 0x814badfe, 0x01405a2a, 0x2e1a5295, 0x3d08cb46, 0xd0dc0d2b,
980 0x4ca64738, 0x2b2e5180},
981 {0x503385b0, 0x030d5f71, 0xd24ad48c, 0x4f246e0b, 0x9e904a36, 0x302748d6,
982 0x1c034d23, 0xf6aa74f6}},
983 {{0x05fc0305, 0xfb7ba8fd, 0x4a8425a1, 0xd69ff60a, 0x356d1941, 0x4559a790,
984 0xcf1088e9, 0x63784e99},
985 {0xa8a6d207, 0x6e6ed383, 0xf8a9804e, 0x0be13d11, 0xcef9010b, 0x90c8c91a,
986 0x0b1302ef, 0xe2ce5b67}}}};
987 Fq12Elem res;
988 Fq12MulSpecial(&res, &left, &right);
989 EXPECT_EQ(expected, res);
990 }
991
992 ////////////////////////////////////////////////////////////////////////
993 // Fq12Cp
994
TEST(TinyFq12Test,Fq12CpWorks)995 TEST(TinyFq12Test, Fq12CpWorks) {
996 Fq12Elem a = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357,
997 0x4780716c, 0xffd94b0f, 0x5e643124},
998 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651,
999 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
1000 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8,
1001 0x88aa7982, 0xafae53e0, 0xecd73957},
1002 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c,
1003 0x1837550e, 0x1f45a674, 0x93d557cd}},
1004 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a,
1005 0x38ee9923, 0xa18c3407, 0x582edecf},
1006 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79,
1007 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
1008 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, 0x62a80f0a,
1009 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
1010 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, 0x6e80b955,
1011 0x2f93adc4, 0x92734322, 0x3d539b24}},
1012 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, 0xa8cc1ef5,
1013 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
1014 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, 0xabb68325,
1015 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
1016 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, 0x8626fe26,
1017 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
1018 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, 0xb6db8586,
1019 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
1020 Fq12Elem result = {0};
1021 Fq12Cp(&result, &a);
1022 EXPECT_EQ(a, result);
1023 }
1024
1025 ////////////////////////////////////////////////////////////////////////
1026 // Fq12Clear
1027
TEST(TinyFq12Test,Fq12ClearWorks)1028 TEST(TinyFq12Test, Fq12ClearWorks) {
1029 Fq12Elem zero = {0};
1030 Fq12Elem a = {{{{0x22cfd6a2, 0x23e82f1e, 0xd50e1450, 0xe853e88c, 0xafa65357,
1031 0x4780716c, 0xffd94b0f, 0x5e643124},
1032 {0x4d23497f, 0x189daf4d, 0x0ac5c478, 0x3583e2b0, 0x34dd5651,
1033 0x1bb8f3e0, 0x1e1f4181, 0x8aa45bf5}},
1034 {{0xaf9cf50f, 0xdfb22086, 0x170f8bcb, 0x75bbd889, 0x5d391be8,
1035 0x88aa7982, 0xafae53e0, 0xecd73957},
1036 {0x2e2e734a, 0xf6e7e2b7, 0x90b6df9f, 0x2eef83b7, 0x5000252c,
1037 0x1837550e, 0x1f45a674, 0x93d557cd}},
1038 {{0xcb5e99ef, 0x42374c61, 0x323344a2, 0x6aa052c7, 0x6e58060a,
1039 0x38ee9923, 0xa18c3407, 0x582edecf},
1040 {0x873d4160, 0xb0e68183, 0x6cade2bc, 0x77ba8f60, 0x26ec9f79,
1041 0xc8b2c612, 0x79e80d5f, 0x180fdb61}}},
1042 {{{0x51a7809d, 0xf8eca154, 0x3c6e23f3, 0xad809603, 0x62a80f0a,
1043 0x41a7438e, 0x633b97dc, 0x2bff7dc0},
1044 {0xb097729b, 0xe9ec6749, 0x125f70be, 0xa9a546bd, 0x6e80b955,
1045 0x2f93adc4, 0x92734322, 0x3d539b24}},
1046 {{0xd1719fbe, 0x651cbd10, 0x8a4524f4, 0x25a76399, 0xa8cc1ef5,
1047 0x09d65b42, 0xdfb7b8ab, 0x58e4393c},
1048 {0x93e7c6a6, 0x553e24e7, 0x3dcd9201, 0xd6894612, 0xabb68325,
1049 0xf1039ad5, 0xbdef6e94, 0xe3b7cc9e}},
1050 {{0xb28f5a78, 0x890b3670, 0x23c0c6e0, 0xeb127c48, 0x8626fe26,
1051 0x48fe77de, 0xbc8309f8, 0x67a2fd2b},
1052 {0xf5175d3c, 0x27c16a53, 0x93a131c4, 0x10d8cb8e, 0xb6db8586,
1053 0x153b2bba, 0xc4d17107, 0xbe451bde}}}};
1054 Fq12Clear(&a);
1055 EXPECT_EQ(zero, a);
1056 }
1057
1058 } // namespace
1059