mbedtls/tests/suites/test_suite_pkcs12.function
Paul Elliott 73051b4176 Rename (and relabel) pkcs12 test case
Remove surplus _test suffix. Change labeling from Pcks12 to PCKS#12 as
it should be.

Signed-off-by: Paul Elliott <paul.elliott@arm.com>
2021-12-13 11:14:45 +00:00

74 lines
1.8 KiB
Plaintext

/* BEGIN_HEADER */
#include "mbedtls/pkcs12.h"
#include "mbedtls/error.h"
typedef enum
{
USE_NULL_INPUT = 0,
USE_GIVEN_INPUT = 1,
USE_NULL_INPUT_WITH_SIZE = 2,
} 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, int expected_status )
{
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
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;
}
else if( password_usage == USE_NULL_INPUT_WITH_SIZE )
{
password_len = password_arg->len;
}
if( salt_usage == USE_GIVEN_INPUT )
{
salt = salt_arg->x;
salt_len = salt_arg->len;
}
else if( salt_usage == USE_NULL_INPUT_WITH_SIZE )
{
salt_len = salt_arg->len;
}
ASSERT_ALLOC( output_data, key_size );
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 );
exit:
mbedtls_free( output_data );
}
/* END_CASE */