TianoCore EDK2 master
Loading...
Searching...
No Matches
Pkcs5Pbkdf2Tests.c
Go to the documentation of this file.
1
9#include "TestBaseCryptLib.h"
10
11//
12// PBKDF2 HMAC-SHA1 Test Vector from RFC6070
13//
14GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Password = "password"; // Input Password
15GLOBAL_REMOVE_IF_UNREFERENCED UINTN PassLen = 8; // Length of Input Password
16GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *Salt = "salt"; // Input Salt
17GLOBAL_REMOVE_IF_UNREFERENCED UINTN SaltLen = 4; // Length of Input Salt
18GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN Count = 2; // InterationCount
19GLOBAL_REMOVE_IF_UNREFERENCED CONST UINTN KeyLen = 20; // Length of derived key
20GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 DerivedKey[] = {
21 // Expected output key
22 0xea, 0x6c, 0x01, 0x4d, 0xc7, 0x2d, 0x6f, 0x8c, 0xcd, 0x1e, 0xd9, 0x2a, 0xce, 0x1d, 0x41, 0xf0,
23 0xd8, 0xde, 0x89, 0x57
24};
25
27EFIAPI
28TestVerifyPkcs5Pbkdf2 (
29 IN UNIT_TEST_CONTEXT Context
30 )
31{
32 BOOLEAN Status;
33 UINT8 *OutKey;
34
35 OutKey = AllocatePool (KeyLen);
36
37 //
38 // Verify PKCS#5 PBKDF2 Key Derivation Function
39 //
40 Status = Pkcs5HashPassword (
41 PassLen,
42 Password,
43 SaltLen,
44 (CONST UINT8 *)Salt,
45 Count,
47 KeyLen,
48 OutKey
49 );
50 UT_ASSERT_TRUE (Status);
51
52 //
53 // Check the output key with the expected key result
54 //
55 UT_ASSERT_MEM_EQUAL (OutKey, DerivedKey, KeyLen);
56
57 //
58 // Release Resources
59 //
60 FreePool (OutKey);
61
62 return EFI_SUCCESS;
63}
64
65TEST_DESC mPkcs5Test[] = {
66 //
67 // -----Description------------------------------Class----------------------Function-----------------Pre---Post--Context
68 //
69 { "TestVerifyPkcs5Pbkdf2()", "CryptoPkg.BaseCryptLib.Pkcs5", TestVerifyPkcs5Pbkdf2, NULL, NULL, NULL },
70};
71
72UINTN mPkcs5TestNum = ARRAY_SIZE (mPkcs5Test);
UINT64 UINTN
BOOLEAN EFIAPI Pkcs5HashPassword(IN UINTN PasswordLength, IN CONST CHAR8 *Password, IN UINTN SaltLength, IN CONST UINT8 *Salt, IN UINTN IterationCount, IN UINTN DigestSize, IN UINTN KeyLength, OUT UINT8 *OutKey)
#define SHA1_DIGEST_SIZE
Definition: BaseCryptLib.h:39
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
#define GLOBAL_REMOVE_IF_UNREFERENCED
Definition: Base.h:48
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
Definition: UnitTestLib.h:389
#define UT_ASSERT_TRUE(Expression)
Definition: UnitTestLib.h:350
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16