PolarSSL v1.1.4
camellia.h
Go to the documentation of this file.
00001 
00027 #ifndef POLARSSL_CAMELLIA_H
00028 #define POLARSSL_CAMELLIA_H
00029 
00030 #include <string.h>
00031 
00032 #ifdef _MSC_VER
00033 #include <basetsd.h>
00034 typedef UINT32 uint32_t;
00035 #else
00036 #include <inttypes.h>
00037 #endif
00038 
00039 #define CAMELLIA_ENCRYPT     1
00040 #define CAMELLIA_DECRYPT     0
00041 
00042 #define POLARSSL_ERR_CAMELLIA_INVALID_KEY_LENGTH           -0x0024  
00043 #define POLARSSL_ERR_CAMELLIA_INVALID_INPUT_LENGTH         -0x0026  
00048 typedef struct
00049 {
00050     int nr;                     
00051     uint32_t rk[68];            
00052 }
00053 camellia_context;
00054 
00055 #ifdef __cplusplus
00056 extern "C" {
00057 #endif
00058 
00068 int camellia_setkey_enc( camellia_context *ctx, const unsigned char *key, unsigned int keysize );
00069 
00079 int camellia_setkey_dec( camellia_context *ctx, const unsigned char *key, unsigned int keysize );
00080 
00091 int camellia_crypt_ecb( camellia_context *ctx,
00092                     int mode,
00093                     const unsigned char input[16],
00094                     unsigned char output[16] );
00095 
00110 int camellia_crypt_cbc( camellia_context *ctx,
00111                     int mode,
00112                     size_t length,
00113                     unsigned char iv[16],
00114                     const unsigned char *input,
00115                     unsigned char *output );
00116 
00134 int camellia_crypt_cfb128( camellia_context *ctx,
00135                        int mode,
00136                        size_t length,
00137                        size_t *iv_off,
00138                        unsigned char iv[16],
00139                        const unsigned char *input,
00140                        unsigned char *output );
00141 
00142 /*
00143  * \brief               CAMELLIA-CTR buffer encryption/decryption
00144  *
00145  * Warning: You have to keep the maximum use of your counter in mind!
00146  *
00147  * Note: Due to the nature of CTR you should use the same key schedule for
00148  * both encryption and decryption. So a context initialized with
00149  * camellia_setkey_enc() for both CAMELLIA_ENCRYPT and CAMELLIA_DECRYPT.
00150  *
00151  * \param length        The length of the data
00152  * \param nc_off        The offset in the current stream_block (for resuming
00153  *                      within current cipher stream). The offset pointer to
00154  *                      should be 0 at the start of a stream.
00155  * \param nonce_counter The 128-bit nonce and counter.
00156  * \param stream_block  The saved stream-block for resuming. Is overwritten
00157  *                      by the function.
00158  * \param input         The input data stream
00159  * \param output        The output data stream
00160  *
00161  * \return         0 if successful
00162  */
00163 int camellia_crypt_ctr( camellia_context *ctx,
00164                        size_t length,
00165                        size_t *nc_off,
00166                        unsigned char nonce_counter[16],
00167                        unsigned char stream_block[16],
00168                        const unsigned char *input,
00169                        unsigned char *output );
00170 
00176 int camellia_self_test( int verbose );
00177 
00178 #ifdef __cplusplus
00179 }
00180 #endif
00181 
00182 #endif /* camellia.h */