ed448.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /* ed448.h
  2. *
  3. * Copyright (C) 2006-2022 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. int devId;
  80. #endif
  81. void *heap;
  82. #ifdef WOLFSSL_ED448_PERSISTENT_SHA
  83. wc_Shake sha;
  84. int sha_clean_flag;
  85. #endif
  86. };
  87. WOLFSSL_API
  88. int wc_ed448_make_public(ed448_key* key, unsigned char* pubKey,
  89. word32 pubKeySz);
  90. WOLFSSL_API
  91. int wc_ed448_make_key(WC_RNG* rng, int keysize, ed448_key* key);
  92. #ifdef HAVE_ED448_SIGN
  93. WOLFSSL_API
  94. int wc_ed448_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
  95. ed448_key* key, const byte* context, byte contextLen);
  96. WOLFSSL_API
  97. int wc_ed448ph_sign_hash(const byte* hash, word32 hashLen, byte* out,
  98. word32 *outLen, ed448_key* key,
  99. const byte* context, byte contextLen);
  100. WOLFSSL_API
  101. int wc_ed448_sign_msg_ex(const byte* in, word32 inLen, byte* out,
  102. word32 *outLen, ed448_key* key, byte type,
  103. const byte* context, byte contextLen);
  104. WOLFSSL_API
  105. int wc_ed448ph_sign_msg(const byte* in, word32 inLen, byte* out,
  106. word32 *outLen, ed448_key* key, const byte* context,
  107. byte contextLen);
  108. #endif /* HAVE_ED448_SIGN */
  109. #ifdef HAVE_ED448_VERIFY
  110. WOLFSSL_API
  111. int wc_ed448_verify_msg_ex(const byte* sig, word32 sigLen, const byte* msg,
  112. word32 msgLen, int* res, ed448_key* key,
  113. byte type, const byte* context, byte contextLen);
  114. #ifdef WOLFSSL_ED448_STREAMING_VERIFY
  115. WOLFSSL_API
  116. int wc_ed448_verify_msg_init(const byte* sig, word32 sigLen, ed448_key* key,
  117. byte type, const byte* context, byte contextLen);
  118. WOLFSSL_API
  119. int wc_ed448_verify_msg_update(const byte* msgSegment, word32 msgSegmentLen,
  120. ed448_key* key);
  121. WOLFSSL_API
  122. int wc_ed448_verify_msg_final(const byte* sig, word32 sigLen,
  123. int* res, ed448_key* key);
  124. #endif /* WOLFSSL_ED448_STREAMING_VERIFY */
  125. WOLFSSL_API
  126. int wc_ed448_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
  127. word32 msgLen, int* res, ed448_key* key,
  128. const byte* context, byte contextLen);
  129. WOLFSSL_API
  130. int wc_ed448ph_verify_hash(const byte* sig, word32 sigLen, const byte* hash,
  131. word32 hashLen, int* res, ed448_key* key,
  132. const byte* context, byte contextLen);
  133. WOLFSSL_API
  134. int wc_ed448ph_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
  135. word32 msgLen, int* res, ed448_key* key,
  136. const byte* context, byte contextLen);
  137. #endif /* HAVE_ED448_VERIFY */
  138. WOLFSSL_API
  139. int wc_ed448_init_ex(ed448_key* key, void *heap, int devId);
  140. WOLFSSL_API
  141. int wc_ed448_init(ed448_key* key);
  142. WOLFSSL_API
  143. void wc_ed448_free(ed448_key* key);
  144. #ifdef HAVE_ED448_KEY_IMPORT
  145. WOLFSSL_API
  146. int wc_ed448_import_public(const byte* in, word32 inLen, ed448_key* key);
  147. WOLFSSL_API
  148. int wc_ed448_import_public_ex(const byte* in, word32 inLen, ed448_key* key,
  149. int trusted);
  150. WOLFSSL_API
  151. int wc_ed448_import_private_only(const byte* priv, word32 privSz,
  152. ed448_key* key);
  153. WOLFSSL_API
  154. int wc_ed448_import_private_key(const byte* priv, word32 privSz,
  155. const byte* pub, word32 pubSz, ed448_key* key);
  156. WOLFSSL_API
  157. int wc_ed448_import_private_key_ex(const byte* priv, word32 privSz,
  158. const byte* pub, word32 pubSz, ed448_key* key, int trusted);
  159. #endif /* HAVE_ED448_KEY_IMPORT */
  160. #ifdef HAVE_ED448_KEY_EXPORT
  161. WOLFSSL_API
  162. int wc_ed448_export_public(ed448_key* key, byte* out, word32* outLen);
  163. WOLFSSL_API
  164. int wc_ed448_export_private_only(ed448_key* key, byte* out, word32* outLen);
  165. WOLFSSL_API
  166. int wc_ed448_export_private(ed448_key* key, byte* out, word32* outLen);
  167. WOLFSSL_API
  168. int wc_ed448_export_key(ed448_key* key, byte* priv, word32 *privSz,
  169. byte* pub, word32 *pubSz);
  170. #endif /* HAVE_ED448_KEY_EXPORT */
  171. WOLFSSL_API
  172. int wc_ed448_check_key(ed448_key* key);
  173. /* size helper */
  174. WOLFSSL_API
  175. int wc_ed448_size(ed448_key* key);
  176. WOLFSSL_API
  177. int wc_ed448_priv_size(ed448_key* key);
  178. WOLFSSL_API
  179. int wc_ed448_pub_size(ed448_key* key);
  180. WOLFSSL_API
  181. int wc_ed448_sig_size(ed448_key* key);
  182. #ifdef __cplusplus
  183. } /* extern "C" */
  184. #endif
  185. #endif /* HAVE_ED448 */
  186. #endif /* WOLF_CRYPT_ED448_H */