mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-25 20:46:57 +00:00
Reduce size of ssl_transform
if no MAC ciphersuite is enabled
The hash contexts `ssl_transform->md_ctx_{enc/dec}` are not used if only AEAD ciphersuites are enabled. This commit removes them from the `ssl_transform` struct in this case, saving a few bytes.
This commit is contained in:
parent
f122944b7d
commit
92231325a7
|
@ -536,6 +536,8 @@ struct mbedtls_ssl_transform
|
|||
unsigned char iv_enc[16]; /*!< IV (encryption) */
|
||||
unsigned char iv_dec[16]; /*!< IV (decryption) */
|
||||
|
||||
#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
|
||||
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
/* Needed only for SSL v3.0 secret */
|
||||
unsigned char mac_enc[20]; /*!< SSL v3.0 secret (enc) */
|
||||
|
@ -545,13 +547,14 @@ struct mbedtls_ssl_transform
|
|||
mbedtls_md_context_t md_ctx_enc; /*!< MAC (encryption) */
|
||||
mbedtls_md_context_t md_ctx_dec; /*!< MAC (decryption) */
|
||||
|
||||
mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
|
||||
mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
|
||||
|
||||
#if defined(MBEDTLS_SSL_ENCRYPT_THEN_MAC)
|
||||
int encrypt_then_mac; /*!< flag for EtM activation */
|
||||
#endif
|
||||
|
||||
#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
|
||||
|
||||
mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
|
||||
mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
|
||||
int minor_ver;
|
||||
|
||||
/*
|
||||
|
|
|
@ -987,10 +987,11 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
|||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
|
||||
#if defined(MBEDTLS_SSL_PROTO_SSL3)
|
||||
if( ssl->minor_ver == MBEDTLS_SSL_MINOR_VERSION_0 )
|
||||
{
|
||||
if( mac_key_len > sizeof transform->mac_enc )
|
||||
if( mac_key_len > sizeof( transform->mac_enc ) )
|
||||
{
|
||||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
|
@ -1019,6 +1020,7 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
|||
MBEDTLS_SSL_DEBUG_MSG( 1, ( "should never happen" ) );
|
||||
return( MBEDTLS_ERR_SSL_INTERNAL_ERROR );
|
||||
}
|
||||
#endif /* MBEDTLS_SSL_SOME_MODES_USE_MAC */
|
||||
|
||||
#if defined(MBEDTLS_SSL_HW_RECORD_ACCEL)
|
||||
if( mbedtls_ssl_hw_record_init != NULL )
|
||||
|
@ -1037,6 +1039,9 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl )
|
|||
return( MBEDTLS_ERR_SSL_HW_ACCEL_FAILED );
|
||||
}
|
||||
}
|
||||
#else
|
||||
((void) mac_dec);
|
||||
((void) mac_enc);
|
||||
#endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */
|
||||
|
||||
#if defined(MBEDTLS_SSL_EXPORT_KEYS)
|
||||
|
@ -6785,8 +6790,10 @@ static void ssl_transform_init( mbedtls_ssl_transform *transform )
|
|||
mbedtls_cipher_init( &transform->cipher_ctx_enc );
|
||||
mbedtls_cipher_init( &transform->cipher_ctx_dec );
|
||||
|
||||
#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
|
||||
mbedtls_md_init( &transform->md_ctx_enc );
|
||||
mbedtls_md_init( &transform->md_ctx_dec );
|
||||
#endif
|
||||
}
|
||||
|
||||
void mbedtls_ssl_session_init( mbedtls_ssl_session *session )
|
||||
|
@ -8888,8 +8895,10 @@ void mbedtls_ssl_transform_free( mbedtls_ssl_transform *transform )
|
|||
mbedtls_cipher_free( &transform->cipher_ctx_enc );
|
||||
mbedtls_cipher_free( &transform->cipher_ctx_dec );
|
||||
|
||||
#if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
|
||||
mbedtls_md_free( &transform->md_ctx_enc );
|
||||
mbedtls_md_free( &transform->md_ctx_dec );
|
||||
#endif
|
||||
|
||||
mbedtls_platform_zeroize( transform, sizeof( mbedtls_ssl_transform ) );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue