mbedtls/tests/suites/test_suite_pkcs12.function
Gilles Peskine a844b4b370 No need to use MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED in tests
Initializing return status variables to CORRUPTION_DETECTED is a second line
of defense in library code in case there's a code path where we forget to
assign to the variable. This isn't useful in test code. In any case, here,
we might as well define the variable at the point of use.

This fixes a build error in configurations with MBEDTLS_ERROR_C and
MBEDTLS_PSA_CRYPTO_C both disabled, because then mbedtls/error.h isn't
included so MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED isn't defined.

Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
2022-09-15 21:05:04 +02:00

70 lines
1.7 KiB
Text

/* BEGIN_HEADER */
#include "mbedtls/pkcs12.h"
#include "common.h"
#include "legacy_or_psa.h"
typedef enum
{
USE_NULL_INPUT = 0,
USE_GIVEN_INPUT = 1,
} input_usage_method_t;
/* END_HEADER */
/* BEGIN_DEPENDENCIES
* depends_on:MBEDTLS_PKCS12_C
* END_DEPENDENCIES
*/
/* BEGIN_CASE */
void pkcs12_derive_key( int md_type, int key_size_arg,
data_t *password_arg, int password_usage,
data_t *salt_arg, int salt_usage,
int iterations,
data_t* expected_output, int expected_status )
{
unsigned char *output_data = NULL;
unsigned char *password = NULL;
size_t password_len = 0;
unsigned char *salt = NULL;
size_t salt_len = 0;
size_t key_size = key_size_arg;
if( password_usage == USE_GIVEN_INPUT )
password = password_arg->x;
password_len = password_arg->len;
if( salt_usage == USE_GIVEN_INPUT )
salt = salt_arg->x;
salt_len = salt_arg->len;
ASSERT_ALLOC( output_data, key_size );
int ret = mbedtls_pkcs12_derivation( output_data,
key_size,
password,
password_len,
salt,
salt_len,
md_type,
MBEDTLS_PKCS12_DERIVE_KEY,
iterations );
TEST_EQUAL( ret, expected_status );
if( expected_status == 0 )
{
ASSERT_COMPARE( expected_output->x, expected_output->len,
output_data, key_size );
}
exit:
mbedtls_free( output_data );
}
/* END_CASE */