32 #if defined(POLARSSL_CIPHER_C)
36 #if defined(POLARSSL_AES_C)
40 #if defined(POLARSSL_ARC4_C)
44 #if defined(POLARSSL_CAMELLIA_C)
48 #if defined(POLARSSL_DES_C)
52 #if defined(POLARSSL_BLOWFISH_C)
56 #if defined(POLARSSL_GCM_C)
60 #if defined(POLARSSL_MEMORY_C)
63 #define polarssl_malloc malloc
64 #define polarssl_free free
69 #if defined(POLARSSL_GCM_C)
71 static void *gcm_ctx_alloc(
void )
76 static void gcm_ctx_free(
void *ctx )
83 #if defined(POLARSSL_AES_C)
85 static int aes_crypt_ecb_wrap(
void *ctx,
operation_t operation,
86 const unsigned char *input,
unsigned char *output )
91 static int aes_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
92 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
94 #if defined(POLARSSL_CIPHER_MODE_CBC)
108 static int aes_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
size_t length,
109 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
111 #if defined(POLARSSL_CIPHER_MODE_CFB)
126 static int aes_crypt_ctr_wrap(
void *ctx,
size_t length,
127 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
128 const unsigned char *input,
unsigned char *output )
130 #if defined(POLARSSL_CIPHER_MODE_CTR)
132 stream_block, input, output );
137 ((void) nonce_counter);
138 ((void) stream_block);
146 static int aes_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
151 static int aes_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
156 static void * aes_ctx_alloc(
void )
161 static void aes_ctx_free(
void *ctx )
170 aes_crypt_cfb128_wrap,
212 #if defined(POLARSSL_CIPHER_MODE_CBC)
247 #if defined(POLARSSL_CIPHER_MODE_CFB)
282 #if defined(POLARSSL_CIPHER_MODE_CTR)
317 #if defined(POLARSSL_GCM_C)
318 static int gcm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
373 #if defined(POLARSSL_CAMELLIA_C)
375 static int camellia_crypt_ecb_wrap(
void *ctx,
operation_t operation,
376 const unsigned char *input,
unsigned char *output )
381 static int camellia_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
382 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
384 #if defined(POLARSSL_CIPHER_MODE_CBC)
398 static int camellia_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
size_t length,
399 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
401 #if defined(POLARSSL_CIPHER_MODE_CFB)
416 static int camellia_crypt_ctr_wrap(
void *ctx,
size_t length,
417 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
418 const unsigned char *input,
unsigned char *output )
420 #if defined(POLARSSL_CIPHER_MODE_CTR)
422 stream_block, input, output );
427 ((void) nonce_counter);
428 ((void) stream_block);
436 static int camellia_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
441 static int camellia_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
446 static void * camellia_ctx_alloc(
void )
451 static void camellia_ctx_free(
void *ctx )
458 camellia_crypt_ecb_wrap,
459 camellia_crypt_cbc_wrap,
460 camellia_crypt_cfb128_wrap,
461 camellia_crypt_ctr_wrap,
463 camellia_setkey_enc_wrap,
464 camellia_setkey_dec_wrap,
502 #if defined(POLARSSL_CIPHER_MODE_CBC)
537 #if defined(POLARSSL_CIPHER_MODE_CFB)
542 "CAMELLIA-128-CFB128",
553 "CAMELLIA-192-CFB128",
564 "CAMELLIA-256-CFB128",
572 #if defined(POLARSSL_CIPHER_MODE_CTR)
607 #if defined(POLARSSL_GCM_C)
608 static int gcm_camellia_setkey_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
621 gcm_camellia_setkey_wrap,
622 gcm_camellia_setkey_wrap,
663 #if defined(POLARSSL_DES_C)
665 static int des_crypt_ecb_wrap(
void *ctx,
operation_t operation,
666 const unsigned char *input,
unsigned char *output )
672 static int des3_crypt_ecb_wrap(
void *ctx,
operation_t operation,
673 const unsigned char *input,
unsigned char *output )
679 static int des_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
680 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
682 #if defined(POLARSSL_CIPHER_MODE_CBC)
696 static int des3_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
697 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
699 #if defined(POLARSSL_CIPHER_MODE_CBC)
713 static int des_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
size_t length,
714 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
727 static int des_crypt_ctr_wrap(
void *ctx,
size_t length,
728 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
729 const unsigned char *input,
unsigned char *output )
734 ((void) nonce_counter);
735 ((void) stream_block);
742 static int des_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
749 static int des_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
756 static int des3_set2key_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
763 static int des3_set2key_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
770 static int des3_set3key_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
777 static int des3_set3key_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
784 static void * des_ctx_alloc(
void )
789 static void * des3_ctx_alloc(
void )
794 static void des_ctx_free(
void *ctx )
803 des_crypt_cfb128_wrap,
823 #if defined(POLARSSL_CIPHER_MODE_CBC)
840 des_crypt_cfb128_wrap,
843 des3_set2key_enc_wrap,
844 des3_set2key_dec_wrap,
860 #if defined(POLARSSL_CIPHER_MODE_CBC)
877 des_crypt_cfb128_wrap,
880 des3_set3key_enc_wrap,
881 des3_set3key_dec_wrap,
896 #if defined(POLARSSL_CIPHER_MODE_CBC)
910 #if defined(POLARSSL_BLOWFISH_C)
912 static int blowfish_crypt_ecb_wrap(
void *ctx,
operation_t operation,
913 const unsigned char *input,
unsigned char *output )
918 static int blowfish_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
919 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
921 #if defined(POLARSSL_CIPHER_MODE_CBC)
935 static int blowfish_crypt_cfb64_wrap(
void *ctx,
operation_t operation,
size_t length,
936 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
938 #if defined(POLARSSL_CIPHER_MODE_CFB)
953 static int blowfish_crypt_ctr_wrap(
void *ctx,
size_t length,
954 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
955 const unsigned char *input,
unsigned char *output )
957 #if defined(POLARSSL_CIPHER_MODE_CTR)
959 stream_block, input, output );
964 ((void) nonce_counter);
965 ((void) stream_block);
973 static int blowfish_setkey_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
978 static void * blowfish_ctx_alloc(
void )
983 static void blowfish_ctx_free(
void *ctx )
990 blowfish_crypt_ecb_wrap,
991 blowfish_crypt_cbc_wrap,
992 blowfish_crypt_cfb64_wrap,
993 blowfish_crypt_ctr_wrap,
995 blowfish_setkey_wrap,
996 blowfish_setkey_wrap,
1012 #if defined(POLARSSL_CIPHER_MODE_CBC)
1025 #if defined(POLARSSL_CIPHER_MODE_CFB)
1038 #if defined(POLARSSL_CIPHER_MODE_CTR)
1052 #if defined(POLARSSL_ARC4_C)
1053 static int arc4_crypt_stream_wrap(
void *ctx,
size_t length,
1054 const unsigned char *input,
1055 unsigned char *output )
1060 static int arc4_setkey_wrap(
void *ctx,
const unsigned char *key,
1061 unsigned int key_length )
1064 if( key_length % 8 != 0)
1071 static void * arc4_ctx_alloc(
void )
1076 static void arc4_ctx_free(
void *ctx )
1087 arc4_crypt_stream_wrap,
1106 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1107 static int null_crypt_stream(
void *ctx,
size_t length,
1108 const unsigned char *input,
1109 unsigned char *output )
1112 memmove( output, input, length );
1116 static int null_setkey(
void *ctx,
const unsigned char *key,
1117 unsigned int key_length )
1121 ((void) key_length);
1126 static void * null_ctx_alloc(
void )
1131 static void null_ctx_free(
void *ctx )
1163 #if defined(POLARSSL_AES_C)
1167 #if defined(POLARSSL_CIPHER_MODE_CBC)
1172 #if defined(POLARSSL_CIPHER_MODE_CFB)
1177 #if defined(POLARSSL_CIPHER_MODE_CTR)
1182 #if defined(POLARSSL_GCM_C)
1189 #if defined(POLARSSL_ARC4_C)
1193 #if defined(POLARSSL_BLOWFISH_C)
1195 #if defined(POLARSSL_CIPHER_MODE_CBC)
1198 #if defined(POLARSSL_CIPHER_MODE_CFB)
1201 #if defined(POLARSSL_CIPHER_MODE_CTR)
1206 #if defined(POLARSSL_CAMELLIA_C)
1210 #if defined(POLARSSL_CIPHER_MODE_CBC)
1215 #if defined(POLARSSL_CIPHER_MODE_CFB)
1220 #if defined(POLARSSL_CIPHER_MODE_CTR)
1225 #if defined(POLARSSL_GCM_C)
1232 #if defined(POLARSSL_DES_C)
1236 #if defined(POLARSSL_CIPHER_MODE_CBC)
1243 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1250 #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.
void *(* polarssl_malloc)(size_t len)
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) ...
void(* polarssl_free)(void *ptr)
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