Rename key_length in cipher_info
This commit is contained in:
parent
b8186a5e54
commit
898e0aa210
@ -21,6 +21,8 @@ API Changes
|
||||
Some names have been further changed to make them more consistent.
|
||||
Migration helpers scripts/rename.pl and include/mbedlts/compat-1.3.h are
|
||||
provided. Full list of renamings in scripts/data_files/rename-1.3-2.0.txt
|
||||
* Renamings of fields inside structures, not covered by the previous list:
|
||||
cipher_info.key_length -> key_bitlen
|
||||
* Headers are now found in the 'mbedtls' directory (previously 'polarssl').
|
||||
* The following _init() functions that could return errors have
|
||||
been split into an _init() that returns void and another function that
|
||||
|
@ -191,7 +191,7 @@ typedef struct {
|
||||
|
||||
/** Cipher key length, in bits (default length for variable sized ciphers)
|
||||
* (Includes parity bits for ciphers like DES) */
|
||||
unsigned int key_length;
|
||||
unsigned int key_bitlen;
|
||||
|
||||
/** Name of the cipher */
|
||||
const char * name;
|
||||
@ -219,7 +219,7 @@ typedef struct {
|
||||
const mbedtls_cipher_info_t *cipher_info;
|
||||
|
||||
/** Key length to use */
|
||||
int key_length;
|
||||
int key_bitlen;
|
||||
|
||||
/** Operation that the context's key has been initialised for */
|
||||
mbedtls_operation_t operation;
|
||||
@ -420,7 +420,7 @@ static inline int mbedtls_cipher_get_key_size( const mbedtls_cipher_context_t *c
|
||||
if( NULL == ctx || NULL == ctx->cipher_info )
|
||||
return MBEDTLS_KEY_LENGTH_NONE;
|
||||
|
||||
return ctx->cipher_info->key_length;
|
||||
return ctx->cipher_info->key_bitlen;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -79,11 +79,11 @@ struct mbedtls_cipher_base_t
|
||||
|
||||
/** Set key for encryption purposes */
|
||||
int (*setkey_enc_func)( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length );
|
||||
unsigned int key_bitlen );
|
||||
|
||||
/** Set key for decryption purposes */
|
||||
int (*setkey_dec_func)( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length);
|
||||
unsigned int key_bitlen);
|
||||
|
||||
/** Allocate a new context */
|
||||
void * (*ctx_alloc_func)( void );
|
||||
|
@ -71,7 +71,7 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
|
||||
* \param salt Salt to use when generating key
|
||||
* \param slen Length of salt
|
||||
* \param iteration_count Iteration count
|
||||
* \param key_length Length of generated key
|
||||
* \param key_length Length of generated key in bytes
|
||||
* \param output Generated key. Must be at least as big as key_length
|
||||
*
|
||||
* \returns 0 on success, or a MBEDTLS_ERR_XXX code if verification fails.
|
||||
|
@ -111,7 +111,7 @@ const mbedtls_cipher_info_t *mbedtls_cipher_info_from_values( const mbedtls_ciph
|
||||
|
||||
for( def = mbedtls_cipher_definitions; def->info != NULL; def++ )
|
||||
if( def->info->base->cipher == cipher_id &&
|
||||
def->info->key_length == (unsigned) key_bitlen &&
|
||||
def->info->key_bitlen == (unsigned) key_bitlen &&
|
||||
def->info->mode == mode )
|
||||
return( def->info );
|
||||
|
||||
@ -167,12 +167,12 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *k
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ctx->cipher_info->flags & MBEDTLS_CIPHER_VARIABLE_KEY_LEN ) == 0 &&
|
||||
(int) ctx->cipher_info->key_length != key_bitlen )
|
||||
(int) ctx->cipher_info->key_bitlen != key_bitlen )
|
||||
{
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
ctx->key_length = key_bitlen;
|
||||
ctx->key_bitlen = key_bitlen;
|
||||
ctx->operation = operation;
|
||||
|
||||
/*
|
||||
@ -183,12 +183,12 @@ int mbedtls_cipher_setkey( mbedtls_cipher_context_t *ctx, const unsigned char *k
|
||||
MBEDTLS_MODE_CTR == ctx->cipher_info->mode )
|
||||
{
|
||||
return ctx->cipher_info->base->setkey_enc_func( ctx->cipher_ctx, key,
|
||||
ctx->key_length );
|
||||
ctx->key_bitlen );
|
||||
}
|
||||
|
||||
if( MBEDTLS_DECRYPT == operation )
|
||||
return ctx->cipher_info->base->setkey_dec_func( ctx->cipher_ctx, key,
|
||||
ctx->key_length );
|
||||
ctx->key_bitlen );
|
||||
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
}
|
||||
|
@ -140,15 +140,15 @@ static int aes_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
static int aes_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_length );
|
||||
return mbedtls_aes_setkey_dec( (mbedtls_aes_context *) ctx, key, key_bitlen );
|
||||
}
|
||||
|
||||
static int aes_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_length );
|
||||
return mbedtls_aes_setkey_enc( (mbedtls_aes_context *) ctx, key, key_bitlen );
|
||||
}
|
||||
|
||||
static void * aes_ctx_alloc( void )
|
||||
@ -330,10 +330,10 @@ static const mbedtls_cipher_info_t aes_256_ctr_info = {
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
static int gcm_aes_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
|
||||
key, key_length );
|
||||
key, key_bitlen );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t gcm_aes_info = {
|
||||
@ -393,10 +393,10 @@ static const mbedtls_cipher_info_t aes_256_gcm_info = {
|
||||
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
|
||||
key, key_length );
|
||||
key, key_bitlen );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t ccm_aes_info = {
|
||||
@ -496,15 +496,15 @@ static int camellia_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
static int camellia_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_length );
|
||||
return mbedtls_camellia_setkey_dec( (mbedtls_camellia_context *) ctx, key, key_bitlen );
|
||||
}
|
||||
|
||||
static int camellia_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_length );
|
||||
return mbedtls_camellia_setkey_enc( (mbedtls_camellia_context *) ctx, key, key_bitlen );
|
||||
}
|
||||
|
||||
static void * camellia_ctx_alloc( void )
|
||||
@ -687,10 +687,10 @@ static const mbedtls_cipher_info_t camellia_256_ctr_info = {
|
||||
|
||||
#if defined(MBEDTLS_GCM_C)
|
||||
static int gcm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_gcm_setkey( (mbedtls_gcm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
|
||||
key, key_length );
|
||||
key, key_bitlen );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t gcm_camellia_info = {
|
||||
@ -750,10 +750,10 @@ static const mbedtls_cipher_info_t camellia_256_gcm_info = {
|
||||
|
||||
#if defined(MBEDTLS_CCM_C)
|
||||
static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
|
||||
key, key_length );
|
||||
key, key_bitlen );
|
||||
}
|
||||
|
||||
static const mbedtls_cipher_base_t ccm_camellia_info = {
|
||||
@ -848,49 +848,49 @@ static int des3_crypt_cbc_wrap( void *ctx, mbedtls_operation_t operation, size_t
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CBC */
|
||||
|
||||
static int des_setkey_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return mbedtls_des_setkey_dec( (mbedtls_des_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des_setkey_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return mbedtls_des_setkey_enc( (mbedtls_des_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set2key_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return mbedtls_des3_set2key_dec( (mbedtls_des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set2key_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return mbedtls_des3_set2key_enc( (mbedtls_des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set3key_dec_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return mbedtls_des3_set3key_dec( (mbedtls_des3_context *) ctx, key );
|
||||
}
|
||||
|
||||
static int des3_set3key_enc_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return mbedtls_des3_set3key_enc( (mbedtls_des3_context *) ctx, key );
|
||||
}
|
||||
@ -1107,9 +1107,9 @@ static int blowfish_crypt_ctr_wrap( void *ctx, size_t length, size_t *nc_off,
|
||||
#endif /* MBEDTLS_CIPHER_MODE_CTR */
|
||||
|
||||
static int blowfish_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_length );
|
||||
return mbedtls_blowfish_setkey( (mbedtls_blowfish_context *) ctx, key, key_bitlen );
|
||||
}
|
||||
|
||||
static void * blowfish_ctx_alloc( void )
|
||||
@ -1212,13 +1212,13 @@ static int arc4_crypt_stream_wrap( void *ctx, size_t length,
|
||||
}
|
||||
|
||||
static int arc4_setkey_wrap( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
/* we get key_length in bits, arc4 expects it in bytes */
|
||||
if( key_length % 8 != 0 )
|
||||
/* we get key_bitlen in bits, arc4 expects it in bytes */
|
||||
if( key_bitlen % 8 != 0 )
|
||||
return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA );
|
||||
|
||||
mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_length / 8 );
|
||||
mbedtls_arc4_setup( (mbedtls_arc4_context *) ctx, key, key_bitlen / 8 );
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
@ -1285,11 +1285,11 @@ static int null_crypt_stream( void *ctx, size_t length,
|
||||
}
|
||||
|
||||
static int null_setkey( void *ctx, const unsigned char *key,
|
||||
unsigned int key_length )
|
||||
unsigned int key_bitlen )
|
||||
{
|
||||
((void) ctx);
|
||||
((void) key);
|
||||
((void) key_length);
|
||||
((void) key_bitlen);
|
||||
|
||||
return( 0 );
|
||||
}
|
||||
|
@ -184,7 +184,7 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode,
|
||||
if( cipher_info == NULL )
|
||||
return( MBEDTLS_ERR_PKCS12_FEATURE_UNAVAILABLE );
|
||||
|
||||
keylen = cipher_info->key_length / 8;
|
||||
keylen = cipher_info->key_bitlen / 8;
|
||||
|
||||
if( ( ret = pkcs12_pbe_derive_key_iv( pbe_params, md_type, pwd, pwdlen,
|
||||
key, keylen,
|
||||
|
@ -176,7 +176,7 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode,
|
||||
* The value of keylen from pkcs5_parse_pbkdf2_params() is ignored
|
||||
* since it is optional and we don't know if it was set or not
|
||||
*/
|
||||
keylen = cipher_info->key_length / 8;
|
||||
keylen = cipher_info->key_bitlen / 8;
|
||||
|
||||
if( enc_scheme_params.tag != MBEDTLS_ASN1_OCTET_STRING ||
|
||||
enc_scheme_params.len != cipher_info->iv_size )
|
||||
|
@ -143,7 +143,7 @@ int mbedtls_ssl_ticket_setup( mbedtls_ssl_ticket_context *ctx,
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
}
|
||||
|
||||
if( cipher_info->key_length > 8 * MAX_KEY_BYTES )
|
||||
if( cipher_info->key_bitlen > 8 * MAX_KEY_BYTES )
|
||||
return( MBEDTLS_ERR_SSL_BAD_INPUT_DATA );
|
||||
|
||||
if( ( ret = mbedtls_cipher_setup( &ctx->keys[0].ctx, cipher_info ) ) != 0 ||
|
||||
|
@ -677,7 +677,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
||||
* Determine the appropriate key, IV and MAC length.
|
||||
*/
|
||||
|
||||
transform->keylen = cipher_info->key_length / 8;
|
||||
transform->keylen = cipher_info->key_bitlen / 8;
|
||||
|
||||
if( cipher_info->mode == MBEDTLS_MODE_GCM ||
|
||||
cipher_info->mode == MBEDTLS_MODE_CCM )
|
||||
@ -880,7 +880,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_cipher_setkey( &transform->cipher_ctx_enc, key1,
|
||||
cipher_info->key_length,
|
||||
cipher_info->key_bitlen,
|
||||
MBEDTLS_ENCRYPT ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_setkey", ret );
|
||||
@ -888,7 +888,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
||||
}
|
||||
|
||||
if( ( ret = mbedtls_cipher_setkey( &transform->cipher_ctx_dec, key2,
|
||||
cipher_info->key_length,
|
||||
cipher_info->key_bitlen,
|
||||
MBEDTLS_DECRYPT ) ) != 0 )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_setkey", ret );
|
||||
|
@ -310,7 +310,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
memset( key, 0, sizeof( key ) );
|
||||
|
||||
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
|
||||
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_bitlen,
|
||||
MBEDTLS_ENCRYPT ) != 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "mbedtls_cipher_setkey() returned error\n");
|
||||
@ -442,7 +442,7 @@ int main( int argc, char *argv[] )
|
||||
|
||||
memset( key, 0, sizeof( key ) );
|
||||
|
||||
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_length,
|
||||
if( mbedtls_cipher_setkey( &cipher_ctx, digest, cipher_info->key_bitlen,
|
||||
MBEDTLS_DECRYPT ) != 0 )
|
||||
{
|
||||
mbedtls_fprintf( stderr, "mbedtls_cipher_setkey() returned error\n" );
|
||||
|
Loading…
Reference in New Issue
Block a user