]>
Commit | Line | Data |
---|---|---|
a8f37449 QL |
1 | /** @file\r |
2 | Application for PKCS#5 PBKDF2 Function Validation.\r | |
3 | \r | |
4 | Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #include "Cryptest.h"\r | |
16 | \r | |
17 | //\r | |
18 | // PBKDF2 HMAC-SHA1 Test Vector from RFC6070\r | |
19 | //\r | |
20 | GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Password = "password"; // Input Password\r | |
21 | GLOBAL_REMOVE_IF_UNREFERENCED UINTN PassLen = 8; // Length of Input Password\r | |
22 | GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Salt = "salt"; // Input Salt\r | |
23 | GLOBAL_REMOVE_IF_UNREFERENCED UINTN SaltLen = 4; // Length of Input Salt\r | |
24 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN Count = 2; // InterationCount\r | |
25 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN KeyLen = 20; // Length of derived key\r | |
26 | GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 DerivedKey[] = { // Expected output key\r | |
27 | 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,\r | |
28 | 0xd8, 0xde, 0x89, 0x57\r | |
29 | };\r | |
30 | \r | |
31 | /**\r | |
32 | Validate UEFI-OpenSSL PKCS#5 PBKDF2 Interface.\r | |
33 | \r | |
34 | @retval EFI_SUCCESS Validation succeeded.\r | |
35 | @retval EFI_ABORTED Validation failed.\r | |
36 | \r | |
37 | **/\r | |
38 | EFI_STATUS\r | |
39 | ValidateCryptPkcs5Pbkdf2 (\r | |
40 | VOID\r | |
41 | )\r | |
42 | {\r | |
43 | BOOLEAN Status;\r | |
44 | UINT8 *OutKey;\r | |
45 | \r | |
46 | Print (L"\nUEFI-OpenSSL PKCS#5 PBKDF2 Testing: ");\r | |
47 | Print (L"\n- PKCS#5 PBKDF2 Verification: ");\r | |
48 | \r | |
49 | OutKey = AllocatePool (KeyLen);\r | |
50 | if (OutKey == NULL) {\r | |
51 | Print (L"[Fail]");\r | |
52 | return EFI_ABORTED;\r | |
53 | }\r | |
54 | \r | |
55 | //\r | |
56 | // Verify PKCS#5 PBKDF2 Key Derivation Function\r | |
57 | //\r | |
58 | Print (L"Deriving Key... ");\r | |
59 | Status = Pkcs5HashPassword (\r | |
60 | PassLen,\r | |
61 | Password,\r | |
62 | SaltLen,\r | |
63 | (CONST UINT8 *)Salt,\r | |
64 | Count,\r | |
65 | SHA1_DIGEST_SIZE,\r | |
66 | KeyLen,\r | |
67 | OutKey\r | |
68 | );\r | |
69 | \r | |
70 | if (!Status) {\r | |
71 | Print (L"[Fail]");\r | |
72 | FreePool (OutKey);\r | |
73 | return EFI_ABORTED;\r | |
74 | }\r | |
75 | \r | |
76 | //\r | |
77 | // Check the output key with the expected key result\r | |
78 | //\r | |
79 | Print (L"Check Derived Key... ");\r | |
80 | if (CompareMem (OutKey, DerivedKey, KeyLen) != 0) {\r | |
81 | Print (L"[Fail]");\r | |
82 | FreePool (OutKey);\r | |
83 | return EFI_ABORTED;\r | |
84 | }\r | |
85 | \r | |
86 | Print (L"[Pass]\n");\r | |
87 | \r | |
88 | //\r | |
89 | // Release Resources\r | |
90 | //\r | |
91 | FreePool (OutKey);\r | |
92 | \r | |
93 | return EFI_SUCCESS;\r | |
94 | }\r |