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_PLATFORM_C)
67 #define polarssl_malloc malloc
68 #define polarssl_free free
73 #if defined(POLARSSL_GCM_C)
75 static void *gcm_ctx_alloc(
void )
80 static void gcm_ctx_free(
void *ctx )
87 #if defined(POLARSSL_AES_C)
89 static int aes_crypt_ecb_wrap(
void *ctx,
operation_t operation,
90 const unsigned char *input,
unsigned char *output )
95 static int aes_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
96 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
98 #if defined(POLARSSL_CIPHER_MODE_CBC)
113 static int aes_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
114 size_t length,
size_t *iv_off,
unsigned char *iv,
115 const unsigned char *input,
unsigned char *output )
117 #if defined(POLARSSL_CIPHER_MODE_CFB)
133 static int aes_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
134 unsigned char *nonce_counter,
unsigned char *stream_block,
135 const unsigned char *input,
unsigned char *output )
137 #if defined(POLARSSL_CIPHER_MODE_CTR)
139 stream_block, input, output );
144 ((void) nonce_counter);
145 ((void) stream_block);
153 static int aes_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
154 unsigned int key_length )
159 static int aes_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
160 unsigned int key_length )
165 static void * aes_ctx_alloc(
void )
170 static void aes_ctx_free(
void *ctx )
179 aes_crypt_cfb128_wrap,
221 #if defined(POLARSSL_CIPHER_MODE_CBC)
256 #if defined(POLARSSL_CIPHER_MODE_CFB)
291 #if defined(POLARSSL_CIPHER_MODE_CTR)
326 #if defined(POLARSSL_GCM_C)
327 static int gcm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
328 unsigned int key_length )
383 #if defined(POLARSSL_CAMELLIA_C)
385 static int camellia_crypt_ecb_wrap(
void *ctx,
operation_t operation,
386 const unsigned char *input,
unsigned char *output )
392 static int camellia_crypt_cbc_wrap(
void *ctx,
operation_t operation,
393 size_t length,
unsigned char *iv,
394 const unsigned char *input,
unsigned char *output )
396 #if defined(POLARSSL_CIPHER_MODE_CBC)
411 static int camellia_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
412 size_t length,
size_t *iv_off,
unsigned char *iv,
413 const unsigned char *input,
unsigned char *output )
415 #if defined(POLARSSL_CIPHER_MODE_CFB)
417 iv_off, iv, input, output );
431 static int camellia_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
432 unsigned char *nonce_counter,
unsigned char *stream_block,
433 const unsigned char *input,
unsigned char *output )
435 #if defined(POLARSSL_CIPHER_MODE_CTR)
437 nonce_counter, stream_block, input, output );
442 ((void) nonce_counter);
443 ((void) stream_block);
451 static int camellia_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
452 unsigned int key_length )
457 static int camellia_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
458 unsigned int key_length )
463 static void * camellia_ctx_alloc(
void )
468 static void camellia_ctx_free(
void *ctx )
475 camellia_crypt_ecb_wrap,
476 camellia_crypt_cbc_wrap,
477 camellia_crypt_cfb128_wrap,
478 camellia_crypt_ctr_wrap,
480 camellia_setkey_enc_wrap,
481 camellia_setkey_dec_wrap,
519 #if defined(POLARSSL_CIPHER_MODE_CBC)
554 #if defined(POLARSSL_CIPHER_MODE_CFB)
559 "CAMELLIA-128-CFB128",
570 "CAMELLIA-192-CFB128",
581 "CAMELLIA-256-CFB128",
589 #if defined(POLARSSL_CIPHER_MODE_CTR)
624 #if defined(POLARSSL_GCM_C)
625 static int gcm_camellia_setkey_wrap(
void *ctx,
const unsigned char *key,
626 unsigned int key_length )
639 gcm_camellia_setkey_wrap,
640 gcm_camellia_setkey_wrap,
681 #if defined(POLARSSL_DES_C)
683 static int des_crypt_ecb_wrap(
void *ctx,
operation_t operation,
684 const unsigned char *input,
unsigned char *output )
690 static int des3_crypt_ecb_wrap(
void *ctx,
operation_t operation,
691 const unsigned char *input,
unsigned char *output )
697 static int des_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
698 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
700 #if defined(POLARSSL_CIPHER_MODE_CBC)
715 static int des3_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
716 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
718 #if defined(POLARSSL_CIPHER_MODE_CBC)
733 static int des_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
734 size_t length,
size_t *iv_off,
unsigned char *iv,
735 const unsigned char *input,
unsigned char *output )
748 static int des_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
749 unsigned char *nonce_counter,
unsigned char *stream_block,
750 const unsigned char *input,
unsigned char *output )
755 ((void) nonce_counter);
756 ((void) stream_block);
763 static int des_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
764 unsigned int key_length )
771 static int des_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
772 unsigned int key_length )
779 static int des3_set2key_dec_wrap(
void *ctx,
const unsigned char *key,
780 unsigned int key_length )
787 static int des3_set2key_enc_wrap(
void *ctx,
const unsigned char *key,
788 unsigned int key_length )
795 static int des3_set3key_dec_wrap(
void *ctx,
const unsigned char *key,
796 unsigned int key_length )
803 static int des3_set3key_enc_wrap(
void *ctx,
const unsigned char *key,
804 unsigned int key_length )
811 static void * des_ctx_alloc(
void )
816 static void * des3_ctx_alloc(
void )
821 static void des_ctx_free(
void *ctx )
830 des_crypt_cfb128_wrap,
850 #if defined(POLARSSL_CIPHER_MODE_CBC)
867 des_crypt_cfb128_wrap,
870 des3_set2key_enc_wrap,
871 des3_set2key_dec_wrap,
887 #if defined(POLARSSL_CIPHER_MODE_CBC)
904 des_crypt_cfb128_wrap,
907 des3_set3key_enc_wrap,
908 des3_set3key_dec_wrap,
923 #if defined(POLARSSL_CIPHER_MODE_CBC)
937 #if defined(POLARSSL_BLOWFISH_C)
939 static int blowfish_crypt_ecb_wrap(
void *ctx,
operation_t operation,
940 const unsigned char *input,
unsigned char *output )
946 static int blowfish_crypt_cbc_wrap(
void *ctx,
operation_t operation,
947 size_t length,
unsigned char *iv,
const unsigned char *input,
948 unsigned char *output )
950 #if defined(POLARSSL_CIPHER_MODE_CBC)
965 static int blowfish_crypt_cfb64_wrap(
void *ctx,
operation_t operation,
966 size_t length,
size_t *iv_off,
unsigned char *iv,
967 const unsigned char *input,
unsigned char *output )
969 #if defined(POLARSSL_CIPHER_MODE_CFB)
971 iv_off, iv, input, output );
985 static int blowfish_crypt_ctr_wrap(
void *ctx,
size_t length,
size_t *nc_off,
986 unsigned char *nonce_counter,
unsigned char *stream_block,
987 const unsigned char *input,
unsigned char *output )
989 #if defined(POLARSSL_CIPHER_MODE_CTR)
991 nonce_counter, stream_block, input, output );
996 ((void) nonce_counter);
997 ((void) stream_block);
1005 static int blowfish_setkey_wrap(
void *ctx,
const unsigned char *key,
1006 unsigned int key_length )
1011 static void * blowfish_ctx_alloc(
void )
1016 static void blowfish_ctx_free(
void *ctx )
1023 blowfish_crypt_ecb_wrap,
1024 blowfish_crypt_cbc_wrap,
1025 blowfish_crypt_cfb64_wrap,
1026 blowfish_crypt_ctr_wrap,
1028 blowfish_setkey_wrap,
1029 blowfish_setkey_wrap,
1045 #if defined(POLARSSL_CIPHER_MODE_CBC)
1058 #if defined(POLARSSL_CIPHER_MODE_CFB)
1071 #if defined(POLARSSL_CIPHER_MODE_CTR)
1085 #if defined(POLARSSL_ARC4_C)
1086 static int arc4_crypt_stream_wrap(
void *ctx,
size_t length,
1087 const unsigned char *input,
1088 unsigned char *output )
1093 static int arc4_setkey_wrap(
void *ctx,
const unsigned char *key,
1094 unsigned int key_length )
1097 if( key_length % 8 != 0)
1104 static void * arc4_ctx_alloc(
void )
1109 static void arc4_ctx_free(
void *ctx )
1120 arc4_crypt_stream_wrap,
1139 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1140 static int null_crypt_stream(
void *ctx,
size_t length,
1141 const unsigned char *input,
1142 unsigned char *output )
1145 memmove( output, input, length );
1149 static int null_setkey(
void *ctx,
const unsigned char *key,
1150 unsigned int key_length )
1154 ((void) key_length);
1159 static void * null_ctx_alloc(
void )
1164 static void null_ctx_free(
void *ctx )
1196 #if defined(POLARSSL_AES_C)
1200 #if defined(POLARSSL_CIPHER_MODE_CBC)
1205 #if defined(POLARSSL_CIPHER_MODE_CFB)
1210 #if defined(POLARSSL_CIPHER_MODE_CTR)
1215 #if defined(POLARSSL_GCM_C)
1222 #if defined(POLARSSL_ARC4_C)
1226 #if defined(POLARSSL_BLOWFISH_C)
1228 #if defined(POLARSSL_CIPHER_MODE_CBC)
1231 #if defined(POLARSSL_CIPHER_MODE_CFB)
1234 #if defined(POLARSSL_CIPHER_MODE_CTR)
1239 #if defined(POLARSSL_CAMELLIA_C)
1243 #if defined(POLARSSL_CIPHER_MODE_CBC)
1248 #if defined(POLARSSL_CIPHER_MODE_CFB)
1253 #if defined(POLARSSL_CIPHER_MODE_CTR)
1258 #if defined(POLARSSL_GCM_C)
1265 #if defined(POLARSSL_DES_C)
1269 #if defined(POLARSSL_CIPHER_MODE_CBC)
1276 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1283 #define NUM_CIPHERS sizeof cipher_definitions / sizeof cipher_definitions[0]
#define POLARSSL_ERR_CIPHER_BAD_INPUT_DATA
Bad input parameters to function.
int blowfish_setkey(blowfish_context *ctx, const unsigned char *key, unsigned int keysize)
Blowfish key schedule.
#define POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE
The selected feature is not available.
int arc4_crypt(arc4_context *ctx, size_t length, const unsigned char *input, unsigned char *output)
ARC4 cipher function.
Key length, in bits (including parity), for DES keys.
void arc4_setup(arc4_context *ctx, const unsigned char *key, unsigned int keylen)
ARC4 key schedule.
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 des_crypt_ecb(des_context *ctx, const unsigned char input[8], unsigned char output[8])
DES-ECB block encryption/decryption.
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.
Configuration options (set of defines)
int aes_setkey_dec(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (decryption)
int camellia_setkey_enc(camellia_context *ctx, const unsigned char *key, unsigned int keysize)
CAMELLIA key schedule (encryption)
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.
const cipher_definition_t cipher_definitions[]
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 des3_set3key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, encryption)
int des3_set3key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *3])
Triple-DES key schedule (168-bit, decryption)
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.
Triple-DES context structure.
int des3_set2key_enc(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-bit, 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) ...
Key length, in bits (including parity), for DES in three-key EDE.
CAMELLIA context structure.
int gcm_init(gcm_context *ctx, cipher_id_t cipher, const unsigned char *key, unsigned int keysize)
GCM initialization (encryption)
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 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)
int des_setkey_enc(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, encryption)
int des_setkey_dec(des_context *ctx, const unsigned char key[DES_KEY_SIZE])
DES key schedule (56-bit, decryption)
void gcm_free(gcm_context *ctx)
Free a GCM context and underlying cipher sub-context.
Galois/Counter mode for 128-bit block ciphers.
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.
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 des3_crypt_ecb(des3_context *ctx, const unsigned char input[8], unsigned char output[8])
3DES-ECB block encryption/decryption
Blowfish context structure.
The ARCFOUR stream cipher.
int aes_setkey_enc(aes_context *ctx, const unsigned char *key, unsigned int keysize)
AES key schedule (encryption)
int aes_crypt_ecb(aes_context *ctx, int mode, const unsigned char input[16], unsigned char output[16])
AES-ECB block encryption/decryption.
Key length, in bits (including parity), for DES in two key EDE.
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 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 des3_set2key_dec(des3_context *ctx, const unsigned char key[DES_KEY_SIZE *2])
Triple-DES key schedule (112-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