00001
00027 #ifndef POLARSSL_AES_H
00028 #define POLARSSL_AES_H
00029
00030 #define POLARSSL_CIPHER_MODE_CTR 1
00031 #include <string.h>
00032
00033 #if defined(_MSC_VER) && !defined(EFIX64) && !defined(EFI32)
00034 #include <basetsd.h>
00035 typedef UINT32 uint32_t;
00036 #else
00037 #include <inttypes.h>
00038 #endif
00039
00040
00041 #define AES_ENCRYPT 1
00042 #define AES_DECRYPT 0
00043
00044 #define POLARSSL_ERR_AES_INVALID_KEY_LENGTH -0x0020
00045 #define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH -0x0022
00047 // Regular implementation
00048
00049
00050 #ifdef __cplusplus
00051 extern "C" {
00052 #endif
00053
00062 typedef struct
00063 {
00064 int nr;
00065 uint32_t *rk;
00066 uint32_t buf[68];
00067 }
00068 aes_context;
00069
00075 void aes_init( aes_context *ctx );
00076
00082 void aes_free( aes_context *ctx );
00083
00093 int aes_setkey_enc( aes_context *ctx, const unsigned char *key,
00094 unsigned int keysize );
00095
00105 int aes_setkey_dec( aes_context *ctx, const unsigned char *key,
00106 unsigned int keysize );
00107
00118 int aes_crypt_ecb( aes_context *ctx,
00119 int mode,
00120 const unsigned char input[16],
00121 unsigned char output[16] );
00122
00123 #if defined(POLARSSL_CIPHER_MODE_CBC)
00124
00138 int aes_crypt_cbc( aes_context *ctx,
00139 int mode,
00140 size_t length,
00141 unsigned char iv[16],
00142 const unsigned char *input,
00143 unsigned char *output );
00144 #endif
00145
00146 #if defined(POLARSSL_CIPHER_MODE_CFB)
00147
00164 int aes_crypt_cfb128( aes_context *ctx,
00165 int mode,
00166 size_t length,
00167 size_t *iv_off,
00168 unsigned char iv[16],
00169 const unsigned char *input,
00170 unsigned char *output );
00171
00188 int aes_crypt_cfb8( aes_context *ctx,
00189 int mode,
00190 size_t length,
00191 unsigned char iv[16],
00192 const unsigned char *input,
00193 unsigned char *output );
00194 #endif
00195
00196 #if defined(POLARSSL_CIPHER_MODE_CTR)
00197
00219 int aes_crypt_ctr( aes_context *ctx,
00220 size_t length,
00221 size_t *nc_off,
00222 unsigned char nonce_counter[16],
00223 unsigned char stream_block[16],
00224 const unsigned char *input,
00225 unsigned char *output );
00226 #endif
00227
00228 #ifdef __cplusplus
00229 }
00230 #endif
00231
00232 #ifdef __cplusplus
00233 extern "C" {
00234 #endif
00235
00241 int aes_self_test( int verbose );
00242
00243 #ifdef __cplusplus
00244 }
00245 #endif
00246
00247 #endif