mbed TLS v3.3.0
Loading...
Searching...
No Matches
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
76{
78 size_t MBEDTLS_PRIVATE(rk_offset);
80 uint32_t MBEDTLS_PRIVATE(buf)[68];
88}
90
91#if defined(MBEDTLS_CIPHER_MODE_XTS)
96{
102#endif /* MBEDTLS_CIPHER_MODE_XTS */
103
104#else /* MBEDTLS_AES_ALT */
105#include "aes_alt.h"
106#endif /* MBEDTLS_AES_ALT */
107
117
126
127#if defined(MBEDTLS_CIPHER_MODE_XTS)
137
146#endif /* MBEDTLS_CIPHER_MODE_XTS */
147
164int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
165 unsigned int keybits );
166
183int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
184 unsigned int keybits );
185
186#if defined(MBEDTLS_CIPHER_MODE_XTS)
205 const unsigned char *key,
206 unsigned int keybits );
207
226 const unsigned char *key,
227 unsigned int keybits );
228#endif /* MBEDTLS_CIPHER_MODE_XTS */
229
255 int mode,
256 const unsigned char input[16],
257 unsigned char output[16] );
258
259#if defined(MBEDTLS_CIPHER_MODE_CBC)
303 int mode,
304 size_t length,
305 unsigned char iv[16],
306 const unsigned char *input,
307 unsigned char *output );
308#endif /* MBEDTLS_CIPHER_MODE_CBC */
309
310#if defined(MBEDTLS_CIPHER_MODE_XTS)
348 int mode,
349 size_t length,
350 const unsigned char data_unit[16],
351 const unsigned char *input,
352 unsigned char *output );
353#endif /* MBEDTLS_CIPHER_MODE_XTS */
354
355#if defined(MBEDTLS_CIPHER_MODE_CFB)
397 int mode,
398 size_t length,
399 size_t *iv_off,
400 unsigned char iv[16],
401 const unsigned char *input,
402 unsigned char *output );
403
442 int mode,
443 size_t length,
444 unsigned char iv[16],
445 const unsigned char *input,
446 unsigned char *output );
447#endif /*MBEDTLS_CIPHER_MODE_CFB */
448
449#if defined(MBEDTLS_CIPHER_MODE_OFB)
497 size_t length,
498 size_t *iv_off,
499 unsigned char iv[16],
500 const unsigned char *input,
501 unsigned char *output );
502
503#endif /* MBEDTLS_CIPHER_MODE_OFB */
504
505#if defined(MBEDTLS_CIPHER_MODE_CTR)
580 size_t length,
581 size_t *nc_off,
582 unsigned char nonce_counter[16],
583 unsigned char stream_block[16],
584 const unsigned char *input,
585 unsigned char *output );
586#endif /* MBEDTLS_CIPHER_MODE_CTR */
587
601 const unsigned char input[16],
602 unsigned char output[16] );
603
617 const unsigned char input[16],
618 unsigned char output[16] );
619
620#if defined(MBEDTLS_SELF_TEST)
628int mbedtls_aes_self_test( int verbose );
629
630#endif /* MBEDTLS_SELF_TEST */
631
632#ifdef __cplusplus
633}
634#endif
635
636#endif /* aes.h */
MBEDTLS_CHECK_RETURN_CRITICAL 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.
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.
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_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.
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_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...
void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
This function releases and clears the specified AES XTS context.
void mbedtls_aes_init(mbedtls_aes_context *ctx)
This function initializes the specified AES context.
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_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_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_free(mbedtls_aes_context *ctx)
This function releases and clears the specified AES context.
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.
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.
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.
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.
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:76
The AES XTS context-type definition.
Definition: aes.h:96