2
Application for HMAC Primitives Validation.
4
Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5
This program and the accompanying materials
6
are licensed and made available under the terms and conditions of the BSD License
7
which accompanies this distribution. The full text of the license may be found at
8
http://opensource.org/licenses/bsd-license.php
10
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18
// Max Known Digest Size is SHA512 Output (64 bytes) by far
20
#define MAX_DIGEST_SIZE 64
23
// Data string for HMAC validation
25
GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8 *HmacData = "Hi There";
28
// Key value for HMAC-MD5 validation. (From "2. Test Cases for HMAC-MD5" of IETF RFC2202)
30
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacMd5Key[16] = {
31
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b
35
// Result for HMAC-MD5("Hi There"). (From "2. Test Cases for HMAC-MD5" of IETF RFC2202)
37
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacMd5Digest[] = {
38
0x92, 0x94, 0x72, 0x7a, 0x36, 0x38, 0xbb, 0x1c, 0x13, 0xf4, 0x8e, 0xf8, 0x15, 0x8b, 0xfc, 0x9d
42
// Key value for HMAC-SHA-1 validation. (From "3. Test Cases for HMAC-SHA-1" of IETF RFC2202)
44
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Key[20] = {
45
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
46
0x0b, 0x0b, 0x0b, 0x0b
50
// Result for HMAC-SHA-1 ("Hi There"). (From "3. Test Cases for HMAC-SHA-1" of IETF RFC2202)
52
GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Digest[] = {
53
0xb6, 0x17, 0x31, 0x86, 0x55, 0x05, 0x72, 0x64, 0xe2, 0x8b, 0xc0, 0xb6, 0xfb, 0x37, 0x8c, 0x8e,
54
0xf1, 0x46, 0xbe, 0x00
58
Validate UEFI-OpenSSL Message Authentication Codes Interfaces.
60
@retval EFI_SUCCESS Validation succeeded.
61
@retval EFI_ABORTED Validation failed.
71
UINT8 Digest[MAX_DIGEST_SIZE];
74
Print (L" \nUEFI-OpenSSL HMAC Engine Testing:\n");
76
Print (L"- HMAC-MD5: ");
79
// HMAC-MD5 Digest Validation
81
ZeroMem (Digest, MAX_DIGEST_SIZE);
82
CtxSize = HmacMd5GetContextSize ();
83
HmacCtx = AllocatePool (CtxSize);
86
Status = HmacMd5Init (HmacCtx, HmacMd5Key, sizeof (HmacMd5Key));
92
Print (L"Update... ");
93
Status = HmacMd5Update (HmacCtx, HmacData, 8);
99
Print (L"Finalize... ");
100
Status = HmacMd5Final (HmacCtx, Digest);
108
Print (L"Check Value... ");
109
if (CompareMem (Digest, HmacMd5Digest, MD5_DIGEST_SIZE) != 0) {
116
Print (L"- HMAC-SHA1: ");
119
// HMAC-SHA1 Digest Validation
121
ZeroMem (Digest, MAX_DIGEST_SIZE);
122
CtxSize = HmacSha1GetContextSize ();
123
HmacCtx = AllocatePool (CtxSize);
126
Status = HmacSha1Init (HmacCtx, HmacSha1Key, sizeof (HmacSha1Key));
132
Print (L"Update... ");
133
Status = HmacSha1Update (HmacCtx, HmacData, 8);
139
Print (L"Finalize... ");
140
Status = HmacSha1Final (HmacCtx, Digest);
148
Print (L"Check Value... ");
149
if (CompareMem (Digest, HmacSha1Digest, SHA1_DIGEST_SIZE) != 0) {