30#if !defined(POLARSSL_CONFIG_FILE)
33#include POLARSSL_CONFIG_FILE
36#if defined(POLARSSL_CIPHER_C)
40#if defined(POLARSSL_AES_C)
44#if defined(POLARSSL_ARC4_C)
48#if defined(POLARSSL_CAMELLIA_C)
52#if defined(POLARSSL_DES_C)
56#if defined(POLARSSL_BLOWFISH_C)
60#if defined(POLARSSL_GCM_C)
64#if defined(POLARSSL_CCM_C)
68#if defined(POLARSSL_PLATFORM_C)
71#define polarssl_malloc malloc
72#define polarssl_free free
77#if defined(POLARSSL_GCM_C)
79static void *gcm_ctx_alloc(
void )
84static void gcm_ctx_free(
void *ctx )
91#if defined(POLARSSL_CCM_C)
93static void *ccm_ctx_alloc(
void )
98static void ccm_ctx_free(
void *ctx )
105#if defined(POLARSSL_AES_C)
107static int aes_crypt_ecb_wrap(
void *ctx,
operation_t operation,
108 const unsigned char *input,
unsigned char *output )
113static int aes_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
114 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
116#if defined(POLARSSL_CIPHER_MODE_CBC)
131static int aes_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
132 size_t length,
size_t *iv_off,
unsigned char *iv,
133 const unsigned char *input,
unsigned char *output )
135#if defined(POLARSSL_CIPHER_MODE_CFB)
151static int aes_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
152 unsigned char *nonce_counter,
unsigned char *stream_block,
153 const unsigned char *input,
unsigned char *output )
155#if defined(POLARSSL_CIPHER_MODE_CTR)
157 stream_block, input, output );
162 ((void) nonce_counter);
163 ((void) stream_block);
171static int aes_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
172 unsigned int key_length )
177static int aes_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
178 unsigned int key_length )
183static void * aes_ctx_alloc(
void )
195static void aes_ctx_free(
void *ctx )
205 aes_crypt_cfb128_wrap,
247#if defined(POLARSSL_CIPHER_MODE_CBC)
282#if defined(POLARSSL_CIPHER_MODE_CFB)
317#if defined(POLARSSL_CIPHER_MODE_CTR)
352#if defined(POLARSSL_GCM_C)
353static int gcm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
354 unsigned int key_length )
407#if defined(POLARSSL_CCM_C)
408static int ccm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
409 unsigned int key_length )
464#if defined(POLARSSL_CAMELLIA_C)
466static int camellia_crypt_ecb_wrap(
void *ctx,
operation_t operation,
467 const unsigned char *input,
unsigned char *output )
473static int camellia_crypt_cbc_wrap(
void *ctx,
operation_t operation,
474 size_t length,
unsigned char *iv,
475 const unsigned char *input,
unsigned char *output )
477#if defined(POLARSSL_CIPHER_MODE_CBC)
492static int camellia_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
493 size_t length,
size_t *iv_off,
unsigned char *iv,
494 const unsigned char *input,
unsigned char *output )
496#if defined(POLARSSL_CIPHER_MODE_CFB)
498 iv_off, iv, input, output );
512static int camellia_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
513 unsigned char *nonce_counter,
unsigned char *stream_block,
514 const unsigned char *input,
unsigned char *output )
516#if defined(POLARSSL_CIPHER_MODE_CTR)
518 nonce_counter, stream_block, input, output );
523 ((void) nonce_counter);
524 ((void) stream_block);
532static int camellia_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
533 unsigned int key_length )
538static int camellia_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
539 unsigned int key_length )
544static void * camellia_ctx_alloc(
void )
557static void camellia_ctx_free(
void *ctx )
565 camellia_crypt_ecb_wrap,
566 camellia_crypt_cbc_wrap,
567 camellia_crypt_cfb128_wrap,
568 camellia_crypt_ctr_wrap,
570 camellia_setkey_enc_wrap,
571 camellia_setkey_dec_wrap,
609#if defined(POLARSSL_CIPHER_MODE_CBC)
644#if defined(POLARSSL_CIPHER_MODE_CFB)
649 "CAMELLIA-128-CFB128",
660 "CAMELLIA-192-CFB128",
671 "CAMELLIA-256-CFB128",
679#if defined(POLARSSL_CIPHER_MODE_CTR)
714#if defined(POLARSSL_GCM_C)
715static int gcm_camellia_setkey_wrap(
void *ctx,
const unsigned char *key,
716 unsigned int key_length )
729 gcm_camellia_setkey_wrap,
730 gcm_camellia_setkey_wrap,
769#if defined(POLARSSL_CCM_C)
770static int ccm_camellia_setkey_wrap(
void *ctx,
const unsigned char *key,
771 unsigned int key_length )
784 ccm_camellia_setkey_wrap,
785 ccm_camellia_setkey_wrap,
826#if defined(POLARSSL_DES_C)
828static int des_crypt_ecb_wrap(
void *ctx,
operation_t operation,
829 const unsigned char *input,
unsigned char *output )
835static int des3_crypt_ecb_wrap(
void *ctx,
operation_t operation,
836 const unsigned char *input,
unsigned char *output )
842static int des_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
843 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
845#if defined(POLARSSL_CIPHER_MODE_CBC)
860static int des3_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
861 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
863#if defined(POLARSSL_CIPHER_MODE_CBC)
878static int des_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
879 unsigned int key_length )
886static int des_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
887 unsigned int key_length )
894static int des3_set2key_dec_wrap(
void *ctx,
const unsigned char *key,
895 unsigned int key_length )
902static int des3_set2key_enc_wrap(
void *ctx,
const unsigned char *key,
903 unsigned int key_length )
910static int des3_set3key_dec_wrap(
void *ctx,
const unsigned char *key,
911 unsigned int key_length )
918static int des3_set3key_enc_wrap(
void *ctx,
const unsigned char *key,
919 unsigned int key_length )
926static void * des_ctx_alloc(
void )
938static void des_ctx_free(
void *ctx )
944static void * des3_ctx_alloc(
void )
957static void des3_ctx_free(
void *ctx )
987#if defined(POLARSSL_CIPHER_MODE_CBC)
1002 des3_crypt_ecb_wrap,
1003 des3_crypt_cbc_wrap,
1007 des3_set2key_enc_wrap,
1008 des3_set2key_dec_wrap,
1024#if defined(POLARSSL_CIPHER_MODE_CBC)
1039 des3_crypt_ecb_wrap,
1040 des3_crypt_cbc_wrap,
1044 des3_set3key_enc_wrap,
1045 des3_set3key_dec_wrap,
1060#if defined(POLARSSL_CIPHER_MODE_CBC)
1074#if defined(POLARSSL_BLOWFISH_C)
1076static int blowfish_crypt_ecb_wrap(
void *ctx,
operation_t operation,
1077 const unsigned char *input,
unsigned char *output )
1083static int blowfish_crypt_cbc_wrap(
void *ctx,
operation_t operation,
1084 size_t length,
unsigned char *iv,
const unsigned char *input,
1085 unsigned char *output )
1087#if defined(POLARSSL_CIPHER_MODE_CBC)
1102static int blowfish_crypt_cfb64_wrap(
void *ctx,
operation_t operation,
1103 size_t length,
size_t *iv_off,
unsigned char *iv,
1104 const unsigned char *input,
unsigned char *output )
1106#if defined(POLARSSL_CIPHER_MODE_CFB)
1108 iv_off, iv, input, output );
1122static int blowfish_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
1123 unsigned char *nonce_counter,
unsigned char *stream_block,
1124 const unsigned char *input,
unsigned char *output )
1126#if defined(POLARSSL_CIPHER_MODE_CTR)
1128 nonce_counter, stream_block, input, output );
1133 ((void) nonce_counter);
1134 ((void) stream_block);
1142static int blowfish_setkey_wrap(
void *ctx,
const unsigned char *key,
1143 unsigned int key_length )
1148static void * blowfish_ctx_alloc(
void )
1161static void blowfish_ctx_free(
void *ctx )
1169 blowfish_crypt_ecb_wrap,
1170 blowfish_crypt_cbc_wrap,
1171 blowfish_crypt_cfb64_wrap,
1172 blowfish_crypt_ctr_wrap,
1174 blowfish_setkey_wrap,
1175 blowfish_setkey_wrap,
1191#if defined(POLARSSL_CIPHER_MODE_CBC)
1204#if defined(POLARSSL_CIPHER_MODE_CFB)
1217#if defined(POLARSSL_CIPHER_MODE_CTR)
1231#if defined(POLARSSL_ARC4_C)
1232static int arc4_crypt_stream_wrap(
void *ctx,
size_t length,
1233 const unsigned char *input,
1234 unsigned char *output )
1239static int arc4_setkey_wrap(
void *ctx,
const unsigned char *key,
1240 unsigned int key_length )
1243 if( key_length % 8 != 0 )
1250static void * arc4_ctx_alloc(
void )
1263static void arc4_ctx_free(
void *ctx )
1275 arc4_crypt_stream_wrap,
1294#if defined(POLARSSL_CIPHER_NULL_CIPHER)
1295static int null_crypt_stream(
void *ctx,
size_t length,
1296 const unsigned char *input,
1297 unsigned char *output )
1300 memmove( output, input, length );
1304static int null_setkey(
void *ctx,
const unsigned char *key,
1305 unsigned int key_length )
1309 ((void) key_length);
1314static void * null_ctx_alloc(
void )
1316 return( (
void *) 1 );
1319static void null_ctx_free(
void *ctx )
1351#if defined(POLARSSL_AES_C)
1355#if defined(POLARSSL_CIPHER_MODE_CBC)
1360#if defined(POLARSSL_CIPHER_MODE_CFB)
1365#if defined(POLARSSL_CIPHER_MODE_CTR)
1370#if defined(POLARSSL_GCM_C)
1375#if defined(POLARSSL_CCM_C)
1382#if defined(POLARSSL_ARC4_C)
1386#if defined(POLARSSL_BLOWFISH_C)
1388#if defined(POLARSSL_CIPHER_MODE_CBC)
1391#if defined(POLARSSL_CIPHER_MODE_CFB)
1394#if defined(POLARSSL_CIPHER_MODE_CTR)
1399#if defined(POLARSSL_CAMELLIA_C)
1403#if defined(POLARSSL_CIPHER_MODE_CBC)
1408#if defined(POLARSSL_CIPHER_MODE_CFB)
1413#if defined(POLARSSL_CIPHER_MODE_CTR)
1418#if defined(POLARSSL_GCM_C)
1423#if defined(POLARSSL_CCM_C)
1430#if defined(POLARSSL_DES_C)
1434#if defined(POLARSSL_CIPHER_MODE_CBC)
1441#if defined(POLARSSL_CIPHER_NULL_CIPHER)
1448#define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
int aes_crypt_ctr(aes_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output)
AES-CTR buffer encryption/decryption.
int aes_crypt_ecb(aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
AES-ECB block encryption/decryption.
int aes_setkey_enc(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (encryption)
int aes_crypt_cbc(aes_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes)
int aes_crypt_cfb128(aes_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
AES-CFB128 buffer encryption/decryption.
void aes_free(aes_context *ctx)
Clear AES context.
int aes_setkey_dec(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (decryption)
void aes_init(aes_context *ctx)
Initialize AES context.
The ARCFOUR stream cipher.
void arc4_setup(arc4_context *ctx, const unsigned char *key, unsigned int keylen)
ARC4 key schedule.
void arc4_init(arc4_context *ctx)
Initialize ARC4 context.
int arc4_crypt(arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
ARC4 cipher function.
void arc4_free(arc4_context *ctx)
Clear ARC4 context.
int blowfish_setkey(blowfish_context *ctx, const unsigned char *key, unsigned int keysize)
Blowfish key schedule.
int blowfish_crypt_ecb(blowfish_context *ctx, int mode, const unsigned char input[BLOWFISH_BLOCKSIZE], unsigned char output[BLOWFISH_BLOCKSIZE])
Blowfish-ECB block encryption/decryption.
int blowfish_crypt_cfb64(blowfish_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish CFB buffer encryption/decryption.
int blowfish_crypt_cbc(blowfish_context *ctx, int mode, size_t length, unsigned char iv[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CBC buffer encryption/decryption Length should be a multiple of the block size (8 bytes)
int blowfish_crypt_ctr(blowfish_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[BLOWFISH_BLOCKSIZE], unsigned char stream_block[BLOWFISH_BLOCKSIZE], const unsigned char *input, unsigned char *output)
Blowfish-CTR buffer encryption/decryption.
void blowfish_free(blowfish_context *ctx)
Clear Blowfish context.
void blowfish_init(blowfish_context *ctx)
Initialize Blowfish context.
int camellia_crypt_cbc(camellia_context *ctx, int mode, size_t length, unsigned char iv[16], const unsigned char *input, unsigned char *output)
CAMELLIA-CBC buffer encryption/decryption Length should be a multiple of the block size (16 bytes)
int camellia_crypt_cfb128(camellia_context *ctx, int mode, size_t length, size_t *iv_off, unsigned char iv[16], const unsigned char *input, unsigned char *output)
CAMELLIA-CFB128 buffer encryption/decryption.
int camellia_setkey_enc(camellia_context *ctx, const unsigned char *key, unsigned int keysize)
CAMELLIA key schedule (encryption)
int camellia_crypt_ecb(camellia_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
CAMELLIA-ECB block encryption/decryption.
int camellia_setkey_dec(camellia_context *ctx, const unsigned char *key, unsigned int keysize)
CAMELLIA key schedule (decryption)
void camellia_init(camellia_context *ctx)
Initialize CAMELLIA context.
void camellia_free(camellia_context *ctx)
Clear CAMELLIA context.
int camellia_crypt_ctr(camellia_context *ctx, size_t length, size_t *nc_off, unsigned char nonce_counter[16], unsigned char stream_block[16], const unsigned char *input, unsigned char *output)
CAMELLIA-CTR buffer encryption/decryption.
Counter with CBC-MAC (CCM) for 128-bit block ciphers.
void ccm_free(ccm_context *ctx)
Free a CCM context and underlying cipher sub-context.
int ccm_init(ccm_context *ctx, cipher_id_t cipher, const unsigned char *key, unsigned int keysize)
CCM initialization (encryption and decryption)
@ POLARSSL_KEY_LENGTH_DES
Key length, in bits (including parity), for DES keys.
@ POLARSSL_KEY_LENGTH_DES_EDE
Key length, in bits (including parity), for DES in two key EDE.
@ POLARSSL_KEY_LENGTH_DES_EDE3
Key length, in bits (including parity), for DES in three-key EDE.
@ POLARSSL_CIPHER_ID_ARC4
@ POLARSSL_CIPHER_ID_BLOWFISH
@ POLARSSL_CIPHER_ID_CAMELLIA
@ POLARSSL_CIPHER_ID_NULL
#define POLARSSL_CIPHER_VARIABLE_KEY_LEN
Cipher accepts keys of variable length.
#define POLARSSL_ERR_CIPHER_BAD_INPUT_DATA
Bad input parameters to function.
@ POLARSSL_CIPHER_CAMELLIA_256_GCM
@ POLARSSL_CIPHER_BLOWFISH_CTR
@ POLARSSL_CIPHER_DES_EDE_ECB
@ POLARSSL_CIPHER_DES_ECB
@ POLARSSL_CIPHER_CAMELLIA_192_CCM
@ POLARSSL_CIPHER_CAMELLIA_256_CTR
@ POLARSSL_CIPHER_CAMELLIA_192_CBC
@ POLARSSL_CIPHER_AES_256_CCM
@ POLARSSL_CIPHER_CAMELLIA_128_CCM
@ POLARSSL_CIPHER_AES_128_GCM
@ POLARSSL_CIPHER_AES_256_CBC
@ POLARSSL_CIPHER_BLOWFISH_CBC
@ POLARSSL_CIPHER_AES_128_ECB
@ POLARSSL_CIPHER_CAMELLIA_128_GCM
@ POLARSSL_CIPHER_AES_256_GCM
@ POLARSSL_CIPHER_AES_192_CTR
@ POLARSSL_CIPHER_CAMELLIA_256_CFB128
@ POLARSSL_CIPHER_AES_256_CFB128
@ POLARSSL_CIPHER_AES_128_CTR
@ POLARSSL_CIPHER_CAMELLIA_128_CTR
@ POLARSSL_CIPHER_DES_EDE3_ECB
@ POLARSSL_CIPHER_AES_128_CFB128
@ POLARSSL_CIPHER_CAMELLIA_128_CBC
@ POLARSSL_CIPHER_CAMELLIA_256_CCM
@ POLARSSL_CIPHER_CAMELLIA_128_CFB128
@ POLARSSL_CIPHER_CAMELLIA_192_GCM
@ POLARSSL_CIPHER_CAMELLIA_256_ECB
@ POLARSSL_CIPHER_DES_EDE_CBC
@ POLARSSL_CIPHER_AES_128_CBC
@ POLARSSL_CIPHER_CAMELLIA_192_CTR
@ POLARSSL_CIPHER_AES_192_GCM
@ POLARSSL_CIPHER_CAMELLIA_192_ECB
@ POLARSSL_CIPHER_CAMELLIA_192_CFB128
@ POLARSSL_CIPHER_AES_192_CFB128
@ POLARSSL_CIPHER_AES_128_CCM
@ POLARSSL_CIPHER_AES_192_CCM
@ POLARSSL_CIPHER_ARC4_128
@ POLARSSL_CIPHER_AES_256_CTR
@ POLARSSL_CIPHER_CAMELLIA_256_CBC
@ POLARSSL_CIPHER_BLOWFISH_CFB64
@ POLARSSL_CIPHER_AES_256_ECB
@ POLARSSL_CIPHER_BLOWFISH_ECB
@ POLARSSL_CIPHER_AES_192_ECB
@ POLARSSL_CIPHER_AES_192_CBC
@ POLARSSL_CIPHER_DES_EDE3_CBC
@ POLARSSL_CIPHER_DES_CBC
@ POLARSSL_CIPHER_CAMELLIA_128_ECB
#define POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE
The selected feature is not available.
#define POLARSSL_CIPHER_VARIABLE_IV_LEN
Cipher accepts IVs of variable length.
const cipher_definition_t cipher_definitions[]
Configuration options (set of defines)
int des_setkey_enc(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
void des_init(des_context *ctx)
Initialize DES context.
int des3_set2key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, encryption)
void des3_init(des3_context *ctx)
Initialize Triple-DES context.
int des3_set3key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
int des_crypt_cbc(des_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
DES-CBC buffer encryption/decryption.
int des_crypt_ecb(des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
int des3_set3key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
void des3_free(des3_context *ctx)
Clear Triple-DES context.
int des3_set2key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, decryption)
int des_setkey_dec(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
int des3_crypt_cbc(des3_context *ctx, int mode, size_t length, unsigned char iv[8], const unsigned char *input, unsigned char *output)
3DES-CBC buffer encryption/decryption
int des3_crypt_ecb(des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
void des_free(des_context *ctx)
Clear DES context.
Galois/Counter mode for 128-bit block ciphers.
void gcm_free(gcm_context *ctx)
Free a GCM context and underlying cipher sub-context.
int gcm_init(gcm_context *ctx, cipher_id_t cipher, const unsigned char *key, unsigned int keysize)
GCM initialization (encryption)
Blowfish context structure.
CAMELLIA context structure.
Triple-DES context structure.