]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Application/Cryptest/HmacVerify.c
Update CryptoPkg for new ciphers (HMAC, Block Cipher, etc) supports.
[mirror_edk2.git] / CryptoPkg / Application / Cryptest / HmacVerify.c
CommitLineData
a8c44645 1/** @file \r
2 Application for HMAC Primitives Validation.\r
3\r
4Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include "Cryptest.h"\r
16\r
17//\r
18// Max Known Digest Size is SHA512 Output (64 bytes) by far\r
19//\r
20#define MAX_DIGEST_SIZE 64\r
21\r
22//\r
23// Data string for HMAC validation\r
24//\r
25GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *HmacData = "Hi There";\r
26\r
27//\r
28// Key value for HMAC-MD5 validation. (From "2. Test Cases for HMAC-MD5" of IETF RFC2202)\r
29//\r
30GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacMd5Key[16] = {\r
31 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b\r
32 };\r
33\r
34//\r
35// Result for HMAC-MD5("Hi There"). (From "2. Test Cases for HMAC-MD5" of IETF RFC2202)\r
36//\r
37GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacMd5Digest[] = {\r
38 0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d\r
39 };\r
40\r
41//\r
42// Key value for HMAC-SHA-1 validation. (From "3. Test Cases for HMAC-SHA-1" of IETF RFC2202)\r
43//\r
44GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Key[20] = {\r
45 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,\r
46 0x0b, 0x0b, 0x0b, 0x0b\r
47 };\r
48\r
49//\r
50// Result for HMAC-SHA-1 ("Hi There"). (From "3. Test Cases for HMAC-SHA-1" of IETF RFC2202)\r
51//\r
52GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Digest[] = {\r
53 0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,\r
54 0xf1, 0x46, 0xbe, 0x00\r
55 };\r
56\r
57/**\r
58 Validate UEFI-OpenSSL Message Authentication Codes Interfaces.\r
59\r
60 @retval EFI_SUCCESS Validation succeeded.\r
61 @retval EFI_ABORTED Validation failed.\r
62\r
63**/\r
64EFI_STATUS\r
65ValidateCryptHmac (\r
66 VOID\r
67 )\r
68{\r
69 UINTN CtxSize;\r
70 VOID *HmacCtx;\r
71 UINT8 Digest[MAX_DIGEST_SIZE];\r
72 BOOLEAN Status;\r
73\r
74 Print (L" \nUEFI-OpenSSL HMAC Engine Testing:\n");\r
75\r
76 Print (L"- HMAC-MD5: ");\r
77\r
78 //\r
79 // HMAC-MD5 Digest Validation\r
80 //\r
81 ZeroMem (Digest, MAX_DIGEST_SIZE);\r
82 CtxSize = HmacMd5GetContextSize ();\r
83 HmacCtx = AllocatePool (CtxSize);\r
84\r
85 Print (L"Init... ");\r
86 Status = HmacMd5Init (HmacCtx, HmacMd5Key, sizeof (HmacMd5Key));\r
87 if (!Status) {\r
88 Print (L"[Fail]");\r
89 return EFI_ABORTED;\r
90 }\r
91\r
92 Print (L"Update... ");\r
93 Status = HmacMd5Update (HmacCtx, HmacData, 8);\r
94 if (!Status) {\r
95 Print (L"[Fail]");\r
96 return EFI_ABORTED;\r
97 }\r
98\r
99 Print (L"Finalize... ");\r
100 Status = HmacMd5Final (HmacCtx, Digest);\r
101 if (!Status) {\r
102 Print (L"[Fail]");\r
103 return EFI_ABORTED;\r
104 }\r
105\r
106 FreePool (HmacCtx);\r
107\r
108 Print (L"Check Value... ");\r
109 if (CompareMem (Digest, HmacMd5Digest, MD5_DIGEST_SIZE) != 0) {\r
110 Print (L"[Fail]");\r
111 return EFI_ABORTED;\r
112 }\r
113\r
114 Print (L"[Pass]\n");\r
115\r
116 Print (L"- HMAC-SHA1: ");\r
117\r
118 //\r
119 // HMAC-SHA1 Digest Validation\r
120 //\r
121 ZeroMem (Digest, MAX_DIGEST_SIZE);\r
122 CtxSize = HmacSha1GetContextSize ();\r
123 HmacCtx = AllocatePool (CtxSize);\r
124\r
125 Print (L"Init... ");\r
126 Status = HmacSha1Init (HmacCtx, HmacSha1Key, sizeof (HmacSha1Key));\r
127 if (!Status) {\r
128 Print (L"[Fail]");\r
129 return EFI_ABORTED;\r
130 }\r
131\r
132 Print (L"Update... ");\r
133 Status = HmacSha1Update (HmacCtx, HmacData, 8);\r
134 if (!Status) {\r
135 Print (L"[Fail]");\r
136 return EFI_ABORTED;\r
137 }\r
138\r
139 Print (L"Finalize... ");\r
140 Status = HmacSha1Final (HmacCtx, Digest);\r
141 if (!Status) {\r
142 Print (L"[Fail]");\r
143 return EFI_ABORTED;\r
144 }\r
145\r
146 FreePool (HmacCtx);\r
147\r
148 Print (L"Check Value... ");\r
149 if (CompareMem (Digest, HmacSha1Digest, SHA1_DIGEST_SIZE) != 0) {\r
150 Print (L"[Fail]");\r
151 return EFI_ABORTED;\r
152 }\r
153\r
154 Print (L"[Pass]\n");\r
155\r
156 return EFI_SUCCESS;\r
157}\r