From 5648d577a460ffe07d834666a4e7afc9314b00aa Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Thu, 3 Feb 2022 14:09:02 +0100 Subject: [PATCH] Optimize psa_cipher_encrypt_helper() Signed-off-by: Przemyslaw Stekiel --- tests/suites/test_suite_ssl.function | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index 2a7b29dbd..53f541fad 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -1186,12 +1186,12 @@ int psk_dummy_callback( void *p_info, mbedtls_ssl_context *ssl, #define SSL_CID_LEN_MIN MBEDTLS_SSL_CID_OUT_LEN_MAX #endif -#if defined(MBEDTLS_USE_PSA_CRYPTO) static int psa_cipher_encrypt_helper( mbedtls_ssl_transform *transform, const unsigned char *iv, size_t iv_len, const unsigned char *input, size_t ilen, unsigned char *output, size_t *olen ) { +#if defined(MBEDTLS_USE_PSA_CRYPTO) psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED; psa_cipher_operation_t cipher_op = PSA_CIPHER_OPERATION_INIT; size_t part_len; @@ -1221,8 +1221,11 @@ static int psa_cipher_encrypt_helper( mbedtls_ssl_transform *transform, *olen += part_len; return( 0 ); -} +#else + return mbedtls_cipher_crypt( &transform->cipher_ctx_enc, + iv, iv_len, input, ilen, output, olen ); #endif /* MBEDTLS_USE_PSA_CRYPTO */ +} static int build_transforms( mbedtls_ssl_transform *t_in, mbedtls_ssl_transform *t_out, @@ -3718,16 +3721,9 @@ void ssl_decrypt_non_etm_cbc( int cipher_type, int hash_id, int trunc_hmac, /* * Encrypt and decrypt the correct record, expecting success */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) TEST_EQUAL( 0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen, rec.buf + rec.data_offset, rec.data_len, rec.buf + rec.data_offset, &olen ) ); -#else - TEST_EQUAL( 0, mbedtls_cipher_crypt( &t0.cipher_ctx_enc, - t0.iv_enc, t0.ivlen, - rec.buf + rec.data_offset, rec.data_len, - rec.buf + rec.data_offset, &olen ) ); -#endif /* MBEDTLS_USE_PSA_CRYPTO */ rec.data_offset -= t0.ivlen; rec.data_len += t0.ivlen; @@ -3750,16 +3746,9 @@ void ssl_decrypt_non_etm_cbc( int cipher_type, int hash_id, int trunc_hmac, rec.buf[i] ^= 0x01; /* Encrypt */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) TEST_EQUAL( 0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen, rec.buf + rec.data_offset, rec.data_len, rec.buf + rec.data_offset, &olen ) ); -#else - TEST_EQUAL( 0, mbedtls_cipher_crypt( &t0.cipher_ctx_enc, - t0.iv_enc, t0.ivlen, - rec.buf + rec.data_offset, rec.data_len, - rec.buf + rec.data_offset, &olen ) ); -#endif /* MBEDTLS_USE_PSA_CRYPTO */ rec.data_offset -= t0.ivlen; rec.data_len += t0.ivlen; @@ -3793,16 +3782,9 @@ void ssl_decrypt_non_etm_cbc( int cipher_type, int hash_id, int trunc_hmac, memset( buf + buflen - padlen - 1, i, padlen + 1 ); /* Encrypt */ -#if defined(MBEDTLS_USE_PSA_CRYPTO) TEST_EQUAL( 0, psa_cipher_encrypt_helper(&t0, t0.iv_enc, t0.ivlen, rec.buf + rec.data_offset, rec.data_len, rec.buf + rec.data_offset, &olen ) ); -#else - TEST_EQUAL( 0, mbedtls_cipher_crypt( &t0.cipher_ctx_enc, - t0.iv_enc, t0.ivlen, - rec.buf + rec.data_offset, rec.data_len, - rec.buf + rec.data_offset, &olen ) ); -#endif /* MBEDTLS_USE_PSA_CRYPTO */ rec.data_offset -= t0.ivlen; rec.data_len += t0.ivlen;