TianoCore EDK2 master
Loading...
Searching...
No Matches
AeadAesGcmTests.c
Go to the documentation of this file.
1
10#include "TestBaseCryptLib.h"
11
12/* AES-GCM test data from NIST public test vectors */
13GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gcm_key[] = {
14 0xee, 0xbc, 0x1f, 0x57, 0x48, 0x7f, 0x51, 0x92, 0x1c, 0x04, 0x65, 0x66,
15 0x5f, 0x8a, 0xe6, 0xd1, 0x65, 0x8b, 0xb2, 0x6d, 0xe6, 0xf8, 0xa0, 0x69,
16 0xa3, 0x52, 0x02, 0x93, 0xa5, 0x72, 0x07, 0x8f
17};
18
19GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gcm_iv[] = {
20 0x99, 0xaa, 0x3e, 0x68, 0xed, 0x81, 0x73, 0xa0, 0xee, 0xd0, 0x66, 0x84
21};
22
23GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gcm_pt[] = {
24 0xf5, 0x6e, 0x87, 0x05, 0x5b, 0xc3, 0x2d, 0x0e, 0xeb, 0x31, 0xb2, 0xea,
25 0xcc, 0x2b, 0xf2, 0xa5
26};
27
28GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gcm_aad[] = {
29 0x4d, 0x23, 0xc3, 0xce, 0xc3, 0x34, 0xb4, 0x9b, 0xdb, 0x37, 0x0c, 0x43,
30 0x7f, 0xec, 0x78, 0xde
31};
32
33GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gcm_ct[] = {
34 0xf7, 0x26, 0x44, 0x13, 0xa8, 0x4c, 0x0e, 0x7c, 0xd5, 0x36, 0x86, 0x7e,
35 0xb9, 0xf2, 0x17, 0x36
36};
37
38GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 gcm_tag[] = {
39 0x67, 0xba, 0x05, 0x10, 0x26, 0x2a, 0xe4, 0x87, 0xd7, 0x37, 0xee, 0x62,
40 0x98, 0xf7, 0x7e, 0x0c
41};
42
44EFIAPI
45TestVerifyAeadAesGcm (
46 IN UNIT_TEST_CONTEXT Context
47 )
48{
49 BOOLEAN Status;
50 UINT8 OutBuffer[1024];
51 UINTN OutBufferSize;
52 UINT8 OutTag[1024];
53 UINTN OutTagSize;
54
55 OutBufferSize = sizeof (OutBuffer);
56 OutTagSize = sizeof (gcm_tag);
57 ZeroMem (OutBuffer, sizeof (OutBuffer));
58 ZeroMem (OutTag, sizeof (OutTag));
59 Status = AeadAesGcmEncrypt (
60 gcm_key,
61 sizeof (gcm_key),
62 gcm_iv,
63 sizeof (gcm_iv),
64 gcm_aad,
65 sizeof (gcm_aad),
66 gcm_pt,
67 sizeof (gcm_pt),
68 OutTag,
69 OutTagSize,
70 OutBuffer,
71 &OutBufferSize
72 );
73 UT_ASSERT_TRUE (Status);
74
75 UT_ASSERT_EQUAL (OutBufferSize, sizeof (gcm_ct));
76
77 UT_ASSERT_MEM_EQUAL (OutBuffer, gcm_ct, sizeof (gcm_ct));
78
79 UT_ASSERT_MEM_EQUAL (OutTag, gcm_tag, sizeof (gcm_tag));
80
81 ZeroMem (OutBuffer, sizeof (OutBuffer));
82 Status = AeadAesGcmDecrypt (
83 gcm_key,
84 sizeof (gcm_key),
85 gcm_iv,
86 sizeof (gcm_iv),
87 gcm_aad,
88 sizeof (gcm_aad),
89 gcm_ct,
90 sizeof (gcm_ct),
91 gcm_tag,
92 sizeof (gcm_tag),
93 OutBuffer,
94 &OutBufferSize
95 );
96 UT_ASSERT_TRUE (Status);
97
98 UT_ASSERT_EQUAL (OutBufferSize, sizeof (gcm_pt));
99
100 UT_ASSERT_MEM_EQUAL (OutBuffer, gcm_pt, sizeof (gcm_pt));
101
102 return UNIT_TEST_PASSED;
103}
104
105TEST_DESC mAeadAesGcmTest[] = {
106 //
107 // -----Description--------------------------------------Class----------------------Function---------------------------------Pre---------------------Post---------Context
108 //
109 { "TestVerifyAeadAesGcm()", "CryptoPkg.BaseCryptLib.AeadAesGcm", TestVerifyAeadAesGcm, NULL, NULL, NULL },
110};
111
112UINTN mAeadAesGcmTestNum = ARRAY_SIZE (mAeadAesGcmTest);
UINT64 UINTN
BOOLEAN EFIAPI AeadAesGcmDecrypt(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Iv, IN UINTN IvSize, IN CONST UINT8 *AData, IN UINTN ADataSize, IN CONST UINT8 *DataIn, IN UINTN DataInSize, IN CONST UINT8 *Tag, IN UINTN TagSize, OUT UINT8 *DataOut, OUT UINTN *DataOutSize)
BOOLEAN EFIAPI AeadAesGcmEncrypt(IN CONST UINT8 *Key, IN UINTN KeySize, IN CONST UINT8 *Iv, IN UINTN IvSize, IN CONST UINT8 *AData, IN UINTN ADataSize, IN CONST UINT8 *DataIn, IN UINTN DataInSize, OUT UINT8 *TagOut, IN UINTN TagSize, OUT UINT8 *DataOut, OUT UINTN *DataOutSize)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#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 * 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
#define UT_ASSERT_EQUAL(ValueA, ValueB)
Definition: UnitTestLib.h:375
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16