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_AES_C)
71 static int aes_crypt_ecb_wrap(
void *ctx,
operation_t operation,
72 const unsigned char *input,
unsigned char *output )
77 static int aes_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
78 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
80 #if defined(POLARSSL_CIPHER_MODE_CBC)
94 static int aes_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
size_t length,
95 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
97 #if defined(POLARSSL_CIPHER_MODE_CFB)
112 static int aes_crypt_ctr_wrap(
void *ctx,
size_t length,
113 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
114 const unsigned char *input,
unsigned char *output )
116 #if defined(POLARSSL_CIPHER_MODE_CTR)
118 stream_block, input, output );
123 ((void) nonce_counter);
124 ((void) stream_block);
132 static int aes_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
137 static int aes_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
142 static void * aes_ctx_alloc(
void )
147 static void aes_ctx_free(
void *ctx )
156 aes_crypt_cfb128_wrap,
198 #if defined(POLARSSL_CIPHER_MODE_CBC)
233 #if defined(POLARSSL_CIPHER_MODE_CFB)
268 #if defined(POLARSSL_CIPHER_MODE_CTR)
303 #if defined(POLARSSL_GCM_C)
304 static void *gcm_ctx_alloc(
void )
309 static void gcm_ctx_free(
void *ctx )
315 static int gcm_aes_setkey_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
370 #if defined(POLARSSL_CAMELLIA_C)
372 static int camellia_crypt_ecb_wrap(
void *ctx,
operation_t operation,
373 const unsigned char *input,
unsigned char *output )
378 static int camellia_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
379 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
381 #if defined(POLARSSL_CIPHER_MODE_CBC)
395 static int camellia_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
size_t length,
396 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
398 #if defined(POLARSSL_CIPHER_MODE_CFB)
413 static int camellia_crypt_ctr_wrap(
void *ctx,
size_t length,
414 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
415 const unsigned char *input,
unsigned char *output )
417 #if defined(POLARSSL_CIPHER_MODE_CTR)
419 stream_block, input, output );
424 ((void) nonce_counter);
425 ((void) stream_block);
433 static int camellia_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
438 static int camellia_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
443 static void * camellia_ctx_alloc(
void )
448 static void camellia_ctx_free(
void *ctx )
455 camellia_crypt_ecb_wrap,
456 camellia_crypt_cbc_wrap,
457 camellia_crypt_cfb128_wrap,
458 camellia_crypt_ctr_wrap,
460 camellia_setkey_enc_wrap,
461 camellia_setkey_dec_wrap,
499 #if defined(POLARSSL_CIPHER_MODE_CBC)
534 #if defined(POLARSSL_CIPHER_MODE_CFB)
539 "CAMELLIA-128-CFB128",
550 "CAMELLIA-192-CFB128",
561 "CAMELLIA-256-CFB128",
569 #if defined(POLARSSL_CIPHER_MODE_CTR)
606 #if defined(POLARSSL_DES_C)
608 static int des_crypt_ecb_wrap(
void *ctx,
operation_t operation,
609 const unsigned char *input,
unsigned char *output )
615 static int des3_crypt_ecb_wrap(
void *ctx,
operation_t operation,
616 const unsigned char *input,
unsigned char *output )
622 static int des_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
623 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
625 #if defined(POLARSSL_CIPHER_MODE_CBC)
639 static int des3_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
640 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
642 #if defined(POLARSSL_CIPHER_MODE_CBC)
656 static int des_crypt_cfb128_wrap(
void *ctx,
operation_t operation,
size_t length,
657 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
670 static int des_crypt_ctr_wrap(
void *ctx,
size_t length,
671 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
672 const unsigned char *input,
unsigned char *output )
677 ((void) nonce_counter);
678 ((void) stream_block);
685 static int des_setkey_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
692 static int des_setkey_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
699 static int des3_set2key_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
706 static int des3_set2key_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
713 static int des3_set3key_dec_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
720 static int des3_set3key_enc_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
727 static void * des_ctx_alloc(
void )
732 static void * des3_ctx_alloc(
void )
737 static void des_ctx_free(
void *ctx )
746 des_crypt_cfb128_wrap,
766 #if defined(POLARSSL_CIPHER_MODE_CBC)
783 des_crypt_cfb128_wrap,
786 des3_set2key_enc_wrap,
787 des3_set2key_dec_wrap,
803 #if defined(POLARSSL_CIPHER_MODE_CBC)
820 des_crypt_cfb128_wrap,
823 des3_set3key_enc_wrap,
824 des3_set3key_dec_wrap,
839 #if defined(POLARSSL_CIPHER_MODE_CBC)
853 #if defined(POLARSSL_BLOWFISH_C)
855 static int blowfish_crypt_ecb_wrap(
void *ctx,
operation_t operation,
856 const unsigned char *input,
unsigned char *output )
861 static int blowfish_crypt_cbc_wrap(
void *ctx,
operation_t operation,
size_t length,
862 unsigned char *iv,
const unsigned char *input,
unsigned char *output )
864 #if defined(POLARSSL_CIPHER_MODE_CBC)
878 static int blowfish_crypt_cfb64_wrap(
void *ctx,
operation_t operation,
size_t length,
879 size_t *iv_off,
unsigned char *iv,
const unsigned char *input,
unsigned char *output )
881 #if defined(POLARSSL_CIPHER_MODE_CFB)
896 static int blowfish_crypt_ctr_wrap(
void *ctx,
size_t length,
897 size_t *nc_off,
unsigned char *nonce_counter,
unsigned char *stream_block,
898 const unsigned char *input,
unsigned char *output )
900 #if defined(POLARSSL_CIPHER_MODE_CTR)
902 stream_block, input, output );
907 ((void) nonce_counter);
908 ((void) stream_block);
916 static int blowfish_setkey_wrap(
void *ctx,
const unsigned char *key,
unsigned int key_length )
921 static void * blowfish_ctx_alloc(
void )
926 static void blowfish_ctx_free(
void *ctx )
933 blowfish_crypt_ecb_wrap,
934 blowfish_crypt_cbc_wrap,
935 blowfish_crypt_cfb64_wrap,
936 blowfish_crypt_ctr_wrap,
938 blowfish_setkey_wrap,
939 blowfish_setkey_wrap,
955 #if defined(POLARSSL_CIPHER_MODE_CBC)
968 #if defined(POLARSSL_CIPHER_MODE_CFB)
981 #if defined(POLARSSL_CIPHER_MODE_CTR)
995 #if defined(POLARSSL_ARC4_C)
996 static int arc4_crypt_stream_wrap(
void *ctx,
size_t length,
997 const unsigned char *input,
998 unsigned char *output )
1003 static int arc4_setkey_wrap(
void *ctx,
const unsigned char *key,
1004 unsigned int key_length )
1007 if( key_length % 8 != 0)
1014 static void * arc4_ctx_alloc(
void )
1019 static void arc4_ctx_free(
void *ctx )
1030 arc4_crypt_stream_wrap,
1049 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1050 static int null_crypt_stream(
void *ctx,
size_t length,
1051 const unsigned char *input,
1052 unsigned char *output )
1055 memmove( output, input, length );
1059 static int null_setkey(
void *ctx,
const unsigned char *key,
1060 unsigned int key_length )
1064 ((void) key_length);
1069 static void * null_ctx_alloc(
void )
1074 static void null_ctx_free(
void *ctx )
1106 #if defined(POLARSSL_AES_C)
1110 #if defined(POLARSSL_CIPHER_MODE_CBC)
1115 #if defined(POLARSSL_CIPHER_MODE_CFB)
1120 #if defined(POLARSSL_CIPHER_MODE_CTR)
1125 #if defined(POLARSSL_GCM_C)
1132 #if defined(POLARSSL_ARC4_C)
1136 #if defined(POLARSSL_BLOWFISH_C)
1138 #if defined(POLARSSL_CIPHER_MODE_CBC)
1141 #if defined(POLARSSL_CIPHER_MODE_CFB)
1144 #if defined(POLARSSL_CIPHER_MODE_CTR)
1149 #if defined(POLARSSL_CAMELLIA_C)
1152 #if defined(POLARSSL_CIPHER_MODE_CBC)
1157 #if defined(POLARSSL_CIPHER_MODE_CFB)
1162 #if defined(POLARSSL_CIPHER_MODE_CTR)
1169 #if defined(POLARSSL_DES_C)
1173 #if defined(POLARSSL_CIPHER_MODE_CBC)
1180 #if defined(POLARSSL_CIPHER_NULL_CIPHER)
1187 #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