efq2-test.cc 19 KB

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