Commit 24c0e848 authored by Paul Bakker's avatar Paul Bakker
Browse files

Merged CBC-as-an-option changes into development

parents 7fb4a79f 92cb1d3a
......@@ -100,6 +100,7 @@ int aes_crypt_ecb( aes_context *ctx,
const unsigned char input[16],
unsigned char output[16] );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/**
* \brief AES-CBC buffer encryption/decryption
* Length should be a multiple of the block
......@@ -120,6 +121,7 @@ int aes_crypt_cbc( aes_context *ctx,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CBC */
/**
* \brief AES-CFB128 buffer encryption/decryption.
......
......@@ -92,6 +92,7 @@ int blowfish_crypt_ecb( blowfish_context *ctx,
const unsigned char input[BLOWFISH_BLOCKSIZE],
unsigned char output[BLOWFISH_BLOCKSIZE] );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/**
* \brief Blowfish-CBC buffer encryption/decryption
* Length should be a multiple of the block
......@@ -112,7 +113,9 @@ int blowfish_crypt_cbc( blowfish_context *ctx,
unsigned char iv[BLOWFISH_BLOCKSIZE],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/**
* \brief Blowfish CFB buffer encryption/decryption.
*
......@@ -133,7 +136,9 @@ int blowfish_crypt_cfb64( blowfish_context *ctx,
unsigned char iv[BLOWFISH_BLOCKSIZE],
const unsigned char *input,
unsigned char *output );
#endif /*POLARSSL_CIPHER_MODE_CFB */
#if defined(POLARSSL_CIPHER_MODE_CTR)
/**
* \brief Blowfish-CTR buffer encryption/decryption
*
......@@ -159,6 +164,7 @@ int blowfish_crypt_ctr( blowfish_context *ctx,
unsigned char stream_block[BLOWFISH_BLOCKSIZE],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CTR */
#ifdef __cplusplus
}
......
......@@ -99,6 +99,7 @@ int camellia_crypt_ecb( camellia_context *ctx,
const unsigned char input[16],
unsigned char output[16] );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/**
* \brief CAMELLIA-CBC buffer encryption/decryption
* Length should be a multiple of the block
......@@ -119,7 +120,9 @@ int camellia_crypt_cbc( camellia_context *ctx,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/**
* \brief CAMELLIA-CFB128 buffer encryption/decryption
*
......@@ -144,7 +147,9 @@ int camellia_crypt_cfb128( camellia_context *ctx,
unsigned char iv[16],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CFB */
#if defined(POLARSSL_CIPHER_MODE_CTR)
/**
* \brief CAMELLIA-CTR buffer encryption/decryption
*
......@@ -174,6 +179,7 @@ int camellia_crypt_ctr( camellia_context *ctx,
unsigned char stream_block[16],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CTR */
#ifdef __cplusplus
}
......
......@@ -36,6 +36,10 @@
#define POLARSSL_CIPHER_MODE_AEAD
#endif
#if defined(POLARSSL_CIPHER_MODE_CBC)
#define POLARSSL_CIPHER_MODE_WITH_PADDING
#endif
#include <string.h>
#if defined(_MSC_VER) && !defined(inline)
......@@ -462,6 +466,7 @@ static inline operation_t cipher_get_operation( const cipher_context_t *ctx )
int cipher_setkey( cipher_context_t *ctx, const unsigned char *key, int key_length,
const operation_t operation );
#if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
/**
* \brief Set padding mode, for cipher modes that use padding.
* (Default: PKCS7 padding.)
......@@ -475,6 +480,7 @@ int cipher_setkey( cipher_context_t *ctx, const unsigned char *key, int key_leng
* does not support padding.
*/
int cipher_set_padding_mode( cipher_context_t *ctx, cipher_padding_t mode );
#endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
/**
* \brief Set the initialization vector (IV) or nonce
......
......@@ -42,9 +42,11 @@ extern const cipher_info_t aes_128_ecb_info;
extern const cipher_info_t aes_192_ecb_info;
extern const cipher_info_t aes_256_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
extern const cipher_info_t aes_128_cbc_info;
extern const cipher_info_t aes_192_cbc_info;
extern const cipher_info_t aes_256_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
extern const cipher_info_t aes_128_cfb128_info;
......@@ -72,9 +74,11 @@ extern const cipher_info_t camellia_128_ecb_info;
extern const cipher_info_t camellia_192_ecb_info;
extern const cipher_info_t camellia_256_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
extern const cipher_info_t camellia_128_cbc_info;
extern const cipher_info_t camellia_192_cbc_info;
extern const cipher_info_t camellia_256_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
extern const cipher_info_t camellia_128_cfb128_info;
......@@ -96,15 +100,19 @@ extern const cipher_info_t des_ecb_info;
extern const cipher_info_t des_ede_ecb_info;
extern const cipher_info_t des_ede3_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
extern const cipher_info_t des_cbc_info;
extern const cipher_info_t des_ede_cbc_info;
extern const cipher_info_t des_ede3_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#endif /* defined(POLARSSL_DES_C) */
#if defined(POLARSSL_BLOWFISH_C)
extern const cipher_info_t blowfish_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
extern const cipher_info_t blowfish_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
extern const cipher_info_t blowfish_cfb64_info;
......
......@@ -152,6 +152,13 @@
#define POLARSSL_AES_ROM_TABLES
*/
/**
* \def POLARSSL_CIPHER_MODE_CBC
*
* Enable Cipher Block Chaining mode (CBC) for symmetric ciphers.
*/
#define POLARSSL_CIPHER_MODE_CBC
/**
* \def POLARSSL_CIPHER_MODE_CFB
*
......@@ -626,6 +633,7 @@
*
* Requires: POLARSSL_AES_C
* POLARSSL_SHA256_C
* POLARSSL_CIPHER_MODE_CBC
*
* Comment this macro to disable support for SSL session tickets
*/
......@@ -1599,7 +1607,8 @@
#endif
#if defined(POLARSSL_SSL_SESSION_TICKETS) && defined(POLARSSL_SSL_TLS_C) && \
( !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA256_C) )
( !defined(POLARSSL_AES_C) || !defined(POLARSSL_SHA256_C) || \
!defined(POLARSSL_CIPHER_MODE_CBC) )
#error "POLARSSL_SSL_SESSION_TICKETS_C defined, but not all prerequisites"
#endif
......
......@@ -177,6 +177,7 @@ int des_crypt_ecb( des_context *ctx,
const unsigned char input[8],
unsigned char output[8] );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/**
* \brief DES-CBC buffer encryption/decryption
*
......@@ -193,6 +194,7 @@ int des_crypt_cbc( des_context *ctx,
unsigned char iv[8],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CBC */
/**
* \brief 3DES-ECB block encryption/decryption
......@@ -207,6 +209,7 @@ int des3_crypt_ecb( des3_context *ctx,
const unsigned char input[8],
unsigned char output[8] );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/**
* \brief 3DES-CBC buffer encryption/decryption
*
......@@ -225,6 +228,7 @@ int des3_crypt_cbc( des3_context *ctx,
unsigned char iv[8],
const unsigned char *input,
unsigned char *output );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#ifdef __cplusplus
}
......
......@@ -83,6 +83,7 @@ int xtea_crypt_ecb( xtea_context *ctx,
const unsigned char input[8],
unsigned char output[8] );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/**
* \brief XTEA CBC cipher function
*
......@@ -102,6 +103,7 @@ int xtea_crypt_cbc( xtea_context *ctx,
unsigned char iv[8],
const unsigned char *input,
unsigned char *output);
#endif /* POLARSSL_CIPHER_MODE_CBC */
#ifdef __cplusplus
}
......
......@@ -769,6 +769,7 @@ int aes_crypt_ecb( aes_context *ctx,
return( 0 );
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
/*
* AES-CBC buffer encryption/decryption
*/
......@@ -832,6 +833,7 @@ int aes_crypt_cbc( aes_context *ctx,
return( 0 );
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/*
......@@ -947,6 +949,7 @@ static const unsigned char aes_test_ecb_enc[3][16] =
0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
static const unsigned char aes_test_cbc_dec[3][16] =
{
{ 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
......@@ -966,6 +969,7 @@ static const unsigned char aes_test_cbc_enc[3][16] =
{ 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
};
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/*
......@@ -1104,8 +1108,10 @@ int aes_self_test( int verbose )
int i, j, u, v;
unsigned char key[32];
unsigned char buf[64];
unsigned char prv[16];
unsigned char iv[16];
#if defined(POLARSSL_CIPHER_MODE_CBC)
unsigned char prv[16];
#endif
#if defined(POLARSSL_CIPHER_MODE_CTR) || defined(POLARSSL_CIPHER_MODE_CFB)
size_t offset;
#endif
......@@ -1170,6 +1176,7 @@ int aes_self_test( int verbose )
if( verbose != 0 )
printf( "\n" );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/*
* CBC mode
*/
......@@ -1231,6 +1238,7 @@ int aes_self_test( int verbose )
if( verbose != 0 )
printf( "\n" );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/*
......
......@@ -233,6 +233,7 @@ int blowfish_crypt_ecb( blowfish_context *ctx,
return( 0 );
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
/*
* Blowfish-CBC buffer encryption/decryption
*/
......@@ -284,6 +285,7 @@ int blowfish_crypt_cbc( blowfish_context *ctx,
return( 0 );
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/*
......
......@@ -523,6 +523,7 @@ int camellia_crypt_ecb( camellia_context *ctx,
return( 0 );
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
/*
* Camellia-CBC buffer encryption/decryption
*/
......@@ -574,6 +575,7 @@ int camellia_crypt_cbc( camellia_context *ctx,
return( 0 );
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
/*
......@@ -732,6 +734,7 @@ static const unsigned char camellia_test_ecb_cipher[3][CAMELLIA_TESTS_ECB][16] =
}
};
#if defined(POLARSSL_CIPHER_MODE_CBC)
#define CAMELLIA_TESTS_CBC 3
static const unsigned char camellia_test_cbc_key[3][32] =
......@@ -793,6 +796,7 @@ static const unsigned char camellia_test_cbc_cipher[3][CAMELLIA_TESTS_CBC][16] =
0x33, 0x30, 0xCD, 0xF1, 0xB1, 0x86, 0x0A, 0x83 }
}
};
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CTR)
/*
......@@ -867,7 +871,9 @@ int camellia_self_test( int verbose )
unsigned char buf[64];
unsigned char src[16];
unsigned char dst[16];
#if defined(POLARSSL_CIPHER_MODE_CBC)
unsigned char iv[16];
#endif
#if defined(POLARSSL_CIPHER_MODE_CTR)
size_t offset, len;
unsigned char nonce_counter[16];
......@@ -917,6 +923,7 @@ int camellia_self_test( int verbose )
if( verbose != 0 )
printf( "\n" );
#if defined(POLARSSL_CIPHER_MODE_CBC)
/*
* CBC mode
*/
......@@ -965,6 +972,7 @@ int camellia_self_test( int verbose )
if( verbose != 0 )
printf( "passed\n" );
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
if( verbose != 0 )
printf( "\n" );
......
......@@ -54,9 +54,12 @@ static const int supported_ciphers[] = {
POLARSSL_CIPHER_AES_128_ECB,
POLARSSL_CIPHER_AES_192_ECB,
POLARSSL_CIPHER_AES_256_ECB,
#if defined(POLARSSL_CIPHER_MODE_CBC)
POLARSSL_CIPHER_AES_128_CBC,
POLARSSL_CIPHER_AES_192_CBC,
POLARSSL_CIPHER_AES_256_CBC,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
POLARSSL_CIPHER_AES_128_CFB128,
......@@ -86,9 +89,12 @@ static const int supported_ciphers[] = {
POLARSSL_CIPHER_CAMELLIA_128_ECB,
POLARSSL_CIPHER_CAMELLIA_192_ECB,
POLARSSL_CIPHER_CAMELLIA_256_ECB,
#if defined(POLARSSL_CIPHER_MODE_CBC)
POLARSSL_CIPHER_CAMELLIA_128_CBC,
POLARSSL_CIPHER_CAMELLIA_192_CBC,
POLARSSL_CIPHER_CAMELLIA_256_CBC,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
POLARSSL_CIPHER_CAMELLIA_128_CFB128,
......@@ -108,14 +114,20 @@ static const int supported_ciphers[] = {
POLARSSL_CIPHER_DES_ECB,
POLARSSL_CIPHER_DES_EDE_ECB,
POLARSSL_CIPHER_DES_EDE3_ECB,
#if defined(POLARSSL_CIPHER_MODE_CBC)
POLARSSL_CIPHER_DES_CBC,
POLARSSL_CIPHER_DES_EDE_CBC,
POLARSSL_CIPHER_DES_EDE3_CBC,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#endif /* defined(POLARSSL_DES_C) */
#if defined(POLARSSL_BLOWFISH_C)
POLARSSL_CIPHER_BLOWFISH_ECB,
#if defined(POLARSSL_CIPHER_MODE_CBC)
POLARSSL_CIPHER_BLOWFISH_CBC,
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
POLARSSL_CIPHER_BLOWFISH_CFB64,
......@@ -152,12 +164,14 @@ const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type )
case POLARSSL_CIPHER_AES_256_ECB:
return &aes_256_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
case POLARSSL_CIPHER_AES_128_CBC:
return &aes_128_cbc_info;
case POLARSSL_CIPHER_AES_192_CBC:
return &aes_192_cbc_info;
case POLARSSL_CIPHER_AES_256_CBC:
return &aes_256_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
case POLARSSL_CIPHER_AES_128_CFB128:
......@@ -196,12 +210,14 @@ const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type )
case POLARSSL_CIPHER_CAMELLIA_256_ECB:
return &camellia_256_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
case POLARSSL_CIPHER_CAMELLIA_128_CBC:
return &camellia_128_cbc_info;
case POLARSSL_CIPHER_CAMELLIA_192_CBC:
return &camellia_192_cbc_info;
case POLARSSL_CIPHER_CAMELLIA_256_CBC:
return &camellia_256_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
case POLARSSL_CIPHER_CAMELLIA_128_CFB128:
......@@ -231,12 +247,14 @@ const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type )
case POLARSSL_CIPHER_DES_EDE3_ECB:
return &des_ede3_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
case POLARSSL_CIPHER_DES_CBC:
return &des_cbc_info;
case POLARSSL_CIPHER_DES_EDE_CBC:
return &des_ede_cbc_info;
case POLARSSL_CIPHER_DES_EDE3_CBC:
return &des_ede3_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#endif
#if defined(POLARSSL_ARC4_C)
......@@ -248,8 +266,10 @@ const cipher_info_t *cipher_info_from_type( const cipher_type_t cipher_type )
case POLARSSL_CIPHER_BLOWFISH_ECB:
return &blowfish_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
case POLARSSL_CIPHER_BLOWFISH_CBC:
return &blowfish_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
case POLARSSL_CIPHER_BLOWFISH_CFB64:
......@@ -280,12 +300,14 @@ const cipher_info_t *cipher_info_from_string( const char *cipher_name )
/* Get the appropriate cipher information */
#if defined(POLARSSL_CAMELLIA_C)
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( !strcasecmp( "CAMELLIA-128-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_128_CBC );
if( !strcasecmp( "CAMELLIA-192-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_192_CBC );
if( !strcasecmp( "CAMELLIA-256-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_CAMELLIA_256_CBC );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( !strcasecmp( "CAMELLIA-128-CFB128", cipher_name ) )
......@@ -307,12 +329,14 @@ const cipher_info_t *cipher_info_from_string( const char *cipher_name )
#endif
#if defined(POLARSSL_AES_C)
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( !strcasecmp( "AES-128-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_AES_128_CBC );
if( !strcasecmp( "AES-192-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_AES_192_CBC );
if( !strcasecmp( "AES-256-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_AES_256_CBC );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( !strcasecmp( "AES-128-CFB128", cipher_name ) )
......@@ -348,17 +372,21 @@ const cipher_info_t *cipher_info_from_string( const char *cipher_name )
#endif
#if defined(POLARSSL_DES_C)
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( !strcasecmp( "DES-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_DES_CBC );
if( !strcasecmp( "DES-EDE-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_DES_EDE_CBC );
if( !strcasecmp( "DES-EDE3-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_DES_EDE3_CBC );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#endif
#if defined(POLARSSL_BLOWFISH_C)
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( !strcasecmp( "BLOWFISH-CBC", cipher_name ) )
return cipher_info_from_type( POLARSSL_CIPHER_BLOWFISH_CBC );
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( !strcasecmp( "BLOWFISH-CFB64", cipher_name ) )
......@@ -396,6 +424,7 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
return &aes_256_ecb_info;
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( mode == POLARSSL_MODE_CBC )
{
if( key_length == 128 )
......@@ -405,6 +434,7 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
if( key_length == 256 )
return &aes_256_cbc_info;
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( mode == POLARSSL_MODE_CFB )
......@@ -457,6 +487,7 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
return &camellia_256_ecb_info;
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( mode == POLARSSL_MODE_CBC )
{
if( key_length == 128 )
......@@ -466,6 +497,7 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
if( key_length == 256 )
return &camellia_256_cbc_info;
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( mode == POLARSSL_MODE_CFB )
......@@ -499,8 +531,10 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
if( mode == POLARSSL_MODE_ECB )
return &des_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( mode == POLARSSL_MODE_CBC )
return &des_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
}
if( cipher_id == POLARSSL_CIPHER_ID_3DES )
......@@ -513,6 +547,7 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
return &des_ede3_ecb_info;
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( mode == POLARSSL_MODE_CBC )
{
if( key_length == 128 )
......@@ -520,6 +555,7 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
if( key_length == 192 )
return &des_ede3_cbc_info;
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
}
#endif
......@@ -535,8 +571,10 @@ const cipher_info_t *cipher_info_from_values( const cipher_id_t cipher_id,
if( mode == POLARSSL_MODE_ECB )
return &blowfish_ecb_info;
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( mode == POLARSSL_MODE_CBC )
return &blowfish_cbc_info;
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( mode == POLARSSL_MODE_CFB )
......@@ -570,6 +608,7 @@ int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info )
ctx->cipher_info = cipher_info;
#if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
/*
* Ignore possible errors caused by a cipher mode that doesn't use padding
*/
......@@ -578,6 +617,7 @@ int cipher_init_ctx( cipher_context_t *ctx, const cipher_info_t *cipher_info )
#else
(void) cipher_set_padding_mode( ctx, POLARSSL_PADDING_NONE );
#endif
#endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
return 0;
}
......@@ -671,7 +711,6 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
unsigned char *output, size_t *olen )
{
int ret;
size_t copy_len = 0;
*olen = 0;
......@@ -710,8 +749,11 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
return POLARSSL_ERR_CIPHER_BAD_INPUT_DATA;
}
#if defined(POLARSSL_CIPHER_MODE_CBC)
if( ctx->cipher_info->mode == POLARSSL_MODE_CBC )
{
size_t copy_len = 0;
/*
* If there is not enough data for a full block, cache it.
*/
......@@ -784,6 +826,7 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
return 0;
}
#endif /* POLARSSL_CIPHER_MODE_CBC */
#if defined(POLARSSL_CIPHER_MODE_CFB)
if( ctx->cipher_info->mode == POLARSSL_MODE_CFB )
......@@ -835,6 +878,7 @@ int cipher_update( cipher_context_t *ctx, const unsigned char *input, size_t ile
return POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE;
}
#if defined(POLARSSL_CIPHER_MODE_WITH_PADDING)
#if defined(POLARSSL_CIPHER_PADDING_PKCS7)
/*
* PKCS7 (and PKCS5) padding: fill with ll bytes, with ll = padding_len
......@@ -990,12 +1034,11 @@ static int get_no_padding( unsigned char *input, size_t input_len,
return 0;
}
#endif /* POLARSSL_CIPHER_MODE_WITH_PADDING */
int cipher_finish( cipher_context_t *ctx,
unsigned char *output, size_t *olen )
{
int ret = 0;
if( NULL == ctx || NULL == ctx->cipher_info || NULL == olen )