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)
79 static void *gcm_ctx_alloc(
void )
84 static void gcm_ctx_free(
void *ctx )
91 #if defined(POLARSSL_CCM_C)
93 static void *ccm_ctx_alloc(
void )
98 static void ccm_ctx_free(
void *ctx )
105 #if defined(POLARSSL_AES_C)
107 static int aes_crypt_ecb_wrap(
void *ctx,
operation_t operation,
108 const unsigned char *input,
unsigned char *output )
113 static 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)
131 static 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)
151 static 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);
171 static int aes_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
172 unsigned int key_length )
177 static int aes_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
178 unsigned int key_length )
183 static void * aes_ctx_alloc(
void )
195 static 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)
353 static int gcm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
354 unsigned int key_length )
407 #if defined(POLARSSL_CCM_C)
408 static int ccm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
409 unsigned int key_length )
464 #if defined(POLARSSL_CAMELLIA_C)
466 static int camellia_crypt_ecb_wrap(
void *ctx,
operation_t operation,
467 const unsigned char *input,
unsigned char *output )
473 static 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)
492 static 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 );
512 static 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);
532 static int camellia_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
533 unsigned int key_length )
538 static int camellia_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
539 unsigned int key_length )
544 static void * camellia_ctx_alloc(
void )
557 static 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)
715 static 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)
770 static 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)
828 static int des_crypt_ecb_wrap(
void *ctx,
operation_t operation,
829 const unsigned char *input,
unsigned char *output )
835 static int des3_crypt_ecb_wrap(
void *ctx,
operation_t operation,
836 const unsigned char *input,
unsigned char *output )
842 static 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)
860 static 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)
878 static int des_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
879 unsigned int key_length )
886 static int des_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
887 unsigned int key_length )
894 static int des3_set2key_dec_wrap(
void *ctx,
const unsigned char *key,
895 unsigned int key_length )
902 static int des3_set2key_enc_wrap(
void *ctx,
const unsigned char *key,
903 unsigned int key_length )
910 static int des3_set3key_dec_wrap(
void *ctx,
const unsigned char *key,
911 unsigned int key_length )
918 static int des3_set3key_enc_wrap(
void *ctx,
const unsigned char *key,
919 unsigned int key_length )
926 static void * des_ctx_alloc(
void )
938 static void des_ctx_free(
void *ctx )
944 static void * des3_ctx_alloc(
void )
957 static 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)
1076 static int blowfish_crypt_ecb_wrap(
void *ctx,
operation_t operation,
1077 const unsigned char *input,
unsigned char *output )
1083 static 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)
1102 static 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 );
1122 static 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);
1142 static int blowfish_setkey_wrap(
void *ctx,
const unsigned char *key,
1143 unsigned int key_length )
1148 static void * blowfish_ctx_alloc(
void )
1161 static 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)
1232 static int arc4_crypt_stream_wrap(
void *ctx,
size_t length,
1233 const unsigned char *input,
1234 unsigned char *output )
1239 static int arc4_setkey_wrap(
void *ctx,
const unsigned char *key,
1240 unsigned int key_length )
1243 if( key_length % 8 != 0 )
1250 static void * arc4_ctx_alloc(
void )
1263 static void arc4_ctx_free(
void *ctx )
1275 arc4_crypt_stream_wrap,
1294 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1295 static int null_crypt_stream(
void *ctx,
size_t length,
1296 const unsigned char *input,
1297 unsigned char *output )
1300 memmove( output, input, length );
1304 static int null_setkey(
void *ctx,
const unsigned char *key,
1305 unsigned int key_length )
1309 ((void) key_length);
1314 static void * null_ctx_alloc(
void )
1316 return( (
void *) 1 )
1319 static 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]