blob: 2ed43693c171c872364bea963f72a1ebd252d1df [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,
22 int iterations, int expected_status )
Paul Elliott13d5a342021-11-18 22:35:48 +000023
24{
25 int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
26 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
46 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 );
55
56 TEST_EQUAL( ret, expected_status );
57
58exit:
59 mbedtls_free( output_data );
60
61}
62/* END_CASE */