aes.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. /**
  2. * \file aes.h
  3. *
  4. * \brief This file contains AES definitions and functions.
  5. *
  6. * The Advanced Encryption Standard (AES) specifies a FIPS-approved
  7. * cryptographic algorithm that can be used to protect electronic
  8. * data.
  9. *
  10. * The AES algorithm is a symmetric block cipher that can
  11. * encrypt and decrypt information. For more information, see
  12. * <em>FIPS Publication 197: Advanced Encryption Standard</em> and
  13. * <em>ISO/IEC 18033-2:2006: Information technology -- Security
  14. * techniques -- Encryption algorithms -- Part 2: Asymmetric
  15. * ciphers</em>.
  16. *
  17. * The AES-XTS block mode is standardized by NIST SP 800-38E
  18. * <https://nvlpubs.nist.gov/nistpubs/legacy/sp/nistspecialpublication800-38e.pdf>
  19. * and described in detail by IEEE P1619
  20. * <https://ieeexplore.ieee.org/servlet/opac?punumber=4375278>.
  21. */
  22. /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
  23. * SPDX-License-Identifier: Apache-2.0
  24. *
  25. * Licensed under the Apache License, Version 2.0 (the "License"); you may
  26. * not use this file except in compliance with the License.
  27. * You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing, software
  32. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  33. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. * See the License for the specific language governing permissions and
  35. * limitations under the License.
  36. *
  37. * This file is part of Mbed TLS (https://tls.mbed.org)
  38. */
  39. #ifndef MBEDTLS_AES_H
  40. #define MBEDTLS_AES_H
  41. #if !defined(MBEDTLS_CONFIG_FILE)
  42. #include "config.h"
  43. #else
  44. #include MBEDTLS_CONFIG_FILE
  45. #endif
  46. #include <stddef.h>
  47. #include <stdint.h>
  48. /* padlock.c and aesni.c rely on these values! */
  49. #define MBEDTLS_AES_ENCRYPT 1 /**< AES encryption. */
  50. #define MBEDTLS_AES_DECRYPT 0 /**< AES decryption. */
  51. /* Error codes in range 0x0020-0x0022 */
  52. #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020 /**< Invalid key length. */
  53. #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022 /**< Invalid data input length. */
  54. /* Error codes in range 0x0021-0x0025 */
  55. #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021 /**< Invalid input data. */
  56. #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023 /**< Feature not available. For example, an unsupported AES key size. */
  57. #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025 /**< AES hardware accelerator failed. */
  58. #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
  59. !defined(inline) && !defined(__cplusplus)
  60. #define inline __inline
  61. #endif
  62. #ifdef __cplusplus
  63. extern "C" {
  64. #endif
  65. #if !defined(MBEDTLS_AES_ALT)
  66. // Regular implementation
  67. //
  68. /**
  69. * \brief The AES context-type definition.
  70. */
  71. typedef struct
  72. {
  73. int nr; /*!< The number of rounds. */
  74. uint32_t *rk; /*!< AES round keys. */
  75. uint32_t buf[68]; /*!< Unaligned data buffer. This buffer can
  76. hold 32 extra Bytes, which can be used for
  77. one of the following purposes:
  78. <ul><li>Alignment if VIA padlock is
  79. used.</li>
  80. <li>Simplifying key expansion in the 256-bit
  81. case by generating an extra round key.
  82. </li></ul> */
  83. }
  84. mbedtls_aes_context;
  85. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  86. /**
  87. * \brief The AES XTS context-type definition.
  88. */
  89. typedef struct
  90. {
  91. mbedtls_aes_context crypt; /*!< The AES context to use for AES block
  92. encryption or decryption. */
  93. mbedtls_aes_context tweak; /*!< The AES context used for tweak
  94. computation. */
  95. } mbedtls_aes_xts_context;
  96. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  97. #else /* MBEDTLS_AES_ALT */
  98. #include "aes_alt.h"
  99. #endif /* MBEDTLS_AES_ALT */
  100. /**
  101. * \brief This function initializes the specified AES context.
  102. *
  103. * It must be the first API called before using
  104. * the context.
  105. *
  106. * \param ctx The AES context to initialize.
  107. */
  108. void mbedtls_aes_init( mbedtls_aes_context *ctx );
  109. /**
  110. * \brief This function releases and clears the specified AES context.
  111. *
  112. * \param ctx The AES context to clear.
  113. */
  114. void mbedtls_aes_free( mbedtls_aes_context *ctx );
  115. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  116. /**
  117. * \brief This function initializes the specified AES XTS context.
  118. *
  119. * It must be the first API called before using
  120. * the context.
  121. *
  122. * \param ctx The AES XTS context to initialize.
  123. */
  124. void mbedtls_aes_xts_init( mbedtls_aes_xts_context *ctx );
  125. /**
  126. * \brief This function releases and clears the specified AES XTS context.
  127. *
  128. * \param ctx The AES XTS context to clear.
  129. */
  130. void mbedtls_aes_xts_free( mbedtls_aes_xts_context *ctx );
  131. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  132. /**
  133. * \brief This function sets the encryption key.
  134. *
  135. * \param ctx The AES context to which the key should be bound.
  136. * \param key The encryption key.
  137. * \param keybits The size of data passed in bits. Valid options are:
  138. * <ul><li>128 bits</li>
  139. * <li>192 bits</li>
  140. * <li>256 bits</li></ul>
  141. *
  142. * \return \c 0 on success.
  143. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
  144. */
  145. int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
  146. unsigned int keybits );
  147. /**
  148. * \brief This function sets the decryption key.
  149. *
  150. * \param ctx The AES context to which the key should be bound.
  151. * \param key The decryption key.
  152. * \param keybits The size of data passed. Valid options are:
  153. * <ul><li>128 bits</li>
  154. * <li>192 bits</li>
  155. * <li>256 bits</li></ul>
  156. *
  157. * \return \c 0 on success.
  158. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
  159. */
  160. int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
  161. unsigned int keybits );
  162. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  163. /**
  164. * \brief This function prepares an XTS context for encryption and
  165. * sets the encryption key.
  166. *
  167. * \param ctx The AES XTS context to which the key should be bound.
  168. * \param key The encryption key. This is comprised of the XTS key1
  169. * concatenated with the XTS key2.
  170. * \param keybits The size of \p key passed in bits. Valid options are:
  171. * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
  172. * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
  173. *
  174. * \return \c 0 on success.
  175. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
  176. */
  177. int mbedtls_aes_xts_setkey_enc( mbedtls_aes_xts_context *ctx,
  178. const unsigned char *key,
  179. unsigned int keybits );
  180. /**
  181. * \brief This function prepares an XTS context for decryption and
  182. * sets the decryption key.
  183. *
  184. * \param ctx The AES XTS context to which the key should be bound.
  185. * \param key The decryption key. This is comprised of the XTS key1
  186. * concatenated with the XTS key2.
  187. * \param keybits The size of \p key passed in bits. Valid options are:
  188. * <ul><li>256 bits (each of key1 and key2 is a 128-bit key)</li>
  189. * <li>512 bits (each of key1 and key2 is a 256-bit key)</li></ul>
  190. *
  191. * \return \c 0 on success.
  192. * \return #MBEDTLS_ERR_AES_INVALID_KEY_LENGTH on failure.
  193. */
  194. int mbedtls_aes_xts_setkey_dec( mbedtls_aes_xts_context *ctx,
  195. const unsigned char *key,
  196. unsigned int keybits );
  197. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  198. /**
  199. * \brief This function performs an AES single-block encryption or
  200. * decryption operation.
  201. *
  202. * It performs the operation defined in the \p mode parameter
  203. * (encrypt or decrypt), on the input data buffer defined in
  204. * the \p input parameter.
  205. *
  206. * mbedtls_aes_init(), and either mbedtls_aes_setkey_enc() or
  207. * mbedtls_aes_setkey_dec() must be called before the first
  208. * call to this API with the same context.
  209. *
  210. * \param ctx The AES context to use for encryption or decryption.
  211. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  212. * #MBEDTLS_AES_DECRYPT.
  213. * \param input The 16-Byte buffer holding the input data.
  214. * \param output The 16-Byte buffer holding the output data.
  215. * \return \c 0 on success.
  216. */
  217. int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
  218. int mode,
  219. const unsigned char input[16],
  220. unsigned char output[16] );
  221. #if defined(MBEDTLS_CIPHER_MODE_CBC)
  222. /**
  223. * \brief This function performs an AES-CBC encryption or decryption operation
  224. * on full blocks.
  225. *
  226. * It performs the operation defined in the \p mode
  227. * parameter (encrypt/decrypt), on the input data buffer defined in
  228. * the \p input parameter.
  229. *
  230. * It can be called as many times as needed, until all the input
  231. * data is processed. mbedtls_aes_init(), and either
  232. * mbedtls_aes_setkey_enc() or mbedtls_aes_setkey_dec() must be called
  233. * before the first call to this API with the same context.
  234. *
  235. * \note This function operates on aligned blocks, that is, the input size
  236. * must be a multiple of the AES block size of 16 Bytes.
  237. *
  238. * \note Upon exit, the content of the IV is updated so that you can
  239. * call the same function again on the next
  240. * block(s) of data and get the same result as if it was
  241. * encrypted in one call. This allows a "streaming" usage.
  242. * If you need to retain the contents of the IV, you should
  243. * either save it manually or use the cipher module instead.
  244. *
  245. *
  246. * \param ctx The AES context to use for encryption or decryption.
  247. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  248. * #MBEDTLS_AES_DECRYPT.
  249. * \param length The length of the input data in Bytes. This must be a
  250. * multiple of the block size (16 Bytes).
  251. * \param iv Initialization vector (updated after use).
  252. * \param input The buffer holding the input data.
  253. * \param output The buffer holding the output data.
  254. *
  255. * \return \c 0 on success.
  256. * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH
  257. * on failure.
  258. */
  259. int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
  260. int mode,
  261. size_t length,
  262. unsigned char iv[16],
  263. const unsigned char *input,
  264. unsigned char *output );
  265. #endif /* MBEDTLS_CIPHER_MODE_CBC */
  266. #if defined(MBEDTLS_CIPHER_MODE_XTS)
  267. /**
  268. * \brief This function performs an AES-XTS encryption or decryption
  269. * operation for an entire XTS data unit.
  270. *
  271. * AES-XTS encrypts or decrypts blocks based on their location as
  272. * defined by a data unit number. The data unit number must be
  273. * provided by \p data_unit.
  274. *
  275. * NIST SP 800-38E limits the maximum size of a data unit to 2^20
  276. * AES blocks. If the data unit is larger than this, this function
  277. * returns #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH.
  278. *
  279. * \param ctx The AES XTS context to use for AES XTS operations.
  280. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  281. * #MBEDTLS_AES_DECRYPT.
  282. * \param length The length of a data unit in bytes. This can be any
  283. * length between 16 bytes and 2^24 bytes inclusive
  284. * (between 1 and 2^20 block cipher blocks).
  285. * \param data_unit The address of the data unit encoded as an array of 16
  286. * bytes in little-endian format. For disk encryption, this
  287. * is typically the index of the block device sector that
  288. * contains the data.
  289. * \param input The buffer holding the input data (which is an entire
  290. * data unit). This function reads \p length bytes from \p
  291. * input.
  292. * \param output The buffer holding the output data (which is an entire
  293. * data unit). This function writes \p length bytes to \p
  294. * output.
  295. *
  296. * \return \c 0 on success.
  297. * \return #MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH if \p length is
  298. * smaller than an AES block in size (16 bytes) or if \p
  299. * length is larger than 2^20 blocks (16 MiB).
  300. */
  301. int mbedtls_aes_crypt_xts( mbedtls_aes_xts_context *ctx,
  302. int mode,
  303. size_t length,
  304. const unsigned char data_unit[16],
  305. const unsigned char *input,
  306. unsigned char *output );
  307. #endif /* MBEDTLS_CIPHER_MODE_XTS */
  308. #if defined(MBEDTLS_CIPHER_MODE_CFB)
  309. /**
  310. * \brief This function performs an AES-CFB128 encryption or decryption
  311. * operation.
  312. *
  313. * It performs the operation defined in the \p mode
  314. * parameter (encrypt or decrypt), on the input data buffer
  315. * defined in the \p input parameter.
  316. *
  317. * For CFB, you must set up the context with mbedtls_aes_setkey_enc(),
  318. * regardless of whether you are performing an encryption or decryption
  319. * operation, that is, regardless of the \p mode parameter. This is
  320. * because CFB mode uses the same key schedule for encryption and
  321. * decryption.
  322. *
  323. * \note Upon exit, the content of the IV is updated so that you can
  324. * call the same function again on the next
  325. * block(s) of data and get the same result as if it was
  326. * encrypted in one call. This allows a "streaming" usage.
  327. * If you need to retain the contents of the
  328. * IV, you must either save it manually or use the cipher
  329. * module instead.
  330. *
  331. *
  332. * \param ctx The AES context to use for encryption or decryption.
  333. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  334. * #MBEDTLS_AES_DECRYPT.
  335. * \param length The length of the input data.
  336. * \param iv_off The offset in IV (updated after use).
  337. * \param iv The initialization vector (updated after use).
  338. * \param input The buffer holding the input data.
  339. * \param output The buffer holding the output data.
  340. *
  341. * \return \c 0 on success.
  342. */
  343. int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
  344. int mode,
  345. size_t length,
  346. size_t *iv_off,
  347. unsigned char iv[16],
  348. const unsigned char *input,
  349. unsigned char *output );
  350. /**
  351. * \brief This function performs an AES-CFB8 encryption or decryption
  352. * operation.
  353. *
  354. * It performs the operation defined in the \p mode
  355. * parameter (encrypt/decrypt), on the input data buffer defined
  356. * in the \p input parameter.
  357. *
  358. * Due to the nature of CFB, you must use the same key schedule for
  359. * both encryption and decryption operations. Therefore, you must
  360. * use the context initialized with mbedtls_aes_setkey_enc() for
  361. * both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
  362. *
  363. * \note Upon exit, the content of the IV is updated so that you can
  364. * call the same function again on the next
  365. * block(s) of data and get the same result as if it was
  366. * encrypted in one call. This allows a "streaming" usage.
  367. * If you need to retain the contents of the
  368. * IV, you should either save it manually or use the cipher
  369. * module instead.
  370. *
  371. *
  372. * \param ctx The AES context to use for encryption or decryption.
  373. * \param mode The AES operation: #MBEDTLS_AES_ENCRYPT or
  374. * #MBEDTLS_AES_DECRYPT
  375. * \param length The length of the input data.
  376. * \param iv The initialization vector (updated after use).
  377. * \param input The buffer holding the input data.
  378. * \param output The buffer holding the output data.
  379. *
  380. * \return \c 0 on success.
  381. */
  382. int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
  383. int mode,
  384. size_t length,
  385. unsigned char iv[16],
  386. const unsigned char *input,
  387. unsigned char *output );
  388. #endif /*MBEDTLS_CIPHER_MODE_CFB */
  389. #if defined(MBEDTLS_CIPHER_MODE_OFB)
  390. /**
  391. * \brief This function performs an AES-OFB (Output Feedback Mode)
  392. * encryption or decryption operation.
  393. *
  394. * For OFB, you must set up the context with
  395. * mbedtls_aes_setkey_enc(), regardless of whether you are
  396. * performing an encryption or decryption operation. This is
  397. * because OFB mode uses the same key schedule for encryption and
  398. * decryption.
  399. *
  400. * The OFB operation is identical for encryption or decryption,
  401. * therefore no operation mode needs to be specified.
  402. *
  403. * \note Upon exit, the content of iv, the Initialisation Vector, is
  404. * updated so that you can call the same function again on the next
  405. * block(s) of data and get the same result as if it was encrypted
  406. * in one call. This allows a "streaming" usage, by initialising
  407. * iv_off to 0 before the first call, and preserving its value
  408. * between calls.
  409. *
  410. * For non-streaming use, the iv should be initialised on each call
  411. * to a unique value, and iv_off set to 0 on each call.
  412. *
  413. * If you need to retain the contents of the initialisation vector,
  414. * you must either save it manually or use the cipher module
  415. * instead.
  416. *
  417. * \warning For the OFB mode, the initialisation vector must be unique
  418. * every encryption operation. Reuse of an initialisation vector
  419. * will compromise security.
  420. *
  421. * \param ctx The AES context to use for encryption or decryption.
  422. * \param length The length of the input data.
  423. * \param iv_off The offset in IV (updated after use).
  424. * \param iv The initialization vector (updated after use).
  425. * \param input The buffer holding the input data.
  426. * \param output The buffer holding the output data.
  427. *
  428. * \return \c 0 on success.
  429. */
  430. int mbedtls_aes_crypt_ofb( mbedtls_aes_context *ctx,
  431. size_t length,
  432. size_t *iv_off,
  433. unsigned char iv[16],
  434. const unsigned char *input,
  435. unsigned char *output );
  436. #endif /* MBEDTLS_CIPHER_MODE_OFB */
  437. #if defined(MBEDTLS_CIPHER_MODE_CTR)
  438. /**
  439. * \brief This function performs an AES-CTR encryption or decryption
  440. * operation.
  441. *
  442. * This function performs the operation defined in the \p mode
  443. * parameter (encrypt/decrypt), on the input data buffer
  444. * defined in the \p input parameter.
  445. *
  446. * Due to the nature of CTR, you must use the same key schedule
  447. * for both encryption and decryption operations. Therefore, you
  448. * must use the context initialized with mbedtls_aes_setkey_enc()
  449. * for both #MBEDTLS_AES_ENCRYPT and #MBEDTLS_AES_DECRYPT.
  450. *
  451. * \warning You must never reuse a nonce value with the same key. Doing so
  452. * would void the encryption for the two messages encrypted with
  453. * the same nonce and key.
  454. *
  455. * There are two common strategies for managing nonces with CTR:
  456. *
  457. * 1. You can handle everything as a single message processed over
  458. * successive calls to this function. In that case, you want to
  459. * set \p nonce_counter and \p nc_off to 0 for the first call, and
  460. * then preserve the values of \p nonce_counter, \p nc_off and \p
  461. * stream_block across calls to this function as they will be
  462. * updated by this function.
  463. *
  464. * With this strategy, you must not encrypt more than 2**128
  465. * blocks of data with the same key.
  466. *
  467. * 2. You can encrypt separate messages by dividing the \p
  468. * nonce_counter buffer in two areas: the first one used for a
  469. * per-message nonce, handled by yourself, and the second one
  470. * updated by this function internally.
  471. *
  472. * For example, you might reserve the first 12 bytes for the
  473. * per-message nonce, and the last 4 bytes for internal use. In that
  474. * case, before calling this function on a new message you need to
  475. * set the first 12 bytes of \p nonce_counter to your chosen nonce
  476. * value, the last 4 to 0, and \p nc_off to 0 (which will cause \p
  477. * stream_block to be ignored). That way, you can encrypt at most
  478. * 2**96 messages of up to 2**32 blocks each with the same key.
  479. *
  480. * The per-message nonce (or information sufficient to reconstruct
  481. * it) needs to be communicated with the ciphertext and must be unique.
  482. * The recommended way to ensure uniqueness is to use a message
  483. * counter. An alternative is to generate random nonces, but this
  484. * limits the number of messages that can be securely encrypted:
  485. * for example, with 96-bit random nonces, you should not encrypt
  486. * more than 2**32 messages with the same key.
  487. *
  488. * Note that for both stategies, sizes are measured in blocks and
  489. * that an AES block is 16 bytes.
  490. *
  491. * \warning Upon return, \p stream_block contains sensitive data. Its
  492. * content must not be written to insecure storage and should be
  493. * securely discarded as soon as it's no longer needed.
  494. *
  495. * \param ctx The AES context to use for encryption or decryption.
  496. * \param length The length of the input data.
  497. * \param nc_off The offset in the current \p stream_block, for
  498. * resuming within the current cipher stream. The
  499. * offset pointer should be 0 at the start of a stream.
  500. * \param nonce_counter The 128-bit nonce and counter.
  501. * \param stream_block The saved stream block for resuming. This is
  502. * overwritten by the function.
  503. * \param input The buffer holding the input data.
  504. * \param output The buffer holding the output data.
  505. *
  506. * \return \c 0 on success.
  507. */
  508. int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
  509. size_t length,
  510. size_t *nc_off,
  511. unsigned char nonce_counter[16],
  512. unsigned char stream_block[16],
  513. const unsigned char *input,
  514. unsigned char *output );
  515. #endif /* MBEDTLS_CIPHER_MODE_CTR */
  516. /**
  517. * \brief Internal AES block encryption function. This is only
  518. * exposed to allow overriding it using
  519. * \c MBEDTLS_AES_ENCRYPT_ALT.
  520. *
  521. * \param ctx The AES context to use for encryption.
  522. * \param input The plaintext block.
  523. * \param output The output (ciphertext) block.
  524. *
  525. * \return \c 0 on success.
  526. */
  527. int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
  528. const unsigned char input[16],
  529. unsigned char output[16] );
  530. /**
  531. * \brief Internal AES block decryption function. This is only
  532. * exposed to allow overriding it using see
  533. * \c MBEDTLS_AES_DECRYPT_ALT.
  534. *
  535. * \param ctx The AES context to use for decryption.
  536. * \param input The ciphertext block.
  537. * \param output The output (plaintext) block.
  538. *
  539. * \return \c 0 on success.
  540. */
  541. int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
  542. const unsigned char input[16],
  543. unsigned char output[16] );
  544. #if !defined(MBEDTLS_DEPRECATED_REMOVED)
  545. #if defined(MBEDTLS_DEPRECATED_WARNING)
  546. #define MBEDTLS_DEPRECATED __attribute__((deprecated))
  547. #else
  548. #define MBEDTLS_DEPRECATED
  549. #endif
  550. /**
  551. * \brief Deprecated internal AES block encryption function
  552. * without return value.
  553. *
  554. * \deprecated Superseded by mbedtls_aes_encrypt_ext() in 2.5.0.
  555. *
  556. * \param ctx The AES context to use for encryption.
  557. * \param input Plaintext block.
  558. * \param output Output (ciphertext) block.
  559. */
  560. MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
  561. const unsigned char input[16],
  562. unsigned char output[16] );
  563. /**
  564. * \brief Deprecated internal AES block decryption function
  565. * without return value.
  566. *
  567. * \deprecated Superseded by mbedtls_aes_decrypt_ext() in 2.5.0.
  568. *
  569. * \param ctx The AES context to use for decryption.
  570. * \param input Ciphertext block.
  571. * \param output Output (plaintext) block.
  572. */
  573. MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
  574. const unsigned char input[16],
  575. unsigned char output[16] );
  576. #undef MBEDTLS_DEPRECATED
  577. #endif /* !MBEDTLS_DEPRECATED_REMOVED */
  578. /**
  579. * \brief Checkup routine.
  580. *
  581. * \return \c 0 on success.
  582. * \return \c 1 on failure.
  583. */
  584. int mbedtls_aes_self_test( int verbose );
  585. #ifdef __cplusplus
  586. }
  587. #endif
  588. #endif /* aes.h */