aes.h 18 KB

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