curve448.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /* curve448.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. /* Implemented to: RFC 7748 */
  22. #ifndef WOLF_CRYPT_CURVE448_H
  23. #define WOLF_CRYPT_CURVE448_H
  24. #include <wolfssl/wolfcrypt/types.h>
  25. #ifdef HAVE_CURVE448
  26. #include <wolfssl/wolfcrypt/fe_448.h>
  27. #include <wolfssl/wolfcrypt/random.h>
  28. #ifdef WOLFSSL_ASYNC_CRYPT
  29. #include <wolfssl/wolfcrypt/async.h>
  30. #endif
  31. #ifdef __cplusplus
  32. extern "C" {
  33. #endif
  34. #define CURVE448_KEY_SIZE 56
  35. #define CURVE448_PUB_KEY_SIZE 56
  36. #ifndef WC_CURVE448KEY_TYPE_DEFINED
  37. typedef struct curve448_key curve448_key;
  38. #define WC_CURVE448KEY_TYPE_DEFINED
  39. #endif
  40. /* A CURVE448 Key */
  41. struct curve448_key {
  42. byte p[CURVE448_PUB_KEY_SIZE]; /* public key */
  43. byte k[CURVE448_KEY_SIZE]; /* private key */
  44. #ifdef WOLFSSL_ASYNC_CRYPT
  45. WC_ASYNC_DEV asyncDev;
  46. #endif
  47. /* bit fields */
  48. byte pubSet:1;
  49. byte privSet:1;
  50. };
  51. enum {
  52. EC448_LITTLE_ENDIAN = 0,
  53. EC448_BIG_ENDIAN = 1
  54. };
  55. WOLFSSL_API
  56. int wc_curve448_make_key(WC_RNG* rng, int keysize, curve448_key* key);
  57. WOLFSSL_API
  58. int wc_curve448_make_pub(int public_size, byte* pub, int private_size,
  59. const byte* priv);
  60. WOLFSSL_API
  61. int wc_curve448_shared_secret(curve448_key* private_key,
  62. curve448_key* public_key,
  63. byte* out, word32* outlen);
  64. WOLFSSL_API
  65. int wc_curve448_shared_secret_ex(curve448_key* private_key,
  66. curve448_key* public_key,
  67. byte* out, word32* outlen, int endian);
  68. WOLFSSL_API
  69. int wc_curve448_init(curve448_key* key);
  70. WOLFSSL_API
  71. void wc_curve448_free(curve448_key* key);
  72. /* raw key helpers */
  73. WOLFSSL_API
  74. int wc_curve448_import_private(const byte* priv, word32 privSz,
  75. curve448_key* key);
  76. WOLFSSL_API
  77. int wc_curve448_import_private_ex(const byte* priv, word32 privSz,
  78. curve448_key* key, int endian);
  79. WOLFSSL_API
  80. int wc_curve448_import_private_raw(const byte* priv, word32 privSz,
  81. const byte* pub, word32 pubSz,
  82. curve448_key* key);
  83. WOLFSSL_API
  84. int wc_curve448_import_private_raw_ex(const byte* priv, word32 privSz,
  85. const byte* pub, word32 pubSz,
  86. curve448_key* key, int endian);
  87. WOLFSSL_API
  88. int wc_curve448_export_private_raw(curve448_key* key, byte* out,
  89. word32* outLen);
  90. WOLFSSL_API
  91. int wc_curve448_export_private_raw_ex(curve448_key* key, byte* out,
  92. word32* outLen, int endian);
  93. WOLFSSL_API
  94. int wc_curve448_import_public(const byte* in, word32 inLen,
  95. curve448_key* key);
  96. WOLFSSL_API
  97. int wc_curve448_import_public_ex(const byte* in, word32 inLen,
  98. curve448_key* key, int endian);
  99. WOLFSSL_API
  100. int wc_curve448_check_public(const byte* pub, word32 pubSz, int endian);
  101. WOLFSSL_API
  102. int wc_curve448_export_public(curve448_key* key, byte* out, word32* outLen);
  103. WOLFSSL_API
  104. int wc_curve448_export_public_ex(curve448_key* key, byte* out,
  105. word32* outLen, int endian);
  106. WOLFSSL_API
  107. int wc_curve448_export_key_raw(curve448_key* key,
  108. byte* priv, word32 *privSz,
  109. byte* pub, word32 *pubSz);
  110. WOLFSSL_API
  111. int wc_curve448_export_key_raw_ex(curve448_key* key,
  112. byte* priv, word32 *privSz,
  113. byte* pub, word32 *pubSz,
  114. int endian);
  115. /* size helper */
  116. WOLFSSL_API
  117. int wc_curve448_size(curve448_key* key);
  118. #ifdef __cplusplus
  119. } /* extern "C" */
  120. #endif
  121. #endif /* HAVE_CURVE448 */
  122. #endif /* WOLF_CRYPT_CURVE448_H */