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.
 
 
 
 
 

635 lines
19 KiB

  1. from curve_data import curve_data
  2. from gen_file import gen_file
  3. gen_file(
  4. name = "decaf/%(c_ns)s.h",
  5. doc = """@brief A group of prime order p, based on %(iso_to)s.""",
  6. code = """
  7. #include <decaf/common.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. #define %(C_NS)s_LIMBS (%(gf_bits)d/DECAF_WORD_BITS)
  12. #define %(C_NS)s_SCALAR_BITS %(scalar_bits)d
  13. #define %(C_NS)s_SCALAR_LIMBS ((%(scalar_bits)d-1)/DECAF_WORD_BITS+1)
  14. /** Galois field element internal structure */
  15. #ifndef __%(C_NS)s_GF_DEFINED__
  16. #define __%(C_NS)s_GF_DEFINED__ 1
  17. typedef struct gf_%(longnum)s_s {
  18. /** @cond internal */
  19. decaf_word_t limb[%(C_NS)s_LIMBS];
  20. /** @endcond */
  21. } __attribute__((aligned(32))) gf_%(longnum)s_s, gf_%(longnum)s_t[1];
  22. #endif /* __%(C_NS)s_GF_DEFINED__ */
  23. /** Number of bytes in a serialized point. */
  24. #define %(C_NS)s_SER_BYTES %(ser_bytes)d
  25. /** Number of bytes in a serialized scalar. */
  26. #define %(C_NS)s_SCALAR_BYTES %(scalar_ser_bytes)d
  27. /** Twisted Edwards extended homogeneous coordinates */
  28. typedef struct %(c_ns)s_point_s {
  29. /** @cond internal */
  30. gf_%(longnum)s_t x,y,z,t;
  31. /** @endcond */
  32. } %(c_ns)s_point_t[1];
  33. /** Precomputed table based on a point. Can be trivial implementation. */
  34. struct %(c_ns)s_precomputed_s;
  35. /** Precomputed table based on a point. Can be trivial implementation. */
  36. typedef struct %(c_ns)s_precomputed_s %(c_ns)s_precomputed_s;
  37. /** Size and alignment of precomputed point tables. */
  38. extern const size_t sizeof_%(c_ns)s_precomputed_s API_VIS, alignof_%(c_ns)s_precomputed_s API_VIS;
  39. /** Scalar is stored packed, because we don't need the speed. */
  40. typedef struct %(c_ns)s_scalar_s {
  41. /** @cond internal */
  42. decaf_word_t limb[%(C_NS)s_SCALAR_LIMBS];
  43. /** @endcond */
  44. } %(c_ns)s_scalar_t[1];
  45. /** A scalar equal to 1. */
  46. extern const %(c_ns)s_scalar_t %(c_ns)s_scalar_one API_VIS;
  47. /** A scalar equal to 0. */
  48. extern const %(c_ns)s_scalar_t %(c_ns)s_scalar_zero API_VIS;
  49. /** The identity point on the curve. */
  50. extern const %(c_ns)s_point_t %(c_ns)s_point_identity API_VIS;
  51. /** An arbitrarily chosen base point on the curve. */
  52. extern const %(c_ns)s_point_t %(c_ns)s_point_base API_VIS;
  53. /** Precomputed table for the base point on the curve. */
  54. extern const struct %(c_ns)s_precomputed_s *%(c_ns)s_precomputed_base API_VIS;
  55. /**
  56. * @brief Read a scalar from wire format or from bytes.
  57. *
  58. * @param [in] ser Serialized form of a scalar.
  59. * @param [out] out Deserialized form.
  60. *
  61. * @retval DECAF_SUCCESS The scalar was correctly encoded.
  62. * @retval DECAF_FAILURE The scalar was greater than the modulus,
  63. * and has been reduced modulo that modulus.
  64. */
  65. decaf_error_t %(c_ns)s_scalar_decode (
  66. %(c_ns)s_scalar_t out,
  67. const unsigned char ser[%(C_NS)s_SCALAR_BYTES]
  68. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  69. /**
  70. * @brief Read a scalar from wire format or from bytes. Reduces mod
  71. * scalar prime.
  72. *
  73. * @param [in] ser Serialized form of a scalar.
  74. * @param [in] ser_len Length of serialized form.
  75. * @param [out] out Deserialized form.
  76. */
  77. void %(c_ns)s_scalar_decode_long (
  78. %(c_ns)s_scalar_t out,
  79. const unsigned char *ser,
  80. size_t ser_len
  81. ) API_VIS NONNULL2 NOINLINE;
  82. /**
  83. * @brief Serialize a scalar to wire format.
  84. *
  85. * @param [out] ser Serialized form of a scalar.
  86. * @param [in] s Deserialized scalar.
  87. */
  88. void %(c_ns)s_scalar_encode (
  89. unsigned char ser[%(C_NS)s_SCALAR_BYTES],
  90. const %(c_ns)s_scalar_t s
  91. ) API_VIS NONNULL2 NOINLINE NOINLINE;
  92. /**
  93. * @brief Add two scalars. The scalars may use the same memory.
  94. * @param [in] a One scalar.
  95. * @param [in] b Another scalar.
  96. * @param [out] out a+b.
  97. */
  98. void %(c_ns)s_scalar_add (
  99. %(c_ns)s_scalar_t out,
  100. const %(c_ns)s_scalar_t a,
  101. const %(c_ns)s_scalar_t b
  102. ) API_VIS NONNULL3 NOINLINE;
  103. /**
  104. * @brief Compare two scalars.
  105. * @param [in] a One scalar.
  106. * @param [in] b Another scalar.
  107. * @retval DECAF_TRUE The scalars are equal.
  108. * @retval DECAF_FALSE The scalars are not equal.
  109. */
  110. decaf_bool_t %(c_ns)s_scalar_eq (
  111. const %(c_ns)s_scalar_t a,
  112. const %(c_ns)s_scalar_t b
  113. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  114. /**
  115. * @brief Subtract two scalars. The scalars may use the same memory.
  116. * @param [in] a One scalar.
  117. * @param [in] b Another scalar.
  118. * @param [out] out a-b.
  119. */
  120. void %(c_ns)s_scalar_sub (
  121. %(c_ns)s_scalar_t out,
  122. const %(c_ns)s_scalar_t a,
  123. const %(c_ns)s_scalar_t b
  124. ) API_VIS NONNULL3 NOINLINE;
  125. /**
  126. * @brief Multiply two scalars. The scalars may use the same memory.
  127. * @param [in] a One scalar.
  128. * @param [in] b Another scalar.
  129. * @param [out] out a*b.
  130. */
  131. void %(c_ns)s_scalar_mul (
  132. %(c_ns)s_scalar_t out,
  133. const %(c_ns)s_scalar_t a,
  134. const %(c_ns)s_scalar_t b
  135. ) API_VIS NONNULL3 NOINLINE;
  136. /**
  137. * @brief Invert a scalar. When passed zero, return 0. The input and output may alias.
  138. * @param [in] a A scalar.
  139. * @param [out] out 1/a.
  140. * @return DECAF_SUCCESS The input is nonzero.
  141. */
  142. decaf_error_t %(c_ns)s_scalar_invert (
  143. %(c_ns)s_scalar_t out,
  144. const %(c_ns)s_scalar_t a
  145. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  146. /**
  147. * @brief Copy a scalar. The scalars may use the same memory, in which
  148. * case this function does nothing.
  149. * @param [in] a A scalar.
  150. * @param [out] out Will become a copy of a.
  151. */
  152. static inline void NONNULL2 %(c_ns)s_scalar_copy (
  153. %(c_ns)s_scalar_t out,
  154. const %(c_ns)s_scalar_t a
  155. ) {
  156. *out = *a;
  157. }
  158. /**
  159. * @brief Set a scalar to an unsigned integer.
  160. * @param [in] a An integer.
  161. * @param [out] out Will become equal to a.
  162. */
  163. void %(c_ns)s_scalar_set_unsigned (
  164. %(c_ns)s_scalar_t out,
  165. decaf_word_t a
  166. ) API_VIS NONNULL1;
  167. /**
  168. * @brief Encode a point as a sequence of bytes.
  169. *
  170. * @param [out] ser The byte representation of the point.
  171. * @param [in] pt The point to encode.
  172. */
  173. void %(c_ns)s_point_encode (
  174. uint8_t ser[%(C_NS)s_SER_BYTES],
  175. const %(c_ns)s_point_t pt
  176. ) API_VIS NONNULL2 NOINLINE;
  177. /**
  178. * @brief Decode a point from a sequence of bytes.
  179. *
  180. * Every point has a unique encoding, so not every
  181. * sequence of bytes is a valid encoding. If an invalid
  182. * encoding is given, the output is undefined.
  183. *
  184. * @param [out] pt The decoded point.
  185. * @param [in] ser The serialized version of the point.
  186. * @param [in] allow_identity DECAF_TRUE if the identity is a legal input.
  187. * @retval DECAF_SUCCESS The decoding succeeded.
  188. * @retval DECAF_FAILURE The decoding didn't succeed, because
  189. * ser does not represent a point.
  190. */
  191. decaf_error_t %(c_ns)s_point_decode (
  192. %(c_ns)s_point_t pt,
  193. const uint8_t ser[%(C_NS)s_SER_BYTES],
  194. decaf_bool_t allow_identity
  195. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  196. /**
  197. * @brief Copy a point. The input and output may alias,
  198. * in which case this function does nothing.
  199. *
  200. * @param [out] a A copy of the point.
  201. * @param [in] b Any point.
  202. */
  203. static inline void NONNULL2 %(c_ns)s_point_copy (
  204. %(c_ns)s_point_t a,
  205. const %(c_ns)s_point_t b
  206. ) {
  207. *a=*b;
  208. }
  209. /**
  210. * @brief Test whether two points are equal. If yes, return
  211. * DECAF_TRUE, else return DECAF_FALSE.
  212. *
  213. * @param [in] a A point.
  214. * @param [in] b Another point.
  215. * @retval DECAF_TRUE The points are equal.
  216. * @retval DECAF_FALSE The points are not equal.
  217. */
  218. decaf_bool_t %(c_ns)s_point_eq (
  219. const %(c_ns)s_point_t a,
  220. const %(c_ns)s_point_t b
  221. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  222. /**
  223. * @brief Add two points to produce a third point. The
  224. * input points and output point can be pointers to the same
  225. * memory.
  226. *
  227. * @param [out] sum The sum a+b.
  228. * @param [in] a An addend.
  229. * @param [in] b An addend.
  230. */
  231. void %(c_ns)s_point_add (
  232. %(c_ns)s_point_t sum,
  233. const %(c_ns)s_point_t a,
  234. const %(c_ns)s_point_t b
  235. ) API_VIS NONNULL3;
  236. /**
  237. * @brief Double a point. Equivalent to
  238. * %(c_ns)s_point_add(two_a,a,a), but potentially faster.
  239. *
  240. * @param [out] two_a The sum a+a.
  241. * @param [in] a A point.
  242. */
  243. void %(c_ns)s_point_double (
  244. %(c_ns)s_point_t two_a,
  245. const %(c_ns)s_point_t a
  246. ) API_VIS NONNULL2;
  247. /**
  248. * @brief Subtract two points to produce a third point. The
  249. * input points and output point can be pointers to the same
  250. * memory.
  251. *
  252. * @param [out] diff The difference a-b.
  253. * @param [in] a The minuend.
  254. * @param [in] b The subtrahend.
  255. */
  256. void %(c_ns)s_point_sub (
  257. %(c_ns)s_point_t diff,
  258. const %(c_ns)s_point_t a,
  259. const %(c_ns)s_point_t b
  260. ) API_VIS NONNULL3;
  261. /**
  262. * @brief Negate a point to produce another point. The input
  263. * and output points can use the same memory.
  264. *
  265. * @param [out] nega The negated input point
  266. * @param [in] a The input point.
  267. */
  268. void %(c_ns)s_point_negate (
  269. %(c_ns)s_point_t nega,
  270. const %(c_ns)s_point_t a
  271. ) API_VIS NONNULL2;
  272. /**
  273. * @brief Multiply a base point by a scalar: scaled = scalar*base.
  274. *
  275. * @param [out] scaled The scaled point base*scalar
  276. * @param [in] base The point to be scaled.
  277. * @param [in] scalar The scalar to multiply by.
  278. */
  279. void %(c_ns)s_point_scalarmul (
  280. %(c_ns)s_point_t scaled,
  281. const %(c_ns)s_point_t base,
  282. const %(c_ns)s_scalar_t scalar
  283. ) API_VIS NONNULL3 NOINLINE;
  284. /**
  285. * @brief Multiply a base point by a scalar: scaled = scalar*base.
  286. * This function operates directly on serialized forms.
  287. *
  288. * @warning This function is experimental. It may not be supported
  289. * long-term.
  290. *
  291. * @param [out] scaled The scaled point base*scalar
  292. * @param [in] base The point to be scaled.
  293. * @param [in] scalar The scalar to multiply by.
  294. * @param [in] allow_identity Allow the input to be the identity.
  295. * @param [in] short_circuit Allow a fast return if the input is illegal.
  296. *
  297. * @retval DECAF_SUCCESS The scalarmul succeeded.
  298. * @retval DECAF_FAILURE The scalarmul didn't succeed, because
  299. * base does not represent a point.
  300. */
  301. decaf_error_t %(c_ns)s_direct_scalarmul (
  302. uint8_t scaled[%(C_NS)s_SER_BYTES],
  303. const uint8_t base[%(C_NS)s_SER_BYTES],
  304. const %(c_ns)s_scalar_t scalar,
  305. decaf_bool_t allow_identity,
  306. decaf_bool_t short_circuit
  307. ) API_VIS NONNULL3 WARN_UNUSED NOINLINE;
  308. /**
  309. * @brief Precompute a table for fast scalar multiplication.
  310. * Some implementations do not include precomputed points; for
  311. * those implementations, this implementation simply copies the
  312. * point.
  313. *
  314. * @param [out] a A precomputed table of multiples of the point.
  315. * @param [in] b Any point.
  316. */
  317. void %(c_ns)s_precompute (
  318. %(c_ns)s_precomputed_s *a,
  319. const %(c_ns)s_point_t b
  320. ) API_VIS NONNULL2 NOINLINE;
  321. /**
  322. * @brief Multiply a precomputed base point by a scalar:
  323. * scaled = scalar*base.
  324. * Some implementations do not include precomputed points; for
  325. * those implementations, this function is the same as
  326. * %(c_ns)s_point_scalarmul
  327. *
  328. * @param [out] scaled The scaled point base*scalar
  329. * @param [in] base The point to be scaled.
  330. * @param [in] scalar The scalar to multiply by.
  331. */
  332. void %(c_ns)s_precomputed_scalarmul (
  333. %(c_ns)s_point_t scaled,
  334. const %(c_ns)s_precomputed_s *base,
  335. const %(c_ns)s_scalar_t scalar
  336. ) API_VIS NONNULL3 NOINLINE;
  337. /**
  338. * @brief Multiply two base points by two scalars:
  339. * scaled = scalar1*base1 + scalar2*base2.
  340. *
  341. * Equivalent to two calls to %(c_ns)s_point_scalarmul, but may be
  342. * faster.
  343. *
  344. * @param [out] combo The linear combination scalar1*base1 + scalar2*base2.
  345. * @param [in] base1 A first point to be scaled.
  346. * @param [in] scalar1 A first scalar to multiply by.
  347. * @param [in] base2 A second point to be scaled.
  348. * @param [in] scalar2 A second scalar to multiply by.
  349. */
  350. void %(c_ns)s_point_double_scalarmul (
  351. %(c_ns)s_point_t combo,
  352. const %(c_ns)s_point_t base1,
  353. const %(c_ns)s_scalar_t scalar1,
  354. const %(c_ns)s_point_t base2,
  355. const %(c_ns)s_scalar_t scalar2
  356. ) API_VIS NONNULL5 NOINLINE;
  357. /*
  358. * @brief Multiply one base point by two scalars:
  359. * a1 = scalar1 * base
  360. * a2 = scalar2 * base
  361. *
  362. * Equivalent to two calls to %(c_ns)s_point_scalarmul, but may be
  363. * faster.
  364. *
  365. * @param [out] a1 The first multiple
  366. * @param [out] a2 The second multiple
  367. * @param [in] base1 A point to be scaled.
  368. * @param [in] scalar1 A first scalar to multiply by.
  369. * @param [in] scalar2 A second scalar to multiply by.
  370. */
  371. void %(c_ns)s_point_dual_scalarmul (
  372. %(c_ns)s_point_t a1,
  373. %(c_ns)s_point_t a2,
  374. const %(c_ns)s_point_t b,
  375. const %(c_ns)s_scalar_t scalar1,
  376. const %(c_ns)s_scalar_t scalar2
  377. ) API_VIS NONNULL5 NOINLINE;
  378. /**
  379. * @brief Multiply two base points by two scalars:
  380. * scaled = scalar1*%(c_ns)s_point_base + scalar2*base2.
  381. *
  382. * Otherwise equivalent to %(c_ns)s_point_double_scalarmul, but may be
  383. * faster at the expense of being variable time.
  384. *
  385. * @param [out] combo The linear combination scalar1*base + scalar2*base2.
  386. * @param [in] scalar1 A first scalar to multiply by.
  387. * @param [in] base2 A second point to be scaled.
  388. * @param [in] scalar2 A second scalar to multiply by.
  389. *
  390. * @warning: This function takes variable time, and may leak the scalars
  391. * used. It is designed for signature verification.
  392. */
  393. void %(c_ns)s_base_double_scalarmul_non_secret (
  394. %(c_ns)s_point_t combo,
  395. const %(c_ns)s_scalar_t scalar1,
  396. const %(c_ns)s_point_t base2,
  397. const %(c_ns)s_scalar_t scalar2
  398. ) API_VIS NONNULL4 NOINLINE;
  399. /**
  400. * @brief Constant-time decision between two points. If pick_b
  401. * is zero, out = a; else out = b.
  402. *
  403. * @param [out] q The output. It may be the same as either input.
  404. * @param [in] a Any point.
  405. * @param [in] b Any point.
  406. * @param [in] pick_b If nonzero, choose point b.
  407. */
  408. void %(c_ns)s_point_cond_sel (
  409. %(c_ns)s_point_t out,
  410. const %(c_ns)s_point_t a,
  411. const %(c_ns)s_point_t b,
  412. decaf_word_t pick_b
  413. ) API_VIS NONNULL3 NOINLINE;
  414. /**
  415. * @brief Constant-time decision between two scalars. If pick_b
  416. * is zero, out = a; else out = b.
  417. *
  418. * @param [out] q The output. It may be the same as either input.
  419. * @param [in] a Any scalar.
  420. * @param [in] b Any scalar.
  421. * @param [in] pick_b If nonzero, choose scalar b.
  422. */
  423. void %(c_ns)s_scalar_cond_sel (
  424. %(c_ns)s_scalar_t out,
  425. const %(c_ns)s_scalar_t a,
  426. const %(c_ns)s_scalar_t b,
  427. decaf_word_t pick_b
  428. ) API_VIS NONNULL3 NOINLINE;
  429. /**
  430. * @brief Test that a point is valid, for debugging purposes.
  431. *
  432. * @param [in] toTest The point to test.
  433. * @retval DECAF_TRUE The point is valid.
  434. * @retval DECAF_FALSE The point is invalid.
  435. */
  436. decaf_bool_t %(c_ns)s_point_valid (
  437. const %(c_ns)s_point_t toTest
  438. ) API_VIS WARN_UNUSED NONNULL1 NOINLINE;
  439. /**
  440. * @brief Torque a point, for debugging purposes. The output
  441. * will be equal to the input.
  442. *
  443. * @param [out] q The point to torque.
  444. * @param [in] p The point to torque.
  445. */
  446. void %(c_ns)s_point_debugging_torque (
  447. %(c_ns)s_point_t q,
  448. const %(c_ns)s_point_t p
  449. ) API_VIS NONNULL2 NOINLINE;
  450. /**
  451. * @brief Projectively scale a point, for debugging purposes.
  452. * The output will be equal to the input, and will be valid
  453. * even if the factor is zero.
  454. *
  455. * @param [out] q The point to scale.
  456. * @param [in] p The point to scale.
  457. * @param [in] factor Serialized GF factor to scale.
  458. */
  459. void %(c_ns)s_point_debugging_pscale (
  460. %(c_ns)s_point_t q,
  461. const %(c_ns)s_point_t p,
  462. const unsigned char factor[%(C_NS)s_SER_BYTES]
  463. ) API_VIS NONNULL2 NOINLINE;
  464. /**
  465. * @brief Almost-Elligator-like hash to curve.
  466. *
  467. * Call this function with the output of a hash to make a hash to the curve.
  468. *
  469. * This function runs Elligator2 on the %(c_ns)s Jacobi quartic model. It then
  470. * uses the isogeny to put the result in twisted Edwards form. As a result,
  471. * it is safe (cannot produce points of order 4), and would be compatible with
  472. * hypothetical other implementations of Decaf using a Montgomery or untwisted
  473. * Edwards model.
  474. *
  475. * Unlike Elligator, this function may be up to 4:1 on [0,(p-1)/2]:
  476. * A factor of 2 due to the isogeny.
  477. * A factor of 2 because we quotient out the 2-torsion.
  478. *
  479. * This makes it about 8:1 overall, or 16:1 overall on curves with cofactor 8.
  480. *
  481. * Negating the input (mod q) results in the same point. Inverting the input
  482. * (mod q) results in the negative point. This is the same as Elligator.
  483. *
  484. * This function isn't quite indifferentiable from a random oracle.
  485. * However, it is suitable for many protocols, including SPEKE and SPAKE2 EE.
  486. * Furthermore, calling it twice with independent seeds and adding the results
  487. * is indifferentiable from a random oracle.
  488. *
  489. * @param [in] hashed_data Output of some hash function.
  490. * @param [out] pt The data hashed to the curve.
  491. */
  492. void
  493. %(c_ns)s_point_from_hash_nonuniform (
  494. %(c_ns)s_point_t pt,
  495. const unsigned char hashed_data[%(C_NS)s_SER_BYTES]
  496. ) API_VIS NONNULL2 NOINLINE;
  497. /**
  498. * @brief Indifferentiable hash function encoding to curve.
  499. *
  500. * Equivalent to calling %(c_ns)s_point_from_hash_nonuniform twice and adding.
  501. *
  502. * @param [in] hashed_data Output of some hash function.
  503. * @param [out] pt The data hashed to the curve.
  504. */
  505. void %(c_ns)s_point_from_hash_uniform (
  506. %(c_ns)s_point_t pt,
  507. const unsigned char hashed_data[2*%(C_NS)s_SER_BYTES]
  508. ) API_VIS NONNULL2 NOINLINE;
  509. /**
  510. * @brief Inverse of elligator-like hash to curve.
  511. *
  512. * This function writes to the buffer, to make it so that
  513. * %(c_ns)s_point_from_hash_nonuniform(buffer) = pt if
  514. * possible. Since there may be multiple preimages, the
  515. * "which" parameter chooses between them. To ensure uniform
  516. * inverse sampling, this function succeeds or fails
  517. * independently for different "which" values.
  518. *
  519. * @param [out] recovered_hash Encoded data.
  520. * @param [in] pt The point to encode.
  521. * @param [in] which A value determining which inverse point
  522. * to return.
  523. *
  524. * @retval DECAF_SUCCESS The inverse succeeded.
  525. * @retval DECAF_FAILURE The inverse failed.
  526. */
  527. decaf_error_t
  528. %(c_ns)s_invert_elligator_nonuniform (
  529. unsigned char recovered_hash[%(C_NS)s_SER_BYTES],
  530. const %(c_ns)s_point_t pt,
  531. uint16_t which
  532. ) API_VIS NONNULL2 NOINLINE WARN_UNUSED;
  533. /**
  534. * @brief Inverse of elligator-like hash to curve.
  535. *
  536. * This function writes to the buffer, to make it so that
  537. * %(c_ns)s_point_from_hash_uniform(buffer) = pt if
  538. * possible. Since there may be multiple preimages, the
  539. * "which" parameter chooses between them. To ensure uniform
  540. * inverse sampling, this function succeeds or fails
  541. * independently for different "which" values.
  542. *
  543. * @param [out] recovered_hash Encoded data.
  544. * @param [in] pt The point to encode.
  545. * @param [in] which A value determining which inverse point
  546. * to return.
  547. *
  548. * @retval DECAF_SUCCESS The inverse succeeded.
  549. * @retval DECAF_FAILURE The inverse failed.
  550. */
  551. decaf_error_t
  552. %(c_ns)s_invert_elligator_uniform (
  553. unsigned char recovered_hash[2*%(C_NS)s_SER_BYTES],
  554. const %(c_ns)s_point_t pt,
  555. uint16_t which
  556. ) API_VIS NONNULL2 NOINLINE WARN_UNUSED;
  557. /**
  558. * @brief Overwrite scalar with zeros.
  559. */
  560. void %(c_ns)s_scalar_destroy (
  561. %(c_ns)s_scalar_t scalar
  562. ) NONNULL1 API_VIS;
  563. /**
  564. * @brief Overwrite point with zeros.
  565. * @todo Use this internally.
  566. */
  567. void %(c_ns)s_point_destroy (
  568. %(c_ns)s_point_t point
  569. ) NONNULL1 API_VIS;
  570. /**
  571. * @brief Overwrite precomputed table with zeros.
  572. */
  573. void %(c_ns)s_precomputed_destroy (
  574. %(c_ns)s_precomputed_s *pre
  575. ) NONNULL1 API_VIS;
  576. #ifdef __cplusplus
  577. } /* extern "C" */
  578. #endif
  579. """
  580. )