TianoCore EDK2 master
Loading...
Searching...
No Matches
ParallelhashTests.c
Go to the documentation of this file.
1
9#include "TestBaseCryptLib.h"
10
11//
12// Parallelhash Test Sample common parameters.
13//
15
16//
17// Parallelhash Test Sample #1 from NIST Special Publication 800-185.
18//
19GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample1[] = {
20 // input data of sample1.
21 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
22 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27
23};
24GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample1ByteLen = 24; // Length of sample1 input data in bytes.
25GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample1 = ""; // Customization string (S) of sample1.
26GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample1ByteLen = 0; // Customization string length of sample1 in bytes.
27GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample1 = 8; // Block size of sample1.
28GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample1[] = {
29 // Expected output data of sample1.
30 0xbc, 0x1e, 0xf1, 0x24, 0xda, 0x34, 0x49, 0x5e, 0x94, 0x8e, 0xad, 0x20, 0x7d, 0xd9, 0x84, 0x22,
31 0x35, 0xda, 0x43, 0x2d, 0x2b, 0xbc, 0x54, 0xb4, 0xc1, 0x10, 0xe6, 0x4c, 0x45, 0x11, 0x05, 0x53,
32 0x1b, 0x7f, 0x2a, 0x3e, 0x0c, 0xe0, 0x55, 0xc0, 0x28, 0x05, 0xe7, 0xc2, 0xde, 0x1f, 0xb7, 0x46,
33 0xaf, 0x97, 0xa1, 0xd0, 0x01, 0xf4, 0x3b, 0x82, 0x4e, 0x31, 0xb8, 0x76, 0x12, 0x41, 0x04, 0x29
34};
35
36//
37// Parallelhash Test Sample #2 from NIST Special Publication 800-185.
38//
39GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 *InputSample2 = InputSample1; // Input of sample2 is same as sample1.
40GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample2ByteLen = 24; // Length of sample2 input data in bytes.
41GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample2 = "Parallel Data"; // Customization string (S) of sample2.
42GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample2ByteLen = 13; // Customization string length of sample2 in bytes.
43GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample2 = 8; // Block size of sample2.
44GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample2[] = {
45 // Expected output data of sample2.
46 0xcd, 0xf1, 0x52, 0x89, 0xb5, 0x4f, 0x62, 0x12, 0xb4, 0xbc, 0x27, 0x05, 0x28, 0xb4, 0x95, 0x26,
47 0x00, 0x6d, 0xd9, 0xb5, 0x4e, 0x2b, 0x6a, 0xdd, 0x1e, 0xf6, 0x90, 0x0d, 0xda, 0x39, 0x63, 0xbb,
48 0x33, 0xa7, 0x24, 0x91, 0xf2, 0x36, 0x96, 0x9c, 0xa8, 0xaf, 0xae, 0xa2, 0x9c, 0x68, 0x2d, 0x47,
49 0xa3, 0x93, 0xc0, 0x65, 0xb3, 0x8e, 0x29, 0xfa, 0xe6, 0x51, 0xa2, 0x09, 0x1c, 0x83, 0x31, 0x10
50};
51
52//
53// Parallelhash Test Sample #3 from NIST Special Publication 800-185.
54//
55GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 InputSample3[] = {
56 // input data of sample3.
57 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x10, 0x11, 0x12, 0x13,
58 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
59 0x28, 0x29, 0x2a, 0x2b, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b,
60 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x50, 0x51, 0x52, 0x53,
61 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x5b
62};
63GLOBAL_REMOVE_IF_UNREFERENCED UINTN InputSample3ByteLen = 72; // Length of sample3 input data in bytes.
64GLOBAL_REMOVE_IF_UNREFERENCED CONST VOID *CustomizationSample3 = "Parallel Data"; // Customization string (S) of sample3.
65GLOBAL_REMOVE_IF_UNREFERENCED UINTN CustomSample3ByteLen = 13; // Customization string length of sample3 in bytes.
66GLOBAL_REMOVE_IF_UNREFERENCED UINTN BlockSizeSample3 = 12; // Block size of sample3.
67GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 ExpectOutputSample3[] = {
68 // Expected output data of sample3.
69 0x69, 0xd0, 0xfc, 0xb7, 0x64, 0xea, 0x05, 0x5d, 0xd0, 0x93, 0x34, 0xbc, 0x60, 0x21, 0xcb, 0x7e,
70 0x4b, 0x61, 0x34, 0x8d, 0xff, 0x37, 0x5d, 0xa2, 0x62, 0x67, 0x1c, 0xde, 0xc3, 0xef, 0xfa, 0x8d,
71 0x1b, 0x45, 0x68, 0xa6, 0xcc, 0xe1, 0x6b, 0x1c, 0xad, 0x94, 0x6d, 0xdd, 0xe2, 0x7f, 0x6c, 0xe2,
72 0xb8, 0xde, 0xe4, 0xcd, 0x1b, 0x24, 0x85, 0x1e, 0xbf, 0x00, 0xeb, 0x90, 0xd4, 0x38, 0x13, 0xe9
73};
74
76EFIAPI
77TestVerifyParallelHash256HashAll (
78 IN UNIT_TEST_CONTEXT Context
79 )
80{
81 BOOLEAN Status;
82 UINT8 Output[64];
83
84 //
85 // Test #1 using sample1.
86 //
87 Status = ParallelHash256HashAll (
88 InputSample1,
89 InputSample1ByteLen,
90 BlockSizeSample1,
91 Output,
92 OutputByteLen,
93 CustomizationSample1,
94 CustomSample1ByteLen
95 );
96 UT_ASSERT_TRUE (Status);
97
98 // Check the output with the expected output.
99 UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample1, OutputByteLen);
100
101 //
102 // Test #2 using sample2.
103 //
104 Status = ParallelHash256HashAll (
105 InputSample2,
106 InputSample2ByteLen,
107 BlockSizeSample2,
108 Output,
109 OutputByteLen,
110 CustomizationSample2,
111 CustomSample2ByteLen
112 );
113 UT_ASSERT_TRUE (Status);
114
115 // Check the output with the expected output.
116 UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample2, OutputByteLen);
117
118 //
119 // Test #3 using sample3.
120 //
121 Status = ParallelHash256HashAll (
122 InputSample3,
123 InputSample3ByteLen,
124 BlockSizeSample3,
125 Output,
126 OutputByteLen,
127 CustomizationSample3,
128 CustomSample3ByteLen
129 );
130 UT_ASSERT_TRUE (Status);
131
132 // Check the output with the expected output.
133 UT_ASSERT_MEM_EQUAL (Output, ExpectOutputSample3, OutputByteLen);
134
135 return EFI_SUCCESS;
136}
137
138TEST_DESC mParallelhashTest[] = {
139 //
140 // -----Description------------------------------Class----------------------Function-----------------Pre---Post--Context
141 //
142 { "TestVerifyParallelHash256HashAll()", "CryptoPkg.BaseCryptLib.ParallelHash256HashAll", TestVerifyParallelHash256HashAll, NULL, NULL, NULL },
143};
144
145UINTN mParallelhashTestNum = ARRAY_SIZE (mParallelhashTest);
UINT64 UINTN
BOOLEAN EFIAPI ParallelHash256HashAll(IN CONST VOID *Input, IN UINTN InputByteLen, IN UINTN BlockSize, OUT VOID *Output, IN UINTN OutputByteLen, IN CONST VOID *Customization, IN UINTN CustomByteLen)
#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
#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