cipher_alg_without_iv: also test multipart operations

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
Gilles Peskine 2022-04-20 17:09:38 +02:00
parent 69d9817a66
commit 4da5a85f80

View File

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