2 Application for Hash 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 // Message string for digest validation
25 GLOBAL_REMOVE_IF_UNREFERENCED CONST CHAR8
*HashData
= "abc";
28 // Result for MD4("abc"). (From "A.5 Test suite" of IETF RFC1320)
30 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Md4Digest
[MD4_DIGEST_SIZE
] = {
31 0xa4, 0x48, 0x01, 0x7a, 0xaf, 0x21, 0xd8, 0x52, 0x5f, 0xc1, 0x0a, 0xe8, 0x7a, 0xa6, 0x72, 0x9d
35 // Result for MD5("abc"). (From "A.5 Test suite" of IETF RFC1321)
37 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Md5Digest
[MD5_DIGEST_SIZE
] = {
38 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72
42 // Result for SHA-1("abc"). (From "A.1 SHA-1 Example" of NIST FIPS 180-2)
44 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Sha1Digest
[SHA1_DIGEST_SIZE
] = {
45 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c,
46 0x9c, 0xd0, 0xd8, 0x9d
50 // Result for SHA-256("abc"). (From "B.1 SHA-256 Example" of NIST FIPS 180-2)
52 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Sha256Digest
[SHA256_DIGEST_SIZE
] = {
53 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
54 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
58 Validate UEFI-OpenSSL Digest Interfaces.
60 @retval EFI_SUCCESS Validation succeeded.
61 @retval EFI_ABORTED Validation failed.
72 UINT8 Digest
[MAX_DIGEST_SIZE
];
75 Print (L
" UEFI-OpenSSL Hash Engine Testing:\n");
76 DataSize
= AsciiStrLen (HashData
);
81 // MD4 Digest Validation
83 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
84 CtxSize
= Md4GetContextSize ();
85 HashCtx
= AllocatePool (CtxSize
);
88 Status
= Md4Init (HashCtx
);
94 Print (L
"Update... ");
95 Status
= Md4Update (HashCtx
, HashData
, DataSize
);
101 Print (L
"Finalize... ");
102 Status
= Md4Final (HashCtx
, Digest
);
110 Print (L
"Check Value... ");
111 if (CompareMem (Digest
, Md4Digest
, MD5_DIGEST_SIZE
) != 0) {
121 // MD5 Digest Validation
123 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
124 CtxSize
= Md5GetContextSize ();
125 HashCtx
= AllocatePool (CtxSize
);
128 Status
= Md5Init (HashCtx
);
134 Print (L
"Update... ");
135 Status
= Md5Update (HashCtx
, HashData
, DataSize
);
141 Print (L
"Finalize... ");
142 Status
= Md5Final (HashCtx
, Digest
);
150 Print (L
"Check Value... ");
151 if (CompareMem (Digest
, Md5Digest
, MD5_DIGEST_SIZE
) != 0) {
161 // SHA-1 Digest Validation
163 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
164 CtxSize
= Sha1GetContextSize ();
165 HashCtx
= AllocatePool (CtxSize
);
168 Status
= Sha1Init (HashCtx
);
174 Print (L
"Update... ");
175 Status
= Sha1Update (HashCtx
, HashData
, DataSize
);
181 Print (L
"Finalize... ");
182 Status
= Sha1Final (HashCtx
, Digest
);
190 Print (L
"Check Value... ");
191 if (CompareMem (Digest
, Sha1Digest
, SHA1_DIGEST_SIZE
) != 0) {
198 Print (L
"- SHA256: ");
201 // SHA256 Digest Validation
203 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
204 CtxSize
= Sha256GetContextSize ();
205 HashCtx
= AllocatePool (CtxSize
);
208 Status
= Sha256Init (HashCtx
);
214 Print (L
"Update... ");
215 Status
= Sha256Update (HashCtx
, HashData
, DataSize
);
221 Print (L
"Finalize... ");
222 Status
= Sha256Final (HashCtx
, Digest
);
230 Print (L
"Check Value... ");
231 if (CompareMem (Digest
, Sha256Digest
, SHA256_DIGEST_SIZE
) != 0) {