ext_kyber.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* ext_kyber.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. #ifndef EXT_KYBER_H
  22. #define EXT_KYBER_H
  23. #ifdef WOLFSSL_HAVE_KYBER
  24. #include <wolfssl/wolfcrypt/kyber.h>
  25. #if !defined(HAVE_LIBOQS) && !defined(HAVE_PQM4)
  26. #error "This code requires liboqs or pqm4"
  27. #endif
  28. #if defined(WOLFSSL_WC_KYBER)
  29. #error "This code is incompatible with wolfCrypt's implementation of Kyber."
  30. #endif
  31. #if defined (HAVE_LIBOQS)
  32. #include <oqs/kem.h>
  33. #define EXT_KYBER_MAX_PRIV_SZ OQS_KEM_kyber_1024_length_secret_key
  34. #define EXT_KYBER_MAX_PUB_SZ OQS_KEM_kyber_1024_length_public_key
  35. #elif defined(HAVE_PQM4)
  36. #include "api_kyber.h"
  37. #define PQM4_PUBLIC_KEY_LENGTH CRYPTO_PUBLICKEYBYTES
  38. #define PQM4_PRIVATE_KEY_LENGTH CRYPTO_SECRETKEYBYTES
  39. #define PQM4_SHARED_SECRET_LENGTH CRYPTO_BYTES
  40. #define PQM4_CIPHERTEXT_LENGTH CRYPTO_CIPHERTEXTBYTES
  41. #define EXT_KYBER_MAX_PRIV_SZ PQM4_PRIVATE_KEY_LENGTH
  42. #define EXT_KYBER_MAX_PUB_SZ PQM4_PUBLIC_KEY_LENGTH
  43. #endif
  44. struct KyberKey {
  45. /* Type of key: KYBER_LEVEL1
  46. * KYBER_LEVEL3
  47. * KYBER_LEVEL5
  48. *
  49. * Note we don't save the variant (SHAKE vs AES) as that is decided at
  50. * configuration time. */
  51. int type;
  52. byte priv[EXT_KYBER_MAX_PRIV_SZ];
  53. byte pub[EXT_KYBER_MAX_PUB_SZ];
  54. };
  55. #if defined (HAVE_LIBOQS)
  56. WOLFSSL_LOCAL int ext_kyber_enabled(int id);
  57. #endif
  58. #endif /* WOLFSSL_HAVE_KYBER */
  59. #endif /* EXT_KYBER_H */