PolarSSL v1.1.4
aes.h
Go to the documentation of this file.
00001 
00027 #ifndef POLARSSL_AES_H
00028 #define POLARSSL_AES_H
00029 
00030 #include <string.h>
00031 
00032 #define AES_ENCRYPT     1
00033 #define AES_DECRYPT     0
00034 
00035 #define POLARSSL_ERR_AES_INVALID_KEY_LENGTH                -0x0020  
00036 #define POLARSSL_ERR_AES_INVALID_INPUT_LENGTH              -0x0022  
00041 typedef struct
00042 {
00043     int nr;                     
00044     unsigned long *rk;          
00045     unsigned long buf[68];      
00046 }
00047 aes_context;
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00062 int aes_setkey_enc( aes_context *ctx, const unsigned char *key, unsigned int keysize );
00063 
00073 int aes_setkey_dec( aes_context *ctx, const unsigned char *key, unsigned int keysize );
00074 
00085 int aes_crypt_ecb( aes_context *ctx,
00086                     int mode,
00087                     const unsigned char input[16],
00088                     unsigned char output[16] );
00089 
00104 int aes_crypt_cbc( aes_context *ctx,
00105                     int mode,
00106                     size_t length,
00107                     unsigned char iv[16],
00108                     const unsigned char *input,
00109                     unsigned char *output );
00110 
00129 int aes_crypt_cfb128( aes_context *ctx,
00130                        int mode,
00131                        size_t length,
00132                        size_t *iv_off,
00133                        unsigned char iv[16],
00134                        const unsigned char *input,
00135                        unsigned char *output );
00136 
00137 /*
00138  * \brief               AES-CTR buffer encryption/decryption
00139  *
00140  * Warning: You have to keep the maximum use of your counter in mind!
00141  *
00142  * Note: Due to the nature of CTR you should use the same key schedule for
00143  * both encryption and decryption. So a context initialized with
00144  * aes_setkey_enc() for both AES_ENCRYPT and AES_DECRYPT.
00145  *
00146  * \param length        The length of the data
00147  * \param nc_off        The offset in the current stream_block (for resuming
00148  *                      within current cipher stream). The offset pointer to
00149  *                      should be 0 at the start of a stream.
00150  * \param nonce_counter The 128-bit nonce and counter.
00151  * \param stream_block  The saved stream-block for resuming. Is overwritten
00152  *                      by the function.
00153  * \param input         The input data stream
00154  * \param output        The output data stream
00155  *
00156  * \return         0 if successful
00157  */
00158 int aes_crypt_ctr( aes_context *ctx,
00159                        size_t length,
00160                        size_t *nc_off,
00161                        unsigned char nonce_counter[16],
00162                        unsigned char stream_block[16],
00163                        const unsigned char *input,
00164                        unsigned char *output );
00170 int aes_self_test( int verbose );
00171 
00172 #ifdef __cplusplus
00173 }
00174 #endif
00175 
00176 #endif /* aes.h */