Optimize psa_cipher_encrypt_helper()

Signed-off-by: Przemyslaw Stekiel <przemyslaw.stekiel@mobica.com>
This commit is contained in:
Przemyslaw Stekiel 2022-02-03 14:09:02 +01:00
parent 6928a5164d
commit 5648d577a4

View file

@ -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;