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