X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=CryptoPkg%2FApplication%2FCryptest%2FHmacVerify.c;h=9a91295bcf83ce7b6615043eac74486344d59f32;hp=73b38f37495cb0301188628e2a044f2bc0a23ca2;hb=72009c626d8b1c237c0de840e9bfe9d23b76b94c;hpb=b7d1ba0a8ae9719689ad9725e02e4cb5d469a3ae diff --git a/CryptoPkg/Application/Cryptest/HmacVerify.c b/CryptoPkg/Application/Cryptest/HmacVerify.c index 73b38f3749..9a91295bcf 100644 --- a/CryptoPkg/Application/Cryptest/HmacVerify.c +++ b/CryptoPkg/Application/Cryptest/HmacVerify.c @@ -1,7 +1,7 @@ /** @file Application for HMAC Primitives Validation. -Copyright (c) 2010, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -54,6 +54,22 @@ GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha1Digest[] = { 0xf1, 0x46, 0xbe, 0x00 }; +// +// Key value for HMAC-SHA-256 validation. (From "4. Test Vectors" of IETF RFC4231) +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha256Key[20] = { + 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, + 0x0b, 0x0b, 0x0b, 0x0b + }; + +// +// Result for HMAC-SHA-256 ("Hi There"). (From "4. Test Vectors" of IETF RFC4231) +// +GLOBAL_REMOVE_IF_UNREFERENCED CONST UINT8 HmacSha256Digest[] = { + 0xb0, 0x34, 0x4c, 0x61, 0xd8, 0xdb, 0x38, 0x53, 0x5c, 0xa8, 0xaf, 0xce, 0xaf, 0x0b, 0xf1, 0x2b, + 0x88, 0x1d, 0xc2, 0x00, 0xc9, 0x83, 0x3d, 0xa7, 0x26, 0xe9, 0x37, 0x6c, 0x2e, 0x32, 0xcf, 0xf7 + }; + /** Validate UEFI-OpenSSL Message Authentication Codes Interfaces. @@ -73,7 +89,7 @@ ValidateCryptHmac ( Print (L" \nUEFI-OpenSSL HMAC Engine Testing:\n"); - Print (L"- HMAC-MD5: "); + Print (L"- HMAC-MD5: "); // // HMAC-MD5 Digest Validation @@ -113,7 +129,7 @@ ValidateCryptHmac ( Print (L"[Pass]\n"); - Print (L"- HMAC-SHA1: "); + Print (L"- HMAC-SHA1: "); // // HMAC-SHA1 Digest Validation @@ -153,5 +169,44 @@ ValidateCryptHmac ( Print (L"[Pass]\n"); + Print (L"- HMAC-SHA256: "); + // + // HMAC-SHA-256 Digest Validation + // + ZeroMem (Digest, MAX_DIGEST_SIZE); + CtxSize = HmacSha256GetContextSize (); + HmacCtx = AllocatePool (CtxSize); + + Print (L"Init... "); + Status = HmacSha256Init (HmacCtx, HmacSha256Key, sizeof (HmacSha256Key)); + if (!Status) { + Print (L"[Fail]"); + return EFI_ABORTED; + } + + Print (L"Update... "); + Status = HmacSha256Update (HmacCtx, HmacData, 8); + if (!Status) { + Print (L"[Fail]"); + return EFI_ABORTED; + } + + Print (L"Finalize... "); + Status = HmacSha256Final (HmacCtx, Digest); + if (!Status) { + Print (L"[Fail]"); + return EFI_ABORTED; + } + + FreePool (HmacCtx); + + Print (L"Check Value... "); + if (CompareMem (Digest, HmacSha256Digest, SHA256_DIGEST_SIZE) != 0) { + Print (L"[Fail]"); + return EFI_ABORTED; + } + + Print (L"[Pass]\n"); + return EFI_SUCCESS; }