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.
 
 
 
 
 

252 lines
9.2 KiB

  1. /**
  2. * @file decaf/ed448.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_ED448_H__
  15. #define __DECAF_ED448_H__ 1
  16. #include <decaf/point_448.h>
  17. #include <decaf/shake.h>
  18. #include <decaf/sha512.h>
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /** Number of bytes in an EdDSA public key. */
  23. #define DECAF_EDDSA_448_PUBLIC_BYTES 57
  24. /** Number of bytes in an EdDSA private key. */
  25. #define DECAF_EDDSA_448_PRIVATE_BYTES DECAF_EDDSA_448_PUBLIC_BYTES
  26. /** Number of bytes in an EdDSA private key. */
  27. #define DECAF_EDDSA_448_SIGNATURE_BYTES (DECAF_EDDSA_448_PUBLIC_BYTES + DECAF_EDDSA_448_PRIVATE_BYTES)
  28. /** Does EdDSA support non-contextual signatures? */
  29. #define DECAF_EDDSA_448_SUPPORTS_CONTEXTLESS_SIGS 0
  30. /** Prehash context renaming macros. */
  31. #define decaf_ed448_prehash_ctx_s decaf_shake256_ctx_s
  32. #define decaf_ed448_prehash_ctx_t decaf_shake256_ctx_t
  33. #define decaf_ed448_prehash_update decaf_shake256_update
  34. #define decaf_ed448_prehash_destroy decaf_shake256_destroy
  35. /** EdDSA encoding ratio. */
  36. #define DECAF_448_EDDSA_ENCODE_RATIO 4
  37. /** EdDSA decoding ratio. */
  38. #define DECAF_448_EDDSA_DECODE_RATIO (4 / 4)
  39. /**
  40. * @brief EdDSA key generation. This function uses a different (non-Decaf)
  41. * encoding.
  42. *
  43. * @param [out] pubkey The public key.
  44. * @param [in] privkey The private key.
  45. */
  46. void decaf_ed448_derive_public_key (
  47. uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES],
  48. const uint8_t privkey[DECAF_EDDSA_448_PRIVATE_BYTES]
  49. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  50. /**
  51. * @brief EdDSA signing.
  52. *
  53. * @param [out] signature The signature.
  54. * @param [in] privkey The private key.
  55. * @param [in] pubkey The public key.
  56. * @param [in] message The message to sign.
  57. * @param [in] message_len The length of the message.
  58. * @param [in] prehashed Nonzero if the message is actually the hash of something you want to sign.
  59. * @param [in] context A "context" for this signature of up to 255 bytes.
  60. * @param [in] context_len Length of the context.
  61. *
  62. * @warning For Ed25519, it is unsafe to use the same key for both prehashed and non-prehashed
  63. * messages, at least without some very careful protocol-level disambiguation. For Ed448 it is
  64. * safe. The C++ wrapper is designed to make it harder to screw this up, but this C code gives
  65. * you no seat belt.
  66. */
  67. void decaf_ed448_sign (
  68. uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES],
  69. const uint8_t privkey[DECAF_EDDSA_448_PRIVATE_BYTES],
  70. const uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES],
  71. const uint8_t *message,
  72. size_t message_len,
  73. uint8_t prehashed,
  74. const uint8_t *context,
  75. uint8_t context_len
  76. ) DECAF_API_VIS __attribute__((nonnull(1,2,3))) DECAF_NOINLINE;
  77. /**
  78. * @brief EdDSA signing with prehash.
  79. *
  80. * @param [out] signature The signature.
  81. * @param [in] privkey The private key.
  82. * @param [in] pubkey The public key.
  83. * @param [in] hash The hash of the message. This object will not be modified by the call.
  84. * @param [in] context A "context" for this signature of up to 255 bytes. Must be the same as what was used for the prehash.
  85. * @param [in] context_len Length of the context.
  86. *
  87. * @warning For Ed25519, it is unsafe to use the same key for both prehashed and non-prehashed
  88. * messages, at least without some very careful protocol-level disambiguation. For Ed448 it is
  89. * safe. The C++ wrapper is designed to make it harder to screw this up, but this C code gives
  90. * you no seat belt.
  91. */
  92. void decaf_ed448_sign_prehash (
  93. uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES],
  94. const uint8_t privkey[DECAF_EDDSA_448_PRIVATE_BYTES],
  95. const uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES],
  96. const decaf_ed448_prehash_ctx_t hash,
  97. const uint8_t *context,
  98. uint8_t context_len
  99. ) DECAF_API_VIS __attribute__((nonnull(1,2,3,4))) DECAF_NOINLINE;
  100. /**
  101. * @brief Prehash initialization, with contexts if supported.
  102. *
  103. * @param [out] hash The hash object to be initialized.
  104. */
  105. void decaf_ed448_prehash_init (
  106. decaf_ed448_prehash_ctx_t hash
  107. ) DECAF_API_VIS __attribute__((nonnull(1))) DECAF_NOINLINE;
  108. /**
  109. * @brief EdDSA signature verification.
  110. *
  111. * Uses the standard (i.e. less-strict) verification formula.
  112. *
  113. * @param [in] signature The signature.
  114. * @param [in] pubkey The public key.
  115. * @param [in] message The message to verify.
  116. * @param [in] message_len The length of the message.
  117. * @param [in] prehashed Nonzero if the message is actually the hash of something you want to verify.
  118. * @param [in] context A "context" for this signature of up to 255 bytes.
  119. * @param [in] context_len Length of the context.
  120. *
  121. * @warning For Ed25519, it is unsafe to use the same key for both prehashed and non-prehashed
  122. * messages, at least without some very careful protocol-level disambiguation. For Ed448 it is
  123. * safe. The C++ wrapper is designed to make it harder to screw this up, but this C code gives
  124. * you no seat belt.
  125. */
  126. decaf_error_t decaf_ed448_verify (
  127. const uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES],
  128. const uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES],
  129. const uint8_t *message,
  130. size_t message_len,
  131. uint8_t prehashed,
  132. const uint8_t *context,
  133. uint8_t context_len
  134. ) DECAF_API_VIS __attribute__((nonnull(1,2))) DECAF_NOINLINE;
  135. /**
  136. * @brief EdDSA signature verification.
  137. *
  138. * Uses the standard (i.e. less-strict) verification formula.
  139. *
  140. * @param [in] signature The signature.
  141. * @param [in] pubkey The public key.
  142. * @param [in] hash The hash of the message. This object will not be modified by the call.
  143. * @param [in] context A "context" for this signature of up to 255 bytes. Must be the same as what was used for the prehash.
  144. * @param [in] context_len Length of the context.
  145. *
  146. * @warning For Ed25519, it is unsafe to use the same key for both prehashed and non-prehashed
  147. * messages, at least without some very careful protocol-level disambiguation. For Ed448 it is
  148. * safe. The C++ wrapper is designed to make it harder to screw this up, but this C code gives
  149. * you no seat belt.
  150. */
  151. decaf_error_t decaf_ed448_verify_prehash (
  152. const uint8_t signature[DECAF_EDDSA_448_SIGNATURE_BYTES],
  153. const uint8_t pubkey[DECAF_EDDSA_448_PUBLIC_BYTES],
  154. const decaf_ed448_prehash_ctx_t hash,
  155. const uint8_t *context,
  156. uint8_t context_len
  157. ) DECAF_API_VIS __attribute__((nonnull(1,2))) DECAF_NOINLINE;
  158. /**
  159. * @brief EdDSA point encoding. Used internally, exposed externally.
  160. * Multiplies by DECAF_448_EDDSA_ENCODE_RATIO first.
  161. *
  162. * The multiplication is required because the EdDSA encoding represents
  163. * the cofactor information, but the Decaf encoding ignores it (which
  164. * is the whole point). So if you decode from EdDSA and re-encode to
  165. * EdDSA, the cofactor info must get cleared, because the intermediate
  166. * representation doesn't track it.
  167. *
  168. * The way libdecaf handles this is to multiply by
  169. * DECAF_448_EDDSA_DECODE_RATIO when decoding, and by
  170. * DECAF_448_EDDSA_ENCODE_RATIO when encoding. The product of these
  171. * ratios is always exactly the cofactor 4, so the cofactor
  172. * ends up cleared one way or another. But exactly how that shakes
  173. * out depends on the base points specified in RFC 8032.
  174. *
  175. * The upshot is that if you pass the Decaf/Ristretto base point to
  176. * this function, you will get DECAF_448_EDDSA_ENCODE_RATIO times the
  177. * EdDSA base point.
  178. *
  179. * @param [out] enc The encoded point.
  180. * @param [in] p The point.
  181. */
  182. void decaf_448_point_mul_by_ratio_and_encode_like_eddsa (
  183. uint8_t enc[DECAF_EDDSA_448_PUBLIC_BYTES],
  184. const decaf_448_point_t p
  185. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  186. /**
  187. * @brief EdDSA point decoding. Multiplies by DECAF_448_EDDSA_DECODE_RATIO,
  188. * and ignores cofactor information.
  189. *
  190. * See notes on decaf_448_point_mul_by_ratio_and_encode_like_eddsa
  191. *
  192. * @param [out] enc The encoded point.
  193. * @param [in] p The point.
  194. */
  195. decaf_error_t decaf_448_point_decode_like_eddsa_and_mul_by_ratio (
  196. decaf_448_point_t p,
  197. const uint8_t enc[DECAF_EDDSA_448_PUBLIC_BYTES]
  198. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  199. /**
  200. * @brief EdDSA to ECDH public key conversion
  201. * Deserialize the point to get y on Edwards curve,
  202. * Convert it to u coordinate on Montgomery curve.
  203. *
  204. * @warning This function does not check that the public key being converted
  205. * is a valid EdDSA public key (FUTURE?)
  206. *
  207. * @param[out] x The ECDH public key as in RFC7748(point on Montgomery curve)
  208. * @param[in] ed The EdDSA public key(point on Edwards curve)
  209. */
  210. void decaf_ed448_convert_public_key_to_x448 (
  211. uint8_t x[DECAF_X448_PUBLIC_BYTES],
  212. const uint8_t ed[DECAF_EDDSA_448_PUBLIC_BYTES]
  213. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  214. /**
  215. * @brief EdDSA to ECDH private key conversion
  216. * Using the appropriate hash function, hash the EdDSA private key
  217. * and keep only the lower bytes to get the ECDH private key
  218. *
  219. * @param[out] x The ECDH private key as in RFC7748
  220. * @param[in] ed The EdDSA private key
  221. */
  222. void decaf_ed448_convert_private_key_to_x448 (
  223. uint8_t x[DECAF_X448_PRIVATE_BYTES],
  224. const uint8_t ed[DECAF_EDDSA_448_PRIVATE_BYTES]
  225. ) DECAF_API_VIS DECAF_NONNULL DECAF_NOINLINE;
  226. #ifdef __cplusplus
  227. } /* extern "C" */
  228. #endif
  229. #endif /* __DECAF_ED448_H__ */