Mbed TLS v3.5.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
43
44#include "mbedtls/build_info.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 */
56#define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
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
65extern "C" {
66#endif
67
68#if !defined(MBEDTLS_AES_ALT)
69// Regular implementation
70//
71
75typedef struct mbedtls_aes_context {
77 size_t MBEDTLS_PRIVATE(rk_offset);
79#if defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH) && !defined(MBEDTLS_PADLOCK_C)
80 uint32_t MBEDTLS_PRIVATE(buf)[44];
82#else
83 uint32_t MBEDTLS_PRIVATE(buf)[68];
91#endif /* MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH && !MBEDTLS_PADLOCK_C */
92}
94
95#if defined(MBEDTLS_CIPHER_MODE_XTS)
105#endif /* MBEDTLS_CIPHER_MODE_XTS */
106
107#else /* MBEDTLS_AES_ALT */
108#include "aes_alt.h"
109#endif /* MBEDTLS_AES_ALT */
110
120
129
130#if defined(MBEDTLS_CIPHER_MODE_XTS)
140
149#endif /* MBEDTLS_CIPHER_MODE_XTS */
150
167int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
168 unsigned int keybits);
169
186int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
187 unsigned int keybits);
188
189#if defined(MBEDTLS_CIPHER_MODE_XTS)
208 const unsigned char *key,
209 unsigned int keybits);
210
229 const unsigned char *key,
230 unsigned int keybits);
231#endif /* MBEDTLS_CIPHER_MODE_XTS */
232
258 int mode,
259 const unsigned char input[16],
260 unsigned char output[16]);
261
262#if defined(MBEDTLS_CIPHER_MODE_CBC)
306 int mode,
307 size_t length,
308 unsigned char iv[16],
309 const unsigned char *input,
310 unsigned char *output);
311#endif /* MBEDTLS_CIPHER_MODE_CBC */
312
313#if defined(MBEDTLS_CIPHER_MODE_XTS)
351 int mode,
352 size_t length,
353 const unsigned char data_unit[16],
354 const unsigned char *input,
355 unsigned char *output);
356#endif /* MBEDTLS_CIPHER_MODE_XTS */
357
358#if defined(MBEDTLS_CIPHER_MODE_CFB)
400 int mode,
401 size_t length,
402 size_t *iv_off,
403 unsigned char iv[16],
404 const unsigned char *input,
405 unsigned char *output);
406
445 int mode,
446 size_t length,
447 unsigned char iv[16],
448 const unsigned char *input,
449 unsigned char *output);
450#endif /*MBEDTLS_CIPHER_MODE_CFB */
451
452#if defined(MBEDTLS_CIPHER_MODE_OFB)
500 size_t length,
501 size_t *iv_off,
502 unsigned char iv[16],
503 const unsigned char *input,
504 unsigned char *output);
505
506#endif /* MBEDTLS_CIPHER_MODE_OFB */
507
508#if defined(MBEDTLS_CIPHER_MODE_CTR)
583 size_t length,
584 size_t *nc_off,
585 unsigned char nonce_counter[16],
586 unsigned char stream_block[16],
587 const unsigned char *input,
588 unsigned char *output);
589#endif /* MBEDTLS_CIPHER_MODE_CTR */
590
604 const unsigned char input[16],
605 unsigned char output[16]);
606
620 const unsigned char input[16],
621 unsigned char output[16]);
622
623#if defined(MBEDTLS_SELF_TEST)
631int mbedtls_aes_self_test(int verbose);
632
633#endif /* MBEDTLS_SELF_TEST */
634
635#ifdef __cplusplus
636}
637#endif
638
639#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
#define MBEDTLS_CHECK_RETURN_CRITICAL
Definition: platform_util.h:93
Macro wrapper for struct's members.
#define MBEDTLS_PRIVATE(member)
The AES context-type definition.
Definition: aes.h:75
The AES XTS context-type definition.
Definition: aes.h:99