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.
 
 
 
 
 

725 lines
22 KiB

  1. /**
  2. * @file decaf/point_448.h
  3. * @author Mike Hamburg
  4. *
  5. * @copyright
  6. * Copyright (c) 2015-2016 Cryptography Research, Inc. \n
  7. * Released under the MIT License. See LICENSE.txt for license information.
  8. *
  9. * @brief A group of prime order p, based on Ed448-Goldilocks.
  10. *
  11. * @warning This file was automatically generated in Python.
  12. * Please do not edit it.
  13. */
  14. #ifndef __DECAF_POINT_448_H__
  15. #define __DECAF_POINT_448_H__ 1
  16. #include <decaf/common.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /** @cond internal */
  21. #define DECAF_448_SCALAR_LIMBS ((446-1)/DECAF_WORD_BITS+1)
  22. /** @endcond */
  23. /** The number of bits in a scalar */
  24. #define DECAF_448_SCALAR_BITS 446
  25. /** @cond internal */
  26. #ifndef __DECAF_448_GF_DEFINED__
  27. #define __DECAF_448_GF_DEFINED__ 1
  28. /** @brief Galois field element internal structure */
  29. typedef struct gf_448_s {
  30. decaf_word_t limb[512/DECAF_WORD_BITS];
  31. } __attribute__((aligned(32))) gf_448_s, gf_448_t[1];
  32. #endif /* __DECAF_448_GF_DEFINED__ */
  33. /** @endcond */
  34. /** Number of bytes in a serialized point. */
  35. #define DECAF_448_SER_BYTES 56
  36. /** Number of bytes in an elligated point. For now set the same as SER_BYTES
  37. * but could be different for other curves.
  38. */
  39. #define DECAF_448_HASH_BYTES 56
  40. /** Number of bytes in a serialized scalar. */
  41. #define DECAF_448_SCALAR_BYTES 56
  42. /** Number of bits in the "which" field of an elligator inverse */
  43. #define DECAF_448_INVERT_ELLIGATOR_WHICH_BITS 3
  44. /** Number of bytes in an x448 public key */
  45. #define DECAF_X448_PUBLIC_BYTES 56
  46. /** Number of bytes in an x448 private key */
  47. #define DECAF_X448_PRIVATE_BYTES 56
  48. /** Twisted Edwards extended homogeneous coordinates */
  49. typedef struct decaf_448_point_s {
  50. /** @cond internal */
  51. gf_448_t x,y,z,t;
  52. /** @endcond */
  53. } decaf_448_point_t[1];
  54. /** Precomputed table based on a point. Can be trivial implementation. */
  55. struct decaf_448_precomputed_s;
  56. /** Precomputed table based on a point. Can be trivial implementation. */
  57. typedef struct decaf_448_precomputed_s decaf_448_precomputed_s;
  58. /** Size and alignment of precomputed point tables. */
  59. extern const size_t decaf_448_sizeof_precomputed_s DECAF_API_VIS, decaf_448_alignof_precomputed_s DECAF_API_VIS;
  60. /** Scalar is stored packed, because we don't need the speed. */
  61. typedef struct decaf_448_scalar_s {
  62. /** @cond internal */
  63. decaf_word_t limb[DECAF_448_SCALAR_LIMBS];
  64. /** @endcond */
  65. } decaf_448_scalar_t[1];
  66. /** A scalar equal to 1. */
  67. extern const decaf_448_scalar_t decaf_448_scalar_one DECAF_API_VIS;
  68. /** A scalar equal to 0. */
  69. extern const decaf_448_scalar_t decaf_448_scalar_zero DECAF_API_VIS;
  70. /** The identity point on the curve. */
  71. extern const decaf_448_point_t decaf_448_point_identity DECAF_API_VIS;
  72. /** An arbitrarily chosen base point on the curve. */
  73. extern const decaf_448_point_t decaf_448_point_base DECAF_API_VIS;
  74. /** Precomputed table for the base point on the curve. */
  75. extern const struct decaf_448_precomputed_s *decaf_448_precomputed_base DECAF_API_VIS;
  76. /**
  77. * @brief Read a scalar from wire format or from bytes.
  78. *
  79. * @param [in] ser Serialized form of a scalar.
  80. * @param [out] out Deserialized form.
  81. *
  82. * @retval DECAF_SUCCESS The scalar was correctly encoded.
  83. * @retval DECAF_FAILURE The scalar was greater than the modulus,
  84. * and has been reduced modulo that modulus.
  85. */
  86. decaf_error_t decaf_448_scalar_decode (
  87. decaf_448_scalar_t out,
  88. const unsigned char ser[DECAF_448_SCALAR_BYTES]
  89. ) DECAF_API_VIS DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE;
  90. /**
  91. * @brief Read a scalar from wire format or from bytes. Reduces mod
  92. * scalar prime.
  93. *
  94. * @param [in] ser Serialized form of a scalar.
  95. * @param [in] ser_len Length of serialized form.
  96. * @param [out] out Deserialized form.
  97. */
  98. void decaf_448_scalar_decode_long (
  99. decaf_448_scalar_t out,
  100. const unsigned char *ser,
  101. size_t ser_len
  102. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  103. /**
  104. * @brief Serialize a scalar to wire format.
  105. *
  106. * @param [out] ser Serialized form of a scalar.
  107. * @param [in] s Deserialized scalar.
  108. */
  109. void decaf_448_scalar_encode (
  110. unsigned char ser[DECAF_448_SCALAR_BYTES],
  111. const decaf_448_scalar_t s
  112. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE DECAF_NOINLINE;
  113. /**
  114. * @brief Add two scalars. The scalars may use the same memory.
  115. * @param [in] a One scalar.
  116. * @param [in] b Another scalar.
  117. * @param [out] out a+b.
  118. */
  119. void decaf_448_scalar_add (
  120. decaf_448_scalar_t out,
  121. const decaf_448_scalar_t a,
  122. const decaf_448_scalar_t b
  123. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  124. /**
  125. * @brief Compare two scalars.
  126. * @param [in] a One scalar.
  127. * @param [in] b Another scalar.
  128. * @retval DECAF_TRUE The scalars are equal.
  129. * @retval DECAF_FALSE The scalars are not equal.
  130. */
  131. decaf_bool_t decaf_448_scalar_eq (
  132. const decaf_448_scalar_t a,
  133. const decaf_448_scalar_t b
  134. ) DECAF_API_VIS DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE;
  135. /**
  136. * @brief Subtract two scalars. The scalars may use the same memory.
  137. * @param [in] a One scalar.
  138. * @param [in] b Another scalar.
  139. * @param [out] out a-b.
  140. */
  141. void decaf_448_scalar_sub (
  142. decaf_448_scalar_t out,
  143. const decaf_448_scalar_t a,
  144. const decaf_448_scalar_t b
  145. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  146. /**
  147. * @brief Multiply two scalars. The scalars may use the same memory.
  148. * @param [in] a One scalar.
  149. * @param [in] b Another scalar.
  150. * @param [out] out a*b.
  151. */
  152. void decaf_448_scalar_mul (
  153. decaf_448_scalar_t out,
  154. const decaf_448_scalar_t a,
  155. const decaf_448_scalar_t b
  156. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  157. /**
  158. * @brief Halve a scalar. The scalars may use the same memory.
  159. * @param [in] a A scalar.
  160. * @param [out] out a/2.
  161. */
  162. void decaf_448_scalar_halve (
  163. decaf_448_scalar_t out,
  164. const decaf_448_scalar_t a
  165. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  166. /**
  167. * @brief Invert a scalar. When passed zero, return 0. The input and output may alias.
  168. * @param [in] a A scalar.
  169. * @param [out] out 1/a.
  170. * @return DECAF_SUCCESS The input is nonzero.
  171. */
  172. decaf_error_t decaf_448_scalar_invert (
  173. decaf_448_scalar_t out,
  174. const decaf_448_scalar_t a
  175. ) DECAF_API_VIS DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE;
  176. /**
  177. * @brief Copy a scalar. The scalars may use the same memory, in which
  178. * case this function does nothing.
  179. * @param [in] a A scalar.
  180. * @param [out] out Will become a copy of a.
  181. */
  182. static inline void DECAF_NONNULL decaf_448_scalar_copy (
  183. decaf_448_scalar_t out,
  184. const decaf_448_scalar_t a
  185. ) {
  186. *out = *a;
  187. }
  188. /**
  189. * @brief Set a scalar to an unsigned 64-bit integer.
  190. * @param [in] a An integer.
  191. * @param [out] out Will become equal to a.
  192. */
  193. void decaf_448_scalar_set_unsigned (
  194. decaf_448_scalar_t out,
  195. uint64_t a
  196. ) DECAF_API_VIS DECAF_NONNULL;
  197. /**
  198. * @brief Encode a point as a sequence of bytes.
  199. *
  200. * @param [out] ser The byte representation of the point.
  201. * @param [in] pt The point to encode.
  202. */
  203. void decaf_448_point_encode (
  204. uint8_t ser[DECAF_448_SER_BYTES],
  205. const decaf_448_point_t pt
  206. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  207. /**
  208. * @brief Decode a point from a sequence of bytes.
  209. *
  210. * Every point has a unique encoding, so not every
  211. * sequence of bytes is a valid encoding. If an invalid
  212. * encoding is given, the output is undefined.
  213. *
  214. * @param [out] pt The decoded point.
  215. * @param [in] ser The serialized version of the point.
  216. * @param [in] allow_identity DECAF_TRUE if the identity is a legal input.
  217. * @retval DECAF_SUCCESS The decoding succeeded.
  218. * @retval DECAF_FAILURE The decoding didn't succeed, because
  219. * ser does not represent a point.
  220. */
  221. decaf_error_t decaf_448_point_decode (
  222. decaf_448_point_t pt,
  223. const uint8_t ser[DECAF_448_SER_BYTES],
  224. decaf_bool_t allow_identity
  225. ) DECAF_API_VIS DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE;
  226. /**
  227. * @brief Copy a point. The input and output may alias,
  228. * in which case this function does nothing.
  229. *
  230. * @param [out] a A copy of the point.
  231. * @param [in] b Any point.
  232. */
  233. static inline void DECAF_NONNULL decaf_448_point_copy (
  234. decaf_448_point_t a,
  235. const decaf_448_point_t b
  236. ) {
  237. *a=*b;
  238. }
  239. /**
  240. * @brief Test whether two points are equal. If yes, return
  241. * DECAF_TRUE, else return DECAF_FALSE.
  242. *
  243. * @param [in] a A point.
  244. * @param [in] b Another point.
  245. * @retval DECAF_TRUE The points are equal.
  246. * @retval DECAF_FALSE The points are not equal.
  247. */
  248. decaf_bool_t decaf_448_point_eq (
  249. const decaf_448_point_t a,
  250. const decaf_448_point_t b
  251. ) DECAF_API_VIS DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE;
  252. /**
  253. * @brief Add two points to produce a third point. The
  254. * input points and output point can be pointers to the same
  255. * memory.
  256. *
  257. * @param [out] sum The sum a+b.
  258. * @param [in] a An addend.
  259. * @param [in] b An addend.
  260. */
  261. void decaf_448_point_add (
  262. decaf_448_point_t sum,
  263. const decaf_448_point_t a,
  264. const decaf_448_point_t b
  265. ) DECAF_API_VIS DECAF_NONNULL;
  266. /**
  267. * @brief Double a point. Equivalent to
  268. * decaf_448_point_add(two_a,a,a), but potentially faster.
  269. *
  270. * @param [out] two_a The sum a+a.
  271. * @param [in] a A point.
  272. */
  273. void decaf_448_point_double (
  274. decaf_448_point_t two_a,
  275. const decaf_448_point_t a
  276. ) DECAF_API_VIS DECAF_NONNULL;
  277. /**
  278. * @brief Subtract two points to produce a third point. The
  279. * input points and output point can be pointers to the same
  280. * memory.
  281. *
  282. * @param [out] diff The difference a-b.
  283. * @param [in] a The minuend.
  284. * @param [in] b The subtrahend.
  285. */
  286. void decaf_448_point_sub (
  287. decaf_448_point_t diff,
  288. const decaf_448_point_t a,
  289. const decaf_448_point_t b
  290. ) DECAF_API_VIS DECAF_NONNULL;
  291. /**
  292. * @brief Negate a point to produce another point. The input
  293. * and output points can use the same memory.
  294. *
  295. * @param [out] nega The negated input point
  296. * @param [in] a The input point.
  297. */
  298. void decaf_448_point_negate (
  299. decaf_448_point_t nega,
  300. const decaf_448_point_t a
  301. ) DECAF_API_VIS DECAF_NONNULL;
  302. /**
  303. * @brief Multiply a base point by a scalar: scaled = scalar*base.
  304. *
  305. * @param [out] scaled The scaled point base*scalar
  306. * @param [in] base The point to be scaled.
  307. * @param [in] scalar The scalar to multiply by.
  308. */
  309. void decaf_448_point_scalarmul (
  310. decaf_448_point_t scaled,
  311. const decaf_448_point_t base,
  312. const decaf_448_scalar_t scalar
  313. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  314. /**
  315. * @brief Multiply a base point by a scalar: scaled = scalar*base.
  316. * This function operates directly on serialized forms.
  317. *
  318. * @warning This function is experimental. It may not be supported
  319. * long-term.
  320. *
  321. * @param [out] scaled The scaled point base*scalar
  322. * @param [in] base The point to be scaled.
  323. * @param [in] scalar The scalar to multiply by.
  324. * @param [in] allow_identity Allow the input to be the identity.
  325. * @param [in] short_circuit Allow a fast return if the input is illegal.
  326. *
  327. * @retval DECAF_SUCCESS The scalarmul succeeded.
  328. * @retval DECAF_FAILURE The scalarmul didn't succeed, because
  329. * base does not represent a point.
  330. */
  331. decaf_error_t decaf_448_direct_scalarmul (
  332. uint8_t scaled[DECAF_448_SER_BYTES],
  333. const uint8_t base[DECAF_448_SER_BYTES],
  334. const decaf_448_scalar_t scalar,
  335. decaf_bool_t allow_identity,
  336. decaf_bool_t short_circuit
  337. ) DECAF_API_VIS DECAF_NONNULL DECAF_WARN_UNUSED DECAF_NOINLINE;
  338. /**
  339. * @brief RFC 7748 Diffie-Hellman scalarmul. This function uses a different
  340. * (non-Decaf) encoding.
  341. *
  342. * @param [out] scaled The scaled point base*scalar
  343. * @param [in] base The point to be scaled.
  344. * @param [in] scalar The scalar to multiply by.
  345. *
  346. * @retval DECAF_SUCCESS The scalarmul succeeded.
  347. * @retval DECAF_FAILURE The scalarmul didn't succeed, because the base
  348. * point is in a small subgroup.
  349. */
  350. decaf_error_t decaf_x448 (
  351. uint8_t out[DECAF_X448_PUBLIC_BYTES],
  352. const uint8_t base[DECAF_X448_PUBLIC_BYTES],
  353. const uint8_t scalar[DECAF_X448_PRIVATE_BYTES]
  354. ) DECAF_API_VIS DECAF_NONNULL DECAF_WARN_UNUSED DECAF_NOINLINE;
  355. /** The base point for X448 Diffie-Hellman */
  356. extern const uint8_t decaf_x448_base_point[DECAF_X448_PUBLIC_BYTES] DECAF_API_VIS;
  357. /**
  358. * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses
  359. * a different (non-Decaf) encoding.
  360. *
  361. * @deprecated Renamed to decaf_x448_derive_public_key.
  362. * I have no particular timeline for removing this name.
  363. *
  364. * @param [out] scaled The scaled point base*scalar
  365. * @param [in] scalar The scalar to multiply by.
  366. */
  367. void decaf_x448_generate_key (
  368. uint8_t out[DECAF_X448_PUBLIC_BYTES],
  369. const uint8_t scalar[DECAF_X448_PRIVATE_BYTES]
  370. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE DECAF_DEPRECATED("Renamed to decaf_x448_derive_public_key");
  371. /**
  372. * @brief RFC 7748 Diffie-Hellman base point scalarmul. This function uses
  373. * a different (non-Decaf) encoding.
  374. *
  375. * Does exactly the same thing as decaf_x448_generate_key,
  376. * but has a better name.
  377. *
  378. * @param [out] scaled The scaled point base*scalar
  379. * @param [in] scalar The scalar to multiply by.
  380. */
  381. void decaf_x448_derive_public_key (
  382. uint8_t out[DECAF_X448_PUBLIC_BYTES],
  383. const uint8_t scalar[DECAF_X448_PRIVATE_BYTES]
  384. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  385. /* FUTURE: uint8_t decaf_448_encode_like_curve448) */
  386. /**
  387. * @brief Precompute a table for fast scalar multiplication.
  388. * Some implementations do not include precomputed points; for
  389. * those implementations, this implementation simply copies the
  390. * point.
  391. *
  392. * @param [out] a A precomputed table of multiples of the point.
  393. * @param [in] b Any point.
  394. */
  395. void decaf_448_precompute (
  396. decaf_448_precomputed_s *a,
  397. const decaf_448_point_t b
  398. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  399. /**
  400. * @brief Multiply a precomputed base point by a scalar:
  401. * scaled = scalar*base.
  402. * Some implementations do not include precomputed points; for
  403. * those implementations, this function is the same as
  404. * decaf_448_point_scalarmul
  405. *
  406. * @param [out] scaled The scaled point base*scalar
  407. * @param [in] base The point to be scaled.
  408. * @param [in] scalar The scalar to multiply by.
  409. */
  410. void decaf_448_precomputed_scalarmul (
  411. decaf_448_point_t scaled,
  412. const decaf_448_precomputed_s *base,
  413. const decaf_448_scalar_t scalar
  414. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  415. /**
  416. * @brief Multiply two base points by two scalars:
  417. * scaled = scalar1*base1 + scalar2*base2.
  418. *
  419. * Equivalent to two calls to decaf_448_point_scalarmul, but may be
  420. * faster.
  421. *
  422. * @param [out] combo The linear combination scalar1*base1 + scalar2*base2.
  423. * @param [in] base1 A first point to be scaled.
  424. * @param [in] scalar1 A first scalar to multiply by.
  425. * @param [in] base2 A second point to be scaled.
  426. * @param [in] scalar2 A second scalar to multiply by.
  427. */
  428. void decaf_448_point_double_scalarmul (
  429. decaf_448_point_t combo,
  430. const decaf_448_point_t base1,
  431. const decaf_448_scalar_t scalar1,
  432. const decaf_448_point_t base2,
  433. const decaf_448_scalar_t scalar2
  434. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  435. /**
  436. * Multiply one base point by two scalars:
  437. *
  438. * a1 = scalar1 * base
  439. * a2 = scalar2 * base
  440. *
  441. * Equivalent to two calls to decaf_448_point_scalarmul, but may be
  442. * faster.
  443. *
  444. * @param [out] a1 The first multiple. It may be the same as the input point.
  445. * @param [out] a2 The second multiple. It may be the same as the input point.
  446. * @param [in] base1 A point to be scaled.
  447. * @param [in] scalar1 A first scalar to multiply by.
  448. * @param [in] scalar2 A second scalar to multiply by.
  449. */
  450. void decaf_448_point_dual_scalarmul (
  451. decaf_448_point_t a1,
  452. decaf_448_point_t a2,
  453. const decaf_448_point_t base1,
  454. const decaf_448_scalar_t scalar1,
  455. const decaf_448_scalar_t scalar2
  456. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  457. /**
  458. * @brief Multiply two base points by two scalars:
  459. * scaled = scalar1*decaf_448_point_base + scalar2*base2.
  460. *
  461. * Otherwise equivalent to decaf_448_point_double_scalarmul, but may be
  462. * faster at the expense of being variable time.
  463. *
  464. * @param [out] combo The linear combination scalar1*base + scalar2*base2.
  465. * @param [in] scalar1 A first scalar to multiply by.
  466. * @param [in] base2 A second point to be scaled.
  467. * @param [in] scalar2 A second scalar to multiply by.
  468. *
  469. * @warning: This function takes variable time, and may leak the scalars
  470. * used. It is designed for signature verification.
  471. */
  472. void decaf_448_base_double_scalarmul_non_secret (
  473. decaf_448_point_t combo,
  474. const decaf_448_scalar_t scalar1,
  475. const decaf_448_point_t base2,
  476. const decaf_448_scalar_t scalar2
  477. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  478. /**
  479. * @brief Constant-time decision between two points. If pick_b
  480. * is zero, out = a; else out = b.
  481. *
  482. * @param [out] out The output. It may be the same as either input.
  483. * @param [in] a Any point.
  484. * @param [in] b Any point.
  485. * @param [in] pick_b If nonzero, choose point b.
  486. */
  487. void decaf_448_point_cond_sel (
  488. decaf_448_point_t out,
  489. const decaf_448_point_t a,
  490. const decaf_448_point_t b,
  491. decaf_word_t pick_b
  492. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  493. /**
  494. * @brief Constant-time decision between two scalars. If pick_b
  495. * is zero, out = a; else out = b.
  496. *
  497. * @param [out] out The output. It may be the same as either input.
  498. * @param [in] a Any scalar.
  499. * @param [in] b Any scalar.
  500. * @param [in] pick_b If nonzero, choose scalar b.
  501. */
  502. void decaf_448_scalar_cond_sel (
  503. decaf_448_scalar_t out,
  504. const decaf_448_scalar_t a,
  505. const decaf_448_scalar_t b,
  506. decaf_word_t pick_b
  507. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  508. /**
  509. * @brief Test that a point is valid, for debugging purposes.
  510. *
  511. * @param [in] to_test The point to test.
  512. * @retval DECAF_TRUE The point is valid.
  513. * @retval DECAF_FALSE The point is invalid.
  514. */
  515. decaf_bool_t decaf_448_point_valid (
  516. const decaf_448_point_t to_test
  517. ) DECAF_API_VIS DECAF_WARN_UNUSED DECAF_NONNULL DECAF_NOINLINE;
  518. /**
  519. * @brief Torque a point, for debugging purposes. The output
  520. * will be equal to the input.
  521. *
  522. * @param [out] q The point to torque.
  523. * @param [in] p The point to torque.
  524. */
  525. void decaf_448_point_debugging_torque (
  526. decaf_448_point_t q,
  527. const decaf_448_point_t p
  528. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  529. /**
  530. * @brief Projectively scale a point, for debugging purposes.
  531. * The output will be equal to the input, and will be valid
  532. * even if the factor is zero.
  533. *
  534. * @param [out] q The point to scale.
  535. * @param [in] p The point to scale.
  536. * @param [in] factor Serialized GF factor to scale.
  537. */
  538. void decaf_448_point_debugging_pscale (
  539. decaf_448_point_t q,
  540. const decaf_448_point_t p,
  541. const unsigned char factor[DECAF_448_SER_BYTES]
  542. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  543. /**
  544. * @brief Almost-Elligator-like hash to curve.
  545. *
  546. * Call this function with the output of a hash to make a hash to the curve.
  547. *
  548. * This function runs Elligator2 on the decaf_448 Jacobi quartic model. It then
  549. * uses the isogeny to put the result in twisted Edwards form. As a result,
  550. * it is safe (cannot produce points of order 4), and would be compatible with
  551. * hypothetical other implementations of Decaf using a Montgomery or untwisted
  552. * Edwards model.
  553. *
  554. * Unlike Elligator, this function may be up to 4:1 on [0,(p-1)/2]:
  555. * A factor of 2 due to the isogeny.
  556. * A factor of 2 because we quotient out the 2-torsion.
  557. *
  558. * This makes it about 8:1 overall, or 16:1 overall on curves with cofactor 8.
  559. *
  560. * Negating the input (mod q) results in the same point. Inverting the input
  561. * (mod q) results in the negative point. This is the same as Elligator.
  562. *
  563. * This function isn't quite indifferentiable from a random oracle.
  564. * However, it is suitable for many protocols, including SPEKE and SPAKE2 EE.
  565. * Furthermore, calling it twice with independent seeds and adding the results
  566. * is indifferentiable from a random oracle.
  567. *
  568. * @param [in] hashed_data Output of some hash function.
  569. * @param [out] pt The data hashed to the curve.
  570. */
  571. void
  572. decaf_448_point_from_hash_nonuniform (
  573. decaf_448_point_t pt,
  574. const unsigned char hashed_data[DECAF_448_HASH_BYTES]
  575. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  576. /**
  577. * @brief Indifferentiable hash function encoding to curve.
  578. *
  579. * Equivalent to calling decaf_448_point_from_hash_nonuniform twice and adding.
  580. *
  581. * @param [in] hashed_data Output of some hash function.
  582. * @param [out] pt The data hashed to the curve.
  583. */
  584. void decaf_448_point_from_hash_uniform (
  585. decaf_448_point_t pt,
  586. const unsigned char hashed_data[2*DECAF_448_HASH_BYTES]
  587. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  588. /**
  589. * @brief Inverse of elligator-like hash to curve.
  590. *
  591. * This function writes to the buffer, to make it so that
  592. * decaf_448_point_from_hash_nonuniform(buffer) = pt if
  593. * possible. Since there may be multiple preimages, the
  594. * "which" parameter chooses between them. To ensure uniform
  595. * inverse sampling, this function succeeds or fails
  596. * independently for different "which" values.
  597. *
  598. * @param [out] recovered_hash Encoded data.
  599. * @param [in] pt The point to encode.
  600. * @param [in] which A value determining which inverse point
  601. * to return.
  602. *
  603. * @retval DECAF_SUCCESS The inverse succeeded.
  604. * @retval DECAF_FAILURE The inverse failed.
  605. */
  606. decaf_error_t
  607. decaf_448_invert_elligator_nonuniform (
  608. unsigned char recovered_hash[DECAF_448_HASH_BYTES],
  609. const decaf_448_point_t pt,
  610. uint32_t which
  611. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE DECAF_WARN_UNUSED;
  612. /**
  613. * @brief Inverse of elligator-like hash to curve.
  614. *
  615. * This function writes to the buffer, to make it so that
  616. * decaf_448_point_from_hash_uniform(buffer) = pt if
  617. * possible. Since there may be multiple preimages, the
  618. * "which" parameter chooses between them. To ensure uniform
  619. * inverse sampling, this function succeeds or fails
  620. * independently for different "which" values.
  621. *
  622. * @param [out] recovered_hash Encoded data.
  623. * @param [in] pt The point to encode.
  624. * @param [in] which A value determining which inverse point
  625. * to return.
  626. *
  627. * @retval DECAF_SUCCESS The inverse succeeded.
  628. * @retval DECAF_FAILURE The inverse failed.
  629. */
  630. decaf_error_t
  631. decaf_448_invert_elligator_uniform (
  632. unsigned char recovered_hash[2*DECAF_448_HASH_BYTES],
  633. const decaf_448_point_t pt,
  634. uint32_t which
  635. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE DECAF_WARN_UNUSED;
  636. /**
  637. * @brief Overwrite scalar with zeros.
  638. */
  639. void decaf_448_scalar_destroy (
  640. decaf_448_scalar_t scalar
  641. ) DECAF_NONNULL DECAF_API_VIS;
  642. /**
  643. * @brief Overwrite point with zeros.
  644. */
  645. void decaf_448_point_destroy (
  646. decaf_448_point_t point
  647. ) DECAF_NONNULL DECAF_API_VIS;
  648. /**
  649. * @brief Overwrite precomputed table with zeros.
  650. */
  651. void decaf_448_precomputed_destroy (
  652. decaf_448_precomputed_s *pre
  653. ) DECAF_NONNULL DECAF_API_VIS;
  654. #ifdef __cplusplus
  655. } /* extern "C" */
  656. #endif
  657. #endif /* __DECAF_POINT_448_H__ */