wc_encrypt.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* wc_encrypt.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/wc_encrypt.h
  23. */
  24. #ifndef WOLF_CRYPT_ENCRYPT_H
  25. #define WOLF_CRYPT_ENCRYPT_H
  26. #include <wolfssl/wolfcrypt/types.h>
  27. #ifndef NO_AES
  28. #include <wolfssl/wolfcrypt/aes.h>
  29. #endif
  30. #ifdef HAVE_CHACHA
  31. #include <wolfssl/wolfcrypt/chacha.h>
  32. #endif
  33. #ifndef NO_DES3
  34. #include <wolfssl/wolfcrypt/des3.h>
  35. #endif
  36. #ifndef NO_RC4
  37. #include <wolfssl/wolfcrypt/arc4.h>
  38. #endif
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42. /* determine max cipher key size - cannot use enum values here, must be define,
  43. * since WC_MAX_SYM_KEY_SIZE is used in if macro logic. */
  44. #ifndef NO_AES
  45. #define WC_MAX_SYM_KEY_SIZE (AES_MAX_KEY_SIZE/8)
  46. #elif defined(HAVE_CHACHA)
  47. #define WC_MAX_SYM_KEY_SIZE 32 /* CHACHA_MAX_KEY_SZ */
  48. #elif !defined(NO_DES3)
  49. #define WC_MAX_SYM_KEY_SIZE 24 /* DES3_KEY_SIZE */
  50. #elif !defined(NO_RC4)
  51. #define WC_MAX_SYM_KEY_SIZE 16 /* RC4_KEY_SIZE */
  52. #else
  53. #define WC_MAX_SYM_KEY_SIZE 32
  54. #endif
  55. #if (defined(HAVE_FIPS) && defined(HAVE_FIPS_VERSION) && \
  56. (HAVE_FIPS_VERSION <= 2)) || (defined(HAVE_SELFTEST) && \
  57. (!defined(HAVE_SELFTEST_VERSION) || (HAVE_SELFTEST_VERSION < 2)))
  58. /* In FIPS cert 3389 and CAVP selftest v1 build, these enums are
  59. * not in aes.h. Define them here outside the fips boundary.
  60. */
  61. #ifndef GCM_NONCE_MID_SZ
  62. /* The usual default nonce size for AES-GCM. */
  63. #define GCM_NONCE_MID_SZ 12
  64. #endif
  65. #ifndef CCM_NONCE_MIN_SZ
  66. #define CCM_NONCE_MIN_SZ 7
  67. #endif
  68. #endif
  69. #if !defined(NO_AES) && defined(HAVE_AES_CBC)
  70. WOLFSSL_API int wc_AesCbcEncryptWithKey(byte* out, const byte* in, word32 inSz,
  71. const byte* key, word32 keySz,
  72. const byte* iv);
  73. WOLFSSL_API int wc_AesCbcDecryptWithKey(byte* out, const byte* in, word32 inSz,
  74. const byte* key, word32 keySz,
  75. const byte* iv);
  76. #endif /* !NO_AES */
  77. #ifndef NO_DES3
  78. WOLFSSL_API int wc_Des_CbcDecryptWithKey(byte* out,
  79. const byte* in, word32 sz,
  80. const byte* key, const byte* iv);
  81. WOLFSSL_API int wc_Des_CbcEncryptWithKey(byte* out,
  82. const byte* in, word32 sz,
  83. const byte* key, const byte* iv);
  84. WOLFSSL_API int wc_Des3_CbcEncryptWithKey(byte* out,
  85. const byte* in, word32 sz,
  86. const byte* key, const byte* iv);
  87. WOLFSSL_API int wc_Des3_CbcDecryptWithKey(byte* out,
  88. const byte* in, word32 sz,
  89. const byte* key, const byte* iv);
  90. #endif /* !NO_DES3 */
  91. #ifdef WOLFSSL_ENCRYPTED_KEYS
  92. struct EncryptedInfo;
  93. WOLFSSL_API int wc_BufferKeyDecrypt(struct EncryptedInfo* info, byte* der, word32 derSz,
  94. const byte* password, int passwordSz, int hashType);
  95. WOLFSSL_API int wc_BufferKeyEncrypt(struct EncryptedInfo* info, byte* der, word32 derSz,
  96. const byte* password, int passwordSz, int hashType);
  97. #endif /* WOLFSSL_ENCRYPTED_KEYS */
  98. #ifndef NO_PWDBASED
  99. WOLFSSL_LOCAL int wc_CryptKey(const char* password, int passwordSz,
  100. byte* salt, int saltSz, int iterations, int id, byte* input, int length,
  101. int version, byte* cbcIv, int enc, int shaOid);
  102. #endif
  103. #ifdef __cplusplus
  104. } /* extern "C" */
  105. #endif
  106. #endif /* WOLF_CRYPT_ENCRYPT_H */