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
00060
00061 #ifndef MBEDTLS_AES_H
00062 #define MBEDTLS_AES_H
00063
00064 #if !defined(MBEDTLS_CONFIG_FILE)
00065 #include "config.h"
00066 #else
00067 #include MBEDTLS_CONFIG_FILE
00068 #endif
00069
00070 #include <stddef.h>
00071 #include <stdint.h>
00072
00073
00074 #define MBEDTLS_AES_ENCRYPT 1
00075 #define MBEDTLS_AES_DECRYPT 0
00077
00078 #define MBEDTLS_ERR_AES_INVALID_KEY_LENGTH -0x0020
00079 #define MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH -0x0022
00081
00082 #define MBEDTLS_ERR_AES_FEATURE_UNAVAILABLE -0x0023
00083 #define MBEDTLS_ERR_AES_HW_ACCEL_FAILED -0x0025
00085 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
00086 !defined(inline) && !defined(__cplusplus)
00087 #define inline __inline
00088 #endif
00089
00090 #if !defined(MBEDTLS_AES_ALT)
00091
00092
00093
00094 #ifdef __cplusplus
00095 extern "C" {
00096 #endif
00097
00101 typedef struct
00102 {
00103 int nr;
00104 uint32_t *rk;
00105 uint32_t buf[68];
00113 }
00114 mbedtls_aes_context;
00115
00124 void mbedtls_aes_init( mbedtls_aes_context *ctx );
00125
00131 void mbedtls_aes_free( mbedtls_aes_context *ctx );
00132
00146 int mbedtls_aes_setkey_enc( mbedtls_aes_context *ctx, const unsigned char *key,
00147 unsigned int keybits );
00148
00161 int mbedtls_aes_setkey_dec( mbedtls_aes_context *ctx, const unsigned char *key,
00162 unsigned int keybits );
00163
00184 int mbedtls_aes_crypt_ecb( mbedtls_aes_context *ctx,
00185 int mode,
00186 const unsigned char input[16],
00187 unsigned char output[16] );
00188
00189 #if defined(MBEDTLS_CIPHER_MODE_CBC)
00190
00226 int mbedtls_aes_crypt_cbc( mbedtls_aes_context *ctx,
00227 int mode,
00228 size_t length,
00229 unsigned char iv[16],
00230 const unsigned char *input,
00231 unsigned char *output );
00232 #endif
00233
00234 #if defined(MBEDTLS_CIPHER_MODE_CFB)
00235
00269 int mbedtls_aes_crypt_cfb128( mbedtls_aes_context *ctx,
00270 int mode,
00271 size_t length,
00272 size_t *iv_off,
00273 unsigned char iv[16],
00274 const unsigned char *input,
00275 unsigned char *output );
00276
00309 int mbedtls_aes_crypt_cfb8( mbedtls_aes_context *ctx,
00310 int mode,
00311 size_t length,
00312 unsigned char iv[16],
00313 const unsigned char *input,
00314 unsigned char *output );
00315 #endif
00316
00317 #if defined(MBEDTLS_CIPHER_MODE_CTR)
00318
00346 int mbedtls_aes_crypt_ctr( mbedtls_aes_context *ctx,
00347 size_t length,
00348 size_t *nc_off,
00349 unsigned char nonce_counter[16],
00350 unsigned char stream_block[16],
00351 const unsigned char *input,
00352 unsigned char *output );
00353 #endif
00354
00366 int mbedtls_internal_aes_encrypt( mbedtls_aes_context *ctx,
00367 const unsigned char input[16],
00368 unsigned char output[16] );
00369
00381 int mbedtls_internal_aes_decrypt( mbedtls_aes_context *ctx,
00382 const unsigned char input[16],
00383 unsigned char output[16] );
00384
00385 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
00386 #if defined(MBEDTLS_DEPRECATED_WARNING)
00387 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
00388 #else
00389 #define MBEDTLS_DEPRECATED
00390 #endif
00391
00401 MBEDTLS_DEPRECATED void mbedtls_aes_encrypt( mbedtls_aes_context *ctx,
00402 const unsigned char input[16],
00403 unsigned char output[16] );
00404
00415 MBEDTLS_DEPRECATED void mbedtls_aes_decrypt( mbedtls_aes_context *ctx,
00416 const unsigned char input[16],
00417 unsigned char output[16] );
00418
00419 #undef MBEDTLS_DEPRECATED
00420 #endif
00421
00422 #ifdef __cplusplus
00423 }
00424 #endif
00425
00426 #else
00427 #include "aes_alt.h"
00428 #endif
00429
00430 #ifdef __cplusplus
00431 extern "C" {
00432 #endif
00433
00439 int mbedtls_aes_self_test( int verbose );
00440
00441 #ifdef __cplusplus
00442 }
00443 #endif
00444
00445 #endif