Structify cipher test driver hook variables

Signed-off-by: Steven Cooreman <steven.cooreman@silabs.com>
This commit is contained in:
Steven Cooreman 2020-09-08 14:06:57 +02:00
parent 435beeaef3
commit acb5a100a7
3 changed files with 146 additions and 124 deletions

View File

@ -45,11 +45,25 @@ typedef struct{
test_transparent_cipher_operation_t ctx;
} test_opaque_cipher_operation_t;
extern void *test_driver_cipher_forced_output;
extern size_t test_driver_cipher_forced_output_length;
typedef struct {
/* If non-null, on success, copy this to the output. */
void *forced_output;
size_t forced_output_length;
/* If not PSA_SUCCESS, return this error code instead of processing the
* function call. */
psa_status_t forced_status;
/* Count the amount of times one of the keygen driver functions is called. */
unsigned long hits;
} test_driver_cipher_hooks_t;
extern psa_status_t test_transparent_cipher_status;
extern unsigned long test_transparent_cipher_hit;
#define TEST_DRIVER_CIPHER_INIT { NULL, 0, PSA_SUCCESS, 0 }
static inline test_driver_cipher_hooks_t test_driver_cipher_hooks_init( void )
{
const test_driver_cipher_hooks_t v = TEST_DRIVER_CIPHER_INIT;
return( v );
}
extern test_driver_cipher_hooks_t test_driver_cipher_hooks;
psa_status_t test_transparent_cipher_encrypt(
const psa_key_attributes_t *attributes,

View File

@ -26,25 +26,21 @@
#if defined(MBEDTLS_PSA_CRYPTO_DRIVERS) && defined(PSA_CRYPTO_DRIVER_TEST)
#include "psa/crypto.h"
#include "psa_crypto_core.h"
#include "mbedtls/cipher.h"
#include "drivers/cipher.h"
#include "test/drivers/cipher.h"
#include "test/random.h"
#include <string.h>
/* If non-null, on success, copy this to the output. */
void *test_driver_cipher_forced_output = NULL;
size_t test_driver_cipher_forced_output_length = 0;
/* Test driver implements AES-CTR by default when it's status is not overridden.
* Set test_transparent_cipher_status to PSA_ERROR_NOT_SUPPORTED to use fallback
* even for AES-CTR.
* Keep in mind this code is only exercised during the crypto drivers test target,
* meaning the other test runs will still test only the non-driver implementation. */
psa_status_t test_transparent_cipher_status = PSA_SUCCESS;
unsigned long test_transparent_cipher_hit = 0;
* Set test_driver_cipher_hooks.forced_status to PSA_ERROR_NOT_SUPPORTED to use
* fallback even for AES-CTR.
* Keep in mind this code is only exercised with the crypto drivers test target,
* meaning the other test runs will only test the non-driver implementation. */
test_driver_cipher_hooks_t test_driver_cipher_hooks = TEST_DRIVER_CIPHER_INIT;
psa_status_t test_transparent_cipher_encrypt(
const psa_key_attributes_t *attributes,
@ -59,17 +55,19 @@ psa_status_t test_transparent_cipher_encrypt(
(void) alg;
(void) input;
(void) input_length;
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( test_transparent_cipher_status != PSA_SUCCESS )
return test_transparent_cipher_status;
if( output_size < test_driver_cipher_forced_output_length )
return PSA_ERROR_BUFFER_TOO_SMALL;
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status );
if( output_size < test_driver_cipher_hooks.forced_output_length )
return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy(output, test_driver_cipher_forced_output, test_driver_cipher_forced_output_length);
*output_length = test_driver_cipher_forced_output_length;
memcpy( output,
test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length;
return test_transparent_cipher_status;
return( test_driver_cipher_hooks.forced_status );
}
psa_status_t test_transparent_cipher_decrypt(
@ -85,17 +83,19 @@ psa_status_t test_transparent_cipher_decrypt(
(void) alg;
(void) input;
(void) input_length;
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( test_transparent_cipher_status != PSA_SUCCESS )
return test_transparent_cipher_status;
if( output_size < test_driver_cipher_forced_output_length )
return PSA_ERROR_BUFFER_TOO_SMALL;
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
return( test_driver_cipher_hooks.forced_status );
if( output_size < test_driver_cipher_hooks.forced_output_length )
return( PSA_ERROR_BUFFER_TOO_SMALL );
memcpy(output, test_driver_cipher_forced_output, test_driver_cipher_forced_output_length);
*output_length = test_driver_cipher_forced_output_length;
memcpy( output,
test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length;
return test_transparent_cipher_status;
return( test_driver_cipher_hooks.forced_status );
}
psa_status_t test_transparent_cipher_encrypt_setup(
@ -107,10 +107,10 @@ psa_status_t test_transparent_cipher_encrypt_setup(
const mbedtls_cipher_info_t *cipher_info = NULL;
int ret = 0;
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( operation->alg != 0 )
return PSA_ERROR_BAD_STATE;
return( PSA_ERROR_BAD_STATE );
/* write our struct, this will trigger memory corruption failures
* in test when we go outside of bounds, or when the function is called
@ -118,8 +118,9 @@ psa_status_t test_transparent_cipher_encrypt_setup(
memset( operation, 0, sizeof( test_transparent_cipher_operation_t ) );
/* Test driver supports AES-CTR only, to verify operation calls. */
if( alg != PSA_ALG_CTR || psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES )
return PSA_ERROR_NOT_SUPPORTED;
if( alg != PSA_ALG_CTR ||
psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES )
return( PSA_ERROR_NOT_SUPPORTED );
operation->alg = alg;
operation->iv_size = 16;
@ -129,14 +130,14 @@ psa_status_t test_transparent_cipher_encrypt_setup(
key_length * 8,
MBEDTLS_MODE_CTR );
if( cipher_info == NULL )
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
mbedtls_cipher_init( &operation->cipher );
ret = mbedtls_cipher_setup( &operation->cipher, cipher_info );
if( ret != 0 ) {
mbedtls_cipher_free( &operation->cipher );
return mbedtls_to_psa_error( ret );
return( mbedtls_to_psa_error( ret ) );
}
ret = mbedtls_cipher_setkey( &operation->cipher,
@ -144,7 +145,7 @@ psa_status_t test_transparent_cipher_encrypt_setup(
key_length * 8, MBEDTLS_ENCRYPT );
if( ret != 0 ) {
mbedtls_cipher_free( &operation->cipher );
return mbedtls_to_psa_error( ret );
return( mbedtls_to_psa_error( ret ) );
}
operation->iv_set = 0;
@ -152,10 +153,10 @@ psa_status_t test_transparent_cipher_encrypt_setup(
operation->key_set = 1;
/* Allow overriding return value for testing purposes */
if( test_transparent_cipher_status != PSA_SUCCESS )
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
mbedtls_cipher_free( &operation->cipher );
return test_transparent_cipher_status;
return( test_driver_cipher_hooks.forced_status );
}
psa_status_t test_transparent_cipher_decrypt_setup(
@ -167,10 +168,10 @@ psa_status_t test_transparent_cipher_decrypt_setup(
const mbedtls_cipher_info_t *cipher_info = NULL;
int ret = 0;
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( operation->alg != 0 )
return PSA_ERROR_BAD_STATE;
return( PSA_ERROR_BAD_STATE );
/* write our struct, this will trigger memory corruption failures
* in test when we go outside of bounds, or when the function is called
@ -195,23 +196,23 @@ const mbedtls_cipher_info_t *cipher_info = NULL;
ret = mbedtls_cipher_setup( &operation->cipher, cipher_info );
if( ret != 0 )
return mbedtls_to_psa_error( ret );
return( mbedtls_to_psa_error( ret ) );
ret = mbedtls_cipher_setkey( &operation->cipher,
key,
key_length * 8, MBEDTLS_DECRYPT );
if( ret != 0 )
return mbedtls_to_psa_error( ret );
return( mbedtls_to_psa_error( ret ) );
operation->iv_set = 0;
operation->iv_required = 1;
operation->key_set = 1;
/* Allow overriding return value for testing purposes */
if( test_transparent_cipher_status != PSA_SUCCESS )
if( test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
mbedtls_cipher_free( &operation->cipher );
return test_transparent_cipher_status;
return( test_driver_cipher_hooks.forced_status );
}
psa_status_t test_transparent_cipher_abort(
@ -228,8 +229,8 @@ psa_status_t test_transparent_cipher_abort(
* in test when we go outside of bounds. */
memset( operation, 0, sizeof( test_transparent_cipher_operation_t ) );
test_transparent_cipher_hit++;
return PSA_SUCCESS;
test_driver_cipher_hooks.hits++;
return( PSA_SUCCESS );
}
psa_status_t test_transparent_cipher_generate_iv(
@ -242,7 +243,7 @@ psa_status_t test_transparent_cipher_generate_iv(
mbedtls_test_rnd_pseudo_info rnd_info;
memset( &rnd_info, 0x5A, sizeof( mbedtls_test_rnd_pseudo_info ) );
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( operation->alg != PSA_ALG_CTR )
return( PSA_ERROR_BAD_STATE );
@ -258,12 +259,12 @@ psa_status_t test_transparent_cipher_generate_iv(
iv,
operation->iv_size ) );
if( status != PSA_SUCCESS )
return status;
return( status );
*iv_length = operation->iv_size;
status = test_transparent_cipher_set_iv( operation, iv, *iv_length );
return status;
return( status );
}
psa_status_t test_transparent_cipher_set_iv(
@ -273,10 +274,10 @@ psa_status_t test_transparent_cipher_set_iv(
{
psa_status_t status;
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( operation->alg != PSA_ALG_CTR )
return PSA_ERROR_BAD_STATE;
return( PSA_ERROR_BAD_STATE );
if( operation->iv_set || ! operation->iv_required )
return( PSA_ERROR_BAD_STATE );
@ -290,7 +291,7 @@ psa_status_t test_transparent_cipher_set_iv(
if( status == PSA_SUCCESS )
operation->iv_set = 1;
return status;
return( status );
}
psa_status_t test_transparent_cipher_update(
@ -304,7 +305,7 @@ psa_status_t test_transparent_cipher_update(
size_t expected_output_size;
psa_status_t status;
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( operation->alg != PSA_ALG_CTR )
return( PSA_ERROR_BAD_STATE );
@ -322,16 +323,18 @@ psa_status_t test_transparent_cipher_update(
if( status != PSA_SUCCESS )
return status;
if( test_driver_cipher_forced_output != NULL )
if( test_driver_cipher_hooks.forced_output != NULL )
{
if( output_size < test_driver_cipher_forced_output_length )
if( output_size < test_driver_cipher_hooks.forced_output_length )
return PSA_ERROR_BUFFER_TOO_SMALL;
memcpy(output, test_driver_cipher_forced_output, test_driver_cipher_forced_output_length);
*output_length = test_driver_cipher_forced_output_length;
memcpy( output,
test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length;
}
return test_transparent_cipher_status;
return( test_driver_cipher_hooks.forced_status );
}
psa_status_t test_transparent_cipher_finish(
@ -343,7 +346,7 @@ psa_status_t test_transparent_cipher_finish(
psa_status_t status = PSA_ERROR_GENERIC_ERROR;
uint8_t temp_output_buffer[MBEDTLS_MAX_BLOCK_LENGTH];
test_transparent_cipher_hit++;
test_driver_cipher_hooks.hits++;
if( operation->alg != PSA_ALG_CTR )
return( PSA_ERROR_BAD_STATE );
@ -372,16 +375,18 @@ psa_status_t test_transparent_cipher_finish(
return( PSA_ERROR_BUFFER_TOO_SMALL );
if( test_driver_cipher_forced_output != NULL )
if( test_driver_cipher_hooks.forced_output != NULL )
{
if( output_size < test_driver_cipher_forced_output_length )
if( output_size < test_driver_cipher_hooks.forced_output_length )
return PSA_ERROR_BUFFER_TOO_SMALL;
memcpy(output, test_driver_cipher_forced_output, test_driver_cipher_forced_output_length);
*output_length = test_driver_cipher_forced_output_length;
memcpy( output,
test_driver_cipher_hooks.forced_output,
test_driver_cipher_hooks.forced_output_length );
*output_length = test_driver_cipher_hooks.forced_output_length;
}
return test_transparent_cipher_status;
return( test_driver_cipher_hooks.forced_status );
}
/*
@ -403,7 +408,7 @@ psa_status_t test_opaque_cipher_encrypt(
(void) output;
(void) output_size;
(void) output_length;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_decrypt(
@ -422,7 +427,7 @@ psa_status_t test_opaque_cipher_decrypt(
(void) output;
(void) output_size;
(void) output_length;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_encrypt_setup(
@ -436,7 +441,7 @@ psa_status_t test_opaque_cipher_encrypt_setup(
(void) key;
(void) key_length;
(void) alg;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_decrypt_setup(
@ -450,14 +455,14 @@ psa_status_t test_opaque_cipher_decrypt_setup(
(void) key;
(void) key_length;
(void) alg;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_abort(
test_opaque_cipher_operation_t *operation)
{
(void) operation;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_generate_iv(
@ -470,7 +475,7 @@ psa_status_t test_opaque_cipher_generate_iv(
(void) iv;
(void) iv_size;
(void) iv_length;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_set_iv(
@ -481,7 +486,7 @@ psa_status_t test_opaque_cipher_set_iv(
(void) operation;
(void) iv;
(void) iv_length;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_update(
@ -498,7 +503,7 @@ psa_status_t test_opaque_cipher_update(
(void) output;
(void) output_size;
(void) output_length;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
psa_status_t test_opaque_cipher_finish(
@ -511,6 +516,6 @@ psa_status_t test_opaque_cipher_finish(
(void) output;
(void) output_size;
(void) output_length;
return PSA_ERROR_NOT_SUPPORTED;
return( PSA_ERROR_NOT_SUPPORTED );
}
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */

View File

@ -201,7 +201,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_transparent_cipher_hit = 0;
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
PSA_ASSERT( psa_crypto_init( ) );
@ -213,12 +213,12 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
PSA_ASSERT( psa_cipher_encrypt_setup( &operation,
handle, alg ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
@ -228,16 +228,16 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
input->x, input->len,
output, output_buffer_size,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length;
status = psa_cipher_finish( &operation,
output + total_output_length,
output_buffer_size - total_output_length,
&function_output_length );
TEST_EQUAL( test_transparent_cipher_hit, 2);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 );
test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length;
@ -246,8 +246,7 @@ void cipher_encrypt( int alg_arg, int key_type_arg,
{
PSA_ASSERT( psa_cipher_abort( &operation ) );
// driver function should've been called as part of the finish() core routine
TEST_EQUAL( test_transparent_cipher_hit, 0);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length );
}
@ -257,6 +256,7 @@ exit:
mbedtls_free( output );
psa_destroy_key( handle );
PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
}
/* END_CASE */
@ -280,7 +280,7 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_transparent_cipher_hit = 0;
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
PSA_ASSERT( psa_crypto_init( ) );
@ -292,12 +292,12 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
PSA_ASSERT( psa_cipher_encrypt_setup( &operation,
handle, alg ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
@ -307,8 +307,8 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
PSA_ASSERT( psa_cipher_update( &operation, input->x, first_part_size,
output, output_buffer_size,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output1_length );
total_output_length += function_output_length;
@ -318,19 +318,19 @@ void cipher_encrypt_multipart( int alg_arg, int key_type_arg,
output + total_output_length,
output_buffer_size - total_output_length,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output2_length );
total_output_length += function_output_length;
PSA_ASSERT( psa_cipher_finish( &operation,
output + total_output_length,
output_buffer_size - total_output_length,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 2);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 );
test_driver_cipher_hooks.hits = 0 ;
total_output_length += function_output_length;
PSA_ASSERT( psa_cipher_abort( &operation ) );
TEST_EQUAL( test_transparent_cipher_hit, 0);
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length );
@ -340,6 +340,7 @@ exit:
mbedtls_free( output );
psa_destroy_key( handle );
PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
}
/* END_CASE */
@ -364,7 +365,7 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_transparent_cipher_hit = 0;
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
PSA_ASSERT( psa_crypto_init( ) );
@ -376,12 +377,12 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
PSA_ASSERT( psa_cipher_decrypt_setup( &operation,
handle, alg ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
@ -392,8 +393,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
input->x, first_part_size,
output, output_buffer_size,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output1_length );
total_output_length += function_output_length;
@ -403,8 +404,8 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
output + total_output_length,
output_buffer_size - total_output_length,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
TEST_ASSERT( function_output_length == output2_length );
total_output_length += function_output_length;
@ -412,11 +413,11 @@ void cipher_decrypt_multipart( int alg_arg, int key_type_arg,
output + total_output_length,
output_buffer_size - total_output_length,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 2);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 );
test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length;
PSA_ASSERT( psa_cipher_abort( &operation ) );
TEST_EQUAL( test_transparent_cipher_hit, 0);
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length );
@ -426,6 +427,7 @@ exit:
mbedtls_free( output );
psa_destroy_key( handle );
PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
}
/* END_CASE */
@ -446,7 +448,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
size_t total_output_length = 0;
psa_cipher_operation_t operation = PSA_CIPHER_OPERATION_INIT;
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
test_transparent_cipher_hit = 0;
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
PSA_ASSERT( psa_crypto_init( ) );
@ -458,12 +460,12 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
PSA_ASSERT( psa_cipher_decrypt_setup( &operation,
handle, alg ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
PSA_ASSERT( psa_cipher_set_iv( &operation, iv->x, iv->len ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
output_buffer_size = ( (size_t) input->len +
PSA_BLOCK_CIPHER_BLOCK_SIZE( key_type ) );
@ -473,16 +475,16 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
input->x, input->len,
output, output_buffer_size,
&function_output_length ) );
TEST_EQUAL( test_transparent_cipher_hit, 1);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 1 );
test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length;
status = psa_cipher_finish( &operation,
output + total_output_length,
output_buffer_size - total_output_length,
&function_output_length );
TEST_EQUAL( test_transparent_cipher_hit, 2);
test_transparent_cipher_hit = 0;
TEST_EQUAL( test_driver_cipher_hooks.hits, 2 );
test_driver_cipher_hooks.hits = 0;
total_output_length += function_output_length;
TEST_EQUAL( status, expected_status );
@ -490,7 +492,7 @@ void cipher_decrypt( int alg_arg, int key_type_arg,
if( expected_status == PSA_SUCCESS )
{
PSA_ASSERT( psa_cipher_abort( &operation ) );
TEST_EQUAL( test_transparent_cipher_hit, 0);
TEST_EQUAL( test_driver_cipher_hooks.hits, 0 );
ASSERT_COMPARE( expected_output->x, expected_output->len,
output, total_output_length );
}
@ -500,5 +502,6 @@ exit:
mbedtls_free( output );
psa_destroy_key( handle );
PSA_DONE( );
test_driver_cipher_hooks = test_driver_cipher_hooks_init();
}
/* END_CASE */