ed448.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. /* ed448.h
  2. *
  3. * Copyright (C) 2006-2023 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. /*!
  22. \file wolfssl/wolfcrypt/ed448.h
  23. */
  24. #ifndef WOLF_CRYPT_ED448_H
  25. #define WOLF_CRYPT_ED448_H
  26. #include <wolfssl/wolfcrypt/types.h>
  27. #ifdef HAVE_ED448
  28. #include <wolfssl/wolfcrypt/fe_448.h>
  29. #include <wolfssl/wolfcrypt/ge_448.h>
  30. #include <wolfssl/wolfcrypt/random.h>
  31. #ifndef WOLFSSL_SHAKE256
  32. #error ED448 requires SHAKE256
  33. #endif
  34. #include <wolfssl/wolfcrypt/sha3.h>
  35. #ifdef WOLFSSL_ASYNC_CRYPT
  36. #include <wolfssl/wolfcrypt/async.h>
  37. #endif
  38. #ifdef __cplusplus
  39. extern "C" {
  40. #endif
  41. /* info about EdDSA curve specifically ed448, defined as an elliptic curve
  42. * over GF(p)
  43. *
  44. * 56 key size
  45. * "ED448" curve name
  46. * "2^448-2^224-1" prime number
  47. * "-39081" value of d
  48. * "SHAKE256" hash function
  49. */
  50. #define ED448_KEY_SIZE 57 /* private key only */
  51. #define ED448_SIG_SIZE 114 /* two elements */
  52. #define ED448_PUB_KEY_SIZE 57 /* compressed */
  53. /* both private and public key */
  54. #define ED448_PRV_KEY_SIZE (ED448_PUB_KEY_SIZE+ED448_KEY_SIZE)
  55. #define ED448_PREHASH_SIZE 64
  56. enum {
  57. Ed448 = 0,
  58. Ed448ph = 1
  59. };
  60. #ifndef WC_ED448KEY_TYPE_DEFINED
  61. typedef struct ed448_key ed448_key;
  62. #define WC_ED448KEY_TYPE_DEFINED
  63. #endif
  64. /* An ED448 Key */
  65. struct ed448_key {
  66. byte p[ED448_PUB_KEY_SIZE]; /* compressed public key */
  67. byte k[ED448_PRV_KEY_SIZE]; /* private key : 56 secret -- 56 public */
  68. #ifdef FREESCALE_LTC_ECC
  69. /* uncompressed point coordinates */
  70. byte pointX[ED448_KEY_SIZE]; /* recovered X coordinate */
  71. byte pointY[ED448_KEY_SIZE]; /* Y coordinate is the public key with The most significant bit of the final octet always zero. */
  72. #endif
  73. word16 privKeySet:1;
  74. word16 pubKeySet:1;
  75. #ifdef WOLFSSL_ASYNC_CRYPT
  76. WC_ASYNC_DEV asyncDev;
  77. #endif
  78. #if defined(WOLF_CRYPTO_CB)
  79. void* devCtx;
  80. int devId;
  81. #endif
  82. void *heap;
  83. #ifdef WOLFSSL_ED448_PERSISTENT_SHA
  84. wc_Shake sha;
  85. int sha_clean_flag;
  86. #endif
  87. };
  88. WOLFSSL_API
  89. int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
  90. word32 pubKeySz);
  91. WOLFSSL_API
  92. int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
  93. #ifdef HAVE_ED448_SIGN
  94. WOLFSSL_API
  95. int wc_ed448_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
  96. ed448_key* key, const byte* context, byte contextLen);
  97. WOLFSSL_API
  98. int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
  99. word32 *outLen, ed448_key* key,
  100. const byte* context, byte contextLen);
  101. WOLFSSL_API
  102. int wc_ed448_sign_msg_ex(const byte* in, word32 inLen, byte* out,
  103. word32 *outLen, ed448_key* key, byte type,
  104. const byte* context, byte contextLen);
  105. WOLFSSL_API
  106. int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
  107. word32 *outLen, ed448_key* key, const byte* context,
  108. byte contextLen);
  109. #endif /* HAVE_ED448_SIGN */
  110. #ifdef HAVE_ED448_VERIFY
  111. WOLFSSL_API
  112. int wc_ed448_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
  113. word32 msgLen, int* res, ed448_key* key,
  114. byte type, const byte* context, byte contextLen);
  115. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  116. WOLFSSL_API
  117. int wc_ed448_verify_msg_init(const byte* sig, word32 sigLen, ed448_key* key,
  118. byte type, const byte* context, byte contextLen);
  119. WOLFSSL_API
  120. int wc_ed448_verify_msg_update(const byte* msgSegment, word32 msgSegmentLen,
  121. ed448_key* key);
  122. WOLFSSL_API
  123. int wc_ed448_verify_msg_final(const byte* sig, word32 sigLen,
  124. int* res, ed448_key* key);
  125. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  126. WOLFSSL_API
  127. int wc_ed448_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
  128. word32 msgLen, int* res, ed448_key* key,
  129. const byte* context, byte contextLen);
  130. WOLFSSL_API
  131. int wc_ed448ph_verify_hash(const byte* sig, word32 sigLen, const byte* hash,
  132. word32 hashLen, int* res, ed448_key* key,
  133. const byte* context, byte contextLen);
  134. WOLFSSL_API
  135. int wc_ed448ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
  136. word32 msgLen, int* res, ed448_key* key,
  137. const byte* context, byte contextLen);
  138. #endif /* HAVE_ED448_VERIFY */
  139. WOLFSSL_API
  140. int wc_ed448_init_ex(ed448_key* key, void *heap, int devId);
  141. WOLFSSL_API
  142. int wc_ed448_init(ed448_key* key);
  143. WOLFSSL_API
  144. void wc_ed448_free(ed448_key* key);
  145. #ifdef HAVE_ED448_KEY_IMPORT
  146. WOLFSSL_API
  147. int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
  148. WOLFSSL_API
  149. int wc_ed448_import_public_ex(const byte* in, word32 inLen, ed448_key* key,
  150. int trusted);
  151. WOLFSSL_API
  152. int wc_ed448_import_private_only(const byte* priv, word32 privSz,
  153. ed448_key* key);
  154. WOLFSSL_API
  155. int wc_ed448_import_private_key(const byte* priv, word32 privSz,
  156. const byte* pub, word32 pubSz, ed448_key* key);
  157. WOLFSSL_API
  158. int wc_ed448_import_private_key_ex(const byte* priv, word32 privSz,
  159. const byte* pub, word32 pubSz, ed448_key* key, int trusted);
  160. #endif /* HAVE_ED448_KEY_IMPORT */
  161. #ifdef HAVE_ED448_KEY_EXPORT
  162. WOLFSSL_API
  163. int wc_ed448_export_public(ed448_key* key, byte* out, word32* outLen);
  164. WOLFSSL_API
  165. int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
  166. WOLFSSL_API
  167. int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
  168. WOLFSSL_API
  169. int wc_ed448_export_key(ed448_key* key, byte* priv, word32 *privSz,
  170. byte* pub, word32 *pubSz);
  171. #endif /* HAVE_ED448_KEY_EXPORT */
  172. WOLFSSL_API
  173. int wc_ed448_check_key(ed448_key* key);
  174. /* size helper */
  175. WOLFSSL_API
  176. int wc_ed448_size(ed448_key* key);
  177. WOLFSSL_API
  178. int wc_ed448_priv_size(ed448_key* key);
  179. WOLFSSL_API
  180. int wc_ed448_pub_size(ed448_key* key);
  181. WOLFSSL_API
  182. int wc_ed448_sig_size(ed448_key* key);
  183. #ifdef __cplusplus
  184. } /* extern "C" */
  185. #endif
  186. #endif /* HAVE_ED448 */
  187. #endif /* WOLF_CRYPT_ED448_H */