]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Application/Cryptest/Pkcs5Pbkdf2Verify.c
CryptoPkg: Add PKCS5 PBKDF2 interface for password derivation.
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / Pkcs5Pbkdf2Verify.c
CommitLineData
a8f37449
QL
1/** @file\r
2 Application for PKCS#5 PBKDF2 Function Validation.\r
3\r
4Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT 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
20GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Password = "password"; // Input Password\r
21GLOBAL_REMOVE_IF_UNREFERENCED UINTN PassLen = 8; // Length of Input Password\r
22GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Salt = "salt"; // Input Salt\r
23GLOBAL_REMOVE_IF_UNREFERENCED UINTN SaltLen = 4; // Length of Input Salt\r
24GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN Count = 2; // InterationCount\r
25GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN KeyLen = 20; // Length of derived key\r
26GLOBAL_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
38EFI_STATUS\r
39ValidateCryptPkcs5Pbkdf2 (\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