mbed TLS v3.4.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
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 #include "mbedtls/private_access.h"
43 
44 #include "mbedtls/build_info.h"
45 #include "mbedtls/platform_util.h"
46 
47 #include <stddef.h>
48 #include <stdint.h>
49 
50 /* padlock.c and aesni.c rely on these values! */
51 #define MBEDTLS_AES_ENCRYPT 1
52 #define MBEDTLS_AES_DECRYPT 0
54 /* Error codes in range 0x0020-0x0022 */
55 
56 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
57 
58 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
59 
60 /* Error codes in range 0x0021-0x0025 */
62 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 #if !defined(MBEDTLS_AES_ALT)
69 // Regular implementation
70 //
71 
75 typedef struct mbedtls_aes_context {
76  int MBEDTLS_PRIVATE(nr);
77  size_t MBEDTLS_PRIVATE(rk_offset);
79  uint32_t MBEDTLS_PRIVATE(buf)[68];
87 }
89 
90 #if defined(MBEDTLS_CIPHER_MODE_XTS)
91 
94 typedef struct mbedtls_aes_xts_context {
100 #endif /* MBEDTLS_CIPHER_MODE_XTS */
101 
102 #else /* MBEDTLS_AES_ALT */
103 #include "aes_alt.h"
104 #endif /* MBEDTLS_AES_ALT */
105 
115 
124 
125 #if defined(MBEDTLS_CIPHER_MODE_XTS)
126 
135 
144 #endif /* MBEDTLS_CIPHER_MODE_XTS */
145 
162 int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
163  unsigned int keybits);
164 
181 int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
182  unsigned int keybits);
183 
184 #if defined(MBEDTLS_CIPHER_MODE_XTS)
185 
203  const unsigned char *key,
204  unsigned int keybits);
205 
224  const unsigned char *key,
225  unsigned int keybits);
226 #endif /* MBEDTLS_CIPHER_MODE_XTS */
227 
253  int mode,
254  const unsigned char input[16],
255  unsigned char output[16]);
256 
257 #if defined(MBEDTLS_CIPHER_MODE_CBC)
258 
301  int mode,
302  size_t length,
303  unsigned char iv[16],
304  const unsigned char *input,
305  unsigned char *output);
306 #endif /* MBEDTLS_CIPHER_MODE_CBC */
307 
308 #if defined(MBEDTLS_CIPHER_MODE_XTS)
309 
346  int mode,
347  size_t length,
348  const unsigned char data_unit[16],
349  const unsigned char *input,
350  unsigned char *output);
351 #endif /* MBEDTLS_CIPHER_MODE_XTS */
352 
353 #if defined(MBEDTLS_CIPHER_MODE_CFB)
354 
395  int mode,
396  size_t length,
397  size_t *iv_off,
398  unsigned char iv[16],
399  const unsigned char *input,
400  unsigned char *output);
401 
440  int mode,
441  size_t length,
442  unsigned char iv[16],
443  const unsigned char *input,
444  unsigned char *output);
445 #endif /*MBEDTLS_CIPHER_MODE_CFB */
446 
447 #if defined(MBEDTLS_CIPHER_MODE_OFB)
448 
495  size_t length,
496  size_t *iv_off,
497  unsigned char iv[16],
498  const unsigned char *input,
499  unsigned char *output);
500 
501 #endif /* MBEDTLS_CIPHER_MODE_OFB */
502 
503 #if defined(MBEDTLS_CIPHER_MODE_CTR)
504 
578  size_t length,
579  size_t *nc_off,
580  unsigned char nonce_counter[16],
581  unsigned char stream_block[16],
582  const unsigned char *input,
583  unsigned char *output);
584 #endif /* MBEDTLS_CIPHER_MODE_CTR */
585 
599  const unsigned char input[16],
600  unsigned char output[16]);
601 
615  const unsigned char input[16],
616  unsigned char output[16]);
617 
618 #if defined(MBEDTLS_SELF_TEST)
619 
626 int mbedtls_aes_self_test(int verbose);
627 
628 #endif /* MBEDTLS_SELF_TEST */
629 
630 #ifdef __cplusplus
631 }
632 #endif
633 
634 #endif /* aes.h */
MBEDTLS_CHECK_RETURN_TYPICAL 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.
MBEDTLS_CHECK_RETURN_TYPICAL 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...
#define MBEDTLS_CHECK_RETURN_TYPICAL
MBEDTLS_CHECK_RETURN_TYPICAL 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.
#define MBEDTLS_PRIVATE(member)
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
Common and shared functions used by multiple modules in the Mbed TLS library.
MBEDTLS_CHECK_RETURN_TYPICAL 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...
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:94
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the decryption key.
MBEDTLS_CHECK_RETURN_TYPICAL 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. ...
MBEDTLS_CHECK_RETURN_CRITICAL int mbedtls_aes_self_test(int verbose)
Checkup routine.
Macro wrapper for struct's members.
MBEDTLS_CHECK_RETURN_TYPICAL 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_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
Build-time configuration info.
MBEDTLS_CHECK_RETURN_TYPICAL 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.
MBEDTLS_CHECK_RETURN_TYPICAL int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key, unsigned int keybits)
This function sets the encryption key.
#define MBEDTLS_CHECK_RETURN_CRITICAL
Definition: platform_util.h:93
MBEDTLS_CHECK_RETURN_TYPICAL 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.
MBEDTLS_CHECK_RETURN_TYPICAL 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_CHECK_RETURN_TYPICAL 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. ...
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:75
MBEDTLS_CHECK_RETURN_TYPICAL 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...
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.