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.
 
 
 
 
 

652 lines
20 KiB

  1. /**
  2. * @file decaf_255.h
  3. * @author Mike Hamburg
  4. *
  5. * @copyright
  6. * Copyright (c) 2015 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.
  10. *
  11. * The Decaf library implements cryptographic operations on a an elliptic curve
  12. * group of prime order p. It accomplishes this by using a twisted Edwards
  13. * curve (isogenous to Ed255-Goldilocks) and wiping out the cofactor.
  14. *
  15. * The formulas are all complete and have no special cases, except that
  16. * decaf_255_decode can fail because not every sequence of bytes is a valid group
  17. * element.
  18. *
  19. * The formulas contain no data-dependent branches, timing or memory accesses,
  20. * except for decaf_255_base_double_scalarmul_non_secret.
  21. *
  22. * This library may support multiple curves eventually. The Ed255-Goldilocks
  23. * specific identifiers are prefixed with DECAF_255 or decaf_255.
  24. */
  25. #ifndef __DECAF_255_H__
  26. #define __DECAF_255_H__ 1
  27. #include <stdint.h>
  28. #include <sys/types.h>
  29. /* Goldilocks' build flags default to hidden and stripping executables. */
  30. /** @cond internal */
  31. #if defined(DOXYGEN) && !defined(__attribute__)
  32. #define __attribute__((x))
  33. #endif
  34. #define API_VIS __attribute__((visibility("default")))
  35. #define NOINLINE __attribute__((noinline))
  36. #define WARN_UNUSED __attribute__((warn_unused_result))
  37. #define NONNULL1 __attribute__((nonnull(1)))
  38. #define NONNULL2 __attribute__((nonnull(1,2)))
  39. #define NONNULL3 __attribute__((nonnull(1,2,3)))
  40. #define NONNULL4 __attribute__((nonnull(1,2,3,4)))
  41. #define NONNULL5 __attribute__((nonnull(1,2,3,4,5)))
  42. /* Internal word types */
  43. #if (defined(__ILP64__) || defined(__amd64__) || defined(__x86_64__) || (((__UINT_FAST32_MAX__)>>30)>>30)) \
  44. && !defined(DECAF_FORCE_32_BIT)
  45. #define DECAF_WORD_BITS 64
  46. typedef uint64_t decaf_word_t, decaf_bool_t;
  47. typedef __uint128_t decaf_dword_t;
  48. #else
  49. #define DECAF_WORD_BITS 32
  50. typedef uint32_t decaf_word_t, decaf_bool_t;
  51. typedef uint64_t decaf_dword_t;
  52. #endif
  53. #define DECAF_255_LIMBS (320/DECAF_WORD_BITS)
  54. #define DECAF_255_SCALAR_BITS 254 // Curve25519: 253
  55. #define DECAF_255_SCALAR_LIMBS (256/DECAF_WORD_BITS)
  56. /** Galois field element internal structure */
  57. typedef struct gf_s {
  58. decaf_word_t limb[DECAF_255_LIMBS];
  59. } gf_s, gf[1];
  60. /** @endcond */
  61. /** Number of bytes in a serialized point. */
  62. #define DECAF_255_SER_BYTES 32
  63. /** Number of bytes in a serialized scalar. */
  64. #define DECAF_255_SCALAR_BYTES 32
  65. /** Twisted Edwards (-1,d-1) extended homogeneous coordinates */
  66. typedef struct decaf_255_point_s { /**@cond internal*/gf x,y,z,t;/**@endcond*/ } decaf_255_point_t[1];
  67. /** Precomputed table based on a point. Can be trivial implementation. */
  68. struct decaf_255_precomputed_s;
  69. /** Precomputed table based on a point. Can be trivial implementation. */
  70. typedef struct decaf_255_precomputed_s decaf_255_precomputed_s;
  71. /** Size and alignment of precomputed point tables. */
  72. extern const size_t sizeof_decaf_255_precomputed_s API_VIS, alignof_decaf_255_precomputed_s API_VIS;
  73. /** Scalar is stored packed, because we don't need the speed. */
  74. typedef struct decaf_255_scalar_s {
  75. /** @cond internal */
  76. decaf_word_t limb[DECAF_255_SCALAR_LIMBS];
  77. /** @endcond */
  78. } decaf_255_scalar_t[1];
  79. /** DECAF_TRUE = -1 so that DECAF_TRUE & x = x */
  80. static const decaf_bool_t DECAF_TRUE = -(decaf_bool_t)1, DECAF_FALSE = 0;
  81. /** NB Success is -1, failure is 0. TODO: see if people would rather the reverse. */
  82. static const decaf_bool_t DECAF_SUCCESS = -(decaf_bool_t)1 /*DECAF_TRUE*/,
  83. DECAF_FAILURE = 0 /*DECAF_FALSE*/;
  84. /** A scalar equal to 1. */
  85. extern const decaf_255_scalar_t decaf_255_scalar_one API_VIS;
  86. /** A scalar equal to 0. */
  87. extern const decaf_255_scalar_t decaf_255_scalar_zero API_VIS;
  88. /** The identity point on the curve. */
  89. extern const decaf_255_point_t decaf_255_point_identity API_VIS;
  90. /**
  91. * An arbitrarily chosen base point on the curve.
  92. * Equal to Ed255-Goldilocks base point defined by DJB, except of course that
  93. * it's on the twist in this case. TODO: choose a base point with nice encoding?
  94. */
  95. extern const decaf_255_point_t decaf_255_point_base API_VIS;
  96. /** Precomputed table for the base point on the curve. */
  97. extern const struct decaf_255_precomputed_s *decaf_255_precomputed_base API_VIS;
  98. #ifdef __cplusplus
  99. extern "C" {
  100. #endif
  101. /**
  102. * @brief Read a scalar from wire format or from bytes.
  103. *
  104. * @param [in] ser Serialized form of a scalar.
  105. * @param [out] out Deserialized form.
  106. *
  107. * @retval DECAF_SUCCESS The scalar was correctly encoded.
  108. * @retval DECAF_FAILURE The scalar was greater than the modulus,
  109. * and has been reduced modulo that modulus.
  110. */
  111. decaf_bool_t decaf_255_scalar_decode (
  112. decaf_255_scalar_t out,
  113. const unsigned char ser[DECAF_255_SCALAR_BYTES]
  114. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  115. /**
  116. * @brief Read a scalar from wire format or from bytes. Reduces mod
  117. * scalar prime.
  118. *
  119. * @param [in] ser Serialized form of a scalar.
  120. * @param [in] ser_len Length of serialized form.
  121. * @param [out] out Deserialized form.
  122. */
  123. void decaf_255_scalar_decode_long (
  124. decaf_255_scalar_t out,
  125. const unsigned char *ser,
  126. size_t ser_len
  127. ) API_VIS NONNULL2 NOINLINE;
  128. /**
  129. * @brief Serialize a scalar to wire format.
  130. *
  131. * @param [out] ser Serialized form of a scalar.
  132. * @param [in] s Deserialized scalar.
  133. */
  134. void decaf_255_scalar_encode (
  135. unsigned char ser[DECAF_255_SCALAR_BYTES],
  136. const decaf_255_scalar_t s
  137. ) API_VIS NONNULL2 NOINLINE NOINLINE;
  138. /**
  139. * @brief Add two scalars. The scalars may use the same memory.
  140. * @param [in] a One scalar.
  141. * @param [in] b Another scalar.
  142. * @param [out] out a+b.
  143. */
  144. void decaf_255_scalar_add (
  145. decaf_255_scalar_t out,
  146. const decaf_255_scalar_t a,
  147. const decaf_255_scalar_t b
  148. ) API_VIS NONNULL3 NOINLINE;
  149. /**
  150. * @brief Compare two scalars.
  151. * @param [in] a One scalar.
  152. * @param [in] b Another scalar.
  153. * @retval DECAF_TRUE The scalars are equal.
  154. * @retval DECAF_FALSE The scalars are not equal.
  155. */
  156. decaf_bool_t decaf_255_scalar_eq (
  157. const decaf_255_scalar_t a,
  158. const decaf_255_scalar_t b
  159. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  160. /**
  161. * @brief Subtract two scalars. The scalars may use the same memory.
  162. * @param [in] a One scalar.
  163. * @param [in] b Another scalar.
  164. * @param [out] out a-b.
  165. */
  166. void decaf_255_scalar_sub (
  167. decaf_255_scalar_t out,
  168. const decaf_255_scalar_t a,
  169. const decaf_255_scalar_t b
  170. ) API_VIS NONNULL3 NOINLINE;
  171. /**
  172. * @brief Multiply two scalars. The scalars may use the same memory.
  173. * @param [in] a One scalar.
  174. * @param [in] b Another scalar.
  175. * @param [out] out a*b.
  176. */
  177. void decaf_255_scalar_mul (
  178. decaf_255_scalar_t out,
  179. const decaf_255_scalar_t a,
  180. const decaf_255_scalar_t b
  181. ) API_VIS NONNULL3 NOINLINE;
  182. /**
  183. * @brief Invert a scalar. When passed zero, return 0. The input and output may alias.
  184. * @param [in] a A scalar.
  185. * @param [out] out 1/a.
  186. * @return DECAF_TRUE The input is nonzero.
  187. */
  188. decaf_bool_t decaf_255_scalar_invert (
  189. decaf_255_scalar_t out,
  190. const decaf_255_scalar_t a
  191. ) API_VIS NONNULL2 NOINLINE;
  192. /**
  193. * @brief Copy a scalar. The scalars may use the same memory, in which
  194. * case this function does nothing.
  195. * @param [in] a A scalar.
  196. * @param [out] out Will become a copy of a.
  197. */
  198. static inline void NONNULL2 decaf_255_scalar_copy (
  199. decaf_255_scalar_t out,
  200. const decaf_255_scalar_t a
  201. ) {
  202. *out = *a;
  203. }
  204. /**
  205. * @brief Set a scalar to an integer.
  206. * @param [in] a An integer.
  207. * @param [out] out Will become equal to a.
  208. * @todo Make inline?
  209. */
  210. void decaf_255_scalar_set(
  211. decaf_255_scalar_t out,
  212. decaf_word_t a
  213. ) API_VIS NONNULL1;
  214. /**
  215. * @brief Encode a point as a sequence of bytes.
  216. *
  217. * @param [out] ser The byte representation of the point.
  218. * @param [in] pt The point to encode.
  219. */
  220. void decaf_255_point_encode (
  221. uint8_t ser[DECAF_255_SER_BYTES],
  222. const decaf_255_point_t pt
  223. ) API_VIS NONNULL2 NOINLINE;
  224. /**
  225. * @brief Decode a point from a sequence of bytes.
  226. *
  227. * Every point has a unique encoding, so not every
  228. * sequence of bytes is a valid encoding. If an invalid
  229. * encoding is given, the output is undefined.
  230. *
  231. * @param [out] pt The decoded point.
  232. * @param [in] ser The serialized version of the point.
  233. * @param [in] allow_identity DECAF_TRUE if the identity is a legal input.
  234. * @retval DECAF_SUCCESS The decoding succeeded.
  235. * @retval DECAF_FAILURE The decoding didn't succeed, because
  236. * ser does not represent a point.
  237. */
  238. decaf_bool_t decaf_255_point_decode (
  239. decaf_255_point_t pt,
  240. const uint8_t ser[DECAF_255_SER_BYTES],
  241. decaf_bool_t allow_identity
  242. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  243. /**
  244. * @brief Copy a point. The input and output may alias,
  245. * in which case this function does nothing.
  246. *
  247. * @param [out] a A copy of the point.
  248. * @param [in] b Any point.
  249. */
  250. static inline void NONNULL2 decaf_255_point_copy (
  251. decaf_255_point_t a,
  252. const decaf_255_point_t b
  253. ) {
  254. *a=*b;
  255. }
  256. /**
  257. * @brief Test whether two points are equal. If yes, return
  258. * DECAF_TRUE, else return DECAF_FALSE.
  259. *
  260. * @param [in] a A point.
  261. * @param [in] b Another point.
  262. * @retval DECAF_TRUE The points are equal.
  263. * @retval DECAF_FALSE The points are not equal.
  264. */
  265. decaf_bool_t decaf_255_point_eq (
  266. const decaf_255_point_t a,
  267. const decaf_255_point_t b
  268. ) API_VIS WARN_UNUSED NONNULL2 NOINLINE;
  269. /**
  270. * @brief Add two points to produce a third point. The
  271. * input points and output point can be pointers to the same
  272. * memory.
  273. *
  274. * @param [out] sum The sum a+b.
  275. * @param [in] a An addend.
  276. * @param [in] b An addend.
  277. */
  278. void decaf_255_point_add (
  279. decaf_255_point_t sum,
  280. const decaf_255_point_t a,
  281. const decaf_255_point_t b
  282. ) API_VIS NONNULL3;
  283. /**
  284. * @brief Double a point. Equivalent to
  285. * decaf_255_point_add(two_a,a,a), but potentially faster.
  286. *
  287. * @param [out] two_a The sum a+a.
  288. * @param [in] a A point.
  289. */
  290. void decaf_255_point_double (
  291. decaf_255_point_t two_a,
  292. const decaf_255_point_t a
  293. ) API_VIS NONNULL2;
  294. /**
  295. * @brief Subtract two points to produce a third point. The
  296. * input points and output point can be pointers to the same
  297. * memory.
  298. *
  299. * @param [out] diff The difference a-b.
  300. * @param [in] a The minuend.
  301. * @param [in] b The subtrahend.
  302. */
  303. void decaf_255_point_sub (
  304. decaf_255_point_t diff,
  305. const decaf_255_point_t a,
  306. const decaf_255_point_t b
  307. ) API_VIS NONNULL3;
  308. /**
  309. * @brief Negate a point to produce another point. The input
  310. * and output points can use the same memory.
  311. *
  312. * @param [out] nega The negated input point
  313. * @param [in] a The input point.
  314. */
  315. void decaf_255_point_negate (
  316. decaf_255_point_t nega,
  317. const decaf_255_point_t a
  318. ) API_VIS NONNULL2;
  319. /**
  320. * @brief Multiply a base point by a scalar: scaled = scalar*base.
  321. *
  322. * @param [out] scaled The scaled point base*scalar
  323. * @param [in] base The point to be scaled.
  324. * @param [in] scalar The scalar to multiply by.
  325. */
  326. void decaf_255_point_scalarmul (
  327. decaf_255_point_t scaled,
  328. const decaf_255_point_t base,
  329. const decaf_255_scalar_t scalar
  330. ) API_VIS NONNULL3 NOINLINE;
  331. /**
  332. * @brief Multiply a base point by a scalar: scaled = scalar*base.
  333. * This function operates directly on serialized forms.
  334. *
  335. * @warning This function is experimental. It may not be supported
  336. * long-term.
  337. *
  338. * @param [out] scaled The scaled point base*scalar
  339. * @param [in] base The point to be scaled.
  340. * @param [in] scalar The scalar to multiply by.
  341. * @param [in] allow_identity Allow the input to be the identity.
  342. * @param [in] short_circuit Allow a fast return if the input is illegal.
  343. *
  344. * @retval DECAF_SUCCESS The scalarmul succeeded.
  345. * @retval DECAF_FAILURE The scalarmul didn't succeed, because
  346. * base does not represent a point.
  347. */
  348. decaf_bool_t decaf_255_direct_scalarmul (
  349. uint8_t scaled[DECAF_255_SER_BYTES],
  350. const uint8_t base[DECAF_255_SER_BYTES],
  351. const decaf_255_scalar_t scalar,
  352. decaf_bool_t allow_identity,
  353. decaf_bool_t short_circuit
  354. ) API_VIS NONNULL3 WARN_UNUSED NOINLINE;
  355. /**
  356. * @brief Precompute a table for fast scalar multiplication.
  357. * Some implementations do not include precomputed points; for
  358. * those implementations, this implementation simply copies the
  359. * point.
  360. *
  361. * @param [out] a A precomputed table of multiples of the point.
  362. * @param [in] b Any point.
  363. */
  364. void decaf_255_precompute (
  365. decaf_255_precomputed_s *a,
  366. const decaf_255_point_t b
  367. ) API_VIS NONNULL2 NOINLINE;
  368. /**
  369. * @brief Multiply a precomputed base point by a scalar:
  370. * scaled = scalar*base.
  371. * Some implementations do not include precomputed points; for
  372. * those implementations, this function is the same as
  373. * decaf_255_point_scalarmul
  374. *
  375. * @param [out] scaled The scaled point base*scalar
  376. * @param [in] base The point to be scaled.
  377. * @param [in] scalar The scalar to multiply by.
  378. *
  379. * @todo precomputed dsmul? const or variable time?
  380. */
  381. void decaf_255_precomputed_scalarmul (
  382. decaf_255_point_t scaled,
  383. const decaf_255_precomputed_s *base,
  384. const decaf_255_scalar_t scalar
  385. ) API_VIS NONNULL3 NOINLINE;
  386. /**
  387. * @brief Multiply two base points by two scalars:
  388. * scaled = scalar1*base1 + scalar2*base2.
  389. *
  390. * Equivalent to two calls to decaf_255_point_scalarmul, but may be
  391. * faster.
  392. *
  393. * @param [out] combo The linear combination scalar1*base1 + scalar2*base2.
  394. * @param [in] base1 A first point to be scaled.
  395. * @param [in] scalar1 A first scalar to multiply by.
  396. * @param [in] base2 A second point to be scaled.
  397. * @param [in] scalar2 A second scalar to multiply by.
  398. */
  399. void decaf_255_point_double_scalarmul (
  400. decaf_255_point_t combo,
  401. const decaf_255_point_t base1,
  402. const decaf_255_scalar_t scalar1,
  403. const decaf_255_point_t base2,
  404. const decaf_255_scalar_t scalar2
  405. ) API_VIS NONNULL5 NOINLINE;
  406. /**
  407. * @brief Multiply two base points by two scalars:
  408. * scaled = scalar1*decaf_255_point_base + scalar2*base2.
  409. *
  410. * Otherwise equivalent to decaf_255_point_double_scalarmul, but may be
  411. * faster at the expense of being variable time.
  412. *
  413. * @param [out] combo The linear combination scalar1*base + scalar2*base2.
  414. * @param [in] scalar1 A first scalar to multiply by.
  415. * @param [in] base2 A second point to be scaled.
  416. * @param [in] scalar2 A second scalar to multiply by.
  417. *
  418. * @warning: This function takes variable time, and may leak the scalars
  419. * used. It is designed for signature verification.
  420. */
  421. void decaf_255_base_double_scalarmul_non_secret (
  422. decaf_255_point_t combo,
  423. const decaf_255_scalar_t scalar1,
  424. const decaf_255_point_t base2,
  425. const decaf_255_scalar_t scalar2
  426. ) API_VIS NONNULL4 NOINLINE;
  427. /**
  428. * @brief Test that a point is valid, for debugging purposes.
  429. *
  430. * @param [in] toTest The point to test.
  431. * @retval DECAF_TRUE The point is valid.
  432. * @retval DECAF_FALSE The point is invalid.
  433. */
  434. decaf_bool_t decaf_255_point_valid (
  435. const decaf_255_point_t toTest
  436. ) API_VIS WARN_UNUSED NONNULL1 NOINLINE;
  437. /**
  438. * @brief 2-torque a point, for debugging purposes.
  439. *
  440. * @param [out] q The point to torque.
  441. * @param [in] p The point to torque.
  442. */
  443. void decaf_255_point_debugging_2torque (
  444. decaf_255_point_t q,
  445. const decaf_255_point_t p
  446. ) API_VIS NONNULL2 NOINLINE;
  447. /**
  448. * @brief Almost-Elligator-like hash to curve.
  449. *
  450. * Call this function with the output of a hash to make a hash to the curve.
  451. *
  452. * This function runs Elligator2 on the decaf_255 Jacobi quartic model. It then
  453. * uses the isogeny to put the result in twisted Edwards form. As a result,
  454. * it is safe (cannot produce points of order 4), and would be compatible with
  455. * hypothetical other implementations of Decaf using a Montgomery or untwisted
  456. * Edwards model.
  457. *
  458. * Unlike Elligator, this function may be up to 4:1 on [0,(p-1)/2]:
  459. * A factor of 2 due to the isogeny.
  460. * A factor of 2 because we quotient out the 2-torsion.
  461. *
  462. * This makes it about 8:1 overall.
  463. *
  464. * Negating the input (mod q) results in the same point. Inverting the input
  465. * (mod q) results in the negative point. This is the same as Elligator.
  466. *
  467. * This function isn't quite indifferentiable from a random oracle.
  468. * However, it is suitable for many protocols, including SPEKE and SPAKE2 EE.
  469. * Furthermore, calling it twice with independent seeds and adding the results
  470. * is indifferentiable from a random oracle.
  471. *
  472. * @param [in] hashed_data Output of some hash function.
  473. * @param [out] pt The data hashed to the curve.
  474. * @return A "hint" value which can be used to help invert the encoding.
  475. */
  476. unsigned char
  477. decaf_255_point_from_hash_nonuniform (
  478. decaf_255_point_t pt,
  479. const unsigned char hashed_data[DECAF_255_SER_BYTES]
  480. ) API_VIS NONNULL2 NOINLINE;
  481. /**
  482. * @brief Inverse of elligator-like hash to curve.
  483. *
  484. * This function writes to the buffer, to make it so that
  485. * decaf_255_point_from_hash_nonuniform(buffer) = pt,hint
  486. * if possible.
  487. *
  488. * @param [out] recovered_hash Encoded data.
  489. * @param [in] pt The point to encode.
  490. * @param [in] hint The hint value returned from
  491. * decaf_255_point_from_hash_nonuniform.
  492. *
  493. * @retval DECAF_SUCCESS The inverse succeeded.
  494. * @retval DECAF_FAILURE The pt isn't the image of
  495. * decaf_255_point_from_hash_nonuniform with the given hint.
  496. *
  497. * @warning The hinting system is subject to change, especially in corner cases.
  498. * @warning FIXME The hinting system doesn't work for certain inputs which have many 0xFF.
  499. */
  500. decaf_bool_t
  501. decaf_255_invert_elligator_nonuniform (
  502. unsigned char recovered_hash[DECAF_255_SER_BYTES],
  503. const decaf_255_point_t pt,
  504. unsigned char hint
  505. ) API_VIS NONNULL2 NOINLINE WARN_UNUSED;
  506. /**
  507. * @brief Inverse of elligator-like hash to curve, uniform.
  508. *
  509. * This function modifies the first DECAF_255_SER_BYTES of the
  510. * buffer, to make it so that
  511. * decaf_255_point_from_hash_uniform(buffer) = pt,hint
  512. * if possible.
  513. *
  514. * @param [out] recovered_hash Encoded data.
  515. * @param [in] pt The point to encode.
  516. * @param [in] hint The hint value returned from
  517. * decaf_255_point_from_hash_nonuniform.
  518. *
  519. * @retval DECAF_SUCCESS The inverse succeeded.
  520. * @retval DECAF_FAILURE The pt isn't the image of
  521. * decaf_255_point_from_hash_uniform with the given hint.
  522. *
  523. * @warning The hinting system is subject to change, especially in corner cases.
  524. * @warning FIXME The hinting system doesn't work for certain inputs which have many 0xFF.
  525. */
  526. decaf_bool_t
  527. decaf_255_invert_elligator_uniform (
  528. unsigned char recovered_hash[2*DECAF_255_SER_BYTES],
  529. const decaf_255_point_t pt,
  530. unsigned char hint
  531. ) API_VIS NONNULL2 NOINLINE WARN_UNUSED;
  532. /**
  533. * @brief Indifferentiable hash function encoding to curve.
  534. *
  535. * Equivalent to calling decaf_255_point_from_hash_nonuniform twice and adding.
  536. *
  537. * @param [in] hashed_data Output of some hash function.
  538. * @param [out] pt The data hashed to the curve.
  539. * @return A "hint" value which can be used to help invert the encoding.
  540. */
  541. unsigned char decaf_255_point_from_hash_uniform (
  542. decaf_255_point_t pt,
  543. const unsigned char hashed_data[2*DECAF_255_SER_BYTES]
  544. ) API_VIS NONNULL2 NOINLINE;
  545. /**
  546. * @brief Overwrite data with zeros. Uses memset_s if available.
  547. */
  548. void decaf_bzero (
  549. void *data,
  550. size_t size
  551. ) NONNULL1 API_VIS NOINLINE;
  552. /**
  553. * @brief Compare two buffers, returning DECAF_TRUE if they are equal.
  554. */
  555. decaf_bool_t decaf_memeq (
  556. const void *data1,
  557. const void *data2,
  558. size_t size
  559. ) NONNULL2 WARN_UNUSED API_VIS NOINLINE;
  560. /**
  561. * @brief Overwrite scalar with zeros.
  562. */
  563. void decaf_255_scalar_destroy (
  564. decaf_255_scalar_t scalar
  565. ) NONNULL1 API_VIS;
  566. /**
  567. * @brief Overwrite point with zeros.
  568. * @todo Use this internally.
  569. */
  570. void decaf_255_point_destroy (
  571. decaf_255_point_t point
  572. ) NONNULL1 API_VIS;
  573. /**
  574. * @brief Overwrite point with zeros.
  575. * @todo Use this internally.
  576. */
  577. void decaf_255_precomputed_destroy (
  578. decaf_255_precomputed_s *pre
  579. ) NONNULL1 API_VIS;
  580. /* TODO: functions to invert point_from_hash?? */
  581. #undef API_VIS
  582. #undef WARN_UNUSED
  583. #undef NOINLINE
  584. #undef NONNULL1
  585. #undef NONNULL2
  586. #undef NONNULL3
  587. #undef NONNULL4
  588. #undef NONNULL5
  589. #ifdef __cplusplus
  590. } /* extern "C" */
  591. #endif
  592. #endif /* __DECAF_255_H__ */