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.
 
 
 
 
 

622 lines
17 KiB

  1. /* Copyright (c) 2014 Cryptography Research, Inc.
  2. * Released under the MIT License. See LICENSE.txt for license information.
  3. */
  4. /* This file was generated with the assistance of a tool written in SAGE. */
  5. #include "ec_point.h"
  6. void
  7. p448_isr (
  8. struct p448_t* a,
  9. const struct p448_t* x
  10. ) {
  11. struct p448_t L0, L1, L2;
  12. p448_sqr ( &L1, x );
  13. p448_mul ( &L2, x, &L1 );
  14. p448_sqr ( &L1, &L2 );
  15. p448_mul ( &L2, x, &L1 );
  16. p448_sqrn ( &L1, &L2, 3 );
  17. p448_mul ( &L0, &L2, &L1 );
  18. p448_sqrn ( &L1, &L0, 3 );
  19. p448_mul ( &L0, &L2, &L1 );
  20. p448_sqrn ( &L2, &L0, 9 );
  21. p448_mul ( &L1, &L0, &L2 );
  22. p448_sqr ( &L0, &L1 );
  23. p448_mul ( &L2, x, &L0 );
  24. p448_sqrn ( &L0, &L2, 18 );
  25. p448_mul ( &L2, &L1, &L0 );
  26. p448_sqrn ( &L0, &L2, 37 );
  27. p448_mul ( &L1, &L2, &L0 );
  28. p448_sqrn ( &L0, &L1, 37 );
  29. p448_mul ( &L1, &L2, &L0 );
  30. p448_sqrn ( &L0, &L1, 111 );
  31. p448_mul ( &L2, &L1, &L0 );
  32. p448_sqr ( &L0, &L2 );
  33. p448_mul ( &L1, x, &L0 );
  34. p448_sqrn ( &L0, &L1, 223 );
  35. p448_mul ( a, &L2, &L0 );
  36. }
  37. void
  38. p448_inverse (
  39. struct p448_t* a,
  40. const struct p448_t* x
  41. ) {
  42. struct p448_t L0, L1;
  43. p448_isr ( &L0, x );
  44. p448_sqr ( &L1, &L0 );
  45. p448_sqr ( &L0, &L1 );
  46. p448_mul ( a, x, &L0 );
  47. }
  48. void
  49. p448_tw_extensible_add_niels (
  50. struct tw_extensible_t* d,
  51. const struct tw_niels_t* e
  52. ) {
  53. struct p448_t L0, L1;
  54. p448_bias ( &d->y, 2 );
  55. p448_bias ( &d->z, 2 );
  56. p448_sub ( &L1, &d->y, &d->x );
  57. p448_mul ( &L0, &e->a, &L1 );
  58. p448_add ( &L1, &d->x, &d->y );
  59. p448_mul ( &d->y, &e->b, &L1 );
  60. p448_bias ( &d->y, 2 );
  61. p448_mul ( &L1, &d->u, &d->t );
  62. p448_mul ( &d->x, &e->c, &L1 );
  63. p448_add ( &d->u, &L0, &d->y );
  64. p448_sub ( &d->t, &d->y, &L0 );
  65. p448_sub ( &d->y, &d->z, &d->x );
  66. p448_add ( &L0, &d->x, &d->z );
  67. p448_mul ( &d->z, &L0, &d->y );
  68. p448_mul ( &d->x, &d->y, &d->t );
  69. p448_mul ( &d->y, &L0, &d->u );
  70. }
  71. void
  72. p448_tw_extensible_add_pniels (
  73. struct tw_extensible_t* e,
  74. const struct tw_pniels_t* a
  75. ) {
  76. struct p448_t L0;
  77. p448_mul ( &L0, &e->z, &a->z );
  78. p448_copy ( &e->z, &L0 );
  79. p448_tw_extensible_add_niels( e, &a->n );
  80. }
  81. void
  82. p448_tw_extensible_double (
  83. struct tw_extensible_t* a
  84. ) {
  85. struct p448_t L0, L1, L2;
  86. p448_sqr ( &L2, &a->x );
  87. p448_sqr ( &L0, &a->y );
  88. p448_add ( &a->u, &L2, &L0 );
  89. p448_add ( &a->t, &a->y, &a->x );
  90. p448_sqr ( &L1, &a->t );
  91. p448_bias ( &L1, 3 );
  92. p448_sub ( &a->t, &L1, &a->u );
  93. p448_sub ( &L1, &L0, &L2 );
  94. p448_bias ( &L1, 2 );
  95. p448_sqr ( &a->x, &a->z );
  96. p448_bias ( &a->x, 2 );
  97. p448_add ( &a->z, &a->x, &a->x );
  98. p448_sub ( &L0, &a->z, &L1 );
  99. p448_mul ( &a->z, &L1, &L0 );
  100. p448_mul ( &a->x, &L0, &a->t );
  101. p448_mul ( &a->y, &L1, &a->u );
  102. }
  103. void
  104. p448_extensible_double (
  105. struct extensible_t* a
  106. ) {
  107. struct p448_t L0, L1, L2;
  108. p448_sqr ( &L2, &a->x );
  109. p448_sqr ( &L0, &a->y );
  110. p448_add ( &L1, &L2, &L0 );
  111. p448_add ( &a->t, &a->y, &a->x );
  112. p448_sqr ( &a->u, &a->t );
  113. p448_bias ( &a->u, 3 );
  114. p448_sub ( &a->t, &a->u, &L1 );
  115. p448_sub ( &a->u, &L0, &L2 );
  116. p448_bias ( &a->u, 2 );
  117. p448_sqr ( &a->x, &a->z );
  118. p448_bias ( &a->x, 2 );
  119. p448_add ( &a->z, &a->x, &a->x );
  120. p448_sub ( &L0, &a->z, &L1 );
  121. p448_mul ( &a->z, &L1, &L0 );
  122. p448_mul ( &a->x, &L0, &a->t );
  123. p448_mul ( &a->y, &L1, &a->u );
  124. }
  125. void
  126. p448_isogeny_un_to_tw (
  127. struct tw_extensible_t* b,
  128. const struct extensible_t* a
  129. ) {
  130. struct p448_t L0;
  131. p448_sqr ( &b->x, &a->x );
  132. p448_sqr ( &b->z, &a->y );
  133. p448_add ( &b->u, &b->x, &b->z );
  134. p448_add ( &b->t, &a->y, &a->x );
  135. p448_sqr ( &L0, &b->t );
  136. p448_bias ( &L0, 3 );
  137. p448_sub ( &b->t, &L0, &b->u );
  138. p448_sub ( &L0, &b->z, &b->x );
  139. p448_bias ( &L0, 2 );
  140. p448_sqr ( &b->x, &a->z );
  141. p448_bias ( &b->x, 2 );
  142. p448_add ( &b->z, &b->x, &b->x );
  143. p448_sub ( &b->y, &b->z, &b->u );
  144. p448_mul ( &b->z, &L0, &b->y );
  145. p448_mul ( &b->x, &b->y, &b->t );
  146. p448_mul ( &b->y, &L0, &b->u );
  147. }
  148. void
  149. p448_isogeny_tw_to_un (
  150. struct extensible_t* b,
  151. const struct tw_extensible_t* a
  152. ) {
  153. struct p448_t L0;
  154. p448_sqr ( &b->x, &a->x );
  155. p448_sqr ( &b->z, &a->y );
  156. p448_add ( &L0, &b->x, &b->z );
  157. p448_add ( &b->t, &a->y, &a->x );
  158. p448_sqr ( &b->u, &b->t );
  159. p448_bias ( &b->u, 3 );
  160. p448_sub ( &b->t, &b->u, &L0 );
  161. p448_sub ( &b->u, &b->z, &b->x );
  162. p448_bias ( &b->u, 2 );
  163. p448_sqr ( &b->x, &a->z );
  164. p448_bias ( &b->x, 2 );
  165. p448_add ( &b->z, &b->x, &b->x );
  166. p448_sub ( &b->y, &b->z, &b->u );
  167. p448_mul ( &b->z, &L0, &b->y );
  168. p448_mul ( &b->x, &b->y, &b->t );
  169. p448_mul ( &b->y, &L0, &b->u );
  170. }
  171. void
  172. convert_tw_affine_to_tw_pniels (
  173. struct tw_pniels_t* b,
  174. const struct tw_affine_t* a
  175. ) {
  176. p448_sub ( &b->n.a, &a->y, &a->x );
  177. p448_bias ( &b->n.a, 2 );
  178. p448_weak_reduce( &b->n.a );
  179. p448_add ( &b->n.b, &a->x, &a->y );
  180. p448_weak_reduce( &b->n.b );
  181. p448_mul ( &b->n.c, &a->y, &a->x );
  182. p448_mulw ( &b->z, &b->n.c, 78164 );
  183. p448_neg ( &b->n.c, &b->z );
  184. p448_bias ( &b->n.c, 2 );
  185. p448_weak_reduce( &b->n.c );
  186. p448_set_ui( &b->z, 2 );
  187. }
  188. void
  189. convert_tw_affine_to_tw_extensible (
  190. struct tw_extensible_t* b,
  191. const struct tw_affine_t* a
  192. ) {
  193. p448_copy ( &b->x, &a->x );
  194. p448_copy ( &b->y, &a->y );
  195. p448_set_ui( &b->z, 1 );
  196. p448_copy ( &b->t, &a->x );
  197. p448_copy ( &b->u, &a->y );
  198. }
  199. void
  200. convert_affine_to_extensible (
  201. struct extensible_t* b,
  202. const struct affine_t* a
  203. ) {
  204. p448_copy ( &b->x, &a->x );
  205. p448_copy ( &b->y, &a->y );
  206. p448_set_ui( &b->z, 1 );
  207. p448_copy ( &b->t, &a->x );
  208. p448_copy ( &b->u, &a->y );
  209. }
  210. void
  211. convert_tw_extensible_to_tw_pniels (
  212. struct tw_pniels_t* b,
  213. const struct tw_extensible_t* a
  214. ) {
  215. p448_sub ( &b->n.a, &a->y, &a->x );
  216. p448_bias ( &b->n.a, 2 );
  217. p448_weak_reduce( &b->n.a );
  218. p448_add ( &b->n.b, &a->x, &a->y );
  219. p448_weak_reduce( &b->n.b );
  220. p448_mul ( &b->n.c, &a->u, &a->t );
  221. p448_mulw ( &b->z, &b->n.c, 78164 );
  222. p448_neg ( &b->n.c, &b->z );
  223. p448_bias ( &b->n.c, 2 );
  224. p448_weak_reduce( &b->n.c );
  225. p448_add ( &b->z, &a->z, &a->z );
  226. p448_weak_reduce( &b->z );
  227. }
  228. void
  229. convert_tw_pniels_to_tw_extensible (
  230. struct tw_extensible_t* e,
  231. const struct tw_pniels_t* d
  232. ) {
  233. p448_add ( &e->u, &d->n.b, &d->n.a );
  234. p448_sub ( &e->t, &d->n.b, &d->n.a );
  235. p448_bias ( &e->t, 2 );
  236. p448_mul ( &e->x, &d->z, &e->t );
  237. p448_mul ( &e->y, &d->z, &e->u );
  238. p448_sqr ( &e->z, &d->z );
  239. }
  240. void
  241. convert_tw_niels_to_tw_extensible (
  242. struct tw_extensible_t* e,
  243. const struct tw_niels_t* d
  244. ) {
  245. p448_add ( &e->y, &d->b, &d->a );
  246. p448_weak_reduce( &e->y );
  247. p448_sub ( &e->x, &d->b, &d->a );
  248. p448_bias ( &e->x, 2 );
  249. p448_weak_reduce( &e->x );
  250. p448_set_ui( &e->z, 1 );
  251. p448_copy ( &e->t, &e->x );
  252. p448_copy ( &e->u, &e->y );
  253. }
  254. void
  255. p448_montgomery_step (
  256. struct montgomery_t* a
  257. ) {
  258. struct p448_t L0, L1;
  259. p448_bias ( &a->xd, 2 );
  260. p448_bias ( &a->xa, 2 );
  261. p448_add ( &L0, &a->zd, &a->xd );
  262. p448_sub ( &L1, &a->xd, &a->zd );
  263. p448_sub ( &a->zd, &a->xa, &a->za );
  264. p448_mul ( &a->xd, &L0, &a->zd );
  265. p448_bias ( &a->xd, 2 );
  266. p448_add ( &a->zd, &a->za, &a->xa );
  267. p448_mul ( &a->za, &L1, &a->zd );
  268. p448_add ( &a->xa, &a->za, &a->xd );
  269. p448_sqr ( &a->zd, &a->xa );
  270. p448_mul ( &a->xa, &a->z0, &a->zd );
  271. p448_sub ( &a->zd, &a->xd, &a->za );
  272. p448_sqr ( &a->za, &a->zd );
  273. p448_sqr ( &a->xd, &L0 );
  274. p448_bias ( &a->xd, 2 );
  275. p448_sqr ( &L0, &L1 );
  276. p448_mulw ( &a->zd, &a->xd, 39082 );
  277. p448_bias ( &a->zd, 4 );
  278. p448_sub ( &L1, &a->xd, &L0 );
  279. p448_mul ( &a->xd, &L0, &a->zd );
  280. p448_sub ( &L0, &a->zd, &L1 );
  281. p448_mul ( &a->zd, &L0, &L1 );
  282. }
  283. void
  284. p448_montgomery_serialize (
  285. struct p448_t* sign,
  286. struct p448_t* ser,
  287. const struct montgomery_t* a,
  288. const struct p448_t* sbz
  289. ) {
  290. struct p448_t L0, L1, L2, L3;
  291. p448_mul ( &L2, &a->z0, &a->zd );
  292. p448_bias ( &L2, 2 );
  293. p448_sub ( &L0, &L2, &a->xd );
  294. p448_mul ( &L2, &a->za, &L0 );
  295. p448_bias ( &L2, 2 );
  296. p448_mul ( &L1, &a->z0, &a->xd );
  297. p448_bias ( &L1, 2 );
  298. p448_sub ( &L0, &L1, &a->zd );
  299. p448_mul ( &L3, &a->xa, &L0 );
  300. p448_add ( &L1, &L3, &L2 );
  301. p448_sub ( &L0, &L2, &L3 );
  302. p448_mul ( &L2, &L0, &L1 );
  303. p448_mul ( &L0, sbz, &L2 );
  304. p448_mul ( &L2, &a->zd, &L0 );
  305. p448_mul ( sign, &L2, &a->zd );
  306. p448_mul ( ser, &L2, &a->xd );
  307. p448_mul ( &L2, sign, ser );
  308. p448_isr ( &L1, &L2 );
  309. p448_mul ( ser, sign, &L1 );
  310. p448_sqr ( &L0, &L1 );
  311. p448_mul ( sign, &L2, &L0 );
  312. }
  313. void
  314. extensible_serialize (
  315. struct p448_t* b,
  316. const struct extensible_t* a
  317. ) {
  318. struct p448_t L0, L1, L2;
  319. p448_sub ( &L0, &a->y, &a->z );
  320. p448_bias ( &L0, 2 );
  321. p448_add ( b, &a->z, &a->y );
  322. p448_mul ( &L1, &a->z, &a->x );
  323. p448_mul ( &L2, &L0, &L1 );
  324. p448_mul ( &L1, &L2, &L0 );
  325. p448_mul ( &L0, &L2, b );
  326. p448_mul ( &L2, &L1, &L0 );
  327. p448_isr ( &L0, &L2 );
  328. p448_mul ( b, &L1, &L0 );
  329. p448_sqr ( &L1, &L0 );
  330. p448_mul ( &L0, &L2, &L1 );
  331. }
  332. void
  333. isogeny_and_serialize (
  334. struct p448_t* b,
  335. const struct tw_extensible_t* a
  336. ) {
  337. struct p448_t L0, L1, L2, L3;
  338. p448_mul ( &L3, &a->y, &a->x );
  339. p448_add ( &L1, &a->y, &a->x );
  340. p448_sqr ( b, &L1 );
  341. p448_add ( &L2, &L3, &L3 );
  342. p448_sub ( &L1, b, &L2 );
  343. p448_bias ( &L1, 3 );
  344. p448_sqr ( &L2, &a->z );
  345. p448_sqr ( b, &L2 );
  346. p448_add ( &L2, &L1, &L1 );
  347. p448_mulw ( &L1, &L2, 39082 );
  348. p448_neg ( &L2, &L1 );
  349. p448_bias ( &L2, 2 );
  350. p448_mulw ( &L0, &L2, 39082 );
  351. p448_neg ( &L1, &L0 );
  352. p448_bias ( &L1, 2 );
  353. p448_mul ( &L0, &L2, b );
  354. p448_mul ( b, &L1, &L0 );
  355. p448_isr ( &L0, b );
  356. p448_mul ( &L2, &L1, &L0 );
  357. p448_sqr ( &L1, &L0 );
  358. p448_mul ( &L0, b, &L1 );
  359. p448_mul ( b, &L2, &L3 );
  360. }
  361. mask_t
  362. affine_deserialize (
  363. struct affine_t* a,
  364. const struct p448_t* sz
  365. ) {
  366. struct p448_t L0, L1, L2, L3;
  367. p448_sqr ( &L1, sz );
  368. p448_copy ( &L3, &L1 );
  369. p448_addw ( &L3, 1 );
  370. p448_sqr ( &a->x, &L3 );
  371. p448_mulw ( &L3, &a->x, 39082 );
  372. p448_neg ( &a->x, &L3 );
  373. p448_add ( &L3, &L1, &L1 );
  374. p448_bias ( &L3, 1 );
  375. p448_add ( &a->y, &L3, &L3 );
  376. p448_add ( &L3, &a->y, &a->x );
  377. p448_copy ( &a->y, &L1 );
  378. p448_subw ( &a->y, 1 );
  379. p448_neg ( &a->x, &a->y );
  380. p448_bias ( &a->x, 2 );
  381. p448_mul ( &a->y, &a->x, &L3 );
  382. p448_sqr ( &L2, &a->x );
  383. p448_mul ( &L0, &L2, &a->y );
  384. p448_mul ( &a->y, &a->x, &L0 );
  385. p448_isr ( &L3, &a->y );
  386. p448_mul ( &a->y, &L2, &L3 );
  387. p448_sqr ( &L2, &L3 );
  388. p448_mul ( &L3, &L0, &L2 );
  389. p448_mul ( &L0, &a->x, &L3 );
  390. p448_bias ( &L0, 1 );
  391. p448_add ( &L2, &a->y, &a->y );
  392. p448_mul ( &a->x, sz, &L2 );
  393. p448_addw ( &L1, 1 );
  394. p448_mul ( &a->y, &L1, &L3 );
  395. p448_subw ( &L0, 1 );
  396. return p448_is_zero( &L0 );
  397. }
  398. void
  399. set_identity_extensible (
  400. struct extensible_t* a
  401. ) {
  402. p448_set_ui( &a->x, 0 );
  403. p448_set_ui( &a->y, 1 );
  404. p448_set_ui( &a->z, 1 );
  405. p448_set_ui( &a->t, 0 );
  406. p448_set_ui( &a->u, 0 );
  407. }
  408. void
  409. set_identity_tw_extensible (
  410. struct tw_extensible_t* a
  411. ) {
  412. p448_set_ui( &a->x, 0 );
  413. p448_set_ui( &a->y, 1 );
  414. p448_set_ui( &a->z, 1 );
  415. p448_set_ui( &a->t, 0 );
  416. p448_set_ui( &a->u, 0 );
  417. }
  418. void
  419. set_identity_affine (
  420. struct affine_t* a
  421. ) {
  422. p448_set_ui( &a->x, 0 );
  423. p448_set_ui( &a->y, 1 );
  424. }
  425. mask_t
  426. eq_affine (
  427. const struct affine_t* a,
  428. const struct affine_t* b
  429. ) {
  430. mask_t L0, L1;
  431. struct p448_t L2;
  432. p448_sub ( &L2, &a->x, &b->x );
  433. p448_bias ( &L2, 2 );
  434. L1 = p448_is_zero( &L2 );
  435. p448_sub ( &L2, &a->y, &b->y );
  436. p448_bias ( &L2, 2 );
  437. L0 = p448_is_zero( &L2 );
  438. return L1 & L0;
  439. }
  440. mask_t
  441. eq_extensible (
  442. const struct extensible_t* a,
  443. const struct extensible_t* b
  444. ) {
  445. mask_t L0, L1;
  446. struct p448_t L2, L3, L4;
  447. p448_mul ( &L4, &b->z, &a->x );
  448. p448_mul ( &L3, &a->z, &b->x );
  449. p448_sub ( &L2, &L4, &L3 );
  450. p448_bias ( &L2, 2 );
  451. L1 = p448_is_zero( &L2 );
  452. p448_mul ( &L4, &b->z, &a->y );
  453. p448_mul ( &L3, &a->z, &b->y );
  454. p448_sub ( &L2, &L4, &L3 );
  455. p448_bias ( &L2, 2 );
  456. L0 = p448_is_zero( &L2 );
  457. return L1 & L0;
  458. }
  459. mask_t
  460. eq_tw_extensible (
  461. const struct tw_extensible_t* a,
  462. const struct tw_extensible_t* b
  463. ) {
  464. mask_t L0, L1;
  465. struct p448_t L2, L3, L4;
  466. p448_mul ( &L4, &b->z, &a->x );
  467. p448_mul ( &L3, &a->z, &b->x );
  468. p448_sub ( &L2, &L4, &L3 );
  469. p448_bias ( &L2, 2 );
  470. L1 = p448_is_zero( &L2 );
  471. p448_mul ( &L4, &b->z, &a->y );
  472. p448_mul ( &L3, &a->z, &b->y );
  473. p448_sub ( &L2, &L4, &L3 );
  474. p448_bias ( &L2, 2 );
  475. L0 = p448_is_zero( &L2 );
  476. return L1 & L0;
  477. }
  478. void
  479. elligator_2s_inject (
  480. struct affine_t* a,
  481. const struct p448_t* r
  482. ) {
  483. mask_t L0, L1;
  484. struct p448_t L2, L3, L4, L5, L6, L7, L8, L9;
  485. p448_sqr ( &a->x, r );
  486. p448_sqr ( &L3, &a->x );
  487. p448_copy ( &a->y, &L3 );
  488. p448_subw ( &a->y, 1 );
  489. p448_neg ( &L9, &a->y );
  490. p448_bias ( &L9, 2 );
  491. p448_sqr ( &L2, &L9 );
  492. p448_bias ( &L2, 1 );
  493. p448_mulw ( &L7, &L2, 1527402724 );
  494. p448_bias ( &L7, 2 );
  495. p448_mulw ( &L8, &L3, 6108985600 );
  496. p448_add ( &a->y, &L8, &L7 );
  497. p448_mulw ( &L8, &L2, 6109454568 );
  498. p448_sub ( &L7, &a->y, &L8 );
  499. p448_mulw ( &L4, &a->y, 78160 );
  500. p448_mul ( &L6, &L7, &L9 );
  501. p448_mul ( &L8, &L6, &L4 );
  502. p448_mul ( &L4, &L7, &L8 );
  503. p448_isr ( &L5, &L4 );
  504. p448_mul ( &L4, &L6, &L5 );
  505. p448_sqr ( &L6, &L5 );
  506. p448_mul ( &L5, &L8, &L6 );
  507. p448_mul ( &L8, &L7, &L5 );
  508. p448_mul ( &L7, &L8, &L5 );
  509. p448_copy ( &L6, &a->x );
  510. p448_subw ( &L6, 1 );
  511. p448_addw ( &a->x, 1 );
  512. p448_mul ( &L5, &a->x, &L8 );
  513. p448_sub ( &a->x, &L6, &L5 );
  514. p448_bias ( &a->x, 3 );
  515. p448_mul ( &L5, &L4, &a->x );
  516. p448_mulw ( &L4, &L5, 78160 );
  517. p448_neg ( &a->x, &L4 );
  518. p448_bias ( &a->x, 2 );
  519. p448_weak_reduce( &a->x );
  520. p448_add ( &L4, &L3, &L3 );
  521. p448_add ( &L3, &L4, &L2 );
  522. p448_subw ( &L3, 2 );
  523. p448_mul ( &L2, &L3, &L8 );
  524. p448_mulw ( &L3, &L2, 3054649120 );
  525. p448_add ( &L2, &L3, &a->y );
  526. p448_mul ( &a->y, &L7, &L2 );
  527. L1 = p448_is_zero( &L9 );
  528. L0 = - L1;
  529. p448_addw ( &a->y, L0 );
  530. p448_weak_reduce( &a->y );
  531. }
  532. mask_t
  533. p448_affine_validate (
  534. const struct affine_t* a
  535. ) {
  536. struct p448_t L0, L1, L2, L3;
  537. p448_sqr ( &L0, &a->y );
  538. p448_sqr ( &L2, &a->x );
  539. p448_add ( &L3, &L2, &L0 );
  540. p448_subw ( &L3, 1 );
  541. p448_mulw ( &L1, &L2, 39081 );
  542. p448_neg ( &L2, &L1 );
  543. p448_bias ( &L2, 2 );
  544. p448_mul ( &L1, &L0, &L2 );
  545. p448_sub ( &L0, &L3, &L1 );
  546. p448_bias ( &L0, 3 );
  547. return p448_is_zero( &L0 );
  548. }
  549. mask_t
  550. p448_tw_extensible_validate (
  551. const struct tw_extensible_t* ext
  552. ) {
  553. mask_t L0, L1;
  554. struct p448_t L2, L3, L4, L5;
  555. /*
  556. * Check invariant:
  557. * 0 = -x*y + z*t*u
  558. */
  559. p448_mul ( &L2, &ext->t, &ext->u );
  560. p448_mul ( &L4, &ext->z, &L2 );
  561. p448_addw ( &L4, 0 );
  562. p448_mul ( &L3, &ext->x, &ext->y );
  563. p448_neg ( &L2, &L3 );
  564. p448_add ( &L3, &L2, &L4 );
  565. p448_bias ( &L3, 2 );
  566. L1 = p448_is_zero( &L3 );
  567. /*
  568. * Check invariant:
  569. * 0 = d*t^2*u^2 + x^2 - y^2 + z^2 - t^2*u^2
  570. */
  571. p448_sqr ( &L4, &ext->y );
  572. p448_neg ( &L2, &L4 );
  573. p448_addw ( &L2, 0 );
  574. p448_sqr ( &L3, &ext->x );
  575. p448_bias ( &L3, 4 );
  576. p448_add ( &L4, &L3, &L2 );
  577. p448_sqr ( &L5, &ext->u );
  578. p448_sqr ( &L3, &ext->t );
  579. p448_mul ( &L2, &L3, &L5 );
  580. p448_mulw ( &L3, &L2, 39081 );
  581. p448_neg ( &L5, &L3 );
  582. p448_add ( &L3, &L5, &L4 );
  583. p448_neg ( &L5, &L2 );
  584. p448_add ( &L4, &L5, &L3 );
  585. p448_sqr ( &L3, &ext->z );
  586. p448_add ( &L2, &L3, &L4 );
  587. L0 = p448_is_zero( &L2 );
  588. return L1 & L0;
  589. }