• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* BEGIN_HEADER */
2#include "mbedtls/pkcs12.h"
3#include "common.h"
4
5typedef enum
6{
7   USE_NULL_INPUT = 0,
8   USE_GIVEN_INPUT = 1,
9} input_usage_method_t;
10
11/* END_HEADER */
12
13/* BEGIN_DEPENDENCIES
14 * depends_on:MBEDTLS_PKCS12_C
15 * END_DEPENDENCIES
16 */
17
18/* BEGIN_CASE */
19void 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,
23                        data_t* expected_output, int expected_status )
24
25{
26   int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
27   unsigned char *output_data = NULL;
28
29   unsigned char *password = NULL;
30   size_t password_len = 0;
31   unsigned char *salt = NULL;
32   size_t salt_len = 0;
33   size_t key_size = key_size_arg;
34
35   if( password_usage == USE_GIVEN_INPUT )
36      password = password_arg->x;
37
38   password_len = password_arg->len;
39
40   if( salt_usage == USE_GIVEN_INPUT )
41      salt = salt_arg->x;
42
43   salt_len = salt_arg->len;
44
45   ASSERT_ALLOC( output_data, key_size );
46
47   ret = mbedtls_pkcs12_derivation( output_data,
48                                    key_size,
49                                    password,
50                                    password_len,
51                                    salt,
52                                    salt_len,
53                                    md_type,
54                                    MBEDTLS_PKCS12_DERIVE_KEY,
55                                    iterations );
56
57   TEST_EQUAL( ret, expected_status );
58
59   if( expected_status == 0 )
60   {
61      ASSERT_COMPARE( expected_output->x, expected_output->len,
62                      output_data, key_size );
63   }
64
65exit:
66   mbedtls_free( output_data );
67
68}
69/* END_CASE */
70