Mbed TLS v2.28.7
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 
31 #if !defined(MBEDTLS_CONFIG_FILE)
32 #include "mbedtls/config.h"
33 #else
34 #include MBEDTLS_CONFIG_FILE
35 #endif
36 #include "mbedtls/platform_util.h"
37 
38 #include <stddef.h>
39 #include <stdint.h>
40 
41 /* padlock.c and aesni.c rely on these values! */
42 #define MBEDTLS_AES_ENCRYPT 1
43 #define MBEDTLS_AES_DECRYPT 0
45 /* Error codes in range 0x0020-0x0022 */
46 
47 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
48 
49 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
50 
51 /* Error codes in range 0x0021-0x0025 */
53 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
54 
55 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
57 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
58 
59 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
61 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
62 
63 #if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
64  !defined(inline) && !defined(__cplusplus)
65 #define inline __inline
66 #endif
67 
68 #ifdef __cplusplus
69 extern "C" {
70 #endif
71 
72 #if !defined(MBEDTLS_AES_ALT)
73 // Regular implementation
74 //
75 
79 typedef struct mbedtls_aes_context {
80  int nr;
81  uint32_t *rk;
82  uint32_t buf[68];
90 }
92 
93 #if defined(MBEDTLS_CIPHER_MODE_XTS)
94 
97 typedef struct mbedtls_aes_xts_context {
103 #endif /* MBEDTLS_CIPHER_MODE_XTS */
104 
105 #else /* MBEDTLS_AES_ALT */
106 #include "aes_alt.h"
107 #endif /* MBEDTLS_AES_ALT */
108 
118 
127 
128 #if defined(MBEDTLS_CIPHER_MODE_XTS)
129 
138 
147 #endif /* MBEDTLS_CIPHER_MODE_XTS */
148 
165 int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
166  unsigned int keybits);
167 
184 int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
185  unsigned int keybits);
186 
187 #if defined(MBEDTLS_CIPHER_MODE_XTS)
188 
206  const unsigned char *key,
207  unsigned int keybits);
208 
227  const unsigned char *key,
228  unsigned int keybits);
229 #endif /* MBEDTLS_CIPHER_MODE_XTS */
230 
256  int mode,
257  const unsigned char input[16],
258  unsigned char output[16]);
259 
260 #if defined(MBEDTLS_CIPHER_MODE_CBC)
261 
304  int mode,
305  size_t length,
306  unsigned char iv[16],
307  const unsigned char *input,
308  unsigned char *output);
309 #endif /* MBEDTLS_CIPHER_MODE_CBC */
310 
311 #if defined(MBEDTLS_CIPHER_MODE_XTS)
312 
349  int mode,
350  size_t length,
351  const unsigned char data_unit[16],
352  const unsigned char *input,
353  unsigned char *output);
354 #endif /* MBEDTLS_CIPHER_MODE_XTS */
355 
356 #if defined(MBEDTLS_CIPHER_MODE_CFB)
357 
398  int mode,
399  size_t length,
400  size_t *iv_off,
401  unsigned char iv[16],
402  const unsigned char *input,
403  unsigned char *output);
404 
443  int mode,
444  size_t length,
445  unsigned char iv[16],
446  const unsigned char *input,
447  unsigned char *output);
448 #endif /*MBEDTLS_CIPHER_MODE_CFB */
449 
450 #if defined(MBEDTLS_CIPHER_MODE_OFB)
451 
498  size_t length,
499  size_t *iv_off,
500  unsigned char iv[16],
501  const unsigned char *input,
502  unsigned char *output);
503 
504 #endif /* MBEDTLS_CIPHER_MODE_OFB */
505 
506 #if defined(MBEDTLS_CIPHER_MODE_CTR)
507 
581  size_t length,
582  size_t *nc_off,
583  unsigned char nonce_counter[16],
584  unsigned char stream_block[16],
585  const unsigned char *input,
586  unsigned char *output);
587 #endif /* MBEDTLS_CIPHER_MODE_CTR */
588 
602  const unsigned char input[16],
603  unsigned char output[16]);
604 
618  const unsigned char input[16],
619  unsigned char output[16]);
620 
621 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
622 #if defined(MBEDTLS_DEPRECATED_WARNING)
623 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
624 #else
625 #define MBEDTLS_DEPRECATED
626 #endif
627 
638  const unsigned char input[16],
639  unsigned char output[16]);
640 
652  const unsigned char input[16],
653  unsigned char output[16]);
654 
655 #undef MBEDTLS_DEPRECATED
656 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
657 
658 
659 #if defined(MBEDTLS_SELF_TEST)
660 
667 int mbedtls_aes_self_test(int verbose);
668 
669 #endif /* MBEDTLS_SELF_TEST */
670 
671 #ifdef __cplusplus
672 }
673 #endif
674 
675 #endif /* aes.h */
uint32_t buf[68]
Definition: aes.h:82
mbedtls_aes_context crypt
Definition: aes.h:98
MBEDTLS_DEPRECATED 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_aes_self_test(int verbose)
Checkup routine.
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_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. ...
#define MBEDTLS_CHECK_RETURN_TYPICAL
#define MBEDTLS_DEPRECATED
Definition: aes.h:625
Configuration options (set of defines)
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
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...
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...
Common and shared functions used by multiple modules in the Mbed TLS library.
void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
This function initializes the specified AES XTS context.
The AES XTS context-type definition.
Definition: aes.h:97
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_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_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_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the decryption key.
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
mbedtls_aes_context tweak
Definition: aes.h:100
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.
uint32_t * rk
Definition: aes.h:81
#define MBEDTLS_CHECK_RETURN_CRITICAL
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_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.
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.
The AES context-type definition.
Definition: aes.h:79
struct mbedtls_aes_xts_context mbedtls_aes_xts_context
The AES XTS context-type definition.
struct mbedtls_aes_context mbedtls_aes_context
The AES context-type definition.
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...
MBEDTLS_DEPRECATED 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.