diff options
author | Amol N Sukerkar <amol.n.sukerkar@intel.com> | 2020-02-03 10:18:50 -0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2020-02-03 23:49:28 +0000 |
commit | 3feea54eae33a6689bedf1e023edeb219faa76d6 (patch) | |
tree | c70d63f074e1a07b4e4e8126a697a6b01ffac71b /CryptoPkg/Include | |
parent | 2c061de06336d31dcc24d0765b702c975c6f06a9 (diff) | |
download | edk2-3feea54eae33a6689bedf1e023edeb219faa76d6.tar.gz edk2-3feea54eae33a6689bedf1e023edeb219faa76d6.tar.bz2 edk2-3feea54eae33a6689bedf1e023edeb219faa76d6.zip |
CryptoPkg/BaseHashApiLib: Implement Unified Hash Calculation API
https://bugzilla.tianocore.org/show_bug.cgi?id=2151
This commit introduces a Unified Hash API to calculate hash using a
hashing algorithm specified by the PCD, PcdHashApiLibPolicy. This library
interfaces with the various hashing API, such as, MD4, MD5, SHA1, SHA256,
SHA512 and SM3_256 implemented in BaseCryptLib. The user can calculate
the desired hash by setting PcdHashApiLibPolicy to appropriate value.
This feature is documented in the Bugzilla,
https://bugzilla.tianocore.org/show_bug.cgi?id=2151.
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Amol N Sukerkar <amol.n.sukerkar@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
Diffstat (limited to 'CryptoPkg/Include')
-rw-r--r-- | CryptoPkg/Include/Library/HashApiLib.h | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/CryptoPkg/Include/Library/HashApiLib.h b/CryptoPkg/Include/Library/HashApiLib.h new file mode 100644 index 0000000000..22068e5a17 --- /dev/null +++ b/CryptoPkg/Include/Library/HashApiLib.h @@ -0,0 +1,122 @@ +/** @file
+ Unified Hash API Defines
+
+ This API when called will calculate the Hash using the
+ hashing algorithm specified by PcdHashApiLibPolicy.
+
+ Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __BASEHASHAPILIB_H_
+#define __BASEHASHAPILIB_H_
+
+typedef VOID *HASH_API_CONTEXT;
+
+//
+// Hash Algorithms
+//
+#define HASH_API_ALGO_INVALID 0x00000000
+#define HASH_API_ALGO_MD4 0x00000001
+#define HASH_API_ALGO_MD5 0x00000002
+#define HASH_API_ALGO_SHA1 0x00000003
+#define HASH_API_ALGO_SHA256 0x00000004
+#define HASH_API_ALGO_SHA384 0x00000005
+#define HASH_API_ALGO_SHA512 0x00000006
+#define HASH_API_ALGO_SM3_256 0x00000007
+
+/**
+ Retrieves the size, in bytes, of the context buffer required for hash operations.
+
+ @return The size, in bytes, of the context buffer required for hash operations.
+**/
+UINTN
+EFIAPI
+HashApiGetContextSize (
+ VOID
+ );
+
+/**
+ Init hash sequence.
+
+ @param[out] HashContext Hash context.
+
+ @retval TRUE Hash start and HashHandle returned.
+ @retval FALSE Hash Init unsuccessful.
+**/
+BOOLEAN
+EFIAPI
+HashApiInit (
+ OUT HASH_API_CONTEXT HashContext
+ );
+
+/**
+ Makes a copy of an existing hash context.
+
+ @param[in] HashContext Hash context.
+ @param[out] NewHashContext New copy of hash context.
+
+ @retval TRUE Hash context copy succeeded.
+ @retval FALSE Hash context copy failed.
+**/
+BOOLEAN
+EFIAPI
+HashApiDuplicate (
+ IN HASH_API_CONTEXT HashContext,
+ OUT HASH_API_CONTEXT NewHashContext
+ );
+
+/**
+ Update hash data.
+
+ @param[in] HashContext Hash context.
+ @param[in] DataToHash Data to be hashed.
+ @param[in] DataToHashLen Data size.
+
+ @retval TRUE Hash updated.
+ @retval FALSE Hash updated unsuccessful.
+**/
+BOOLEAN
+EFIAPI
+HashApiUpdate (
+ IN HASH_API_CONTEXT HashContext,
+ IN VOID *DataToHash,
+ IN UINTN DataToHashLen
+ );
+
+/**
+ Hash complete.
+
+ @param[in] HashContext Hash context.
+ @param[out] Digest Hash Digest.
+
+ @retval TRUE Hash complete and Digest is returned.
+ @retval FALSE Hash complete unsuccessful.
+**/
+BOOLEAN
+EFIAPI
+HashApiFinal (
+ IN HASH_API_CONTEXT HashContext,
+ OUT UINT8 *Digest
+ );
+
+/**
+ Computes hash message digest of a input data buffer.
+
+ @param[in] DataToHash Data to be hashed.
+ @param[in] DataToHashLen Data size.
+ @param[out] Digest Hash Digest.
+
+ @retval TRUE Hash digest computation succeeded.
+ @retval FALSE Hash digest computation failed.
+**/
+BOOLEAN
+EFIAPI
+HashApiHashAll (
+ IN CONST VOID *DataToHash,
+ IN UINTN DataToHashLen,
+ OUT UINT8 *Digest
+ );
+
+#endif
|