Re-arrange some code in ssl_derive_keys()

This commit is contained in:
Manuel Pégourié-Gonnard 2014-06-18 15:34:40 +02:00 committed by Paul Bakker
parent ee415031e5
commit e800cd81d7

View file

@ -511,34 +511,31 @@ int ssl_derive_keys( ssl_context *ssl )
* Determine the appropriate key, IV and MAC length. * Determine the appropriate key, IV and MAC length.
*/ */
transform->keylen = cipher_info->key_length / 8;
if( cipher_info->mode == POLARSSL_MODE_GCM || if( cipher_info->mode == POLARSSL_MODE_GCM ||
cipher_info->mode == POLARSSL_MODE_CCM ) cipher_info->mode == POLARSSL_MODE_CCM )
{ {
transform->keylen = cipher_info->key_length; transform->maclen = 0;
transform->keylen /= 8;
transform->minlen = 1;
transform->ivlen = 12; transform->ivlen = 12;
transform->fixed_ivlen = 4; transform->fixed_ivlen = 4;
transform->maclen = 0;
transform->minlen = 1; // FIXME
} }
else else
{
if( md_info->type != POLARSSL_MD_NONE )
{ {
int ret; int ret;
if( ( ret = md_init_ctx( &transform->md_ctx_enc, md_info ) ) != 0 ) /* Initialize HMAC contexts */
{ if( ( ret = md_init_ctx( &transform->md_ctx_enc, md_info ) ) != 0 ||
SSL_DEBUG_RET( 1, "md_init_ctx", ret ); ( ret = md_init_ctx( &transform->md_ctx_dec, md_info ) ) != 0 )
return( ret );
}
if( ( ret = md_init_ctx( &transform->md_ctx_dec, md_info ) ) != 0 )
{ {
SSL_DEBUG_RET( 1, "md_init_ctx", ret ); SSL_DEBUG_RET( 1, "md_init_ctx", ret );
return( ret ); return( ret );
} }
/* Get MAC length */
transform->maclen = md_get_size( md_info ); transform->maclen = md_get_size( md_info );
#if defined(POLARSSL_SSL_TRUNCATED_HMAC) #if defined(POLARSSL_SSL_TRUNCATED_HMAC)
@ -550,12 +547,11 @@ int ssl_derive_keys( ssl_context *ssl )
if( session->trunc_hmac == SSL_TRUNC_HMAC_ENABLED ) if( session->trunc_hmac == SSL_TRUNC_HMAC_ENABLED )
transform->maclen = SSL_TRUNCATED_HMAC_LEN; transform->maclen = SSL_TRUNCATED_HMAC_LEN;
#endif /* POLARSSL_SSL_TRUNCATED_HMAC */ #endif /* POLARSSL_SSL_TRUNCATED_HMAC */
}
transform->keylen = cipher_info->key_length; /* IV length */
transform->keylen /= 8;
transform->ivlen = cipher_info->iv_size; transform->ivlen = cipher_info->iv_size;
/* Minimum length: FIXME */
transform->minlen = transform->keylen; transform->minlen = transform->keylen;
if( transform->minlen < transform->maclen ) if( transform->minlen < transform->maclen )
{ {