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.
 
 
 
 
 

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