00001
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059 #ifndef MBEDTLS_AES_H
00060 #define MBEDTLS_AES_H
00061
00062 #if !defined(MBEDTLS_CONFIG_FILE)
00063 #include "config.h"
00064 #else
00065 #include MBEDTLS_CONFIG_FILE
00066 #endif
00067
00068 #include <stddef.h>
00069 #include <stdint.h>
00070
00071
00072 #define MBEDTLS_AES_ENCRYPT 1
00073 #define MBEDTLS_AES_DECRYPT 0
00075
00076 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
00077 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
00079
00080 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
00081 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
00083 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
00084 !defined(inline) && !defined(__cplusplus)
00085 #define inline __inline
00086 #endif
00087
00088 #if !defined(MBEDTLS_AES_ALT)
00089
00090
00091
00092 #ifdef __cplusplus
00093 extern "C" {
00094 #endif
00095
00099 typedef struct
00100 {
00101 int nr;
00102 uint32_t *rk;
00103 uint32_t buf[68];
00111 }
00112 mbedtls_aes_context;
00113
00122 void mbedtls_aes_init( mbedtls_aes_context *ctx );
00123
00129 void mbedtls_aes_free( mbedtls_aes_context *ctx );
00130
00144 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
00145 unsigned int keybits );
00146
00159 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
00160 unsigned int keybits );
00161
00182 int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
00183 int mode,
00184 const unsigned char input[16],
00185 unsigned char output[16] );
00186
00187 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00188
00224 int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
00225 int mode,
00226 size_t length,
00227 unsigned char iv[16],
00228 const unsigned char *input,
00229 unsigned char *output );
00230 #endif
00231
00232 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00233
00267 int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
00268 int mode,
00269 size_t length,
00270 size_t *iv_off,
00271 unsigned char iv[16],
00272 const unsigned char *input,
00273 unsigned char *output );
00274
00307 int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
00308 int mode,
00309 size_t length,
00310 unsigned char iv[16],
00311 const unsigned char *input,
00312 unsigned char *output );
00313 #endif
00314
00315 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00316
00344 int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
00345 size_t length,
00346 size_t *nc_off,
00347 unsigned char nonce_counter[16],
00348 unsigned char stream_block[16],
00349 const unsigned char *input,
00350 unsigned char *output );
00351 #endif
00352
00364 int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
00365 const unsigned char input[16],
00366 unsigned char output[16] );
00367
00379 int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
00380 const unsigned char input[16],
00381 unsigned char output[16] );
00382
00383 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00384 #if defined(MBEDTLS_DEPRECATED_WARNING)
00385 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
00386 #else
00387 #define MBEDTLS_DEPRECATED
00388 #endif
00389
00399 MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
00400 const unsigned char input[16],
00401 unsigned char output[16] );
00402
00413 MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
00414 const unsigned char input[16],
00415 unsigned char output[16] );
00416
00417 #undef MBEDTLS_DEPRECATED
00418 #endif
00419
00420 #ifdef __cplusplus
00421 }
00422 #endif
00423
00424 #else
00425 #include "aes_alt.h"
00426 #endif
00427
00428 #ifdef __cplusplus
00429 extern "C" {
00430 #endif
00431
00437 int mbedtls_aes_self_test( int verbose );
00438
00439 #ifdef __cplusplus
00440 }
00441 #endif
00442
00443 #endif