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 MD5("abc"). (From "A.5 Test suite" of IETF RFC1321)
30 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Md5Digest
[MD5_DIGEST_SIZE
] = {
31 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72
35 // Result for SHA-1("abc"). (From "A.1 SHA-1 Example" of NIST FIPS 180-2)
37 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Sha1Digest
[SHA1_DIGEST_SIZE
] = {
38 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c,
39 0x9c, 0xd0, 0xd8, 0x9d
43 // Result for SHA-256("abc"). (From "B.1 SHA-256 Example" of NIST FIPS 180-2)
45 GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 Sha256Digest
[SHA256_DIGEST_SIZE
] = {
46 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
47 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
51 Validate UEFI-OpenSSL Digest Interfaces.
53 @retval EFI_SUCCESS Validation succeeded.
54 @retval EFI_ABORTED Validation failed.
65 UINT8 Digest
[MAX_DIGEST_SIZE
];
68 Print (L
" UEFI-OpenSSL Hash Engine Testing:\n");
69 DataSize
= AsciiStrLen (HashData
);
74 // MD5 Digest Validation
76 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
77 CtxSize
= Md5GetContextSize ();
78 HashCtx
= AllocatePool (CtxSize
);
81 Status
= Md5Init (HashCtx
);
87 Print (L
"Update... ");
88 Status
= Md5Update (HashCtx
, HashData
, DataSize
);
94 Print (L
"Finalize... ");
95 Status
= Md5Final (HashCtx
, Digest
);
103 Print (L
"Check Value... ");
104 if (CompareMem (Digest
, Md5Digest
, MD5_DIGEST_SIZE
) != 0) {
114 // SHA-1 Digest Validation
116 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
117 CtxSize
= Sha1GetContextSize ();
118 HashCtx
= AllocatePool (CtxSize
);
121 Status
= Sha1Init (HashCtx
);
127 Print (L
"Update... ");
128 Status
= Sha1Update (HashCtx
, HashData
, DataSize
);
134 Print (L
"Finalize... ");
135 Status
= Sha1Final (HashCtx
, Digest
);
143 Print (L
"Check Value... ");
144 if (CompareMem (Digest
, Sha1Digest
, SHA1_DIGEST_SIZE
) != 0) {
151 Print (L
"- SHA256: ");
154 // SHA256 Digest Validation
156 ZeroMem (Digest
, MAX_DIGEST_SIZE
);
157 CtxSize
= Sha256GetContextSize ();
158 HashCtx
= AllocatePool (CtxSize
);
161 Status
= Sha256Init (HashCtx
);
167 Print (L
"Update... ");
168 Status
= Sha256Update (HashCtx
, HashData
, DataSize
);
174 Print (L
"Finalize... ");
175 Status
= Sha256Final (HashCtx
, Digest
);
183 Print (L
"Check Value... ");
184 if (CompareMem (Digest
, Sha256Digest
, SHA256_DIGEST_SIZE
) != 0) {