2021-11-18 23:35:48 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "mbedtls/pkcs12.h"
|
|
|
|
#include "mbedtls/error.h"
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
USE_NULL_INPUT = 0,
|
|
|
|
USE_GIVEN_INPUT = 1,
|
|
|
|
} input_usage_method_t;
|
|
|
|
|
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_DEPENDENCIES
|
2021-11-30 17:21:27 +01:00
|
|
|
* depends_on:MBEDTLS_PKCS12_C
|
2021-11-18 23:35:48 +01:00
|
|
|
* END_DEPENDENCIES
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2021-11-30 17:31:10 +01:00
|
|
|
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 )
|
2021-11-18 23:35:48 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
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;
|
2021-11-30 17:39:51 +01:00
|
|
|
|
|
|
|
password_len = password_arg->len;
|
2021-11-18 23:35:48 +01:00
|
|
|
|
|
|
|
if( salt_usage == USE_GIVEN_INPUT )
|
|
|
|
salt = salt_arg->x;
|
2021-11-30 17:39:51 +01:00
|
|
|
|
|
|
|
salt_len = salt_arg->len;
|
2021-11-18 23:35:48 +01:00
|
|
|
|
|
|
|
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 */
|