Mbed TLS v3.6.0
aes.h
Go to the documentation of this file.
1 
23 /*
24  * Copyright The Mbed TLS Contributors
25  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
26  */
27 
28 #ifndef MBEDTLS_AES_H
29 #define MBEDTLS_AES_H
30 #include "mbedtls/private_access.h"
31 
32 #include "mbedtls/build_info.h"
33 #include "mbedtls/platform_util.h"
34 
35 #include <stddef.h>
36 #include <stdint.h>
37 
38 /* padlock.c and aesni.c rely on these values! */
39 #define MBEDTLS_AES_ENCRYPT 1
40 #define MBEDTLS_AES_DECRYPT 0
42 /* Error codes in range 0x0020-0x0022 */
44 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
46 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
47 
48 /* Error codes in range 0x0021-0x0025 */
50 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #if !defined(MBEDTLS_AES_ALT)
57 // Regular implementation
58 //
59 
63 typedef struct mbedtls_aes_context {
64  int MBEDTLS_PRIVATE(nr);
65  size_t MBEDTLS_PRIVATE(rk_offset);
67 #if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
68  uint32_t MBEDTLS_PRIVATE(buf)[44];
70 #else
71  uint32_t MBEDTLS_PRIVATE(buf)[68];
79 #endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH && !MBEDTLS_PADLOCK_C */
80 }
82 
83 #if defined(MBEDTLS_CIPHER_MODE_XTS)
87 typedef struct mbedtls_aes_xts_context {
93 #endif /* MBEDTLS_CIPHER_MODE_XTS */
94 
95 #else /* MBEDTLS_AES_ALT */
96 #include "aes_alt.h"
97 #endif /* MBEDTLS_AES_ALT */
98 
108 
117 
118 #if defined(MBEDTLS_CIPHER_MODE_XTS)
128 
137 #endif /* MBEDTLS_CIPHER_MODE_XTS */
138 
155 int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
156  unsigned int keybits);
157 
158 #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
175 int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
176  unsigned int keybits);
177 #endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
178 
179 #if defined(MBEDTLS_CIPHER_MODE_XTS)
198  const unsigned char *key,
199  unsigned int keybits);
200 
219  const unsigned char *key,
220  unsigned int keybits);
221 #endif /* MBEDTLS_CIPHER_MODE_XTS */
222 
248  int mode,
249  const unsigned char input[16],
250  unsigned char output[16]);
251 
252 #if defined(MBEDTLS_CIPHER_MODE_CBC)
296  int mode,
297  size_t length,
298  unsigned char iv[16],
299  const unsigned char *input,
300  unsigned char *output);
301 #endif /* MBEDTLS_CIPHER_MODE_CBC */
302 
303 #if defined(MBEDTLS_CIPHER_MODE_XTS)
341  int mode,
342  size_t length,
343  const unsigned char data_unit[16],
344  const unsigned char *input,
345  unsigned char *output);
346 #endif /* MBEDTLS_CIPHER_MODE_XTS */
347 
348 #if defined(MBEDTLS_CIPHER_MODE_CFB)
390  int mode,
391  size_t length,
392  size_t *iv_off,
393  unsigned char iv[16],
394  const unsigned char *input,
395  unsigned char *output);
396 
435  int mode,
436  size_t length,
437  unsigned char iv[16],
438  const unsigned char *input,
439  unsigned char *output);
440 #endif /*MBEDTLS_CIPHER_MODE_CFB */
441 
442 #if defined(MBEDTLS_CIPHER_MODE_OFB)
490  size_t length,
491  size_t *iv_off,
492  unsigned char iv[16],
493  const unsigned char *input,
494  unsigned char *output);
495 
496 #endif /* MBEDTLS_CIPHER_MODE_OFB */
497 
498 #if defined(MBEDTLS_CIPHER_MODE_CTR)
573  size_t length,
574  size_t *nc_off,
575  unsigned char nonce_counter[16],
576  unsigned char stream_block[16],
577  const unsigned char *input,
578  unsigned char *output);
579 #endif /* MBEDTLS_CIPHER_MODE_CTR */
580 
594  const unsigned char input[16],
595  unsigned char output[16]);
596 
597 #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
611  const unsigned char input[16],
612  unsigned char output[16]);
613 #endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
614 
615 #if defined(MBEDTLS_SELF_TEST)
623 int mbedtls_aes_self_test(int verbose);
624 
625 #endif /* MBEDTLS_SELF_TEST */
626 
627 #ifdef __cplusplus
628 }
629 #endif
630 
631 #endif /* aes.h */
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_self_test(int verbose)
Checkup routine.
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
This function initializes the specified AES XTS context.
int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-OFB (Output Feedback Mode) encryption or decryption operation.
int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CBC encryption or decryption operation on full blocks.
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.
int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits)
This function prepares an XTS context for decryption and sets the decryption key.
int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx, int mode, size_t length, const unsigned char data_unit[16], const unsigned char *input, unsigned char *output)
This function performs an AES-XTS encryption or decryption operation for an entire XTS data unit.
int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx, const unsigned char input[16], unsigned char output[16])
Internal AES block encryption function. This is only exposed to allow overriding it using MBEDTLS_AES...
struct mbedtls_aes_xts_context mbedtls_aes_xts_context
The AES XTS context-type definition.
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CFB128 encryption or decryption operation.
int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
This function performs an AES-CFB8 encryption or decryption operation.
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
struct mbedtls_aes_context mbedtls_aes_context
The AES context-type definition.
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. This is only exposed to allow overriding it using see MBEDTLS...
int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx, const unsigned char *key, unsigned int keybits)
This function prepares an XTS context for encryption and sets the encryption key.
Build-time configuration info.
Common and shared functions used by multiple modules in the Mbed TLS library.
#define MBEDTLS_CHECK_RETURN_TYPICAL
Definition: platform_util.h:99
#define MBEDTLS_CHECK_RETURN_CRITICAL
Definition: platform_util.h:77
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
The AES context-type definition.
Definition: aes.h:63
The AES XTS context-type definition.
Definition: aes.h:87