diff options
author | Wenxing Hou <wenxing.hou@intel.com> | 2023-08-18 15:21:47 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2023-10-12 05:31:19 +0000 |
commit | b26f7dfe2927a276bf5c3238bec363abadd5a52f (patch) | |
tree | 9a1cca79269d6430521b943fd09de46187b7a653 /CryptoPkg/Library | |
parent | 97f51f2e9b78ce94127c2972841342edaefbcc80 (diff) | |
download | edk2-b26f7dfe2927a276bf5c3238bec363abadd5a52f.zip edk2-b26f7dfe2927a276bf5c3238bec363abadd5a52f.tar.gz edk2-b26f7dfe2927a276bf5c3238bec363abadd5a52f.tar.bz2 |
CryptoPkg: Add all .inf files for BaseCryptLibMbedTls
Add .inf files and other support files.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4177
Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yi Li <yi1.li@intel.com>
Cc: Xiaoyu Lu <xiaoyu1.lu@intel.com>
Cc: Guomin Jiang <guomin.jiang@intel.com>
Signed-off-by: Wenxing Hou <wenxing.hou@intel.com>
Reviewed-by: Yi Li <yi1.li@intel.com>
Diffstat (limited to 'CryptoPkg/Library')
17 files changed, 1434 insertions, 1 deletions
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/BaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/BaseCryptLib.inf new file mode 100644 index 0000000..16def79 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/BaseCryptLib.inf @@ -0,0 +1,81 @@ +## @file
+# Cryptographic Library Instance for DXE_DRIVER.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseCryptLib
+ FILE_GUID = 693C5308-AF95-4CE5-ADE9-CA011C2FC642
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|DXE_DRIVER DXE_CORE UEFI_APPLICATION UEFI_DRIVER
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Cipher/CryptAeadAesGcmNull.c
+ Cipher/CryptAes.c
+ Hash/CryptSha256.c
+ Hash/CryptSha512.c
+ Hash/CryptParallelHashNull.c
+ Hash/CryptSm3Null.c
+ Hash/CryptMd5.c
+ Hash/CryptSha1.c
+ Hmac/CryptHmac.c
+ Kdf/CryptHkdf.c
+ Pk/CryptRsaBasic.c
+ Pk/CryptRsaExtNull.c
+ Pk/CryptRsaPss.c
+ Pk/CryptRsaPssSignNull.c
+ Bn/CryptBnNull.c
+ Pem/CryptPemNull.c
+ Pk/CryptDhNull.c
+ Pk/CryptEcNull.c
+ Pk/CryptPkcs1OaepNull.c
+ Pk/CryptPkcs5Pbkdf2Null.c
+ Pk/CryptPkcs7SignNull.c
+ Pk/CryptPkcs7VerifyNull.c
+ Pk/CryptPkcs7VerifyEkuNull.c
+ Pk/CryptX509Null.c
+ Pk/CryptAuthenticodeNull.c
+ Pk/CryptTsNull.c
+ Rand/CryptRandNull.c
+ SysCall/CrtWrapper.c
+ SysCall/TimerWrapper.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ UefiRuntimeServicesTableLib
+ DebugLib
+ MbedTlsLib
+ PrintLib
+ IntrinsicLib
+ RngLib
+ SynchronizationLib
+[Protocols]
+ gEfiMpServiceProtocolGuid
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /GL-
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/PeiCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/PeiCryptLib.inf new file mode 100644 index 0000000..72b22a2 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/PeiCryptLib.inf @@ -0,0 +1,101 @@ +## @file
+# Cryptographic Library Instance for PEIM.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Note:
+# HMAC-SHA256 functions, AES functions, RSA external
+# functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, X.509
+# certificate handler functions, authenticode signature verification functions,
+# PEM handler functions, and pseudorandom number generator functions are not
+# supported in this instance.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = PeiCryptLib
+ MODULE_UNI_FILE = PeiCryptLib.uni
+ FILE_GUID = 91E0A3C3-37A7-4AEE-8689-C5B0AD2C8E63
+ MODULE_TYPE = PEIM
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|PEIM PEI_CORE
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Hash/CryptMd5.c
+ Hash/CryptSha1.c
+ Hash/CryptSha256.c
+ Hash/CryptSm3Null.c
+ Hash/CryptSha512.c
+ Hash/CryptParallelHashNull.c
+ Hmac/CryptHmac.c
+ Kdf/CryptHkdf.c
+ Cipher/CryptAes.c
+ Cipher/CryptAeadAesGcmNull.c
+ Pk/CryptRsaBasic.c
+ Pk/CryptRsaExtNull.c
+ Pk/CryptRsaPss.c
+ Pk/CryptRsaPssSignNull.c
+ Bn/CryptBnNull.c
+ Pem/CryptPemNull.c
+ Pk/CryptDhNull.c
+ Pk/CryptEcNull.c
+ Pk/CryptPkcs1OaepNull.c
+ Pk/CryptPkcs5Pbkdf2Null.c
+ Pk/CryptPkcs7SignNull.c
+ Pk/CryptPkcs7VerifyNull.c
+ Pk/CryptPkcs7VerifyEkuNull.c
+ Pk/CryptX509Null.c
+ Pk/CryptAuthenticodeNull.c
+ Pk/CryptTsNull.c
+ Rand/CryptRandNull.c
+ SysCall/CrtWrapper.c
+ SysCall/ConstantTimeClock.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ DebugLib
+ MbedTlsLib
+ IntrinsicLib
+ PrintLib
+ PeiServicesTablePointerLib
+ PeiServicesLib
+ SynchronizationLib
+
+[Ppis]
+ gEfiPeiMpServicesPpiGuid
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ #
+ # suppress the following warnings so we do not break the build with warnings-as-errors:
+ # C4090: 'function' : different 'const' qualifiers
+ # C4718: 'function call' : recursive call has no side effects, deleting
+ #
+ MSFT:*_*_*_CC_FLAGS = /wd4090 /wd4718
+
+ GCC:*_CLANG35_*_CC_FLAGS = -std=c99
+ GCC:*_CLANG38_*_CC_FLAGS = -std=c99
+ GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
+
+ XCODE:*_*_*_CC_FLAGS = -std=c99
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/PeiCryptLib.uni b/CryptoPkg/Library/BaseCryptLibMbedTls/PeiCryptLib.uni new file mode 100644 index 0000000..3a68456 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/PeiCryptLib.uni @@ -0,0 +1,25 @@ +// /** @file
+// Cryptographic Library Instance for PEIM.
+//
+// Caution: This module requires additional review when modified.
+// This library will have external input - signature.
+// This external input must be validated carefully to avoid security issues such as
+// buffer overflow or integer overflow.
+//
+// Note: AES
+// functions, RSA external functions, PKCS#7 SignedData sign functions,
+// Diffie-Hellman functions, X.509 certificate handler functions, authenticode
+// signature verification functions, PEM handler functions, and pseudorandom number
+// generator functions are not supported in this instance.
+//
+// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Cryptographic Library Instance for PEIM"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Caution: This module requires additional review when modified. This library will have external input - signature. This external input must be validated carefully to avoid security issues such as buffer overflow or integer overflow. Note: AES functions, RSA external functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, X.509 certificate handler functions, authenticode signature verification functions, PEM handler functions, and pseudorandom number generator functions are not supported in this instance."
+
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/RuntimeCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/RuntimeCryptLib.inf new file mode 100644 index 0000000..9f17ef0 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/RuntimeCryptLib.inf @@ -0,0 +1,92 @@ +## @file
+# Cryptographic Library Instance for DXE_RUNTIME_DRIVER.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Note: SHA-384 Digest functions, SHA-512 Digest functions,
+# HMAC-SHA256 functions, AES functions, RSA external
+# functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, and
+# authenticode signature verification functions are not supported in this instance.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = RuntimeCryptLib
+ MODULE_UNI_FILE = RuntimeCryptLib.uni
+ FILE_GUID = D263B580-D9FC-4DC4-B445-578AAEFF530E
+ MODULE_TYPE = DXE_RUNTIME_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|DXE_RUNTIME_DRIVER
+ CONSTRUCTOR = RuntimeCryptLibConstructor
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Hash/CryptMd5.c
+ Hash/CryptSha1.c
+ Hash/CryptSha256.c
+ Hash/CryptSm3Null.c
+ Hash/CryptSha512.c
+ Hash/CryptParallelHashNull.c
+ Hmac/CryptHmac.c
+ Kdf/CryptHkdf.c
+ Cipher/CryptAes.c
+ Cipher/CryptAeadAesGcmNull.c
+ Pk/CryptRsaBasic.c
+ Pk/CryptRsaExtNull.c
+ Pk/CryptRsaPssNull.c
+ Pk/CryptRsaPssSignNull.c
+ Bn/CryptBnNull.c
+ Pem/CryptPemNull.c
+ Pk/CryptDhNull.c
+ Pk/CryptEcNull.c
+ Pk/CryptPkcs1OaepNull.c
+ Pk/CryptPkcs5Pbkdf2Null.c
+ Pk/CryptPkcs7SignNull.c
+ Pk/CryptPkcs7VerifyNull.c
+ Pk/CryptPkcs7VerifyEkuNull.c
+ Pk/CryptX509Null.c
+ Pk/CryptAuthenticodeNull.c
+ Pk/CryptTsNull.c
+ Rand/CryptRandNull.c
+ SysCall/CrtWrapper.c
+ SysCall/TimerWrapper.c
+ SysCall/RuntimeMemAllocation.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ UefiRuntimeServicesTableLib
+ DebugLib
+ MbedTlsLib
+ IntrinsicLib
+ PrintLib
+
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ #
+ # suppress the following warnings so we do not break the build with warnings-as-errors:
+ #
+ GCC:*_CLANG35_*_CC_FLAGS = -std=c99
+ GCC:*_CLANG38_*_CC_FLAGS = -std=c99
+ GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
+
+ XCODE:*_*_*_CC_FLAGS = -std=c99
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/RuntimeCryptLib.uni b/CryptoPkg/Library/BaseCryptLibMbedTls/RuntimeCryptLib.uni new file mode 100644 index 0000000..b2a2f5f --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/RuntimeCryptLib.uni @@ -0,0 +1,22 @@ +// /** @file
+// Cryptographic Library Instance for DXE_RUNTIME_DRIVER.
+//
+// Caution: This module requires additional review when modified.
+// This library will have external input - signature.
+// This external input must be validated carefully to avoid security issues such as
+// buffer overflow or integer overflow.
+//
+// Note: AES
+// functions, RSA external functions, PKCS#7 SignedData sign functions,
+// Diffie-Hellman functions, and authenticode signature verification functions are
+// not supported in this instance.
+//
+// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Cryptographic Library Instance for DXE_RUNTIME_DRIVER"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Caution: This module requires additional review when modified. This library will have external input - signature. This external input must be validated carefully to avoid security issues such as buffer overflow or integer overflow. Note: AES functions, RSA external functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, and authenticode signature verification functions are not supported in this instance."
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SecCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/SecCryptLib.inf new file mode 100644 index 0000000..6fc073a --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SecCryptLib.inf @@ -0,0 +1,84 @@ +## @file
+# Cryptographic Library Instance for SEC.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SecCryptLib
+ MODULE_UNI_FILE = SecCryptLib.uni
+ FILE_GUID = 894C367F-254A-4563-8624-798D46EAD796
+ MODULE_TYPE = BASE
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|SEC
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Hash/CryptSha512.c
+
+ Hash/CryptMd5Null.c
+ Hash/CryptSha1Null.c
+ Hash/CryptSha256Null.c
+ Hash/CryptSm3Null.c
+ Hash/CryptParallelHashNull.c
+ Hmac/CryptHmacNull.c
+ Kdf/CryptHkdfNull.c
+ Cipher/CryptAesNull.c
+ Cipher/CryptAeadAesGcmNull.c
+ Pk/CryptRsaBasicNull.c
+ Pk/CryptRsaExtNull.c
+ Bn/CryptBnNull.c
+ Pem/CryptPemNull.c
+ Pk/CryptDhNull.c
+ Pk/CryptEcNull.c
+ Pk/CryptPkcs1OaepNull.c
+ Pk/CryptPkcs5Pbkdf2Null.c
+ Pk/CryptPkcs7SignNull.c
+ Pk/CryptPkcs7VerifyNull.c
+ Pk/CryptPkcs7VerifyEkuNull.c
+ Pk/CryptX509Null.c
+ Pk/CryptAuthenticodeNull.c
+ Pk/CryptTsNull.c
+ Rand/CryptRandNull.c
+ SysCall/CrtWrapper.c
+ SysCall/ConstantTimeClock.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ DebugLib
+ MbedTlsLib
+ IntrinsicLib
+ PrintLib
+
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ #
+ # suppress the following warnings so we do not break the build with warnings-as-errors:
+ #
+ GCC:*_CLANG35_*_CC_FLAGS = -std=c99
+ GCC:*_CLANG38_*_CC_FLAGS = -std=c99
+ GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
+
+ XCODE:*_*_*_CC_FLAGS = -std=c99
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SecCryptLib.uni b/CryptoPkg/Library/BaseCryptLibMbedTls/SecCryptLib.uni new file mode 100644 index 0000000..be2fc40 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SecCryptLib.uni @@ -0,0 +1,17 @@ +// /** @file
+// Cryptographic Library Instance for SEC driver.
+//
+// Caution: This module requires additional review when modified.
+// This library will have external input - signature.
+// This external input must be validated carefully to avoid security issues such as
+// buffer overflow or integer overflow.
+//
+// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Cryptographic Library Instance for SEC driver"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Caution: This module requires additional review when modified. This library will have external input - signature. This external input must be validated carefully to avoid security issues such as buffer overflow or integer overflow. Note: AES functions, RSA external functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, and authenticode signature verification functions are not supported in this instance."
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SmmCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/SmmCryptLib.inf new file mode 100644 index 0000000..40c56d1 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SmmCryptLib.inf @@ -0,0 +1,92 @@ +## @file
+# Cryptographic Library Instance for SMM driver.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Note: SHA-384 Digest functions, SHA-512 Digest functions,
+# RSA external functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, and
+# authenticode signature verification functions are not supported in this instance.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = SmmCryptLib
+ MODULE_UNI_FILE = SmmCryptLib.uni
+ FILE_GUID = CF104633-9901-4504-AD7A-91690926A253
+ MODULE_TYPE = DXE_SMM_DRIVER
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x0001000A
+ LIBRARY_CLASS = BaseCryptLib|DXE_SMM_DRIVER SMM_CORE MM_STANDALONE
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Hash/CryptMd5.c
+ Hash/CryptSha1.c
+ Hash/CryptSha256.c
+ Hash/CryptSm3Null.c
+ Hash/CryptSha512.c
+ Hash/CryptParallelHashNull.c
+ Hmac/CryptHmac.c
+ Kdf/CryptHkdf.c
+ Cipher/CryptAes.c
+ Cipher/CryptAeadAesGcmNull.c
+ Pk/CryptRsaBasic.c
+ Pk/CryptRsaExtNull.c
+ Pk/CryptRsaPss.c
+ Pk/CryptRsaPssSignNull.c
+ Bn/CryptBnNull.c
+ Pem/CryptPemNull.c
+ Pk/CryptDhNull.c
+ Pk/CryptEcNull.c
+ Pk/CryptPkcs1OaepNull.c
+ Pk/CryptPkcs5Pbkdf2Null.c
+ Pk/CryptPkcs7SignNull.c
+ Pk/CryptPkcs7VerifyNull.c
+ Pk/CryptPkcs7VerifyEkuNull.c
+ Pk/CryptX509Null.c
+ Pk/CryptAuthenticodeNull.c
+ Pk/CryptTsNull.c
+ Rand/CryptRandNull.c
+ SysCall/CrtWrapper.c
+ SysCall/ConstantTimeClock.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ MbedTlsLib
+ IntrinsicLib
+ PrintLib
+ MmServicesTableLib
+ SynchronizationLib
+
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ #
+ # suppress the following warnings so we do not break the build with warnings-as-errors:
+ #
+
+ XCODE:*_*_*_CC_FLAGS = -mmmx -msse -std=c99
+
+ GCC:*_CLANG35_*_CC_FLAGS = -std=c99
+ GCC:*_CLANG38_*_CC_FLAGS = -std=c99
+ GCC:*_CLANGPDB_*_CC_FLAGS = -std=c99 -Wno-error=incompatible-pointer-types
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SmmCryptLib.uni b/CryptoPkg/Library/BaseCryptLibMbedTls/SmmCryptLib.uni new file mode 100644 index 0000000..13948c2 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SmmCryptLib.uni @@ -0,0 +1,22 @@ +// /** @file
+// Cryptographic Library Instance for SMM driver.
+//
+// Caution: This module requires additional review when modified.
+// This library will have external input - signature.
+// This external input must be validated carefully to avoid security issues such as
+// buffer overflow or integer overflow.
+//
+// Note: AES
+// functions, RSA external functions, PKCS#7 SignedData sign functions,
+// Diffie-Hellman functions, and authenticode signature verification functions are
+// not supported in this instance.
+//
+// Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_MODULE_ABSTRACT #language en-US "Cryptographic Library Instance for SMM driver"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Caution: This module requires additional review when modified. This library will have external input - signature. This external input must be validated carefully to avoid security issues such as buffer overflow or integer overflow. Note: AES functions, RSA external functions, PKCS#7 SignedData sign functions, Diffie-Hellman functions, and authenticode signature verification functions are not supported in this instance."
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/ConstantTimeClock.c b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/ConstantTimeClock.c new file mode 100644 index 0000000..2ec13ef --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/ConstantTimeClock.c @@ -0,0 +1,75 @@ +/** @file
+ C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation
+ for MbedTLS-based Cryptographic Library.
+
+ This C file implements constant time value for time() and NULL for gmtime()
+ thus should not be used in library instances which require functionality
+ of following APIs which need system time support:
+ 1) RsaGenerateKey
+ 2) RsaCheckKey
+ 3) RsaPkcs1Sign
+ 4) Pkcs7Sign
+ 5) DhGenerateParameter
+ 6) DhGenerateKey
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseMemoryLib.h>
+
+typedef int time_t;
+
+//
+// Structures Definitions
+//
+struct tm {
+ int tm_sec; /* seconds after the minute [0-60] */
+ int tm_min; /* minutes after the hour [0-59] */
+ int tm_hour; /* hours since midnight [0-23] */
+ int tm_mday; /* day of the month [1-31] */
+ int tm_mon; /* months since January [0-11] */
+ int tm_year; /* years since 1900 */
+ int tm_wday; /* days since Sunday [0-6] */
+ int tm_yday; /* days since January 1 [0-365] */
+ int tm_isdst; /* Daylight Savings Time flag */
+ long tm_gmtoff; /* offset from CUT in seconds */
+ char *tm_zone; /* timezone abbreviation */
+};
+
+//
+// -- Time Management Routines --
+//
+
+/**time function. **/
+time_t
+time (
+ time_t *timer
+ )
+{
+ if (timer != NULL) {
+ *timer = 0;
+ }
+
+ return 0;
+}
+
+/**gmtime function. **/
+struct tm *
+gmtime (
+ const time_t *timer
+ )
+{
+ return NULL;
+}
+
+/**_time64 function. **/
+time_t
+_time64 (
+ time_t *t
+ )
+{
+ return time (t);
+}
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/CrtWrapper.c b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/CrtWrapper.c new file mode 100644 index 0000000..f1d9b9c --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/CrtWrapper.c @@ -0,0 +1,58 @@ +/** @file
+ C Run-Time Libraries (CRT) Wrapper Implementation for MbedTLS-based
+ Cryptographic Library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <stdio.h>
+
+/**dummy mbedtls_printf function. **/
+int
+mbedtls_printf (
+ char const *fmt,
+ ...
+ )
+{
+ ASSERT (FALSE);
+ return 0;
+}
+
+/**dummy mbedtls_vsnprintf function. **/
+int
+mbedtls_vsnprintf (
+ char *str,
+ size_t size,
+ const char *format,
+ ...
+ )
+{
+ ASSERT (FALSE);
+ return 0;
+}
+
+/**strchr function. **/
+char *
+strchr (
+ const char *str,
+ int ch
+ )
+{
+ return ScanMem8 (str, AsciiStrSize (str), (char)ch);
+}
+
+/**strcmp function. **/
+int
+strcmp (
+ const char *s1,
+ const char *s2
+ )
+{
+ return (int)AsciiStrCmp (s1, s2);
+}
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/RuntimeMemAllocation.c b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/RuntimeMemAllocation.c new file mode 100644 index 0000000..5199202 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/RuntimeMemAllocation.c @@ -0,0 +1,462 @@ +/** @file
+ Light-weight Memory Management Routines for MbedTLS-based Crypto
+ Library at Runtime Phase.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <CrtLibSupport.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/UefiRuntimeLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Guid/EventGroup.h>
+
+// ----------------------------------------------------------------
+// Initial version. Needs further optimizations.
+// ----------------------------------------------------------------
+
+//
+// Definitions for Runtime Memory Operations
+//
+#define RT_PAGE_SIZE 0x200
+#define RT_PAGE_MASK 0x1FF
+#define RT_PAGE_SHIFT 9
+
+#define RT_SIZE_TO_PAGES(a) (((a) >> RT_PAGE_SHIFT) + (((a) & RT_PAGE_MASK) ? 1 : 0))
+#define RT_PAGES_TO_SIZE(a) ((a) << RT_PAGE_SHIFT)
+
+//
+// Page Flag Definitions
+//
+#define RT_PAGE_FREE 0x00000000
+#define RT_PAGE_USED 0x00000001
+
+#define MIN_REQUIRED_BLOCKS 600
+
+//
+// Memory Page Table
+//
+typedef struct {
+ UINTN StartPageOffset; // Offset of the starting page allocated.
+ // Only available for USED pages.
+ UINT32 PageFlag; // Page Attributes.
+} RT_MEMORY_PAGE_ENTRY;
+
+typedef struct {
+ UINTN PageCount;
+ UINTN LastEmptyPageOffset;
+ UINT8 *DataAreaBase; // Pointer to data Area.
+ RT_MEMORY_PAGE_ENTRY Pages[1]; // Page Table Entries.
+} RT_MEMORY_PAGE_TABLE;
+
+//
+// Global Page Table for Runtime Cryptographic Provider.
+//
+RT_MEMORY_PAGE_TABLE *mRTPageTable = NULL;
+
+//
+// Event for Runtime Address Conversion.
+//
+STATIC EFI_EVENT mVirtualAddressChangeEvent;
+
+/**
+ Initializes pre-allocated memory pointed by ScratchBuffer for subsequent
+ runtime use.
+
+ @param[in, out] ScratchBuffer Pointer to user-supplied memory buffer.
+ @param[in] ScratchBufferSize Size of supplied buffer in bytes.
+
+ @retval EFI_SUCCESS Successful initialization.
+
+**/
+EFI_STATUS
+InitializeScratchMemory (
+ IN OUT UINT8 *ScratchBuffer,
+ IN UINTN ScratchBufferSize
+ )
+{
+ UINTN Index;
+ UINTN MemorySize;
+
+ //
+ // Parameters Checking
+ //
+ if (ScratchBuffer == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ScratchBufferSize < MIN_REQUIRED_BLOCKS * 1024) {
+ return EFI_BUFFER_TOO_SMALL;
+ }
+
+ mRTPageTable = (RT_MEMORY_PAGE_TABLE *)ScratchBuffer;
+
+ //
+ // Initialize Internal Page Table for Memory Management
+ //
+ SetMem (mRTPageTable, ScratchBufferSize, 0xFF);
+ MemorySize = ScratchBufferSize - sizeof (RT_MEMORY_PAGE_TABLE) + sizeof (RT_MEMORY_PAGE_ENTRY);
+
+ mRTPageTable->PageCount = MemorySize / (RT_PAGE_SIZE + sizeof (RT_MEMORY_PAGE_ENTRY));
+ mRTPageTable->LastEmptyPageOffset = 0x0;
+
+ for (Index = 0; Index < mRTPageTable->PageCount; Index++) {
+ mRTPageTable->Pages[Index].PageFlag = RT_PAGE_FREE;
+ mRTPageTable->Pages[Index].StartPageOffset = 0;
+ }
+
+ mRTPageTable->DataAreaBase = ScratchBuffer + sizeof (RT_MEMORY_PAGE_TABLE) +
+ (mRTPageTable->PageCount - 1) * sizeof (RT_MEMORY_PAGE_ENTRY);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Look-up Free memory Region for object allocation.
+
+ @param[in] AllocationSize Bytes to be allocated.
+
+ @return Return available page offset for object allocation.
+
+**/
+UINTN
+LookupFreeMemRegion (
+ IN UINTN AllocationSize
+ )
+{
+ UINTN StartPageIndex;
+ UINTN Index;
+ UINTN SubIndex;
+ UINTN ReqPages;
+
+ StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->LastEmptyPageOffset);
+ ReqPages = RT_SIZE_TO_PAGES (AllocationSize);
+ if (ReqPages > mRTPageTable->PageCount) {
+ //
+ // No enough region for object allocation.
+ //
+ return (UINTN)(-1);
+ }
+
+ //
+ // Look up the free memory region with in current memory map table.
+ //
+ for (Index = StartPageIndex; Index <= (mRTPageTable->PageCount - ReqPages); ) {
+ //
+ // Check consecutive ReqPages pages.
+ //
+ for (SubIndex = 0; SubIndex < ReqPages; SubIndex++) {
+ if ((mRTPageTable->Pages[SubIndex + Index].PageFlag & RT_PAGE_USED) != 0) {
+ break;
+ }
+ }
+
+ if (SubIndex == ReqPages) {
+ //
+ // Succeed! Return the Starting Offset.
+ //
+ return RT_PAGES_TO_SIZE (Index);
+ }
+
+ //
+ // Failed! Skip current free memory pages and adjacent Used pages
+ //
+ while ((mRTPageTable->Pages[SubIndex + Index].PageFlag & RT_PAGE_USED) != 0) {
+ SubIndex++;
+ }
+
+ Index += SubIndex;
+ }
+
+ //
+ // Look up the free memory region from the beginning of the memory table
+ // until the StartCursorOffset
+ //
+ if (ReqPages > StartPageIndex) {
+ //
+ // No enough region for object allocation.
+ //
+ return (UINTN)(-1);
+ }
+
+ for (Index = 0; Index < (StartPageIndex - ReqPages); ) {
+ //
+ // Check Consecutive ReqPages Pages.
+ //
+ for (SubIndex = 0; SubIndex < ReqPages; SubIndex++) {
+ if ((mRTPageTable->Pages[SubIndex + Index].PageFlag & RT_PAGE_USED) != 0) {
+ break;
+ }
+ }
+
+ if (SubIndex == ReqPages) {
+ //
+ // Succeed! Return the Starting Offset.
+ //
+ return RT_PAGES_TO_SIZE (Index);
+ }
+
+ //
+ // Failed! Skip current adjacent Used pages
+ //
+ while ((SubIndex < (StartPageIndex - ReqPages)) &&
+ ((mRTPageTable->Pages[SubIndex + Index].PageFlag & RT_PAGE_USED) != 0))
+ {
+ SubIndex++;
+ }
+
+ Index += SubIndex;
+ }
+
+ //
+ // No available region for object allocation!
+ //
+ return (UINTN)(-1);
+}
+
+/**
+ Allocates a buffer at runtime phase.
+
+ @param[in] AllocationSize Bytes to be allocated.
+
+ @return A pointer to the allocated buffer or NULL if allocation fails.
+
+**/
+VOID *
+RuntimeAllocateMem (
+ IN UINTN AllocationSize
+ )
+{
+ UINT8 *AllocPtr;
+ UINTN ReqPages;
+ UINTN Index;
+ UINTN StartPage;
+ UINTN AllocOffset;
+
+ AllocPtr = NULL;
+ ReqPages = 0;
+
+ //
+ // Look for available consecutive memory region starting from LastEmptyPageOffset.
+ // If no proper memory region found, look up from the beginning.
+ // If still not found, return NULL to indicate failed allocation.
+ //
+ AllocOffset = LookupFreeMemRegion (AllocationSize);
+ if (AllocOffset == (UINTN)(-1)) {
+ return NULL;
+ }
+
+ //
+ // Allocates consecutive memory pages with length of Size. Update the page
+ // table status. Returns the starting address.
+ //
+ ReqPages = RT_SIZE_TO_PAGES (AllocationSize);
+ AllocPtr = mRTPageTable->DataAreaBase + AllocOffset;
+ StartPage = RT_SIZE_TO_PAGES (AllocOffset);
+ Index = 0;
+ while (Index < ReqPages) {
+ mRTPageTable->Pages[StartPage + Index].PageFlag |= RT_PAGE_USED;
+ mRTPageTable->Pages[StartPage + Index].StartPageOffset = AllocOffset;
+
+ Index++;
+ }
+
+ mRTPageTable->LastEmptyPageOffset = AllocOffset + RT_PAGES_TO_SIZE (ReqPages);
+
+ ZeroMem (AllocPtr, AllocationSize);
+
+ //
+ // Returns a VOID pointer to the allocated space
+ //
+ return AllocPtr;
+}
+
+/**
+ Frees a buffer that was previously allocated at runtime phase.
+
+ @param[in] Buffer Pointer to the buffer to free.
+
+**/
+VOID
+RuntimeFreeMem (
+ IN VOID *Buffer
+ )
+{
+ UINTN StartOffset;
+ UINTN StartPageIndex;
+
+ StartOffset = (UINTN)Buffer - (UINTN)mRTPageTable->DataAreaBase;
+ StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->Pages[RT_SIZE_TO_PAGES (StartOffset)].StartPageOffset);
+
+ while (StartPageIndex < mRTPageTable->PageCount) {
+ if (((mRTPageTable->Pages[StartPageIndex].PageFlag & RT_PAGE_USED) != 0) &&
+ (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset))
+ {
+ //
+ // Free this page
+ //
+ mRTPageTable->Pages[StartPageIndex].PageFlag &= ~RT_PAGE_USED;
+ mRTPageTable->Pages[StartPageIndex].PageFlag |= RT_PAGE_FREE;
+ mRTPageTable->Pages[StartPageIndex].StartPageOffset = 0;
+
+ StartPageIndex++;
+ } else {
+ break;
+ }
+ }
+
+ return;
+}
+
+/**
+ Notification function of EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE.
+
+ This is a notification function registered on EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE
+ event. It converts a pointer to a new virtual address.
+
+ @param[in] Event The event whose notification function is being invoked.
+ @param[in] Context The pointer to the notification function's context.
+
+**/
+VOID
+EFIAPI
+RuntimeCryptLibAddressChangeEvent (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ //
+ // Converts a pointer for runtime memory management to a new virtual address.
+ //
+ EfiConvertPointer (0x0, (VOID **)&mRTPageTable->DataAreaBase);
+ EfiConvertPointer (0x0, (VOID **)&mRTPageTable);
+}
+
+/**
+ Constructor routine for runtime crypt library instance.
+
+ The constructor function pre-allocates space for runtime cryptographic operation.
+
+ @param ImageHandle The firmware allocated handle for the EFI image.
+ @param SystemTable A pointer to the EFI System Table.
+
+ @retval EFI_SUCCESS The construction succeeded.
+ @retval EFI_OUT_OF_RESOURCE Failed to allocate memory.
+
+**/
+EFI_STATUS
+EFIAPI
+RuntimeCryptLibConstructor (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ VOID *Buffer;
+
+ //
+ // Pre-allocates runtime space for possible cryptographic operations
+ //
+ Buffer = AllocateRuntimePool (MIN_REQUIRED_BLOCKS * 1024);
+ Status = InitializeScratchMemory (Buffer, MIN_REQUIRED_BLOCKS * 1024);
+ if (EFI_ERROR (Status)) {
+ return Status;
+ }
+
+ //
+ // Create address change event
+ //
+ Status = gBS->CreateEventEx (
+ EVT_NOTIFY_SIGNAL,
+ TPL_NOTIFY,
+ RuntimeCryptLibAddressChangeEvent,
+ NULL,
+ &gEfiEventVirtualAddressChangeGuid,
+ &mVirtualAddressChangeEvent
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
+
+//
+// -- Memory-Allocation Routines Wrapper for UEFI-MbedTLS Library --
+//
+
+/** Allocates memory blocks. **/
+VOID *
+malloc (
+ size_t size
+ )
+{
+ return RuntimeAllocateMem ((UINTN)size);
+}
+
+/** Reallocate memory blocks. **/
+VOID *
+realloc (
+ VOID *ptr,
+ size_t size
+ )
+{
+ VOID *NewPtr;
+ UINTN StartOffset;
+ UINTN StartPageIndex;
+ UINTN PageCount;
+
+ if (ptr == NULL) {
+ return malloc (size);
+ }
+
+ //
+ // Get Original Size of ptr
+ //
+ StartOffset = (UINTN)ptr - (UINTN)mRTPageTable->DataAreaBase;
+ StartPageIndex = RT_SIZE_TO_PAGES (mRTPageTable->Pages[RT_SIZE_TO_PAGES (StartOffset)].StartPageOffset);
+ PageCount = 0;
+ while (StartPageIndex < mRTPageTable->PageCount) {
+ if (((mRTPageTable->Pages[StartPageIndex].PageFlag & RT_PAGE_USED) != 0) &&
+ (mRTPageTable->Pages[StartPageIndex].StartPageOffset == StartOffset))
+ {
+ StartPageIndex++;
+ PageCount++;
+ } else {
+ break;
+ }
+ }
+
+ if (size <= RT_PAGES_TO_SIZE (PageCount)) {
+ //
+ // Return the original pointer, if Caller try to reduce region size;
+ //
+ return ptr;
+ }
+
+ NewPtr = RuntimeAllocateMem ((UINTN)size);
+ if (NewPtr == NULL) {
+ return NULL;
+ }
+
+ CopyMem (NewPtr, ptr, RT_PAGES_TO_SIZE (PageCount));
+
+ RuntimeFreeMem (ptr);
+
+ return NewPtr;
+}
+
+/** Deallocates or frees a memory block. **/
+VOID
+free (
+ VOID *ptr
+ )
+{
+ //
+ // In Standard C, free() handles a null pointer argument transparently. This
+ // is not true of RuntimeFreeMem() below, so protect it.
+ //
+ if (ptr != NULL) {
+ RuntimeFreeMem (ptr);
+ }
+}
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/TimerWrapper.c b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/TimerWrapper.c new file mode 100644 index 0000000..b7cd4d3 --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/SysCall/TimerWrapper.c @@ -0,0 +1,198 @@ +/** @file
+ C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation
+ for MbedTLS-based Cryptographic Library (used in DXE & RUNTIME).
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/UefiRuntimeServicesTableLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+typedef int time_t;
+
+//
+// Structures Definitions
+//
+struct tm {
+ int tm_sec; /* seconds after the minute [0-60] */
+ int tm_min; /* minutes after the hour [0-59] */
+ int tm_hour; /* hours since midnight [0-23] */
+ int tm_mday; /* day of the month [1-31] */
+ int tm_mon; /* months since January [0-11] */
+ int tm_year; /* years since 1900 */
+ int tm_wday; /* days since Sunday [0-6] */
+ int tm_yday; /* days since January 1 [0-365] */
+ int tm_isdst; /* Daylight Savings Time flag */
+ long tm_gmtoff; /* offset from CUT in seconds */
+ char *tm_zone; /* timezone abbreviation */
+};
+
+//
+// -- Time Management Routines --
+//
+
+#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
+#define SECSPERMIN (60)
+#define SECSPERHOUR (60 * 60)
+#define SECSPERDAY (24 * SECSPERHOUR)
+
+//
+// The arrays give the cumulative number of days up to the first of the
+// month number used as the index (1 -> 12) for regular and leap years.
+// The value at index 13 is for the whole year.
+//
+UINTN CumulativeDays[2][14] = {
+ {
+ 0,
+ 0,
+ 31,
+ 31 + 28,
+ 31 + 28 + 31,
+ 31 + 28 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
+ 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31
+ },
+ {
+ 0,
+ 0,
+ 31,
+ 31 + 29,
+ 31 + 29 + 31,
+ 31 + 29 + 31 + 30,
+ 31 + 29 + 31 + 30 + 31,
+ 31 + 29 + 31 + 30 + 31 + 30,
+ 31 + 29 + 31 + 30 + 31 + 30 + 31,
+ 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,
+ 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
+ 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
+ 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
+ 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31
+ }
+};
+
+/** Get the system time as seconds elapsed since midnight, January 1, 1970. **/
+time_t
+time (
+ time_t *timer
+ )
+{
+ EFI_STATUS Status;
+ EFI_TIME Time;
+ time_t CalTime;
+ UINTN Year;
+
+ //
+ // Get the current time and date information
+ //
+ Status = gRT->GetTime (&Time, NULL);
+ if (EFI_ERROR (Status) || (Time.Year < 1970)) {
+ return 0;
+ }
+
+ //
+ // Years Handling
+ // UTime should now be set to 00:00:00 on Jan 1 of the current year.
+ //
+ for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {
+ CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
+ }
+
+ //
+ // Add in number of seconds for current Month, Day, Hour, Minute, Seconds, and TimeZone adjustment
+ //
+ CalTime = CalTime +
+ (time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +
+ (time_t)(CumulativeDays[IsLeap (Time.Year)][Time.Month] * SECSPERDAY) +
+ (time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) +
+ (time_t)(Time.Hour * SECSPERHOUR) +
+ (time_t)(Time.Minute * 60) +
+ (time_t)Time.Second;
+
+ if (timer != NULL) {
+ *timer = CalTime;
+ }
+
+ return CalTime;
+}
+
+/** Convert a time value from type time_t to struct tm. **/
+struct tm *
+gmtime (
+ const time_t *timer
+ )
+{
+ struct tm *GmTime;
+ UINT16 DayNo;
+ UINT16 DayRemainder;
+ time_t Year;
+ time_t YearNo;
+ UINT16 TotalDays;
+ UINT16 MonthNo;
+
+ if (timer == NULL) {
+ return NULL;
+ }
+
+ GmTime = AllocateZeroPool (sizeof (struct tm));
+ if (GmTime == NULL) {
+ return NULL;
+ }
+
+ ZeroMem ((VOID *)GmTime, (UINTN)sizeof (struct tm));
+
+ DayNo = (UINT16)(*timer / SECSPERDAY);
+ DayRemainder = (UINT16)(*timer % SECSPERDAY);
+
+ GmTime->tm_sec = (int)(DayRemainder % SECSPERMIN);
+ GmTime->tm_min = (int)((DayRemainder % SECSPERHOUR) / SECSPERMIN);
+ GmTime->tm_hour = (int)(DayRemainder / SECSPERHOUR);
+ GmTime->tm_wday = (int)((DayNo + 4) % 7);
+
+ for (Year = 1970, YearNo = 0; DayNo > 0; Year++) {
+ TotalDays = (UINT16)(IsLeap (Year) ? 366 : 365);
+ if (DayNo >= TotalDays) {
+ DayNo = (UINT16)(DayNo - TotalDays);
+ YearNo++;
+ } else {
+ break;
+ }
+ }
+
+ GmTime->tm_year = (int)(YearNo + (1970 - 1900));
+ GmTime->tm_yday = (int)DayNo;
+
+ for (MonthNo = 12; MonthNo > 1; MonthNo--) {
+ if (DayNo >= CumulativeDays[IsLeap (Year)][MonthNo]) {
+ DayNo = (UINT16)(DayNo - (UINT16)(CumulativeDays[IsLeap (Year)][MonthNo]));
+ break;
+ }
+ }
+
+ GmTime->tm_mon = (int)MonthNo - 1;
+ GmTime->tm_mday = (int)DayNo + 1;
+
+ GmTime->tm_isdst = 0;
+ GmTime->tm_gmtoff = 0;
+ GmTime->tm_zone = NULL;
+
+ return GmTime;
+}
+
+/**_time64 function. **/
+time_t
+_time64 (
+ time_t *t
+ )
+{
+ return time (t);
+}
diff --git a/CryptoPkg/Library/BaseCryptLibMbedTls/TestBaseCryptLib.inf b/CryptoPkg/Library/BaseCryptLibMbedTls/TestBaseCryptLib.inf new file mode 100644 index 0000000..def990b --- /dev/null +++ b/CryptoPkg/Library/BaseCryptLibMbedTls/TestBaseCryptLib.inf @@ -0,0 +1,76 @@ +## @file
+# Cryptographic Library Instance for DXE_DRIVER.
+#
+# Caution: This module requires additional review when modified.
+# This library will have external input - signature.
+# This external input must be validated carefully to avoid security issues such as
+# buffer overflow or integer overflow.
+#
+# Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = BaseCryptLib
+ FILE_GUID = 9DD60CFE-9D05-41E2-8B9E-958E2A4C1913
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = BaseCryptLib|DXE_DRIVER DXE_CORE UEFI_APPLICATION UEFI_DRIVER
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64
+#
+
+[Sources]
+ InternalCryptLib.h
+ Cipher/CryptAeadAesGcmNull.c
+ Cipher/CryptAes.c
+ Hash/CryptSha256.c
+ Hash/CryptSha512.c
+ Hash/CryptSm3Null.c
+ Hash/CryptMd5.c
+ Hash/CryptSha1.c
+ Hmac/CryptHmac.c
+ Kdf/CryptHkdf.c
+ Pk/CryptRsaBasic.c
+ Pk/CryptRsaExtNull.c
+ Pk/CryptRsaPss.c
+ Pk/CryptRsaPssSignNull.c
+ Bn/CryptBnNull.c
+ Pem/CryptPemNull.c
+ Pk/CryptDhNull.c
+ Pk/CryptEcNull.c
+ Pk/CryptPkcs1OaepNull.c
+ Pk/CryptPkcs5Pbkdf2Null.c
+ Pk/CryptPkcs7SignNull.c
+ Pk/CryptPkcs7VerifyNull.c
+ Pk/CryptPkcs7VerifyEkuNull.c
+ Pk/CryptX509Null.c
+ Pk/CryptAuthenticodeNull.c
+ Pk/CryptTsNull.c
+ Rand/CryptRandNull.c
+ SysCall/CrtWrapper.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ CryptoPkg/CryptoPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ MemoryAllocationLib
+ UefiRuntimeServicesTableLib
+ DebugLib
+ MbedTlsLib
+ PrintLib
+ RngLib
+
+#
+# Remove these [BuildOptions] after this library is cleaned up
+#
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /GL-
diff --git a/CryptoPkg/Library/Include/stdint.h b/CryptoPkg/Library/Include/stdint.h new file mode 100644 index 0000000..17b8c76 --- /dev/null +++ b/CryptoPkg/Library/Include/stdint.h @@ -0,0 +1,19 @@ +/** @file
+ Include file to support building the third-party cryptographic library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <CrtLibSupport.h>
+
+typedef INT8 int8_t;
+typedef UINT8 uint8_t;
+typedef INT16 int16_t;
+typedef UINT16 uint16_t;
+typedef INT32 int32_t;
+typedef UINT32 uint32_t;
+typedef INT64 int64_t;
+typedef UINT64 uint64_t;
+typedef UINTN uintptr_t;
diff --git a/CryptoPkg/Library/Include/stubs-32.h b/CryptoPkg/Library/Include/stubs-32.h new file mode 100644 index 0000000..786d57e --- /dev/null +++ b/CryptoPkg/Library/Include/stubs-32.h @@ -0,0 +1,9 @@ +/** @file
+ Include file to support building the third-party cryptographic library.
+
+Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <CrtLibSupport.h>
diff --git a/CryptoPkg/Library/MbedTlsLib/EcSm2Null.c b/CryptoPkg/Library/MbedTlsLib/EcSm2Null.c index c7d5c39..1c9cd72 100644 --- a/CryptoPkg/Library/MbedTlsLib/EcSm2Null.c +++ b/CryptoPkg/Library/MbedTlsLib/EcSm2Null.c @@ -12,7 +12,7 @@ #include <mbedtls/ecdh.h>
#include <mbedtls/ecdsa.h>
#include <mbedtls/bignum.h>
-#include <library/bignum_core.h>
+#include <bignum_core.h>
/*
* Get the curve info for the internal identifier
|