]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add UEFI2.5 HASH protocol implementation.
authorYao, Jiewen <Jiewen.Yao@intel.com>
Tue, 5 May 2015 01:40:16 +0000 (01:40 +0000)
committerjyao1 <jyao1@Edk2>
Tue, 5 May 2015 01:40:16 +0000 (01:40 +0000)
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: "Yao, Jiewen" <Jiewen.Yao@intel.com>
Reviewed-by: "Long, Qin" <Qin.Long@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@17288 6f19259b-4bc3-4df7-8a09-765794883524

SecurityPkg/Hash2DxeCrypto/Driver.c [new file with mode: 0644]
SecurityPkg/Hash2DxeCrypto/Driver.h [new file with mode: 0644]
SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c [new file with mode: 0644]
SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf [new file with mode: 0644]
SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.uni [new file with mode: 0644]
SecurityPkg/Hash2DxeCrypto/Hash2DxeCryptoExtra.uni [new file with mode: 0644]
SecurityPkg/SecurityPkg.dsc

diff --git a/SecurityPkg/Hash2DxeCrypto/Driver.c b/SecurityPkg/Hash2DxeCrypto/Driver.c
new file mode 100644 (file)
index 0000000..ba2fe6a
--- /dev/null
@@ -0,0 +1,242 @@
+/** @file\r
+  This is service binding for Hash driver.\r
+\r
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "Driver.h"\r
+\r
+EFI_SERVICE_BINDING_PROTOCOL    mHash2ServiceBindingProtocol = {\r
+  Hash2ServiceBindingCreateChild,\r
+  Hash2ServiceBindingDestroyChild\r
+};\r
+\r
+/**\r
+  Creates a child handle with a set of I/O services.\r
+\r
+  @param[in]       This              Protocol instance pointer.\r
+  @param[in, out]  ChildHandle       Pointer to the handle of the child to create. If\r
+                                     it is NULL, then a new handle is created. If\r
+                                     it is not NULL, then the I/O services are added\r
+                                     to the existing child handle.\r
+\r
+  @retval EFI_SUCCES                 The protocol was added to ChildHandle.\r
+  @retval EFI_INVALID_PARAMETER      ChildHandle is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES       There are not enough resources availabe to\r
+                                     create the child.\r
+  @retval Others                     The child handle was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Hash2ServiceBindingCreateChild (\r
+  IN     EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN OUT EFI_HANDLE                      *ChildHandle\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  HASH2_SERVICE_DATA  *Hash2ServiceData;\r
+  HASH2_INSTANCE_DATA *Instance;\r
+  EFI_TPL             OldTpl;\r
+\r
+  if ((This == NULL) || (ChildHandle == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // Allocate buffer for the new instance.\r
+  //\r
+  Instance = AllocateZeroPool (sizeof (HASH2_INSTANCE_DATA));\r
+  if (Instance == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Init the instance data.\r
+  //\r
+  Instance->Signature = HASH2_INSTANCE_DATA_SIGNATURE;\r
+  CopyMem (&Instance->Hash2Protocol, &mHash2Protocol, sizeof (Instance->Hash2Protocol));\r
+  Instance->Hash2ServiceData = Hash2ServiceData;\r
+\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  ChildHandle,\r
+                  &gEfiHash2ProtocolGuid,\r
+                  &Instance->Hash2Protocol,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Instance);\r
+    return Status;\r
+  }\r
+\r
+  Instance->Handle = *ChildHandle;\r
+\r
+  //\r
+  // Add the child instance into ChildrenList.\r
+  //\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  InsertTailList (&Hash2ServiceData->ChildrenList, &Instance->InstEntry);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Destroys a child handle with a set of I/O services.\r
+\r
+  The DestroyChild() function does the opposite of CreateChild(). It removes a\r
+  protocol that was installed by CreateChild() from ChildHandle. If the removed\r
+  protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
+\r
+  @param[in]  This               Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
+                                 instance.\r
+  @param[in]  ChildHandle        Handle of the child to destroy.\r
+\r
+  @retval EFI_SUCCES             The protocol was removed from ChildHandle.\r
+  @retval EFI_UNSUPPORTED        ChildHandle does not support the protocol that\r
+                                 is being removed.\r
+  @retval EFI_INVALID_PARAMETER  ChildHandle is NULL.\r
+  @retval EFI_ACCESS_DENIED      The protocol could not be removed from the\r
+                                 ChildHandle because its services are being\r
+                                 used.\r
+  @retval Others                 The child handle was not destroyed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Hash2ServiceBindingDestroyChild (\r
+  IN EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                      ChildHandle\r
+  )\r
+{\r
+  EFI_STATUS                     Status;\r
+  HASH2_SERVICE_DATA             *Hash2ServiceData;\r
+  EFI_HASH2_PROTOCOL             *Hash2Protocol;\r
+  HASH2_INSTANCE_DATA            *Instance;\r
+  EFI_TPL                        OldTpl;\r
+  LIST_ENTRY                     *Entry;\r
+\r
+  if ((This == NULL) || (ChildHandle == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Hash2ServiceData = HASH2_SERVICE_DATA_FROM_THIS (This);\r
+\r
+  //\r
+  // Check if this ChildHandle is valid\r
+  //\r
+  Instance = NULL;\r
+  for(Entry = (&Hash2ServiceData->ChildrenList)->ForwardLink; Entry != (&Hash2ServiceData->ChildrenList); Entry = Entry->ForwardLink) {\r
+    Instance = HASH2_INSTANCE_DATA_FROM_LINK (Entry);\r
+    if (Instance->Handle == ChildHandle) {\r
+      break;\r
+    } else {\r
+      Instance = NULL;\r
+    }\r
+  }\r
+  if (Instance == NULL) {\r
+    DEBUG ((EFI_D_ERROR, "Hash2ServiceBindingDestroyChild - Invalid handle\n"));\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Get HashProtocol\r
+  //\r
+  Status = gBS->HandleProtocol (\r
+                  ChildHandle,\r
+                  &gEfiHash2ProtocolGuid,\r
+                  (VOID **)&Hash2Protocol\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  ASSERT (Hash2Protocol == &Instance->Hash2Protocol);\r
+\r
+  //\r
+  // Uninstall the Hash protocol.\r
+  //\r
+  Status = gBS->UninstallMultipleProtocolInterfaces (\r
+                  ChildHandle,\r
+                  &gEfiHash2ProtocolGuid,\r
+                  &Instance->Hash2Protocol,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  OldTpl = gBS->RaiseTPL (TPL_CALLBACK);\r
+\r
+  //\r
+  // Remove this instance from the ChildrenList.\r
+  //\r
+  RemoveEntryList (&Instance->InstEntry);\r
+\r
+  gBS->RestoreTPL (OldTpl);\r
+\r
+  FreePool (Instance);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  The entry point for Hash driver which installs the service binding protocol.\r
+\r
+  @param[in]  ImageHandle  The image handle of the driver.\r
+  @param[in]  SystemTable  The system table.\r
+\r
+  @retval EFI_SUCCES       The service binding protocols is successfully installed.\r
+  @retval Others           Other errors as indicated.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Hash2DriverEntryPoint (\r
+  IN EFI_HANDLE          ImageHandle,\r
+  IN EFI_SYSTEM_TABLE    *SystemTable\r
+  )\r
+{\r
+  EFI_STATUS         Status;\r
+  HASH2_SERVICE_DATA *Hash2ServiceData;\r
+\r
+  //\r
+  // Initialize the Hash Service Data.\r
+  //\r
+  Hash2ServiceData = AllocateZeroPool (sizeof (HASH2_SERVICE_DATA));\r
+  if (Hash2ServiceData == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Hash2ServiceData->Signature     = HASH2_SERVICE_DATA_SIGNATURE;\r
+  CopyMem (&Hash2ServiceData->ServiceBinding, &mHash2ServiceBindingProtocol, sizeof (EFI_SERVICE_BINDING_PROTOCOL));\r
+  InitializeListHead (&Hash2ServiceData->ChildrenList);\r
+\r
+  //\r
+  // Install the HASH Service Binding Protocol\r
+  //\r
+  Status = gBS->InstallMultipleProtocolInterfaces (\r
+                  &Hash2ServiceData->ServiceHandle,\r
+                  &gEfiHash2ServiceBindingProtocolGuid,\r
+                  &Hash2ServiceData->ServiceBinding,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    FreePool (Hash2ServiceData);\r
+  }\r
+\r
+  return Status;\r
+}
\ No newline at end of file
diff --git a/SecurityPkg/Hash2DxeCrypto/Driver.h b/SecurityPkg/Hash2DxeCrypto/Driver.h
new file mode 100644 (file)
index 0000000..771aedc
--- /dev/null
@@ -0,0 +1,131 @@
+/** @file\r
+  This is definition for service binding for Hash driver.\r
+\r
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _HASH2_DRIVER_H_\r
+#define _HASH2_DRIVER_H_\r
+\r
+#include <Uefi.h>\r
+\r
+#include <Protocol/ServiceBinding.h>\r
+#include <Protocol/Hash2.h>\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/DevicePathLib.h>\r
+#include <Library/UefiLib.h>\r
+\r
+#define HASH2_SERVICE_DATA_SIGNATURE  SIGNATURE_32 ('H', 'S', '2', 'S')\r
+\r
+typedef struct {\r
+  UINT32                        Signature;\r
+  EFI_HANDLE                    ServiceHandle;\r
+  EFI_SERVICE_BINDING_PROTOCOL  ServiceBinding;\r
+\r
+  LIST_ENTRY                    ChildrenList;\r
+} HASH2_SERVICE_DATA;\r
+\r
+#define HASH2_SERVICE_DATA_FROM_THIS(a) \\r
+  CR ( \\r
+  (a), \\r
+  HASH2_SERVICE_DATA, \\r
+  ServiceBinding, \\r
+  HASH2_SERVICE_DATA_SIGNATURE \\r
+  )\r
+\r
+#define HASH2_INSTANCE_DATA_SIGNATURE   SIGNATURE_32 ('H', 's', '2', 'I')\r
+\r
+typedef struct {\r
+  UINT32                           Signature;\r
+  HASH2_SERVICE_DATA               *Hash2ServiceData;\r
+  EFI_HANDLE                       Handle;\r
+  LIST_ENTRY                       InstEntry;\r
+  EFI_HASH2_PROTOCOL               Hash2Protocol;\r
+  VOID                             *HashContext;\r
+  VOID                             *HashInfoContext;\r
+} HASH2_INSTANCE_DATA;\r
+\r
+#define HASH2_INSTANCE_DATA_FROM_THIS(a) \\r
+  CR ( \\r
+  (a), \\r
+  HASH2_INSTANCE_DATA, \\r
+  Hash2Protocol, \\r
+  HASH2_INSTANCE_DATA_SIGNATURE \\r
+  )\r
+\r
+#define HASH2_INSTANCE_DATA_FROM_LINK(a) \\r
+  CR ( \\r
+  (a), \\r
+  HASH2_INSTANCE_DATA, \\r
+  InstEntry, \\r
+  HASH2_INSTANCE_DATA_SIGNATURE \\r
+  )\r
+\r
+/**\r
+  Creates a child handle with a set of I/O services.\r
+\r
+  @param[in]       This              Protocol instance pointer.\r
+  @param[in, out]  ChildHandle       Pointer to the handle of the child to create. If\r
+                                     it is NULL, then a new handle is created. If\r
+                                     it is not NULL, then the I/O services are added\r
+                                     to the existing child handle.\r
+\r
+  @retval EFI_SUCCES                 The protocol was added to ChildHandle.\r
+  @retval EFI_INVALID_PARAMETER      ChildHandle is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES       There are not enough resources availabe to\r
+                                     create the child.\r
+  @retval Others                     The child handle was not created.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Hash2ServiceBindingCreateChild (\r
+  IN     EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN OUT EFI_HANDLE                      *ChildHandle\r
+  );\r
+\r
+/**\r
+  Destroys a child handle with a set of I/O services.\r
+\r
+  The DestroyChild() function does the opposite of CreateChild(). It removes a\r
+  protocol that was installed by CreateChild() from ChildHandle. If the removed\r
+  protocol is the last protocol on ChildHandle, then ChildHandle is destroyed.\r
+\r
+  @param[in]  This               Pointer to the EFI_SERVICE_BINDING_PROTOCOL\r
+                                 instance.\r
+  @param[in]  ChildHandle        Handle of the child to destroy.\r
+\r
+  @retval EFI_SUCCES             The protocol was removed from ChildHandle.\r
+  @retval EFI_UNSUPPORTED        ChildHandle does not support the protocol that\r
+                                 is being removed.\r
+  @retval EFI_INVALID_PARAMETER  ChildHandle is NULL.\r
+  @retval EFI_ACCESS_DENIED      The protocol could not be removed from the\r
+                                 ChildHandle because its services are being\r
+                                 used.\r
+  @retval Others                 The child handle was not destroyed.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Hash2ServiceBindingDestroyChild (\r
+  IN EFI_SERVICE_BINDING_PROTOCOL    *This,\r
+  IN EFI_HANDLE                      ChildHandle\r
+  );\r
+\r
+extern EFI_HASH2_PROTOCOL mHash2Protocol;\r
+\r
+#endif\r
diff --git a/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.c
new file mode 100644 (file)
index 0000000..92cda36
--- /dev/null
@@ -0,0 +1,592 @@
+/** @file\r
+  This module implements Hash2 Protocol.\r
+\r
+Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials are licensed and made available under\r
+the terms and conditions of the BSD License that accompanies this distribution.\r
+The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php.\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Uefi.h>\r
+#include <Protocol/Hash2.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/BaseCryptLib.h>\r
+\r
+#include "Driver.h"\r
+\r
+/**\r
+  Retrieves the size, in bytes, of the context buffer required for hash operations.\r
+\r
+  If this interface is not supported, then return zero.\r
+\r
+  @return  The size, in bytes, of the context buffer required for hash operations.\r
+  @retval  0   This interface is not supported.\r
+\r
+**/\r
+typedef\r
+UINTN\r
+(EFIAPI *EFI_HASH_GET_CONTEXT_SIZE) (\r
+  VOID\r
+  );\r
+\r
+/**\r
+  Initializes user-supplied memory pointed by Sha1Context as hash context for\r
+  subsequent use.\r
+\r
+  If HashContext is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[out]  HashContext  Pointer to Hashcontext being initialized.\r
+\r
+  @retval TRUE   Hash context initialization succeeded.\r
+  @retval FALSE  Hash context initialization failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+typedef\r
+BOOLEAN\r
+(EFIAPI *EFI_HASH_INIT) (\r
+  OUT  VOID  *HashContext\r
+  );\r
+\r
+/**\r
+  Digests the input data and updates Hash context.\r
+\r
+  This function performs Hash digest on a data buffer of the specified size.\r
+  It can be called multiple times to compute the digest of long or discontinuous data streams.\r
+  Hash context should be already correctly intialized by HashInit(), and should not be finalized\r
+  by HashFinal(). Behavior with invalid context is undefined.\r
+\r
+  If HashContext is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  HashContext  Pointer to the Hash context.\r
+  @param[in]       Data         Pointer to the buffer containing the data to be hashed.\r
+  @param[in]       DataSize     Size of Data buffer in bytes.\r
+\r
+  @retval TRUE   SHA-1 data digest succeeded.\r
+  @retval FALSE  SHA-1 data digest failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+typedef\r
+BOOLEAN\r
+(EFIAPI *EFI_HASH_UPDATE) (\r
+  IN OUT  VOID        *HashContext,\r
+  IN      CONST VOID  *Data,\r
+  IN      UINTN       DataSize\r
+  );\r
+\r
+/**\r
+  Completes computation of the Hash digest value.\r
+\r
+  This function completes hash computation and retrieves the digest value into\r
+  the specified memory. After this function has been called, the Hash context cannot\r
+  be used again.\r
+  Hash context should be already correctly intialized by HashInit(), and should not be\r
+  finalized by HashFinal(). Behavior with invalid Hash context is undefined.\r
+\r
+  If HashContext is NULL, then return FALSE.\r
+  If HashValue is NULL, then return FALSE.\r
+  If this interface is not supported, then return FALSE.\r
+\r
+  @param[in, out]  HashContext  Pointer to the Hash context.\r
+  @param[out]      HashValue    Pointer to a buffer that receives the Hash digest\r
+                                value.\r
+\r
+  @retval TRUE   Hash digest computation succeeded.\r
+  @retval FALSE  Hash digest computation failed.\r
+  @retval FALSE  This interface is not supported.\r
+\r
+**/\r
+typedef\r
+BOOLEAN\r
+(EFIAPI *EFI_HASH_FINAL) (\r
+  IN OUT  VOID   *HashContext,\r
+  OUT     UINT8  *HashValue\r
+  );\r
+\r
+typedef struct {\r
+  EFI_GUID                   *Guid;\r
+  UINT32                     HashSize;\r
+  EFI_HASH_GET_CONTEXT_SIZE  GetContextSize;\r
+  EFI_HASH_INIT              Init;\r
+  EFI_HASH_UPDATE            Update;\r
+  EFI_HASH_FINAL             Final;\r
+} EFI_HASH_INFO;\r
+\r
+EFI_HASH_INFO  mHashInfo[] = {\r
+  {&gEfiHashAlgorithmSha1Guid,    sizeof(EFI_SHA1_HASH2),   Sha1GetContextSize,   Sha1Init,   Sha1Update,   Sha1Final   },\r
+  {&gEfiHashAlgorithmSha256Guid,  sizeof(EFI_SHA256_HASH2), Sha256GetContextSize, Sha256Init, Sha256Update, Sha256Final },\r
+  {&gEfiHashAlgorithmSha384Guid,  sizeof(EFI_SHA384_HASH2), Sha384GetContextSize, Sha384Init, Sha384Update, Sha384Final },\r
+  {&gEfiHashAlgorithmSha512Guid,  sizeof(EFI_SHA512_HASH2), Sha512GetContextSize, Sha512Init, Sha512Update, Sha512Final },\r
+};\r
+\r
+/**\r
+  Returns the size of the hash which results from a specific algorithm.\r
+\r
+  @param[in]  This                  Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  HashAlgorithm         Points to the EFI_GUID which identifies the algorithm to use.\r
+  @param[out] HashSize              Holds the returned size of the algorithm's hash.\r
+\r
+  @retval EFI_SUCCESS           Hash size returned successfully.\r
+  @retval EFI_INVALID_PARAMETER This or HashSize is NULL.\r
+  @retval EFI_UNSUPPORTED       The algorithm specified by HashAlgorithm is not supported by this driver\r
+                                or HashAlgorithm is null.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2GetHashSize (\r
+  IN  CONST EFI_HASH2_PROTOCOL     *This,\r
+  IN  CONST EFI_GUID               *HashAlgorithm,\r
+  OUT UINTN                        *HashSize\r
+  );\r
+\r
+/**\r
+  Creates a hash for the specified message text. The hash is not extendable.\r
+  The output is final with any algorithm-required padding added by the function.\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.\r
+  @param[in]  Message       Points to the start of the message.\r
+  @param[in]  MessageSize   The size of Message, in bytes.\r
+  @param[in,out]  Hash      On input, points to a caller-allocated buffer of the size\r
+                              returned by GetHashSize() for the specified HashAlgorithm.\r
+                            On output, the buffer holds the resulting hash computed from the message.\r
+\r
+  @retval EFI_SUCCESS           Hash returned successfully.\r
+  @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r
+  @retval EFI_UNSUPPORTED       The algorithm specified by HashAlgorithm is not supported by this driver\r
+                                or HashAlgorithm is Null.\r
+  @retval EFI_OUT_OF_RESOURCES  Some resource required by the function is not available\r
+                                or MessageSize is greater than platform maximum.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2Hash (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN CONST EFI_GUID                *HashAlgorithm,\r
+  IN CONST UINT8                   *Message,\r
+  IN UINTN                         MessageSize,\r
+  IN OUT EFI_HASH2_OUTPUT          *Hash\r
+  );\r
+\r
+/**\r
+  This function must be called to initialize a digest calculation to be subsequently performed using the\r
+  EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal().\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.\r
+\r
+  @retval EFI_SUCCESS           Initialized successfully.\r
+  @retval EFI_INVALID_PARAMETER This is NULL.\r
+  @retval EFI_UNSUPPORTED       The algorithm specified by HashAlgorithm is not supported by this driver\r
+                                or HashAlgorithm is Null.\r
+  @retval EFI_OUT_OF_RESOURCES  Process failed due to lack of required resource.\r
+  @retval EFI_ALREADY_STARTED   This function is called when the operation in progress is still in processing Hash(),\r
+                                or HashInit() is already called before and not terminated by HashFinal() yet on the same instance.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2HashInit (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN CONST EFI_GUID                *HashAlgorithm\r
+  );\r
+\r
+/**\r
+  Updates the hash of a computation in progress by adding a message text.\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  Message       Points to the start of the message.\r
+  @param[in]  MessageSize   The size of Message, in bytes.\r
+\r
+  @retval EFI_SUCCESS           Digest in progress updated successfully.\r
+  @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES  Some resource required by the function is not available\r
+                                or MessageSize is greater than platform maximum.\r
+  @retval EFI_NOT_READY         This call was not preceded by a valid call to HashInit(),\r
+                                or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2HashUpdate (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN CONST UINT8                   *Message,\r
+  IN UINTN                         MessageSize\r
+  );\r
+\r
+/**\r
+  Finalizes a hash operation in progress and returns calculation result.\r
+  The output is final with any necessary padding added by the function.\r
+  The hash may not be further updated or extended after HashFinal().\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in,out]  Hash      On input, points to a caller-allocated buffer of the size\r
+                              returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit().\r
+                            On output, the buffer holds the resulting hash computed from the message.\r
+\r
+  @retval EFI_SUCCESS           Hash returned successfully.\r
+  @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r
+  @retval EFI_NOT_READY         This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(),\r
+                                or the operation in progress was canceled by a call to Hash() on the same instance.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2HashFinal (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN OUT EFI_HASH2_OUTPUT          *Hash\r
+  );\r
+\r
+EFI_HASH2_PROTOCOL mHash2Protocol = {\r
+  BaseCrypto2GetHashSize,\r
+  BaseCrypto2Hash,\r
+  BaseCrypto2HashInit,\r
+  BaseCrypto2HashUpdate,\r
+  BaseCrypto2HashFinal,\r
+};\r
+\r
+/**\r
+  Returns hash information.\r
+\r
+  @param[in]  HashAlgorithm         Points to the EFI_GUID which identifies the algorithm to use.\r
+\r
+  @return Hash information.\r
+**/\r
+EFI_HASH_INFO *\r
+GetHashInfo (\r
+  IN CONST EFI_GUID              *HashAlgorithm\r
+  )\r
+{\r
+  UINTN      Index;\r
+\r
+  for (Index = 0; Index < sizeof(mHashInfo)/sizeof(mHashInfo[0]); Index++) {\r
+    if (CompareGuid (HashAlgorithm, mHashInfo[Index].Guid)) {\r
+      return &mHashInfo[Index];\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Returns the size of the hash which results from a specific algorithm.\r
+\r
+  @param[in]  This                  Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  HashAlgorithm         Points to the EFI_GUID which identifies the algorithm to use.\r
+  @param[out] HashSize              Holds the returned size of the algorithm's hash.\r
+\r
+  @retval EFI_SUCCESS           Hash size returned successfully.\r
+  @retval EFI_INVALID_PARAMETER This or HashSize is NULL.\r
+  @retval EFI_UNSUPPORTED       The algorithm specified by HashAlgorithm is not supported by this driver\r
+                                or HashAlgorithm is null.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2GetHashSize (\r
+  IN  CONST EFI_HASH2_PROTOCOL     *This,\r
+  IN  CONST EFI_GUID              *HashAlgorithm,\r
+  OUT UINTN                       *HashSize\r
+  )\r
+{\r
+  EFI_HASH_INFO *HashInfo;\r
+\r
+  if ((This == NULL) || (HashSize == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (HashAlgorithm == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  HashInfo = GetHashInfo (HashAlgorithm);\r
+  if (HashInfo == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  *HashSize = HashInfo->HashSize;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Creates a hash for the specified message text. The hash is not extendable.\r
+  The output is final with any algorithm-required padding added by the function.\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.\r
+  @param[in]  Message       Points to the start of the message.\r
+  @param[in]  MessageSize   The size of Message, in bytes.\r
+  @param[in,out]  Hash      On input, points to a caller-allocated buffer of the size\r
+                              returned by GetHashSize() for the specified HashAlgorithm.\r
+                            On output, the buffer holds the resulting hash computed from the message.\r
+\r
+  @retval EFI_SUCCESS           Hash returned successfully.\r
+  @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r
+  @retval EFI_UNSUPPORTED       The algorithm specified by HashAlgorithm is not supported by this driver\r
+                                or HashAlgorithm is Null.\r
+  @retval EFI_OUT_OF_RESOURCES  Some resource required by the function is not available\r
+                                or MessageSize is greater than platform maximum.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2Hash (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN CONST EFI_GUID                *HashAlgorithm,\r
+  IN CONST UINT8                   *Message,\r
+  IN UINTN                         MessageSize,\r
+  IN OUT EFI_HASH2_OUTPUT          *Hash\r
+  )\r
+{\r
+  EFI_HASH_INFO            *HashInfo;\r
+  VOID                     *HashCtx;\r
+  UINTN                    CtxSize;\r
+  BOOLEAN                  Ret;\r
+  EFI_STATUS               Status;\r
+\r
+  Status = EFI_SUCCESS;\r
+\r
+  if ((This == NULL) || (Hash == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (HashAlgorithm == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  HashInfo = GetHashInfo (HashAlgorithm);\r
+  if (HashInfo == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Start hash sequence\r
+  //\r
+  CtxSize = HashInfo->GetContextSize ();\r
+  if (CtxSize == 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  HashCtx = AllocatePool (CtxSize);\r
+  if (HashCtx == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Ret = HashInfo->Init (HashCtx);\r
+  if (!Ret) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Done;\r
+  }\r
+\r
+  Ret = HashInfo->Update (HashCtx, Message, MessageSize);\r
+  if (!Ret) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Done;\r
+  }\r
+\r
+  Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash);\r
+  if (!Ret) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Done;\r
+  }\r
+Done:\r
+  FreePool (HashCtx);\r
+  return Status;\r
+}\r
+\r
+/**\r
+  This function must be called to initialize a digest calculation to be subsequently performed using the\r
+  EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal().\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.\r
+\r
+  @retval EFI_SUCCESS           Initialized successfully.\r
+  @retval EFI_INVALID_PARAMETER This is NULL.\r
+  @retval EFI_UNSUPPORTED       The algorithm specified by HashAlgorithm is not supported by this driver\r
+                                or HashAlgorithm is Null.\r
+  @retval EFI_OUT_OF_RESOURCES  Process failed due to lack of required resource.\r
+  @retval EFI_ALREADY_STARTED   This function is called when the operation in progress is still in processing Hash(),\r
+                                or HashInit() is already called before and not terminated by HashFinal() yet on the same instance.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2HashInit (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN CONST EFI_GUID                *HashAlgorithm\r
+  )\r
+{\r
+  EFI_HASH_INFO            *HashInfo;\r
+  VOID                     *HashCtx;\r
+  UINTN                    CtxSize;\r
+  BOOLEAN                  Ret;\r
+  HASH2_INSTANCE_DATA      *Instance;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (HashAlgorithm == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  HashInfo = GetHashInfo (HashAlgorithm);\r
+  if (HashInfo == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
+  //\r
+  // Consistency Check\r
+  //\r
+  Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r
+  if ((Instance->HashContext != NULL) || (Instance->HashInfoContext != HashInfo)) {\r
+    return EFI_ALREADY_STARTED;\r
+  }\r
+\r
+  //\r
+  // Start hash sequence\r
+  //\r
+  CtxSize = HashInfo->GetContextSize ();\r
+  if (CtxSize == 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+  HashCtx = AllocatePool (CtxSize);\r
+  if (HashCtx == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  Ret = HashInfo->Init (HashCtx);\r
+  if (!Ret) {\r
+    FreePool (HashCtx);\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  //\r
+  // Setup the context\r
+  //\r
+  Instance->HashContext = HashCtx;\r
+  Instance->HashInfoContext = HashInfo;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Updates the hash of a computation in progress by adding a message text.\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in]  Message       Points to the start of the message.\r
+  @param[in]  MessageSize   The size of Message, in bytes.\r
+\r
+  @retval EFI_SUCCESS           Digest in progress updated successfully.\r
+  @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r
+  @retval EFI_OUT_OF_RESOURCES  Some resource required by the function is not available\r
+                                or MessageSize is greater than platform maximum.\r
+  @retval EFI_NOT_READY         This call was not preceded by a valid call to HashInit(),\r
+                                or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2HashUpdate (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN CONST UINT8                   *Message,\r
+  IN UINTN                         MessageSize\r
+  )\r
+{\r
+  EFI_HASH_INFO            *HashInfo;\r
+  VOID                     *HashCtx;\r
+  BOOLEAN                  Ret;\r
+  HASH2_INSTANCE_DATA      *Instance;\r
+\r
+  if (This == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Consistency Check\r
+  //\r
+  Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r
+  if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL)) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  HashInfo = Instance->HashInfoContext;\r
+  HashCtx  = Instance->HashContext;\r
+\r
+  Ret = HashInfo->Update (HashCtx, Message, MessageSize);\r
+  if (!Ret) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Finalizes a hash operation in progress and returns calculation result.\r
+  The output is final with any necessary padding added by the function.\r
+  The hash may not be further updated or extended after HashFinal().\r
+\r
+  @param[in]  This          Points to this instance of EFI_HASH2_PROTOCOL.\r
+  @param[in,out]  Hash      On input, points to a caller-allocated buffer of the size\r
+                              returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit().\r
+                            On output, the buffer holds the resulting hash computed from the message.\r
+\r
+  @retval EFI_SUCCESS           Hash returned successfully.\r
+  @retval EFI_INVALID_PARAMETER This or Hash is NULL.\r
+  @retval EFI_NOT_READY         This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(),\r
+                                or the operation in progress was canceled by a call to Hash() on the same instance.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+BaseCrypto2HashFinal (\r
+  IN CONST EFI_HASH2_PROTOCOL      *This,\r
+  IN OUT EFI_HASH2_OUTPUT          *Hash\r
+  )\r
+{\r
+  EFI_HASH_INFO            *HashInfo;\r
+  VOID                     *HashCtx;\r
+  BOOLEAN                  Ret;\r
+  HASH2_INSTANCE_DATA      *Instance;\r
+\r
+  if ((This == NULL) || (Hash == NULL)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Consistency Check\r
+  //\r
+  Instance = HASH2_INSTANCE_DATA_FROM_THIS(This);\r
+  if ((Instance->HashContext == NULL) || (Instance->HashInfoContext == NULL)) {\r
+    return EFI_NOT_READY;\r
+  }\r
+  HashInfo = Instance->HashInfoContext;\r
+  HashCtx  = Instance->HashContext;\r
+\r
+  Ret = HashInfo->Final (HashCtx, (UINT8 *)Hash->Sha1Hash);\r
+\r
+  //\r
+  // Cleanup the context\r
+  //\r
+  FreePool (HashCtx);\r
+  Instance->HashInfoContext = NULL;\r
+  Instance->HashContext = NULL;\r
+\r
+  if (!Ret) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
diff --git a/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf
new file mode 100644 (file)
index 0000000..c4e6271
--- /dev/null
@@ -0,0 +1,62 @@
+## @file\r
+#  Produces the UEFI HASH2 protocol\r
+#\r
+#  This module will use EDKII crypto libary to HASH2 protocol.\r
+#\r
+#  Copyright (c) 2015, 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
+#  http://opensource.org/licenses/bsd-license.php\r
+#\r
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+  INF_VERSION                    = 0x00010005\r
+  BASE_NAME                      = Hash2DxeCrypto\r
+  FILE_GUID                      = 63E3BDCF-2AC7-4ac0-9B92-03A7541422FF\r
+  MODULE_TYPE                    = UEFI_DRIVER\r
+  VERSION_STRING                 = 1.0\r
+  ENTRY_POINT                    = Hash2DriverEntryPoint\r
+  MODULE_UNI_FILE                = Hash2DxeCrypto.uni\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+#  VALID_ARCHITECTURES           = IA32 X64 IPF\r
+#\r
+\r
+[Sources.common]\r
+  Hash2DxeCrypto.c\r
+  Driver.h\r
+  Driver.c\r
+\r
+[Packages]\r
+  MdePkg/MdePkg.dec\r
+  CryptoPkg/CryptoPkg.dec\r
+\r
+[LibraryClasses]\r
+  UefiBootServicesTableLib\r
+  BaseLib\r
+  BaseMemoryLib\r
+  BaseCryptLib\r
+  MemoryAllocationLib\r
+  UefiDriverEntryPoint\r
+  DebugLib\r
+  UefiLib\r
+\r
+[Guids]\r
+  gEfiHashAlgorithmSha1Guid\r
+  gEfiHashAlgorithmSha256Guid\r
+  gEfiHashAlgorithmSha384Guid\r
+  gEfiHashAlgorithmSha512Guid\r
+\r
+[Protocols]\r
+  gEfiHash2ProtocolGuid\r
+  gEfiHash2ServiceBindingProtocolGuid\r
+\r
+[UserExtensions.TianoCore."ExtraFiles"]\r
+  Hash2DxeCryptoExtra.uni
\ No newline at end of file
diff --git a/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.uni b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.uni
new file mode 100644 (file)
index 0000000..087cee6
Binary files /dev/null and b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.uni differ
diff --git a/SecurityPkg/Hash2DxeCrypto/Hash2DxeCryptoExtra.uni b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCryptoExtra.uni
new file mode 100644 (file)
index 0000000..123b0b4
Binary files /dev/null and b/SecurityPkg/Hash2DxeCrypto/Hash2DxeCryptoExtra.uni differ
index 68a7326e0306fa44145c0b3cd798e74f33d9b9f5..8bd4e7ae56cdc8411b29e5ffe6c3882060ad7639 100644 (file)
 \r
   SecurityPkg/Library/HashLibTpm2/HashLibTpm2.inf\r
 \r
 \r
   SecurityPkg/Library/HashLibTpm2/HashLibTpm2.inf\r
 \r
+  #\r
+  # Hash2\r
+  #\r
+  SecurityPkg/Hash2DxeCrypto/Hash2DxeCrypto.inf\r
+\r
+  #\r
+  # Other\r
+  #\r
   SecurityPkg/Library/DxeRsa2048Sha256GuidedSectionExtractLib/DxeRsa2048Sha256GuidedSectionExtractLib.inf\r
   SecurityPkg/Library/PeiRsa2048Sha256GuidedSectionExtractLib/PeiRsa2048Sha256GuidedSectionExtractLib.inf\r
   \r
   SecurityPkg/Library/DxeRsa2048Sha256GuidedSectionExtractLib/DxeRsa2048Sha256GuidedSectionExtractLib.inf\r
   SecurityPkg/Library/PeiRsa2048Sha256GuidedSectionExtractLib/PeiRsa2048Sha256GuidedSectionExtractLib.inf\r
   \r