Merge pull request #3694 from AndrzejKurek/transform-cipher-optimization

Merge enc/dec cipher contexts in ssl transforms
This commit is contained in:
Andrzej Kurek
2020-09-23 14:06:43 +01:00
committed by GitHub
9 changed files with 262 additions and 18 deletions

View File

@@ -672,6 +672,11 @@
#error "MBEDTLS_SSL_TLS_C defined, but neither TLS or DTLS is active"
#endif
#if defined(MBEDTLS_SSL_TLS_C) && defined(MBEDTLS_SSL_TRANSFORM_OPTIMIZE_CIPHERS) && \
defined(MBEDTLS_ARC4_C)
#error "MBEDTLS_ARC4_C cannot be defined with MBEDTLS_SSL_TRANSFORM_OPTIMIZE_CIPHERS on"
#endif
#if defined(MBEDTLS_SSL_TLS_C) && (defined(MBEDTLS_SSL_PROTO_SSL3) && \
defined(MBEDTLS_SSL_PROTO_TLS1_1) && !defined(MBEDTLS_SSL_PROTO_TLS1))
#error "Illegal protocol selection"

View File

@@ -3284,6 +3284,20 @@
*/
#define MBEDTLS_SSL_TLS_C
/**
* \def MBEDTLS_SSL_TRANSFORM_OPTIMIZE_CIPHERS
* Use one cipher context for both decryption and encryption in ssl transforms.
*
* This change saves some RAM, but makes the operations last longer:
* before every encryption and decryption a key is set on the context.
*
* This change will not work with MBEDTLS_ARC4_C, since it requires an
* additional table and offsets to be saved between cipher calls, and this
* contradicts key resetting before each use.
*
*/
//#define MBEDTLS_SSL_TRANSFORM_OPTIMIZE_CIPHERS
/**
* \def MBEDTLS_THREADING_C
*

View File

@@ -756,9 +756,15 @@ struct mbedtls_ssl_transform
z_stream ctx_inflate; /*!< decompression context */
#endif
#if defined(MBEDTLS_SSL_TRANSFORM_OPTIMIZE_CIPHERS)
unsigned char *key_enc;
unsigned char *key_dec;
unsigned int key_bitlen;
mbedtls_cipher_context_t cipher_ctx; /*!< encryption/decryption context */
#else
mbedtls_cipher_context_t cipher_ctx_enc; /*!< encryption context */
mbedtls_cipher_context_t cipher_ctx_dec; /*!< decryption context */
#endif
#if defined(MBEDTLS_SSL_CONTEXT_SERIALIZATION)
/* We need the Hello random bytes in order to re-derive keys from the
* Master Secret and other session info, see ssl_populate_transform() */