TianoCore EDK2 master
Loading...
Searching...
No Matches
HkdfTests.c
Go to the documentation of this file.
1
9#include "TestBaseCryptLib.h"
10
15UINT8 mHkdfSha256Ikm[22] = {
16 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
17 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
18 0x0b, 0x0b
19};
20
21UINT8 mHkdfSha256Salt[13] = {
22 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
23 0x0a, 0x0b, 0x0c,
24};
25
26UINT8 mHkdfSha256Info[10] = {
27 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9,
28};
29
30UINT8 mHkdfSha256Prk[32] = {
31 0x07, 0x77, 0x09, 0x36, 0x2c, 0x2e, 0x32, 0xdf, 0x0d, 0xdc,
32 0x3f, 0x0d, 0xc4, 0x7b, 0xba, 0x63, 0x90, 0xb6, 0xc7, 0x3b,
33 0xb5, 0x0f, 0x9c, 0x31, 0x22, 0xec, 0x84, 0x4a, 0xd7, 0xc2,
34 0xb3, 0xe5,
35};
36
37UINT8 mHkdfSha256Okm[42] = {
38 0x3c, 0xb2, 0x5f, 0x25, 0xfa, 0xac, 0xd5, 0x7a, 0x90, 0x43,
39 0x4f, 0x64, 0xd0, 0x36, 0x2f, 0x2a, 0x2d, 0x2d, 0x0a, 0x90,
40 0xcf, 0x1a, 0x5a, 0x4c, 0x5d, 0xb0, 0x2d, 0x56, 0xec, 0xc4,
41 0xc5, 0xbf, 0x34, 0x00, 0x72, 0x08, 0xd5, 0xb8, 0x87, 0x18,
42 0x58, 0x65,
43};
44
50UINT8 mHkdfSha384Ikm[16] = {
51 0x86, 0x77, 0xdc, 0x79, 0x23, 0x3e, 0xf3, 0x48, 0x07, 0x77,
52 0xc4, 0xc6, 0x01, 0xef, 0x4f, 0x0b,
53};
54
55UINT8 mHkdfSha384Salt[16] = {
56 0xad, 0x88, 0xdb, 0x71, 0x82, 0x44, 0xe2, 0xcb, 0x60, 0xe3,
57 0x5f, 0x87, 0x4d, 0x7a, 0xd8, 0x1f,
58};
59
60UINT8 mHkdfSha384Info[20] = {
61 0xa3, 0x8f, 0x63, 0x4d, 0x94, 0x78, 0x19, 0xa9, 0xbf, 0xa7,
62 0x92, 0x17, 0x4b, 0x42, 0xba, 0xa2, 0x0c, 0x9f, 0xce, 0x15,
63};
64
65UINT8 mHkdfSha384Prk[48] = {
66 0x60, 0xae, 0xa0, 0xde, 0xca, 0x97, 0x62, 0xaa, 0x43, 0xaf,
67 0x0e, 0x77, 0xa8, 0x0f, 0xb7, 0x76, 0xd0, 0x08, 0x19, 0x62,
68 0xf8, 0x30, 0xb5, 0x0d, 0x92, 0x08, 0x92, 0x7a, 0x8a, 0xd5,
69 0x6a, 0x3d, 0xc4, 0x4a, 0x5d, 0xfe, 0xb6, 0xb4, 0x79, 0x2f,
70 0x97, 0x92, 0x71, 0xe6, 0xcb, 0x08, 0x86, 0x52,
71};
72
73UINT8 mHkdfSha384Okm[64] = {
74 0x75, 0x85, 0x46, 0x36, 0x2a, 0x07, 0x0c, 0x0f, 0x13, 0xcb,
75 0xfb, 0xf1, 0x75, 0x6e, 0x8f, 0x29, 0xb7, 0x81, 0x9f, 0xb9,
76 0x03, 0xc7, 0xed, 0x4f, 0x97, 0xa5, 0x6b, 0xe3, 0xc8, 0xf8,
77 0x1e, 0x8c, 0x37, 0xae, 0xf5, 0xc0, 0xf8, 0xe5, 0xd2, 0xb1,
78 0x7e, 0xb1, 0xaa, 0x02, 0xec, 0x04, 0xc3, 0x3f, 0x54, 0x6c,
79 0xb2, 0xf3, 0xd1, 0x93, 0xe9, 0x30, 0xa9, 0xf8, 0x9e, 0xc9,
80 0xce, 0x3a, 0x82, 0xb5
81};
82
84EFIAPI
85TestVerifyHkdfSha256 (
86 IN UNIT_TEST_CONTEXT Context
87 )
88{
89 UINT8 PrkOut[32];
90 UINT8 Out[42];
91 BOOLEAN Status;
92
93 /* HKDF-SHA-256 digest Validation*/
94
95 ZeroMem (PrkOut, sizeof (PrkOut));
96 Status = HkdfSha256Extract (
98 sizeof (mHkdfSha256Ikm),
99 mHkdfSha256Salt,
100 sizeof (mHkdfSha256Salt),
101 PrkOut,
102 sizeof (PrkOut)
103 );
104 UT_ASSERT_TRUE (Status);
105
106 UT_ASSERT_MEM_EQUAL (PrkOut, mHkdfSha256Prk, sizeof (mHkdfSha256Prk));
107
108 ZeroMem (Out, sizeof (Out));
109 Status = HkdfSha256Expand (
110 mHkdfSha256Prk,
111 sizeof (mHkdfSha256Prk),
112 mHkdfSha256Info,
113 sizeof (mHkdfSha256Info),
114 Out,
115 sizeof (Out)
116 );
117 UT_ASSERT_TRUE (Status);
118
119 UT_ASSERT_MEM_EQUAL (Out, mHkdfSha256Okm, sizeof (mHkdfSha256Okm));
120
121 ZeroMem (Out, sizeof (Out));
124 sizeof (mHkdfSha256Ikm),
125 mHkdfSha256Salt,
126 sizeof (mHkdfSha256Salt),
127 mHkdfSha256Info,
128 sizeof (mHkdfSha256Info),
129 Out,
130 sizeof (Out)
131 );
132 UT_ASSERT_TRUE (Status);
133
134 UT_ASSERT_MEM_EQUAL (Out, mHkdfSha256Okm, sizeof (mHkdfSha256Okm));
135
136 return UNIT_TEST_PASSED;
137}
138
140EFIAPI
141TestVerifyHkdfSha384 (
142 IN UNIT_TEST_CONTEXT Context
143 )
144{
145 UINT8 PrkOut[48];
146 UINT8 Out[64];
147 BOOLEAN Status;
148
149 /* HKDF-SHA-384 digest Validation*/
150 ZeroMem (PrkOut, sizeof (PrkOut));
151 Status = HkdfSha384Extract (
153 sizeof (mHkdfSha384Ikm),
154 mHkdfSha384Salt,
155 sizeof (mHkdfSha384Salt),
156 PrkOut,
157 sizeof (PrkOut)
158 );
159 UT_ASSERT_TRUE (Status);
160
161 UT_ASSERT_MEM_EQUAL (PrkOut, mHkdfSha384Prk, sizeof (mHkdfSha384Prk));
162
163 ZeroMem (Out, sizeof (Out));
164 Status = HkdfSha384Expand (
165 mHkdfSha384Prk,
166 sizeof (mHkdfSha384Prk),
167 mHkdfSha384Info,
168 sizeof (mHkdfSha384Info),
169 Out,
170 sizeof (Out)
171 );
172 UT_ASSERT_TRUE (Status);
173
174 UT_ASSERT_MEM_EQUAL (Out, mHkdfSha384Okm, sizeof (mHkdfSha384Okm));
175
176 ZeroMem (Out, sizeof (Out));
179 sizeof (mHkdfSha384Ikm),
180 mHkdfSha384Salt,
181 sizeof (mHkdfSha384Salt),
182 mHkdfSha384Info,
183 sizeof (mHkdfSha384Info),
184 Out,
185 sizeof (Out)
186 );
187 UT_ASSERT_TRUE (Status);
188
189 UT_ASSERT_MEM_EQUAL (Out, mHkdfSha384Okm, sizeof (mHkdfSha384Okm));
190
191 return UNIT_TEST_PASSED;
192}
193
194TEST_DESC mHkdfTest[] = {
195 //
196 // -----Description--------------------------------------Class----------------------Function---------------------------------Pre---------------------Post---------Context
197 //
198 { "TestVerifyHkdfSha256()", "CryptoPkg.BaseCryptLib.Hkdf", TestVerifyHkdfSha256, NULL, NULL, NULL },
199 { "TestVerifyHkdfSha384()", "CryptoPkg.BaseCryptLib.Hkdf", TestVerifyHkdfSha384, NULL, NULL, NULL },
200};
201
202UINTN mHkdfTestNum = ARRAY_SIZE (mHkdfTest);
UINT64 UINTN
BOOLEAN EFIAPI HkdfSha256Extract(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
Definition: CryptHkdf.c:279
BOOLEAN EFIAPI HkdfSha384ExtractAndExpand(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
Definition: CryptHkdf.c:345
BOOLEAN EFIAPI HkdfSha384Extract(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, OUT UINT8 *PrkOut, UINTN PrkOutSize)
Definition: CryptHkdf.c:375
BOOLEAN EFIAPI HkdfSha256Expand(IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
Definition: CryptHkdf.c:315
BOOLEAN EFIAPI HkdfSha256ExtractAndExpand(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Salt, IN UINTN SaltSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
Definition: CryptHkdf.c:249
BOOLEAN EFIAPI HkdfSha384Expand(IN CONST UINT8 *Prk, IN UINTN PrkSize, IN CONST UINT8 *Info, IN UINTN InfoSize, OUT UINT8 *Out, IN UINTN OutSize)
Definition: CryptHkdf.c:411
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
UINT8 mHkdfSha384Ikm[16]
Definition: HkdfTests.c:50
UINT8 mHkdfSha256Ikm[22]
Definition: HkdfTests.c:15
#define NULL
Definition: Base.h:319
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
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