From 4da5a85f800d424849e33a6d2fa1c4db755bee85 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 20 Apr 2022 17:09:38 +0200 Subject: [PATCH] cipher_alg_without_iv: also test multipart operations Signed-off-by: Gilles Peskine --- tests/suites/test_suite_psa_crypto.function | 43 +++++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/tests/suites/test_suite_psa_crypto.function b/tests/suites/test_suite_psa_crypto.function index cabf97651..7c1254430 100644 --- a/tests/suites/test_suite_psa_crypto.function +++ b/tests/suites/test_suite_psa_crypto.function @@ -2600,10 +2600,9 @@ void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data, psa_algorithm_t alg = alg_arg; psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT; uint8_t iv[1] = { 0x5a }; - size_t iv_length; unsigned char *output = NULL; size_t output_buffer_size = 0; - size_t output_length; + size_t output_length, length; psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT; PSA_ASSERT( psa_crypto_init( ) ); @@ -2641,13 +2640,49 @@ void cipher_alg_without_iv( int alg_arg, int key_type_arg, data_t *key_data, /* generate_iv() is not allowed */ PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ), - &iv_length ), + &length ), PSA_ERROR_BAD_STATE ); PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); TEST_EQUAL( psa_cipher_generate_iv( &operation, iv, sizeof( iv ), - &iv_length ), + &length ), PSA_ERROR_BAD_STATE ); + /* Multipart encryption */ + PSA_ASSERT( psa_cipher_encrypt_setup( &operation, key, alg ) ); + output_length = 0; + length = ~0; + PSA_ASSERT( psa_cipher_update( &operation, + plaintext->x, plaintext->len, + output, output_buffer_size, + &length ) ); + TEST_ASSERT( length <= output_buffer_size ); + output_length += length; + PSA_ASSERT( psa_cipher_finish( &operation, + output + output_length, + output_buffer_size - output_length, + &length ) ); + output_length += length; + ASSERT_COMPARE( ciphertext->x, ciphertext->len, + output, output_length ); + + /* Multipart encryption */ + PSA_ASSERT( psa_cipher_decrypt_setup( &operation, key, alg ) ); + output_length = 0; + length = ~0; + PSA_ASSERT( psa_cipher_update( &operation, + ciphertext->x, ciphertext->len, + output, output_buffer_size, + &length ) ); + TEST_ASSERT( length <= output_buffer_size ); + output_length += length; + PSA_ASSERT( psa_cipher_finish( &operation, + output + output_length, + output_buffer_size - output_length, + &length ) ); + output_length += length; + ASSERT_COMPARE( plaintext->x, plaintext->len, + output, output_length ); + /* One-shot encryption */ output_length = ~0; PSA_ASSERT( psa_cipher_encrypt( key, alg, plaintext->x, plaintext->len,