aes.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /* aes.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/aes.h
  23. */
  24. /*
  25. DESCRIPTION
  26. This library provides the interfaces to the Advanced Encryption Standard (AES)
  27. for encrypting and decrypting data. AES is the standard known for a symmetric
  28. block cipher mechanism that uses n-bit binary string parameter key with 128-bits,
  29. 192-bits, and 256-bits of key sizes.
  30. */
  31. #ifndef WOLF_CRYPT_AES_H
  32. #define WOLF_CRYPT_AES_H
  33. #include <wolfssl/wolfcrypt/types.h>
  34. #ifndef NO_AES
  35. #if defined(HAVE_FIPS) && \
  36. defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2)
  37. #include <wolfssl/wolfcrypt/fips.h>
  38. #endif /* HAVE_FIPS_VERSION >= 2 */
  39. /* included for fips @wc_fips */
  40. #if defined(HAVE_FIPS) && \
  41. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
  42. #include <cyassl/ctaocrypt/aes.h>
  43. #if defined(CYASSL_AES_COUNTER) && !defined(WOLFSSL_AES_COUNTER)
  44. #define WOLFSSL_AES_COUNTER
  45. #endif
  46. #if !defined(WOLFSSL_AES_DIRECT) && defined(CYASSL_AES_DIRECT)
  47. #define WOLFSSL_AES_DIRECT
  48. #endif
  49. #endif
  50. #ifndef WC_NO_RNG
  51. #include <wolfssl/wolfcrypt/random.h>
  52. #endif
  53. #ifdef STM32_CRYPTO
  54. #include <wolfssl/wolfcrypt/port/st/stm32.h>
  55. #endif
  56. #ifdef WOLFSSL_IMXRT_DCP
  57. #include "fsl_dcp.h"
  58. #endif
  59. #ifdef WOLFSSL_XILINX_CRYPT
  60. #include "xsecure_aes.h"
  61. #endif
  62. #ifdef WOLFSSL_SE050
  63. #include <wolfssl/wolfcrypt/port/nxp/se050_port.h>
  64. #endif
  65. #if defined(WOLFSSL_AFALG) || defined(WOLFSSL_AFALG_XILINX_AES)
  66. /* included for struct msghdr */
  67. #include <wolfssl/wolfcrypt/port/af_alg/wc_afalg.h>
  68. #endif
  69. #if defined(WOLFSSL_KCAPI_AES)
  70. #include <wolfssl/wolfcrypt/port/kcapi/wc_kcapi.h>
  71. #endif
  72. #if defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC)
  73. #include <wolfssl/wolfcrypt/port/devcrypto/wc_devcrypto.h>
  74. #endif
  75. #ifdef WOLFSSL_SILABS_SE_ACCEL
  76. #include <wolfssl/wolfcrypt/port/silabs/silabs_aes.h>
  77. #endif
  78. #if defined(HAVE_AESGCM) && !defined(WC_NO_RNG)
  79. #include <wolfssl/wolfcrypt/random.h>
  80. #endif
  81. #if defined(WOLFSSL_HAVE_PSA) && !defined(WOLFSSL_PSA_NO_AES)
  82. #include <psa/crypto.h>
  83. #endif
  84. #if defined(WOLFSSL_CRYPTOCELL)
  85. #include <wolfssl/wolfcrypt/port/arm/cryptoCell.h>
  86. #endif
  87. #if defined(WOLFSSL_RENESAS_TSIP_TLS) && \
  88. defined(WOLFSSL_RENESAS_TSIP_TLS_AES_CRYPT)
  89. #include <wolfssl/wolfcrypt/port/Renesas/renesas_tsip_types.h>
  90. #endif
  91. #ifdef __cplusplus
  92. extern "C" {
  93. #endif
  94. #ifndef WOLFSSL_AES_KEY_SIZE_ENUM
  95. #define WOLFSSL_AES_KEY_SIZE_ENUM
  96. /* these are required for FIPS and non-FIPS */
  97. enum {
  98. AES_128_KEY_SIZE = 16, /* for 128 bit */
  99. AES_192_KEY_SIZE = 24, /* for 192 bit */
  100. AES_256_KEY_SIZE = 32, /* for 256 bit */
  101. AES_IV_SIZE = 16, /* always block size */
  102. };
  103. #endif
  104. /* avoid redefinition of structs */
  105. #if !defined(HAVE_FIPS) || \
  106. (defined(HAVE_FIPS_VERSION) && (HAVE_FIPS_VERSION >= 2))
  107. #ifdef WOLFSSL_ASYNC_CRYPT
  108. #include <wolfssl/wolfcrypt/async.h>
  109. #endif
  110. enum {
  111. AES_ENC_TYPE = WC_CIPHER_AES, /* cipher unique type */
  112. AES_ENCRYPTION = 0,
  113. AES_DECRYPTION = 1,
  114. AES_BLOCK_SIZE = 16,
  115. KEYWRAP_BLOCK_SIZE = 8,
  116. GCM_NONCE_MAX_SZ = 16, /* wolfCrypt's maximum nonce size allowed. */
  117. GCM_NONCE_MID_SZ = 12, /* The default nonce size for AES-GCM. */
  118. GCM_NONCE_MIN_SZ = 8, /* wolfCrypt's minimum nonce size allowed. */
  119. CCM_NONCE_MIN_SZ = 7,
  120. CCM_NONCE_MAX_SZ = 13,
  121. CTR_SZ = 4,
  122. AES_IV_FIXED_SZ = 4,
  123. #ifdef WOLFSSL_AES_CFB
  124. AES_CFB_MODE = 1,
  125. #endif
  126. #ifdef WOLFSSL_AES_OFB
  127. AES_OFB_MODE = 2,
  128. #endif
  129. #ifdef WOLFSSL_AES_XTS
  130. AES_XTS_MODE = 3,
  131. #endif
  132. #ifdef WOLF_PRIVATE_KEY_ID
  133. AES_MAX_ID_LEN = 32,
  134. AES_MAX_LABEL_LEN = 32,
  135. #endif
  136. };
  137. struct Aes {
  138. /* AESNI needs key first, rounds 2nd, not sure why yet */
  139. ALIGN16 word32 key[60];
  140. word32 rounds;
  141. int keylen;
  142. ALIGN16 word32 reg[AES_BLOCK_SIZE / sizeof(word32)]; /* for CBC mode */
  143. ALIGN16 word32 tmp[AES_BLOCK_SIZE / sizeof(word32)]; /* same */
  144. #if defined(HAVE_AESGCM) || defined(HAVE_AESCCM)
  145. word32 invokeCtr[2];
  146. word32 nonceSz;
  147. #endif
  148. #ifdef HAVE_AESGCM
  149. ALIGN16 byte H[AES_BLOCK_SIZE];
  150. #ifdef OPENSSL_EXTRA
  151. word32 aadH[4]; /* additional authenticated data GHASH */
  152. word32 aadLen; /* additional authenticated data len */
  153. #endif
  154. #ifdef WOLFSSL_SE050
  155. sss_symmetric_t aes_ctx; /* used as the function context */
  156. int ctxInitDone;
  157. int keyId;
  158. #endif
  159. #ifdef GCM_TABLE
  160. /* key-based fast multiplication table. */
  161. ALIGN16 byte M0[256][AES_BLOCK_SIZE];
  162. #elif defined(GCM_TABLE_4BIT)
  163. #if defined(BIG_ENDIAN_ORDER) || defined(WC_16BIT_CPU)
  164. ALIGN16 byte M0[16][AES_BLOCK_SIZE];
  165. #else
  166. ALIGN16 byte M0[32][AES_BLOCK_SIZE];
  167. #endif
  168. #endif /* GCM_TABLE */
  169. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  170. word32 y0;
  171. #endif
  172. #endif /* HAVE_AESGCM */
  173. #ifdef WOLFSSL_CAAM
  174. int blackKey; /* black key / hsm key id */
  175. #endif
  176. #ifdef WOLFSSL_AESNI
  177. byte use_aesni;
  178. #endif /* WOLFSSL_AESNI */
  179. #ifdef WOLF_CRYPTO_CB
  180. int devId;
  181. void* devCtx;
  182. #endif
  183. #ifdef WOLF_PRIVATE_KEY_ID
  184. byte id[AES_MAX_ID_LEN];
  185. int idLen;
  186. char label[AES_MAX_LABEL_LEN];
  187. int labelLen;
  188. #endif
  189. #ifdef WOLFSSL_ASYNC_CRYPT
  190. WC_ASYNC_DEV asyncDev;
  191. #endif /* WOLFSSL_ASYNC_CRYPT */
  192. #if defined(WOLFSSL_AES_COUNTER) || defined(WOLFSSL_AES_CFB) || \
  193. defined(WOLFSSL_AES_OFB) || defined(WOLFSSL_AES_XTS)
  194. word32 left; /* unused bytes left from last call */
  195. #endif
  196. #ifdef WOLFSSL_XILINX_CRYPT
  197. XSecure_Aes xilAes;
  198. XCsuDma dma;
  199. word32 key_init[8];
  200. word32 kup;
  201. #endif
  202. #if defined(WOLFSSL_AFALG) || defined(WOLFSSL_AFALG_XILINX_AES)
  203. int alFd; /* server socket to bind to */
  204. int rdFd; /* socket to read from */
  205. struct msghdr msg;
  206. int dir; /* flag for encrpyt or decrypt */
  207. #ifdef WOLFSSL_AFALG_XILINX_AES
  208. word32 msgBuf[CMSG_SPACE(4) + CMSG_SPACE(sizeof(struct af_alg_iv) +
  209. GCM_NONCE_MID_SZ)];
  210. #endif
  211. #endif
  212. #if defined(WOLFSSL_KCAPI_AES)
  213. struct kcapi_handle* handle;
  214. int init;
  215. #endif
  216. #if defined(WOLF_CRYPTO_CB) || (defined(WOLFSSL_DEVCRYPTO) && \
  217. (defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))) || \
  218. (defined(WOLFSSL_ASYNC_CRYPT) && defined(WC_ASYNC_ENABLE_AES)) || \
  219. defined(WOLFSSL_KCAPI_AES)
  220. word32 devKey[AES_MAX_KEY_SIZE/WOLFSSL_BIT_SIZE/sizeof(word32)]; /* raw key */
  221. #ifdef HAVE_CAVIUM_OCTEON_SYNC
  222. int keySet;
  223. #endif
  224. #endif
  225. #if defined(WOLFSSL_DEVCRYPTO) && \
  226. (defined(WOLFSSL_DEVCRYPTO_AES) || defined(WOLFSSL_DEVCRYPTO_CBC))
  227. WC_CRYPTODEV ctx;
  228. #endif
  229. #if defined(WOLFSSL_CRYPTOCELL)
  230. aes_context_t ctx;
  231. #endif
  232. #if defined(WOLFSSL_RENESAS_TSIP_TLS) && \
  233. defined(WOLFSSL_RENESAS_TSIP_TLS_AES_CRYPT)
  234. TSIP_AES_CTX ctx;
  235. #endif
  236. #if defined(WOLFSSL_RENESAS_SCEPROTECT)
  237. SCE_AES_CTX ctx;
  238. #endif
  239. #if defined(WOLFSSL_IMXRT_DCP)
  240. dcp_handle_t handle;
  241. #endif
  242. #if defined(WOLFSSL_SILABS_SE_ACCEL)
  243. silabs_aes_t ctx;
  244. #endif
  245. #if defined(WOLFSSL_HAVE_PSA) && !defined(WOLFSSL_PSA_NO_AES)
  246. psa_key_id_t key_id;
  247. psa_cipher_operation_t psa_ctx;
  248. int ctx_initialized;
  249. int key_need_importing;
  250. #endif
  251. void* heap; /* memory hint to use */
  252. #ifdef WOLFSSL_AESGCM_STREAM
  253. #if !defined(WOLFSSL_SMALL_STACK) || defined(WOLFSSL_AESNI)
  254. ALIGN16 byte streamData[5 * AES_BLOCK_SIZE];
  255. #else
  256. byte* streamData;
  257. #endif
  258. word32 aSz;
  259. word32 cSz;
  260. byte over;
  261. byte aOver;
  262. byte cOver;
  263. byte gcmKeySet:1;
  264. byte nonceSet:1;
  265. byte ctrSet:1;
  266. #endif
  267. };
  268. #ifndef WC_AES_TYPE_DEFINED
  269. typedef struct Aes Aes;
  270. #define WC_AES_TYPE_DEFINED
  271. #endif
  272. #ifdef WOLFSSL_AES_XTS
  273. typedef struct XtsAes {
  274. Aes aes;
  275. Aes tweak;
  276. } XtsAes;
  277. #endif
  278. #ifdef HAVE_AESGCM
  279. typedef struct Gmac {
  280. Aes aes;
  281. } Gmac;
  282. #endif /* HAVE_AESGCM */
  283. #endif /* HAVE_FIPS */
  284. /* Authenticate cipher function prototypes */
  285. typedef int (*wc_AesAuthEncryptFunc)(Aes* aes, byte* out,
  286. const byte* in, word32 sz,
  287. const byte* iv, word32 ivSz,
  288. byte* authTag, word32 authTagSz,
  289. const byte* authIn, word32 authInSz);
  290. typedef int (*wc_AesAuthDecryptFunc)(Aes* aes, byte* out,
  291. const byte* in, word32 sz,
  292. const byte* iv, word32 ivSz,
  293. const byte* authTag, word32 authTagSz,
  294. const byte* authIn, word32 authInSz);
  295. /* AES-CBC */
  296. WOLFSSL_API int wc_AesSetKey(Aes* aes, const byte* key, word32 len,
  297. const byte* iv, int dir);
  298. WOLFSSL_API int wc_AesSetIV(Aes* aes, const byte* iv);
  299. #ifdef HAVE_AES_CBC
  300. WOLFSSL_API int wc_AesCbcEncrypt(Aes* aes, byte* out,
  301. const byte* in, word32 sz);
  302. WOLFSSL_API int wc_AesCbcDecrypt(Aes* aes, byte* out,
  303. const byte* in, word32 sz);
  304. #endif
  305. #ifdef WOLFSSL_AES_CFB
  306. WOLFSSL_API int wc_AesCfbEncrypt(Aes* aes, byte* out,
  307. const byte* in, word32 sz);
  308. WOLFSSL_API int wc_AesCfb1Encrypt(Aes* aes, byte* out,
  309. const byte* in, word32 sz);
  310. WOLFSSL_API int wc_AesCfb8Encrypt(Aes* aes, byte* out,
  311. const byte* in, word32 sz);
  312. #ifdef HAVE_AES_DECRYPT
  313. WOLFSSL_API int wc_AesCfbDecrypt(Aes* aes, byte* out,
  314. const byte* in, word32 sz);
  315. WOLFSSL_API int wc_AesCfb1Decrypt(Aes* aes, byte* out,
  316. const byte* in, word32 sz);
  317. WOLFSSL_API int wc_AesCfb8Decrypt(Aes* aes, byte* out,
  318. const byte* in, word32 sz);
  319. #endif /* HAVE_AES_DECRYPT */
  320. #endif /* WOLFSSL_AES_CFB */
  321. #ifdef WOLFSSL_AES_OFB
  322. WOLFSSL_API int wc_AesOfbEncrypt(Aes* aes, byte* out,
  323. const byte* in, word32 sz);
  324. #ifdef HAVE_AES_DECRYPT
  325. WOLFSSL_API int wc_AesOfbDecrypt(Aes* aes, byte* out,
  326. const byte* in, word32 sz);
  327. #endif /* HAVE_AES_DECRYPT */
  328. #endif /* WOLFSSL_AES_OFB */
  329. #ifdef HAVE_AES_ECB
  330. WOLFSSL_API int wc_AesEcbEncrypt(Aes* aes, byte* out,
  331. const byte* in, word32 sz);
  332. WOLFSSL_API int wc_AesEcbDecrypt(Aes* aes, byte* out,
  333. const byte* in, word32 sz);
  334. #endif
  335. /* AES-CTR */
  336. #ifdef WOLFSSL_AES_COUNTER
  337. WOLFSSL_API int wc_AesCtrEncrypt(Aes* aes, byte* out,
  338. const byte* in, word32 sz);
  339. #endif
  340. /* AES-DIRECT */
  341. #if defined(WOLFSSL_AES_DIRECT)
  342. #if defined(HAVE_FIPS) && \
  343. (!defined(HAVE_FIPS_VERSION) || (HAVE_FIPS_VERSION < 2))
  344. WOLFSSL_API void wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
  345. WOLFSSL_API void wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
  346. WOLFSSL_API int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
  347. const byte* iv, int dir);
  348. #elif defined(BUILDING_WOLFSSL)
  349. WOLFSSL_API WARN_UNUSED_RESULT int wc_AesEncryptDirect(Aes* aes, byte* out,
  350. const byte* in);
  351. WOLFSSL_API WARN_UNUSED_RESULT int wc_AesDecryptDirect(Aes* aes, byte* out,
  352. const byte* in);
  353. WOLFSSL_API WARN_UNUSED_RESULT int wc_AesSetKeyDirect(Aes* aes,
  354. const byte* key,
  355. word32 len,
  356. const byte* iv, int dir);
  357. #else
  358. WOLFSSL_API int wc_AesEncryptDirect(Aes* aes, byte* out, const byte* in);
  359. WOLFSSL_API int wc_AesDecryptDirect(Aes* aes, byte* out, const byte* in);
  360. WOLFSSL_API int wc_AesSetKeyDirect(Aes* aes, const byte* key, word32 len,
  361. const byte* iv, int dir);
  362. #endif
  363. #endif
  364. #ifdef HAVE_AESGCM
  365. #ifdef WOLFSSL_XILINX_CRYPT
  366. WOLFSSL_API int wc_AesGcmSetKey_ex(Aes* aes, const byte* key, word32 len,
  367. word32 kup);
  368. #elif defined(WOLFSSL_AFALG_XILINX_AES)
  369. WOLFSSL_LOCAL int wc_AesGcmSetKey_ex(Aes* aes, const byte* key, word32 len,
  370. word32 kup);
  371. #endif
  372. WOLFSSL_API int wc_AesGcmSetKey(Aes* aes, const byte* key, word32 len);
  373. WOLFSSL_API int wc_AesGcmEncrypt(Aes* aes, byte* out,
  374. const byte* in, word32 sz,
  375. const byte* iv, word32 ivSz,
  376. byte* authTag, word32 authTagSz,
  377. const byte* authIn, word32 authInSz);
  378. WOLFSSL_API int wc_AesGcmDecrypt(Aes* aes, byte* out,
  379. const byte* in, word32 sz,
  380. const byte* iv, word32 ivSz,
  381. const byte* authTag, word32 authTagSz,
  382. const byte* authIn, word32 authInSz);
  383. #ifdef WOLFSSL_AESGCM_STREAM
  384. WOLFSSL_API int wc_AesGcmInit(Aes* aes, const byte* key, word32 len,
  385. const byte* iv, word32 ivSz);
  386. WOLFSSL_API int wc_AesGcmEncryptInit(Aes* aes, const byte* key, word32 len,
  387. const byte* iv, word32 ivSz);
  388. WOLFSSL_API int wc_AesGcmEncryptInit_ex(Aes* aes, const byte* key, word32 len,
  389. byte* ivOut, word32 ivOutSz);
  390. WOLFSSL_API int wc_AesGcmEncryptUpdate(Aes* aes, byte* out, const byte* in,
  391. word32 sz, const byte* authIn, word32 authInSz);
  392. WOLFSSL_API int wc_AesGcmEncryptFinal(Aes* aes, byte* authTag,
  393. word32 authTagSz);
  394. WOLFSSL_API int wc_AesGcmDecryptInit(Aes* aes, const byte* key, word32 len,
  395. const byte* iv, word32 ivSz);
  396. WOLFSSL_API int wc_AesGcmDecryptUpdate(Aes* aes, byte* out, const byte* in,
  397. word32 sz, const byte* authIn, word32 authInSz);
  398. WOLFSSL_API int wc_AesGcmDecryptFinal(Aes* aes, const byte* authTag,
  399. word32 authTagSz);
  400. #endif
  401. #ifndef WC_NO_RNG
  402. WOLFSSL_API int wc_AesGcmSetExtIV(Aes* aes, const byte* iv, word32 ivSz);
  403. WOLFSSL_API int wc_AesGcmSetIV(Aes* aes, word32 ivSz,
  404. const byte* ivFixed, word32 ivFixedSz,
  405. WC_RNG* rng);
  406. WOLFSSL_API int wc_AesGcmEncrypt_ex(Aes* aes, byte* out,
  407. const byte* in, word32 sz,
  408. byte* ivOut, word32 ivOutSz,
  409. byte* authTag, word32 authTagSz,
  410. const byte* authIn, word32 authInSz);
  411. #endif /* WC_NO_RNG */
  412. WOLFSSL_API int wc_GmacSetKey(Gmac* gmac, const byte* key, word32 len);
  413. WOLFSSL_API int wc_GmacUpdate(Gmac* gmac, const byte* iv, word32 ivSz,
  414. const byte* authIn, word32 authInSz,
  415. byte* authTag, word32 authTagSz);
  416. #ifndef WC_NO_RNG
  417. WOLFSSL_API int wc_Gmac(const byte* key, word32 keySz, byte* iv, word32 ivSz,
  418. const byte* authIn, word32 authInSz,
  419. byte* authTag, word32 authTagSz, WC_RNG* rng);
  420. WOLFSSL_API int wc_GmacVerify(const byte* key, word32 keySz,
  421. const byte* iv, word32 ivSz,
  422. const byte* authIn, word32 authInSz,
  423. const byte* authTag, word32 authTagSz);
  424. #endif /* WC_NO_RNG */
  425. WOLFSSL_LOCAL void GHASH(Aes* aes, const byte* a, word32 aSz, const byte* c,
  426. word32 cSz, byte* s, word32 sSz);
  427. #endif /* HAVE_AESGCM */
  428. #ifdef HAVE_AESCCM
  429. WOLFSSL_LOCAL int wc_AesCcmCheckTagSize(int sz);
  430. WOLFSSL_API int wc_AesCcmSetKey(Aes* aes, const byte* key, word32 keySz);
  431. WOLFSSL_API int wc_AesCcmEncrypt(Aes* aes, byte* out,
  432. const byte* in, word32 inSz,
  433. const byte* nonce, word32 nonceSz,
  434. byte* authTag, word32 authTagSz,
  435. const byte* authIn, word32 authInSz);
  436. WOLFSSL_API int wc_AesCcmDecrypt(Aes* aes, byte* out,
  437. const byte* in, word32 inSz,
  438. const byte* nonce, word32 nonceSz,
  439. const byte* authTag, word32 authTagSz,
  440. const byte* authIn, word32 authInSz);
  441. WOLFSSL_API int wc_AesCcmSetNonce(Aes* aes,
  442. const byte* nonce, word32 nonceSz);
  443. WOLFSSL_API int wc_AesCcmEncrypt_ex(Aes* aes, byte* out,
  444. const byte* in, word32 sz,
  445. byte* ivOut, word32 ivOutSz,
  446. byte* authTag, word32 authTagSz,
  447. const byte* authIn, word32 authInSz);
  448. #endif /* HAVE_AESCCM */
  449. #ifdef HAVE_AES_KEYWRAP
  450. WOLFSSL_API int wc_AesKeyWrap(const byte* key, word32 keySz,
  451. const byte* in, word32 inSz,
  452. byte* out, word32 outSz,
  453. const byte* iv);
  454. WOLFSSL_API int wc_AesKeyWrap_ex(Aes *aes,
  455. const byte* in, word32 inSz,
  456. byte* out, word32 outSz,
  457. const byte* iv);
  458. WOLFSSL_API int wc_AesKeyUnWrap(const byte* key, word32 keySz,
  459. const byte* in, word32 inSz,
  460. byte* out, word32 outSz,
  461. const byte* iv);
  462. WOLFSSL_API int wc_AesKeyUnWrap_ex(Aes *aes,
  463. const byte* in, word32 inSz,
  464. byte* out, word32 outSz,
  465. const byte* iv);
  466. #endif /* HAVE_AES_KEYWRAP */
  467. #ifdef WOLFSSL_AES_XTS
  468. WOLFSSL_API int wc_AesXtsSetKey(XtsAes* aes, const byte* key,
  469. word32 len, int dir, void* heap, int devId);
  470. WOLFSSL_API int wc_AesXtsEncryptSector(XtsAes* aes, byte* out,
  471. const byte* in, word32 sz, word64 sector);
  472. WOLFSSL_API int wc_AesXtsDecryptSector(XtsAes* aes, byte* out,
  473. const byte* in, word32 sz, word64 sector);
  474. WOLFSSL_API int wc_AesXtsEncrypt(XtsAes* aes, byte* out,
  475. const byte* in, word32 sz, const byte* i, word32 iSz);
  476. WOLFSSL_API int wc_AesXtsDecrypt(XtsAes* aes, byte* out,
  477. const byte* in, word32 sz, const byte* i, word32 iSz);
  478. WOLFSSL_API int wc_AesXtsFree(XtsAes* aes);
  479. #endif
  480. WOLFSSL_API int wc_AesGetKeySize(Aes* aes, word32* keySize);
  481. WOLFSSL_API int wc_AesInit(Aes* aes, void* heap, int devId);
  482. #ifdef WOLF_PRIVATE_KEY_ID
  483. WOLFSSL_API int wc_AesInit_Id(Aes* aes, unsigned char* id, int len, void* heap,
  484. int devId);
  485. WOLFSSL_API int wc_AesInit_Label(Aes* aes, const char* label, void* heap,
  486. int devId);
  487. #endif
  488. WOLFSSL_API void wc_AesFree(Aes* aes);
  489. #ifdef WOLFSSL_AES_SIV
  490. WOLFSSL_API
  491. int wc_AesSivEncrypt(const byte* key, word32 keySz, const byte* assoc,
  492. word32 assocSz, const byte* nonce, word32 nonceSz,
  493. const byte* in, word32 inSz, byte* siv, byte* out);
  494. WOLFSSL_API
  495. int wc_AesSivDecrypt(const byte* key, word32 keySz, const byte* assoc,
  496. word32 assocSz, const byte* nonce, word32 nonceSz,
  497. const byte* in, word32 inSz, byte* siv, byte* out);
  498. #endif
  499. #ifdef __cplusplus
  500. } /* extern "C" */
  501. #endif
  502. #endif /* NO_AES */
  503. #endif /* WOLF_CRYPT_AES_H */