mbed TLS v2.9.0
aes.h
Go to the documentation of this file.
1 
18 /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
19  * SPDX-License-Identifier: Apache-2.0
20  *
21  * Licensed under the Apache License, Version 2.0 (the "License"); you may
22  * not use this file except in compliance with the License.
23  * You may obtain a copy of the License at
24  *
25  * http://www.apache.org/licenses/LICENSE-2.0
26  *
27  * Unless required by applicable law or agreed to in writing, software
28  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
29  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30  * See the License for the specific language governing permissions and
31  * limitations under the License.
32  *
33  * This file is part of Mbed TLS (https://tls.mbed.org)
34  */
35 
36 #ifndef MBEDTLS_AES_H
37 #define MBEDTLS_AES_H
38 
39 #if !defined(MBEDTLS_CONFIG_FILE)
40 #include "config.h"
41 #else
42 #include MBEDTLS_CONFIG_FILE
43 #endif
44 
45 #include <stddef.h>
46 #include <stdint.h>
47 
48 /* padlock.c and aesni.c rely on these values! */
49 #define MBEDTLS_AES_ENCRYPT 1
50 #define MBEDTLS_AES_DECRYPT 0
52 /* Error codes in range 0x0020-0x0022 */
53 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
54 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
56 /* Error codes in range 0x0023-0x0025 */
57 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
58 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
60 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
61  !defined(inline) && !defined(__cplusplus)
62 #define inline __inline
63 #endif
64 
65 #ifdef __cplusplus
66 extern "C" {
67 #endif
68 
69 #if !defined(MBEDTLS_AES_ALT)
70 // Regular implementation
71 //
72 
76 typedef struct
77 {
78  int nr;
79  uint32_t *rk;
80  uint32_t buf[68];
88 }
90 
91 #else /* MBEDTLS_AES_ALT */
92 #include "aes_alt.h"
93 #endif /* MBEDTLS_AES_ALT */
94 
104 
111 
125 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
126  unsigned int keybits );
127 
141 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
142  unsigned int keybits );
143 
165  int mode,
166  const unsigned char input[16],
167  unsigned char output[16] );
168 
169 #if defined(MBEDTLS_CIPHER_MODE_CBC)
170 
208  int mode,
209  size_t length,
210  unsigned char iv[16],
211  const unsigned char *input,
212  unsigned char *output );
213 #endif /* MBEDTLS_CIPHER_MODE_CBC */
214 
215 #if defined(MBEDTLS_CIPHER_MODE_CFB)
216 
251  int mode,
252  size_t length,
253  size_t *iv_off,
254  unsigned char iv[16],
255  const unsigned char *input,
256  unsigned char *output );
257 
291  int mode,
292  size_t length,
293  unsigned char iv[16],
294  const unsigned char *input,
295  unsigned char *output );
296 #endif /*MBEDTLS_CIPHER_MODE_CFB */
297 
298 #if defined(MBEDTLS_CIPHER_MODE_CTR)
299 
328  size_t length,
329  size_t *nc_off,
330  unsigned char nonce_counter[16],
331  unsigned char stream_block[16],
332  const unsigned char *input,
333  unsigned char *output );
334 #endif /* MBEDTLS_CIPHER_MODE_CTR */
335 
348  const unsigned char input[16],
349  unsigned char output[16] );
350 
363  const unsigned char input[16],
364  unsigned char output[16] );
365 
366 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
367 #if defined(MBEDTLS_DEPRECATED_WARNING)
368 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
369 #else
370 #define MBEDTLS_DEPRECATED
371 #endif
372 
383  const unsigned char input[16],
384  unsigned char output[16] );
385 
397  const unsigned char input[16],
398  unsigned char output[16] );
399 
400 #undef MBEDTLS_DEPRECATED
401 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
402 
409 int mbedtls_aes_self_test( int verbose );
410 
411 #ifdef __cplusplus
412 }
413 #endif
414 
415 #endif /* aes.h */
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.
#define MBEDTLS_DEPRECATED
Definition: aes.h:370
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_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.
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:79
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:76
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.