File: test_suite_pkcs12.function

package info (click to toggle)
edk2 2025.02-8
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 271,704 kB
  • sloc: ansic: 2,109,987; asm: 263,832; perl: 227,730; python: 149,919; sh: 34,967; cpp: 21,813; makefile: 3,282; xml: 806; pascal: 721; lisp: 35; ruby: 16; sed: 6; tcl: 4
file content (70 lines) | stat: -rw-r--r-- 1,767 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* BEGIN_HEADER */
#include "mbedtls/pkcs12.h"
#include "common.h"

#include "mbedtls/legacy_or_psa.h"

typedef enum
{
   USE_NULL_INPUT = 0,
   USE_GIVEN_INPUT = 1,
} input_usage_method_t;

/* END_HEADER */

/* BEGIN_DEPENDENCIES
 * depends_on:MBEDTLS_PKCS12_C
 * END_DEPENDENCIES
 */

/* BEGIN_CASE */
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,
                        data_t* expected_output, int expected_status )

{
   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;

   password_len = password_arg->len;

   if( salt_usage == USE_GIVEN_INPUT )
      salt = salt_arg->x;

   salt_len = salt_arg->len;

   ASSERT_ALLOC( output_data, key_size );

   int 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 );

   if( expected_status == 0 )
   {
      ASSERT_COMPARE( expected_output->x, expected_output->len,
                      output_data, key_size );
   }

exit:
   mbedtls_free( output_data );

}
/* END_CASE */