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
71
|
/** @file
Application for PKCS#5 PBKDF2 Function Validation.
Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include "TestBaseCryptLib.h"
//
// PBKDF2 HMAC-SHA1 Test Vector from RFC6070
//
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Password = "password"; // Input Password
GLOBAL_REMOVE_IF_UNREFERENCED UINTN PassLen = 8; // Length of Input Password
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Salt = "salt"; // Input Salt
GLOBAL_REMOVE_IF_UNREFERENCED UINTN SaltLen = 4; // Length of Input Salt
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN Count = 2; // InterationCount
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN KeyLen = 20; // Length of derived key
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 DerivedKey[] = { // Expected output key
0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
0xd8, 0xde, 0x89, 0x57
};
UNIT_TEST_STATUS
EFIAPI
TestVerifyPkcs5Pbkdf2 (
IN UNIT_TEST_CONTEXT Context
)
{
BOOLEAN Status;
UINT8 *OutKey;
OutKey = AllocatePool (KeyLen);
//
// Verify PKCS#5 PBKDF2 Key Derivation Function
//
Status = Pkcs5HashPassword (
PassLen,
Password,
SaltLen,
(CONST UINT8 *)Salt,
Count,
SHA1_DIGEST_SIZE,
KeyLen,
OutKey
);
UT_ASSERT_TRUE (Status);
//
// Check the output key with the expected key result
//
UT_ASSERT_MEM_EQUAL (OutKey, DerivedKey, KeyLen);
//
// Release Resources
//
FreePool (OutKey);
return EFI_SUCCESS;
}
TEST_DESC mPkcs5Test[] = {
//
// -----Description------------------------------Class----------------------Function-----------------Pre---Post--Context
//
{"TestVerifyPkcs5Pbkdf2()", "CryptoPkg.BaseCryptLib.Pkcs5", TestVerifyPkcs5Pbkdf2, NULL, NULL, NULL},
};
UINTN mPkcs5TestNum = ARRAY_SIZE(mPkcs5Test);
|