You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

590 lines
19 KiB

  1. /**
  2. * @file test_decaf.cxx
  3. * @author Mike Hamburg
  4. *
  5. * @copyright
  6. * Copyright (c) 2015 Cryptography Research, Inc. \n
  7. * Released under the MIT License. See LICENSE.txt for license information.
  8. *
  9. * @brief C++ tests, because that's easier.
  10. */
  11. #include <decaf.hxx>
  12. #include <decaf/spongerng.hxx>
  13. #include <decaf/crypto.h>
  14. #include <decaf/crypto.hxx>
  15. #include <stdio.h>
  16. using namespace decaf;
  17. static bool passing = true;
  18. static const long NTESTS = 10000;
  19. class Test {
  20. public:
  21. bool passing_now;
  22. Test(const char *test) {
  23. passing_now = true;
  24. printf("%s...", test);
  25. if (strlen(test) < 27) printf("%*s",int(27-strlen(test)),"");
  26. fflush(stdout);
  27. }
  28. ~Test() {
  29. if (std::uncaught_exception()) {
  30. fail();
  31. printf(" due to uncaught exception.\n");
  32. }
  33. if (passing_now) printf("[PASS]\n");
  34. }
  35. void fail() {
  36. if (!passing_now) return;
  37. passing_now = passing = false;
  38. printf("[FAIL]\n");
  39. }
  40. };
  41. static uint64_t leint(const SecureBuffer &xx) {
  42. uint64_t out = 0;
  43. for (unsigned int i=0; i<xx.size() && i<sizeof(out); i++) {
  44. out |= uint64_t(xx[i]) << (8*i);
  45. }
  46. return out;
  47. }
  48. template<typename Group> struct Tests {
  49. typedef typename Group::Scalar Scalar;
  50. typedef typename Group::Point Point;
  51. typedef typename Group::DhLadder DhLadder;
  52. typedef typename Group::Precomputed Precomputed;
  53. static void print(const char *name, const Scalar &x) {
  54. unsigned char buffer[Scalar::SER_BYTES];
  55. x.serialize_into(buffer);
  56. printf(" %s = 0x", name);
  57. for (int i=sizeof(buffer)-1; i>=0; i--) {
  58. printf("%02x", buffer[i]);
  59. }
  60. printf("\n");
  61. }
  62. static void hexprint(const char *name, const SecureBuffer &buffer) {
  63. printf(" %s = 0x", name);
  64. for (int i=buffer.size()-1; i>=0; i--) {
  65. printf("%02x", buffer[i]);
  66. }
  67. printf("\n");
  68. }
  69. static void print(const char *name, const Point &x) {
  70. unsigned char buffer[Point::SER_BYTES];
  71. x.serialize_into(buffer);
  72. printf(" %s = 0x", name);
  73. for (int i=Point::SER_BYTES-1; i>=0; i--) {
  74. printf("%02x", buffer[i]);
  75. }
  76. printf("\n");
  77. }
  78. static bool arith_check(
  79. Test &test,
  80. const Scalar &x,
  81. const Scalar &y,
  82. const Scalar &z,
  83. const Scalar &l,
  84. const Scalar &r,
  85. const char *name
  86. ) {
  87. if (l == r) return true;
  88. test.fail();
  89. printf(" %s", name);
  90. print("x", x);
  91. print("y", y);
  92. print("z", z);
  93. print("lhs", l);
  94. print("rhs", r);
  95. return false;
  96. }
  97. static bool point_check(
  98. Test &test,
  99. const Point &p,
  100. const Point &q,
  101. const Point &R,
  102. const Scalar &x,
  103. const Scalar &y,
  104. const Point &l,
  105. const Point &r,
  106. const char *name
  107. ) {
  108. bool good = l==r;
  109. if (!p.validate()) { good = false; printf(" p invalid\n"); }
  110. if (!q.validate()) { good = false; printf(" q invalid\n"); }
  111. if (!r.validate()) { good = false; printf(" r invalid\n"); }
  112. if (!l.validate()) { good = false; printf(" l invalid\n"); }
  113. if (good) return true;
  114. test.fail();
  115. printf(" %s", name);
  116. print("x", x);
  117. print("y", y);
  118. print("p", p);
  119. print("q", q);
  120. print("r", R);
  121. print("lhs", r);
  122. print("rhs", l);
  123. return false;
  124. }
  125. static void test_arithmetic() {
  126. SpongeRng rng(Block("test_arithmetic"),SpongeRng::DETERMINISTIC);
  127. Test test("Arithmetic");
  128. Scalar x(0),y(0),z(0);
  129. arith_check(test,x,y,z,INT_MAX,(decaf_word_t)INT_MAX,"cast from max");
  130. arith_check(test,x,y,z,INT_MIN,-Scalar(1+(decaf_word_t)INT_MAX),"cast from min");
  131. for (int i=0; i<NTESTS*10 && test.passing_now; i++) {
  132. size_t sob = i % (2*Group::Scalar::SER_BYTES);
  133. SecureBuffer xx = rng.read(sob), yy = rng.read(sob), zz = rng.read(sob);
  134. Scalar x(xx);
  135. Scalar y(yy);
  136. Scalar z(zz);
  137. arith_check(test,x,y,z,x+y,y+x,"commute add");
  138. arith_check(test,x,y,z,x,x+0,"ident add");
  139. arith_check(test,x,y,z,x,x-0,"ident sub");
  140. arith_check(test,x,y,z,x+-x,0,"inverse add");
  141. arith_check(test,x,y,z,x-x,0,"inverse sub");
  142. arith_check(test,x,y,z,x-(x+1),-1,"inverse add2");
  143. arith_check(test,x,y,z,x+(y+z),(x+y)+z,"assoc add");
  144. arith_check(test,x,y,z,x*(y+z),x*y + x*z,"distributive mul/add");
  145. arith_check(test,x,y,z,x*(y-z),x*y - x*z,"distributive mul/add");
  146. arith_check(test,x,y,z,x*(y*z),(x*y)*z,"assoc mul");
  147. arith_check(test,x,y,z,x*y,y*x,"commute mul");
  148. arith_check(test,x,y,z,x,x*1,"ident mul");
  149. arith_check(test,x,y,z,0,x*0,"mul by 0");
  150. arith_check(test,x,y,z,-x,x*-1,"mul by -1");
  151. arith_check(test,x,y,z,x+x,x*2,"mul by 2");
  152. arith_check(test,x,y,z,-(x*y),(-x)*y,"neg prop mul");
  153. arith_check(test,x,y,z,x*y,(-x)*(-y),"double neg prop mul");
  154. arith_check(test,x,y,z,-(x+y),(-x)+(-y),"neg prop add");
  155. arith_check(test,x,y,z,x-y,(x)+(-y),"add neg sub");
  156. arith_check(test,x,y,z,(-x)-y,-(x+y),"neg add");
  157. if (sob <= 4) {
  158. uint64_t xi = leint(xx), yi = leint(yy);
  159. arith_check(test,x,y,z,x,xi,"parse consistency");
  160. arith_check(test,x,y,z,x+y,xi+yi,"add consistency");
  161. arith_check(test,x,y,z,x*y,xi*yi,"mul consistency");
  162. }
  163. if (i%20) continue;
  164. if (y!=0) arith_check(test,x,y,z,x*y/y,x,"invert");
  165. try {
  166. y = x/0;
  167. test.fail();
  168. printf(" Inverted zero!");
  169. print("x", x);
  170. print("y", y);
  171. } catch(CryptoException) {}
  172. }
  173. }
  174. static const Block sqrt_minus_one;
  175. static const Block minus_sqrt_minus_one;
  176. static const Block elli_patho; /* sqrt(1/(u(1-d))) */
  177. static void test_elligator() {
  178. SpongeRng rng(Block("test_elligator"),SpongeRng::DETERMINISTIC);
  179. Test test("Elligator");
  180. const int NHINTS = Group::REMOVED_COFACTOR * 2;
  181. SecureBuffer *alts[NHINTS];
  182. bool successes[NHINTS];
  183. SecureBuffer *alts2[NHINTS];
  184. bool successes2[NHINTS];
  185. for (int i=0; i<NTESTS/10 && test.passing_now; i++) {
  186. size_t len = (i % (2*Point::HASH_BYTES + 3));
  187. SecureBuffer b1(len);
  188. if (i!=Point::HASH_BYTES) rng.read(b1); /* special test case */
  189. if (len >= Point::HASH_BYTES) b1[Point::HASH_BYTES-1] &= 0x7F; // FIXME MAGIC
  190. /* Pathological cases */
  191. if (i==1) b1[0] = 1;
  192. if (i==2 && sqrt_minus_one.size()) b1 = sqrt_minus_one;
  193. if (i==3 && minus_sqrt_minus_one.size()) b1 = minus_sqrt_minus_one;
  194. if (i==4 && elli_patho.size()) b1 = elli_patho;
  195. len = b1.size();
  196. Point s = Point::from_hash(b1), ss=s;
  197. for (int j=0; j<(i&3); j++) ss = ss.debugging_torque();
  198. ss = ss.debugging_pscale(rng);
  199. bool good = false;
  200. for (int j=0; j<NHINTS; j++) {
  201. alts[j] = new SecureBuffer(len);
  202. alts2[j] = new SecureBuffer(len);
  203. if (len > Point::HASH_BYTES)
  204. memcpy(&(*alts[j])[Point::HASH_BYTES], &b1[Point::HASH_BYTES], len-Point::HASH_BYTES);
  205. if (len > Point::HASH_BYTES)
  206. memcpy(&(*alts2[j])[Point::HASH_BYTES], &b1[Point::HASH_BYTES], len-Point::HASH_BYTES);
  207. successes[j] = decaf_successful( s.invert_elligator(*alts[j], j));
  208. successes2[j] = decaf_successful(ss.invert_elligator(*alts2[j],j));
  209. if (successes[j] != successes2[j]
  210. || (successes[j] && successes2[j] && *alts[j] != *alts2[j])
  211. ) {
  212. test.fail();
  213. printf(" Unscalable Elligator inversion: i=%d, hint=%d, s=%d,%d\n",i,j,
  214. -int(successes[j]),-int(successes2[j]));
  215. hexprint("x",b1);
  216. hexprint("X",*alts[j]);
  217. hexprint("X",*alts2[j]);
  218. }
  219. if (successes[j]) {
  220. good = good || (b1 == *alts[j]);
  221. for (int k=0; k<j; k++) {
  222. if (successes[k] && *alts[j] == *alts[k]) {
  223. test.fail();
  224. printf(" Duplicate Elligator inversion: i=%d, hints=%d, %d\n",i,j,k);
  225. hexprint("x",b1);
  226. hexprint("X",*alts[j]);
  227. }
  228. }
  229. if (s != Point::from_hash(*alts[j])) {
  230. test.fail();
  231. printf(" Fail Elligator inversion round-trip: i=%d, hint=%d %s\n",i,j,
  232. (s==-Point::from_hash(*alts[j])) ? "[output was -input]": "");
  233. hexprint("x",b1);
  234. hexprint("X",*alts[j]);
  235. }
  236. }
  237. }
  238. if (!good) {
  239. test.fail();
  240. printf(" %s Elligator inversion: i=%d\n",good ? "Passed" : "Failed", i);
  241. hexprint("B", b1);
  242. for (int j=0; j<NHINTS; j++) {
  243. printf(" %d: %s%s", j, successes[j] ? "succ" : "fail\n", (successes[j] && *alts[j] == b1) ? " [x]" : "");
  244. if (successes[j]) {
  245. hexprint("b", *alts[j]);
  246. }
  247. }
  248. printf("\n");
  249. }
  250. for (int j=0; j<NHINTS; j++) {
  251. delete alts[j];
  252. alts[j] = NULL;
  253. delete alts2[j];
  254. alts2[j] = NULL;
  255. }
  256. Point t(rng);
  257. point_check(test,t,t,t,0,0,t,Point::from_hash(t.steg_encode(rng)),"steg round-trip");
  258. }
  259. }
  260. static void test_ec() {
  261. SpongeRng rng(Block("test_ec"),SpongeRng::DETERMINISTIC);
  262. Test test("EC");
  263. Point id = Point::identity(), base = Point::base();
  264. point_check(test,id,id,id,0,0,Point::from_hash(""),id,"fh0");
  265. unsigned char enc[Point::SER_BYTES] = {0};
  266. if (Group::FIELD_MODULUS_TYPE == 3) {
  267. /* When p == 3 mod 4, the QNR is -1, so u*1^2 = -1 also produces the
  268. * identity.
  269. */
  270. point_check(test,id,id,id,0,0,Point::from_hash("\x01"),id,"fh1");
  271. }
  272. point_check(test,id,id,id,0,0,Point(FixedBlock<sizeof(enc)>(enc)),id,"decode [0]");
  273. try {
  274. enc[0] = 1;
  275. Point f((FixedBlock<sizeof(enc)>(enc)));
  276. test.fail();
  277. printf(" Allowed deserialize of [1]: %d", f==id);
  278. } catch (CryptoException) {
  279. /* ok */
  280. }
  281. if (sqrt_minus_one.size()) {
  282. try {
  283. Point f(sqrt_minus_one);
  284. test.fail();
  285. printf(" Allowed deserialize of [i]: %d", f==id);
  286. } catch (CryptoException) {
  287. /* ok */
  288. }
  289. }
  290. if (minus_sqrt_minus_one.size()) {
  291. try {
  292. Point f(minus_sqrt_minus_one);
  293. test.fail();
  294. printf(" Allowed deserialize of [-i]: %d", f==id);
  295. } catch (CryptoException) {
  296. /* ok */
  297. }
  298. }
  299. for (int i=0; i<NTESTS && test.passing_now; i++) {
  300. Scalar x(rng);
  301. Scalar y(rng);
  302. Point p(rng);
  303. Point q(rng);
  304. Point d1, d2;
  305. SecureBuffer buffer(2*Point::HASH_BYTES);
  306. rng.read(buffer);
  307. Point r = Point::from_hash(buffer);
  308. point_check(test,p,q,r,0,0,p,Point(p.serialize()),"round-trip");
  309. Point pp = p.debugging_torque().debugging_pscale(rng);
  310. if (!memeq(pp.serialize(),p.serialize())) {
  311. test.fail();
  312. printf(" Fail torque seq test\n");
  313. }
  314. if (!memeq((p-pp).serialize(),id.serialize())) {
  315. test.fail();
  316. printf(" Fail torque id test\n");
  317. }
  318. if (!memeq((p-p).serialize(),id.serialize())) {
  319. test.fail();
  320. printf(" Fail id test\n");
  321. }
  322. point_check(test,p,q,r,0,0,p,pp,"torque eq");
  323. point_check(test,p,q,r,0,0,p+q,q+p,"commute add");
  324. point_check(test,p,q,r,0,0,(p-q)+q,p,"correct sub");
  325. point_check(test,p,q,r,0,0,p+(q+r),(p+q)+r,"assoc add");
  326. point_check(test,p,q,r,0,0,p.times_two(),p+p,"dbl add");
  327. if (i%10) continue;
  328. point_check(test,p,q,r,0,0,p.times_two(),p*Scalar(2),"add times two");
  329. point_check(test,p,q,r,x,0,x*(p+q),x*p+x*q,"distr mul");
  330. point_check(test,p,q,r,x,y,(x*y)*p,x*(y*p),"assoc mul");
  331. point_check(test,p,q,r,x,y,x*p+y*q,Point::double_scalarmul(x,p,y,q),"double mul");
  332. p.dual_scalarmul(d1,d2,x,y);
  333. point_check(test,p,q,r,x,y,x*p,d1,"dual mul 1");
  334. point_check(test,p,q,r,x,y,y*p,d2,"dual mul 2");
  335. point_check(test,base,q,r,x,y,x*base+y*q,q.non_secret_combo_with_base(y,x),"ds vt mul");
  336. point_check(test,p,q,r,x,0,Precomputed(p)*x,p*x,"precomp mul");
  337. point_check(test,p,q,r,0,0,r,
  338. Point::from_hash(Buffer(buffer).slice(0,Point::HASH_BYTES))
  339. + Point::from_hash(Buffer(buffer).slice(Point::HASH_BYTES,Point::HASH_BYTES)),
  340. "unih = hash+add"
  341. );
  342. point_check(test,p,q,r,x,0,Point(x.direct_scalarmul(p.serialize())),x*p,"direct mul");
  343. }
  344. }
  345. static void test_crypto() {
  346. Test test("Sample crypto");
  347. SpongeRng rng(Block("test_decaf_crypto"),SpongeRng::DETERMINISTIC);
  348. for (int i=0; i<NTESTS && test.passing_now; i++) {
  349. try {
  350. PrivateKey<Group> priv1(rng), priv2(rng);
  351. PublicKey<Group> pub1(priv1), pub2(priv2);
  352. SecureBuffer message = rng.read(i);
  353. SecureBuffer sig(priv1.sign(message));
  354. pub1.verify(message, sig);
  355. SecureBuffer s1(priv1.sharedSecret(pub2,32,true));
  356. SecureBuffer s2(priv2.sharedSecret(pub1,32,false));
  357. if (!memeq(s1,s2)) {
  358. test.fail();
  359. printf(" Shared secrets disagree on iteration %d.\n",i);
  360. }
  361. } catch (CryptoException) {
  362. test.fail();
  363. printf(" Threw CryptoException.\n");
  364. }
  365. }
  366. }
  367. static const uint8_t rfc7748_1[DhLadder::PUBLIC_BYTES];
  368. static const uint8_t rfc7748_1000[DhLadder::PUBLIC_BYTES];
  369. static const uint8_t rfc7748_1000000[DhLadder::PUBLIC_BYTES];
  370. static void test_cfrg_crypto() {
  371. Test test("CFRG crypto");
  372. SpongeRng rng(Block("test_cfrg_crypto"),SpongeRng::DETERMINISTIC);
  373. for (int i=0; i<NTESTS && test.passing_now; i++) {
  374. FixedArrayBuffer<DhLadder::PUBLIC_BYTES> base(rng);
  375. FixedArrayBuffer<DhLadder::PRIVATE_BYTES> s1(rng), s2(rng);
  376. SecureBuffer p1 = DhLadder::shared_secret(base,s1);
  377. SecureBuffer p2 = DhLadder::shared_secret(base,s2);
  378. SecureBuffer ss1 = DhLadder::shared_secret(p2,s1);
  379. SecureBuffer ss2 = DhLadder::shared_secret(p1,s2);
  380. if (!memeq(ss1,ss2)) {
  381. test.fail();
  382. printf(" Shared secrets disagree on iteration %d.\n",i);
  383. }
  384. if (!memeq(
  385. DhLadder::shared_secret(DhLadder::base_point(),s1),
  386. DhLadder::generate_key(s1)
  387. )) {
  388. test.fail();
  389. printf(" Generated keys disagree on iteration %d.\n",i);
  390. }
  391. }
  392. }
  393. static void test_cfrg_vectors() {
  394. Test test("CFRG test vectors");
  395. SecureBuffer k = DhLadder::base_point();
  396. SecureBuffer u = DhLadder::base_point();
  397. int the_ntests = (NTESTS < 1000000) ? 1000 : 1000000;
  398. for (int i=0; i<the_ntests && test.passing_now; i++) {
  399. SecureBuffer n = DhLadder::shared_secret(u,k);
  400. u = k; k = n;
  401. if (i==1-1) {
  402. if (!memeq(k,SecureBuffer(FixedBlock<DhLadder::PUBLIC_BYTES>(rfc7748_1)))) {
  403. test.fail();
  404. printf(" Test vectors disagree at 1.");
  405. }
  406. } else if (i==1000-1) {
  407. if (!memeq(k,SecureBuffer(FixedBlock<DhLadder::PUBLIC_BYTES>(rfc7748_1000)))) {
  408. test.fail();
  409. printf(" Test vectors disagree at 1000.");
  410. }
  411. } else if (i==1000000-1) {
  412. if (!memeq(k,SecureBuffer(FixedBlock<DhLadder::PUBLIC_BYTES>(rfc7748_1000000)))) {
  413. test.fail();
  414. printf(" Test vectors disagree at 1000000.");
  415. }
  416. }
  417. }
  418. }
  419. static void run() {
  420. printf("Testing %s:\n",Group::name());
  421. test_arithmetic();
  422. test_elligator();
  423. test_ec();
  424. test_cfrg_crypto();
  425. test_cfrg_vectors();
  426. test_crypto();
  427. printf("\n");
  428. }
  429. }; /* template<GroupId GROUP> struct Tests */
  430. template<> const uint8_t Tests<IsoEd25519>::rfc7748_1[32] = {
  431. 0x42,0x2c,0x8e,0x7a,0x62,0x27,0xd7,0xbc,
  432. 0xa1,0x35,0x0b,0x3e,0x2b,0xb7,0x27,0x9f,
  433. 0x78,0x97,0xb8,0x7b,0xb6,0x85,0x4b,0x78,
  434. 0x3c,0x60,0xe8,0x03,0x11,0xae,0x30,0x79
  435. };
  436. template<> const uint8_t Tests<IsoEd25519>::rfc7748_1000[32] = {
  437. 0x68,0x4c,0xf5,0x9b,0xa8,0x33,0x09,0x55,
  438. 0x28,0x00,0xef,0x56,0x6f,0x2f,0x4d,0x3c,
  439. 0x1c,0x38,0x87,0xc4,0x93,0x60,0xe3,0x87,
  440. 0x5f,0x2e,0xb9,0x4d,0x99,0x53,0x2c,0x51
  441. };
  442. template<> const uint8_t Tests<IsoEd25519>::rfc7748_1000000[32] = {
  443. 0x7c,0x39,0x11,0xe0,0xab,0x25,0x86,0xfd,
  444. 0x86,0x44,0x97,0x29,0x7e,0x57,0x5e,0x6f,
  445. 0x3b,0xc6,0x01,0xc0,0x88,0x3c,0x30,0xdf,
  446. 0x5f,0x4d,0xd2,0xd2,0x4f,0x66,0x54,0x24
  447. };
  448. template<> const uint8_t Tests<Ed448Goldilocks>::rfc7748_1[56] = {
  449. 0x3f,0x48,0x2c,0x8a,0x9f,0x19,0xb0,0x1e,
  450. 0x6c,0x46,0xee,0x97,0x11,0xd9,0xdc,0x14,
  451. 0xfd,0x4b,0xf6,0x7a,0xf3,0x07,0x65,0xc2,
  452. 0xae,0x2b,0x84,0x6a,0x4d,0x23,0xa8,0xcd,
  453. 0x0d,0xb8,0x97,0x08,0x62,0x39,0x49,0x2c,
  454. 0xaf,0x35,0x0b,0x51,0xf8,0x33,0x86,0x8b,
  455. 0x9b,0xc2,0xb3,0xbc,0xa9,0xcf,0x41,0x13
  456. };
  457. template<> const uint8_t Tests<Ed448Goldilocks>::rfc7748_1000[56] = {
  458. 0xaa,0x3b,0x47,0x49,0xd5,0x5b,0x9d,0xaf,
  459. 0x1e,0x5b,0x00,0x28,0x88,0x26,0xc4,0x67,
  460. 0x27,0x4c,0xe3,0xeb,0xbd,0xd5,0xc1,0x7b,
  461. 0x97,0x5e,0x09,0xd4,0xaf,0x6c,0x67,0xcf,
  462. 0x10,0xd0,0x87,0x20,0x2d,0xb8,0x82,0x86,
  463. 0xe2,0xb7,0x9f,0xce,0xea,0x3e,0xc3,0x53,
  464. 0xef,0x54,0xfa,0xa2,0x6e,0x21,0x9f,0x38
  465. };
  466. template<> const uint8_t Tests<Ed448Goldilocks>::rfc7748_1000000[56] = {
  467. 0x07,0x7f,0x45,0x36,0x81,0xca,0xca,0x36,
  468. 0x93,0x19,0x84,0x20,0xbb,0xe5,0x15,0xca,
  469. 0xe0,0x00,0x24,0x72,0x51,0x9b,0x3e,0x67,
  470. 0x66,0x1a,0x7e,0x89,0xca,0xb9,0x46,0x95,
  471. 0xc8,0xf4,0xbc,0xd6,0x6e,0x61,0xb9,0xb9,
  472. 0xc9,0x46,0xda,0x8d,0x52,0x4d,0xe3,0xd6,
  473. 0x9b,0xd9,0xd9,0xd6,0x6b,0x99,0x7e,0x37
  474. };
  475. template<> const Block Tests<Ed448Goldilocks>::sqrt_minus_one(NULL,0);
  476. const uint8_t sm1_25519[32] = {
  477. 0xb0,0xa0,0x0e,0x4a,0x27,0x1b,0xee,0xc4,
  478. 0x78,0xe4,0x2f,0xad,0x06,0x18,0x43,0x2f,
  479. 0xa7,0xd7,0xfb,0x3d,0x99,0x00,0x4d,0x2b,
  480. 0x0b,0xdf,0xc1,0x4f,0x80,0x24,0x83,0x2b
  481. };
  482. template<> const Block Tests<IsoEd25519>::sqrt_minus_one(sm1_25519,32);
  483. template<> const Block Tests<Ed448Goldilocks>::minus_sqrt_minus_one(NULL,0);
  484. const uint8_t msm1_25519[32] = {
  485. 0x3d,0x5f,0xf1,0xb5,0xd8,0xe4,0x11,0x3b,
  486. 0x87,0x1b,0xd0,0x52,0xf9,0xe7,0xbc,0xd0,
  487. 0x58,0x28,0x04,0xc2,0x66,0xff,0xb2,0xd4,
  488. 0xf4,0x20,0x3e,0xb0,0x7f,0xdb,0x7c,0x54
  489. };
  490. template<> const Block Tests<IsoEd25519>::minus_sqrt_minus_one(msm1_25519,32);
  491. const uint8_t elli_patho_448[56] = {
  492. 0x14,0xf0,0x70,0x58,0x41,0xc7,0xf9,0xa5,
  493. 0xfa,0x2c,0x7d,0x87,0x07,0x89,0xe8,0x61,
  494. 0x63,0xe8,0xc8,0xdc,0x06,0x2d,0x39,0x8f,
  495. 0x18,0x83,0x1e,0xc6,0x8c,0x6d,0x73,0x24,
  496. 0xd4,0xb3,0xd3,0xe1,0xf3,0x51,0x8c,0xee,
  497. 0x65,0x79,0x88,0xc1,0x0b,0xcf,0x8e,0xa5,
  498. 0x86,0xa9,0x2e,0xc9,0x17,0x68,0x9b,0x20
  499. };
  500. template<> const Block Tests<Ed448Goldilocks>::elli_patho(elli_patho_448,56);
  501. template<> const Block Tests<IsoEd25519>::elli_patho(NULL,0);
  502. int main(int argc, char **argv) {
  503. (void) argc; (void) argv;
  504. run_for_all_curves<Tests>();
  505. if (passing) printf("Passed all tests.\n");
  506. return passing ? 0 : 1;
  507. }