blob: 3fad814a5487998c9c5f6f563c8407e5bdd318f1 [file] [log] [blame]
Paul Elliottd6635432021-11-18 22:35:48 +00001/* BEGIN_HEADER */
2#include "mbedtls/pkcs12.h"
Paul Elliott6e7deb12021-12-03 18:55:31 +00003#include "common.h"
Paul Elliottd6635432021-11-18 22:35:48 +00004
Manuel Pégourié-Gonnard07018f92022-09-15 11:29:35 +02005#include "mbedtls/legacy_or_psa.h"
Andrzej Kurek7bd12c52022-08-24 10:47:10 -04006
Paul Elliottd6635432021-11-18 22:35:48 +00007typedef enum
8{
9 USE_NULL_INPUT = 0,
10 USE_GIVEN_INPUT = 1,
Paul Elliottd6635432021-11-18 22:35:48 +000011} input_usage_method_t;
12
13/* END_HEADER */
14
15/* BEGIN_DEPENDENCIES
Paul Elliott3584ae42021-11-30 16:21:27 +000016 * depends_on:MBEDTLS_PKCS12_C
Paul Elliottd6635432021-11-18 22:35:48 +000017 * END_DEPENDENCIES
18 */
19
20/* BEGIN_CASE */
Paul Elliottdf006952021-11-30 16:31:10 +000021void pkcs12_derive_key( int md_type, int key_size_arg,
22 data_t *password_arg, int password_usage,
23 data_t *salt_arg, int salt_usage,
Paul Elliott6e7deb12021-12-03 18:55:31 +000024 int iterations,
25 data_t* expected_output, int expected_status )
Paul Elliottd6635432021-11-18 22:35:48 +000026
27{
Paul Elliottd6635432021-11-18 22:35:48 +000028 unsigned char *output_data = NULL;
29
30 unsigned char *password = NULL;
31 size_t password_len = 0;
32 unsigned char *salt = NULL;
33 size_t salt_len = 0;
34 size_t key_size = key_size_arg;
35
36 if( password_usage == USE_GIVEN_INPUT )
Paul Elliottd6635432021-11-18 22:35:48 +000037 password = password_arg->x;
Paul Elliott4768a302021-11-30 16:39:51 +000038
39 password_len = password_arg->len;
Paul Elliottd6635432021-11-18 22:35:48 +000040
41 if( salt_usage == USE_GIVEN_INPUT )
Paul Elliottd6635432021-11-18 22:35:48 +000042 salt = salt_arg->x;
Paul Elliott4768a302021-11-30 16:39:51 +000043
44 salt_len = salt_arg->len;
Paul Elliottd6635432021-11-18 22:35:48 +000045
46 ASSERT_ALLOC( output_data, key_size );
47
Gilles Peskinea844b4b2022-09-15 21:05:04 +020048 int ret = mbedtls_pkcs12_derivation( output_data,
49 key_size,
50 password,
51 password_len,
52 salt,
53 salt_len,
54 md_type,
55 MBEDTLS_PKCS12_DERIVE_KEY,
56 iterations );
Paul Elliottd6635432021-11-18 22:35:48 +000057
58 TEST_EQUAL( ret, expected_status );
59
Paul Elliott6e7deb12021-12-03 18:55:31 +000060 if( expected_status == 0 )
61 {
62 ASSERT_COMPARE( expected_output->x, expected_output->len,
63 output_data, key_size );
64 }
65
Paul Elliottd6635432021-11-18 22:35:48 +000066exit:
67 mbedtls_free( output_data );
68
69}
70/* END_CASE */