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