mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2026-05-11 22:42:23 +02:00
Switch to the new code style
Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
@@ -27,48 +27,48 @@
|
||||
|
||||
#include <mbedtls/asn1.h>
|
||||
|
||||
int mbedtls_test_asn1_skip_integer( unsigned char **p, const unsigned char *end,
|
||||
size_t min_bits, size_t max_bits,
|
||||
int must_be_odd )
|
||||
int mbedtls_test_asn1_skip_integer(unsigned char **p, const unsigned char *end,
|
||||
size_t min_bits, size_t max_bits,
|
||||
int must_be_odd)
|
||||
{
|
||||
size_t len;
|
||||
size_t actual_bits;
|
||||
unsigned char msb;
|
||||
TEST_EQUAL( mbedtls_asn1_get_tag( p, end, &len,
|
||||
MBEDTLS_ASN1_INTEGER ),
|
||||
0 );
|
||||
TEST_EQUAL(mbedtls_asn1_get_tag(p, end, &len,
|
||||
MBEDTLS_ASN1_INTEGER),
|
||||
0);
|
||||
|
||||
/* Check if the retrieved length doesn't extend the actual buffer's size.
|
||||
* It is assumed here, that end >= p, which validates casting to size_t. */
|
||||
TEST_ASSERT( len <= (size_t)( end - *p) );
|
||||
TEST_ASSERT(len <= (size_t) (end - *p));
|
||||
|
||||
/* Tolerate a slight departure from DER encoding:
|
||||
* - 0 may be represented by an empty string or a 1-byte string.
|
||||
* - The sign bit may be used as a value bit. */
|
||||
if( ( len == 1 && ( *p )[0] == 0 ) ||
|
||||
( len > 1 && ( *p )[0] == 0 && ( ( *p )[1] & 0x80 ) != 0 ) )
|
||||
{
|
||||
++( *p );
|
||||
if ((len == 1 && (*p)[0] == 0) ||
|
||||
(len > 1 && (*p)[0] == 0 && ((*p)[1] & 0x80) != 0)) {
|
||||
++(*p);
|
||||
--len;
|
||||
}
|
||||
if( min_bits == 0 && len == 0 )
|
||||
return( 1 );
|
||||
msb = ( *p )[0];
|
||||
TEST_ASSERT( msb != 0 );
|
||||
actual_bits = 8 * ( len - 1 );
|
||||
while( msb != 0 )
|
||||
{
|
||||
if (min_bits == 0 && len == 0) {
|
||||
return 1;
|
||||
}
|
||||
msb = (*p)[0];
|
||||
TEST_ASSERT(msb != 0);
|
||||
actual_bits = 8 * (len - 1);
|
||||
while (msb != 0) {
|
||||
msb >>= 1;
|
||||
++actual_bits;
|
||||
}
|
||||
TEST_ASSERT( actual_bits >= min_bits );
|
||||
TEST_ASSERT( actual_bits <= max_bits );
|
||||
if( must_be_odd )
|
||||
TEST_ASSERT( ( ( *p )[len-1] & 1 ) != 0 );
|
||||
TEST_ASSERT(actual_bits >= min_bits);
|
||||
TEST_ASSERT(actual_bits <= max_bits);
|
||||
if (must_be_odd) {
|
||||
TEST_ASSERT(((*p)[len-1] & 1) != 0);
|
||||
}
|
||||
*p += len;
|
||||
return( 1 );
|
||||
return 1;
|
||||
exit:
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_ASN1_PARSE_C */
|
||||
|
||||
@@ -38,105 +38,107 @@
|
||||
#include <test/helpers.h>
|
||||
#include <test/macros.h>
|
||||
|
||||
int mbedtls_test_read_mpi_core( mbedtls_mpi_uint **pX, size_t *plimbs,
|
||||
const char *input )
|
||||
int mbedtls_test_read_mpi_core(mbedtls_mpi_uint **pX, size_t *plimbs,
|
||||
const char *input)
|
||||
{
|
||||
/* Sanity check */
|
||||
if( *pX != NULL )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
if (*pX != NULL) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
size_t hex_len = strlen( input );
|
||||
size_t byte_len = ( hex_len + 1 ) / 2;
|
||||
*plimbs = CHARS_TO_LIMBS( byte_len );
|
||||
size_t hex_len = strlen(input);
|
||||
size_t byte_len = (hex_len + 1) / 2;
|
||||
*plimbs = CHARS_TO_LIMBS(byte_len);
|
||||
|
||||
/* A core bignum is not allowed to be empty. Forbid it as test data,
|
||||
* this way static analyzers have a chance of knowing we don't expect
|
||||
* the bignum functions to support empty inputs. */
|
||||
if( *plimbs == 0 )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
|
||||
*pX = mbedtls_calloc( *plimbs, sizeof( **pX ) );
|
||||
if( *pX == NULL )
|
||||
return( MBEDTLS_ERR_MPI_ALLOC_FAILED );
|
||||
|
||||
unsigned char *byte_start = ( unsigned char * ) *pX;
|
||||
if( byte_len % sizeof( mbedtls_mpi_uint ) != 0 )
|
||||
{
|
||||
byte_start += sizeof( mbedtls_mpi_uint ) - byte_len % sizeof( mbedtls_mpi_uint );
|
||||
if (*plimbs == 0) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
if( ( hex_len & 1 ) != 0 )
|
||||
{
|
||||
|
||||
*pX = mbedtls_calloc(*plimbs, sizeof(**pX));
|
||||
if (*pX == NULL) {
|
||||
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
||||
}
|
||||
|
||||
unsigned char *byte_start = (unsigned char *) *pX;
|
||||
if (byte_len % sizeof(mbedtls_mpi_uint) != 0) {
|
||||
byte_start += sizeof(mbedtls_mpi_uint) - byte_len % sizeof(mbedtls_mpi_uint);
|
||||
}
|
||||
if ((hex_len & 1) != 0) {
|
||||
/* mbedtls_test_unhexify wants an even number of hex digits */
|
||||
TEST_ASSERT( mbedtls_test_ascii2uc( *input, byte_start ) == 0 );
|
||||
TEST_ASSERT(mbedtls_test_ascii2uc(*input, byte_start) == 0);
|
||||
++byte_start;
|
||||
++input;
|
||||
--byte_len;
|
||||
}
|
||||
TEST_ASSERT( mbedtls_test_unhexify( byte_start,
|
||||
byte_len,
|
||||
input,
|
||||
&byte_len ) == 0 );
|
||||
TEST_ASSERT(mbedtls_test_unhexify(byte_start,
|
||||
byte_len,
|
||||
input,
|
||||
&byte_len) == 0);
|
||||
|
||||
mbedtls_mpi_core_bigendian_to_host( *pX, *plimbs );
|
||||
return( 0 );
|
||||
mbedtls_mpi_core_bigendian_to_host(*pX, *plimbs);
|
||||
return 0;
|
||||
|
||||
exit:
|
||||
mbedtls_free( *pX );
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
mbedtls_free(*pX);
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
|
||||
int mbedtls_test_read_mpi_modulus( mbedtls_mpi_mod_modulus *N,
|
||||
const char *s,
|
||||
mbedtls_mpi_mod_rep_selector int_rep )
|
||||
int mbedtls_test_read_mpi_modulus(mbedtls_mpi_mod_modulus *N,
|
||||
const char *s,
|
||||
mbedtls_mpi_mod_rep_selector int_rep)
|
||||
{
|
||||
mbedtls_mpi_uint *p = NULL;
|
||||
size_t limbs = 0;
|
||||
if( N->limbs != 0 )
|
||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||
int ret = mbedtls_test_read_mpi_core( &p, &limbs, s );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
ret = mbedtls_mpi_mod_modulus_setup( N, p, limbs, int_rep );
|
||||
if( ret != 0 )
|
||||
mbedtls_free( p );
|
||||
return( ret );
|
||||
if (N->limbs != 0) {
|
||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||
}
|
||||
int ret = mbedtls_test_read_mpi_core(&p, &limbs, s);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
ret = mbedtls_mpi_mod_modulus_setup(N, p, limbs, int_rep);
|
||||
if (ret != 0) {
|
||||
mbedtls_free(p);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mbedtls_test_mpi_mod_modulus_free_with_limbs( mbedtls_mpi_mod_modulus *N )
|
||||
void mbedtls_test_mpi_mod_modulus_free_with_limbs(mbedtls_mpi_mod_modulus *N)
|
||||
{
|
||||
mbedtls_free( (mbedtls_mpi_uint*) N->p );
|
||||
mbedtls_mpi_mod_modulus_free( N );
|
||||
mbedtls_free((mbedtls_mpi_uint *) N->p);
|
||||
mbedtls_mpi_mod_modulus_free(N);
|
||||
}
|
||||
|
||||
int mbedtls_test_read_mpi( mbedtls_mpi *X, const char *s )
|
||||
int mbedtls_test_read_mpi(mbedtls_mpi *X, const char *s)
|
||||
{
|
||||
int negative = 0;
|
||||
/* Always set the sign bit to -1 if the input has a minus sign, even for 0.
|
||||
* This creates an invalid representation, which mbedtls_mpi_read_string()
|
||||
* avoids but we want to be able to create that in test data. */
|
||||
if( s[0] == '-' )
|
||||
{
|
||||
if (s[0] == '-') {
|
||||
++s;
|
||||
negative = 1;
|
||||
}
|
||||
/* mbedtls_mpi_read_string() currently retains leading zeros.
|
||||
* It always allocates at least one limb for the value 0. */
|
||||
if( s[0] == 0 )
|
||||
{
|
||||
mbedtls_mpi_free( X );
|
||||
return( 0 );
|
||||
if (s[0] == 0) {
|
||||
mbedtls_mpi_free(X);
|
||||
return 0;
|
||||
}
|
||||
int ret = mbedtls_mpi_read_string( X, 16, s );
|
||||
if( ret != 0 )
|
||||
return( ret );
|
||||
if( negative )
|
||||
{
|
||||
if( mbedtls_mpi_cmp_int( X, 0 ) == 0 )
|
||||
int ret = mbedtls_mpi_read_string(X, 16, s);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
if (negative) {
|
||||
if (mbedtls_mpi_cmp_int(X, 0) == 0) {
|
||||
++mbedtls_test_case_uses_negative_0;
|
||||
}
|
||||
X->s = -1;
|
||||
}
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_BIGNUM_C */
|
||||
|
||||
|
||||
1818
tests/src/certs.c
1818
tests/src/certs.c
File diff suppressed because it is too large
Load Diff
@@ -34,28 +34,25 @@ mbedtls_test_driver_hash_hooks_t
|
||||
psa_status_t mbedtls_test_transparent_hash_compute(
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *input, size_t input_length,
|
||||
uint8_t *hash, size_t hash_size, size_t *hash_length )
|
||||
uint8_t *hash, size_t hash_size, size_t *hash_length)
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_compute(
|
||||
alg, input, input_length,
|
||||
hash, hash_size, hash_length );
|
||||
hash, hash_size, hash_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_psa_hash_compute(
|
||||
alg, input, input_length,
|
||||
hash, hash_size, hash_length );
|
||||
hash, hash_size, hash_length);
|
||||
#else
|
||||
(void) alg;
|
||||
(void) input;
|
||||
@@ -67,29 +64,26 @@ psa_status_t mbedtls_test_transparent_hash_compute(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||
return mbedtls_test_driver_hash_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_setup(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_setup( operation, alg );
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_setup(operation, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_psa_hash_setup( operation, alg );
|
||||
mbedtls_psa_hash_setup(operation, alg);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) alg;
|
||||
@@ -97,30 +91,27 @@ psa_status_t mbedtls_test_transparent_hash_setup(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||
return mbedtls_test_driver_hash_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_clone(
|
||||
const mbedtls_transparent_test_driver_hash_operation_t *source_operation,
|
||||
mbedtls_transparent_test_driver_hash_operation_t *target_operation )
|
||||
mbedtls_transparent_test_driver_hash_operation_t *target_operation)
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_clone( source_operation,
|
||||
target_operation );
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_clone(source_operation,
|
||||
target_operation);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_psa_hash_clone( source_operation, target_operation );
|
||||
mbedtls_psa_hash_clone(source_operation, target_operation);
|
||||
#else
|
||||
(void) source_operation;
|
||||
(void) target_operation;
|
||||
@@ -128,31 +119,28 @@ psa_status_t mbedtls_test_transparent_hash_clone(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||
return mbedtls_test_driver_hash_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_update(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length )
|
||||
size_t input_length)
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_update(
|
||||
operation, input, input_length );
|
||||
operation, input, input_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_psa_hash_update( operation, input, input_length );
|
||||
mbedtls_psa_hash_update(operation, input, input_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) input;
|
||||
@@ -161,32 +149,29 @@ psa_status_t mbedtls_test_transparent_hash_update(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||
return mbedtls_test_driver_hash_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_finish(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation,
|
||||
uint8_t *hash,
|
||||
size_t hash_size,
|
||||
size_t *hash_length )
|
||||
size_t *hash_length)
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_finish(
|
||||
operation, hash, hash_size, hash_length );
|
||||
operation, hash, hash_size, hash_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_psa_hash_finish( operation, hash, hash_size, hash_length );
|
||||
mbedtls_psa_hash_finish(operation, hash, hash_size, hash_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) hash;
|
||||
@@ -196,34 +181,31 @@ psa_status_t mbedtls_test_transparent_hash_finish(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||
return mbedtls_test_driver_hash_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_hash_abort(
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation )
|
||||
mbedtls_transparent_test_driver_hash_operation_t *operation)
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
if (mbedtls_test_driver_hash_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_abort( operation );
|
||||
mbedtls_test_driver_hash_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_hash_abort(operation);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
mbedtls_test_driver_hash_hooks.driver_status =
|
||||
mbedtls_psa_hash_abort( operation );
|
||||
mbedtls_psa_hash_abort(operation);
|
||||
#else
|
||||
(void) operation;
|
||||
mbedtls_test_driver_hash_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_hash_hooks.driver_status );
|
||||
return mbedtls_test_driver_hash_hooks.driver_status;
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
@@ -29,8 +29,7 @@
|
||||
#include <test/drivers/test_driver.h>
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
typedef struct {
|
||||
psa_key_id_t builtin_key_id;
|
||||
psa_key_lifetime_t lifetime;
|
||||
psa_drv_slot_number_t slot_number;
|
||||
@@ -42,52 +41,50 @@ static const mbedtls_psa_builtin_key_description_t builtin_keys[] = {
|
||||
* ECDSA can be exercised on key ID MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + 1. */
|
||||
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MIN - 1,
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
|
||||
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MIN,
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
|
||||
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MIN + 1,
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT},
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT },
|
||||
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MAX - 1,
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT},
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
|
||||
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MAX,
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT},
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
|
||||
{ MBEDTLS_PSA_KEY_ID_BUILTIN_MAX + 1,
|
||||
PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION ),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT},
|
||||
PSA_KEY_PERSISTENCE_READ_ONLY, PSA_CRYPTO_TEST_DRIVER_LOCATION),
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT },
|
||||
#else
|
||||
{0, 0, 0}
|
||||
{ 0, 0, 0 }
|
||||
#endif
|
||||
};
|
||||
|
||||
psa_status_t mbedtls_psa_platform_get_builtin_key(
|
||||
mbedtls_svc_key_id_t key_id,
|
||||
psa_key_lifetime_t *lifetime,
|
||||
psa_drv_slot_number_t *slot_number )
|
||||
psa_drv_slot_number_t *slot_number)
|
||||
{
|
||||
psa_key_id_t app_key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key_id );
|
||||
psa_key_id_t app_key_id = MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key_id);
|
||||
const mbedtls_psa_builtin_key_description_t *builtin_key;
|
||||
|
||||
for( size_t i = 0;
|
||||
i < ( sizeof( builtin_keys ) / sizeof( builtin_keys[0] ) ); i++ )
|
||||
{
|
||||
for (size_t i = 0;
|
||||
i < (sizeof(builtin_keys) / sizeof(builtin_keys[0])); i++) {
|
||||
builtin_key = &builtin_keys[i];
|
||||
if( builtin_key->builtin_key_id == app_key_id )
|
||||
{
|
||||
if (builtin_key->builtin_key_id == app_key_id) {
|
||||
*lifetime = builtin_key->lifetime;
|
||||
*slot_number = builtin_key->slot_number;
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
return PSA_ERROR_DOES_NOT_EXIST;
|
||||
}
|
||||
|
||||
@@ -39,28 +39,25 @@ psa_status_t mbedtls_test_transparent_aead_encrypt(
|
||||
const uint8_t *nonce, size_t nonce_length,
|
||||
const uint8_t *additional_data, size_t additional_data_length,
|
||||
const uint8_t *plaintext, size_t plaintext_length,
|
||||
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length )
|
||||
uint8_t *ciphertext, size_t ciphertext_size, size_t *ciphertext_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_encrypt++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_encrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg,
|
||||
nonce, nonce_length,
|
||||
additional_data, additional_data_length,
|
||||
plaintext, plaintext_length,
|
||||
ciphertext, ciphertext_size, ciphertext_length );
|
||||
ciphertext, ciphertext_size, ciphertext_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_encrypt(
|
||||
@@ -69,7 +66,7 @@ psa_status_t mbedtls_test_transparent_aead_encrypt(
|
||||
nonce, nonce_length,
|
||||
additional_data, additional_data_length,
|
||||
plaintext, plaintext_length,
|
||||
ciphertext, ciphertext_size, ciphertext_length );
|
||||
ciphertext, ciphertext_size, ciphertext_length);
|
||||
#else
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -88,7 +85,7 @@ psa_status_t mbedtls_test_transparent_aead_encrypt(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_decrypt(
|
||||
@@ -98,28 +95,25 @@ psa_status_t mbedtls_test_transparent_aead_decrypt(
|
||||
const uint8_t *nonce, size_t nonce_length,
|
||||
const uint8_t *additional_data, size_t additional_data_length,
|
||||
const uint8_t *ciphertext, size_t ciphertext_length,
|
||||
uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length )
|
||||
uint8_t *plaintext, size_t plaintext_size, size_t *plaintext_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_decrypt++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_decrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg,
|
||||
nonce, nonce_length,
|
||||
additional_data, additional_data_length,
|
||||
ciphertext, ciphertext_length,
|
||||
plaintext, plaintext_size, plaintext_length );
|
||||
plaintext, plaintext_size, plaintext_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_decrypt(
|
||||
@@ -128,7 +122,7 @@ psa_status_t mbedtls_test_transparent_aead_decrypt(
|
||||
nonce, nonce_length,
|
||||
additional_data, additional_data_length,
|
||||
ciphertext, ciphertext_length,
|
||||
plaintext, plaintext_size, plaintext_length );
|
||||
plaintext, plaintext_size, plaintext_length);
|
||||
#else
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -147,35 +141,33 @@ psa_status_t mbedtls_test_transparent_aead_decrypt(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_encrypt_setup++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_encrypt_setup( operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer,
|
||||
key_buffer_size, alg );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_encrypt_setup(operation,
|
||||
(const libtestdriver1_psa_key_attributes_t
|
||||
*) attributes,
|
||||
key_buffer,
|
||||
key_buffer_size, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_encrypt_setup( operation, attributes, key_buffer,
|
||||
key_buffer_size, alg );
|
||||
mbedtls_psa_aead_encrypt_setup(operation, attributes, key_buffer,
|
||||
key_buffer_size, alg);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
@@ -186,34 +178,32 @@ psa_status_t mbedtls_test_transparent_aead_encrypt_setup(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_decrypt_setup++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_decrypt_setup( operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size, alg );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_decrypt_setup(operation,
|
||||
(const libtestdriver1_psa_key_attributes_t
|
||||
*) attributes,
|
||||
key_buffer, key_buffer_size, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_decrypt_setup( operation, attributes, key_buffer,
|
||||
key_buffer_size, alg );
|
||||
mbedtls_psa_aead_decrypt_setup(operation, attributes, key_buffer,
|
||||
key_buffer_size, alg);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
@@ -224,30 +214,27 @@ psa_status_t mbedtls_test_transparent_aead_decrypt_setup(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_set_nonce(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
const uint8_t *nonce,
|
||||
size_t nonce_length )
|
||||
size_t nonce_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_set_nonce++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_set_nonce(operation, nonce, nonce_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_set_nonce( operation, nonce, nonce_length );
|
||||
mbedtls_psa_aead_set_nonce(operation, nonce, nonce_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) nonce;
|
||||
@@ -256,32 +243,29 @@ psa_status_t mbedtls_test_transparent_aead_set_nonce(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_set_lengths(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
size_t ad_length,
|
||||
size_t plaintext_length )
|
||||
size_t plaintext_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_set_lengths++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_set_lengths( operation, ad_length,
|
||||
plaintext_length );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_set_lengths(operation, ad_length,
|
||||
plaintext_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_set_lengths( operation, ad_length,
|
||||
plaintext_length );
|
||||
mbedtls_psa_aead_set_lengths(operation, ad_length,
|
||||
plaintext_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) ad_length;
|
||||
@@ -290,30 +274,27 @@ psa_status_t mbedtls_test_transparent_aead_set_lengths(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_update_ad(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length )
|
||||
size_t input_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_update_ad++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_update_ad( operation, input, input_length );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_update_ad(operation, input, input_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_update_ad( operation, input, input_length );
|
||||
mbedtls_psa_aead_update_ad(operation, input, input_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) input;
|
||||
@@ -322,36 +303,33 @@ psa_status_t mbedtls_test_transparent_aead_update_ad(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_update(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length )
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_update++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_update( operation, input,
|
||||
input_length, output,
|
||||
output_size, output_length );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_update(operation, input,
|
||||
input_length, output,
|
||||
output_size, output_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_update( operation, input, input_length, output,
|
||||
output_size, output_length );
|
||||
mbedtls_psa_aead_update(operation, input, input_length, output,
|
||||
output_size, output_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) input;
|
||||
@@ -363,38 +341,35 @@ psa_status_t mbedtls_test_transparent_aead_update(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_finish(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
uint8_t *ciphertext,
|
||||
size_t ciphertext_size,
|
||||
size_t *ciphertext_length,
|
||||
uint8_t *tag,
|
||||
size_t tag_size,
|
||||
size_t *tag_length )
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
uint8_t *ciphertext,
|
||||
size_t ciphertext_size,
|
||||
size_t *ciphertext_length,
|
||||
uint8_t *tag,
|
||||
size_t tag_size,
|
||||
size_t *tag_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_finish++;
|
||||
mbedtls_test_driver_aead_hooks.hits_finish++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_finish( operation, ciphertext,
|
||||
ciphertext_size, ciphertext_length,
|
||||
tag, tag_size, tag_length );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_finish(operation, ciphertext,
|
||||
ciphertext_size, ciphertext_length,
|
||||
tag, tag_size, tag_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_finish( operation, ciphertext, ciphertext_size,
|
||||
ciphertext_length, tag, tag_size,
|
||||
tag_length );
|
||||
mbedtls_psa_aead_finish(operation, ciphertext, ciphertext_size,
|
||||
ciphertext_length, tag, tag_size,
|
||||
tag_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) ciphertext;
|
||||
@@ -407,48 +382,45 @@ psa_status_t mbedtls_test_transparent_aead_finish(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_verify(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
uint8_t *plaintext,
|
||||
size_t plaintext_size,
|
||||
size_t *plaintext_length,
|
||||
const uint8_t *tag,
|
||||
size_t tag_length )
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation,
|
||||
uint8_t *plaintext,
|
||||
size_t plaintext_size,
|
||||
size_t *plaintext_length,
|
||||
const uint8_t *tag,
|
||||
size_t tag_length)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_verify++;
|
||||
mbedtls_test_driver_aead_hooks.hits_verify++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE];
|
||||
size_t check_tag_length = 0;
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
uint8_t check_tag[PSA_AEAD_TAG_MAX_SIZE];
|
||||
size_t check_tag_length = 0;
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_finish( operation,
|
||||
plaintext,
|
||||
plaintext_size,
|
||||
plaintext_length,
|
||||
check_tag,
|
||||
sizeof( check_tag ),
|
||||
&check_tag_length );
|
||||
libtestdriver1_mbedtls_psa_aead_finish(operation,
|
||||
plaintext,
|
||||
plaintext_size,
|
||||
plaintext_length,
|
||||
check_tag,
|
||||
sizeof(check_tag),
|
||||
&check_tag_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_finish( operation,
|
||||
plaintext,
|
||||
plaintext_size,
|
||||
plaintext_length,
|
||||
check_tag,
|
||||
sizeof( check_tag ),
|
||||
&check_tag_length );
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_finish(operation,
|
||||
plaintext,
|
||||
plaintext_size,
|
||||
plaintext_length,
|
||||
check_tag,
|
||||
sizeof(check_tag),
|
||||
&check_tag_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) plaintext;
|
||||
@@ -457,47 +429,44 @@ psa_status_t mbedtls_test_transparent_aead_verify(
|
||||
mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS )
|
||||
{
|
||||
if( tag_length != check_tag_length ||
|
||||
mbedtls_psa_safer_memcmp( tag, check_tag, tag_length )
|
||||
!= 0 )
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
PSA_ERROR_INVALID_SIGNATURE;
|
||||
}
|
||||
if (mbedtls_test_driver_aead_hooks.driver_status == PSA_SUCCESS) {
|
||||
if (tag_length != check_tag_length ||
|
||||
mbedtls_psa_safer_memcmp(tag, check_tag, tag_length)
|
||||
!= 0) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
PSA_ERROR_INVALID_SIGNATURE;
|
||||
}
|
||||
}
|
||||
|
||||
mbedtls_platform_zeroize( check_tag, sizeof( check_tag ) );
|
||||
mbedtls_platform_zeroize(check_tag, sizeof(check_tag));
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_aead_abort(
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation )
|
||||
mbedtls_transparent_test_driver_aead_operation_t *operation)
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.hits_abort++;
|
||||
mbedtls_test_driver_aead_hooks.hits_abort++;
|
||||
|
||||
if( mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
if (mbedtls_test_driver_aead_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_abort( operation );
|
||||
mbedtls_test_driver_aead_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_aead_abort(operation);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_AEAD)
|
||||
mbedtls_test_driver_aead_hooks.driver_status =
|
||||
mbedtls_psa_aead_abort( operation );
|
||||
mbedtls_psa_aead_abort(operation);
|
||||
#else
|
||||
(void) operation;
|
||||
mbedtls_test_driver_aead_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_aead_hooks.driver_status );
|
||||
return mbedtls_test_driver_aead_hooks.driver_status;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
@@ -37,82 +37,84 @@ psa_status_t mbedtls_test_transparent_asymmetric_encrypt(
|
||||
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
||||
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
|
||||
size_t input_length, const uint8_t *salt, size_t salt_length,
|
||||
uint8_t *output, size_t output_size, size_t *output_length )
|
||||
uint8_t *output, size_t output_size, size_t *output_length)
|
||||
{
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL )
|
||||
{
|
||||
if( output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL) {
|
||||
if (output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length );
|
||||
memcpy(output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length);
|
||||
*output_length = mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length;
|
||||
|
||||
return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
|
||||
return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
|
||||
if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_asymmetric_encrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length ) );
|
||||
return libtestdriver1_mbedtls_psa_asymmetric_encrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length);
|
||||
#else
|
||||
return( mbedtls_psa_asymmetric_encrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length ) );
|
||||
return mbedtls_psa_asymmetric_encrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_asymmetric_decrypt(
|
||||
const psa_key_attributes_t *attributes, const uint8_t *key_buffer,
|
||||
size_t key_buffer_size, psa_algorithm_t alg, const uint8_t *input,
|
||||
size_t input_length, const uint8_t *salt, size_t salt_length,
|
||||
uint8_t *output, size_t output_size, size_t *output_length )
|
||||
uint8_t *output, size_t output_size, size_t *output_length)
|
||||
{
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL )
|
||||
{
|
||||
if( output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_output != NULL) {
|
||||
if (output_size < mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length );
|
||||
memcpy(output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output,
|
||||
mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length);
|
||||
*output_length = mbedtls_test_driver_asymmetric_encryption_hooks.forced_output_length;
|
||||
|
||||
return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
|
||||
return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_asymmetric_encryption_hooks.forced_status );
|
||||
if (mbedtls_test_driver_asymmetric_encryption_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_asymmetric_encryption_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_asymmetric_decrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length ) );
|
||||
return libtestdriver1_mbedtls_psa_asymmetric_decrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length);
|
||||
#else
|
||||
return( mbedtls_psa_asymmetric_decrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length ) );
|
||||
return mbedtls_psa_asymmetric_decrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, input, input_length, salt, salt_length,
|
||||
output, output_size, output_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -122,7 +124,7 @@ psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
|
||||
const psa_key_attributes_t *attributes, const uint8_t *key,
|
||||
size_t key_length, psa_algorithm_t alg, const uint8_t *input,
|
||||
size_t input_length, const uint8_t *salt, size_t salt_length,
|
||||
uint8_t *output, size_t output_size, size_t *output_length )
|
||||
uint8_t *output, size_t output_size, size_t *output_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
@@ -135,14 +137,14 @@ psa_status_t mbedtls_test_opaque_asymmetric_encrypt(
|
||||
(void) output;
|
||||
(void) output_size;
|
||||
(void) output_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
|
||||
const psa_key_attributes_t *attributes, const uint8_t *key,
|
||||
size_t key_length, psa_algorithm_t alg, const uint8_t *input,
|
||||
size_t input_length, const uint8_t *salt, size_t salt_length,
|
||||
uint8_t *output, size_t output_size, size_t *output_length )
|
||||
uint8_t *output, size_t output_size, size_t *output_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
@@ -155,7 +157,7 @@ psa_status_t mbedtls_test_opaque_asymmetric_decrypt(
|
||||
(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 */
|
||||
|
||||
@@ -50,41 +50,42 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt(
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length )
|
||||
size_t *output_length)
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
|
||||
{
|
||||
if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
|
||||
if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length );
|
||||
memcpy(output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length);
|
||||
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
|
||||
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_encrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, iv, iv_length, input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_encrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, iv, iv_length, input, input_length,
|
||||
output, output_size, output_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_encrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, iv, iv_length, input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
return mbedtls_psa_cipher_encrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, iv, iv_length, input, input_length,
|
||||
output, output_size, output_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
||||
@@ -96,41 +97,42 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt(
|
||||
size_t input_length,
|
||||
uint8_t *output,
|
||||
size_t output_size,
|
||||
size_t *output_length )
|
||||
size_t *output_length)
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
|
||||
{
|
||||
if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
|
||||
if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length );
|
||||
memcpy(output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length);
|
||||
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
|
||||
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_decrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_decrypt(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, input, input_length,
|
||||
output, output_size, output_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_decrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
return mbedtls_psa_cipher_decrypt(
|
||||
attributes, key_buffer, key_buffer_size,
|
||||
alg, input, input_length,
|
||||
output, output_size, output_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
||||
@@ -145,23 +147,24 @@ psa_status_t mbedtls_test_transparent_cipher_encrypt_setup(
|
||||
* useful for the test suite, since it gives a chance of catching memory
|
||||
* corruption errors should the core not have allocated (enough) memory for
|
||||
* our context struct. */
|
||||
memset( operation, 0, sizeof( *operation ) );
|
||||
memset(operation, 0, sizeof(*operation));
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
|
||||
operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key, key_length, alg ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_encrypt_setup(
|
||||
operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key, key_length, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_encrypt_setup(
|
||||
operation, attributes, key, key_length, alg ) );
|
||||
return mbedtls_psa_cipher_encrypt_setup(
|
||||
operation, attributes, key, key_length, alg);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
||||
@@ -172,21 +175,22 @@ psa_status_t mbedtls_test_transparent_cipher_decrypt_setup(
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
|
||||
operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key, key_length, alg ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_decrypt_setup(
|
||||
operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key, key_length, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_decrypt_setup(
|
||||
operation, attributes, key, key_length, alg ) );
|
||||
return mbedtls_psa_cipher_decrypt_setup(
|
||||
operation, attributes, key, key_length, alg);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_abort(
|
||||
@@ -196,18 +200,18 @@ psa_status_t mbedtls_test_transparent_cipher_abort(
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
libtestdriver1_mbedtls_psa_cipher_abort( operation );
|
||||
libtestdriver1_mbedtls_psa_cipher_abort(operation);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
mbedtls_psa_cipher_abort( operation );
|
||||
mbedtls_psa_cipher_abort(operation);
|
||||
#endif
|
||||
|
||||
/* Wiping the entire struct here, instead of member-by-member. This is
|
||||
* useful for the test suite, since it gives a chance of catching memory
|
||||
* corruption errors should the core not have allocated (enough) memory for
|
||||
* our context struct. */
|
||||
memset( operation, 0, sizeof( *operation ) );
|
||||
memset(operation, 0, sizeof(*operation));
|
||||
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_set_iv(
|
||||
@@ -217,18 +221,19 @@ psa_status_t mbedtls_test_transparent_cipher_set_iv(
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_set_iv(
|
||||
operation, iv, iv_length ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_set_iv(
|
||||
operation, iv, iv_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_set_iv( operation, iv, iv_length ) );
|
||||
return mbedtls_psa_cipher_set_iv(operation, iv, iv_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_update(
|
||||
@@ -241,34 +246,35 @@ psa_status_t mbedtls_test_transparent_cipher_update(
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
|
||||
{
|
||||
if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
|
||||
if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length );
|
||||
memcpy(output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length);
|
||||
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
|
||||
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_update(
|
||||
operation, input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_update(
|
||||
operation, input, input_length,
|
||||
output, output_size, output_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_update(
|
||||
operation, input, input_length,
|
||||
output, output_size, output_length ) );
|
||||
return mbedtls_psa_cipher_update(
|
||||
operation, input, input_length,
|
||||
output, output_size, output_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_cipher_finish(
|
||||
@@ -279,32 +285,33 @@ psa_status_t mbedtls_test_transparent_cipher_finish(
|
||||
{
|
||||
mbedtls_test_driver_cipher_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_output != NULL )
|
||||
{
|
||||
if( output_size < mbedtls_test_driver_cipher_hooks.forced_output_length )
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_output != NULL) {
|
||||
if (output_size < mbedtls_test_driver_cipher_hooks.forced_output_length) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length );
|
||||
memcpy(output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output,
|
||||
mbedtls_test_driver_cipher_hooks.forced_output_length);
|
||||
*output_length = mbedtls_test_driver_cipher_hooks.forced_output_length;
|
||||
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_cipher_hooks.forced_status );
|
||||
if (mbedtls_test_driver_cipher_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_cipher_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( libtestdriver1_mbedtls_psa_cipher_finish(
|
||||
operation, output, output_size, output_length ) );
|
||||
return libtestdriver1_mbedtls_psa_cipher_finish(
|
||||
operation, output, output_size, output_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_CIPHER)
|
||||
return( mbedtls_psa_cipher_finish(
|
||||
operation, output, output_size, output_length ) );
|
||||
return mbedtls_psa_cipher_finish(
|
||||
operation, output, output_size, output_length);
|
||||
#endif
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -329,7 +336,7 @@ psa_status_t mbedtls_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 mbedtls_test_opaque_cipher_decrypt(
|
||||
@@ -348,7 +355,7 @@ psa_status_t mbedtls_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 mbedtls_test_opaque_cipher_encrypt_setup(
|
||||
@@ -362,7 +369,7 @@ psa_status_t mbedtls_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 mbedtls_test_opaque_cipher_decrypt_setup(
|
||||
@@ -376,14 +383,14 @@ psa_status_t mbedtls_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 mbedtls_test_opaque_cipher_abort(
|
||||
mbedtls_opaque_test_driver_cipher_operation_t *operation )
|
||||
mbedtls_opaque_test_driver_cipher_operation_t *operation)
|
||||
{
|
||||
(void) operation;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_cipher_set_iv(
|
||||
@@ -394,7 +401,7 @@ psa_status_t mbedtls_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 mbedtls_test_opaque_cipher_update(
|
||||
@@ -411,7 +418,7 @@ psa_status_t mbedtls_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 mbedtls_test_opaque_cipher_finish(
|
||||
@@ -424,6 +431,6 @@ psa_status_t mbedtls_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 */
|
||||
|
||||
@@ -47,42 +47,42 @@ psa_status_t mbedtls_test_transparent_key_agreement(
|
||||
size_t peer_key_length,
|
||||
uint8_t *shared_secret,
|
||||
size_t shared_secret_size,
|
||||
size_t *shared_secret_length )
|
||||
size_t *shared_secret_length)
|
||||
{
|
||||
mbedtls_test_driver_key_agreement_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_key_agreement_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_key_agreement_hooks.forced_status );
|
||||
|
||||
if( mbedtls_test_driver_key_agreement_hooks.forced_output != NULL )
|
||||
{
|
||||
if( mbedtls_test_driver_key_agreement_hooks.forced_output_length > shared_secret_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
|
||||
memcpy( shared_secret, mbedtls_test_driver_key_agreement_hooks.forced_output,
|
||||
mbedtls_test_driver_key_agreement_hooks.forced_output_length );
|
||||
*shared_secret_length = mbedtls_test_driver_key_agreement_hooks.forced_output_length;
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
if (mbedtls_test_driver_key_agreement_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_key_agreement_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( PSA_ALG_IS_ECDH(alg) )
|
||||
{
|
||||
if (mbedtls_test_driver_key_agreement_hooks.forced_output != NULL) {
|
||||
if (mbedtls_test_driver_key_agreement_hooks.forced_output_length > shared_secret_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy(shared_secret, mbedtls_test_driver_key_agreement_hooks.forced_output,
|
||||
mbedtls_test_driver_key_agreement_hooks.forced_output_length);
|
||||
*shared_secret_length = mbedtls_test_driver_key_agreement_hooks.forced_output_length;
|
||||
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
if (PSA_ALG_IS_ECDH(alg)) {
|
||||
#if (defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDH))
|
||||
return( libtestdriver1_mbedtls_psa_key_agreement_ecdh(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, peer_key, peer_key_length,
|
||||
shared_secret, shared_secret_size,
|
||||
shared_secret_length ) );
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDH))
|
||||
return libtestdriver1_mbedtls_psa_key_agreement_ecdh(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, peer_key, peer_key_length,
|
||||
shared_secret, shared_secret_size,
|
||||
shared_secret_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDH)
|
||||
return( mbedtls_psa_key_agreement_ecdh(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, peer_key, peer_key_length,
|
||||
shared_secret, shared_secret_size,
|
||||
shared_secret_length ) );
|
||||
return mbedtls_psa_key_agreement_ecdh(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, peer_key, peer_key_length,
|
||||
shared_secret, shared_secret_size,
|
||||
shared_secret_length);
|
||||
#else
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -92,12 +92,10 @@ psa_status_t mbedtls_test_transparent_key_agreement(
|
||||
(void) shared_secret;
|
||||
(void) shared_secret_size;
|
||||
(void) shared_secret_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
} else {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -111,7 +109,7 @@ psa_status_t mbedtls_test_opaque_key_agreement(
|
||||
size_t peer_key_length,
|
||||
uint8_t *shared_secret,
|
||||
size_t shared_secret_size,
|
||||
size_t *shared_secret_length )
|
||||
size_t *shared_secret_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -122,7 +120,7 @@ psa_status_t mbedtls_test_opaque_key_agreement(
|
||||
(void) shared_secret;
|
||||
(void) shared_secret_size;
|
||||
(void) shared_secret_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
@@ -44,53 +44,54 @@ mbedtls_test_driver_key_management_hooks_t
|
||||
mbedtls_test_driver_key_management_hooks = MBEDTLS_TEST_DRIVER_KEY_MANAGEMENT_INIT;
|
||||
|
||||
const uint8_t mbedtls_test_driver_aes_key[16] =
|
||||
{ 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46,
|
||||
0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 };
|
||||
{ 0x36, 0x77, 0x39, 0x7A, 0x24, 0x43, 0x26, 0x46,
|
||||
0x29, 0x4A, 0x40, 0x4E, 0x63, 0x52, 0x66, 0x55 };
|
||||
const uint8_t mbedtls_test_driver_ecdsa_key[32] =
|
||||
{ 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63,
|
||||
0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18,
|
||||
0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7,
|
||||
0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a };
|
||||
{ 0xdc, 0x7d, 0x9d, 0x26, 0xd6, 0x7a, 0x4f, 0x63,
|
||||
0x2c, 0x34, 0xc2, 0xdc, 0x0b, 0x69, 0x86, 0x18,
|
||||
0x38, 0x82, 0xc2, 0x06, 0xdf, 0x04, 0xcd, 0xb7,
|
||||
0xd6, 0x9a, 0xab, 0xe2, 0x8b, 0xe4, 0xf8, 0x1a };
|
||||
const uint8_t mbedtls_test_driver_ecdsa_pubkey[65] =
|
||||
{ 0x04,
|
||||
0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c,
|
||||
0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44,
|
||||
0x56, 0x48, 0xdc, 0xb7, 0x01, 0x15, 0x0b, 0x8a,
|
||||
0x95, 0x09, 0x29, 0x58, 0x50, 0xf4, 0x1c, 0x19,
|
||||
0x31, 0xe5, 0x71, 0xfb, 0x8f, 0x8c, 0x78, 0x31,
|
||||
0x7a, 0x20, 0xb3, 0x80, 0xe8, 0x66, 0x58, 0x4b,
|
||||
0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
|
||||
0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
|
||||
{ 0x04,
|
||||
0x85, 0xf6, 0x4d, 0x89, 0xf0, 0x0b, 0xe6, 0x6c,
|
||||
0x88, 0xdd, 0x93, 0x7e, 0xfd, 0x6d, 0x7c, 0x44,
|
||||
0x56, 0x48, 0xdc, 0xb7, 0x01, 0x15, 0x0b, 0x8a,
|
||||
0x95, 0x09, 0x29, 0x58, 0x50, 0xf4, 0x1c, 0x19,
|
||||
0x31, 0xe5, 0x71, 0xfb, 0x8f, 0x8c, 0x78, 0x31,
|
||||
0x7a, 0x20, 0xb3, 0x80, 0xe8, 0x66, 0x58, 0x4b,
|
||||
0xbc, 0x25, 0x16, 0xc3, 0xd2, 0x70, 0x2d, 0x79,
|
||||
0x2f, 0x13, 0x1a, 0x92, 0x20, 0x95, 0xfd, 0x6c };
|
||||
|
||||
psa_status_t mbedtls_test_transparent_init( void )
|
||||
psa_status_t mbedtls_test_transparent_init(void)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||
status = libtestdriver1_psa_crypto_init( );
|
||||
if( status != PSA_SUCCESS )
|
||||
return( status );
|
||||
status = libtestdriver1_psa_crypto_init();
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
||||
(void)status;
|
||||
return( PSA_SUCCESS );
|
||||
(void) status;
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
void mbedtls_test_transparent_free( void )
|
||||
void mbedtls_test_transparent_free(void)
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1)
|
||||
libtestdriver1_mbedtls_psa_crypto_free( );
|
||||
libtestdriver1_mbedtls_psa_crypto_free();
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_init( void )
|
||||
psa_status_t mbedtls_test_opaque_init(void)
|
||||
{
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
void mbedtls_test_opaque_free( void )
|
||||
void mbedtls_test_opaque_free(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -102,22 +103,23 @@ void mbedtls_test_opaque_free( void )
|
||||
* prefixing to the key.
|
||||
*/
|
||||
#define TEST_DRIVER_KEY_CONTEXT_BASE_SIZE \
|
||||
PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE
|
||||
PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX_SIZE
|
||||
|
||||
|
||||
size_t mbedtls_test_opaque_size_function(
|
||||
const psa_key_type_t key_type,
|
||||
const size_t key_bits )
|
||||
const size_t key_bits)
|
||||
{
|
||||
size_t key_buffer_size = 0;
|
||||
|
||||
key_buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE( key_type, key_bits );
|
||||
if( key_buffer_size == 0 )
|
||||
return( 0 );
|
||||
key_buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits);
|
||||
if (key_buffer_size == 0) {
|
||||
return 0;
|
||||
}
|
||||
/* Include spacing for base size overhead over the key size
|
||||
* */
|
||||
key_buffer_size += TEST_DRIVER_KEY_CONTEXT_BASE_SIZE;
|
||||
return( key_buffer_size );
|
||||
return key_buffer_size;
|
||||
}
|
||||
|
||||
static size_t mbedtls_test_opaque_get_base_size()
|
||||
@@ -138,22 +140,24 @@ static psa_status_t mbedtls_test_opaque_wrap_key(
|
||||
size_t key_length,
|
||||
uint8_t *wrapped_key_buffer,
|
||||
size_t wrapped_key_buffer_size,
|
||||
size_t *wrapped_key_buffer_length )
|
||||
size_t *wrapped_key_buffer_length)
|
||||
{
|
||||
size_t opaque_key_base_size = mbedtls_test_opaque_get_base_size();
|
||||
uint64_t prefix = PSA_CRYPTO_TEST_DRIVER_OPAQUE_PAD_PREFIX;
|
||||
|
||||
if( key_length + opaque_key_base_size > wrapped_key_buffer_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (key_length + opaque_key_base_size > wrapped_key_buffer_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
/* Write in the opaque pad prefix */
|
||||
memcpy( wrapped_key_buffer, &prefix, opaque_key_base_size );
|
||||
memcpy(wrapped_key_buffer, &prefix, opaque_key_base_size);
|
||||
wrapped_key_buffer += opaque_key_base_size;
|
||||
*wrapped_key_buffer_length = key_length + opaque_key_base_size;
|
||||
|
||||
while( key_length-- )
|
||||
while (key_length--) {
|
||||
wrapped_key_buffer[key_length] = key[key_length] ^ 0xFF;
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -177,79 +181,80 @@ static psa_status_t mbedtls_test_opaque_unwrap_key(
|
||||
size_t clear_key_size;
|
||||
|
||||
/* Check for underflow */
|
||||
if( wrapped_key_length < opaque_key_base_size )
|
||||
return( PSA_ERROR_DATA_CORRUPT );
|
||||
if (wrapped_key_length < opaque_key_base_size) {
|
||||
return PSA_ERROR_DATA_CORRUPT;
|
||||
}
|
||||
clear_key_size = wrapped_key_length - opaque_key_base_size;
|
||||
|
||||
wrapped_key += opaque_key_base_size;
|
||||
if( clear_key_size > key_buffer_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (clear_key_size > key_buffer_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
*key_buffer_length = clear_key_size;
|
||||
while( clear_key_size-- )
|
||||
while (clear_key_size--) {
|
||||
key_buffer[clear_key_size] = wrapped_key[clear_key_size] ^ 0xFF;
|
||||
return( PSA_SUCCESS );
|
||||
}
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_generate_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *key, size_t key_size, size_t *key_length )
|
||||
uint8_t *key, size_t key_size, size_t *key_length)
|
||||
{
|
||||
++mbedtls_test_driver_key_management_hooks.hits;
|
||||
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_key_management_hooks.forced_status );
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_key_management_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_output != NULL )
|
||||
{
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_output_length >
|
||||
key_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
memcpy( key, mbedtls_test_driver_key_management_hooks.forced_output,
|
||||
mbedtls_test_driver_key_management_hooks.forced_output_length );
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_output != NULL) {
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_output_length >
|
||||
key_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
memcpy(key, mbedtls_test_driver_key_management_hooks.forced_output,
|
||||
mbedtls_test_driver_key_management_hooks.forced_output_length);
|
||||
*key_length = mbedtls_test_driver_key_management_hooks.forced_output_length;
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
if( PSA_KEY_TYPE_IS_ECC( psa_get_key_type( attributes ) )
|
||||
&& PSA_KEY_TYPE_IS_KEY_PAIR( psa_get_key_type( attributes ) ) )
|
||||
{
|
||||
if (PSA_KEY_TYPE_IS_ECC(psa_get_key_type(attributes))
|
||||
&& PSA_KEY_TYPE_IS_KEY_PAIR(psa_get_key_type(attributes))) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
||||
return( libtestdriver1_mbedtls_psa_ecp_generate_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key, key_size, key_length ) );
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
||||
return libtestdriver1_mbedtls_psa_ecp_generate_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key, key_size, key_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR)
|
||||
return( mbedtls_psa_ecp_generate_key(
|
||||
attributes, key, key_size, key_length ) );
|
||||
return mbedtls_psa_ecp_generate_key(
|
||||
attributes, key, key_size, key_length);
|
||||
#endif
|
||||
}
|
||||
else if( psa_get_key_type( attributes ) == PSA_KEY_TYPE_RSA_KEY_PAIR )
|
||||
{
|
||||
} else if (psa_get_key_type(attributes) == PSA_KEY_TYPE_RSA_KEY_PAIR) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
||||
return( libtestdriver1_mbedtls_psa_rsa_generate_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key, key_size, key_length ) );
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
||||
return libtestdriver1_mbedtls_psa_rsa_generate_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key, key_size, key_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR)
|
||||
return( mbedtls_psa_rsa_generate_key(
|
||||
attributes, key, key_size, key_length ) );
|
||||
return mbedtls_psa_rsa_generate_key(
|
||||
attributes, key, key_size, key_length);
|
||||
#endif
|
||||
}
|
||||
|
||||
(void)attributes;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
(void) attributes;
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_generate_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
uint8_t *key, size_t key_size, size_t *key_length )
|
||||
uint8_t *key, size_t key_size, size_t *key_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
(void) key_size;
|
||||
(void) key_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_import_key(
|
||||
@@ -261,62 +266,60 @@ psa_status_t mbedtls_test_transparent_import_key(
|
||||
size_t *key_buffer_length,
|
||||
size_t *bits)
|
||||
{
|
||||
psa_key_type_t type = psa_get_key_type( attributes );
|
||||
psa_key_type_t type = psa_get_key_type(attributes);
|
||||
|
||||
++mbedtls_test_driver_key_management_hooks.hits;
|
||||
mbedtls_test_driver_key_management_hooks.location = PSA_KEY_LOCATION_LOCAL_STORAGE;
|
||||
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_key_management_hooks.forced_status );
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_key_management_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( PSA_KEY_TYPE_IS_ECC( type ) )
|
||||
{
|
||||
if (PSA_KEY_TYPE_IS_ECC(type)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||
return( libtestdriver1_mbedtls_psa_ecp_import_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY))
|
||||
return libtestdriver1_mbedtls_psa_ecp_import_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
return( mbedtls_psa_ecp_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
return mbedtls_psa_ecp_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#endif
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_RSA( type ) )
|
||||
{
|
||||
} else if (PSA_KEY_TYPE_IS_RSA(type)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||
return( libtestdriver1_mbedtls_psa_rsa_import_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY))
|
||||
return libtestdriver1_mbedtls_psa_rsa_import_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
return( mbedtls_psa_rsa_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
return mbedtls_psa_rsa_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#endif
|
||||
}
|
||||
|
||||
(void)data;
|
||||
(void)data_length;
|
||||
(void)key_buffer;
|
||||
(void)key_buffer_size;
|
||||
(void)key_buffer_length;
|
||||
(void)bits;
|
||||
(void)type;
|
||||
(void) data;
|
||||
(void) data_length;
|
||||
(void) key_buffer;
|
||||
(void) key_buffer_size;
|
||||
(void) key_buffer_length;
|
||||
(void) bits;
|
||||
(void) type;
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
|
||||
@@ -330,7 +333,7 @@ psa_status_t mbedtls_test_opaque_import_key(
|
||||
size_t *bits)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_type_t type = psa_get_key_type( attributes );
|
||||
psa_key_type_t type = psa_get_key_type(attributes);
|
||||
/* This buffer will be used as an intermediate placeholder for
|
||||
* the clear key till we wrap it */
|
||||
uint8_t *key_buffer_temp;
|
||||
@@ -338,331 +341,329 @@ psa_status_t mbedtls_test_opaque_import_key(
|
||||
++mbedtls_test_driver_key_management_hooks.hits;
|
||||
mbedtls_test_driver_key_management_hooks.location = PSA_CRYPTO_TEST_DRIVER_LOCATION;
|
||||
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_key_management_hooks.forced_status );
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_key_management_hooks.forced_status;
|
||||
}
|
||||
|
||||
key_buffer_temp = mbedtls_calloc( 1, key_buffer_size );
|
||||
if( key_buffer_temp == NULL )
|
||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
key_buffer_temp = mbedtls_calloc(1, key_buffer_size);
|
||||
if (key_buffer_temp == NULL) {
|
||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) )
|
||||
{
|
||||
*bits = PSA_BYTES_TO_BITS( data_length );
|
||||
if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type)) {
|
||||
*bits = PSA_BYTES_TO_BITS(data_length);
|
||||
|
||||
status = psa_validate_unstructured_key_bit_size( type,
|
||||
*bits );
|
||||
if( status != PSA_SUCCESS )
|
||||
status = psa_validate_unstructured_key_bit_size(type,
|
||||
*bits);
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
if( data_length > key_buffer_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (data_length > key_buffer_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
/* Copy the key material accounting for opaque key padding. */
|
||||
memcpy( key_buffer_temp, data, data_length );
|
||||
memcpy(key_buffer_temp, data, data_length);
|
||||
*key_buffer_length = data_length;
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_ECC( type ) )
|
||||
{
|
||||
} else if (PSA_KEY_TYPE_IS_ECC(type)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||
(defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY))
|
||||
status = libtestdriver1_mbedtls_psa_ecp_import_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits );
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
status = mbedtls_psa_ecp_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits );
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#else
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_RSA( type ) )
|
||||
{
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
} else if (PSA_KEY_TYPE_IS_RSA(type)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||
(defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY))
|
||||
status = libtestdriver1_mbedtls_psa_rsa_import_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits );
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
status = mbedtls_psa_rsa_import_key(
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits );
|
||||
attributes,
|
||||
data, data_length,
|
||||
key_buffer_temp, key_buffer_size,
|
||||
key_buffer_length, bits);
|
||||
#else
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
if( status != PSA_SUCCESS )
|
||||
goto exit;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (status != PSA_SUCCESS) {
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
status = PSA_ERROR_INVALID_ARGUMENT;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
status = mbedtls_test_opaque_wrap_key( key_buffer_temp, *key_buffer_length,
|
||||
key_buffer, key_buffer_size, key_buffer_length );
|
||||
status = mbedtls_test_opaque_wrap_key(key_buffer_temp, *key_buffer_length,
|
||||
key_buffer, key_buffer_size, key_buffer_length);
|
||||
exit:
|
||||
mbedtls_free( key_buffer_temp );
|
||||
return( status );
|
||||
mbedtls_free(key_buffer_temp);
|
||||
return status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_export_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
uint8_t *data, size_t data_size, size_t *data_length )
|
||||
uint8_t *data, size_t data_size, size_t *data_length)
|
||||
{
|
||||
if( key_length == sizeof( psa_drv_slot_number_t ) )
|
||||
{
|
||||
if (key_length == sizeof(psa_drv_slot_number_t)) {
|
||||
/* Assume this is a builtin key based on the key material length. */
|
||||
psa_drv_slot_number_t slot_number = *( ( psa_drv_slot_number_t* ) key );
|
||||
psa_drv_slot_number_t slot_number = *((psa_drv_slot_number_t *) key);
|
||||
|
||||
switch( slot_number )
|
||||
{
|
||||
switch (slot_number) {
|
||||
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT:
|
||||
/* This is the ECDSA slot. Verify the key's attributes before
|
||||
* returning the private key. */
|
||||
if( psa_get_key_type( attributes ) !=
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( psa_get_key_bits( attributes ) != 256 )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( psa_get_key_algorithm( attributes ) !=
|
||||
PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( ( psa_get_key_usage_flags( attributes ) &
|
||||
PSA_KEY_USAGE_EXPORT ) == 0 )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if (psa_get_key_type(attributes) !=
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if (psa_get_key_bits(attributes) != 256) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if (psa_get_key_algorithm(attributes) !=
|
||||
PSA_ALG_ECDSA(PSA_ALG_ANY_HASH)) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if ((psa_get_key_usage_flags(attributes) &
|
||||
PSA_KEY_USAGE_EXPORT) == 0) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
|
||||
if( data_size < sizeof( mbedtls_test_driver_ecdsa_key ) )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (data_size < sizeof(mbedtls_test_driver_ecdsa_key)) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( data, mbedtls_test_driver_ecdsa_key,
|
||||
sizeof( mbedtls_test_driver_ecdsa_key ) );
|
||||
*data_length = sizeof( mbedtls_test_driver_ecdsa_key );
|
||||
return( PSA_SUCCESS );
|
||||
memcpy(data, mbedtls_test_driver_ecdsa_key,
|
||||
sizeof(mbedtls_test_driver_ecdsa_key));
|
||||
*data_length = sizeof(mbedtls_test_driver_ecdsa_key);
|
||||
return PSA_SUCCESS;
|
||||
|
||||
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT:
|
||||
/* This is the AES slot. Verify the key's attributes before
|
||||
* returning the key. */
|
||||
if( psa_get_key_type( attributes ) != PSA_KEY_TYPE_AES )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( psa_get_key_bits( attributes ) != 128 )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( psa_get_key_algorithm( attributes ) != PSA_ALG_CTR )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( ( psa_get_key_usage_flags( attributes ) &
|
||||
PSA_KEY_USAGE_EXPORT ) == 0 )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if (psa_get_key_type(attributes) != PSA_KEY_TYPE_AES) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if (psa_get_key_bits(attributes) != 128) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if (psa_get_key_algorithm(attributes) != PSA_ALG_CTR) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if ((psa_get_key_usage_flags(attributes) &
|
||||
PSA_KEY_USAGE_EXPORT) == 0) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
|
||||
if( data_size < sizeof( mbedtls_test_driver_aes_key ) )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (data_size < sizeof(mbedtls_test_driver_aes_key)) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( data, mbedtls_test_driver_aes_key,
|
||||
sizeof( mbedtls_test_driver_aes_key ) );
|
||||
*data_length = sizeof( mbedtls_test_driver_aes_key );
|
||||
return( PSA_SUCCESS );
|
||||
memcpy(data, mbedtls_test_driver_aes_key,
|
||||
sizeof(mbedtls_test_driver_aes_key));
|
||||
*data_length = sizeof(mbedtls_test_driver_aes_key);
|
||||
return PSA_SUCCESS;
|
||||
|
||||
default:
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
return PSA_ERROR_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
/* This buffer will be used as an intermediate placeholder for
|
||||
* the opaque key till we unwrap the key into key_buffer */
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_type_t type = psa_get_key_type( attributes );
|
||||
psa_key_type_t type = psa_get_key_type(attributes);
|
||||
|
||||
if( PSA_KEY_TYPE_IS_UNSTRUCTURED( type ) ||
|
||||
PSA_KEY_TYPE_IS_RSA( type ) ||
|
||||
PSA_KEY_TYPE_IS_ECC( type ) )
|
||||
{
|
||||
status = mbedtls_test_opaque_unwrap_key( key, key_length,
|
||||
data, data_size, data_length );
|
||||
return( status );
|
||||
if (PSA_KEY_TYPE_IS_UNSTRUCTURED(type) ||
|
||||
PSA_KEY_TYPE_IS_RSA(type) ||
|
||||
PSA_KEY_TYPE_IS_ECC(type)) {
|
||||
status = mbedtls_test_opaque_unwrap_key(key, key_length,
|
||||
data, data_size, data_length);
|
||||
return status;
|
||||
}
|
||||
}
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_export_public_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
uint8_t *data, size_t data_size, size_t *data_length )
|
||||
uint8_t *data, size_t data_size, size_t *data_length)
|
||||
{
|
||||
++mbedtls_test_driver_key_management_hooks.hits;
|
||||
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_key_management_hooks.forced_status );
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_key_management_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_output != NULL )
|
||||
{
|
||||
if( mbedtls_test_driver_key_management_hooks.forced_output_length >
|
||||
data_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
memcpy( data, mbedtls_test_driver_key_management_hooks.forced_output,
|
||||
mbedtls_test_driver_key_management_hooks.forced_output_length );
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_output != NULL) {
|
||||
if (mbedtls_test_driver_key_management_hooks.forced_output_length >
|
||||
data_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
memcpy(data, mbedtls_test_driver_key_management_hooks.forced_output,
|
||||
mbedtls_test_driver_key_management_hooks.forced_output_length);
|
||||
*data_length = mbedtls_test_driver_key_management_hooks.forced_output_length;
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
psa_key_type_t key_type = psa_get_key_type( attributes );
|
||||
psa_key_type_t key_type = psa_get_key_type(attributes);
|
||||
|
||||
if( PSA_KEY_TYPE_IS_ECC( key_type ) )
|
||||
{
|
||||
if (PSA_KEY_TYPE_IS_ECC(key_type)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||
return( libtestdriver1_mbedtls_psa_ecp_export_public_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY))
|
||||
return libtestdriver1_mbedtls_psa_ecp_export_public_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
return( mbedtls_psa_ecp_export_public_key(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
return mbedtls_psa_ecp_export_public_key(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length);
|
||||
#endif
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_RSA( key_type ) )
|
||||
{
|
||||
} else if (PSA_KEY_TYPE_IS_RSA(key_type)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||
return( libtestdriver1_mbedtls_psa_rsa_export_public_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY))
|
||||
return libtestdriver1_mbedtls_psa_rsa_export_public_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
return( mbedtls_psa_rsa_export_public_key(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
return mbedtls_psa_rsa_export_public_key(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
data, data_size, data_length);
|
||||
#endif
|
||||
}
|
||||
|
||||
(void)key_buffer;
|
||||
(void)key_buffer_size;
|
||||
(void)key_type;
|
||||
(void) key_buffer;
|
||||
(void) key_buffer_size;
|
||||
(void) key_type;
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_export_public_key(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key, size_t key_length,
|
||||
uint8_t *data, size_t data_size, size_t *data_length )
|
||||
uint8_t *data, size_t data_size, size_t *data_length)
|
||||
{
|
||||
if( key_length != sizeof( psa_drv_slot_number_t ) )
|
||||
{
|
||||
if (key_length != sizeof(psa_drv_slot_number_t)) {
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
psa_key_type_t key_type = psa_get_key_type( attributes );
|
||||
psa_key_type_t key_type = psa_get_key_type(attributes);
|
||||
uint8_t *key_buffer_temp;
|
||||
|
||||
key_buffer_temp = mbedtls_calloc( 1, key_length );
|
||||
if( key_buffer_temp == NULL )
|
||||
return( PSA_ERROR_INSUFFICIENT_MEMORY );
|
||||
key_buffer_temp = mbedtls_calloc(1, key_length);
|
||||
if (key_buffer_temp == NULL) {
|
||||
return PSA_ERROR_INSUFFICIENT_MEMORY;
|
||||
}
|
||||
|
||||
if( PSA_KEY_TYPE_IS_ECC( key_type ) )
|
||||
{
|
||||
status = mbedtls_test_opaque_unwrap_key( key, key_length,
|
||||
key_buffer_temp, key_length, data_length );
|
||||
if( status == PSA_SUCCESS )
|
||||
{
|
||||
if (PSA_KEY_TYPE_IS_ECC(key_type)) {
|
||||
status = mbedtls_test_opaque_unwrap_key(key, key_length,
|
||||
key_buffer_temp, key_length, data_length);
|
||||
if (status == PSA_SUCCESS) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY) )
|
||||
(defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_ECC_PUBLIC_KEY))
|
||||
status = libtestdriver1_mbedtls_psa_ecp_export_public_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length );
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_ECC_PUBLIC_KEY)
|
||||
status = mbedtls_psa_ecp_export_public_key(
|
||||
attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length );
|
||||
attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length);
|
||||
#else
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_RSA( key_type ) )
|
||||
{
|
||||
status = mbedtls_test_opaque_unwrap_key( key, key_length,
|
||||
key_buffer_temp, key_length, data_length );
|
||||
if( status == PSA_SUCCESS )
|
||||
{
|
||||
} else if (PSA_KEY_TYPE_IS_RSA(key_type)) {
|
||||
status = mbedtls_test_opaque_unwrap_key(key, key_length,
|
||||
key_buffer_temp, key_length, data_length);
|
||||
if (status == PSA_SUCCESS) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY) )
|
||||
(defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_ACCEL_KEY_TYPE_RSA_PUBLIC_KEY))
|
||||
status = libtestdriver1_mbedtls_psa_rsa_export_public_key(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length );
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_KEY_PAIR) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
defined(MBEDTLS_PSA_BUILTIN_KEY_TYPE_RSA_PUBLIC_KEY)
|
||||
status = mbedtls_psa_rsa_export_public_key(
|
||||
attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length );
|
||||
attributes,
|
||||
key_buffer_temp, *data_length,
|
||||
data, data_size, data_length);
|
||||
#else
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
(void)key;
|
||||
(void)key_type;
|
||||
(void) key;
|
||||
(void) key_type;
|
||||
}
|
||||
mbedtls_free( key_buffer_temp );
|
||||
return( status );
|
||||
mbedtls_free(key_buffer_temp);
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Assume this is a builtin key based on the key material length. */
|
||||
psa_drv_slot_number_t slot_number = *( ( psa_drv_slot_number_t* ) key );
|
||||
switch( slot_number )
|
||||
{
|
||||
psa_drv_slot_number_t slot_number = *((psa_drv_slot_number_t *) key);
|
||||
switch (slot_number) {
|
||||
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT:
|
||||
/* This is the ECDSA slot. Verify the key's attributes before
|
||||
* returning the public key. */
|
||||
if( psa_get_key_type( attributes ) !=
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( psa_get_key_bits( attributes ) != 256 )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if( psa_get_key_algorithm( attributes ) !=
|
||||
PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) )
|
||||
return( PSA_ERROR_CORRUPTION_DETECTED );
|
||||
if (psa_get_key_type(attributes) !=
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1)) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if (psa_get_key_bits(attributes) != 256) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
if (psa_get_key_algorithm(attributes) !=
|
||||
PSA_ALG_ECDSA(PSA_ALG_ANY_HASH)) {
|
||||
return PSA_ERROR_CORRUPTION_DETECTED;
|
||||
}
|
||||
|
||||
if( data_size < sizeof( mbedtls_test_driver_ecdsa_pubkey ) )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (data_size < sizeof(mbedtls_test_driver_ecdsa_pubkey)) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( data, mbedtls_test_driver_ecdsa_pubkey,
|
||||
sizeof( mbedtls_test_driver_ecdsa_pubkey ) );
|
||||
*data_length = sizeof( mbedtls_test_driver_ecdsa_pubkey );
|
||||
return( PSA_SUCCESS );
|
||||
memcpy(data, mbedtls_test_driver_ecdsa_pubkey,
|
||||
sizeof(mbedtls_test_driver_ecdsa_pubkey));
|
||||
*data_length = sizeof(mbedtls_test_driver_ecdsa_pubkey);
|
||||
return PSA_SUCCESS;
|
||||
|
||||
default:
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
return PSA_ERROR_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -679,49 +680,50 @@ psa_status_t mbedtls_test_opaque_export_public_key(
|
||||
psa_status_t mbedtls_test_opaque_get_builtin_key(
|
||||
psa_drv_slot_number_t slot_number,
|
||||
psa_key_attributes_t *attributes,
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length )
|
||||
uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length)
|
||||
{
|
||||
switch( slot_number )
|
||||
{
|
||||
switch (slot_number) {
|
||||
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT:
|
||||
psa_set_key_type( attributes, PSA_KEY_TYPE_AES );
|
||||
psa_set_key_bits( attributes, 128 );
|
||||
psa_set_key_type(attributes, PSA_KEY_TYPE_AES);
|
||||
psa_set_key_bits(attributes, 128);
|
||||
psa_set_key_usage_flags(
|
||||
attributes,
|
||||
PSA_KEY_USAGE_ENCRYPT |
|
||||
PSA_KEY_USAGE_DECRYPT |
|
||||
PSA_KEY_USAGE_EXPORT );
|
||||
psa_set_key_algorithm( attributes, PSA_ALG_CTR );
|
||||
PSA_KEY_USAGE_EXPORT);
|
||||
psa_set_key_algorithm(attributes, PSA_ALG_CTR);
|
||||
|
||||
if( key_buffer_size < sizeof( psa_drv_slot_number_t ) )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (key_buffer_size < sizeof(psa_drv_slot_number_t)) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
*( (psa_drv_slot_number_t*) key_buffer ) =
|
||||
*((psa_drv_slot_number_t *) key_buffer) =
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_AES_KEY_SLOT;
|
||||
*key_buffer_length = sizeof( psa_drv_slot_number_t );
|
||||
return( PSA_SUCCESS );
|
||||
*key_buffer_length = sizeof(psa_drv_slot_number_t);
|
||||
return PSA_SUCCESS;
|
||||
case PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT:
|
||||
psa_set_key_type(
|
||||
attributes,
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR( PSA_ECC_FAMILY_SECP_R1 ) );
|
||||
psa_set_key_bits( attributes, 256 );
|
||||
PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_SECP_R1));
|
||||
psa_set_key_bits(attributes, 256);
|
||||
psa_set_key_usage_flags(
|
||||
attributes,
|
||||
PSA_KEY_USAGE_SIGN_HASH |
|
||||
PSA_KEY_USAGE_VERIFY_HASH |
|
||||
PSA_KEY_USAGE_EXPORT );
|
||||
PSA_KEY_USAGE_EXPORT);
|
||||
psa_set_key_algorithm(
|
||||
attributes, PSA_ALG_ECDSA( PSA_ALG_ANY_HASH ) );
|
||||
attributes, PSA_ALG_ECDSA(PSA_ALG_ANY_HASH));
|
||||
|
||||
if( key_buffer_size < sizeof( psa_drv_slot_number_t ) )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (key_buffer_size < sizeof(psa_drv_slot_number_t)) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
*( (psa_drv_slot_number_t*) key_buffer ) =
|
||||
*((psa_drv_slot_number_t *) key_buffer) =
|
||||
PSA_CRYPTO_TEST_DRIVER_BUILTIN_ECDSA_KEY_SLOT;
|
||||
*key_buffer_length = sizeof( psa_drv_slot_number_t );
|
||||
return( PSA_SUCCESS );
|
||||
*key_buffer_length = sizeof(psa_drv_slot_number_t);
|
||||
return PSA_SUCCESS;
|
||||
default:
|
||||
return( PSA_ERROR_DOES_NOT_EXIST );
|
||||
return PSA_ERROR_DOES_NOT_EXIST;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -736,13 +738,14 @@ psa_status_t mbedtls_test_opaque_copy_key(
|
||||
* copied keys. This could change when the opaque test driver is extended
|
||||
* to support SE with storage, or to emulate an SE without storage but
|
||||
* still holding some slot references */
|
||||
if( source_key_length > key_buffer_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (source_key_length > key_buffer_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( key_buffer, source_key, source_key_length );
|
||||
memcpy(key_buffer, source_key, source_key_length);
|
||||
*key_buffer_length = source_key_length;
|
||||
(void)attributes;
|
||||
return( PSA_SUCCESS );
|
||||
(void) attributes;
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
@@ -40,31 +40,28 @@ psa_status_t mbedtls_test_transparent_mac_compute(
|
||||
size_t input_length,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length )
|
||||
size_t *mac_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_compute(
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size, alg,
|
||||
input, input_length,
|
||||
mac, mac_size, mac_length );
|
||||
mac, mac_size, mac_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_compute(
|
||||
attributes, key_buffer, key_buffer_size, alg,
|
||||
input, input_length,
|
||||
mac, mac_size, mac_length );
|
||||
mac, mac_size, mac_length);
|
||||
#else
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -79,7 +76,7 @@ psa_status_t mbedtls_test_transparent_mac_compute(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_sign_setup(
|
||||
@@ -87,28 +84,25 @@ psa_status_t mbedtls_test_transparent_mac_sign_setup(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_sign_setup(
|
||||
operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size, alg );
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_sign_setup(
|
||||
operation, attributes, key_buffer, key_buffer_size, alg );
|
||||
operation, attributes, key_buffer, key_buffer_size, alg);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
@@ -119,7 +113,7 @@ psa_status_t mbedtls_test_transparent_mac_sign_setup(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_verify_setup(
|
||||
@@ -127,28 +121,25 @@ psa_status_t mbedtls_test_transparent_mac_verify_setup(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_verify_setup(
|
||||
operation,
|
||||
(const libtestdriver1_psa_key_attributes_t *)attributes,
|
||||
key_buffer, key_buffer_size, alg );
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size, alg);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_verify_setup(
|
||||
operation, attributes, key_buffer, key_buffer_size, alg );
|
||||
operation, attributes, key_buffer, key_buffer_size, alg);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
@@ -159,32 +150,29 @@ psa_status_t mbedtls_test_transparent_mac_verify_setup(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_update(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length )
|
||||
size_t input_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_update(
|
||||
operation, input, input_length );
|
||||
operation, input, input_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_update(
|
||||
operation, input, input_length );
|
||||
operation, input, input_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) input;
|
||||
@@ -193,33 +181,30 @@ psa_status_t mbedtls_test_transparent_mac_update(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_sign_finish(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length )
|
||||
size_t *mac_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_sign_finish(
|
||||
operation, mac, mac_size, mac_length );
|
||||
operation, mac, mac_size, mac_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_sign_finish(
|
||||
operation, mac, mac_size, mac_length );
|
||||
operation, mac, mac_size, mac_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) mac;
|
||||
@@ -229,32 +214,29 @@ psa_status_t mbedtls_test_transparent_mac_sign_finish(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_verify_finish(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *mac,
|
||||
size_t mac_length )
|
||||
size_t mac_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_verify_finish(
|
||||
operation, mac, mac_length );
|
||||
operation, mac, mac_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_verify_finish(
|
||||
operation, mac, mac_length );
|
||||
operation, mac, mac_length);
|
||||
#else
|
||||
(void) operation;
|
||||
(void) mac;
|
||||
@@ -263,35 +245,32 @@ psa_status_t mbedtls_test_transparent_mac_verify_finish(
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_mac_abort(
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation )
|
||||
mbedtls_transparent_test_driver_mac_operation_t *operation)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_abort( operation );
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
libtestdriver1_mbedtls_psa_mac_abort(operation);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_MAC)
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_psa_mac_abort( operation );
|
||||
mbedtls_psa_mac_abort(operation);
|
||||
#else
|
||||
(void) operation;
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_compute(
|
||||
@@ -303,17 +282,14 @@ psa_status_t mbedtls_test_opaque_mac_compute(
|
||||
size_t input_length,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length )
|
||||
size_t *mac_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
(void) key_buffer_size;
|
||||
@@ -326,7 +302,7 @@ psa_status_t mbedtls_test_opaque_mac_compute(
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_sign_setup(
|
||||
@@ -334,17 +310,14 @@ psa_status_t mbedtls_test_opaque_mac_sign_setup(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -353,7 +326,7 @@ psa_status_t mbedtls_test_opaque_mac_sign_setup(
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_verify_setup(
|
||||
@@ -361,17 +334,14 @@ psa_status_t mbedtls_test_opaque_mac_verify_setup(
|
||||
const psa_key_attributes_t *attributes,
|
||||
const uint8_t *key_buffer,
|
||||
size_t key_buffer_size,
|
||||
psa_algorithm_t alg )
|
||||
psa_algorithm_t alg)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
@@ -380,47 +350,41 @@ psa_status_t mbedtls_test_opaque_mac_verify_setup(
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_update(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *input,
|
||||
size_t input_length )
|
||||
size_t input_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) input;
|
||||
(void) input_length;
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_sign_finish(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
uint8_t *mac,
|
||||
size_t mac_size,
|
||||
size_t *mac_length )
|
||||
size_t *mac_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) mac;
|
||||
(void) mac_size;
|
||||
@@ -428,49 +392,43 @@ psa_status_t mbedtls_test_opaque_mac_sign_finish(
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_verify_finish(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation,
|
||||
const uint8_t *mac,
|
||||
size_t mac_length )
|
||||
size_t mac_length)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) operation;
|
||||
(void) mac;
|
||||
(void) mac_length;
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_mac_abort(
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation )
|
||||
mbedtls_opaque_test_driver_mac_operation_t *operation)
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.hits++;
|
||||
|
||||
if( mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS )
|
||||
{
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mbedtls_test_driver_mac_hooks.forced_status != PSA_SUCCESS) {
|
||||
mbedtls_test_driver_mac_hooks.driver_status =
|
||||
mbedtls_test_driver_mac_hooks.forced_status;
|
||||
} else {
|
||||
(void) operation;
|
||||
mbedtls_test_driver_mac_hooks.driver_status = PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
return( mbedtls_test_driver_mac_hooks.driver_status );
|
||||
return mbedtls_test_driver_mac_hooks.driver_status;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
@@ -60,72 +60,63 @@ psa_status_t sign_hash(
|
||||
size_t hash_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length )
|
||||
size_t *signature_length)
|
||||
{
|
||||
if( attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR )
|
||||
{
|
||||
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ||
|
||||
PSA_ALG_IS_RSA_PSS( alg) )
|
||||
{
|
||||
if (attributes->core.type == PSA_KEY_TYPE_RSA_KEY_PAIR) {
|
||||
if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
|
||||
PSA_ALG_IS_RSA_PSS(alg)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) )
|
||||
return( libtestdriver1_mbedtls_psa_rsa_sign_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS))
|
||||
return libtestdriver1_mbedtls_psa_rsa_sign_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||
return( mbedtls_psa_rsa_sign_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||
return mbedtls_psa_rsa_sign_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length);
|
||||
#endif
|
||||
} else {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
}
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
|
||||
{
|
||||
if( PSA_ALG_IS_ECDSA( alg ) )
|
||||
{
|
||||
} else if (PSA_KEY_TYPE_IS_ECC(attributes->core.type)) {
|
||||
if (PSA_ALG_IS_ECDSA(alg)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) )
|
||||
return( libtestdriver1_mbedtls_psa_ecdsa_sign_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA))
|
||||
return libtestdriver1_mbedtls_psa_ecdsa_sign_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||
return( mbedtls_psa_ecdsa_sign_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||
return mbedtls_psa_ecdsa_sign_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
} else {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
(void)attributes;
|
||||
(void)key_buffer;
|
||||
(void)key_buffer_size;
|
||||
(void)alg;
|
||||
(void)hash;
|
||||
(void)hash_length;
|
||||
(void)signature;
|
||||
(void)signature_size;
|
||||
(void)signature_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
(void) key_buffer_size;
|
||||
(void) alg;
|
||||
(void) hash;
|
||||
(void) hash_length;
|
||||
(void) signature;
|
||||
(void) signature_size;
|
||||
(void) signature_length;
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t verify_hash(
|
||||
@@ -136,71 +127,62 @@ psa_status_t verify_hash(
|
||||
const uint8_t *hash,
|
||||
size_t hash_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length )
|
||||
size_t signature_length)
|
||||
{
|
||||
if( PSA_KEY_TYPE_IS_RSA( attributes->core.type ) )
|
||||
{
|
||||
if( PSA_ALG_IS_RSA_PKCS1V15_SIGN( alg ) ||
|
||||
PSA_ALG_IS_RSA_PSS( alg) )
|
||||
{
|
||||
if (PSA_KEY_TYPE_IS_RSA(attributes->core.type)) {
|
||||
if (PSA_ALG_IS_RSA_PKCS1V15_SIGN(alg) ||
|
||||
PSA_ALG_IS_RSA_PSS(alg)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS) )
|
||||
return( libtestdriver1_mbedtls_psa_rsa_verify_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS))
|
||||
return libtestdriver1_mbedtls_psa_rsa_verify_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PKCS1V15_SIGN) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||
return( mbedtls_psa_rsa_verify_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_RSA_PSS)
|
||||
return mbedtls_psa_rsa_verify_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length);
|
||||
#endif
|
||||
} else {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
}
|
||||
}
|
||||
else if( PSA_KEY_TYPE_IS_ECC( attributes->core.type ) )
|
||||
{
|
||||
if( PSA_ALG_IS_ECDSA( alg ) )
|
||||
{
|
||||
} else if (PSA_KEY_TYPE_IS_ECC(attributes->core.type)) {
|
||||
if (PSA_ALG_IS_ECDSA(alg)) {
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
( defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA) )
|
||||
return( libtestdriver1_mbedtls_psa_ecdsa_verify_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length ) );
|
||||
(defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA))
|
||||
return libtestdriver1_mbedtls_psa_ecdsa_verify_hash(
|
||||
(const libtestdriver1_psa_key_attributes_t *) attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_ALG_ECDSA) || \
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||
return( mbedtls_psa_ecdsa_verify_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length ) );
|
||||
defined(MBEDTLS_PSA_BUILTIN_ALG_DETERMINISTIC_ECDSA)
|
||||
return mbedtls_psa_ecdsa_verify_hash(
|
||||
attributes,
|
||||
key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
return( PSA_ERROR_INVALID_ARGUMENT );
|
||||
} else {
|
||||
return PSA_ERROR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
(void)attributes;
|
||||
(void)key_buffer;
|
||||
(void)key_buffer_size;
|
||||
(void)alg;
|
||||
(void)hash;
|
||||
(void)hash_length;
|
||||
(void)signature;
|
||||
(void)signature_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
(void) attributes;
|
||||
(void) key_buffer;
|
||||
(void) key_buffer_size;
|
||||
(void) alg;
|
||||
(void) hash;
|
||||
(void) hash_length;
|
||||
(void) signature;
|
||||
(void) signature_length;
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_sign_message(
|
||||
@@ -212,7 +194,7 @@ psa_status_t mbedtls_test_transparent_signature_sign_message(
|
||||
size_t input_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length )
|
||||
size_t *signature_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
size_t hash_length;
|
||||
@@ -220,41 +202,43 @@ psa_status_t mbedtls_test_transparent_signature_sign_message(
|
||||
|
||||
++mbedtls_test_driver_signature_sign_hooks.hits;
|
||||
|
||||
if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_signature_sign_hooks.forced_status );
|
||||
if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_signature_sign_hooks.forced_status;
|
||||
}
|
||||
|
||||
if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL )
|
||||
{
|
||||
if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) {
|
||||
if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
memcpy( signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
|
||||
mbedtls_test_driver_signature_sign_hooks.forced_output_length );
|
||||
memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
|
||||
mbedtls_test_driver_signature_sign_hooks.forced_output_length);
|
||||
*signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
|
||||
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
status = libtestdriver1_mbedtls_psa_hash_compute(
|
||||
PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
|
||||
hash, sizeof( hash ), &hash_length );
|
||||
PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
|
||||
hash, sizeof(hash), &hash_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
status = mbedtls_psa_hash_compute(
|
||||
PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
|
||||
hash, sizeof( hash ), &hash_length );
|
||||
PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
|
||||
hash, sizeof(hash), &hash_length);
|
||||
#else
|
||||
(void) input;
|
||||
(void) input_length;
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
if( status != PSA_SUCCESS )
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return( sign_hash( attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length ) );
|
||||
return sign_hash(attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length);
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_sign_message(
|
||||
@@ -266,7 +250,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_message(
|
||||
size_t input_length,
|
||||
uint8_t *signature,
|
||||
size_t signature_size,
|
||||
size_t *signature_length )
|
||||
size_t *signature_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
@@ -278,7 +262,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_message(
|
||||
(void) signature_size;
|
||||
(void) signature_length;
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_verify_message(
|
||||
@@ -289,7 +273,7 @@ psa_status_t mbedtls_test_transparent_signature_verify_message(
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length )
|
||||
size_t signature_length)
|
||||
{
|
||||
psa_status_t status = PSA_ERROR_CORRUPTION_DETECTED;
|
||||
size_t hash_length;
|
||||
@@ -297,29 +281,31 @@ psa_status_t mbedtls_test_transparent_signature_verify_message(
|
||||
|
||||
++mbedtls_test_driver_signature_verify_hooks.hits;
|
||||
|
||||
if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_signature_verify_hooks.forced_status );
|
||||
if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_signature_verify_hooks.forced_status;
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_LIBTESTDRIVER1) && \
|
||||
defined(LIBTESTDRIVER1_MBEDTLS_PSA_BUILTIN_HASH)
|
||||
status = libtestdriver1_mbedtls_psa_hash_compute(
|
||||
PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
|
||||
hash, sizeof( hash ), &hash_length );
|
||||
PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
|
||||
hash, sizeof(hash), &hash_length);
|
||||
#elif defined(MBEDTLS_PSA_BUILTIN_HASH)
|
||||
status = mbedtls_psa_hash_compute(
|
||||
PSA_ALG_SIGN_GET_HASH( alg ), input, input_length,
|
||||
hash, sizeof( hash ), &hash_length );
|
||||
PSA_ALG_SIGN_GET_HASH(alg), input, input_length,
|
||||
hash, sizeof(hash), &hash_length);
|
||||
#else
|
||||
(void) input;
|
||||
(void) input_length;
|
||||
status = PSA_ERROR_NOT_SUPPORTED;
|
||||
#endif
|
||||
if( status != PSA_SUCCESS )
|
||||
if (status != PSA_SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
|
||||
return( verify_hash( attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length ) );
|
||||
return verify_hash(attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length);
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_verify_message(
|
||||
@@ -330,7 +316,7 @@ psa_status_t mbedtls_test_opaque_signature_verify_message(
|
||||
const uint8_t *input,
|
||||
size_t input_length,
|
||||
const uint8_t *signature,
|
||||
size_t signature_length )
|
||||
size_t signature_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
@@ -341,7 +327,7 @@ psa_status_t mbedtls_test_opaque_signature_verify_message(
|
||||
(void) signature;
|
||||
(void) signature_length;
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_sign_hash(
|
||||
@@ -349,26 +335,27 @@ psa_status_t mbedtls_test_transparent_signature_sign_hash(
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length )
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length)
|
||||
{
|
||||
++mbedtls_test_driver_signature_sign_hooks.hits;
|
||||
|
||||
if( mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_signature_sign_hooks.forced_status );
|
||||
|
||||
if( mbedtls_test_driver_signature_sign_hooks.forced_output != NULL )
|
||||
{
|
||||
if( mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size )
|
||||
return( PSA_ERROR_BUFFER_TOO_SMALL );
|
||||
memcpy( signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
|
||||
mbedtls_test_driver_signature_sign_hooks.forced_output_length );
|
||||
*signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
|
||||
return( PSA_SUCCESS );
|
||||
if (mbedtls_test_driver_signature_sign_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_signature_sign_hooks.forced_status;
|
||||
}
|
||||
|
||||
return( sign_hash( attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length ) );
|
||||
if (mbedtls_test_driver_signature_sign_hooks.forced_output != NULL) {
|
||||
if (mbedtls_test_driver_signature_sign_hooks.forced_output_length > signature_size) {
|
||||
return PSA_ERROR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
memcpy(signature, mbedtls_test_driver_signature_sign_hooks.forced_output,
|
||||
mbedtls_test_driver_signature_sign_hooks.forced_output_length);
|
||||
*signature_length = mbedtls_test_driver_signature_sign_hooks.forced_output_length;
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
|
||||
return sign_hash(attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_size, signature_length);
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_sign_hash(
|
||||
@@ -376,7 +363,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_hash(
|
||||
const uint8_t *key, size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length )
|
||||
uint8_t *signature, size_t signature_size, size_t *signature_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
@@ -388,7 +375,7 @@ psa_status_t mbedtls_test_opaque_signature_sign_hash(
|
||||
(void) signature_size;
|
||||
(void) signature_length;
|
||||
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_transparent_signature_verify_hash(
|
||||
@@ -396,16 +383,17 @@ psa_status_t mbedtls_test_transparent_signature_verify_hash(
|
||||
const uint8_t *key_buffer, size_t key_buffer_size,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
const uint8_t *signature, size_t signature_length )
|
||||
const uint8_t *signature, size_t signature_length)
|
||||
{
|
||||
++mbedtls_test_driver_signature_verify_hooks.hits;
|
||||
|
||||
if( mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS )
|
||||
return( mbedtls_test_driver_signature_verify_hooks.forced_status );
|
||||
if (mbedtls_test_driver_signature_verify_hooks.forced_status != PSA_SUCCESS) {
|
||||
return mbedtls_test_driver_signature_verify_hooks.forced_status;
|
||||
}
|
||||
|
||||
return verify_hash( attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length );
|
||||
return verify_hash(attributes, key_buffer, key_buffer_size,
|
||||
alg, hash, hash_length,
|
||||
signature, signature_length);
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_test_opaque_signature_verify_hash(
|
||||
@@ -413,7 +401,7 @@ psa_status_t mbedtls_test_opaque_signature_verify_hash(
|
||||
const uint8_t *key, size_t key_length,
|
||||
psa_algorithm_t alg,
|
||||
const uint8_t *hash, size_t hash_length,
|
||||
const uint8_t *signature, size_t signature_length )
|
||||
const uint8_t *signature, size_t signature_length)
|
||||
{
|
||||
(void) attributes;
|
||||
(void) key;
|
||||
@@ -423,7 +411,7 @@ psa_status_t mbedtls_test_opaque_signature_verify_hash(
|
||||
(void) hash_length;
|
||||
(void) signature;
|
||||
(void) signature_length;
|
||||
return( PSA_ERROR_NOT_SUPPORTED );
|
||||
return PSA_ERROR_NOT_SUPPORTED;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_DRIVERS && PSA_CRYPTO_DRIVER_TEST */
|
||||
|
||||
@@ -28,29 +28,30 @@
|
||||
|
||||
static int test_insecure_external_rng_enabled = 0;
|
||||
|
||||
void mbedtls_test_enable_insecure_external_rng( void )
|
||||
void mbedtls_test_enable_insecure_external_rng(void)
|
||||
{
|
||||
test_insecure_external_rng_enabled = 1;
|
||||
}
|
||||
|
||||
void mbedtls_test_disable_insecure_external_rng( void )
|
||||
void mbedtls_test_disable_insecure_external_rng(void)
|
||||
{
|
||||
test_insecure_external_rng_enabled = 0;
|
||||
}
|
||||
|
||||
psa_status_t mbedtls_psa_external_get_random(
|
||||
mbedtls_psa_external_random_context_t *context,
|
||||
uint8_t *output, size_t output_size, size_t *output_length )
|
||||
uint8_t *output, size_t output_size, size_t *output_length)
|
||||
{
|
||||
(void) context;
|
||||
|
||||
if( !test_insecure_external_rng_enabled )
|
||||
return( PSA_ERROR_INSUFFICIENT_ENTROPY );
|
||||
if (!test_insecure_external_rng_enabled) {
|
||||
return PSA_ERROR_INSUFFICIENT_ENTROPY;
|
||||
}
|
||||
|
||||
/* This implementation is for test purposes only!
|
||||
* Use the libc non-cryptographic random generator. */
|
||||
mbedtls_test_rnd_std_rand( NULL, output, output_size );
|
||||
mbedtls_test_rnd_std_rand(NULL, output, output_size);
|
||||
*output_length = output_size;
|
||||
return( PSA_SUCCESS );
|
||||
return PSA_SUCCESS;
|
||||
}
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG */
|
||||
|
||||
@@ -32,40 +32,40 @@ mbedtls_test_info_t mbedtls_test_info;
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Helper Functions */
|
||||
|
||||
int mbedtls_test_platform_setup( void )
|
||||
int mbedtls_test_platform_setup(void)
|
||||
{
|
||||
int ret = 0;
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
ret = mbedtls_platform_setup( &platform_ctx );
|
||||
ret = mbedtls_platform_setup(&platform_ctx);
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
return( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mbedtls_test_platform_teardown( void )
|
||||
void mbedtls_test_platform_teardown(void)
|
||||
{
|
||||
#if defined(MBEDTLS_PLATFORM_C)
|
||||
mbedtls_platform_teardown( &platform_ctx );
|
||||
mbedtls_platform_teardown(&platform_ctx);
|
||||
#endif /* MBEDTLS_PLATFORM_C */
|
||||
}
|
||||
|
||||
int mbedtls_test_ascii2uc(const char c, unsigned char *uc)
|
||||
{
|
||||
if( ( c >= '0' ) && ( c <= '9' ) )
|
||||
if ((c >= '0') && (c <= '9')) {
|
||||
*uc = c - '0';
|
||||
else if( ( c >= 'a' ) && ( c <= 'f' ) )
|
||||
} else if ((c >= 'a') && (c <= 'f')) {
|
||||
*uc = c - 'a' + 10;
|
||||
else if( ( c >= 'A' ) && ( c <= 'F' ) )
|
||||
} else if ((c >= 'A') && (c <= 'F')) {
|
||||
*uc = c - 'A' + 10;
|
||||
else
|
||||
return( -1 );
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mbedtls_test_fail( const char *test, int line_no, const char* filename )
|
||||
void mbedtls_test_fail(const char *test, int line_no, const char *filename)
|
||||
{
|
||||
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
|
||||
{
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return;
|
||||
@@ -76,7 +76,7 @@ void mbedtls_test_fail( const char *test, int line_no, const char* filename )
|
||||
mbedtls_test_info.filename = filename;
|
||||
}
|
||||
|
||||
void mbedtls_test_skip( const char *test, int line_no, const char* filename )
|
||||
void mbedtls_test_skip(const char *test, int line_no, const char *filename)
|
||||
{
|
||||
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SKIPPED;
|
||||
mbedtls_test_info.test = test;
|
||||
@@ -84,7 +84,7 @@ void mbedtls_test_skip( const char *test, int line_no, const char* filename )
|
||||
mbedtls_test_info.filename = filename;
|
||||
}
|
||||
|
||||
void mbedtls_test_set_step( unsigned long step )
|
||||
void mbedtls_test_set_step(unsigned long step)
|
||||
{
|
||||
mbedtls_test_info.step = step;
|
||||
}
|
||||
@@ -93,201 +93,205 @@ void mbedtls_test_set_step( unsigned long step )
|
||||
unsigned mbedtls_test_case_uses_negative_0 = 0;
|
||||
#endif
|
||||
|
||||
void mbedtls_test_info_reset( void )
|
||||
void mbedtls_test_info_reset(void)
|
||||
{
|
||||
mbedtls_test_info.result = MBEDTLS_TEST_RESULT_SUCCESS;
|
||||
mbedtls_test_info.step = (unsigned long)( -1 );
|
||||
mbedtls_test_info.step = (unsigned long) (-1);
|
||||
mbedtls_test_info.test = 0;
|
||||
mbedtls_test_info.line_no = 0;
|
||||
mbedtls_test_info.filename = 0;
|
||||
memset( mbedtls_test_info.line1, 0, sizeof( mbedtls_test_info.line1 ) );
|
||||
memset( mbedtls_test_info.line2, 0, sizeof( mbedtls_test_info.line2 ) );
|
||||
memset(mbedtls_test_info.line1, 0, sizeof(mbedtls_test_info.line1));
|
||||
memset(mbedtls_test_info.line2, 0, sizeof(mbedtls_test_info.line2));
|
||||
#if defined(MBEDTLS_BIGNUM_C)
|
||||
mbedtls_test_case_uses_negative_0 = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
int mbedtls_test_equal( const char *test, int line_no, const char* filename,
|
||||
unsigned long long value1, unsigned long long value2 )
|
||||
int mbedtls_test_equal(const char *test, int line_no, const char *filename,
|
||||
unsigned long long value1, unsigned long long value2)
|
||||
{
|
||||
TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
|
||||
TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
|
||||
TEST_CF_PUBLIC(&value1, sizeof(value1));
|
||||
TEST_CF_PUBLIC(&value2, sizeof(value2));
|
||||
|
||||
if( value1 == value2 )
|
||||
return( 1 );
|
||||
if (value1 == value2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
|
||||
{
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
mbedtls_test_fail( test, line_no, filename );
|
||||
(void) mbedtls_snprintf( mbedtls_test_info.line1,
|
||||
sizeof( mbedtls_test_info.line1 ),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
value1, (long long) value1 );
|
||||
(void) mbedtls_snprintf( mbedtls_test_info.line2,
|
||||
sizeof( mbedtls_test_info.line2 ),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
value2, (long long) value2 );
|
||||
return( 0 );
|
||||
mbedtls_test_fail(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line1,
|
||||
sizeof(mbedtls_test_info.line1),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
value1, (long long) value1);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line2,
|
||||
sizeof(mbedtls_test_info.line2),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
value2, (long long) value2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_le_u( const char *test, int line_no, const char* filename,
|
||||
unsigned long long value1, unsigned long long value2 )
|
||||
int mbedtls_test_le_u(const char *test, int line_no, const char *filename,
|
||||
unsigned long long value1, unsigned long long value2)
|
||||
{
|
||||
TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
|
||||
TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
|
||||
TEST_CF_PUBLIC(&value1, sizeof(value1));
|
||||
TEST_CF_PUBLIC(&value2, sizeof(value2));
|
||||
|
||||
if( value1 <= value2 )
|
||||
return( 1 );
|
||||
if (value1 <= value2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
|
||||
{
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
mbedtls_test_fail( test, line_no, filename );
|
||||
(void) mbedtls_snprintf( mbedtls_test_info.line1,
|
||||
sizeof( mbedtls_test_info.line1 ),
|
||||
"lhs = 0x%016llx = %llu",
|
||||
value1, value1 );
|
||||
(void) mbedtls_snprintf( mbedtls_test_info.line2,
|
||||
sizeof( mbedtls_test_info.line2 ),
|
||||
"rhs = 0x%016llx = %llu",
|
||||
value2, value2 );
|
||||
return( 0 );
|
||||
mbedtls_test_fail(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line1,
|
||||
sizeof(mbedtls_test_info.line1),
|
||||
"lhs = 0x%016llx = %llu",
|
||||
value1, value1);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line2,
|
||||
sizeof(mbedtls_test_info.line2),
|
||||
"rhs = 0x%016llx = %llu",
|
||||
value2, value2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_le_s( const char *test, int line_no, const char* filename,
|
||||
long long value1, long long value2 )
|
||||
int mbedtls_test_le_s(const char *test, int line_no, const char *filename,
|
||||
long long value1, long long value2)
|
||||
{
|
||||
TEST_CF_PUBLIC( &value1, sizeof( value1 ) );
|
||||
TEST_CF_PUBLIC( &value2, sizeof( value2 ) );
|
||||
TEST_CF_PUBLIC(&value1, sizeof(value1));
|
||||
TEST_CF_PUBLIC(&value2, sizeof(value2));
|
||||
|
||||
if( value1 <= value2 )
|
||||
return( 1 );
|
||||
if (value1 <= value2) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED )
|
||||
{
|
||||
if (mbedtls_test_info.result == MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* We've already recorded the test as having failed. Don't
|
||||
* overwrite any previous information about the failure. */
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
mbedtls_test_fail( test, line_no, filename );
|
||||
(void) mbedtls_snprintf( mbedtls_test_info.line1,
|
||||
sizeof( mbedtls_test_info.line1 ),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value1, value1 );
|
||||
(void) mbedtls_snprintf( mbedtls_test_info.line2,
|
||||
sizeof( mbedtls_test_info.line2 ),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value2, value2 );
|
||||
return( 0 );
|
||||
mbedtls_test_fail(test, line_no, filename);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line1,
|
||||
sizeof(mbedtls_test_info.line1),
|
||||
"lhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value1, value1);
|
||||
(void) mbedtls_snprintf(mbedtls_test_info.line2,
|
||||
sizeof(mbedtls_test_info.line2),
|
||||
"rhs = 0x%016llx = %lld",
|
||||
(unsigned long long) value2, value2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_unhexify( unsigned char *obuf,
|
||||
size_t obufmax,
|
||||
const char *ibuf,
|
||||
size_t *len )
|
||||
int mbedtls_test_unhexify(unsigned char *obuf,
|
||||
size_t obufmax,
|
||||
const char *ibuf,
|
||||
size_t *len)
|
||||
{
|
||||
unsigned char uc, uc2;
|
||||
|
||||
*len = strlen( ibuf );
|
||||
*len = strlen(ibuf);
|
||||
|
||||
/* Must be even number of bytes. */
|
||||
if ( ( *len ) & 1 )
|
||||
return( -1 );
|
||||
if ((*len) & 1) {
|
||||
return -1;
|
||||
}
|
||||
*len /= 2;
|
||||
|
||||
if ( (*len) > obufmax )
|
||||
return( -1 );
|
||||
|
||||
while( *ibuf != 0 )
|
||||
{
|
||||
if ( mbedtls_test_ascii2uc( *(ibuf++), &uc ) != 0 )
|
||||
return( -1 );
|
||||
|
||||
if ( mbedtls_test_ascii2uc( *(ibuf++), &uc2 ) != 0 )
|
||||
return( -1 );
|
||||
|
||||
*(obuf++) = ( uc << 4 ) | uc2;
|
||||
if ((*len) > obufmax) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
while (*ibuf != 0) {
|
||||
if (mbedtls_test_ascii2uc(*(ibuf++), &uc) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mbedtls_test_ascii2uc(*(ibuf++), &uc2) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
*(obuf++) = (uc << 4) | uc2;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void mbedtls_test_hexify( unsigned char *obuf,
|
||||
const unsigned char *ibuf,
|
||||
int len )
|
||||
void mbedtls_test_hexify(unsigned char *obuf,
|
||||
const unsigned char *ibuf,
|
||||
int len)
|
||||
{
|
||||
unsigned char l, h;
|
||||
|
||||
while( len != 0 )
|
||||
{
|
||||
while (len != 0) {
|
||||
h = *ibuf / 16;
|
||||
l = *ibuf % 16;
|
||||
|
||||
if( h < 10 )
|
||||
if (h < 10) {
|
||||
*obuf++ = '0' + h;
|
||||
else
|
||||
} else {
|
||||
*obuf++ = 'a' + h - 10;
|
||||
}
|
||||
|
||||
if( l < 10 )
|
||||
if (l < 10) {
|
||||
*obuf++ = '0' + l;
|
||||
else
|
||||
} else {
|
||||
*obuf++ = 'a' + l - 10;
|
||||
}
|
||||
|
||||
++ibuf;
|
||||
len--;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned char *mbedtls_test_zero_alloc( size_t len )
|
||||
unsigned char *mbedtls_test_zero_alloc(size_t len)
|
||||
{
|
||||
void *p;
|
||||
size_t actual_len = ( len != 0 ) ? len : 1;
|
||||
size_t actual_len = (len != 0) ? len : 1;
|
||||
|
||||
p = mbedtls_calloc( 1, actual_len );
|
||||
TEST_HELPER_ASSERT( p != NULL );
|
||||
p = mbedtls_calloc(1, actual_len);
|
||||
TEST_HELPER_ASSERT(p != NULL);
|
||||
|
||||
memset( p, 0x00, actual_len );
|
||||
memset(p, 0x00, actual_len);
|
||||
|
||||
return( p );
|
||||
return p;
|
||||
}
|
||||
|
||||
unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen )
|
||||
unsigned char *mbedtls_test_unhexify_alloc(const char *ibuf, size_t *olen)
|
||||
{
|
||||
unsigned char *obuf;
|
||||
size_t len;
|
||||
|
||||
*olen = strlen( ibuf ) / 2;
|
||||
*olen = strlen(ibuf) / 2;
|
||||
|
||||
if( *olen == 0 )
|
||||
return( mbedtls_test_zero_alloc( *olen ) );
|
||||
if (*olen == 0) {
|
||||
return mbedtls_test_zero_alloc(*olen);
|
||||
}
|
||||
|
||||
obuf = mbedtls_calloc( 1, *olen );
|
||||
TEST_HELPER_ASSERT( obuf != NULL );
|
||||
TEST_HELPER_ASSERT( mbedtls_test_unhexify( obuf, *olen, ibuf, &len ) == 0 );
|
||||
obuf = mbedtls_calloc(1, *olen);
|
||||
TEST_HELPER_ASSERT(obuf != NULL);
|
||||
TEST_HELPER_ASSERT(mbedtls_test_unhexify(obuf, *olen, ibuf, &len) == 0);
|
||||
|
||||
return( obuf );
|
||||
return obuf;
|
||||
}
|
||||
|
||||
int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
uint32_t a_len, uint32_t b_len )
|
||||
int mbedtls_test_hexcmp(uint8_t *a, uint8_t *b,
|
||||
uint32_t a_len, uint32_t b_len)
|
||||
{
|
||||
int ret = 0;
|
||||
uint32_t i = 0;
|
||||
|
||||
if( a_len != b_len )
|
||||
return( -1 );
|
||||
if (a_len != b_len) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( i = 0; i < a_len; i++ )
|
||||
{
|
||||
if( a[i] != b[i] )
|
||||
{
|
||||
for (i = 0; i < a_len; i++) {
|
||||
if (a[i] != b[i]) {
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@@ -296,8 +300,8 @@ int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b,
|
||||
}
|
||||
|
||||
#if defined(MBEDTLS_TEST_HOOKS)
|
||||
void mbedtls_test_err_add_check( int high, int low,
|
||||
const char *file, int line )
|
||||
void mbedtls_test_err_add_check(int high, int low,
|
||||
const char *file, int line)
|
||||
{
|
||||
/* Error codes are always negative (a value of zero is a success) however
|
||||
* their positive opposites can be easier to understand. The following
|
||||
@@ -311,42 +315,33 @@ void mbedtls_test_err_add_check( int high, int low,
|
||||
* and module-dependent error code (bits 7..11)).
|
||||
* l = low level error code.
|
||||
*/
|
||||
if ( high > -0x1000 && high != 0 )
|
||||
/* high < 0001000000000000
|
||||
* No high level module ID bits are set.
|
||||
*/
|
||||
{
|
||||
mbedtls_test_fail( "'high' is not a high-level error code",
|
||||
line, file );
|
||||
}
|
||||
else if ( high < -0x7F80 )
|
||||
/* high > 0111111110000000
|
||||
* Error code is greater than the largest allowed high level module ID.
|
||||
*/
|
||||
{
|
||||
mbedtls_test_fail( "'high' error code is greater than 15 bits",
|
||||
line, file );
|
||||
}
|
||||
else if ( ( high & 0x7F ) != 0 )
|
||||
/* high & 0000000001111111
|
||||
* Error code contains low level error code bits.
|
||||
*/
|
||||
{
|
||||
mbedtls_test_fail( "'high' contains a low-level error code",
|
||||
line, file );
|
||||
}
|
||||
else if ( low < -0x007F )
|
||||
/* low > 0000000001111111
|
||||
* Error code contains high or module level error code bits.
|
||||
*/
|
||||
{
|
||||
mbedtls_test_fail( "'low' error code is greater than 7 bits",
|
||||
line, file );
|
||||
}
|
||||
else if ( low > 0 )
|
||||
{
|
||||
mbedtls_test_fail( "'low' error code is greater than zero",
|
||||
line, file );
|
||||
if (high > -0x1000 && high != 0) {
|
||||
/* high < 0001000000000000
|
||||
* No high level module ID bits are set.
|
||||
*/
|
||||
mbedtls_test_fail("'high' is not a high-level error code",
|
||||
line, file);
|
||||
} else if (high < -0x7F80) {
|
||||
/* high > 0111111110000000
|
||||
* Error code is greater than the largest allowed high level module ID.
|
||||
*/
|
||||
mbedtls_test_fail("'high' error code is greater than 15 bits",
|
||||
line, file);
|
||||
} else if ((high & 0x7F) != 0) {
|
||||
/* high & 0000000001111111
|
||||
* Error code contains low level error code bits.
|
||||
*/
|
||||
mbedtls_test_fail("'high' contains a low-level error code",
|
||||
line, file);
|
||||
} else if (low < -0x007F) {
|
||||
/* low > 0000000001111111
|
||||
* Error code contains high or module level error code bits.
|
||||
*/
|
||||
mbedtls_test_fail("'low' error code is greater than 7 bits",
|
||||
line, file);
|
||||
} else if (low > 0) {
|
||||
mbedtls_test_fail("'low' error code is greater than zero",
|
||||
line, file);
|
||||
}
|
||||
}
|
||||
#endif /* MBEDTLS_TEST_HOOKS */
|
||||
|
||||
@@ -36,96 +36,106 @@
|
||||
static mbedtls_svc_key_id_t key_ids_used_in_test[9];
|
||||
static size_t num_key_ids_used;
|
||||
|
||||
int mbedtls_test_uses_key_id( mbedtls_svc_key_id_t key_id )
|
||||
int mbedtls_test_uses_key_id(mbedtls_svc_key_id_t key_id)
|
||||
{
|
||||
size_t i;
|
||||
if( MBEDTLS_SVC_KEY_ID_GET_KEY_ID( key_id ) >
|
||||
PSA_MAX_PERSISTENT_KEY_IDENTIFIER )
|
||||
{
|
||||
if (MBEDTLS_SVC_KEY_ID_GET_KEY_ID(key_id) >
|
||||
PSA_MAX_PERSISTENT_KEY_IDENTIFIER) {
|
||||
/* Don't touch key id values that designate non-key files. */
|
||||
return( 1 );
|
||||
return 1;
|
||||
}
|
||||
for( i = 0; i < num_key_ids_used ; i++ )
|
||||
{
|
||||
if( mbedtls_svc_key_id_equal( key_id, key_ids_used_in_test[i] ) )
|
||||
return( 1 );
|
||||
for (i = 0; i < num_key_ids_used; i++) {
|
||||
if (mbedtls_svc_key_id_equal(key_id, key_ids_used_in_test[i])) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (num_key_ids_used == ARRAY_LENGTH(key_ids_used_in_test)) {
|
||||
return 0;
|
||||
}
|
||||
if( num_key_ids_used == ARRAY_LENGTH( key_ids_used_in_test ) )
|
||||
return( 0 );
|
||||
key_ids_used_in_test[num_key_ids_used] = key_id;
|
||||
++num_key_ids_used;
|
||||
return( 1 );
|
||||
return 1;
|
||||
}
|
||||
|
||||
void mbedtls_test_psa_purge_key_storage( void )
|
||||
void mbedtls_test_psa_purge_key_storage(void)
|
||||
{
|
||||
size_t i;
|
||||
for( i = 0; i < num_key_ids_used; i++ )
|
||||
psa_destroy_persistent_key( key_ids_used_in_test[i] );
|
||||
for (i = 0; i < num_key_ids_used; i++) {
|
||||
psa_destroy_persistent_key(key_ids_used_in_test[i]);
|
||||
}
|
||||
num_key_ids_used = 0;
|
||||
}
|
||||
|
||||
void mbedtls_test_psa_purge_key_cache( void )
|
||||
void mbedtls_test_psa_purge_key_cache(void)
|
||||
{
|
||||
size_t i;
|
||||
for( i = 0; i < num_key_ids_used; i++ )
|
||||
psa_purge_key( key_ids_used_in_test[i] );
|
||||
for (i = 0; i < num_key_ids_used; i++) {
|
||||
psa_purge_key(key_ids_used_in_test[i]);
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_STORAGE_C */
|
||||
|
||||
const char *mbedtls_test_helper_is_psa_leaking( void )
|
||||
const char *mbedtls_test_helper_is_psa_leaking(void)
|
||||
{
|
||||
mbedtls_psa_stats_t stats;
|
||||
|
||||
mbedtls_psa_get_stats( &stats );
|
||||
mbedtls_psa_get_stats(&stats);
|
||||
|
||||
if( stats.volatile_slots != 0 )
|
||||
return( "A volatile slot has not been closed properly." );
|
||||
if( stats.persistent_slots != 0 )
|
||||
return( "A persistent slot has not been closed properly." );
|
||||
if( stats.external_slots != 0 )
|
||||
return( "An external slot has not been closed properly." );
|
||||
if( stats.half_filled_slots != 0 )
|
||||
return( "A half-filled slot has not been cleared properly." );
|
||||
if( stats.locked_slots != 0 )
|
||||
return( "Some slots are still marked as locked." );
|
||||
if (stats.volatile_slots != 0) {
|
||||
return "A volatile slot has not been closed properly.";
|
||||
}
|
||||
if (stats.persistent_slots != 0) {
|
||||
return "A persistent slot has not been closed properly.";
|
||||
}
|
||||
if (stats.external_slots != 0) {
|
||||
return "An external slot has not been closed properly.";
|
||||
}
|
||||
if (stats.half_filled_slots != 0) {
|
||||
return "A half-filled slot has not been cleared properly.";
|
||||
}
|
||||
if (stats.locked_slots != 0) {
|
||||
return "Some slots are still marked as locked.";
|
||||
}
|
||||
|
||||
return( NULL );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#if defined(RECORD_PSA_STATUS_COVERAGE_LOG)
|
||||
/** Name of the file where return statuses are logged by #RECORD_STATUS. */
|
||||
#define STATUS_LOG_FILE_NAME "statuses.log"
|
||||
|
||||
psa_status_t mbedtls_test_record_status( psa_status_t status,
|
||||
const char *func,
|
||||
const char *file, int line,
|
||||
const char *expr )
|
||||
psa_status_t mbedtls_test_record_status(psa_status_t status,
|
||||
const char *func,
|
||||
const char *file, int line,
|
||||
const char *expr)
|
||||
{
|
||||
/* We open the log file on first use.
|
||||
* We never close the log file, so the record_status feature is not
|
||||
* compatible with resource leak detectors such as Asan.
|
||||
*/
|
||||
static FILE *log;
|
||||
if( log == NULL )
|
||||
log = fopen( STATUS_LOG_FILE_NAME, "a" );
|
||||
fprintf( log, "%d:%s:%s:%d:%s\n", (int) status, func, file, line, expr );
|
||||
return( status );
|
||||
if (log == NULL) {
|
||||
log = fopen(STATUS_LOG_FILE_NAME, "a");
|
||||
}
|
||||
fprintf(log, "%d:%s:%s:%d:%s\n", (int) status, func, file, line, expr);
|
||||
return status;
|
||||
}
|
||||
#endif /* defined(RECORD_PSA_STATUS_COVERAGE_LOG) */
|
||||
|
||||
psa_key_usage_t mbedtls_test_update_key_usage_flags( psa_key_usage_t usage_flags )
|
||||
psa_key_usage_t mbedtls_test_update_key_usage_flags(psa_key_usage_t usage_flags)
|
||||
{
|
||||
psa_key_usage_t updated_usage = usage_flags;
|
||||
|
||||
if( usage_flags & PSA_KEY_USAGE_SIGN_HASH )
|
||||
if (usage_flags & PSA_KEY_USAGE_SIGN_HASH) {
|
||||
updated_usage |= PSA_KEY_USAGE_SIGN_MESSAGE;
|
||||
}
|
||||
|
||||
if( usage_flags & PSA_KEY_USAGE_VERIFY_HASH )
|
||||
if (usage_flags & PSA_KEY_USAGE_VERIFY_HASH) {
|
||||
updated_usage |= PSA_KEY_USAGE_VERIFY_MESSAGE;
|
||||
}
|
||||
|
||||
return( updated_usage );
|
||||
return updated_usage;
|
||||
}
|
||||
|
||||
#endif /* MBEDTLS_PSA_CRYPTO_C */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -37,109 +37,111 @@
|
||||
|
||||
#include <mbedtls/entropy.h>
|
||||
|
||||
int mbedtls_test_rnd_std_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
int mbedtls_test_rnd_std_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len)
|
||||
{
|
||||
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
|
||||
size_t i;
|
||||
|
||||
if( rng_state != NULL )
|
||||
if (rng_state != NULL) {
|
||||
rng_state = NULL;
|
||||
}
|
||||
|
||||
for( i = 0; i < len; ++i )
|
||||
for (i = 0; i < len; ++i) {
|
||||
output[i] = rand();
|
||||
}
|
||||
#else
|
||||
if( rng_state != NULL )
|
||||
if (rng_state != NULL) {
|
||||
rng_state = NULL;
|
||||
}
|
||||
|
||||
arc4random_buf( output, len );
|
||||
arc4random_buf(output, len);
|
||||
#endif /* !OpenBSD && !NetBSD */
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_rnd_zero_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
int mbedtls_test_rnd_zero_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len)
|
||||
{
|
||||
if( rng_state != NULL )
|
||||
if (rng_state != NULL) {
|
||||
rng_state = NULL;
|
||||
}
|
||||
|
||||
memset( output, 0, len );
|
||||
memset(output, 0, len);
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_rnd_buffer_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
int mbedtls_test_rnd_buffer_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len)
|
||||
{
|
||||
mbedtls_test_rnd_buf_info *info = (mbedtls_test_rnd_buf_info *) rng_state;
|
||||
size_t use_len;
|
||||
|
||||
if( rng_state == NULL )
|
||||
return( mbedtls_test_rnd_std_rand( NULL, output, len ) );
|
||||
if (rng_state == NULL) {
|
||||
return mbedtls_test_rnd_std_rand(NULL, output, len);
|
||||
}
|
||||
|
||||
use_len = len;
|
||||
if( len > info->length )
|
||||
if (len > info->length) {
|
||||
use_len = info->length;
|
||||
}
|
||||
|
||||
if( use_len )
|
||||
{
|
||||
memcpy( output, info->buf, use_len );
|
||||
if (use_len) {
|
||||
memcpy(output, info->buf, use_len);
|
||||
info->buf += use_len;
|
||||
info->length -= use_len;
|
||||
}
|
||||
|
||||
if( len - use_len > 0 )
|
||||
{
|
||||
if( info->fallback_f_rng != NULL )
|
||||
{
|
||||
return( info->fallback_f_rng( info->fallback_p_rng,
|
||||
output + use_len,
|
||||
len - use_len ) );
|
||||
if (len - use_len > 0) {
|
||||
if (info->fallback_f_rng != NULL) {
|
||||
return info->fallback_f_rng(info->fallback_p_rng,
|
||||
output + use_len,
|
||||
len - use_len);
|
||||
} else {
|
||||
return MBEDTLS_ERR_ENTROPY_SOURCE_FAILED;
|
||||
}
|
||||
else
|
||||
return( MBEDTLS_ERR_ENTROPY_SOURCE_FAILED );
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
int mbedtls_test_rnd_pseudo_rand( void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len )
|
||||
int mbedtls_test_rnd_pseudo_rand(void *rng_state,
|
||||
unsigned char *output,
|
||||
size_t len)
|
||||
{
|
||||
mbedtls_test_rnd_pseudo_info *info =
|
||||
(mbedtls_test_rnd_pseudo_info *) rng_state;
|
||||
uint32_t i, *k, sum, delta=0x9E3779B9;
|
||||
uint32_t i, *k, sum, delta = 0x9E3779B9;
|
||||
unsigned char result[4], *out = output;
|
||||
|
||||
if( rng_state == NULL )
|
||||
return( mbedtls_test_rnd_std_rand( NULL, output, len ) );
|
||||
if (rng_state == NULL) {
|
||||
return mbedtls_test_rnd_std_rand(NULL, output, len);
|
||||
}
|
||||
|
||||
k = info->key;
|
||||
|
||||
while( len > 0 )
|
||||
{
|
||||
size_t use_len = ( len > 4 ) ? 4 : len;
|
||||
while (len > 0) {
|
||||
size_t use_len = (len > 4) ? 4 : len;
|
||||
sum = 0;
|
||||
|
||||
for( i = 0; i < 32; i++ )
|
||||
{
|
||||
info->v0 += ( ( ( info->v1 << 4 ) ^ ( info->v1 >> 5 ) )
|
||||
+ info->v1 ) ^ ( sum + k[sum & 3] );
|
||||
for (i = 0; i < 32; i++) {
|
||||
info->v0 += (((info->v1 << 4) ^ (info->v1 >> 5))
|
||||
+ info->v1) ^ (sum + k[sum & 3]);
|
||||
sum += delta;
|
||||
info->v1 += ( ( ( info->v0 << 4 ) ^ ( info->v0 >> 5 ) )
|
||||
+ info->v0 ) ^ ( sum + k[( sum>>11 ) & 3] );
|
||||
info->v1 += (((info->v0 << 4) ^ (info->v0 >> 5))
|
||||
+ info->v0) ^ (sum + k[(sum>>11) & 3]);
|
||||
}
|
||||
|
||||
PUT_UINT32_BE( info->v0, result, 0 );
|
||||
memcpy( out, result, use_len );
|
||||
PUT_UINT32_BE(info->v0, result, 0);
|
||||
memcpy(out, result, use_len);
|
||||
len -= use_len;
|
||||
out += 4;
|
||||
}
|
||||
|
||||
return( 0 );
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -70,8 +70,7 @@
|
||||
* indicate the exact location of the problematic call. To locate the error,
|
||||
* use a debugger and set a breakpoint on mbedtls_test_mutex_usage_error().
|
||||
*/
|
||||
enum value_of_mutex_is_valid_field
|
||||
{
|
||||
enum value_of_mutex_is_valid_field {
|
||||
/* Potential values for the is_valid field of mbedtls_threading_mutex_t.
|
||||
* Note that MUTEX_FREED must be 0 and MUTEX_IDLE must be 1 for
|
||||
* compatibility with threading_mutex_init_pthread() and
|
||||
@@ -82,12 +81,11 @@ enum value_of_mutex_is_valid_field
|
||||
MUTEX_LOCKED = 2, //!< Set by our lock
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void (*init)( mbedtls_threading_mutex_t * );
|
||||
void (*free)( mbedtls_threading_mutex_t * );
|
||||
int (*lock)( mbedtls_threading_mutex_t * );
|
||||
int (*unlock)( mbedtls_threading_mutex_t * );
|
||||
typedef struct {
|
||||
void (*init)(mbedtls_threading_mutex_t *);
|
||||
void (*free)(mbedtls_threading_mutex_t *);
|
||||
int (*lock)(mbedtls_threading_mutex_t *);
|
||||
int (*unlock)(mbedtls_threading_mutex_t *);
|
||||
} mutex_functions_t;
|
||||
static mutex_functions_t mutex_functions;
|
||||
|
||||
@@ -98,94 +96,96 @@ static mutex_functions_t mutex_functions;
|
||||
*/
|
||||
static int live_mutexes;
|
||||
|
||||
static void mbedtls_test_mutex_usage_error( mbedtls_threading_mutex_t *mutex,
|
||||
const char *msg )
|
||||
static void mbedtls_test_mutex_usage_error(mbedtls_threading_mutex_t *mutex,
|
||||
const char *msg)
|
||||
{
|
||||
(void) mutex;
|
||||
if( mbedtls_test_info.mutex_usage_error == NULL )
|
||||
if (mbedtls_test_info.mutex_usage_error == NULL) {
|
||||
mbedtls_test_info.mutex_usage_error = msg;
|
||||
mbedtls_fprintf( stdout, "[mutex: %s] ", msg );
|
||||
}
|
||||
mbedtls_fprintf(stdout, "[mutex: %s] ", msg);
|
||||
/* Don't mark the test as failed yet. This way, if the test fails later
|
||||
* for a functional reason, the test framework will report the message
|
||||
* and location for this functional reason. If the test passes,
|
||||
* mbedtls_test_mutex_usage_check() will mark it as failed. */
|
||||
}
|
||||
|
||||
static void mbedtls_test_wrap_mutex_init( mbedtls_threading_mutex_t *mutex )
|
||||
static void mbedtls_test_wrap_mutex_init(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
mutex_functions.init( mutex );
|
||||
if( mutex->is_valid )
|
||||
mutex_functions.init(mutex);
|
||||
if (mutex->is_valid) {
|
||||
++live_mutexes;
|
||||
}
|
||||
}
|
||||
|
||||
static void mbedtls_test_wrap_mutex_free( mbedtls_threading_mutex_t *mutex )
|
||||
static void mbedtls_test_wrap_mutex_free(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
switch( mutex->is_valid )
|
||||
{
|
||||
switch (mutex->is_valid) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error( mutex, "free without init or double free" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "free without init or double free");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
/* Do nothing. The underlying free function will reset is_valid
|
||||
* to 0. */
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mbedtls_test_mutex_usage_error( mutex, "free without unlock" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "free without unlock");
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
if( mutex->is_valid )
|
||||
if (mutex->is_valid) {
|
||||
--live_mutexes;
|
||||
mutex_functions.free( mutex );
|
||||
}
|
||||
mutex_functions.free(mutex);
|
||||
}
|
||||
|
||||
static int mbedtls_test_wrap_mutex_lock( mbedtls_threading_mutex_t *mutex )
|
||||
static int mbedtls_test_wrap_mutex_lock(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
int ret = mutex_functions.lock( mutex );
|
||||
switch( mutex->is_valid )
|
||||
{
|
||||
int ret = mutex_functions.lock(mutex);
|
||||
switch (mutex->is_valid) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error( mutex, "lock without init" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "lock without init");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
if( ret == 0 )
|
||||
if (ret == 0) {
|
||||
mutex->is_valid = 2;
|
||||
}
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
mbedtls_test_mutex_usage_error( mutex, "double lock" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "double lock");
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
return( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mbedtls_test_wrap_mutex_unlock( mbedtls_threading_mutex_t *mutex )
|
||||
static int mbedtls_test_wrap_mutex_unlock(mbedtls_threading_mutex_t *mutex)
|
||||
{
|
||||
int ret = mutex_functions.unlock( mutex );
|
||||
switch( mutex->is_valid )
|
||||
{
|
||||
int ret = mutex_functions.unlock(mutex);
|
||||
switch (mutex->is_valid) {
|
||||
case MUTEX_FREED:
|
||||
mbedtls_test_mutex_usage_error( mutex, "unlock without init" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "unlock without init");
|
||||
break;
|
||||
case MUTEX_IDLE:
|
||||
mbedtls_test_mutex_usage_error( mutex, "unlock without lock" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "unlock without lock");
|
||||
break;
|
||||
case MUTEX_LOCKED:
|
||||
if( ret == 0 )
|
||||
if (ret == 0) {
|
||||
mutex->is_valid = MUTEX_IDLE;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
mbedtls_test_mutex_usage_error( mutex, "corrupted state" );
|
||||
mbedtls_test_mutex_usage_error(mutex, "corrupted state");
|
||||
break;
|
||||
}
|
||||
return( ret );
|
||||
return ret;
|
||||
}
|
||||
|
||||
void mbedtls_test_mutex_usage_init( void )
|
||||
void mbedtls_test_mutex_usage_init(void)
|
||||
{
|
||||
mutex_functions.init = mbedtls_mutex_init;
|
||||
mutex_functions.free = mbedtls_mutex_free;
|
||||
@@ -197,25 +197,24 @@ void mbedtls_test_mutex_usage_init( void )
|
||||
mbedtls_mutex_unlock = &mbedtls_test_wrap_mutex_unlock;
|
||||
}
|
||||
|
||||
void mbedtls_test_mutex_usage_check( void )
|
||||
void mbedtls_test_mutex_usage_check(void)
|
||||
{
|
||||
if( live_mutexes != 0 )
|
||||
{
|
||||
if (live_mutexes != 0) {
|
||||
/* A positive number (more init than free) means that a mutex resource
|
||||
* is leaking (on platforms where a mutex consumes more than the
|
||||
* mbedtls_threading_mutex_t object itself). The rare case of a
|
||||
* negative number means a missing init somewhere. */
|
||||
mbedtls_fprintf( stdout, "[mutex: %d leaked] ", live_mutexes );
|
||||
mbedtls_fprintf(stdout, "[mutex: %d leaked] ", live_mutexes);
|
||||
live_mutexes = 0;
|
||||
if( mbedtls_test_info.mutex_usage_error == NULL )
|
||||
if (mbedtls_test_info.mutex_usage_error == NULL) {
|
||||
mbedtls_test_info.mutex_usage_error = "missing free";
|
||||
}
|
||||
}
|
||||
if( mbedtls_test_info.mutex_usage_error != NULL &&
|
||||
mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED )
|
||||
{
|
||||
if (mbedtls_test_info.mutex_usage_error != NULL &&
|
||||
mbedtls_test_info.result != MBEDTLS_TEST_RESULT_FAILED) {
|
||||
/* Functionally, the test passed. But there was a mutex usage error,
|
||||
* so mark the test as failed after all. */
|
||||
mbedtls_test_fail( "Mutex usage error", __LINE__, __FILE__ );
|
||||
mbedtls_test_fail("Mutex usage error", __LINE__, __FILE__);
|
||||
}
|
||||
mbedtls_test_info.mutex_usage_error = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user