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.
 
 
 
 
 

441 lines
8.2 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. #ifndef __CC_INCLUDED_P448_EDWARDS_H__
  6. #define __CC_INCLUDED_P448_EDWARDS_H__
  7. #include "p448.h"
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /*
  12. * Affine point on an Edwards curve.
  13. */
  14. struct affine_t {
  15. struct p448_t x, y;
  16. };
  17. /*
  18. * Affine point on a twisted Edwards curve.
  19. */
  20. struct tw_affine_t {
  21. struct p448_t x, y;
  22. };
  23. /*
  24. * Montgomery buffer.
  25. */
  26. struct montgomery_t {
  27. struct p448_t z0, xd, zd, xa, za;
  28. };
  29. /*
  30. * Extensible coordinates for Edwards curves, suitable for
  31. * accumulators.
  32. *
  33. * Represents the point (x/z, y/z). The extra coordinates
  34. * t,u satisfy xy = tuz, allowing for conversion to Extended
  35. * form by multiplying t and u.
  36. *
  37. * The idea is that you don't have to do this multiplication
  38. * when doubling the accumulator, because the t-coordinate
  39. * isn't used there. At the same time, as long as you only
  40. * have one point in extensible form, additions don't cost
  41. * extra.
  42. *
  43. * This is essentially a lazier version of Hisil et al's
  44. * lookahead trick. It might be worth considering that trick
  45. * instead.
  46. */
  47. struct extensible_t {
  48. struct p448_t x, y, z, t, u;
  49. };
  50. /*
  51. * Extensible coordinates for twisted Edwards curves,
  52. * suitable for accumulators.
  53. */
  54. struct tw_extensible_t {
  55. struct p448_t x, y, z, t, u;
  56. };
  57. /*
  58. * Niels coordinates for twisted Edwards curves. Good for
  59. * mixed readdition; suitable for fixed tables.
  60. */
  61. struct tw_niels_t {
  62. struct p448_t a, b, c;
  63. };
  64. /*
  65. * Projective niels coordinates for twisted Edwards curves.
  66. * Good for readdition; suitable for temporary tables.
  67. */
  68. struct tw_pniels_t {
  69. struct tw_niels_t n;
  70. struct p448_t z;
  71. };
  72. /*
  73. * Auto-generated copy method.
  74. */
  75. static __inline__ void
  76. copy_affine (
  77. struct affine_t* a,
  78. const struct affine_t* ds
  79. ) __attribute__((unused,always_inline));
  80. /*
  81. * Auto-generated copy method.
  82. */
  83. static __inline__ void
  84. copy_tw_affine (
  85. struct tw_affine_t* a,
  86. const struct tw_affine_t* ds
  87. ) __attribute__((unused,always_inline));
  88. /*
  89. * Auto-generated copy method.
  90. */
  91. static __inline__ void
  92. copy_montgomery (
  93. struct montgomery_t* a,
  94. const struct montgomery_t* ds
  95. ) __attribute__((unused,always_inline));
  96. /*
  97. * Auto-generated copy method.
  98. */
  99. static __inline__ void
  100. copy_extensible (
  101. struct extensible_t* a,
  102. const struct extensible_t* ds
  103. ) __attribute__((unused,always_inline));
  104. /*
  105. * Auto-generated copy method.
  106. */
  107. static __inline__ void
  108. copy_tw_extensible (
  109. struct tw_extensible_t* a,
  110. const struct tw_extensible_t* ds
  111. ) __attribute__((unused,always_inline));
  112. /*
  113. * Auto-generated copy method.
  114. */
  115. static __inline__ void
  116. copy_tw_niels (
  117. struct tw_niels_t* a,
  118. const struct tw_niels_t* ds
  119. ) __attribute__((unused,always_inline));
  120. /*
  121. * Auto-generated copy method.
  122. */
  123. static __inline__ void
  124. copy_tw_pniels (
  125. struct tw_pniels_t* a,
  126. const struct tw_pniels_t* ds
  127. ) __attribute__((unused,always_inline));
  128. /*
  129. * Returns 1/sqrt(+- x).
  130. *
  131. * The Legendre symbol of the result is the same as that of the
  132. * input.
  133. *
  134. * If x=0, returns 0.
  135. */
  136. void
  137. p448_isr (
  138. struct p448_t* a,
  139. const struct p448_t* x
  140. );
  141. /*
  142. * Returns 1/x.
  143. *
  144. * If x=0, returns 0.
  145. */
  146. void
  147. p448_inverse (
  148. struct p448_t* a,
  149. const struct p448_t* x
  150. );
  151. /*
  152. * Add two points on a twisted Edwards curve, one in Extensible form
  153. * and the other in half-Niels form.
  154. */
  155. void
  156. p448_tw_extensible_add_niels (
  157. struct tw_extensible_t* d,
  158. const struct tw_niels_t* e
  159. );
  160. /*
  161. * Add two points on a twisted Edwards curve, one in Extensible form
  162. * and the other in projective Niels form.
  163. */
  164. void
  165. p448_tw_extensible_add_pniels (
  166. struct tw_extensible_t* e,
  167. const struct tw_pniels_t* a
  168. );
  169. /*
  170. * Double a point on a twisted Edwards curve, in "extensible" coordinates.
  171. */
  172. void
  173. p448_tw_extensible_double (
  174. struct tw_extensible_t* a
  175. );
  176. /*
  177. * Double a point on an Edwards curve, in "extensible" coordinates.
  178. */
  179. void
  180. p448_extensible_double (
  181. struct extensible_t* a
  182. );
  183. /*
  184. * 4-isogeny from untwisted to twisted.
  185. */
  186. void
  187. p448_isogeny_un_to_tw (
  188. struct tw_extensible_t* b,
  189. const struct extensible_t* a
  190. );
  191. /*
  192. * Dual 4-isogeny from twisted to untwisted.
  193. */
  194. void
  195. p448_isogeny_tw_to_un (
  196. struct extensible_t* b,
  197. const struct tw_extensible_t* a
  198. );
  199. void
  200. convert_tw_affine_to_tw_pniels (
  201. struct tw_pniels_t* b,
  202. const struct tw_affine_t* a
  203. );
  204. void
  205. convert_tw_affine_to_tw_extensible (
  206. struct tw_extensible_t* b,
  207. const struct tw_affine_t* a
  208. );
  209. void
  210. convert_affine_to_extensible (
  211. struct extensible_t* b,
  212. const struct affine_t* a
  213. );
  214. void
  215. convert_tw_extensible_to_tw_pniels (
  216. struct tw_pniels_t* b,
  217. const struct tw_extensible_t* a
  218. );
  219. void
  220. convert_tw_pniels_to_tw_extensible (
  221. struct tw_extensible_t* e,
  222. const struct tw_pniels_t* d
  223. );
  224. void
  225. convert_tw_niels_to_tw_extensible (
  226. struct tw_extensible_t* e,
  227. const struct tw_niels_t* d
  228. );
  229. void
  230. p448_montgomery_step (
  231. struct montgomery_t* a
  232. );
  233. void
  234. p448_montgomery_serialize (
  235. struct p448_t* sign,
  236. struct p448_t* ser,
  237. const struct montgomery_t* a,
  238. const struct p448_t* sbz
  239. );
  240. /*
  241. * Serialize a point on an Edwards curve
  242. * The serialized form would be sqrt((z-y)/(z+y)) with sign of xz
  243. * It would be on 4y^2/(1-d) = x^3 + 2(1+d)/(1-d) * x^2 + x.
  244. * But 4/(1-d) isn't square, so we need to twist it:
  245. * -x is on 4y^2/(d-1) = x^3 + 2(d+1)/(d-1) * x^2 + x
  246. */
  247. void
  248. extensible_serialize (
  249. struct p448_t* b,
  250. const struct extensible_t* a
  251. );
  252. /*
  253. *
  254. */
  255. void
  256. isogeny_and_serialize (
  257. struct p448_t* b,
  258. const struct tw_extensible_t* a
  259. );
  260. /*
  261. * Deserialize a point to an untwisted affine curve
  262. */
  263. mask_t
  264. affine_deserialize (
  265. struct affine_t* a,
  266. const struct p448_t* sz
  267. );
  268. void
  269. set_identity_extensible (
  270. struct extensible_t* a
  271. );
  272. void
  273. set_identity_tw_extensible (
  274. struct tw_extensible_t* a
  275. );
  276. void
  277. set_identity_affine (
  278. struct affine_t* a
  279. );
  280. mask_t
  281. eq_affine (
  282. const struct affine_t* a,
  283. const struct affine_t* b
  284. );
  285. mask_t
  286. eq_extensible (
  287. const struct extensible_t* a,
  288. const struct extensible_t* b
  289. );
  290. mask_t
  291. eq_tw_extensible (
  292. const struct tw_extensible_t* a,
  293. const struct tw_extensible_t* b
  294. );
  295. void
  296. elligator_2s_inject (
  297. struct affine_t* a,
  298. const struct p448_t* r
  299. );
  300. mask_t
  301. p448_affine_validate (
  302. const struct affine_t* a
  303. );
  304. /*
  305. * Check the invariants for struct tw_extensible_t.
  306. * PERF: This function was automatically generated
  307. * with no regard for speed.
  308. */
  309. mask_t
  310. p448_tw_extensible_validate (
  311. const struct tw_extensible_t* ext
  312. );
  313. void
  314. copy_affine (
  315. struct affine_t* a,
  316. const struct affine_t* ds
  317. ) {
  318. p448_copy ( &a->x, &ds->x );
  319. p448_copy ( &a->y, &ds->y );
  320. }
  321. void
  322. copy_tw_affine (
  323. struct tw_affine_t* a,
  324. const struct tw_affine_t* ds
  325. ) {
  326. p448_copy ( &a->x, &ds->x );
  327. p448_copy ( &a->y, &ds->y );
  328. }
  329. void
  330. copy_montgomery (
  331. struct montgomery_t* a,
  332. const struct montgomery_t* ds
  333. ) {
  334. p448_copy ( &a->z0, &ds->z0 );
  335. p448_copy ( &a->xd, &ds->xd );
  336. p448_copy ( &a->zd, &ds->zd );
  337. p448_copy ( &a->xa, &ds->xa );
  338. p448_copy ( &a->za, &ds->za );
  339. }
  340. void
  341. copy_extensible (
  342. struct extensible_t* a,
  343. const struct extensible_t* ds
  344. ) {
  345. p448_copy ( &a->x, &ds->x );
  346. p448_copy ( &a->y, &ds->y );
  347. p448_copy ( &a->z, &ds->z );
  348. p448_copy ( &a->t, &ds->t );
  349. p448_copy ( &a->u, &ds->u );
  350. }
  351. void
  352. copy_tw_extensible (
  353. struct tw_extensible_t* a,
  354. const struct tw_extensible_t* ds
  355. ) {
  356. p448_copy ( &a->x, &ds->x );
  357. p448_copy ( &a->y, &ds->y );
  358. p448_copy ( &a->z, &ds->z );
  359. p448_copy ( &a->t, &ds->t );
  360. p448_copy ( &a->u, &ds->u );
  361. }
  362. void
  363. copy_tw_niels (
  364. struct tw_niels_t* a,
  365. const struct tw_niels_t* ds
  366. ) {
  367. p448_copy ( &a->a, &ds->a );
  368. p448_copy ( &a->b, &ds->b );
  369. p448_copy ( &a->c, &ds->c );
  370. }
  371. void
  372. copy_tw_pniels (
  373. struct tw_pniels_t* a,
  374. const struct tw_pniels_t* ds
  375. ) {
  376. copy_tw_niels( &a->n, &ds->n );
  377. p448_copy ( &a->z, &ds->z );
  378. }
  379. #ifdef __cplusplus
  380. }; /* extern "C" */
  381. #endif
  382. #endif /* __CC_INCLUDED_P448_EDWARDS_H__ */