Mbed TLS v2.28.5
aes.h
Go to the documentation of this file.
1 
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 #include "mbedtls/platform_util.h"
49 
50 #include <stddef.h>
51 #include <stdint.h>
52 
53 /* padlock.c and aesni.c rely on these values! */
54 #define MBEDTLS_AES_ENCRYPT 1
55 #define MBEDTLS_AES_DECRYPT 0
57 /* Error codes in range 0x0020-0x0022 */
58 
59 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
60 
61 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
62 
63 /* Error codes in range 0x0021-0x0025 */
65 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
66 
67 /* MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE is deprecated and should not be used. */
69 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
70 
71 /* MBEDTLS_ERR_AES_HW_ACCEL_FAILED is deprecated and should not be used. */
73 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
74 
75 #if (defined(__ARMCC_VERSION) || defined(_MSC_VER)) && \
76  !defined(inline) && !defined(__cplusplus)
77 #define inline __inline
78 #endif
79 
80 #ifdef __cplusplus
81 extern "C" {
82 #endif
83 
84 #if !defined(MBEDTLS_AES_ALT)
85 // Regular implementation
86 //
87 
91 typedef struct mbedtls_aes_context {
92  int nr;
93  uint32_t *rk;
94  uint32_t buf[68];
102 }
104 
105 #if defined(MBEDTLS_CIPHER_MODE_XTS)
106 
109 typedef struct mbedtls_aes_xts_context {
115 #endif /* MBEDTLS_CIPHER_MODE_XTS */
116 
117 #else /* MBEDTLS_AES_ALT */
118 #include "aes_alt.h"
119 #endif /* MBEDTLS_AES_ALT */
120 
130 
139 
140 #if defined(MBEDTLS_CIPHER_MODE_XTS)
141 
150 
159 #endif /* MBEDTLS_CIPHER_MODE_XTS */
160 
177 int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
178  unsigned int keybits);
179 
196 int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
197  unsigned int keybits);
198 
199 #if defined(MBEDTLS_CIPHER_MODE_XTS)
200 
218  const unsigned char *key,
219  unsigned int keybits);
220 
239  const unsigned char *key,
240  unsigned int keybits);
241 #endif /* MBEDTLS_CIPHER_MODE_XTS */
242 
268  int mode,
269  const unsigned char input[16],
270  unsigned char output[16]);
271 
272 #if defined(MBEDTLS_CIPHER_MODE_CBC)
273 
316  int mode,
317  size_t length,
318  unsigned char iv[16],
319  const unsigned char *input,
320  unsigned char *output);
321 #endif /* MBEDTLS_CIPHER_MODE_CBC */
322 
323 #if defined(MBEDTLS_CIPHER_MODE_XTS)
324 
361  int mode,
362  size_t length,
363  const unsigned char data_unit[16],
364  const unsigned char *input,
365  unsigned char *output);
366 #endif /* MBEDTLS_CIPHER_MODE_XTS */
367 
368 #if defined(MBEDTLS_CIPHER_MODE_CFB)
369 
410  int mode,
411  size_t length,
412  size_t *iv_off,
413  unsigned char iv[16],
414  const unsigned char *input,
415  unsigned char *output);
416 
455  int mode,
456  size_t length,
457  unsigned char iv[16],
458  const unsigned char *input,
459  unsigned char *output);
460 #endif /*MBEDTLS_CIPHER_MODE_CFB */
461 
462 #if defined(MBEDTLS_CIPHER_MODE_OFB)
463 
510  size_t length,
511  size_t *iv_off,
512  unsigned char iv[16],
513  const unsigned char *input,
514  unsigned char *output);
515 
516 #endif /* MBEDTLS_CIPHER_MODE_OFB */
517 
518 #if defined(MBEDTLS_CIPHER_MODE_CTR)
519 
593  size_t length,
594  size_t *nc_off,
595  unsigned char nonce_counter[16],
596  unsigned char stream_block[16],
597  const unsigned char *input,
598  unsigned char *output);
599 #endif /* MBEDTLS_CIPHER_MODE_CTR */
600 
614  const unsigned char input[16],
615  unsigned char output[16]);
616 
630  const unsigned char input[16],
631  unsigned char output[16]);
632 
633 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
634 #if defined(MBEDTLS_DEPRECATED_WARNING)
635 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
636 #else
637 #define MBEDTLS_DEPRECATED
638 #endif
639 
650  const unsigned char input[16],
651  unsigned char output[16]);
652 
664  const unsigned char input[16],
665  unsigned char output[16]);
666 
667 #undef MBEDTLS_DEPRECATED
668 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
669 
670 
671 #if defined(MBEDTLS_SELF_TEST)
672 
679 int mbedtls_aes_self_test(int verbose);
680 
681 #endif /* MBEDTLS_SELF_TEST */
682 
683 #ifdef __cplusplus
684 }
685 #endif
686 
687 #endif /* aes.h */
uint32_t buf[68]
Definition: aes.h:94
mbedtls_aes_context crypt
Definition: aes.h:110
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:637
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:109
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:112
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:93
#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:91
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.