falcon.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /* falcon.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/falcon.h
  23. */
  24. /* Interfaces for Falcon NIST Level 1 (Falcon512) and Falcon NIST Level 5
  25. * (Falcon1024). */
  26. #ifndef WOLF_CRYPT_FALCON_H
  27. #define WOLF_CRYPT_FALCON_H
  28. #include <wolfssl/wolfcrypt/types.h>
  29. #if defined(HAVE_PQC) && defined(HAVE_FALCON)
  30. #ifdef HAVE_LIBOQS
  31. #include <oqs/oqs.h>
  32. #endif
  33. #ifdef __cplusplus
  34. extern "C" {
  35. #endif
  36. /* Macros Definitions */
  37. #ifdef HAVE_LIBOQS
  38. #define FALCON_LEVEL1_KEY_SIZE OQS_SIG_falcon_512_length_secret_key
  39. #define FALCON_LEVEL1_SIG_SIZE OQS_SIG_falcon_512_length_signature
  40. #define FALCON_LEVEL1_PUB_KEY_SIZE OQS_SIG_falcon_512_length_public_key
  41. #define FALCON_LEVEL1_PRV_KEY_SIZE (FALCON_LEVEL1_PUB_KEY_SIZE+FALCON_LEVEL1_KEY_SIZE)
  42. #define FALCON_LEVEL5_KEY_SIZE OQS_SIG_falcon_1024_length_secret_key
  43. #define FALCON_LEVEL5_SIG_SIZE OQS_SIG_falcon_1024_length_signature
  44. #define FALCON_LEVEL5_PUB_KEY_SIZE OQS_SIG_falcon_1024_length_public_key
  45. #define FALCON_LEVEL5_PRV_KEY_SIZE (FALCON_LEVEL5_PUB_KEY_SIZE+FALCON_LEVEL5_KEY_SIZE)
  46. #endif
  47. #define FALCON_MAX_KEY_SIZE FALCON_LEVEL5_PRV_KEY_SIZE
  48. #define FALCON_MAX_SIG_SIZE FALCON_LEVEL5_SIG_SIZE
  49. #define FALCON_MAX_PUB_KEY_SIZE FALCON_LEVEL5_PUB_KEY_SIZE
  50. #define FALCON_MAX_PRV_KEY_SIZE FALCON_LEVEL5_PRV_KEY_SIZE
  51. /* Structs */
  52. struct falcon_key {
  53. bool pubKeySet;
  54. bool prvKeySet;
  55. byte level;
  56. byte p[FALCON_MAX_PUB_KEY_SIZE];
  57. byte k[FALCON_MAX_PRV_KEY_SIZE];
  58. };
  59. #ifndef WC_FALCONKEY_TYPE_DEFINED
  60. typedef struct falcon_key falcon_key;
  61. #define WC_FALCONKEY_TYPE_DEFINED
  62. #endif
  63. /* Functions */
  64. WOLFSSL_API
  65. int wc_falcon_sign_msg(const byte* in, word32 inLen, byte* out, word32 *outLen,
  66. falcon_key* key);
  67. WOLFSSL_API
  68. int wc_falcon_verify_msg(const byte* sig, word32 sigLen, const byte* msg,
  69. word32 msgLen, int* res, falcon_key* key);
  70. WOLFSSL_API
  71. int wc_falcon_init(falcon_key* key);
  72. WOLFSSL_API
  73. int wc_falcon_set_level(falcon_key* key, byte level);
  74. WOLFSSL_API
  75. int wc_falcon_get_level(falcon_key* key, byte* level);
  76. WOLFSSL_API
  77. void wc_falcon_free(falcon_key* key);
  78. WOLFSSL_API
  79. int wc_falcon_import_public(const byte* in, word32 inLen, falcon_key* key);
  80. WOLFSSL_API
  81. int wc_falcon_import_private_only(const byte* priv, word32 privSz,
  82. falcon_key* key);
  83. WOLFSSL_API
  84. int wc_falcon_import_private_key(const byte* priv, word32 privSz,
  85. const byte* pub, word32 pubSz,
  86. falcon_key* key);
  87. WOLFSSL_API
  88. int wc_falcon_export_public(falcon_key*, byte* out, word32* outLen);
  89. WOLFSSL_API
  90. int wc_falcon_export_private_only(falcon_key* key, byte* out, word32* outLen);
  91. WOLFSSL_API
  92. int wc_falcon_export_private(falcon_key* key, byte* out, word32* outLen);
  93. WOLFSSL_API
  94. int wc_falcon_export_key(falcon_key* key, byte* priv, word32 *privSz,
  95. byte* pub, word32 *pubSz);
  96. WOLFSSL_API
  97. int wc_falcon_check_key(falcon_key* key);
  98. WOLFSSL_API
  99. int wc_falcon_size(falcon_key* key);
  100. WOLFSSL_API
  101. int wc_falcon_priv_size(falcon_key* key);
  102. WOLFSSL_API
  103. int wc_falcon_pub_size(falcon_key* key);
  104. WOLFSSL_API
  105. int wc_falcon_sig_size(falcon_key* key);
  106. #ifdef __cplusplus
  107. } /* extern "C" */
  108. #endif
  109. #endif /* HAVE_PQC && HAVE_FALCON */
  110. #endif /* WOLF_CRYPT_FALCON_H */