mbed TLS v2.13.0
aes.h
Go to the documentation of this file.
1 
23 /* Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved.
24  * SPDX-License-Identifier: Apache-2.0
25  *
26  * Licensed under the Apache License, Version 2.0 (the "License"); you may
27  * not use this file except in compliance with the License.
28  * You may obtain a copy of the License at
29  *
30  * http://www.apache.org/licenses/LICENSE-2.0
31  *
32  * Unless required by applicable law or agreed to in writing, software
33  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
34  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35  * See the License for the specific language governing permissions and
36  * limitations under the License.
37  *
38  * This file is part of Mbed TLS (https://tls.mbed.org)
39  */
40 
41 #ifndef MBEDTLS_AES_H
42 #define MBEDTLS_AES_H
43 
44 #if !defined(MBEDTLS_CONFIG_FILE)
45 #include "config.h"
46 #else
47 #include MBEDTLS_CONFIG_FILE
48 #endif
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 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
59 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
61 /* Error codes in range 0x0021-0x0025 */
62 #define MBEDTLS_ERR_AES_BAD_INPUT_DATA -0x0021
63 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
64 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
66 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
67  !defined(inline) && !defined(__cplusplus)
68 #define inline __inline
69 #endif
70 
71 #ifdef __cplusplus
72 extern "C" {
73 #endif
74 
75 #if !defined(MBEDTLS_AES_ALT)
76 // Regular implementation
77 //
78 
82 typedef struct mbedtls_aes_context
83 {
84  int nr;
85  uint32_t *rk;
86  uint32_t buf[68];
94 }
96 
97 #if defined(MBEDTLS_CIPHER_MODE_XTS)
98 
102 {
108 #endif /* MBEDTLS_CIPHER_MODE_XTS */
109 
110 #else /* MBEDTLS_AES_ALT */
111 #include "aes_alt.h"
112 #endif /* MBEDTLS_AES_ALT */
113 
123 
130 
131 #if defined(MBEDTLS_CIPHER_MODE_XTS)
132 
141 
148 #endif /* MBEDTLS_CIPHER_MODE_XTS */
149 
163 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
164  unsigned int keybits );
165 
179 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
180  unsigned int keybits );
181 
182 #if defined(MBEDTLS_CIPHER_MODE_XTS)
183 
198  const unsigned char *key,
199  unsigned int keybits );
200 
216  const unsigned char *key,
217  unsigned int keybits );
218 #endif /* MBEDTLS_CIPHER_MODE_XTS */
219 
241  int mode,
242  const unsigned char input[16],
243  unsigned char output[16] );
244 
245 #if defined(MBEDTLS_CIPHER_MODE_CBC)
246 
284  int mode,
285  size_t length,
286  unsigned char iv[16],
287  const unsigned char *input,
288  unsigned char *output );
289 #endif /* MBEDTLS_CIPHER_MODE_CBC */
290 
291 #if defined(MBEDTLS_CIPHER_MODE_XTS)
292 
327  int mode,
328  size_t length,
329  const unsigned char data_unit[16],
330  const unsigned char *input,
331  unsigned char *output );
332 #endif /* MBEDTLS_CIPHER_MODE_XTS */
333 
334 #if defined(MBEDTLS_CIPHER_MODE_CFB)
335 
370  int mode,
371  size_t length,
372  size_t *iv_off,
373  unsigned char iv[16],
374  const unsigned char *input,
375  unsigned char *output );
376 
410  int mode,
411  size_t length,
412  unsigned char iv[16],
413  const unsigned char *input,
414  unsigned char *output );
415 #endif /*MBEDTLS_CIPHER_MODE_CFB */
416 
417 #if defined(MBEDTLS_CIPHER_MODE_OFB)
418 
459  size_t length,
460  size_t *iv_off,
461  unsigned char iv[16],
462  const unsigned char *input,
463  unsigned char *output );
464 
465 #endif /* MBEDTLS_CIPHER_MODE_OFB */
466 
467 #if defined(MBEDTLS_CIPHER_MODE_CTR)
468 
539  size_t length,
540  size_t *nc_off,
541  unsigned char nonce_counter[16],
542  unsigned char stream_block[16],
543  const unsigned char *input,
544  unsigned char *output );
545 #endif /* MBEDTLS_CIPHER_MODE_CTR */
546 
559  const unsigned char input[16],
560  unsigned char output[16] );
561 
574  const unsigned char input[16],
575  unsigned char output[16] );
576 
577 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
578 #if defined(MBEDTLS_DEPRECATED_WARNING)
579 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
580 #else
581 #define MBEDTLS_DEPRECATED
582 #endif
583 
594  const unsigned char input[16],
595  unsigned char output[16] );
596 
608  const unsigned char input[16],
609  unsigned char output[16] );
610 
611 #undef MBEDTLS_DEPRECATED
612 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
613 
620 int mbedtls_aes_self_test( int verbose );
621 
622 #ifdef __cplusplus
623 }
624 #endif
625 
626 #endif /* aes.h */
uint32_t buf[68]
Definition: aes.h:86
mbedtls_aes_context crypt
Definition: aes.h:103
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_DEPRECATED
Definition: aes.h:579
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...
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:101
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:105
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:85
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:82
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.