blob: 385f86abb30e4fef5e6f1f9fd0304e88142a269c [file] [log] [blame]
Paul Elliott13d5a342021-11-18 22:35:48 +00001/* BEGIN_HEADER */
2#include "mbedtls/pkcs12.h"
3#include "mbedtls/error.h"
4
5typedef enum
6{
7 USE_NULL_INPUT = 0,
8 USE_GIVEN_INPUT = 1,
Paul Elliott13d5a342021-11-18 22:35:48 +00009} input_usage_method_t;
10
11/* END_HEADER */
12
13/* BEGIN_DEPENDENCIES
Paul Elliott8ca8f2d2021-11-30 16:21:27 +000014 * depends_on:MBEDTLS_PKCS12_C
Paul Elliott13d5a342021-11-18 22:35:48 +000015 * END_DEPENDENCIES
16 */
17
18/* BEGIN_CASE */
Paul Elliott73051b42021-11-30 16:31:10 +000019void pkcs12_derive_key( int md_type, int key_size_arg,
20 data_t *password_arg, int password_usage,
21 data_t *salt_arg, int salt_usage,
Paul Elliott5752b4b2021-12-03 18:55:31 +000022 int iterations,
23 data_t* expected_output, int expected_status )
Paul Elliott13d5a342021-11-18 22:35:48 +000024
25{
Paul Elliott13d5a342021-11-18 22:35:48 +000026 unsigned char *output_data = NULL;
27
28 unsigned char *password = NULL;
29 size_t password_len = 0;
30 unsigned char *salt = NULL;
31 size_t salt_len = 0;
32 size_t key_size = key_size_arg;
33
34 if( password_usage == USE_GIVEN_INPUT )
Paul Elliott13d5a342021-11-18 22:35:48 +000035 password = password_arg->x;
Paul Elliott270a2642021-11-30 16:39:51 +000036
37 password_len = password_arg->len;
Paul Elliott13d5a342021-11-18 22:35:48 +000038
39 if( salt_usage == USE_GIVEN_INPUT )
Paul Elliott13d5a342021-11-18 22:35:48 +000040 salt = salt_arg->x;
Paul Elliott270a2642021-11-30 16:39:51 +000041
42 salt_len = salt_arg->len;
Paul Elliott13d5a342021-11-18 22:35:48 +000043
44 ASSERT_ALLOC( output_data, key_size );
45
Gilles Peskined84ed272022-09-15 21:05:04 +020046 int ret = mbedtls_pkcs12_derivation( output_data,
47 key_size,
48 password,
49 password_len,
50 salt,
51 salt_len,
52 md_type,
53 MBEDTLS_PKCS12_DERIVE_KEY,
54 iterations );
Paul Elliott13d5a342021-11-18 22:35:48 +000055
56 TEST_EQUAL( ret, expected_status );
57
Paul Elliott5752b4b2021-12-03 18:55:31 +000058 if( expected_status == 0 )
59 {
60 ASSERT_COMPARE( expected_output->x, expected_output->len,
61 output_data, key_size );
62 }
63
Paul Elliott13d5a342021-11-18 22:35:48 +000064exit:
65 mbedtls_free( output_data );
66
67}
68/* END_CASE */