diff --git a/.gitignore b/.gitignore index c74cb7bc03..6dc0fd4dc9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,8 @@ tags/ *.pyc *.bak BuildConfig.conf +/Conf +/.vscode # Ignore SelfDescribingEnvironment artifacts. *_extdep/ @@ -12,3 +14,4 @@ BuildConfig.conf # Ignore cloned dependencies /Common /MU_BASECORE +_TEMP_*/ diff --git a/DfciPkg/IdentityAndAuthManager/IdentityAndAuthManagerDxe.inf b/DfciPkg/IdentityAndAuthManager/IdentityAndAuthManagerDxe.inf index a91c522f11..9f38cbb312 100644 --- a/DfciPkg/IdentityAndAuthManager/IdentityAndAuthManagerDxe.inf +++ b/DfciPkg/IdentityAndAuthManager/IdentityAndAuthManagerDxe.inf @@ -76,7 +76,6 @@ UefiLib BaseCryptLib DfciPasswordLib - OpensslLib DfciDeviceIdSupportLib DfciRecoveryLib DfciUiSupportLib diff --git a/Readme.rst b/Readme.rst index 4673e09e56..60f9deb89c 100644 --- a/Readme.rst +++ b/Readme.rst @@ -21,6 +21,7 @@ Main Changes-dev ---------------- - Added Color Bars for DEVICE_STATE_PLATFORM_MODE_[2|3]. (indigo and brown, respectively). Removed display for DEVICE_STATE_UNDEFINED. +- Added SharedCryptoPkg that includes support for having BaseCryptLib over a protocol Bug Fixes-dev ------------- diff --git a/SharedCryptoPkg/BuildDrivers.py b/SharedCryptoPkg/BuildDrivers.py new file mode 100644 index 0000000000..27ccd39896 --- /dev/null +++ b/SharedCryptoPkg/BuildDrivers.py @@ -0,0 +1,88 @@ +## +# Script to Build Shared Crypto Driver +## +## +# Copyright Microsoft Corporation, 2018 +## +## +## Script to Build the SharedCryptoPkg binaries for NuGet publishing +## +## +## Copyright Microsoft Corporation, 2018 +## +import os, sys +import logging +from MuEnvironment.UefiBuild import UefiBuilder +# +#========================================================================== +# PLATFORM BUILD ENVIRONMENT CONFIGURATION +# +SCRIPT_PATH = os.path.dirname(os.path.abspath(__file__)) +WORKSPACE_PATH = os.path.dirname(os.path.dirname(SCRIPT_PATH)) +REQUIRED_REPOS = ('MU_BASECORE', 'Common/MU', 'Common/MU_TIANO') +PROJECT_SCOPE = ("corebuild", "") + +MODULE_PKGS = ('MU_BASECORE', 'Common/MU', 'Common/MU_TIANO') +MODULE_PKG_PATHS = ";".join(os.path.join(WORKSPACE_PATH, pkg_name) for pkg_name in MODULE_PKGS) + +# -------------------------------------------------------------------------------------------------------- +# Subclass the UEFI builder and add platform specific functionality. +# + + +class PlatformBuilder(UefiBuilder): + + def __init__(self, WorkSpace, PackagesPath, PInManager, PInHelper, args): + super(PlatformBuilder, self).__init__( + WorkSpace, PackagesPath, PInManager, PInHelper, args) + + def SetPlatformEnv(self): + + self.env.SetValue("ACTIVE_PLATFORM", "SharedCryptoPkg/SharedCryptoDriver.dsc", "Platform Hardcoded") + self.env.SetValue("TARGET_ARCH", "IA32 X64 AARCH64 ARM", "Platform Hardcoded") + self.env.SetValue("TARGET", "RELEASE", "Platform Hardcoded") + self.env.SetValue("CONF_TEMPLATE_DIR", "SharedCryptoPkg", "Conf template directory hardcoded - temporary and should go away") + + self.env.SetValue("LaunchBuildLogProgram", "Notepad", "default - will fail if already set", True) + self.env.SetValue("LaunchLogOnSuccess", "True", "default - will fail if already set", True) + self.env.SetValue("LaunchLogOnError", "True", "default - will fail if already set", True) + + return 0 + + def PlatformPostBuild(self): + # TODO: Upload to nuget + + return 0 + + + # ------------------------------------------------------------------ + # + # Method for the platform to check if a gated build is needed + # This is part of the build flow. + # return: + # True - Gated build is needed (default) + # False - Gated build is not needed for this platform + # ------------------------------------------------------------------ + def PlatformGatedBuildShouldHappen(self): + return True + + # + # Platform defined flash method + # + def PlatformFlashImage(self): + raise Exception("Flashing not supported") +# +#========================================================================== +# + +# Smallest 'main' possible. Please don't add unnecessary code. +if __name__ == '__main__': + # If CommonBuildEntry is not found, the mu_environment pip module has not been installed correctly + try: + from MuEnvironment import CommonBuildEntry + except ImportError: + print("Running Python version {0} from {1}".format(sys.version, sys.executable)) + raise RuntimeError("Please run \"python -m pip install --upgrade mu_build\".\nContact Microsoft Project Mu team if you run into any problems.") + + # Now that we have access to the entry, hand off to the common code. + CommonBuildEntry.build_entry(SCRIPT_PATH, WORKSPACE_PATH, REQUIRED_REPOS, PROJECT_SCOPE, MODULE_PKGS, MODULE_PKG_PATHS) diff --git a/SharedCryptoPkg/Driver/Common/CommonSharedCryptoFull.c b/SharedCryptoPkg/Driver/Common/CommonSharedCryptoFull.c new file mode 100644 index 0000000000..3b4cd94785 --- /dev/null +++ b/SharedCryptoPkg/Driver/Common/CommonSharedCryptoFull.c @@ -0,0 +1,167 @@ + +/** @file + This module is consumed by both DXE and SMM as well as PEI + + This links the functions in the protocol to the functions in BaseCryptLib. + This is the Full flavor, which means this supports all the functions that are + in BaseCryptLib. + + See Readme.md in the root of SharedCryptoPkg for more info. + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include "SharedCryptoVersion.h" + + +CONST SHARED_CRYPTO_FUNCTIONS mSharedCryptoFunctions = { + GetCryptoVersion, + /// HMAC + HmacMd5GetContextSize, //SHAREDCRYPTO_HMAC_MD5_GetContextSize HMAC_MD5_GetContextSize; + HmacMd5New, //SHAREDCRYPTO_HMAC_MD5_New HMAC_MD5_New; + HmacMd5Free, //SHAREDCRYPTO_HMAC_MD5_Free HMAC_MD5_Free; + HmacMd5Init, //SHAREDCRYPTO_HMAC_MD5_Init HMAC_MD5_Init; + HmacMd5Duplicate, //SHAREDCRYPTO_HMAC_MD5_Duplicate HMAC_MD5_Duplicate; + HmacMd5Update, //SHAREDCRYPTO_HMAC_MD5_Update HMAC_MD5_Update; + HmacMd5Final, //SHAREDCRYPTO_HMAC_MD5_Final HMAC_MD5_Final; + HmacSha1GetContextSize, //SHAREDCRYPTO_HMAC_SHA1_GetContextSize HMAC_SHA1_GetContextSize; + HmacSha1New, //SHAREDCRYPTO_HMAC_SHA1_New HMAC_SHA1_New; + HmacSha1Free, //SHAREDCRYPTO_HMAC_SHA1_Free HMAC_SHA1_Free; + HmacSha1Init, //SHAREDCRYPTO_HMAC_SHA1_Init HMAC_SHA1_Init; + HmacSha1Duplicate, //SHAREDCRYPTO_HMAC_SHA1_Duplicate HMAC_SHA1_Duplicate; + HmacSha1Update, //SHAREDCRYPTO_HMAC_SHA1_Update HMAC_SHA1_Update; + HmacSha1Final, //SHAREDCRYPTO_HMAC_SHA1_Final HMAC_SHA1_Final; + HmacSha256GetContextSize, //SHAREDCRYPTO_HMAC_SHA256_GetContextSize HMAC_SHA256_GetContextSize; + HmacSha256New, //SHAREDCRYPTO_HMAC_SHA256_New HMAC_SHA256_New; + HmacSha256Free, //SHAREDCRYPTO_HMAC_SHA256_Free HMAC_SHA256_Free; + HmacSha256Init, //SHAREDCRYPTO_HMAC_SHA256_Init HMAC_SHA256_Init; + HmacSha256Duplicate, //SHAREDCRYPTO_HMAC_SHA256_Duplicate HMAC_SHA256_Duplicate; + HmacSha256Update, //SHAREDCRYPTO_HMAC_SHA256_Update HMAC_SHA256_Update; + HmacSha256Final, //SHAREDCRYPTO_HMAC_SHA256_Final HMAC_SHA256_Final; + /// Md4 + Md4GetContextSize, //SHAREDCRYPTO_MD4_GetContextSize MD4_GetContextSize; + Md4Init, //SHAREDCRYPTO_MD4_Init MD4_Init; + Md4Duplicate, //SHAREDCRYPTO_MD4_Duplicate MD4_Duplicate; + Md4Update, //SHAREDCRYPTO_MD4_Update MD4_Update; + Md4Final, //SHAREDCRYPTO_MD4_Final MD4_Final; + Md4HashAll, //SHAREDCRYPTO_MD4_HashAll MD4_HashAll; + /// Md5 + Md5GetContextSize, //SHAREDCRYPTO_MD5_GetContextSize MD5_GetContextSize; + Md5Init, //SHAREDCRYPTO_MD5_Init MD5_Init; + Md5Duplicate, //SHAREDCRYPTO_MD5_Duplicate MD5_Duplicate; + Md5Update, //SHAREDCRYPTO_MD5_Update MD5_Update; + Md5Final, //SHAREDCRYPTO_MD5_Final MD5_Final; + Md5HashAll, //SHAREDCRYPTO_MD5_HashAll MD5_HashAll; + /// Pkcs + Pkcs1v2Encrypt, //SHAREDCRYPTO_PKCS1_ENCRYPT_V2 PKCS1_ENCRYPT_V2; + Pkcs5HashPassword, //SHAREDCRYPTO_PKCS5_PW_HASH PKCS5_PW_HASH; + Pkcs7Verify, //SHAREDCRYPTO_PKCS7_VERIFY PKCS7_VERIFY; + VerifyEKUsInPkcs7Signature, //SHAREDCRYPTO_PKCS7_VERIFY_EKU PKCS7_VERIFY_EKU; + Pkcs7GetSigners, //SHAREDCRYPTO_PKCS7_GetSigners PKCS7_GetSigners; + Pkcs7FreeSigners, //SHAREDCRYPTO_PKCS7_FreeSigners PKCS7_FreeSigners; + Pkcs7Sign, //SHAREDCRYPTO_PKCS7_Sign PKCS7_Sign; + Pkcs7GetAttachedContent, //SHAREDCRYPTO_PKCS7_GetAttachedContent PKCS7_GetAttachedContent; + Pkcs7GetCertificatesList, //SHAREDCRYPTO_PKCS7_GetCertificatesList PKCS7_GetCertificatesList; + AuthenticodeVerify, //SHAREDCRYPTO_AuthenticodeVerify Authenticode_Verify; + ImageTimestampVerify, //SHAREDCRYPTO_ImageTimestampVerify Image_TimestampVerify; + /// DH + DhNew, //SHAREDCRYPTO_DH_New DH_New; + DhFree, //SHAREDCRYPTO_DH_Free DH_Free; + DhGenerateParameter, //SHAREDCRYPTO_DH_GenerateParameter DH_GenerateParameter; + DhSetParameter, //SHAREDCRYPTO_DH_SetParameter DH_SetParameter; + DhGenerateKey, //SHAREDCRYPTO_DH_GenerateKey DH_GenerateKey; + DhComputeKey, //SHAREDCRYPTO_DH_ComputeKey DH_ComputeKey; + /// Random + RandomSeed, //SHAREDCRYPTO_RANDOM_Seed RANDOM_Seed; + RandomBytes, //SHAREDCRYPTO_RANDOM_Bytes RANDOM_Bytes; + /// RSA + RsaPkcs1Verify, //SHAREDCRYPTO_RSA_VERIFY_PKCS1 RSA_VERIFY_PKCS1; + RsaFree, //SHAREDCRYPTO_RSA_FREE RSA_FREE; + RsaGetPublicKeyFromX509, //SHAREDCRYPTO_RSA_GET_PUBLIC_KEY_FROM_X509 RSA_GET_PUBLIC_KEY_FROM_X509; + RsaNew, //SHAREDCRYPTO_RSA_New RSA_New; + RsaFree, //SHAREDCRYPTO_RSA_Free RSA_Free; + RsaSetKey, //SHAREDCRYPTO_RSA_SetKey RSA_SetKey; + RsaGetKey, //SHAREDCRYPTO_RSA_GetKey RSA_GetKey; + RsaGenerateKey, //SHAREDCRYPTO_RSA_GenerateKey RSA_GenerateKey; + RsaCheckKey, //SHAREDCRYPTO_RSA_CheckKey RSA_CheckKey; + RsaPkcs1Sign, //SHAREDCRYPTO_RSA_Pkcs1Sign RSA_Pkcs1Sign; + RsaPkcs1Verify, //SHAREDCRYPTO_RSA_Pkcs1Verify RSA_Pkcs1Verify; + RsaGetPrivateKeyFromPem, //SHAREDCRYPTO_RSA_GetPrivateKeyFromPem RSA_GetPrivateKeyFromPem; + RsaGetPublicKeyFromX509, //SHAREDCRYPTO_RSA_GetPublicKeyFromX509 RSA_GetPublicKeyFromX509; + /// Sha protocol + Sha1GetContextSize, //SHAREDCRYPTO_SHA1_GET_CONTEXT_SIZE SHA1_GET_CONTEXT_SIZE; + Sha1Init, //SHAREDCRYPTO_SHA1_INIT SHA1_INIT; + Sha1Duplicate, //SHAREDCRYPTO_SHA1_DUPLICATE SHA1_DUPLICATE; + Sha1Update, //SHAREDCRYPTO_SHA1_UPDATE SHA1_UPDATE; + Sha1Final, //SHAREDCRYPTO_SHA1_FINAL SHA1_FINAL; + Sha1HashAll, //SHAREDCRYPTO_SHA1_HASH_ALL SHA1_HASH_ALL; + Sha256GetContextSize, //SHAREDCRYPTO_SHA256_GET_CONTEXT_SIZE SHA256_GET_CONTEXT_SIZE; + Sha256Init, //SHAREDCRYPTO_SHA256_INIT SHA256_INIT; + Sha256Duplicate, //SHAREDCRYPTO_SHA256_DUPLICATE SHA256_DUPLICATE; + Sha256Update, //SHAREDCRYPTO_SHA256_UPDATE SHA256_UPDATE; + Sha256Final, //SHAREDCRYPTO_SHA256_FINAL SHA256_FINAL; + Sha256HashAll, //SHAREDCRYPTO_SHA256_HASH_ALL SHA256_HASH_ALL; + Sha384GetContextSize, //SHAREDCRYPTO_SHA384_GetContextSize SHA384_GetContextSize; + Sha384Init, //SHAREDCRYPTO_SHA384_Init SHA384_Init; + Sha384Duplicate, //SHAREDCRYPTO_SHA384_Duplicate SHA384_Duplicate; + Sha384Update, //SHAREDCRYPTO_SHA384_Update SHA384_Update; + Sha384Final, //SHAREDCRYPTO_SHA384_Final SHA384_Final; + Sha384HashAll, //SHAREDCRYPTO_SHA384_HashAll SHA384_HashAll; + Sha512GetContextSize, //SHAREDCRYPTO_SHA512_GetContextSize SHA512_GetContextSize; + Sha512Init, //SHAREDCRYPTO_SHA512_Init SHA512_Init; + Sha512Duplicate, //SHAREDCRYPTO_SHA512_Duplicate SHA512_Duplicate; + Sha512Update, //SHAREDCRYPTO_SHA512_Update SHA512_Update; + Sha512Final, //SHAREDCRYPTO_SHA512_Final SHA512_Final; + Sha512HashAll, //SHAREDCRYPTO_SHA512_HashAll SHA512_HashAll; + /// X509 + X509GetSubjectName, //SHAREDCRYPTO_X509_GET_SUBJECT_NAME X509_GET_SUBJECT_NAME; + X509GetCommonName, //SHAREDCRYPTO_X509_GET_COMMON_NAME X509_GET_COMMON_NAME; + X509GetOrganizationName, //SHAREDCRYPTO_X509_GET_ORGANIZATION_NAME X509_GET_ORGANIZATION_NAME; + X509VerifyCert, //SHAREDCRYPTO_X509_VerifyCert X509_VerifyCert; + X509ConstructCertificate, //SHAREDCRYPTO_X509_ConstructCertificate X509_ConstructCertificate; + X509ConstructCertificateStack, //SHAREDCRYPTO_X509_ConstructCertificateStack X509_ConstructCertificateStack; + X509Free, //SHAREDCRYPTO_X509_Free X509_Free; + X509StackFree, //SHAREDCRYPTO_X509_StackFree X509_StackFree; + X509GetTBSCert, //SHAREDCRYPTO_X509_GetTBSCert X509_GetTBSCert; + /// TDES + TdesGetContextSize, //SHAREDCRYPTO_TDES_GetContextSize TDES_GetContextSize; + TdesInit, //SHAREDCRYPTO_TDES_Init TDES_Init; + TdesEcbEncrypt, //SHAREDCRYPTO_TDES_EcbEncrypt TDES_EcbEncrypt; + TdesEcbDecrypt, //SHAREDCRYPTO_TDES_EcbDecrypt TDES_EcbDecrypt; + TdesCbcEncrypt, //SHAREDCRYPTO_TDES_CbcEncrypt TDES_CbcEncrypt; + TdesCbcDecrypt, //SHAREDCRYPTO_TDES_CbcDecrypt TDES_CbcDecrypt; + /// AES + AesGetContextSize, //SHAREDCRYPTO_AES_GetContextSize AES_GetContextSize; + AesInit, //SHAREDCRYPTO_AES_Init AES_Init; + AesEcbEncrypt, //SHAREDCRYPTO_AES_EcbEncrypt AES_EcbEncrypt; + AesEcbDecrypt, //SHAREDCRYPTO_AES_EcbDecrypt AES_EcbDecrypt; + AesCbcEncrypt, //SHAREDCRYPTO_AES_CbcEncrypt AES_CbcEncrypt; + AesCbcDecrypt, //SHAREDCRYPTO_AES_CbcDecrypt AES_CbcDecrypt; + /// Arc4 + Arc4GetContextSize, //SHAREDCRYPTO_ARC4_GetContextSize ARC4_GetContextSize; + Arc4Init, //SHAREDCRYPTO_ARC4_Init ARC4_Init; + Arc4Encrypt, //SHAREDCRYPTO_ARC4_Encrypt ARC4_Encrypt; + Arc4Decrypt, //SHAREDCRYPTO_ARC4_Decrypt ARC4_Decrypt; + Arc4Reset //SHAREDCRYPTO_ARC4_Reset ARC4_Reset; +}; \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Common/CommonSharedCryptoMu.c b/SharedCryptoPkg/Driver/Common/CommonSharedCryptoMu.c new file mode 100644 index 0000000000..2739ba2e50 --- /dev/null +++ b/SharedCryptoPkg/Driver/Common/CommonSharedCryptoMu.c @@ -0,0 +1,167 @@ + +/** @file + This module is consumed by both DXE and SMM as well as PEI + + This links the functions in the protocol to the functions in BaseCryptLib. + This is the Mu flavor, which means we only support the functions that are used + by Microsoft Surface platforms and what we believe is a sensible set of Crypto + functions to support. + + See Readme.md in the root of SharedCryptoPkg for more info. + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include "SharedCryptoVersion.h" + +CONST SHARED_CRYPTO_FUNCTIONS mSharedCryptoFunctions = { + GetCryptoVersion, + /// HMAC + NULL, //SHAREDCRYPTO_HMAC_MD5_GetContextSize HMAC_MD5_GetContextSize; + NULL, //SHAREDCRYPTO_HMAC_MD5_New HMAC_MD5_New; + NULL, //SHAREDCRYPTO_HMAC_MD5_Free HMAC_MD5_Free; + NULL, //SHAREDCRYPTO_HMAC_MD5_Init HMAC_MD5_Init; + NULL, //SHAREDCRYPTO_HMAC_MD5_Duplicate HMAC_MD5_Duplicate; + NULL, //SHAREDCRYPTO_HMAC_MD5_Update HMAC_MD5_Update; + NULL, //SHAREDCRYPTO_HMAC_MD5_Final HMAC_MD5_Final; + HmacSha1GetContextSize, //SHAREDCRYPTO_HMAC_SHA1_GetContextSize HMAC_SHA1_GetContextSize; + HmacSha1New, //SHAREDCRYPTO_HMAC_SHA1_New HMAC_SHA1_New; + HmacSha1Free, //SHAREDCRYPTO_HMAC_SHA1_Free HMAC_SHA1_Free; + HmacSha1Init, //SHAREDCRYPTO_HMAC_SHA1_Init HMAC_SHA1_Init; + HmacSha1Duplicate, //SHAREDCRYPTO_HMAC_SHA1_Duplicate HMAC_SHA1_Duplicate; + HmacSha1Update, //SHAREDCRYPTO_HMAC_SHA1_Update HMAC_SHA1_Update; + HmacSha1Final, //SHAREDCRYPTO_HMAC_SHA1_Final HMAC_SHA1_Final; + HmacSha256GetContextSize, //SHAREDCRYPTO_HMAC_SHA256_GetContextSize HMAC_SHA256_GetContextSize; + HmacSha256New, //SHAREDCRYPTO_HMAC_SHA256_New HMAC_SHA256_New; + HmacSha256Free, //SHAREDCRYPTO_HMAC_SHA256_Free HMAC_SHA256_Free; + HmacSha256Init, //SHAREDCRYPTO_HMAC_SHA256_Init HMAC_SHA256_Init; + HmacSha256Duplicate, //SHAREDCRYPTO_HMAC_SHA256_Duplicate HMAC_SHA256_Duplicate; + HmacSha256Update, //SHAREDCRYPTO_HMAC_SHA256_Update HMAC_SHA256_Update; + HmacSha256Final, //SHAREDCRYPTO_HMAC_SHA256_Final HMAC_SHA256_Final; + /// Md4 + NULL, //SHAREDCRYPTO_MD4_GetContextSize MD4_GetContextSize; + NULL, //SHAREDCRYPTO_MD4_Init MD4_Init; + NULL, //SHAREDCRYPTO_MD4_Duplicate MD4_Duplicate; + NULL, //SHAREDCRYPTO_MD4_Update MD4_Update; + NULL, //SHAREDCRYPTO_MD4_Final MD4_Final; + NULL, //SHAREDCRYPTO_MD4_HashAll MD4_HashAll; + /// Md5 + NULL, //SHAREDCRYPTO_MD5_GetContextSize MD5_GetContextSize; + NULL, //SHAREDCRYPTO_MD5_Init MD5_Init; + NULL, //SHAREDCRYPTO_MD5_Duplicate MD5_Duplicate; + NULL, //SHAREDCRYPTO_MD5_Update MD5_Update; + NULL, //SHAREDCRYPTO_MD5_Final MD5_Final; + NULL, //SHAREDCRYPTO_MD5_HashAll MD5_HashAll; + /// Pkcs + Pkcs1v2Encrypt, //SHAREDCRYPTO_PKCS1_ENCRYPT_V2 PKCS1_ENCRYPT_V2; + Pkcs5HashPassword, //SHAREDCRYPTO_PKCS5_PW_HASH PKCS5_PW_HASH; + Pkcs7Verify, //SHAREDCRYPTO_PKCS7_VERIFY PKCS7_VERIFY; + VerifyEKUsInPkcs7Signature, //SHAREDCRYPTO_PKCS7_VERIFY_EKU PKCS7_VERIFY_EKU; + Pkcs7GetSigners, //SHAREDCRYPTO_PKCS7_GetSigners PKCS7_GetSigners; + Pkcs7FreeSigners, //SHAREDCRYPTO_PKCS7_FreeSigners PKCS7_FreeSigners; + NULL, //SHAREDCRYPTO_PKCS7_Sign PKCS7_Sign; + NULL, //SHAREDCRYPTO_PKCS7_GetAttachedContent PKCS7_GetAttachedContent; + NULL, //SHAREDCRYPTO_PKCS7_GetCertificatesList PKCS7_GetCertificatesList; + NULL, //SHAREDCRYPTO_AuthenticodeVerify AuthenticodeVerify; + NULL, //SHAREDCRYPTO_ImageTimestampVerify ImageTimestampVerify; + /// DH + NULL, //SHAREDCRYPTO_DH_New DH_New; + NULL, //SHAREDCRYPTO_DH_Free DH_Free; + NULL, //SHAREDCRYPTO_DH_GenerateParameter DH_GenerateParameter; + NULL, //SHAREDCRYPTO_DH_SetParameter DH_SetParameter; + NULL, //SHAREDCRYPTO_DH_GenerateKey DH_GenerateKey; + NULL, //SHAREDCRYPTO_DH_ComputeKey DH_ComputeKey; + /// Random + RandomSeed, //SHAREDCRYPTO_RANDOM_Seed RANDOM_Seed; + RandomBytes, //SHAREDCRYPTO_RANDOM_Bytes RANDOM_Bytes; + /// RSA + RsaPkcs1Verify, //SHAREDCRYPTO_RSA_VERIFY_PKCS1 RSA_VERIFY_PKCS1; + RsaFree, //SHAREDCRYPTO_RSA_FREE RSA_FREE; + RsaGetPublicKeyFromX509, //SHAREDCRYPTO_RSA_GET_PUBLIC_KEY_FROM_X509 RSA_GET_PUBLIC_KEY_FROM_X509; + NULL, //SHAREDCRYPTO_RSA_New RSA_New; + NULL, //SHAREDCRYPTO_RSA_Free RSA_Free; + NULL, //SHAREDCRYPTO_RSA_SetKey RSA_SetKey; + NULL, //SHAREDCRYPTO_RSA_GetKey RSA_GetKey; + NULL, //SHAREDCRYPTO_RSA_GenerateKey RSA_GenerateKey; + NULL, //SHAREDCRYPTO_RSA_CheckKey RSA_CheckKey; + NULL, //SHAREDCRYPTO_RSA_Pkcs1Sign RSA_Pkcs1Sign; + NULL, //SHAREDCRYPTO_RSA_Pkcs1Verify RSA_Pkcs1Verify; + NULL, //SHAREDCRYPTO_RSA_GetPrivateKeyFromPem RSA_GetPrivateKeyFromPem; + NULL, //SHAREDCRYPTO_RSA_GetPublicKeyFromX509 RSA_GetPublicKeyFromX509; + /// Sha protocol + Sha1GetContextSize, //SHAREDCRYPTO_SHA1_GET_CONTEXT_SIZE SHA1_GET_CONTEXT_SIZE; + Sha1Init, //SHAREDCRYPTO_SHA1_INIT SHA1_INIT; + Sha1Duplicate, //SHAREDCRYPTO_SHA1_DUPLICATE SHA1_DUPLICATE; + Sha1Update, //SHAREDCRYPTO_SHA1_UPDATE SHA1_UPDATE; + Sha1Final, //SHAREDCRYPTO_SHA1_FINAL SHA1_FINAL; + NULL, //SHAREDCRYPTO_SHA1_HASH_ALL SHA1_HASH_ALL; + Sha256GetContextSize, //SHAREDCRYPTO_SHA256_GET_CONTEXT_SIZE SHA256_GET_CONTEXT_SIZE; + Sha256Init, //SHAREDCRYPTO_SHA256_INIT SHA256_INIT; + Sha256Duplicate, //SHAREDCRYPTO_SHA256_DUPLICATE SHA256_DUPLICATE; + Sha256Update, //SHAREDCRYPTO_SHA256_UPDATE SHA256_UPDATE; + Sha256Final, //SHAREDCRYPTO_SHA256_FINAL SHA256_FINAL; + NULL, //SHAREDCRYPTO_SHA256_HASH_ALL SHA256_HASH_ALL; + NULL, //SHAREDCRYPTO_SHA384_GetContextSize SHA384_GetContextSize; + NULL, //SHAREDCRYPTO_SHA384_Init SHA384_Init; + NULL, //SHAREDCRYPTO_SHA384_Duplicate SHA384_Duplicate; + NULL, //SHAREDCRYPTO_SHA384_Update SHA384_Update; + NULL, //SHAREDCRYPTO_SHA384_Final SHA384_Final; + NULL, //SHAREDCRYPTO_SHA384_HashAll SHA384_HashAll; + NULL, //SHAREDCRYPTO_SHA512_GetContextSize SHA512_GetContextSize; + NULL, //SHAREDCRYPTO_SHA512_Init SHA512_Init; + NULL, //SHAREDCRYPTO_SHA512_Duplicate SHA512_Duplicate; + NULL, //SHAREDCRYPTO_SHA512_Update SHA512_Update; + NULL, //SHAREDCRYPTO_SHA512_Final SHA512_Final; + NULL, //SHAREDCRYPTO_SHA512_HashAll SHA512_HashAll; + /// X509 + X509GetSubjectName, //SHAREDCRYPTO_X509_GET_SUBJECT_NAME X509_GET_SUBJECT_NAME; + X509GetCommonName, //SHAREDCRYPTO_X509_GET_COMMON_NAME X509_GET_COMMON_NAME; + X509GetOrganizationName, //SHAREDCRYPTO_X509_GET_ORGANIZATION_NAME X509_GET_ORGANIZATION_NAME; + NULL, //SHAREDCRYPTO_X509_VerifyCert X509_VerifyCert; + NULL, //SHAREDCRYPTO_X509_ConstructCertificate X509_ConstructCertificate; + NULL, //SHAREDCRYPTO_X509_ConstructCertificateStack X509_ConstructCertificateStack; + NULL, //SHAREDCRYPTO_X509_Free X509_Free; + NULL, //SHAREDCRYPTO_X509_StackFree X509_StackFree; + X509GetTBSCert, //SHAREDCRYPTO_X509_GetTBSCert X509_GetTBSCert; + /// TDES + NULL, //SHAREDCRYPTO_TDES_GetContextSize TDES_GetContextSize; + NULL, //SHAREDCRYPTO_TDES_Init TDES_Init; + NULL, //SHAREDCRYPTO_TDES_EcbEncrypt TDES_EcbEncrypt; + NULL, //SHAREDCRYPTO_TDES_EcbDecrypt TDES_EcbDecrypt; + NULL, //SHAREDCRYPTO_TDES_CbcEncrypt TDES_CbcEncrypt; + NULL, //SHAREDCRYPTO_TDES_CbcDecrypt TDES_CbcDecrypt; + /// AES + NULL, //SHAREDCRYPTO_AES_GetContextSize AES_GetContextSize; + NULL, //SHAREDCRYPTO_AES_Init AES_Init; + NULL, //SHAREDCRYPTO_AES_EcbEncrypt AES_EcbEncrypt; + NULL, //SHAREDCRYPTO_AES_EcbDecrypt AES_EcbDecrypt; + NULL, //SHAREDCRYPTO_AES_CbcEncrypt AES_CbcEncrypt; + NULL, //SHAREDCRYPTO_AES_CbcDecrypt AES_CbcDecrypt; + /// Arc4 + NULL, //SHAREDCRYPTO_ARC4_GetContextSize ARC4_GetContextSize; + NULL, //SHAREDCRYPTO_ARC4_Init ARC4_Init; + NULL, //SHAREDCRYPTO_ARC4_Encrypt ARC4_Encrypt; + NULL, //SHAREDCRYPTO_ARC4_Decrypt ARC4_Decrypt; + NULL //SHAREDCRYPTO_ARC4_Reset ARC4_Reset; +}; \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Common/CommonSharedCryptoShaOnly.c b/SharedCryptoPkg/Driver/Common/CommonSharedCryptoShaOnly.c new file mode 100644 index 0000000000..77aab4b148 --- /dev/null +++ b/SharedCryptoPkg/Driver/Common/CommonSharedCryptoShaOnly.c @@ -0,0 +1,174 @@ + +/** @file + This module is designed to be just SHA and compile to a small EFI. + + Currently it is consumed by the reduced version of PEI (to reduce the size of + the PEI FV since it isn't compressed on many platforms.) Other phases (DXE,SMM) + can utilize this flavor if SHA is all they need. + + This links the functions in the protocol to the functions in BaseCryptLib. + This is the ShaOnly flavor, which means we only support SHA1 and SHA256. This + is used by PEI on Microsoft Surface platforms as SHA is the only crypto + functions that we use in PEI. Using the ShaOnly flavor reduces in a smaller + binary size. + + See Readme.md in the root of SharedCryptoPkg for more info. + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include "SharedCryptoVersion.h" + + +CONST SHARED_CRYPTO_FUNCTIONS mSharedCryptoFunctions = { + GetCryptoVersion, + /// HMAC + NULL, //SHAREDCRYPTO_HMAC_MD5_GetContextSize HMAC_MD5_GetContextSize; + NULL, //SHAREDCRYPTO_HMAC_MD5_New HMAC_MD5_New; + NULL, //SHAREDCRYPTO_HMAC_MD5_Free HMAC_MD5_Free; + NULL, //SHAREDCRYPTO_HMAC_MD5_Init HMAC_MD5_Init; + NULL, //SHAREDCRYPTO_HMAC_MD5_Duplicate HMAC_MD5_Duplicate; + NULL, //SHAREDCRYPTO_HMAC_MD5_Update HMAC_MD5_Update; + NULL, //SHAREDCRYPTO_HMAC_MD5_Final HMAC_MD5_Final; + NULL, //SHAREDCRYPTO_HMAC_SHA1_GetContextSize HMAC_SHA1_GetContextSize; + NULL, //SHAREDCRYPTO_HMAC_SHA1_New HMAC_SHA1_New; + NULL, //SHAREDCRYPTO_HMAC_SHA1_Free HMAC_SHA1_Free; + NULL, //SHAREDCRYPTO_HMAC_SHA1_Init HMAC_SHA1_Init; + NULL, //SHAREDCRYPTO_HMAC_SHA1_Duplicate HMAC_SHA1_Duplicate; + NULL, //SHAREDCRYPTO_HMAC_SHA1_Update HMAC_SHA1_Update; + NULL, //SHAREDCRYPTO_HMAC_SHA1_Final HMAC_SHA1_Final; + NULL, //SHAREDCRYPTO_HMAC_SHA256_GetContextSize HMAC_SHA256_GetContextSize; + NULL, //SHAREDCRYPTO_HMAC_SHA256_New HMAC_SHA256_New; + NULL, //SHAREDCRYPTO_HMAC_SHA256_Free HMAC_SHA256_Free; + NULL, //SHAREDCRYPTO_HMAC_SHA256_Init HMAC_SHA256_Init; + NULL, //SHAREDCRYPTO_HMAC_SHA256_Duplicate HMAC_SHA256_Duplicate; + NULL, //SHAREDCRYPTO_HMAC_SHA256_Update HMAC_SHA256_Update; + NULL, //SHAREDCRYPTO_HMAC_SHA256_Final HMAC_SHA256_Final; + /// Md4 + NULL, //SHAREDCRYPTO_MD4_GetContextSize MD4_GetContextSize; + NULL, //SHAREDCRYPTO_MD4_Init MD4_Init; + NULL, //SHAREDCRYPTO_MD4_Duplicate MD4_Duplicate; + NULL, //SHAREDCRYPTO_MD4_Update MD4_Update; + NULL, //SHAREDCRYPTO_MD4_Final MD4_Final; + NULL, //SHAREDCRYPTO_MD4_HashAll MD4_HashAll; + /// Md5 + NULL, //SHAREDCRYPTO_MD5_GetContextSize MD5_GetContextSize; + NULL, //SHAREDCRYPTO_MD5_Init MD5_Init; + NULL, //SHAREDCRYPTO_MD5_Duplicate MD5_Duplicate; + NULL, //SHAREDCRYPTO_MD5_Update MD5_Update; + NULL, //SHAREDCRYPTO_MD5_Final MD5_Final; + NULL, //SHAREDCRYPTO_MD5_HashAll MD5_HashAll; + /// Pkcs + NULL, //SHAREDCRYPTO_PKCS1_ENCRYPT_V2 PKCS1_ENCRYPT_V2; + NULL, //SHAREDCRYPTO_PKCS5_PW_HASH PKCS5_PW_HASH; + NULL, //SHAREDCRYPTO_PKCS7_VERIFY PKCS7_VERIFY; + NULL, //SHAREDCRYPTO_PKCS7_VERIFY_EKU PKCS7_VERIFY_EKU; + NULL, //SHAREDCRYPTO_PKCS7_GetSigners PKCS7_GetSigners; + NULL, //SHAREDCRYPTO_PKCS7_FreeSigners PKCS7_FreeSigners; + NULL, //SHAREDCRYPTO_PKCS7_Sign PKCS7_Sign; + NULL, //SHAREDCRYPTO_PKCS7_GetAttachedContent PKCS7_GetAttachedContent; + NULL, //SHAREDCRYPTO_PKCS7_GetCertificatesList PKCS7_GetCertificatesList; + NULL, //SHAREDCRYPTO_AuthenticodeVerify AuthenticodeVerify; + NULL, //SHAREDCRYPTO_ImageTimestampVerify ImageTimestampVerify; + /// DH + NULL, //SHAREDCRYPTO_DH_New DH_New; + NULL, //SHAREDCRYPTO_DH_Free DH_Free; + NULL, //SHAREDCRYPTO_DH_GenerateParameter DH_GenerateParameter; + NULL, //SHAREDCRYPTO_DH_SetParameter DH_SetParameter; + NULL, //SHAREDCRYPTO_DH_GenerateKey DH_GenerateKey; + NULL, //SHAREDCRYPTO_DH_ComputeKey DH_ComputeKey; + /// Random + NULL, //SHAREDCRYPTO_RANDOM_Seed RANDOM_Seed; + NULL, //SHAREDCRYPTO_RANDOM_Bytes RANDOM_Bytes; + /// RSA + NULL, //SHAREDCRYPTO_RSA_VERIFY_PKCS1 RSA_VERIFY_PKCS1; + NULL, //SHAREDCRYPTO_RSA_FREE RSA_FREE; + NULL, //SHAREDCRYPTO_RSA_GET_PUBLIC_KEY_FROM_X509 RSA_GET_PUBLIC_KEY_FROM_X509; + NULL, //SHAREDCRYPTO_RSA_New RSA_New; + NULL, //SHAREDCRYPTO_RSA_Free RSA_Free; + NULL, //SHAREDCRYPTO_RSA_SetKey RSA_SetKey; + NULL, //SHAREDCRYPTO_RSA_GetKey RSA_GetKey; + NULL, //SHAREDCRYPTO_RSA_GenerateKey RSA_GenerateKey; + NULL, //SHAREDCRYPTO_RSA_CheckKey RSA_CheckKey; + NULL, //SHAREDCRYPTO_RSA_Pkcs1Sign RSA_Pkcs1Sign; + NULL, //SHAREDCRYPTO_RSA_Pkcs1Verify RSA_Pkcs1Verify; + NULL, //SHAREDCRYPTO_RSA_GetPrivateKeyFromPem RSA_GetPrivateKeyFromPem; + NULL, //SHAREDCRYPTO_RSA_GetPublicKeyFromX509 RSA_GetPublicKeyFromX509; + /// Sha protocol + Sha1GetContextSize, //SHAREDCRYPTO_SHA1_GET_CONTEXT_SIZE SHA1_GET_CONTEXT_SIZE; + Sha1Init, //SHAREDCRYPTO_SHA1_INIT SHA1_INIT; + Sha1Duplicate, //SHAREDCRYPTO_SHA1_DUPLICATE SHA1_DUPLICATE; + Sha1Update, //SHAREDCRYPTO_SHA1_UPDATE SHA1_UPDATE; + Sha1Final, //SHAREDCRYPTO_SHA1_FINAL SHA1_FINAL; + NULL, //SHAREDCRYPTO_SHA1_HASH_ALL SHA1_HASH_ALL; + Sha256GetContextSize, //SHAREDCRYPTO_SHA256_GET_CONTEXT_SIZE SHA256_GET_CONTEXT_SIZE; + Sha256Init, //SHAREDCRYPTO_SHA256_INIT SHA256_INIT; + Sha256Duplicate, //SHAREDCRYPTO_SHA256_DUPLICATE SHA256_DUPLICATE; + Sha256Update, //SHAREDCRYPTO_SHA256_UPDATE SHA256_UPDATE; + Sha256Final, //SHAREDCRYPTO_SHA256_FINAL SHA256_FINAL; + NULL, //SHAREDCRYPTO_SHA256_HASH_ALL SHA256_HASH_ALL; + NULL, //SHAREDCRYPTO_SHA384_GetContextSize SHA384_GetContextSize; + NULL, //SHAREDCRYPTO_SHA384_Init SHA384_Init; + NULL, //SHAREDCRYPTO_SHA384_Duplicate SHA384_Duplicate; + NULL, //SHAREDCRYPTO_SHA384_Update SHA384_Update; + NULL, //SHAREDCRYPTO_SHA384_Final SHA384_Final; + NULL, //SHAREDCRYPTO_SHA384_HashAll SHA384_HashAll; + NULL, //SHAREDCRYPTO_SHA512_GetContextSize SHA512_GetContextSize; + NULL, //SHAREDCRYPTO_SHA512_Init SHA512_Init; + NULL, //SHAREDCRYPTO_SHA512_Duplicate SHA512_Duplicate; + NULL, //SHAREDCRYPTO_SHA512_Update SHA512_Update; + NULL, //SHAREDCRYPTO_SHA512_Final SHA512_Final; + NULL, //SHAREDCRYPTO_SHA512_HashAll SHA512_HashAll; + /// X509 + NULL, //SHAREDCRYPTO_X509_GET_SUBJECT_NAME X509_GET_SUBJECT_NAME; + NULL, //SHAREDCRYPTO_X509_GET_COMMON_NAME X509_GET_COMMON_NAME; + NULL, //SHAREDCRYPTO_X509_GET_ORGANIZATION_NAME X509_GET_ORGANIZATION_NAME; + NULL, //SHAREDCRYPTO_X509_VerifyCert X509_VerifyCert; + NULL, //SHAREDCRYPTO_X509_ConstructCertificate X509_ConstructCertificate; + NULL, //SHAREDCRYPTO_X509_ConstructCertificateStack X509_ConstructCertificateStack; + NULL, //SHAREDCRYPTO_X509_Free X509_Free; + NULL, //SHAREDCRYPTO_X509_StackFree X509_StackFree; + NULL, //SHAREDCRYPTO_X509_GetTBSCert X509_GetTBSCert; + /// TDES + NULL, //SHAREDCRYPTO_TDES_GetContextSize TDES_GetContextSize; + NULL, //SHAREDCRYPTO_TDES_Init TDES_Init; + NULL, //SHAREDCRYPTO_TDES_EcbEncrypt TDES_EcbEncrypt; + NULL, //SHAREDCRYPTO_TDES_EcbDecrypt TDES_EcbDecrypt; + NULL, //SHAREDCRYPTO_TDES_CbcEncrypt TDES_CbcEncrypt; + NULL, //SHAREDCRYPTO_TDES_CbcDecrypt TDES_CbcDecrypt; + /// AES + NULL, //SHAREDCRYPTO_AES_GetContextSize AES_GetContextSize; + NULL, //SHAREDCRYPTO_AES_Init AES_Init; + NULL, //SHAREDCRYPTO_AES_EcbEncrypt AES_EcbEncrypt; + NULL, //SHAREDCRYPTO_AES_EcbDecrypt AES_EcbDecrypt; + NULL, //SHAREDCRYPTO_AES_CbcEncrypt AES_CbcEncrypt; + NULL, //SHAREDCRYPTO_AES_CbcDecrypt AES_CbcDecrypt; + /// Arc4 + NULL, //SHAREDCRYPTO_ARC4_GetContextSize ARC4_GetContextSize; + NULL, //SHAREDCRYPTO_ARC4_Init ARC4_Init; + NULL, //SHAREDCRYPTO_ARC4_Encrypt ARC4_Encrypt; + NULL, //SHAREDCRYPTO_ARC4_Decrypt ARC4_Decrypt; + NULL //SHAREDCRYPTO_ARC4_Reset ARC4_Reset; + +}; \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Common/SharedCryptoVersion.c b/SharedCryptoPkg/Driver/Common/SharedCryptoVersion.c new file mode 100644 index 0000000000..dc6c0d2f88 --- /dev/null +++ b/SharedCryptoPkg/Driver/Common/SharedCryptoVersion.c @@ -0,0 +1,38 @@ + +/** @file + This function returns the version number that the shared crypto driver is + This is compared against the library and if they do not match, the library asserts + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include + +UINTN +EFIAPI +GetCryptoVersion ( + VOID +) +{ + return SHARED_CRYPTO_VERSION; +} \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Common/SharedCryptoVersion.h b/SharedCryptoPkg/Driver/Common/SharedCryptoVersion.h new file mode 100644 index 0000000000..629ec55d57 --- /dev/null +++ b/SharedCryptoPkg/Driver/Common/SharedCryptoVersion.h @@ -0,0 +1,38 @@ + +/** @file + This module is consumed by both DXE and SMM as well as PEI + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include + +#ifndef __SHARED_CRYPTO_VERSION_H__ +#define __SHARED_CRYPTO_VERSION_H__ + +UINTN +EFIAPI GetCryptoVersion ( + VOID +); + +#endif \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Dxe/SharedCryptoDxe.c b/SharedCryptoPkg/Driver/Dxe/SharedCryptoDxe.c new file mode 100644 index 0000000000..a920544bd2 --- /dev/null +++ b/SharedCryptoPkg/Driver/Dxe/SharedCryptoDxe.c @@ -0,0 +1,59 @@ +/** @file + This module installs Crypto protocol used by Project Mu Firmware + + Specifically, it installs the DXE protocol listed in the SharedCryptoPkg.dec + + See Readme.md in the root of SharedCryptoPkg for more information + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include + +extern SHARED_CRYPTO_FUNCTIONS mSharedCryptoFunctions; + +/** + The module Entry Point of the Project Shared Crypto Dxe Driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +SharedCryptoDxeEntry( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return gBS->InstallMultipleProtocolInterfaces( + &ImageHandle, + &gSharedCryptoProtocolGuid, + (SHARED_CRYPTO_PROTOCOL*) &mSharedCryptoFunctions, + NULL + ); +} \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Mu-SharedCrypto.config.json b/SharedCryptoPkg/Driver/Mu-SharedCrypto.config.json new file mode 100644 index 0000000000..027a7ec4f3 --- /dev/null +++ b/SharedCryptoPkg/Driver/Mu-SharedCrypto.config.json @@ -0,0 +1,9 @@ +{ + "name": "Mu-SharedCrypto", + "author_string": "ProjectMu, TianoCore", + "server_url": "https://api.nuget.org/v3/index.json", + "project_url": "https://aka.ms/projectmu", + "license_url": "https://github.com/Microsoft/mu/blob/master/LICENSE", + "description_string": "The SharedCrypto Binary Package for Project Mu", + "copyright_string": "Copyright 2018" +} \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/Mu-SharedCrypto.md b/SharedCryptoPkg/Driver/Mu-SharedCrypto.md new file mode 100644 index 0000000000..37bfcbfb43 --- /dev/null +++ b/SharedCryptoPkg/Driver/Mu-SharedCrypto.md @@ -0,0 +1,133 @@ +# Crypto Bin Package + +## Copyright + + +## Version 20190329.0.4 + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following conditions are +met: +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + +## About + +The purpose of this package is to provide a wrapper around BaseCryptLib without having to compile the EFI. In theory, linking against BaseCryptLib should give you a higher rate of compression since it will inline code, but in practice the linker gets clever and messes things up. + +It is comprised of a Library Instance that is called SharedCryptoLib. It is contains many of the functions included by BaseCryptLib as well as a few more (mainly X509 related stuff). The library simply locates the protocol and then calls the protocol version of BaseCryptLib (SharedCryptoProtocol). It should be a drop in replacement for the BaseCryptLib. Alternatively, you call the protocol directly. + +The protocol is installed by a prebuilt EFI that gets downloaded via nuget. The EFI is packaged for consumption via an INF that is loaded and installed. + +![Diagram showing dependencies](SharedCryptoPkg.png "Diagram") + + +## Building SharedCryptoPkg + +There are two pieces to be build: the library and the driver. The library is to be included in your project + +There are 24 different versions of the prebuild driver. One for each arch (X86, AARCH64, ARM, X64) and for each phase (DXE, PEI, SMM) and for mode (DEBUG, RELEASE). The nuget system should take care of downloading the correct version for your project. + +## Supported Functions + ++ Pkcs + + PKCS1_ENCRYPT_V2 _Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the encrypted message in a newly allocated buffer._ + + PKCS5_PW_HASH _Hashes a password using Pkcs5_ + + PKCS7_VERIFY_EKU _Receives a PKCS7 formatted signature, and then verifies that the specified EKU's are present in the end-entity leaf signing certificate_ + + PKCS7_VERIFY _Verifies the validility of a PKCS7 signed data. The data can be wrappedin a ContentInfo structure._ ++ RSA + + RSA_VERIFY_PKCS1 _Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in RSA PKCS1_ + + RSA_FREE _Release the specified RSA context_ + + RSA_GET_PUBLIC_KEY_FROM_X509 _Retrieve the RSA Public Key from one DER-encoded X509 certificate._ ++ SHA + + SHA1_GET_CONTEXT_SIZE _Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations._ + + SHA1_INIT _Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for subsequent use._ + + SHA1_DUPLICATE _Makes a copy of an existing SHA1 context_ + + SHA1_UPDATE _Digests input and updates SHA content_ + + SHA1_FINAL _Completes computation of SHA1 digest values_ + + SHA1_HASH_ALL _Computes the SHA1 message digest of an data buffer_ + + SHA256_GET_CONTEXT_SIZE _Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operation_ + + SHA256_INIT _Initializes user-supplied memory pointed by Sha1Context as SHA-256 hash context for subsequent use._ + + SHA256_DUPLICATE _Makes a copy of an existing SHA256 context_ + + SHA256_UPDATE _Digests input and updates SHA content_ + + SHA256_FINAL _Completes computation of SHA256 digest values_ + + SHA256_HASH_ALL _Computes the SHA256 message digest of an data buffer_ ++ X509 + + X509_GET_SUBJECT_NAME _Retrive the subject btyes from one X.509 cert_ + + X509_GET_COMMON_NAME _Retrieve the common name (CN) string from one X.509 certificate._ + + X509_GET_ORGANIZATION_NAME _Retrieve the organization name (O) string from one X.509 certificate._ ++ MD5 + + ++ Hmac + + HMAC_SHA256_GetContextSize + + HMAC_SHA256_New + + HMAC_SHA256_Free + + HMAC_SHA256_Init + + HMAC_SHA256_Duplicate + + HMAC_SHA256_Update + + HMAC_SHA256_Final + + HMAC_SHA1_GetContextSize + + HMAC_SHA1_New + + HMAC_SHA1_Free + + HMAC_SHA1_Init + + HMAC_SHA1_Duplicate + + HMAC_SHA1_Update + + HMAC_SHA1_Final ++ Random + + RANDOM_Bytes _Generates a pseudorandom byte stream of the specified size_ + + RANDOM_Seed _Sets up the seed value for the pseudorandom number generator._ + +## Supported Architectures +This currently supports x86, x64, AARCH64, and ARM. + +# Including in your platform + +There are two ways to include this in your project: getting the protocol directly or using SharedCryptoLib. SharedCryptoLib is a wrapper that is a super set of the API for BaseCryptLib so you can just drop it in. + + + +## Sample DSC change + +This would replace where you would normally include BaseCryptLib. + +``` +[LibraryClasses.X64] + BaseCryptLib|SharedCryptoPkg/Library/SharedCryptoLib/SharedCryptoLibDxe.inf + ... + +[LibraryClasses.IA32.PEIM] + BaseCryptLib|SharedCryptoPkg/Library/SharedCryptoLib/SharedCryptoLibPei.inf + ... + +[LibraryClasses.DXE_SMM] + BaseCryptLib|SharedCryptoPkg/Library/SharedCryptoLib/SharedCryptoLibSmm.inf + ... +``` + +## Sample FDF change + +TODO: re-evluate this once nuget dependency is live +Include this file in your FV and the module will get loaded. + +``` +[FV.FVDXE] + INF SharedCryptoPkg/Package/SharedCryptoPkgDxe.inf + ... + ... +``` diff --git a/SharedCryptoPkg/Driver/Pei/SharedCryptoPei.c b/SharedCryptoPkg/Driver/Pei/SharedCryptoPei.c new file mode 100644 index 0000000000..114bc9e826 --- /dev/null +++ b/SharedCryptoPkg/Driver/Pei/SharedCryptoPei.c @@ -0,0 +1,56 @@ +/** @file + This module installs Crypto PPI used by Project Mu Firmware + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include + +extern const SHARED_CRYPTO_FUNCTIONS mSharedCryptoFunctions; + +CONST EFI_PEI_PPI_DESCRIPTOR mUefiCryptoPpiList = { + (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST), + &gSharedCryptoPpiGuid, + (SHARED_CRYPTO_PPI*) &mSharedCryptoFunctions +}; + + +/** +Entry to MsWheaReportPei. + +@param FileHandle The image handle. +@param PeiServices The PEI services table. + +@retval Status From internal routine or boot object, should not fail +**/ +EFI_STATUS +EFIAPI +SharedCryptoPeiEntry ( + IN EFI_PEI_FILE_HANDLE FileHandle, + IN CONST EFI_PEI_SERVICES **PeiServices + ) +{ + EFI_STATUS Status = PeiServicesInstallPpi (&mUefiCryptoPpiList); + return Status; +} diff --git a/SharedCryptoPkg/Driver/SharedCryptoDxe.inf b/SharedCryptoPkg/Driver/SharedCryptoDxe.inf new file mode 100644 index 0000000000..5819c29435 --- /dev/null +++ b/SharedCryptoPkg/Driver/SharedCryptoDxe.inf @@ -0,0 +1,67 @@ +## @file +# This module consolidates all crypto needed for Project Mu UEFI and provides +# protocol for those functions. This protocol provides a subset of BaseCryptLib. +# +# see Readme.md in SharedCryptoPkg +# There are a few flavors of support from the protocol and this is just one version. +# This supports all baseCrypt function +# +# Copyright (c) 2019, Microsoft Corporation. All rights reserved. +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x0001001B + PI_SPECIFICATION_VERSION = 0x0001000A + BASE_NAME = SharedCryptoDxe + FILE_GUID = FEA01457-E381-4135-9475-C6AFD0076C61 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoDxeEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +[Sources] + Common/CommonSharedCryptoFull.c + Common/SharedCryptoVersion.c + Dxe/SharedCryptoDxe.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + BaseCryptLib + UefiDriverEntryPoint + +[Protocols] + gSharedCryptoProtocolGuid ## produces + +[Depex] + TRUE \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/SharedCryptoDxeMu.inf b/SharedCryptoPkg/Driver/SharedCryptoDxeMu.inf new file mode 100644 index 0000000000..8deb1050b9 --- /dev/null +++ b/SharedCryptoPkg/Driver/SharedCryptoDxeMu.inf @@ -0,0 +1,67 @@ +## @file +# This module consolidates all crypto needed for Project Mu UEFI and provides +# protocol for those functions. This protocol provides a subset of BaseCryptLib. +# +# see Readme.md in SharedCryptoPkg +# There are a few flavors of support from the protocol and this is just one version. +# This supports just the functions that Project Mu uses. +# +# Copyright (c) 2019, Microsoft Corporation. All rights reserved. +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x0001001B + PI_SPECIFICATION_VERSION = 0x0001000A + BASE_NAME = SharedCryptoDxeMu + FILE_GUID = BECD81FD-AC56-4308-BEFC-957EA17384D2 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoDxeEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +[Sources] + Common/SharedCryptoVersion.c + Common/CommonSharedCryptoMu.c + Dxe/SharedCryptoDxe.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + +[LibraryClasses] + UefiBootServicesTableLib + BaseCryptLib + UefiDriverEntryPoint + +[Protocols] + gSharedCryptoProtocolGuid ## produces + +[Depex] + TRUE \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/SharedCryptoPeiShaOnly.inf b/SharedCryptoPkg/Driver/SharedCryptoPeiShaOnly.inf new file mode 100644 index 0000000000..3e9b73d575 --- /dev/null +++ b/SharedCryptoPkg/Driver/SharedCryptoPeiShaOnly.inf @@ -0,0 +1,66 @@ +## @file +# This module consolidates all crypto needed for Project Mu UEFI and provides +# a PPI for those functions. +# +# There are several different flavors of each driver and this flavor just supports SHA +# +# Copyright (c) 2019, Microsoft Corporation. All rights reserved. +# + +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x0001000A + BASE_NAME = SharedCryptoPeiShaOnly + FILE_GUID = 0D1CE46B-72D9-4BA7-95DA-23511865E661 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoPeiEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + Common/CommonSharedCryptoShaOnly.c + Pei/SharedCryptoPei.c + Common/SharedCryptoVersion.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + +[LibraryClasses] + PeimEntryPoint + BaseCryptLib + DebugLib + PeiServicesLib + +[Ppis] + gSharedCryptoPpiGuid ## produces + +[Depex] + TRUE \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/SharedCryptoSmm.inf b/SharedCryptoPkg/Driver/SharedCryptoSmm.inf new file mode 100644 index 0000000000..3cb3715386 --- /dev/null +++ b/SharedCryptoPkg/Driver/SharedCryptoSmm.inf @@ -0,0 +1,70 @@ +## @file +# This module consolidates all crypto needed for Project Mu UEFI and provides a +# protocol for those functions. +# +# see Readme.md in SharedCryptoPkg +# +# There are a few flavors of support from the protocol and this is just one version. +# This supports all the functions that BaseCryptLib has. +# +# Copyright (c) 2019, Microsoft Corporation. All rights reserved. +# + +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x0001001B + PI_SPECIFICATION_VERSION = 0x0001001B + BASE_NAME = SharedCryptoSmm + FILE_GUID = 391B853F-F488-479B-A3D6-870766C7A38F + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoSmmEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + Common/CommonSharedCryptoFull.c + Common/SharedCryptoVersion.c + Smm/SharedCryptoSmm.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + SmmServicesTableLib + UefiDriverEntryPoint + BaseCryptLib + +[Protocols] + gSharedCryptoSmmProtocolGuid ## produces + +[Depex] + TRUE \ No newline at end of file diff --git a/SharedCryptoPkg/Driver/SharedCryptoSmmMu.inf b/SharedCryptoPkg/Driver/SharedCryptoSmmMu.inf new file mode 100644 index 0000000000..27b0863f3a --- /dev/null +++ b/SharedCryptoPkg/Driver/SharedCryptoSmmMu.inf @@ -0,0 +1,70 @@ +## @file +# This module consolidates all crypto needed for Project Mu UEFI and provides a +# protocol for those functions. +# +# see Readme.md in SharedCryptoPkg +# +# There are a few flavors of support from the protocol and this is just one version. +# This supports just the functions that Project Mu uses. +# +# Copyright (c) 2019, Microsoft Corporation. All rights reserved. +# + +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x0001001B + PI_SPECIFICATION_VERSION = 0x0001000A + BASE_NAME = SharedCryptoSmmMu + FILE_GUID = 8866803C-2F32-4835-B9AC-6510CAF56B52 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoSmmEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +[Sources] + Common/CommonSharedCryptoMu.c + Common/SharedCryptoVersion.c + Smm/SharedCryptoSmm.c + +[Packages] + MdePkg/MdePkg.dec + CryptoPkg/CryptoPkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + SmmServicesTableLib + UefiDriverEntryPoint + BaseCryptLib + +[Protocols] + gSharedCryptoSmmProtocolGuid ## produces + +[Depex] + TRUE diff --git a/SharedCryptoPkg/Driver/Smm/SharedCryptoSmm.c b/SharedCryptoPkg/Driver/Smm/SharedCryptoSmm.c new file mode 100644 index 0000000000..457c772d15 --- /dev/null +++ b/SharedCryptoPkg/Driver/Smm/SharedCryptoSmm.c @@ -0,0 +1,56 @@ +/** @file + This module installs Crypto protocols used by Project Mu Firmware + + Copyright (c) 2019, Microsoft Corporation. All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE + OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include + +extern const SHARED_CRYPTO_FUNCTIONS mSharedCryptoFunctions; + +/** + The module Entry Point of the Project Shared Crypto Dxe Driver. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval Other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +SharedCryptoSmmEntry( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable +) +{ + EFI_HANDLE Handle = NULL; + return gSmst->SmmInstallProtocolInterface ( + &Handle, + &gSharedCryptoSmmProtocolGuid, + EFI_NATIVE_INTERFACE, + (SHARED_CRYPTO_PROTOCOL*) &mSharedCryptoFunctions); + +} \ No newline at end of file diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/Common/CommonSharedCryptoLib.c b/SharedCryptoPkg/Library/CryptLibSharedDriver/Common/CommonSharedCryptoLib.c new file mode 100644 index 0000000000..f82d1cd376 --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/Common/CommonSharedCryptoLib.c @@ -0,0 +1,3884 @@ +/** @file +SharedCryptoLib.c + +This defines the implementation of BaseCryptLib and calls out to the protocol +published by SharedCryptoDriver. The ProtocolFunctionNotFound and GetProtocol +funtion is defined by the flavor of the library. + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include +#include +#include +#include + + +//===================================================================================== +// One-Way Cryptographic Hash Primitives +//===================================================================================== + +/** + Retrieves the size, in bytes, of the context buffer required for MD4 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for MD4 hash operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +Md4GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_GetContextSize == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->MD4_GetContextSize(); +} + +/** + Initializes user-supplied memory pointed by Md4Context as MD4 hash context for + subsequent use. + + If Md4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Md4Context Pointer to MD4 context being initialized. + + @retval TRUE MD4 context initialization succeeded. + @retval FALSE MD4 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Init ( + OUT VOID *Md4Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Init == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->MD4_Init(Md4Context); +} + +/** + Makes a copy of an existing MD4 context. + + If Md4Context is NULL, then return FALSE. + If NewMd4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Md4Context Pointer to MD4 context being copied. + @param[out] NewMd4Context Pointer to new MD4 context. + + @retval TRUE MD4 context copy succeeded. + @retval FALSE MD4 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Duplicate ( + IN CONST VOID *Md4Context, + OUT VOID *NewMd4Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Duplicate == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->MD4_Duplicate(Md4Context, NewMd4Context); +} + +/** + Digests the input data and updates MD4 context. + + This function performs MD4 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + MD4 context should be already correctly initialized by Md4Init(), and should not be finalized + by Md4Final(). Behavior with invalid context is undefined. + + If Md4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md4Context Pointer to the MD4 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE MD4 data digest succeeded. + @retval FALSE MD4 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Update ( + IN OUT VOID *Md4Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Update == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->MD4_Update(Md4Context, Data, DataSize); +} + +/** + Completes computation of the MD4 digest value. + + This function completes MD4 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the MD4 context cannot + be used again. + MD4 context should be already correctly initialized by Md4Init(), and should not be + finalized by Md4Final(). Behavior with invalid MD4 context is undefined. + + If Md4Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md4Context Pointer to the MD4 context. + @param[out] HashValue Pointer to a buffer that receives the MD4 digest + value (16 bytes). + + @retval TRUE MD4 digest computation succeeded. + @retval FALSE MD4 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4Final ( + IN OUT VOID *Md4Context, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Final == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->MD4_Final(Md4Context, HashValue); +} + +/** + Computes the MD4 message digest of a input data buffer. + + This function performs the MD4 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the MD4 digest + value (16 bytes). + + @retval TRUE MD4 digest computation succeeded. + @retval FALSE MD4 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md4HashAll ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_HashAll == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->MD4_HashAll(Data, DataSize, HashValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for MD5 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for MD5 hash operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +Md5GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return 0; + + if (prot->MD5_GetContextSize == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + + return prot->MD5_GetContextSize(); +} + +/** + Initializes user-supplied memory pointed by Md5Context as MD5 hash context for + subsequent use. + + If Md5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Md5Context Pointer to MD5 context being initialized. + + @retval TRUE MD5 context initialization succeeded. + @retval FALSE MD5 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md5Init ( + OUT VOID *Md5Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + + if (prot->MD5_Init == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->MD5_Init(Md5Context); +} + +/** + Makes a copy of an existing MD5 context. + + If Md5Context is NULL, then return FALSE. + If NewMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Md5Context Pointer to MD5 context being copied. + @param[out] NewMd5Context Pointer to new MD5 context. + + @retval TRUE MD5 context copy succeeded. + @retval FALSE MD5 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md5Duplicate ( + IN CONST VOID *Md5Context, + OUT VOID *NewMd5Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + + if (prot->MD5_Update == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->MD5_Duplicate(Md5Context, NewMd5Context); +} + +/** + Digests the input data and updates MD5 context. + + This function performs MD5 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + MD5 context should be already correctly initialized by Md5Init(), and should not be finalized + by Md5Final(). Behavior with invalid context is undefined. + + If Md5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md5Context Pointer to the MD5 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE MD5 data digest succeeded. + @retval FALSE MD5 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md5Update ( + IN OUT VOID *Md5Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + + if (prot->MD5_Update == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->MD5_Update(Md5Context, Data, DataSize); +} + +/** + Completes computation of the MD5 digest value. + + This function completes MD5 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the MD5 context cannot + be used again. + MD5 context should be already correctly initialized by Md5Init(), and should not be + finalized by Md5Final(). Behavior with invalid MD5 context is undefined. + + If Md5Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md5Context Pointer to the MD5 context. + @param[out] HashValue Pointer to a buffer that receives the MD5 digest + value (16 bytes). + + @retval TRUE MD5 digest computation succeeded. + @retval FALSE MD5 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md5Final ( + IN OUT VOID *Md5Context, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + + if (prot->MD5_Final == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->MD5_Final(Md5Context, HashValue); +} + +/** + Computes the MD5 message digest of a input data buffer. + + This function performs the MD5 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the MD5 digest + value (16 bytes). + + @retval TRUE MD5 digest computation succeeded. + @retval FALSE MD5 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Md5HashAll ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + + if (prot->MD5_HashAll == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->MD5_HashAll(Data, DataSize, HashValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for SHA-1 hash operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +Sha1GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return 0; + if (prot->SHA1_GET_CONTEXT_SIZE == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + + return prot->SHA1_GET_CONTEXT_SIZE(); +} + +/** + Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for + subsequent use. + + If Sha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Sha1Context Pointer to SHA-1 context being initialized. + + @retval TRUE SHA-1 context initialization succeeded. + @retval FALSE SHA-1 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha1Init ( + OUT VOID *Sha1Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA1_INIT == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA1_INIT(Sha1Context); +} + +/** + Makes a copy of an existing SHA-1 context. + + If Sha1Context is NULL, then return FALSE. + If NewSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha1Context Pointer to SHA-1 context being copied. + @param[out] NewSha1Context Pointer to new SHA-1 context. + + @retval TRUE SHA-1 context copy succeeded. + @retval FALSE SHA-1 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha1Duplicate ( + IN CONST VOID *Sha1Context, + OUT VOID *NewSha1Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA1_DUPLICATE == NULL) + return FALSE; + + return prot->SHA1_DUPLICATE(Sha1Context, NewSha1Context); +} + +/** + Digests the input data and updates SHA-1 context. + + This function performs SHA-1 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized + by Sha1Final(). Behavior with invalid context is undefined. + + If Sha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Sha1Context Pointer to the SHA-1 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-1 data digest succeeded. + @retval FALSE SHA-1 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha1Update ( + IN OUT VOID *Sha1Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA1_UPDATE == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA1_UPDATE(Sha1Context, Data, DataSize); +} + +/** + Completes computation of the SHA-1 digest value. + + This function completes SHA-1 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-1 context cannot + be used again. + SHA-1 context should be already correctly initialized by Sha1Init(), and should not be + finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined. + + If Sha1Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Sha1Context Pointer to the SHA-1 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest + value (20 bytes). + + @retval TRUE SHA-1 digest computation succeeded. + @retval FALSE SHA-1 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha1Final ( + IN OUT VOID *Sha1Context, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA1_FINAL == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA1_FINAL(Sha1Context, HashValue); +} + +/** + Computes the SHA-1 message digest of a input data buffer. + + This function performs the SHA-1 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest + value (20 bytes). + + @retval TRUE SHA-1 digest computation succeeded. + @retval FALSE SHA-1 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha1HashAll ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA1_HASH_ALL == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA1_HASH_ALL(Data, DataSize, HashValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-256 hash operations. + +**/ +UINTN +EFIAPI +Sha256GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return 0; + if (prot->SHA256_GET_CONTEXT_SIZE == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + + return prot->SHA256_GET_CONTEXT_SIZE(); +} + +/** + Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for + subsequent use. + + If Sha256Context is NULL, then return FALSE. + + @param[out] Sha256Context Pointer to SHA-256 context being initialized. + + @retval TRUE SHA-256 context initialization succeeded. + @retval FALSE SHA-256 context initialization failed. + +**/ +BOOLEAN +EFIAPI +Sha256Init ( + OUT VOID *Sha256Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA256_INIT == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA256_INIT(Sha256Context); +} + +/** + Makes a copy of an existing SHA-256 context. + + If Sha256Context is NULL, then return FALSE. + If NewSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha256Context Pointer to SHA-256 context being copied. + @param[out] NewSha256Context Pointer to new SHA-256 context. + + @retval TRUE SHA-256 context copy succeeded. + @retval FALSE SHA-256 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha256Duplicate ( + IN CONST VOID *Sha256Context, + OUT VOID *NewSha256Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA256_DUPLICATE == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA256_DUPLICATE(Sha256Context, NewSha256Context); +} + +/** + Digests the input data and updates SHA-256 context. + + This function performs SHA-256 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized + by Sha256Final(). Behavior with invalid context is undefined. + + If Sha256Context is NULL, then return FALSE. + + @param[in, out] Sha256Context Pointer to the SHA-256 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-256 data digest succeeded. + @retval FALSE SHA-256 data digest failed. + +**/ +BOOLEAN +EFIAPI +Sha256Update ( + IN OUT VOID *Sha256Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA256_UPDATE == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA256_UPDATE(Sha256Context, Data, DataSize); +} + +/** + Completes computation of the SHA-256 digest value. + + This function completes SHA-256 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-256 context cannot + be used again. + SHA-256 context should be already correctly initialized by Sha256Init(), and should not be + finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined. + + If Sha256Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha256Context Pointer to the SHA-256 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest + value (32 bytes). + + @retval TRUE SHA-256 digest computation succeeded. + @retval FALSE SHA-256 digest computation failed. + +**/ +BOOLEAN +EFIAPI +Sha256Final ( + IN OUT VOID *Sha256Context, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL) + return FALSE; + if (prot->SHA256_FINAL == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->SHA256_FINAL(Sha256Context, HashValue); +} + +/** + Computes the SHA-256 message digest of a input data buffer. + + This function performs the SHA-256 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest + value (32 bytes). + + @retval TRUE SHA-256 digest computation succeeded. + @retval FALSE SHA-256 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha256HashAll ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA256_HASH_ALL == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA256_HASH_ALL(Data, DataSize, HashValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-384 hash operations. + +**/ +UINTN +EFIAPI +Sha384GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA384_GetContextSize == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->SHA384_GetContextSize(); +} + +/** + Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for + subsequent use. + + If Sha384Context is NULL, then return FALSE. + + @param[out] Sha384Context Pointer to SHA-384 context being initialized. + + @retval TRUE SHA-384 context initialization succeeded. + @retval FALSE SHA-384 context initialization failed. + +**/ +BOOLEAN +EFIAPI +Sha384Init ( + OUT VOID *Sha384Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA384_Init == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA384_Init(Sha384Context); +} + +/** + Makes a copy of an existing SHA-384 context. + + If Sha384Context is NULL, then return FALSE. + If NewSha384Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha384Context Pointer to SHA-384 context being copied. + @param[out] NewSha384Context Pointer to new SHA-384 context. + + @retval TRUE SHA-384 context copy succeeded. + @retval FALSE SHA-384 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha384Duplicate ( + IN CONST VOID *Sha384Context, + OUT VOID *NewSha384Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA384_Duplicate == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA384_Duplicate(Sha384Context, NewSha384Context); +} + +/** + Digests the input data and updates SHA-384 context. + + This function performs SHA-384 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized + by Sha384Final(). Behavior with invalid context is undefined. + + If Sha384Context is NULL, then return FALSE. + + @param[in, out] Sha384Context Pointer to the SHA-384 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-384 data digest succeeded. + @retval FALSE SHA-384 data digest failed. + +**/ +BOOLEAN +EFIAPI +Sha384Update ( + IN OUT VOID *Sha384Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA384_Update == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA384_Update(Sha384Context, Data, DataSize); +} + +/** + Completes computation of the SHA-384 digest value. + + This function completes SHA-384 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-384 context cannot + be used again. + SHA-384 context should be already correctly initialized by Sha384Init(), and should not be + finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined. + + If Sha384Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha384Context Pointer to the SHA-384 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest + value (48 bytes). + + @retval TRUE SHA-384 digest computation succeeded. + @retval FALSE SHA-384 digest computation failed. + +**/ +BOOLEAN +EFIAPI +Sha384Final ( + IN OUT VOID *Sha384Context, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA384_Final == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA384_Final(Sha384Context, HashValue); +} + +/** + Computes the SHA-384 message digest of a input data buffer. + + This function performs the SHA-384 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest + value (48 bytes). + + @retval TRUE SHA-384 digest computation succeeded. + @retval FALSE SHA-384 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha384HashAll ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA384_HashAll == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA384_HashAll(Data, DataSize, HashValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-512 hash operations. + +**/ +UINTN +EFIAPI +Sha512GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA512_GetContextSize == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->SHA512_GetContextSize(); +} + +/** + Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for + subsequent use. + + If Sha512Context is NULL, then return FALSE. + + @param[out] Sha512Context Pointer to SHA-512 context being initialized. + + @retval TRUE SHA-512 context initialization succeeded. + @retval FALSE SHA-512 context initialization failed. + +**/ +BOOLEAN +EFIAPI +Sha512Init ( + OUT VOID *Sha512Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA512_Init == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA512_Init(Sha512Context); +} + +/** + Makes a copy of an existing SHA-512 context. + + If Sha512Context is NULL, then return FALSE. + If NewSha512Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha512Context Pointer to SHA-512 context being copied. + @param[out] NewSha512Context Pointer to new SHA-512 context. + + @retval TRUE SHA-512 context copy succeeded. + @retval FALSE SHA-512 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha512Duplicate ( + IN CONST VOID *Sha512Context, + OUT VOID *NewSha512Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA512_Duplicate == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA512_Duplicate(Sha512Context, NewSha512Context); +} + +/** + Digests the input data and updates SHA-512 context. + + This function performs SHA-512 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized + by Sha512Final(). Behavior with invalid context is undefined. + + If Sha512Context is NULL, then return FALSE. + + @param[in, out] Sha512Context Pointer to the SHA-512 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-512 data digest succeeded. + @retval FALSE SHA-512 data digest failed. + +**/ +BOOLEAN +EFIAPI +Sha512Update ( + IN OUT VOID *Sha512Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA512_Update == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA512_Update(Sha512Context, Data, DataSize); +} + +/** + Completes computation of the SHA-512 digest value. + + This function completes SHA-512 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-512 context cannot + be used again. + SHA-512 context should be already correctly initialized by Sha512Init(), and should not be + finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined. + + If Sha512Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha512Context Pointer to the SHA-512 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest + value (64 bytes). + + @retval TRUE SHA-512 digest computation succeeded. + @retval FALSE SHA-512 digest computation failed. + +**/ +BOOLEAN +EFIAPI +Sha512Final ( + IN OUT VOID *Sha512Context, + OUT UINT8 *HashValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA512_Final == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA512_Final(Sha512Context, HashValue); +} + +/** + Computes the SHA-512 message digest of a input data buffer. + + This function performs the SHA-512 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest + value (64 bytes). + + @retval TRUE SHA-512 digest computation succeeded. + @retval FALSE SHA-512 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Sha512HashAll ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->SHA512_HashAll == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->SHA512_HashAll(Data, DataSize, HashValue); +} + +//===================================================================================== +// MAC (Message Authentication Code) Primitive +//===================================================================================== + +/** + Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations. + (NOTE: This API is deprecated. + Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for HMAC-MD5 operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +HmacMd5GetContextSize ( + VOID +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_GetContextSize == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->HMAC_MD5_GetContextSize(); +} + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use. + + If this interface is not supported, then return NULL. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacMd5New() returns NULL. + @retval NULL This interface is not supported. + +**/ +VOID * +EFIAPI +HmacMd5New ( + VOID +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_New == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->HMAC_MD5_New(); +} + +/** + Release the specified HMAC_CTX context. + + If this interface is not supported, then do nothing. + + @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released. + +**/ +VOID +EFIAPI +HmacMd5Free ( + IN VOID *HmacMd5Ctx +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_Free == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return; + } + prot->HMAC_MD5_Free(HmacMd5Ctx); +} + +/** + Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for + subsequent use. + + If HmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized. + @param[in] Key Pointer to the user-supplied key. + @param[in] KeySize Key size in bytes. + + @retval TRUE HMAC-MD5 context initialization succeeded. + @retval FALSE HMAC-MD5 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacMd5Init ( + OUT VOID *HmacMd5Context, + IN CONST UINT8 *Key, + IN UINTN KeySize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_Init == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->HMAC_MD5_Init(HmacMd5Context, Key, KeySize); +} + +/** + Makes a copy of an existing HMAC-MD5 context. + + If HmacMd5Context is NULL, then return FALSE. + If NewHmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied. + @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context. + + @retval TRUE HMAC-MD5 context copy succeeded. + @retval FALSE HMAC-MD5 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacMd5Duplicate ( + IN CONST VOID *HmacMd5Context, + OUT VOID *NewHmacMd5Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_Duplicate == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->HMAC_MD5_Duplicate(HmacMd5Context, NewHmacMd5Context); +} + +/** + Digests the input data and updates HMAC-MD5 context. + + This function performs HMAC-MD5 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be + finalized by HmacMd5Final(). Behavior with invalid context is undefined. + + If HmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context. + @param[in] Data Pointer to the buffer containing the data to be digested. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE HMAC-MD5 data digest succeeded. + @retval FALSE HMAC-MD5 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacMd5Update ( + IN OUT VOID *HmacMd5Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_Update == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->HMAC_MD5_Update(HmacMd5Context, Data, DataSize); +} + +/** + Completes computation of the HMAC-MD5 digest value. + + This function completes HMAC-MD5 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the HMAC-MD5 context cannot + be used again. + HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be + finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined. + + If HmacMd5Context is NULL, then return FALSE. + If HmacValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context. + @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest + value (16 bytes). + + @retval TRUE HMAC-MD5 digest computation succeeded. + @retval FALSE HMAC-MD5 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacMd5Final ( + IN OUT VOID *HmacMd5Context, + OUT UINT8 *HmacValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_MD5_Final == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->HMAC_MD5_Final(HmacMd5Context, HmacValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations. + (NOTE: This API is deprecated. + Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operations.) + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +HmacSha1GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA1_GetContextSize == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + + return prot->HMAC_SHA1_GetContextSize(); +} + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use. + + If this interface is not supported, then return NULL. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacSha1New() returns NULL. + @return NULL This interface is not supported. + +**/ +VOID * +EFIAPI +HmacSha1New ( + VOID +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL||prot->HMAC_SHA1_New == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return NULL; + } + + return prot->HMAC_SHA1_New(); +} + +/** + Release the specified HMAC_CTX context. + + If this interface is not supported, then do nothing. + + @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released. + +**/ +VOID + EFIAPI + HmacSha1Free ( + IN VOID *HmacSha1Ctx) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA1_Free == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return; + } + + prot->HMAC_SHA1_Free(HmacSha1Ctx); +} + +/** + Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for + subsequent use. + + If HmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized. + @param[in] Key Pointer to the user-supplied key. + @param[in] KeySize Key size in bytes. + + @retval TRUE HMAC-SHA1 context initialization succeeded. + @retval FALSE HMAC-SHA1 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha1Init ( + OUT VOID *HmacSha1Context, + IN CONST UINT8 *Key, + IN UINTN KeySize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA1_Init == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA1_Init(HmacSha1Context, Key, KeySize); +} + +/** + Makes a copy of an existing HMAC-SHA1 context. + + If HmacSha1Context is NULL, then return FALSE. + If NewHmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied. + @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context. + + @retval TRUE HMAC-SHA1 context copy succeeded. + @retval FALSE HMAC-SHA1 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha1Duplicate ( + IN CONST VOID *HmacSha1Context, + OUT VOID *NewHmacSha1Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA1_Duplicate == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA1_Duplicate(HmacSha1Context, NewHmacSha1Context); +} + +/** + Digests the input data and updates HMAC-SHA1 context. + + This function performs HMAC-SHA1 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should not + be finalized by HmacSha1Final(). Behavior with invalid context is undefined. + + If HmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context. + @param[in] Data Pointer to the buffer containing the data to be digested. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE HMAC-SHA1 data digest succeeded. + @retval FALSE HMAC-SHA1 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha1Update ( + IN OUT VOID *HmacSha1Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA1_Update == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA1_Update(HmacSha1Context, Data, DataSize); +} + +/** + Completes computation of the HMAC-SHA1 digest value. + + This function completes HMAC-SHA1 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the HMAC-SHA1 context cannot + be used again. + HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should + not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined. + + If HmacSha1Context is NULL, then return FALSE. + If HmacValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context. + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest + value (20 bytes). + + @retval TRUE HMAC-SHA1 digest computation succeeded. + @retval FALSE HMAC-SHA1 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha1Final ( + IN OUT VOID *HmacSha1Context, + OUT UINT8 *HmacValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA1_Final == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA1_Final(HmacSha1Context, HmacValue); +} + +/** + Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations. + (NOTE: This API is deprecated. + Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.) + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +HmacSha256GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_GetContextSize == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + + return prot->HMAC_SHA256_GetContextSize(); +} + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacSha256New() returns NULL. + +**/ +VOID * + EFIAPI + HmacSha256New ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_New == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return NULL; + } + + return prot->HMAC_SHA256_New(); +} + +/** + Release the specified HMAC_CTX context. + + @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released. + +**/ +VOID + EFIAPI + HmacSha256Free ( + IN VOID *HmacSha256Ctx) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_Free == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return; + } + + prot->HMAC_SHA256_Free(HmacSha256Ctx); +} + +/** + Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for + subsequent use. + + If HmacSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized. + @param[in] Key Pointer to the user-supplied key. + @param[in] KeySize Key size in bytes. + + @retval TRUE HMAC-SHA256 context initialization succeeded. + @retval FALSE HMAC-SHA256 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha256Init ( + OUT VOID *HmacSha256Context, + IN CONST UINT8 *Key, + IN UINTN KeySize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_Free == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA256_Init(HmacSha256Context, Key, KeySize); +} + +/** + Makes a copy of an existing HMAC-SHA256 context. + + If HmacSha256Context is NULL, then return FALSE. + If NewHmacSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied. + @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context. + + @retval TRUE HMAC-SHA256 context copy succeeded. + @retval FALSE HMAC-SHA256 context copy failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha256Duplicate ( + IN CONST VOID *HmacSha256Context, + OUT VOID *NewHmacSha256Context) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_Duplicate == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA256_Duplicate(HmacSha256Context, NewHmacSha256Context); +} + +/** + Digests the input data and updates HMAC-SHA256 context. + + This function performs HMAC-SHA256 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not + be finalized by HmacSha256Final(). Behavior with invalid context is undefined. + + If HmacSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context. + @param[in] Data Pointer to the buffer containing the data to be digested. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE HMAC-SHA256 data digest succeeded. + @retval FALSE HMAC-SHA256 data digest failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha256Update ( + IN OUT VOID *HmacSha256Context, + IN CONST VOID *Data, + IN UINTN DataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_Update == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA256_Update(HmacSha256Context, Data, DataSize); +} + +/** + Completes computation of the HMAC-SHA256 digest value. + + This function completes HMAC-SHA256 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the HMAC-SHA256 context cannot + be used again. + HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should + not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined. + + If HmacSha256Context is NULL, then return FALSE. + If HmacValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context. + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest + value (32 bytes). + + @retval TRUE HMAC-SHA256 digest computation succeeded. + @retval FALSE HMAC-SHA256 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +HmacSha256Final ( + IN OUT VOID *HmacSha256Context, + OUT UINT8 *HmacValue) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->HMAC_SHA256_Final == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->HMAC_SHA256_Final(HmacSha256Context, HmacValue); +} + +//===================================================================================== +// Symmetric Cryptography Primitive +//===================================================================================== + +/** + Retrieves the size, in bytes, of the context buffer required for TDES operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for TDES operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +TdesGetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->TDES_GetContextSize == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->TDES_GetContextSize(); +} + +/** + Initializes user-supplied memory as TDES context for subsequent use. + + This function initializes user-supplied memory pointed by TdesContext as TDES context. + In addition, it sets up all TDES key materials for subsequent encryption and decryption + operations. + There are 3 key options as follows: + KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES) + KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security) + KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest) + + If TdesContext is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeyLength is not valid, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] TdesContext Pointer to TDES context being initialized. + @param[in] Key Pointer to the user-supplied TDES key. + @param[in] KeyLength Length of TDES key in bits. + + @retval TRUE TDES context initialization succeeded. + @retval FALSE TDES context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +TdesInit ( + OUT VOID *TdesContext, + IN CONST UINT8 *Key, + IN UINTN KeyLength) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->TDES_Init == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->TDES_Init(TdesContext, Key, KeyLength); +} + +/** + Performs TDES encryption on a data buffer of the specified size in ECB mode. + + This function performs TDES encryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the TDES encryption output. + + @retval TRUE TDES encryption succeeded. + @retval FALSE TDES encryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +TdesEcbEncrypt ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->TDES_EcbEncrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->TDES_EcbEncrypt(TdesContext, Input, InputSize, Output); +} + +/** + Performs TDES decryption on a data buffer of the specified size in ECB mode. + + This function performs TDES decryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be decrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the TDES decryption output. + + @retval TRUE TDES decryption succeeded. + @retval FALSE TDES decryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +TdesEcbDecrypt ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->TDES_EcbDecrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->TDES_EcbDecrypt(TdesContext, Input, InputSize, Output); +} + +/** + Performs TDES encryption on a data buffer of the specified size in CBC mode. + + This function performs TDES encryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (8 bytes). + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the TDES encryption output. + + @retval TRUE TDES encryption succeeded. + @retval FALSE TDES encryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +TdesCbcEncrypt ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->TDES_CbcEncrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->TDES_CbcEncrypt(TdesContext, Input, InputSize, Ivec, Output); +} + +/** + Performs TDES decryption on a data buffer of the specified size in CBC mode. + + This function performs TDES decryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (8 bytes). + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the TDES encryption output. + + @retval TRUE TDES decryption succeeded. + @retval FALSE TDES decryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +TdesCbcDecrypt ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->TDES_CbcDecrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->TDES_CbcDecrypt(TdesContext, Input, InputSize, Ivec, Output); +} + +/** + Retrieves the size, in bytes, of the context buffer required for AES operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for AES operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +AesGetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->AES_GetContextSize == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->AES_GetContextSize(); +} + +/** + Initializes user-supplied memory as AES context for subsequent use. + + This function initializes user-supplied memory pointed by AesContext as AES context. + In addition, it sets up all AES key materials for subsequent encryption and decryption + operations. + There are 3 options for key length, 128 bits, 192 bits, and 256 bits. + + If AesContext is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeyLength is not valid, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] AesContext Pointer to AES context being initialized. + @param[in] Key Pointer to the user-supplied AES key. + @param[in] KeyLength Length of AES key in bits. + + @retval TRUE AES context initialization succeeded. + @retval FALSE AES context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AesInit ( + OUT VOID *AesContext, + IN CONST UINT8 *Key, + IN UINTN KeyLength) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->AES_Init == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->AES_Init(AesContext, Key, KeyLength); +} + +/** + Performs AES encryption on a data buffer of the specified size in ECB mode. + + This function performs AES encryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AesEcbEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->AES_EcbEncrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->AES_EcbEncrypt(AesContext, Input, InputSize, Output); +} + +/** + Performs AES decryption on a data buffer of the specified size in ECB mode. + + This function performs AES decryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be decrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AesEcbDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->AES_EcbDecrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->AES_EcbDecrypt(AesContext, Input, InputSize, Output); +} + +/** + Performs AES encryption on a data buffer of the specified size in CBC mode. + + This function performs AES encryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (16 bytes). + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AesCbcEncrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->AES_CbcEncrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->AES_CbcEncrypt(AesContext, Input, InputSize, Ivec, Output); +} + +/** + Performs AES decryption on a data buffer of the specified size in CBC mode. + + This function performs AES decryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (16 bytes). + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AesCbcDecrypt ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->AES_CbcDecrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->AES_CbcDecrypt(AesContext, Input, InputSize, Ivec, Output); +} + +/** + Retrieves the size, in bytes, of the context buffer required for ARC4 operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for ARC4 operations. + @retval 0 This interface is not supported. + +**/ +UINTN +EFIAPI +Arc4GetContextSize ( + VOID) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Update == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return 0; + } + return prot->ARC4_GetContextSize(); +} + +/** + Initializes user-supplied memory as ARC4 context for subsequent use. + + This function initializes user-supplied memory pointed by Arc4Context as ARC4 context. + In addition, it sets up all ARC4 key materials for subsequent encryption and decryption + operations. + + If Arc4Context is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeySize does not in the range of [5, 256] bytes, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Arc4Context Pointer to ARC4 context being initialized. + @param[in] Key Pointer to the user-supplied ARC4 key. + @param[in] KeySize Size of ARC4 key in bytes. + + @retval TRUE ARC4 context initialization succeeded. + @retval FALSE ARC4 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Arc4Init ( + OUT VOID *Arc4Context, + IN CONST UINT8 *Key, + IN UINTN KeySize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->ARC4_Init == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->ARC4_Init(Arc4Context, Key, KeySize); +} + +/** + Performs ARC4 encryption on a data buffer of the specified size. + + This function performs ARC4 encryption on data buffer pointed by Input, of specified + size of InputSize. + Arc4Context should be already correctly initialized by Arc4Init(). Behavior with + invalid ARC4 context is undefined. + + If Arc4Context is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Arc4Context Pointer to the ARC4 context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the ARC4 encryption output. + + @retval TRUE ARC4 encryption succeeded. + @retval FALSE ARC4 encryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Arc4Encrypt ( + IN OUT VOID *Arc4Context, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->ARC4_Encrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->ARC4_Encrypt(Arc4Context, Input, InputSize, Output); +} + +/** + Performs ARC4 decryption on a data buffer of the specified size. + + This function performs ARC4 decryption on data buffer pointed by Input, of specified + size of InputSize. + Arc4Context should be already correctly initialized by Arc4Init(). Behavior with + invalid ARC4 context is undefined. + + If Arc4Context is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Arc4Context Pointer to the ARC4 context. + @param[in] Input Pointer to the buffer containing the data to be decrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the ARC4 decryption output. + + @retval TRUE ARC4 decryption succeeded. + @retval FALSE ARC4 decryption failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Arc4Decrypt ( + IN OUT VOID *Arc4Context, + IN UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->ARC4_Decrypt == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->ARC4_Decrypt(Arc4Context, Input, InputSize, Output); +} + +/** + Resets the ARC4 context to the initial state. + + The function resets the ARC4 context to the state it had immediately after the + ARC4Init() function call. + Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context + should be already correctly initialized by ARC4Init(). + + If Arc4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Arc4Context Pointer to the ARC4 context. + + @retval TRUE ARC4 reset succeeded. + @retval FALSE ARC4 reset failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Arc4Reset ( + IN OUT VOID *Arc4Context +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->ARC4_Reset == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->ARC4_Reset(Arc4Context); +} + +//===================================================================================== +// Asymmetric Cryptography Primitive +//===================================================================================== + +/** + Allocates and initializes one RSA context for subsequent use. + + @return Pointer to the RSA context that has been initialized. + If the allocations fails, RsaNew() returns NULL. + +**/ +VOID * +EFIAPI +RsaNew ( + VOID +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_New == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return NULL; + } + return prot->RSA_New(); +} + +/** + Release the specified RSA context. + + If RsaContext is NULL, then return FALSE. + + @param[in] RsaContext Pointer to the RSA context to be released. + +**/ +VOID +EFIAPI +RsaFree ( + IN VOID *RsaContext +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_Free == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return; + } + + prot->RSA_Free(RsaContext); +} + +/** + Sets the tag-designated key component into the established RSA context. + + This function sets the tag-designated RSA key component into the established + RSA context from the user-specified non-negative integer (octet string format + represented in RSA PKCS#1). + If BigNumber is NULL, then the specified key component in RSA context is cleared. + + If RsaContext is NULL, then return FALSE. + + @param[in, out] RsaContext Pointer to RSA context being set. + @param[in] KeyTag Tag of RSA key component being set. + @param[in] BigNumber Pointer to octet integer buffer. + If NULL, then the specified key component in RSA + context is cleared. + @param[in] BnSize Size of big number buffer in bytes. + If BigNumber is NULL, then it is ignored. + + @retval TRUE RSA key component was set successfully. + @retval FALSE Invalid RSA key component tag. + +**/ +BOOLEAN +EFIAPI +RsaSetKey ( + IN OUT VOID *RsaContext, + IN RSA_KEY_TAG KeyTag, + IN CONST UINT8 *BigNumber, + IN UINTN BnSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_SetKey == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->RSA_SetKey(RsaContext, KeyTag, BigNumber, BnSize); +} + +/** + Gets the tag-designated RSA key component from the established RSA context. + + This function retrieves the tag-designated RSA key component from the + established RSA context as a non-negative integer (octet string format + represented in RSA PKCS#1). + If specified key component has not been set or has been cleared, then returned + BnSize is set to 0. + If the BigNumber buffer is too small to hold the contents of the key, FALSE + is returned and BnSize is set to the required buffer size to obtain the key. + + If RsaContext is NULL, then return FALSE. + If BnSize is NULL, then return FALSE. + If BnSize is large enough but BigNumber is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] RsaContext Pointer to RSA context being set. + @param[in] KeyTag Tag of RSA key component being set. + @param[out] BigNumber Pointer to octet integer buffer. + @param[in, out] BnSize On input, the size of big number buffer in bytes. + On output, the size of data returned in big number buffer in bytes. + + @retval TRUE RSA key component was retrieved successfully. + @retval FALSE Invalid RSA key component tag. + @retval FALSE BnSize is too small. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaGetKey ( + IN OUT VOID *RsaContext, + IN RSA_KEY_TAG KeyTag, + OUT UINT8 *BigNumber, + IN OUT UINTN *BnSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_GetKey == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->RSA_GetKey(RsaContext, KeyTag, BigNumber, BnSize); +} + +/** + Generates RSA key components. + + This function generates RSA key components. It takes RSA public exponent E and + length in bits of RSA modulus N as input, and generates all key components. + If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used. + + Before this function can be invoked, pseudorandom number generator must be correctly + initialized by RandomSeed(). + + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] RsaContext Pointer to RSA context being set. + @param[in] ModulusLength Length of RSA modulus N in bits. + @param[in] PublicExponent Pointer to RSA public exponent. + @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes. + + @retval TRUE RSA key component was generated successfully. + @retval FALSE Invalid RSA key component tag. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaGenerateKey ( + IN OUT VOID *RsaContext, + IN UINTN ModulusLength, + IN CONST UINT8 *PublicExponent, + IN UINTN PublicExponentSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_GenerateKey == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->RSA_GenerateKey(RsaContext, ModulusLength, PublicExponent, PublicExponentSize); +} + +/** + Validates key components of RSA context. + NOTE: This function performs integrity checks on all the RSA key material, so + the RSA key structure must contain all the private key data. + + This function validates key components of RSA context in following aspects: + - Whether p is a prime + - Whether q is a prime + - Whether n = p * q + - Whether d*e = 1 mod lcm(p-1,q-1) + + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] RsaContext Pointer to RSA context to check. + + @retval TRUE RSA key components are valid. + @retval FALSE RSA key components are not valid. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaCheckKey ( + IN VOID *RsaContext) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_CheckKey == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->RSA_CheckKey(RsaContext); +} + +/** + Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme. + + This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in + RSA PKCS#1. + If the Signature buffer is too small to hold the contents of signature, FALSE + is returned and SigSize is set to the required buffer size to obtain the signature. + + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE. + If SigSize is large enough but Signature is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] RsaContext Pointer to RSA context for signature generation. + @param[in] MessageHash Pointer to octet message hash to be signed. + @param[in] HashSize Size of the message hash in bytes. + @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature. + @param[in, out] SigSize On input, the size of Signature buffer in bytes. + On output, the size of data returned in Signature buffer in bytes. + + @retval TRUE Signature successfully generated in PKCS1-v1_5. + @retval FALSE Signature generation failed. + @retval FALSE SigSize is too small. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaPkcs1Sign ( + IN VOID *RsaContext, + IN CONST UINT8 *MessageHash, + IN UINTN HashSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_Pkcs1Sign == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->RSA_Pkcs1Sign(RsaContext, MessageHash, HashSize, Signature, SigSize); +} + +/** + Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in + RSA PKCS#1. + + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE. + + @param[in] RsaContext Pointer to RSA context for signature verification. + @param[in] MessageHash Pointer to octet message hash to be checked. + @param[in] HashSize Size of the message hash in bytes. + @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified. + @param[in] SigSize Size of signature in bytes. + + @retval TRUE Valid signature encoded in PKCS1-v1_5. + @retval FALSE Invalid signature or invalid RSA context. + +**/ +BOOLEAN +EFIAPI +RsaPkcs1Verify ( + IN VOID *RsaContext, + IN CONST UINT8 *MessageHash, + IN UINTN HashSize, + IN CONST UINT8 *Signature, + IN UINTN SigSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + EFI_STATUS Status; + if (prot == NULL || prot->RSA_Pkcs1Verify == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + Status = prot->RSA_Pkcs1Verify(RsaContext, MessageHash, HashSize, Signature, SigSize); + if (EFI_ERROR(Status)) + return FALSE; + return TRUE; +} + +/** + Retrieve the RSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA private key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaGetPrivateKeyFromPem ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **RsaContext) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RSA_GetPrivateKeyFromPem == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->RSA_GetPrivateKeyFromPem(PemData, PemSize, Password, RsaContext); +} + +/** + Retrieve the RSA Public Key from one DER-encoded X509 certificate. + + If Cert is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA public key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve RSA public key from X509 certificate. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RsaGetPublicKeyFromX509 ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **RsaContext) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + EFI_STATUS Status; + if (prot == NULL || prot->RSA_GetPublicKeyFromX509 == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + Status = prot->RSA_GetPublicKeyFromX509(Cert, CertSize, RsaContext); + if (EFI_ERROR(Status)) + return FALSE; + return TRUE; +} + +/** + Retrieve the subject bytes from one X.509 certificate. + + If Cert is NULL, then return FALSE. + If SubjectSize is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] CertSubject Pointer to the retrieved certificate subject bytes. + @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input, + and the size of buffer returned CertSubject on output. + + @retval TRUE The certificate subject retrieved successfully. + @retval FALSE Invalid certificate, or the SubjectSize is too small for the result. + The SubjectSize will be updated with the required size. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509GetSubjectName ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 *CertSubject, + IN OUT UINTN *SubjectSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + EFI_STATUS Status; + if (prot == NULL || prot->X509_GET_SUBJECT_NAME == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + Status = prot->X509_GET_SUBJECT_NAME(Cert, CertSize, CertSubject, SubjectSize); + if (EFI_ERROR(Status)) + return FALSE; + return TRUE; +} + +/** + Retrieve the common name (CN) string from one X.509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] CommonName Buffer to contain the retrieved certificate common + name string (UTF8). At most CommonNameSize bytes will be + written and the string will be null terminated. May be + NULL in order to determine the size buffer needed. + @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input, + and the size of buffer returned CommonName on output. + If CommonName is NULL then the amount of space needed + in buffer (including the final null) is returned. + + @retval RETURN_SUCCESS The certificate CommonName retrieved successfully. + @retval RETURN_INVALID_PARAMETER If Cert is NULL. + If CommonNameSize is NULL. + If CommonName is not NULL and *CommonNameSize is 0. + If Certificate is invalid. + @retval RETURN_NOT_FOUND If no CommonName entry exists. + @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size + (including the final null) is returned in the + CommonNameSize parameter. + @retval RETURN_UNSUPPORTED The operation is not supported. + +**/ +RETURN_STATUS +EFIAPI +X509GetCommonName ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT CHAR8 *CommonName, + OPTIONAL IN OUT UINTN *CommonNameSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->X509_GET_COMMON_NAME == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return EFI_PROTOCOL_UNREACHABLE; + } + + return prot->X509_GET_COMMON_NAME(Cert, CertSize, CommonName, CommonNameSize); +} + +// MSCHANGE [Begin] +/** + Retrieve the organization name (O) string from one X.509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] NameBuffer Buffer to contain the retrieved certificate organization + name string. At most NameBufferSize bytes will be + written and the string will be null terminated. May be + NULL in order to determine the size buffer needed. + @param[in,out] NameBufferSiz e The size in bytes of the Name buffer on input, + and the size of buffer returned Name on output. + If NameBuffer is NULL then the amount of space needed + in buffer (including the final null) is returned. + + @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully. + @retval RETURN_INVALID_PARAMETER If Cert is NULL. + If NameBufferSize is NULL. + If NameBuffer is not NULL and *CommonNameSize is 0. + If Certificate is invalid. + @retval RETURN_NOT_FOUND If no Organization Name entry exists. + @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size + (including the final null) is returned in the + CommonNameSize parameter. + @retval RETURN_UNSUPPORTED The operation is not supported. + +**/ +RETURN_STATUS +EFIAPI +X509GetOrganizationName ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT CHAR8 *NameBuffer, + OPTIONAL IN OUT UINTN *NameBufferSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->X509_GET_ORGANIZATION_NAME == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return EFI_PROTOCOL_UNREACHABLE; + } + + return prot->X509_GET_ORGANIZATION_NAME(Cert, CertSize, NameBuffer, NameBufferSize); +} + +/** + Verify one X509 certificate was issued by the trusted CA. + + If Cert is NULL, then return FALSE. + If CACert is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[in] CACert Pointer to the DER-encoded trusted CA certificate. + @param[in] CACertSize Size of the CA Certificate in bytes. + + @retval TRUE The certificate was issued by the trusted CA. + @retval FALSE Invalid certificate or the certificate was not issued by the given + trusted CA. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509VerifyCert ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + IN CONST UINT8 *CACert, + IN UINTN CACertSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Update == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->X509_VerifyCert(Cert, CertSize, CACert, CACertSize); +} + +/** + Construct a X509 object from DER-encoded certificate data. + + If Cert is NULL, then return FALSE. + If SingleX509Cert is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded certificate data. + @param[in] CertSize The size of certificate data in bytes. + @param[out] SingleX509Cert The generated X509 object. + + @retval TRUE The X509 object generation succeeded. + @retval FALSE The operation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509ConstructCertificate ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 **SingleX509Cert) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->X509_ConstructCertificate == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->X509_ConstructCertificate(Cert, CertSize, SingleX509Cert); +} + +/** + Construct a X509 stack object from a list of DER-encoded certificate data. + + If X509Stack is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object. + On output, pointer to the X509 stack object with new + inserted X509 certificate. + @param ... A list of DER-encoded single certificate data followed + by certificate size. A NULL terminates the list. The + pairs are the arguments to X509ConstructCertificate(). + + @retval TRUE The X509 stack construction succeeded. + @retval FALSE The construction operation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +X509ConstructCertificateStack ( + IN OUT UINT8 **X509Stack, + ...) +{ + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + /* + //This function doesn't work because we don't have a good way to pass the VA_LIST without a function that takes it directly + //https://stackoverflow.com/questions/150543/forward-an-invocation-of-a-variadic-function-in-c + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); //FIX + VA_LIST args; + va_start(args, X509Stack); + if (prot == NULL || prot->X509_ConstructCertificateStack == NULL) { + + return FALSE; + } + return prot->X509_ConstructCertificateStack(X509Stack, args); + */ +} + +/** + Release the specified X509 object. + + If the interface is not supported, then ASSERT(). + + @param[in] X509Cert Pointer to the X509 object to be released. + +**/ +VOID +EFIAPI +X509Free ( + IN VOID *X509Cert +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->X509_Free == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return; + } + prot->X509_Free(X509Cert); +} + +/** + Release the specified X509 stack object. + + If the interface is not supported, then ASSERT(). + + @param[in] X509Stack Pointer to the X509 stack object to be released. + +**/ +VOID +EFIAPI +X509StackFree ( + IN VOID *X509Stack + ) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->X509_StackFree == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + } + prot->X509_StackFree(X509Stack); +} + +/** + Retrieve the TBSCertificate from one given X.509 certificate. + + @param[in] Cert Pointer to the given DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] TBSCert DER-Encoded To-Be-Signed certificate. + @param[out] TBSCertSize Size of the TBS certificate in bytes. + + If Cert is NULL, then return FALSE. + If TBSCert is NULL, then return FALSE. + If TBSCertSize is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @retval TRUE The TBSCertificate was retrieved successfully. + @retval FALSE Invalid X.509 certificate. + +**/ +BOOLEAN +EFIAPI +X509GetTBSCert ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 **TBSCert, + OUT UINTN *TBSCertSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->X509_GetTBSCert == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->X509_GetTBSCert(Cert, CertSize, TBSCert, TBSCertSize); +} + +/** + Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0 + password based encryption key derivation function PBKDF2, as specified in RFC 2898. + + If Password or Salt or OutKey is NULL, then return FALSE. + If the hash algorithm could not be determined, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] PasswordLength Length of input password in bytes. + @param[in] Password Pointer to the array for the password. + @param[in] SaltLength Size of the Salt in bytes. + @param[in] Salt Pointer to the Salt. + @param[in] IterationCount Number of iterations to perform. Its value should be + greater than or equal to 1. + @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE). + NOTE: DigestSize will be used to determine the hash algorithm. + Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported. + @param[in] KeyLength Size of the derived key buffer in bytes. + @param[out] OutKey Pointer to the output derived key buffer. + + @retval TRUE A key was derived successfully. + @retval FALSE One of the pointers was NULL or one of the sizes was too large. + @retval FALSE The hash algorithm could not be determined from the digest size. + @retval FALSE The key derivation operation failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Pkcs5HashPassword ( + IN UINTN PasswordLength, + IN CONST CHAR8 *Password, + IN UINTN SaltLength, + IN CONST UINT8 *Salt, + IN UINTN IterationCount, + IN UINTN DigestSize, + IN UINTN KeyLength, + OUT UINT8 *OutKey) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + EFI_STATUS Status; + if (prot == NULL || prot->PKCS5_PW_HASH == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + Status = prot->PKCS5_PW_HASH(PasswordLength, Password, SaltLength, Salt, IterationCount, DigestSize, KeyLength, OutKey); + if (EFI_ERROR(Status)) + return FALSE; + return TRUE; +} + +// MSChange [BEGIN] - Add a wrapper function for the PKCS1v2 RSAES-OAEP PKI encryption +// functionality provided by OpenSSL. +/** + Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the encrypted message in + in a newly allocated buffer. + + Things that can cause a failure include: + - X509 key size does not match any known key size. + - Fail to parse X509 certificate. + - Fail to allocate an intermediate buffer. + - NULL pointer provided for a non-optional parameter. + - Data size is too large for the provided key size (max size is a function of key size and hash digest size). + + @param[in] PublicKey A pointer to the DER-encoded X509 certificate that will be used to encrypt the data. + @param[in] PublicKeySize Size of the X509 cert buffer. + @param[in] InData Data to be encrypted. + @param[in] InDataSize Size of the data buffer. + @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer to be used when initializing the PRNG. NULL otherwise. + @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer. 0 otherwise. + @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted message. + @param[out] EncryptedDataSize Size of the encrypted message buffer. + + @retval TRUE Encryption was successful. + @retval FALSE Encryption failed. + +**/ +BOOLEAN +Pkcs1v2Encrypt ( + IN CONST UINT8 *PublicKey, + IN UINTN PublicKeySize, + IN UINT8 *InData, + IN UINTN InDataSize, + IN CONST UINT8 *PrngSeed OPTIONAL, + IN UINTN PrngSeedSize OPTIONAL, + OUT UINT8 **EncryptedData, + OUT UINTN *EncryptedDataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS1_ENCRYPT_V2 == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->PKCS1_ENCRYPT_V2(PublicKey, PublicKeySize, InData, InDataSize, PrngSeed, PrngSeedSize, EncryptedData, EncryptedDataSize); +} + +/** + Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard". The input signed data could be wrapped + in a ContentInfo structure. + + If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then + return FALSE. If P7Length overflow, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] P7Data Pointer to the PKCS#7 message to verify. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data. + It's caller's responsibility to free the buffer with + Pkcs7FreeSigners(). + This data structure is EFI_CERT_STACK type. + @param[out] StackLength Length of signer's certificates in bytes. + @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates. + It's caller's responsibility to free the buffer with + Pkcs7FreeSigners(). + @param[out] CertLength Length of the trusted certificate in bytes. + + @retval TRUE The operation is finished successfully. + @retval FALSE Error occurs during the operation. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Pkcs7GetSigners ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT UINT8 **CertStack, + OUT UINTN *StackLength, + OUT UINT8 **TrustedCert, + OUT UINTN *CertLength) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_GetSigners == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->PKCS7_GetSigners(P7Data, P7Length, CertStack, StackLength, TrustedCert, CertLength); +} + +/** + Wrap function to use free() to free allocated memory for certificates. + + If this interface is not supported, then ASSERT(). + + @param[in] Certs Pointer to the certificates to be freed. + +**/ +VOID +EFIAPI +Pkcs7FreeSigners ( + IN UINT8 *Certs +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_FreeSigners == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + } + prot->PKCS7_FreeSigners(Certs); +} + +/** + Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard", and outputs two certificate lists chained and + unchained to the signer's certificates. + The input signed data could be wrapped in a ContentInfo structure. + + @param[in] P7Data Pointer to the PKCS#7 message. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[out] SignerChainCerts Pointer to the certificates list chained to signer's + certificate. It's caller's responsibility to free the buffer + with Pkcs7FreeSigners(). + This data structure is EFI_CERT_STACK type. + @param[out] ChainLength Length of the chained certificates list buffer in bytes. + @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's + responsibility to free the buffer with Pkcs7FreeSigners(). + This data structure is EFI_CERT_STACK type. + @param[out] UnchainLength Length of the unchained certificates list buffer in bytes. + + @retval TRUE The operation is finished successfully. + @retval FALSE Error occurs during the operation. + +**/ +BOOLEAN +EFIAPI +Pkcs7GetCertificatesList ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT UINT8 **SignerChainCerts, + OUT UINTN *ChainLength, + OUT UINT8 **UnchainCerts, + OUT UINTN *UnchainLength) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_GetCertificatesList == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->PKCS7_GetCertificatesList(P7Data, P7Length, SignerChainCerts, ChainLength, UnchainCerts, UnchainLength); +} + +/** + Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message + Syntax Standard, version 1.5". This interface is only intended to be used for + application to perform PKCS#7 functionality validation. + + If this interface is not supported, then return FALSE. + + @param[in] PrivateKey Pointer to the PEM-formatted private key data for + data signing. + @param[in] PrivateKeySize Size of the PEM private key data in bytes. + @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM + key data. + @param[in] InData Pointer to the content to be signed. + @param[in] InDataSize Size of InData in bytes. + @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with. + @param[in] OtherCerts Pointer to an optional additional set of certificates to + include in the PKCS#7 signedData (e.g. any intermediate + CAs in the chain). + @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's + responsibility to free the buffer with FreePool(). + @param[out] SignedDataSize Size of SignedData in bytes. + + @retval TRUE PKCS#7 data signing succeeded. + @retval FALSE PKCS#7 data signing failed. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Pkcs7Sign ( + IN CONST UINT8 *PrivateKey, + IN UINTN PrivateKeySize, + IN CONST UINT8 *KeyPassword, + IN UINT8 *InData, + IN UINTN InDataSize, + IN UINT8 *SignCert, + IN UINT8 *OtherCerts OPTIONAL, + OUT UINT8 **SignedData, + OUT UINTN *SignedDataSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_Sign == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->PKCS7_Sign(PrivateKey, PrivateKeySize, KeyPassword, InData, InDataSize, SignCert, OtherCerts, SignedData, SignedDataSize); +} + +/** + Verifies the validity of a PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard". The input signed data could be wrapped + in a ContentInfo structure. + + If P7Data, TrustedCert or InData is NULL, then return FALSE. + If P7Length, CertLength or DataLength overflow, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] P7Data Pointer to the PKCS#7 message to verify. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which + is used for certificate chain verification. + @param[in] CertLength Length of the trusted certificate in bytes. + @param[in] InData Pointer to the content to be verified. + @param[in] DataLength Length of InData in bytes. + + @retval TRUE The specified PKCS#7 signed data is valid. + @retval FALSE Invalid PKCS#7 signed data. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +Pkcs7Verify ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + IN CONST UINT8 *TrustedCert, + IN UINTN CertLength, + IN CONST UINT8 *InData, + IN UINTN DataLength) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_VERIFY == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->PKCS7_VERIFY(P7Data, P7Length, TrustedCert, CertLength, InData, DataLength); +} + +// MS_CHANGE [BEGIN] - Add a function that will verify Extended Key Usages +// are present in the end-entity (leaf) signer certificate +// in a PKCS7 formatted signature. + +/** + VerifyEKUsInPkcs7Signature() + + This function receives a PKCS7 formatted signature, and then verifies that + the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity + leaf signing certificate. + + Note that this function does not validate the certificate chain. + + Applications for custom EKU's are quite flexible. For example, a policy EKU + may be present in an Issuing Certificate Authority (CA), and any sub-ordinate + certificate issued might also contain this EKU, thus constraining the + sub-ordinate certificate. Other applications might allow a certificate + embedded in a device to specify that other Object Identifiers (OIDs) are + present which contains binary data specifying custom capabilities that + the device is able to do. + + @param[in] Pkcs7Signature - The PKCS#7 signed information content block. An array + containing the content block with both the signature, + the signer's certificate, and any necessary intermediate + certificates. + + @param[in] Pkcs7SignatureSize - Number of bytes in Pkcs7Signature. + + @param[in] RequiredEKUs - Array of null-terminated strings listing OIDs of + required EKUs that must be present in the signature. + + @param[in] RequiredEKUsSize - Number of elements in the RequiredEKUs string array. + + @param[in] RequireAllPresent - If this is TRUE, then all of the specified EKU's + must be present in the leaf signer. If it is + FALSE, then we will succeed if we find any + of the specified EKU's. + + @retval EFI_SUCCESS - The required EKUs were found in the signature. + @retval EFI_INVALID_PARAMETER - A parameter was invalid. + @retval EFI_NOT_FOUND - One or more EKU's were not found in the signature. + +**/ +EFI_STATUS +EFIAPI +VerifyEKUsInPkcs7Signature ( + IN CONST UINT8 *Pkcs7Signature, + IN CONST UINT32 SignatureSize, + IN CONST CHAR8 *RequiredEKUs[], + IN CONST UINT32 RequiredEKUsSize, + IN BOOLEAN RequireAllPresent) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_VERIFY_EKU == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->PKCS7_VERIFY_EKU(Pkcs7Signature, SignatureSize, RequiredEKUs, RequiredEKUsSize, RequireAllPresent); +} + +// MS_CHANGE [END] + +/** + Extracts the attached content from a PKCS#7 signed data if existed. The input signed + data could be wrapped in a ContentInfo structure. + + If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow, + then return FALSE. If the P7Data is not correctly formatted, then return FALSE. + + Caution: This function may receive untrusted input. So this function will do + basic check for PKCS#7 data structure. + + @param[in] P7Data Pointer to the PKCS#7 signed data to process. + @param[in] P7Length Length of the PKCS#7 signed data in bytes. + @param[out] Content Pointer to the extracted content from the PKCS#7 signedData. + It's caller's responsibility to free the buffer with FreePool(). + @param[out] ContentSize The size of the extracted content in bytes. + + @retval TRUE The P7Data was correctly formatted for processing. + @retval FALSE The P7Data was not correctly formatted for processing. + +**/ +BOOLEAN +EFIAPI +Pkcs7GetAttachedContent ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT VOID **Content, + OUT UINTN *ContentSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->PKCS7_GetAttachedContent == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->PKCS7_GetAttachedContent(P7Data, P7Length, Content, ContentSize); +} + +/** + Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows + Authenticode Portable Executable Signature Format". + + If AuthData is NULL, then return FALSE. + If ImageHash is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed + PE/COFF image to be verified. + @param[in] DataSize Size of the Authenticode Signature in bytes. + @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which + is used for certificate chain verification. + @param[in] CertSize Size of the trusted certificate in bytes. + @param[in] ImageHash Pointer to the original image file hash value. The procedure + for calculating the image hash value is described in Authenticode + specification. + @param[in] HashSize Size of Image hash value in bytes. + + @retval TRUE The specified Authenticode Signature is valid. + @retval FALSE Invalid Authenticode Signature. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +AuthenticodeVerify ( + IN CONST UINT8 *AuthData, + IN UINTN DataSize, + IN CONST UINT8 *TrustedCert, + IN UINTN CertSize, + IN CONST UINT8 *ImageHash, + IN UINTN HashSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->Authenticode_Verify == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->Authenticode_Verify(AuthData, DataSize, TrustedCert, CertSize, ImageHash, HashSize); +} + +/** + Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode + signature. + + If AuthData is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed + PE/COFF image to be verified. + @param[in] DataSize Size of the Authenticode Signature in bytes. + @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which + is used for TSA certificate chain verification. + @param[in] CertSize Size of the trusted certificate in bytes. + @param[out] SigningTime Return the time of timestamp generation time if the timestamp + signature is valid. + + @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature. + @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data. + +**/ +BOOLEAN +EFIAPI +ImageTimestampVerify ( + IN CONST UINT8 *AuthData, + IN UINTN DataSize, + IN CONST UINT8 *TsaCert, + IN UINTN CertSize, + OUT EFI_TIME *SigningTime) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->MD4_Update == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->Image_TimestampVerify(AuthData, DataSize, TsaCert, CertSize, SigningTime); +} + +//===================================================================================== +// DH Key Exchange Primitive +//===================================================================================== + +/** + Allocates and Initializes one Diffie-Hellman Context for subsequent use. + + @return Pointer to the Diffie-Hellman Context that has been initialized. + If the allocations fails, DhNew() returns NULL. + If the interface is not supported, DhNew() returns NULL. + +**/ +VOID * +EFIAPI +DhNew ( + VOID +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->DH_New == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return NULL; + } + return prot->DH_New(); +} + +/** + Release the specified DH context. + + If the interface is not supported, then ASSERT(). + + @param[in] DhContext Pointer to the DH context to be released. + +**/ +VOID +EFIAPI +DhFree ( + IN VOID *DhContext +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->DH_Free == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + } + prot->DH_Free(DhContext); +} + +/** + Generates DH parameter. + + Given generator g, and length of prime number p in bits, this function generates p, + and sets DH context according to value of g and p. + + Before this function can be invoked, pseudorandom number generator must be correctly + initialized by RandomSeed(). + + If DhContext is NULL, then return FALSE. + If Prime is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[in] Generator Value of generator. + @param[in] PrimeLength Length in bits of prime to be generated. + @param[out] Prime Pointer to the buffer to receive the generated prime number. + + @retval TRUE DH parameter generation succeeded. + @retval FALSE Value of Generator is not supported. + @retval FALSE PRNG fails to generate random prime number with PrimeLength. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +DhGenerateParameter ( + IN OUT VOID *DhContext, + IN UINTN Generator, + IN UINTN PrimeLength, + OUT UINT8 *Prime) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->DH_GenerateParameter == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->DH_GenerateParameter(DhContext, Generator, PrimeLength, Prime); +} + +/** + Sets generator and prime parameters for DH. + + Given generator g, and prime number p, this function and sets DH + context accordingly. + + If DhContext is NULL, then return FALSE. + If Prime is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[in] Generator Value of generator. + @param[in] PrimeLength Length in bits of prime to be generated. + @param[in] Prime Pointer to the prime number. + + @retval TRUE DH parameter setting succeeded. + @retval FALSE Value of Generator is not supported. + @retval FALSE Value of Generator is not suitable for the Prime. + @retval FALSE Value of Prime is not a prime number. + @retval FALSE Value of Prime is not a safe prime number. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +DhSetParameter ( + IN OUT VOID *DhContext, + IN UINTN Generator, + IN UINTN PrimeLength, + IN CONST UINT8 *Prime +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->DH_SetParameter == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->DH_SetParameter(DhContext, Generator, PrimeLength, Prime); +} + +/** + Generates DH public key. + + This function generates random secret exponent, and computes the public key, which is + returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly. + If the PublicKey buffer is too small to hold the public key, FALSE is returned and + PublicKeySize is set to the required buffer size to obtain the public key. + + If DhContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If PublicKeySize is large enough but PublicKey is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[out] PublicKey Pointer to the buffer to receive generated public key. + @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes. + On output, the size of data returned in PublicKey buffer in bytes. + + @retval TRUE DH public key generation succeeded. + @retval FALSE DH public key generation failed. + @retval FALSE PublicKeySize is not large enough. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +DhGenerateKey ( + IN OUT VOID *DhContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize +) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->DH_GenerateKey == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->DH_GenerateKey(DhContext, PublicKey, PublicKeySize); +} + +/** + Computes exchanged common key. + + Given peer's public key, this function computes the exchanged common key, based on its own + context including value of prime modulus and random secret exponent. + + If DhContext is NULL, then return FALSE. + If PeerPublicKey is NULL, then return FALSE. + If KeySize is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeySize is not large enough, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[in] PeerPublicKey Pointer to the peer's public key. + @param[in] PeerPublicKeySize Size of peer's public key in bytes. + @param[out] Key Pointer to the buffer to receive generated key. + @param[in, out] KeySize On input, the size of Key buffer in bytes. + On output, the size of data returned in Key buffer in bytes. + + @retval TRUE DH exchanged key generation succeeded. + @retval FALSE DH exchanged key generation failed. + @retval FALSE KeySize is not large enough. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +DhComputeKey ( + IN OUT VOID *DhContext, + IN CONST UINT8 *PeerPublicKey, + IN UINTN PeerPublicKeySize, + OUT UINT8 *Key, + IN OUT UINTN *KeySize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->DH_ComputeKey == NULL) { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + return prot->DH_ComputeKey(DhContext, PeerPublicKey, PeerPublicKeySize, Key, KeySize); +} + +//===================================================================================== +// Pseudo-Random Generation Primitive +//===================================================================================== + +/** + Sets up the seed value for the pseudorandom number generator. + + This function sets up the seed value for the pseudorandom number generator. + If Seed is not NULL, then the seed passed in is used. + If Seed is NULL, then default seed is used. + If this interface is not supported, then return FALSE. + + @param[in] Seed Pointer to seed value. + If NULL, default seed is used. + @param[in] SeedSize Size of seed value. + If Seed is NULL, this parameter is ignored. + + @retval TRUE Pseudorandom number generator has enough entropy for random generation. + @retval FALSE Pseudorandom number generator does not have enough entropy for random generation. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RandomSeed ( + IN CONST UINT8 *Seed OPTIONAL, + IN UINTN SeedSize) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RANDOM_Seed == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->RANDOM_Seed(Seed, SeedSize); +} + +/** + Generates a pseudorandom byte stream of the specified size. + + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Output Pointer to buffer to receive random value. + @param[in] Size Size of random bytes to generate. + + @retval TRUE Pseudorandom byte stream generated successfully. + @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy. + @retval FALSE This interface is not supported. + +**/ +BOOLEAN +EFIAPI +RandomBytes ( + OUT UINT8 *Output, + IN UINTN Size) +{ + SHARED_CRYPTO_FUNCTIONS *prot = GetProtocol(); + if (prot == NULL || prot->RANDOM_Bytes == NULL) + { + ProtocolFunctionNotFound(__FUNCTION__); + return FALSE; + } + + return prot->RANDOM_Bytes(Output, Size); +} \ No newline at end of file diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/Common/SharedCryptoHelpers.h b/SharedCryptoPkg/Library/CryptLibSharedDriver/Common/SharedCryptoHelpers.h new file mode 100644 index 0000000000..8ab5598eba --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/Common/SharedCryptoHelpers.h @@ -0,0 +1,46 @@ +/** @file + Device Boot Manager library definition. A device can implement + instances to support device specific behavior. + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#ifndef __CRYPTO_BIN_LIB_HELPERS_H_ +#define __CRYPTO_BIN_LIB_HELPERS_H_ + + +#include + +SHARED_CRYPTO_FUNCTIONS* GetProtocol(); + +// Called when the protocol cannot be found +VOID ProtocolNotFound ( + EFI_STATUS Status +); + +//Called when a particular function cannot be called +VOID ProtocolFunctionNotFound(CHAR8*); + + +#endif \ No newline at end of file diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.c b/SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.c new file mode 100644 index 0000000000..61c41aa5f4 --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.c @@ -0,0 +1,74 @@ +/** @file +SharedCryptoLibDxe.c + +The version of the SharedCrypto wrapper Library for DXE + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include +#include +#include +#include + +SHARED_CRYPTO_PROTOCOL* pCryptoProtocol = NULL; + +SHARED_CRYPTO_FUNCTIONS* GetProtocol () +{ + EFI_STATUS Status; + UINTN Version; + if (pCryptoProtocol == NULL) + { + Status = gBS->LocateProtocol(&gSharedCryptoProtocolGuid, NULL, (VOID **)&pCryptoProtocol); + if (EFI_ERROR(Status)) + { + ProtocolNotFound(Status); + } + else { + Version = pCryptoProtocol->SharedCrypto_GetLowestSupportedVersion(); + if (Version != SHARED_CRYPTO_VERSION) + { + ProtocolNotFound(EFI_PROTOCOL_ERROR); + } + } + } + return pCryptoProtocol; +} +VOID ProtocolNotFound ( + EFI_STATUS Status +) +{ + DEBUG((DEBUG_ERROR, "[SharedCryptoLibrary_DXE] Failed to locate Support Protocol. Status = %r\n", Status)); + ASSERT_EFI_ERROR(Status); + pCryptoProtocol = NULL; +} + +VOID ProtocolFunctionNotFound (CHAR8* function_name) +{ + DEBUG((DEBUG_ERROR, "[SharedCryptoLibrary_DXE] This function was not found: %a\n",function_name)); + ASSERT_EFI_ERROR(EFI_UNSUPPORTED); +} \ No newline at end of file diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.inf b/SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.inf new file mode 100644 index 0000000000..aa104d8d34 --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.inf @@ -0,0 +1,60 @@ +## @file +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = DxeSharedCryptoLib + FILE_GUID = B38CBDA6-8017-4111-8232-9E8328DE82F6 + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_DRIVER + LIBRARY_CLASS = BaseCryptLib | DXE_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[LibraryClasses] + DebugLib + BaseLib + UefiBootServicesTableLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + CryptoPkg/CryptoPkg.dec + +[Sources] + DxeCryptLibSharedDriver.c + Common/CommonSharedCryptoLib.c + Common/SharedCryptoHelpers.h + +[Protocols] + gSharedCryptoProtocolGuid ## consumes + +[Depex] + gSharedCryptoProtocolGuid ## depends on this protocol diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.c b/SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.c new file mode 100644 index 0000000000..b75863ea10 --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.c @@ -0,0 +1,80 @@ +/** @file +SharedCryptoLibPei.c + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include +#include +#include +#include +#include + +SHARED_CRYPTO_FUNCTIONS *GetProtocol() +{ + EFI_STATUS Status; + UINTN Version; + SHARED_CRYPTO_PPI *pCryptoProt = NULL; + if (pCryptoProt == NULL) + { + Status = PeiServicesLocatePpi( + &gSharedCryptoPpiGuid, + 0, + NULL, + (VOID **)&pCryptoProt); + if (EFI_ERROR(Status)) + { + ProtocolNotFound(Status); + pCryptoProt = NULL; + } + else { + Version = pCryptoProt->SharedCrypto_GetLowestSupportedVersion(); + if (Version != SHARED_CRYPTO_VERSION) + { + ProtocolNotFound(EFI_PROTOCOL_ERROR); + pCryptoProt = NULL; + } + + } + } + + return pCryptoProt; +} + +VOID ProtocolNotFound ( + EFI_STATUS Status +) +{ + DEBUG((DEBUG_ERROR, "[SharedCryptoLibrary_PEI] Failed to locate Crypto Support Protocol. Status = %r\n", Status)); + ASSERT_EFI_ERROR(Status); +} + +VOID ProtocolFunctionNotFound (CHAR8* function_name) +{ + DEBUG((DEBUG_ERROR, "[SharedCryptoLibrary_PEI] This function was not found: %a\n",function_name)); + ASSERT_EFI_ERROR(EFI_UNSUPPORTED); +} diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.inf b/SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.inf new file mode 100644 index 0000000000..4aafd2ce8e --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.inf @@ -0,0 +1,62 @@ +## @file +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = PeiSharedCryptoLib + FILE_GUID = 3E8B50C6-F68C-4212-B903-94A10FE02399 + VERSION_STRING = 1.0 + MODULE_TYPE = PEIM + LIBRARY_CLASS = BaseCryptLib | PEIM +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[LibraryClasses] + DebugLib + BaseLib + PeimEntryPoint + PeiServicesTablePointerLib + PeiServicesLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + CryptoPkg/CryptoPkg.dec + +[Sources] + PeiCryptLibSharedDriver.c + Common/CommonSharedCryptoLib.c + Common/SharedCryptoHelpers.h + +[Ppis] + gSharedCryptoPpiGuid ## consumes + +[Depex] + gSharedCryptoPpiGuid ## Everything is riding on this PPI. diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.c b/SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.c new file mode 100644 index 0000000000..cb47c9f2e6 --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.c @@ -0,0 +1,71 @@ +/** @file +SharedCryptoLibSmm.c + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ +#include +#include +#include +#include "Common/SharedCryptoHelpers.h" +#include + +SHARED_CRYPTO_PROTOCOL* pCryptoProtocol = NULL; + +SHARED_CRYPTO_FUNCTIONS *GetProtocol() +{ + EFI_STATUS Status; + UINTN Version; + if (pCryptoProtocol == NULL) + { + Status = gSmst->SmmLocateProtocol(&gSharedCryptoSmmProtocolGuid, NULL, (VOID **)&pCryptoProtocol); + if (EFI_ERROR(Status)) + { + ProtocolNotFound(Status); + } + else { + Version = pCryptoProtocol->SharedCrypto_GetLowestSupportedVersion(); + if (Version != SHARED_CRYPTO_VERSION) + { + ProtocolNotFound(EFI_PROTOCOL_ERROR); + } + } + } + return pCryptoProtocol; +} + +VOID ProtocolNotFound ( + EFI_STATUS Status +) +{ + DEBUG((DEBUG_ERROR, "[SharedCryptoLibrary_SMM] Failed to locate Support Protocol. Status = %r\n", Status)); + ASSERT_EFI_ERROR(Status); + pCryptoProtocol = NULL; +} +VOID ProtocolFunctionNotFound (CHAR8* function_name) +{ + DEBUG((DEBUG_ERROR, "[SharedCryptoLibrary_SMM] This function was not found: %a\n",function_name)); + ASSERT_EFI_ERROR(EFI_UNSUPPORTED); +} \ No newline at end of file diff --git a/SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.inf b/SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.inf new file mode 100644 index 0000000000..18f4a91ecc --- /dev/null +++ b/SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.inf @@ -0,0 +1,60 @@ +## @file +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = SmmSharedCryptoLib + FILE_GUID = 5CC6ECC9-E961-46A9-8D5C-6581A060DC0D + VERSION_STRING = 1.0 + MODULE_TYPE = DXE_SMM_DRIVER + LIBRARY_CLASS = BaseCryptLib | DXE_SMM_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +[LibraryClasses] + DebugLib + BaseLib + SmmServicesTableLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + SharedCryptoPkg/SharedCryptoPkg.dec + CryptoPkg/CryptoPkg.dec + +[Sources] + SmmCryptLibSharedDriver.c + Common/CommonSharedCryptoLib.c + Common/SharedCryptoHelpers.h + +[Protocols] + gSharedCryptoSmmProtocolGuid ## consumes + +[Depex] + gSharedCryptoSmmProtocolGuid diff --git a/SharedCryptoPkg/Package/SharedCryptoPkgDxe.inf b/SharedCryptoPkg/Package/SharedCryptoPkgDxe.inf new file mode 100644 index 0000000000..18ba5db102 --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCryptoPkgDxe.inf @@ -0,0 +1,64 @@ +## @file +# Crypto Bin Driver package +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SharedCryptoDriverDxe + FILE_GUID = BDFC3C26-73AF-4A14-B861-1B6922EE0C46 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoDxeEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +# these binaries are resolved by the Nuget Package +# if they are not found, check there + +[Binaries] + DXE_DEPEX|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoDxe.depex|DEBUG + DXE_DEPEX|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoDxe.depex|RELEASE + +[Binaries.X64] + PE32|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoDxe.efi|DEBUG + PE32|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoDxe.efi|RELEASE + +[Binaries.ARM] + PE32|Mu-SharedCrypto_extdep/DEBUG/Arm/SharedCryptoDxe.efi|DEBUG + PE32|Mu-SharedCrypto_extdep/RELEASE/Arm/SharedCryptoDxe.efi|RELEASE + +[Binaries.AArch64] + PE32|Mu-SharedCrypto_extdep/DEBUG/AArch64/SharedCryptoDxe.efi|DEBUG + PE32|Mu-SharedCrypto_extdep/RELEASE/AArch64/SharedCryptoDxe.efi|RELEASE + +[Packages] + SharedCryptoPkg/SharedCryptoPkg.dec + +[Depex] + TRUE \ No newline at end of file diff --git a/SharedCryptoPkg/Package/SharedCryptoPkgDxeMu.inf b/SharedCryptoPkg/Package/SharedCryptoPkgDxeMu.inf new file mode 100644 index 0000000000..26530b03ca --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCryptoPkgDxeMu.inf @@ -0,0 +1,64 @@ +## @file +# Crypto Bin Driver package +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION = 0x0001001B + BASE_NAME = SharedCryptoDriverDxeMu + FILE_GUID = 5550445C-7B09-4D69-8198-7060F9C1C732 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoDxeEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +# these binaries are resolved by the Nuget Package +# if they are not found, check there + +[Binaries] + DXE_DEPEX|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoDxeMu.depex|DEBUG + DXE_DEPEX|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoDxeMu.depex|RELEASE + +[Binaries.X64] + PE32|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoDxeMu.efi|DEBUG + PE32|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoDxeMu.efi|RELEASE + +[Binaries.ARM] + PE32|Mu-SharedCrypto_extdep/DEBUG/Arm/SharedCryptoDxeMu.efi|DEBUG + PE32|Mu-SharedCrypto_extdep/RELEASE/Arm/SharedCryptoDxeMu.efi|RELEASE + +[Binaries.AArch64] + PE32|Mu-SharedCrypto_extdep/DEBUG/AArch64/SharedCryptoDxeMu.efi|DEBUG + PE32|Mu-SharedCrypto_extdep/RELEASE/AArch64/SharedCryptoDxeMu.efi|RELEASE + +[Packages] + SharedCryptoPkg/SharedCryptoPkg.dec + +[Depex] + TRUE \ No newline at end of file diff --git a/SharedCryptoPkg/Package/SharedCryptoPkgPei.inf b/SharedCryptoPkg/Package/SharedCryptoPkgPei.inf new file mode 100644 index 0000000000..0b2df9e7c5 --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCryptoPkgPei.inf @@ -0,0 +1,52 @@ +## @file +# Crypto Bin Driver package +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = SharedCryptoDriver + FILE_GUID = D27946C9-2212-42DD-8252-14EF9134D741 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +# these binaries are resolved by the Nuget Package +# if they are not found, check there + +[Binaries.Ia32] + PE32|Mu-SharedCrypto_extdep/DEBUG/IA32/SharedCryptoPei.efi|DEBUG + PEI_DEPEX|Mu-SharedCrypto_extdep/DEBUG/IA32/SharedCryptoPei.depex|DEBUG + + PE32|Mu-SharedCrypto_extdep/RELEASE/IA32/SharedCryptoPei.efi|RELEASE + PEI_DEPEX|Mu-SharedCrypto_extdep/RELEASE/IA32/SharedCryptoPei.depex|RELEASE + + +[Depex] + gEfiPeiMemoryDiscoveredPpiGuid diff --git a/SharedCryptoPkg/Package/SharedCryptoPkgPeiShaOnly.inf b/SharedCryptoPkg/Package/SharedCryptoPkgPeiShaOnly.inf new file mode 100644 index 0000000000..cde17c15c9 --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCryptoPkgPeiShaOnly.inf @@ -0,0 +1,48 @@ +## @file +# Crypto Bin Driver package +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION = 0x0001000A + BASE_NAME = SharedCryptoDriverShaOnly + FILE_GUID = 566312D1-4878-4695-8E7A-AA585F1C0DA1 + MODULE_TYPE = PEIM + VERSION_STRING = 1.0 + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 +# + +# these binaries are resolved by the Nuget Package +# if they are not found, check there + +[Binaries.IA32] + PE32|Mu-SharedCrypto_extdep/DEBUG/IA32/SharedCryptoPeiShaOnly.efi|DEBUG + PEI_DEPEX|Mu-SharedCrypto_extdep/DEBUG/IA32/SharedCryptoPeiShaOnly.depex|DEBUG + + PE32|Mu-SharedCrypto_extdep/RELEASE/IA32/SharedCryptoPeiShaOnly.efi|RELEASE + PEI_DEPEX|Mu-SharedCrypto_extdep/RELEASE/IA32/SharedCryptoPeiShaOnly.depex|RELEASE diff --git a/SharedCryptoPkg/Package/SharedCryptoPkgSmm.inf b/SharedCryptoPkg/Package/SharedCryptoPkgSmm.inf new file mode 100644 index 0000000000..4c5bb9c9e2 --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCryptoPkgSmm.inf @@ -0,0 +1,56 @@ +## @file +# Crypto Bin Driver package +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION = 0x0001001B + PI_SPECIFICATION_VERSION = 0x0001000A + BASE_NAME = SharedCryptoDriverSmm + FILE_GUID = 391B853F-F488-479B-A3D6-870766C7A38F + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoSmmEntry + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +# these binaries are resolved by the Nuget Package Mu-SharedCrypto +# if they are not found, check there + +[Binaries.X64] + PE32|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoSmm.efi|DEBUG + SMM_DEPEX|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoSmm.depex|DEBUG + + PE32|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoSmm.efi|RELEASE + SMM_DEPEX|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoSmm.depex|RELEASE + +[Packages] + SharedCryptoPkg/SharedCryptoPkg.dec + +[Protocols] + gSharedCryptoSmmProtocolGuid ## produces diff --git a/SharedCryptoPkg/Package/SharedCryptoPkgSmmMu.inf b/SharedCryptoPkg/Package/SharedCryptoPkgSmmMu.inf new file mode 100644 index 0000000000..904bb32baf --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCryptoPkgSmmMu.inf @@ -0,0 +1,57 @@ +## @file +# Crypto Bin Driver package +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + INF_VERSION = 0x0001001B + PI_SPECIFICATION_VERSION = 0x0001000A + BASE_NAME = SharedCryptoDriverSmmMu + FILE_GUID = C3589CC2-A610-48C5-8DD3-C66E5D05B9E2 + MODULE_TYPE = DXE_SMM_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = SharedCryptoSmmEntry + TARGET = DEBUG + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 AARCH64 +# + +# these binaries are resolved by the Nuget Package Mu-SharedCrypto +# if they are not found, check there + +[Binaries.X64] + PE32|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoSmmMu.efi|DEBUG + SMM_DEPEX|Mu-SharedCrypto_extdep/DEBUG/X64/SharedCryptoSmmMu.depex|DEBUG + + PE32|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoSmmMu.efi|RELEASE + SMM_DEPEX|Mu-SharedCrypto_extdep/RELEASE/X64/SharedCryptoSmmMu.depex|RELEASE + +[Packages] + SharedCryptoPkg/SharedCryptoPkg.dec + +[Protocols] + gSharedCryptoSmmProtocolGuid ## produces diff --git a/SharedCryptoPkg/Package/SharedCrypto_ext_dep.json b/SharedCryptoPkg/Package/SharedCrypto_ext_dep.json new file mode 100644 index 0000000000..cb6abd6baf --- /dev/null +++ b/SharedCryptoPkg/Package/SharedCrypto_ext_dep.json @@ -0,0 +1,8 @@ +{ + "scope": "global", + "type": "nuget", + "name": "Mu-SharedCrypto", + "source": "https://api.nuget.org/v3/index.json", + "version": "20190411.0.1", + "flags": [] +} \ No newline at end of file diff --git a/SharedCryptoPkg/Private/Ppi/SharedCryptoPpi.h b/SharedCryptoPkg/Private/Ppi/SharedCryptoPpi.h new file mode 100644 index 0000000000..59dff3f7ad --- /dev/null +++ b/SharedCryptoPkg/Private/Ppi/SharedCryptoPpi.h @@ -0,0 +1,38 @@ +/** @file +This PPI is for Shared Crypto + + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include + +#ifndef __SHARED_CRYPTO_PPI_H__ +#define __SHARED_CRYPTO_PPI_H__ + +typedef struct _SHARED_CRYPTO_FUNCTIONS SHARED_CRYPTO_PPI; + +extern GUID gSharedCryptoPpiGuid; + +#endif \ No newline at end of file diff --git a/SharedCryptoPkg/Private/Protocol/SharedCrypto.h b/SharedCryptoPkg/Private/Protocol/SharedCrypto.h new file mode 100644 index 0000000000..fa968f3ec5 --- /dev/null +++ b/SharedCryptoPkg/Private/Protocol/SharedCrypto.h @@ -0,0 +1,3194 @@ + +/** @file +This is the shared data between the DXE protocol, the SMM protocol, and the PEI PPI + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include + +#ifndef __SHARED_CRYPTO_H__ +#define __SHARED_CRYPTO_H__ + +#define SHARED_CRYPTO_VERSION 1 + +typedef struct _SHARED_CRYPTO_FUNCTIONS SHARED_CRYPTO_FUNCTIONS; +typedef struct _SHARED_CRYPTO_FUNCTIONS SHARED_CRYPTO_PROTOCOL; + +extern GUID gSharedCryptoSmmProtocolGuid; +extern GUID gSharedCryptoProtocolGuid; + + + +//A function that returns the version number of the packaged crypto efi +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_GET_VERSION) ( + VOID +); + +//===================================================================================== +// MAC (Message Authentication Code) Primitive +//===================================================================================== +/** + Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations. + (NOTE: This API is deprecated. + Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for HMAC-MD5 operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_GetContextSize) ( + VOID + ); + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use. + + If this interface is not supported, then return NULL. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacMd5New() returns NULL. + @retval NULL This interface is not supported. + +**/ +typedef +VOID* +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_New) ( + VOID + ); + +/** + Release the specified HMAC_CTX context. + + If this interface is not supported, then do nothing. + + @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_Free) ( + IN VOID *HmacMd5Ctx + ); + +/** + Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for + subsequent use. + + If HmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized. + @param[in] Key Pointer to the user-supplied key. + @param[in] KeySize Key size in bytes. + + @retval TRUE HMAC-MD5 context initialization succeeded. + @retval FALSE HMAC-MD5 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_Init) ( + OUT VOID *HmacMd5Context, + IN CONST UINT8 *Key, + IN UINTN KeySize + ); + +/** + Makes a copy of an existing HMAC-MD5 context. + + If HmacMd5Context is NULL, then return FALSE. + If NewHmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied. + @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context. + + @retval TRUE HMAC-MD5 context copy succeeded. + @retval FALSE HMAC-MD5 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_Duplicate) ( + IN CONST VOID *HmacMd5Context, + OUT VOID *NewHmacMd5Context + ); + +/** + Digests the input data and updates HMAC-MD5 context. + + This function performs HMAC-MD5 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be + finalized by HmacMd5Final(). Behavior with invalid context is undefined. + + If HmacMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context. + @param[in] Data Pointer to the buffer containing the data to be digested. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE HMAC-MD5 data digest succeeded. + @retval FALSE HMAC-MD5 data digest failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_Update) ( + IN OUT VOID *HmacMd5Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + + +/** + Completes computation of the HMAC-MD5 digest value. + + This function completes HMAC-MD5 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the HMAC-MD5 context cannot + be used again. + HMAC-MD5 context should be already correctly initialized by HmacMd5Init(), and should not be + finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined. + + If HmacMd5Context is NULL, then return FALSE. + If HmacValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context. + @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest + value (16 bytes). + + @retval TRUE HMAC-MD5 digest computation succeeded. + @retval FALSE HMAC-MD5 digest computation failed. + @retval FALSE This interface is not supported. + +**/ + +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_MD5_Final) ( + IN OUT VOID *HmacMd5Context, + OUT UINT8 *HmacValue + ); + +/** + Retrieves the size, in bytes, of the context buffer required for HMAC-SHA1 operations. + (NOTE: This API is deprecated. + Use HmacSha1New() / HmacSha1Free() for HMAC-SHA1 Context operations.) + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for HMAC-SHA1 operations. + @retval 0 This interface is not supported. +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_GetContextSize )( + VOID + ); + + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA1 use. + + If this interface is not supported, then return NULL. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacSha1New() returns NULL. + @return NULL This interface is not supported. + +**/ +typedef +VOID* +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_New) ( + VOID + ); + +/** + Release the specified HMAC_CTX context. + + If this interface is not supported, then do nothing. + + @param[in] HmacSha1Ctx Pointer to the HMAC_CTX context to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_Free) ( + IN VOID *HmacSha1Ctx + ); + + +/** + Initializes user-supplied memory pointed by HmacSha1Context as HMAC-SHA1 context for + subsequent use. + + If HmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] HmacSha1Context Pointer to HMAC-SHA1 context being initialized. + @param[in] Key Pointer to the user-supplied key. + @param[in] KeySize Key size in bytes. + + @retval TRUE HMAC-SHA1 context initialization succeeded. + @retval FALSE HMAC-SHA1 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_Init) ( + OUT VOID *HmacSha1Context, + IN CONST UINT8 *Key, + IN UINTN KeySize + ); + + +/** + Makes a copy of an existing HMAC-SHA1 context. + + If HmacSha1Context is NULL, then return FALSE. + If NewHmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] HmacSha1Context Pointer to HMAC-SHA1 context being copied. + @param[out] NewHmacSha1Context Pointer to new HMAC-SHA1 context. + + @retval TRUE HMAC-SHA1 context copy succeeded. + @retval FALSE HMAC-SHA1 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_Duplicate) ( + IN CONST VOID *HmacSha1Context, + OUT VOID *NewHmacSha1Context + ); + + +/** + Digests the input data and updates HMAC-SHA1 context. + + This function performs HMAC-SHA1 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should not + be finalized by HmacSha1Final(). Behavior with invalid context is undefined. + + If HmacSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context. + @param[in] Data Pointer to the buffer containing the data to be digested. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE HMAC-SHA1 data digest succeeded. + @retval FALSE HMAC-SHA1 data digest failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_Update) ( + IN OUT VOID *HmacSha1Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + + +/** + Completes computation of the HMAC-SHA1 digest value. + + This function completes HMAC-SHA1 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the HMAC-SHA1 context cannot + be used again. + HMAC-SHA1 context should be already correctly initialized by HmacSha1Init(), and should + not be finalized by HmacSha1Final(). Behavior with invalid HMAC-SHA1 context is undefined. + + If HmacSha1Context is NULL, then return FALSE. + If HmacValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha1Context Pointer to the HMAC-SHA1 context. + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA1 digest + value (20 bytes). + + @retval TRUE HMAC-SHA1 digest computation succeeded. + @retval FALSE HMAC-SHA1 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA1_Final) ( + IN OUT VOID *HmacSha1Context, + OUT UINT8 *HmacValue + ); + + +/** + Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations. + (NOTE: This API is deprecated. + Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.) + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_GetContextSize) ( + VOID + ); + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacSha256New() returns NULL. + +**/ +typedef +VOID * +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_New) ( + VOID + ); + +/** + Release the specified HMAC_CTX context. + + @param[in] HmacSha256Ctx Pointer to the HMAC_CTX context to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_Free) ( + IN VOID *HmacSha256Ctx + ); + + +/** + Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for + subsequent use. + + If HmacSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized. + @param[in] Key Pointer to the user-supplied key. + @param[in] KeySize Key size in bytes. + + @retval TRUE HMAC-SHA256 context initialization succeeded. + @retval FALSE HMAC-SHA256 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_Init) ( + OUT VOID *HmacSha256Context, + IN CONST UINT8 *Key, + IN UINTN KeySize + ); + +/** + Makes a copy of an existing HMAC-SHA256 context. + + If HmacSha256Context is NULL, then return FALSE. + If NewHmacSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] HmacSha256Context Pointer to HMAC-SHA256 context being copied. + @param[out] NewHmacSha256Context Pointer to new HMAC-SHA256 context. + + @retval TRUE HMAC-SHA256 context copy succeeded. + @retval FALSE HMAC-SHA256 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_Duplicate) ( + IN CONST VOID *HmacSha256Context, + OUT VOID *NewHmacSha256Context + ); + + +/** + Digests the input data and updates HMAC-SHA256 context. + + This function performs HMAC-SHA256 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not + be finalized by HmacSha256Final(). Behavior with invalid context is undefined. + + If HmacSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context. + @param[in] Data Pointer to the buffer containing the data to be digested. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE HMAC-SHA256 data digest succeeded. + @retval FALSE HMAC-SHA256 data digest failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_Update) ( + IN OUT VOID *HmacSha256Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + +/** + Completes computation of the HMAC-SHA256 digest value. + + This function completes HMAC-SHA256 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the HMAC-SHA256 context cannot + be used again. + HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should + not be finalized by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined. + + If HmacSha256Context is NULL, then return FALSE. + If HmacValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] HmacSha256Context Pointer to the HMAC-SHA256 context. + @param[out] HmacValue Pointer to a buffer that receives the HMAC-SHA256 digest + value (32 bytes). + + @retval TRUE HMAC-SHA256 digest computation succeeded. + @retval FALSE HMAC-SHA256 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_HMAC_SHA256_Final) ( + IN OUT VOID *HmacSha256Context, + OUT UINT8 *HmacValue + ); + + +//===================================================================================== +// One-Way Cryptographic Hash Primitives +//===================================================================================== + +/** + Retrieves the size, in bytes, of the context buffer required for MD4 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for MD4 hash operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_MD4_GetContextSize) ( + VOID + ); + + +/** + Initializes user-supplied memory pointed by Md4Context as MD4 hash context for + subsequent use. + + If Md4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Md4Context Pointer to MD4 context being initialized. + + @retval TRUE MD4 context initialization succeeded. + @retval FALSE MD4 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_MD4_Init) ( + OUT VOID *Md4Context + ); + + +/** + Makes a copy of an existing MD4 context. + + If Md4Context is NULL, then return FALSE. + If NewMd4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Md4Context Pointer to MD4 context being copied. + @param[out] NewMd4Context Pointer to new MD4 context. + + @retval TRUE MD4 context copy succeeded. + @retval FALSE MD4 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_MD4_Duplicate) ( + IN CONST VOID *Md4Context, + OUT VOID *NewMd4Context + ); + + +/** + Digests the input data and updates MD4 context. + + This function performs MD4 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + MD4 context should be already correctly initialized by Md4Init(), and should not be finalized + by Md4Final(). Behavior with invalid context is undefined. + + If Md4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md4Context Pointer to the MD4 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE MD4 data digest succeeded. + @retval FALSE MD4 data digest failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_MD4_Update) ( + IN OUT VOID *Md4Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + + +/** + Completes computation of the MD4 digest value. + + This function completes MD4 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the MD4 context cannot + be used again. + MD4 context should be already correctly initialized by Md4Init(), and should not be + finalized by Md4Final(). Behavior with invalid MD4 context is undefined. + + If Md4Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md4Context Pointer to the MD4 context. + @param[out] HashValue Pointer to a buffer that receives the MD4 digest + value (16 bytes). + + @retval TRUE MD4 digest computation succeeded. + @retval FALSE MD4 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_MD4_Final) ( + IN OUT VOID *Md4Context, + OUT UINT8 *HashValue + ); + + +/** + Computes the MD4 message digest of a input data buffer. + + This function performs the MD4 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the MD4 digest + value (16 bytes). + + @retval TRUE MD4 digest computation succeeded. + @retval FALSE MD4 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_MD4_HashAll) ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue + ); + +// ---------------------------------------------------------------------------- + +/** + Retrieves the size, in bytes, of the context buffer required for MD5 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for MD5 hash operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI* SHAREDCRYPTO_MD5_GetContextSize )( + VOID + ); + +/** + Initializes user-supplied memory pointed by Md5Context as MD5 hash context for + subsequent use. + + If Md5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Md5Context Pointer to MD5 context being initialized. + + @retval TRUE MD5 context initialization succeeded. + @retval FALSE MD5 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI* SHAREDCRYPTO_MD5_Init)( + OUT VOID *Md5Context); + +/** + Makes a copy of an existing MD5 context. + + If Md5Context is NULL, then return FALSE. + If NewMd5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Md5Context Pointer to MD5 context being copied. + @param[out] NewMd5Context Pointer to new MD5 context. + + @retval TRUE MD5 context copy succeeded. + @retval FALSE MD5 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI* SHAREDCRYPTO_MD5_Duplicate) ( + IN CONST VOID *Md5Context, + OUT VOID *NewMd5Context); + + +/** + Digests the input data and updates MD5 context. + + This function performs MD5 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + MD5 context should be already correctly initialized by Md5Init(), and should not be finalized + by Md5Final(). Behavior with invalid context is undefined. + + If Md5Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md5Context Pointer to the MD5 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE MD5 data digest succeeded. + @retval FALSE MD5 data digest failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI* SHAREDCRYPTO_MD5_Update)( + IN OUT VOID *Md5Context, + IN CONST VOID *Data, + IN UINTN DataSize); + + +/** + Completes computation of the MD5 digest value. + + This function completes MD5 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the MD5 context cannot + be used again. + MD5 context should be already correctly initialized by Md5Init(), and should not be + finalized by Md5Final(). Behavior with invalid MD5 context is undefined. + + If Md5Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Md5Context Pointer to the MD5 context. + @param[out] HashValue Pointer to a buffer that receives the MD5 digest + value (16 bytes). + + @retval TRUE MD5 digest computation succeeded. + @retval FALSE MD5 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI* SHAREDCRYPTO_MD5_Final)( + IN OUT VOID *Md5Context, + OUT UINT8 *HashValue); + + +/** + Computes the MD5 message digest of a input data buffer. + + This function performs the MD5 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the MD5 digest + value (16 bytes). + + @retval TRUE MD5 digest computation succeeded. + @retval FALSE MD5 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI* SHAREDCRYPTO_MD5_HashAll)( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue); + + +//===================================================================================== +// PKCS +//===================================================================================== + + +/** + Encrypts a blob using PKCS1v2 (RSAES-OAEP) schema. On success, will return the encrypted message in + in a newly allocated buffer. + + Things that can cause a failure include: + - X509 key size does not match any known key size. + - Fail to parse X509 certificate. + - Fail to allocate an intermediate buffer. + - NULL pointer provided for a non-optional parameter. + - Data size is too large for the provided key size (max size is a function of key size and hash digest size). + + @param[in] PublicKey A pointer to the DER-encoded X509 certificate that will be used to encrypt the data. + @param[in] PublicKeySize Size of the X509 cert buffer. + @param[in] InData Data to be encrypted. + @param[in] InDataSize Size of the data buffer. + @param[in] PrngSeed [Optional] If provided, a pointer to a random seed buffer to be used when initializing the PRNG. NULL otherwise. + @param[in] PrngSeedSize [Optional] If provided, size of the random seed buffer. 0 otherwise. + @param[out] EncryptedData Pointer to an allocated buffer containing the encrypted message. + @param[out] EncryptedDataSize Size of the encrypted message buffer. + + @retval TRUE Encryption was successful. + @retval FALSE Encryption failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS1_ENCRYPT_V2) ( +IN CONST UINT8 *PublicKey, +IN UINTN PublicKeySize, +IN UINT8 *InData, +IN UINTN InDataSize, +IN CONST UINT8 *PrngSeed OPTIONAL, +IN UINTN PrngSeedSize OPTIONAL, +OUT UINT8 **EncryptedData, +OUT UINTN *EncryptedDataSize +); + + + + +// --------------------------------------------- +// PKCS5 + +/** + Derives a key from a password using a salt and iteration count, based on PKCS#5 v2.0 + password based encryption key derivation function PBKDF2, as specified in RFC 2898. + + If Password or Salt or OutKey is NULL, then return FALSE. + If the hash algorithm could not be determined, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] PasswordLength Length of input password in bytes. + @param[in] Password Pointer to the array for the password. + @param[in] SaltLength Size of the Salt in bytes. + @param[in] Salt Pointer to the Salt. + @param[in] IterationCount Number of iterations to perform. Its value should be + greater than or equal to 1. + @param[in] DigestSize Size of the message digest to be used (eg. SHA256_DIGEST_SIZE). + NOTE: DigestSize will be used to determine the hash algorithm. + Only SHA1_DIGEST_SIZE or SHA256_DIGEST_SIZE is supported. + @param[in] KeyLength Size of the derived key buffer in bytes. + @param[out] OutKey Pointer to the output derived key buffer. + + @retval TRUE A key was derived successfully. + @retval FALSE One of the pointers was NULL or one of the sizes was too large. + @retval FALSE The hash algorithm could not be determined from the digest size. + @retval FALSE The key derivation operation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS5_PW_HASH) ( + IN UINTN PasswordSize, + IN CONST CHAR8 *Password, + IN UINTN SaltSize, + IN CONST UINT8 *Salt, + IN UINTN IterationCount, + IN UINTN DigestSize, + IN UINTN OutputSize, + OUT UINT8 *Output + ); + + + +// --------------------------------------------- +// PKCS7 + +/** + Verifies the validity of a PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard". The input signed data could be wrapped + in a ContentInfo structure. + + If P7Data, TrustedCert or InData is NULL, then return FALSE. + If P7Length, CertLength or DataLength overflow, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] P7Data Pointer to the PKCS#7 message to verify. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which + is used for certificate chain verification. + @param[in] CertLength Length of the trusted certificate in bytes. + @param[in] InData Pointer to the content to be verified. + @param[in] DataLength Length of InData in bytes. + + @retval TRUE The specified PKCS#7 signed data is valid. + @retval FALSE Invalid PKCS#7 signed data. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS7_VERIFY) ( +IN CONST UINT8 *P7Data, +IN UINTN P7DataLength, +IN CONST UINT8 *TrustedCert, +IN UINTN TrustedCertLength, +IN CONST UINT8 *Data, +IN UINTN DataLength +); + +/** + VerifyEKUsInPkcs7Signature() + + This function receives a PKCS7 formatted signature, and then verifies that + the specified Enhanced or Extended Key Usages (EKU's) are present in the end-entity + leaf signing certificate. + + Note that this function does not validate the certificate chain. + + Applications for custom EKU's are quite flexible. For example, a policy EKU + may be present in an Issuing Certificate Authority (CA), and any sub-ordinate + certificate issued might also contain this EKU, thus constraining the + sub-ordinate certificate. Other applications might allow a certificate + embedded in a device to specify that other Object Identifiers (OIDs) are + present which contains binary data specifying custom capabilities that + the device is able to do. + + @param[in] Pkcs7Signature - The PKCS#7 signed information content block. An array + containing the content block with both the signature, + the signer's certificate, and any necessary intermediate + certificates. + + @param[in] Pkcs7SignatureSize - Number of bytes in Pkcs7Signature. + + @param[in] RequiredEKUs - Array of null-terminated strings listing OIDs of + required EKUs that must be present in the signature. + + @param[in] RequiredEKUsSize - Number of elements in the RequiredEKUs string array. + + @param[in] RequireAllPresent - If this is TRUE, then all of the specified EKU's + must be present in the leaf signer. If it is + FALSE, then we will succeed if we find any + of the specified EKU's. + + @retval EFI_SUCCESS - The required EKUs were found in the signature. + @retval EFI_INVALID_PARAMETER - A parameter was invalid. + @retval EFI_NOT_FOUND - One or more EKU's were not found in the signature. + +**/ +typedef +EFI_STATUS +(EFIAPI *SHAREDCRYPTO_PKCS7_VERIFY_EKU) ( +IN CONST UINT8 *Pkcs7Signature, +IN CONST UINT32 SignatureSize, +IN CONST CHAR8 *RequiredEKUs[], +IN CONST UINT32 RequiredEKUsSize, +IN BOOLEAN RequireAllPresent +); + +/** + Get the signer's certificates from PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard". The input signed data could be wrapped + in a ContentInfo structure. + + If P7Data, CertStack, StackLength, TrustedCert or CertLength is NULL, then + return FALSE. If P7Length overflow, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] P7Data Pointer to the PKCS#7 message to verify. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[out] CertStack Pointer to Signer's certificates retrieved from P7Data. + It's caller's responsibility to free the buffer with + Pkcs7FreeSigners(). + This data structure is EFI_CERT_STACK type. + @param[out] StackLength Length of signer's certificates in bytes. + @param[out] TrustedCert Pointer to a trusted certificate from Signer's certificates. + It's caller's responsibility to free the buffer with + Pkcs7FreeSigners(). + @param[out] CertLength Length of the trusted certificate in bytes. + + @retval TRUE The operation is finished successfully. + @retval FALSE Error occurs during the operation. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS7_GetSigners) ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT UINT8 **CertStack, + OUT UINTN *StackLength, + OUT UINT8 **TrustedCert, + OUT UINTN *CertLength + ); + +/** + Wrap function to use free() to free allocated memory for certificates. + + If this interface is not supported, then ASSERT(). + + @param[in] Certs Pointer to the certificates to be freed. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_PKCS7_FreeSigners) ( + IN UINT8 *Certs + ); + +/** + Creates a PKCS#7 signedData as described in "PKCS #7: Cryptographic Message + Syntax Standard, version 1.5". This interface is only intended to be used for + application to perform PKCS#7 functionality validation. + + If this interface is not supported, then return FALSE. + + @param[in] PrivateKey Pointer to the PEM-formatted private key data for + data signing. + @param[in] PrivateKeySize Size of the PEM private key data in bytes. + @param[in] KeyPassword NULL-terminated passphrase used for encrypted PEM + key data. + @param[in] InData Pointer to the content to be signed. + @param[in] InDataSize Size of InData in bytes. + @param[in] SignCert Pointer to signer's DER-encoded certificate to sign with. + @param[in] OtherCerts Pointer to an optional additional set of certificates to + include in the PKCS#7 signedData (e.g. any intermediate + CAs in the chain). + @param[out] SignedData Pointer to output PKCS#7 signedData. It's caller's + responsibility to free the buffer with FreePool(). + @param[out] SignedDataSize Size of SignedData in bytes. + + @retval TRUE PKCS#7 data signing succeeded. + @retval FALSE PKCS#7 data signing failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS7_Sign) ( + IN CONST UINT8 *PrivateKey, + IN UINTN PrivateKeySize, + IN CONST UINT8 *KeyPassword, + IN UINT8 *InData, + IN UINTN InDataSize, + IN UINT8 *SignCert, + IN UINT8 *OtherCerts OPTIONAL, + OUT UINT8 **SignedData, + OUT UINTN *SignedDataSize + ); + +/** + Extracts the attached content from a PKCS#7 signed data if existed. The input signed + data could be wrapped in a ContentInfo structure. + + If P7Data, Content, or ContentSize is NULL, then return FALSE. If P7Length overflow, + then return FALSE. If the P7Data is not correctly formatted, then return FALSE. + + Caution: This function may receive untrusted input. So this function will do + basic check for PKCS#7 data structure. + + @param[in] P7Data Pointer to the PKCS#7 signed data to process. + @param[in] P7Length Length of the PKCS#7 signed data in bytes. + @param[out] Content Pointer to the extracted content from the PKCS#7 signedData. + It's caller's responsibility to free the buffer with FreePool(). + @param[out] ContentSize The size of the extracted content in bytes. + + @retval TRUE The P7Data was correctly formatted for processing. + @retval FALSE The P7Data was not correctly formatted for processing. + + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS7_GetAttachedContent) ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT VOID **Content, + OUT UINTN *ContentSize + ); + +/** + Retrieves all embedded certificates from PKCS#7 signed data as described in "PKCS #7: + Cryptographic Message Syntax Standard", and outputs two certificate lists chained and + unchained to the signer's certificates. + The input signed data could be wrapped in a ContentInfo structure. + + @param[in] P7Data Pointer to the PKCS#7 message. + @param[in] P7Length Length of the PKCS#7 message in bytes. + @param[out] SignerChainCerts Pointer to the certificates list chained to signer's + certificate. It's caller's responsibility to free the buffer + with Pkcs7FreeSigners(). + This data structure is EFI_CERT_STACK type. + @param[out] ChainLength Length of the chained certificates list buffer in bytes. + @param[out] UnchainCerts Pointer to the unchained certificates lists. It's caller's + responsibility to free the buffer with Pkcs7FreeSigners(). + This data structure is EFI_CERT_STACK type. + @param[out] UnchainLength Length of the unchained certificates list buffer in bytes. + + @retval TRUE The operation is finished successfully. + @retval FALSE Error occurs during the operation. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_PKCS7_GetCertificatesList) ( + IN CONST UINT8 *P7Data, + IN UINTN P7Length, + OUT UINT8 **SignerChainCerts, + OUT UINTN *ChainLength, + OUT UINT8 **UnchainCerts, + OUT UINTN *UnchainLength + ); + +/** + Verifies the validity of a PE/COFF Authenticode Signature as described in "Windows + Authenticode Portable Executable Signature Format". + + If AuthData is NULL, then return FALSE. + If ImageHash is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed + PE/COFF image to be verified. + @param[in] DataSize Size of the Authenticode Signature in bytes. + @param[in] TrustedCert Pointer to a trusted/root certificate encoded in DER, which + is used for certificate chain verification. + @param[in] CertSize Size of the trusted certificate in bytes. + @param[in] ImageHash Pointer to the original image file hash value. The procedure + for calculating the image hash value is described in Authenticode + specification. + @param[in] HashSize Size of Image hash value in bytes. + + @retval TRUE The specified Authenticode Signature is valid. + @retval FALSE Invalid Authenticode Signature. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_AuthenticodeVerify) ( + IN CONST UINT8 *AuthData, + IN UINTN DataSize, + IN CONST UINT8 *TrustedCert, + IN UINTN CertSize, + IN CONST UINT8 *ImageHash, + IN UINTN HashSize + ); + +/** + Verifies the validity of a RFC3161 Timestamp CounterSignature embedded in PE/COFF Authenticode + signature. + + If AuthData is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AuthData Pointer to the Authenticode Signature retrieved from signed + PE/COFF image to be verified. + @param[in] DataSize Size of the Authenticode Signature in bytes. + @param[in] TsaCert Pointer to a trusted/root TSA certificate encoded in DER, which + is used for TSA certificate chain verification. + @param[in] CertSize Size of the trusted certificate in bytes. + @param[out] SigningTime Return the time of timestamp generation time if the timestamp + signature is valid. + + @retval TRUE The specified Authenticode includes a valid RFC3161 Timestamp CounterSignature. + @retval FALSE No valid RFC3161 Timestamp CounterSignature in the specified Authenticode data. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_ImageTimestampVerify) ( + IN CONST UINT8 *AuthData, + IN UINTN DataSize, + IN CONST UINT8 *TsaCert, + IN UINTN CertSize, + OUT EFI_TIME *SigningTime + ); + + +//===================================================================================== +// DH Key Exchange Primitive +//===================================================================================== + +/** + Allocates and Initializes one Diffie-Hellman Context for subsequent use. + + @return Pointer to the Diffie-Hellman Context that has been initialized. + If the allocations fails, DhNew() returns NULL. + If the interface is not supported, DhNew() returns NULL. + +**/ +typedef +VOID* +(EFIAPI *SHAREDCRYPTO_DH_New) ( + VOID + ); + +/** + Release the specified DH context. + + If the interface is not supported, then ASSERT(). + + @param[in] DhContext Pointer to the DH context to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_DH_Free) ( + IN VOID *DhContext + ); + +/** + Generates DH parameter. + + Given generator g, and length of prime number p in bits, this function generates p, + and sets DH context according to value of g and p. + + Before this function can be invoked, pseudorandom number generator must be correctly + initialized by RandomSeed(). + + If DhContext is NULL, then return FALSE. + If Prime is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[in] Generator Value of generator. + @param[in] PrimeLength Length in bits of prime to be generated. + @param[out] Prime Pointer to the buffer to receive the generated prime number. + + @retval TRUE DH parameter generation succeeded. + @retval FALSE Value of Generator is not supported. + @retval FALSE PRNG fails to generate random prime number with PrimeLength. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_DH_GenerateParameter) ( + IN OUT VOID *DhContext, + IN UINTN Generator, + IN UINTN PrimeLength, + OUT UINT8 *Prime + ); + +/** + Sets generator and prime parameters for DH. + + Given generator g, and prime number p, this function and sets DH + context accordingly. + + If DhContext is NULL, then return FALSE. + If Prime is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[in] Generator Value of generator. + @param[in] PrimeLength Length in bits of prime to be generated. + @param[in] Prime Pointer to the prime number. + + @retval TRUE DH parameter setting succeeded. + @retval FALSE Value of Generator is not supported. + @retval FALSE Value of Generator is not suitable for the Prime. + @retval FALSE Value of Prime is not a prime number. + @retval FALSE Value of Prime is not a safe prime number. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_DH_SetParameter) ( + IN OUT VOID *DhContext, + IN UINTN Generator, + IN UINTN PrimeLength, + IN CONST UINT8 *Prime + ); + +/** + Generates DH public key. + + This function generates random secret exponent, and computes the public key, which is + returned via parameter PublicKey and PublicKeySize. DH context is updated accordingly. + If the PublicKey buffer is too small to hold the public key, FALSE is returned and + PublicKeySize is set to the required buffer size to obtain the public key. + + If DhContext is NULL, then return FALSE. + If PublicKeySize is NULL, then return FALSE. + If PublicKeySize is large enough but PublicKey is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[out] PublicKey Pointer to the buffer to receive generated public key. + @param[in, out] PublicKeySize On input, the size of PublicKey buffer in bytes. + On output, the size of data returned in PublicKey buffer in bytes. + + @retval TRUE DH public key generation succeeded. + @retval FALSE DH public key generation failed. + @retval FALSE PublicKeySize is not large enough. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_DH_GenerateKey) ( + IN OUT VOID *DhContext, + OUT UINT8 *PublicKey, + IN OUT UINTN *PublicKeySize + ); + +/** + Computes exchanged common key. + + Given peer's public key, this function computes the exchanged common key, based on its own + context including value of prime modulus and random secret exponent. + + If DhContext is NULL, then return FALSE. + If PeerPublicKey is NULL, then return FALSE. + If KeySize is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeySize is not large enough, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] DhContext Pointer to the DH context. + @param[in] PeerPublicKey Pointer to the peer's public key. + @param[in] PeerPublicKeySize Size of peer's public key in bytes. + @param[out] Key Pointer to the buffer to receive generated key. + @param[in, out] KeySize On input, the size of Key buffer in bytes. + On output, the size of data returned in Key buffer in bytes. + + @retval TRUE DH exchanged key generation succeeded. + @retval FALSE DH exchanged key generation failed. + @retval FALSE KeySize is not large enough. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_DH_ComputeKey) ( + IN OUT VOID *DhContext, + IN CONST UINT8 *PeerPublicKey, + IN UINTN PeerPublicKeySize, + OUT UINT8 *Key, + IN OUT UINTN *KeySize + ); + +//===================================================================================== +// Pseudo-Random Generation Primitive +//===================================================================================== + +/** + Sets up the seed value for the pseudorandom number generator. + + This function sets up the seed value for the pseudorandom number generator. + If Seed is not NULL, then the seed passed in is used. + If Seed is NULL, then default seed is used. + If this interface is not supported, then return FALSE. + + @param[in] Seed Pointer to seed value. + If NULL, default seed is used. + @param[in] SeedSize Size of seed value. + If Seed is NULL, this parameter is ignored. + + @retval TRUE Pseudorandom number generator has enough entropy for random generation. + @retval FALSE Pseudorandom number generator does not have enough entropy for random generation. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RANDOM_Seed) ( + IN CONST UINT8 *Seed OPTIONAL, + IN UINTN SeedSize + ); + +/** + Generates a pseudorandom byte stream of the specified size. + + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Output Pointer to buffer to receive random value. + @param[in] Size Size of random bytes to generate. + + @retval TRUE Pseudorandom byte stream generated successfully. + @retval FALSE Pseudorandom number generator fails to generate due to lack of entropy. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RANDOM_Bytes) ( + OUT UINT8 *Output, + IN UINTN Size + ); + +/** + Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in + RSA PKCS#1. + + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE. + + @param[in] RsaContext Pointer to RSA context for signature verification. + @param[in] MessageHash Pointer to octet message hash to be checked. + @param[in] HashSize Size of the message hash in bytes. + @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified. + @param[in] SigSize Size of signature in bytes. + + @retval TRUE Valid signature encoded in PKCS1-v1_5. + @retval FALSE Invalid signature or invalid RSA context. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_VERIFY_PKCS1 ) ( + IN VOID *RsaContext, + IN CONST UINT8 *MessageHash, + IN UINTN HashSize, + IN CONST UINT8 *Signature, + IN UINTN SigSize + ); + +/** + Release the specified RSA context. + + If RsaContext is NULL, then return FALSE. + + @param[in] RsaContext Pointer to the RSA context to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_RSA_FREE) ( + IN VOID *RsaContext + ); + +/** + Retrieve the RSA Public Key from one DER-encoded X509 certificate. + + If Cert is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA public key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve RSA public key from X509 certificate. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_GET_PUBLIC_KEY_FROM_X509) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **RsaContext + ); + +/** + Allocates and initializes one RSA context for subsequent use. + + @return Pointer to the RSA context that has been initialized. + If the allocations fails, RsaNew() returns NULL. + +**/ +typedef +VOID* +(EFIAPI *SHAREDCRYPTO_RSA_New) ( + VOID + ); + +/** + Release the specified RSA context. + + If RsaContext is NULL, then return FALSE. + + @param[in] RsaContext Pointer to the RSA context to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_RSA_Free) ( + IN VOID *RsaContext + ); + +/** + Sets the tag-designated key component into the established RSA context. + + This function sets the tag-designated RSA key component into the established + RSA context from the user-specified non-negative integer (octet string format + represented in RSA PKCS#1). + If BigNumber is NULL, then the specified key component in RSA context is cleared. + + If RsaContext is NULL, then return FALSE. + + @param[in, out] RsaContext Pointer to RSA context being set. + @param[in] KeyTag Tag of RSA key component being set. + @param[in] BigNumber Pointer to octet integer buffer. + If NULL, then the specified key component in RSA + context is cleared. + @param[in] BnSize Size of big number buffer in bytes. + If BigNumber is NULL, then it is ignored. + + @retval TRUE RSA key component was set successfully. + @retval FALSE Invalid RSA key component tag. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_SetKey) ( + IN OUT VOID *RsaContext, + IN RSA_KEY_TAG KeyTag, + IN CONST UINT8 *BigNumber, + IN UINTN BnSize + ); + +/** + Gets the tag-designated RSA key component from the established RSA context. + + This function retrieves the tag-designated RSA key component from the + established RSA context as a non-negative integer (octet string format + represented in RSA PKCS#1). + If specified key component has not been set or has been cleared, then returned + BnSize is set to 0. + If the BigNumber buffer is too small to hold the contents of the key, FALSE + is returned and BnSize is set to the required buffer size to obtain the key. + + If RsaContext is NULL, then return FALSE. + If BnSize is NULL, then return FALSE. + If BnSize is large enough but BigNumber is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] RsaContext Pointer to RSA context being set. + @param[in] KeyTag Tag of RSA key component being set. + @param[out] BigNumber Pointer to octet integer buffer. + @param[in, out] BnSize On input, the size of big number buffer in bytes. + On output, the size of data returned in big number buffer in bytes. + + @retval TRUE RSA key component was retrieved successfully. + @retval FALSE Invalid RSA key component tag. + @retval FALSE BnSize is too small. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_GetKey) ( + IN OUT VOID *RsaContext, + IN RSA_KEY_TAG KeyTag, + OUT UINT8 *BigNumber, + IN OUT UINTN *BnSize + ); + +/** + Generates RSA key components. + + This function generates RSA key components. It takes RSA public exponent E and + length in bits of RSA modulus N as input, and generates all key components. + If PublicExponent is NULL, the default RSA public exponent (0x10001) will be used. + + Before this function can be invoked, pseudorandom number generator must be correctly + initialized by RandomSeed(). + + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] RsaContext Pointer to RSA context being set. + @param[in] ModulusLength Length of RSA modulus N in bits. + @param[in] PublicExponent Pointer to RSA public exponent. + @param[in] PublicExponentSize Size of RSA public exponent buffer in bytes. + + @retval TRUE RSA key component was generated successfully. + @retval FALSE Invalid RSA key component tag. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_GenerateKey) ( + IN OUT VOID *RsaContext, + IN UINTN ModulusLength, + IN CONST UINT8 *PublicExponent, + IN UINTN PublicExponentSize + ); + +/** + Validates key components of RSA context. + NOTE: This function performs integrity checks on all the RSA key material, so + the RSA key structure must contain all the private key data. + + This function validates key components of RSA context in following aspects: + - Whether p is a prime + - Whether q is a prime + - Whether n = p * q + - Whether d*e = 1 mod lcm(p-1,q-1) + + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] RsaContext Pointer to RSA context to check. + + @retval TRUE RSA key components are valid. + @retval FALSE RSA key components are not valid. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_CheckKey) ( + IN VOID *RsaContext + ); + +/** + Carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme. + + This function carries out the RSA-SSA signature generation with EMSA-PKCS1-v1_5 encoding scheme defined in + RSA PKCS#1. + If the Signature buffer is too small to hold the contents of signature, FALSE + is returned and SigSize is set to the required buffer size to obtain the signature. + + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1 or SHA-256 digest, then return FALSE. + If SigSize is large enough but Signature is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] RsaContext Pointer to RSA context for signature generation. + @param[in] MessageHash Pointer to octet message hash to be signed. + @param[in] HashSize Size of the message hash in bytes. + @param[out] Signature Pointer to buffer to receive RSA PKCS1-v1_5 signature. + @param[in, out] SigSize On input, the size of Signature buffer in bytes. + On output, the size of data returned in Signature buffer in bytes. + + @retval TRUE Signature successfully generated in PKCS1-v1_5. + @retval FALSE Signature generation failed. + @retval FALSE SigSize is too small. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_Pkcs1Sign) ( + IN VOID *RsaContext, + IN CONST UINT8 *MessageHash, + IN UINTN HashSize, + OUT UINT8 *Signature, + IN OUT UINTN *SigSize + ); + +/** + Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in + RSA PKCS#1. + + If RsaContext is NULL, then return FALSE. + If MessageHash is NULL, then return FALSE. + If Signature is NULL, then return FALSE. + If HashSize is not equal to the size of MD5, SHA-1, SHA-256 digest, then return FALSE. + + @param[in] RsaContext Pointer to RSA context for signature verification. + @param[in] MessageHash Pointer to octet message hash to be checked. + @param[in] HashSize Size of the message hash in bytes. + @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified. + @param[in] SigSize Size of signature in bytes. + + @retval TRUE Valid signature encoded in PKCS1-v1_5. + @retval FALSE Invalid signature or invalid RSA context. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_Pkcs1Verify) ( + IN VOID *RsaContext, + IN CONST UINT8 *MessageHash, + IN UINTN HashSize, + IN CONST UINT8 *Signature, + IN UINTN SigSize + ); + +/** + Retrieve the RSA Private Key from the password-protected PEM key data. + + If PemData is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] PemData Pointer to the PEM-encoded key data to be retrieved. + @param[in] PemSize Size of the PEM key data in bytes. + @param[in] Password NULL-terminated passphrase used for encrypted PEM key data. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA private key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Private Key was retrieved successfully. + @retval FALSE Invalid PEM key data or incorrect password. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_GetPrivateKeyFromPem) ( + IN CONST UINT8 *PemData, + IN UINTN PemSize, + IN CONST CHAR8 *Password, + OUT VOID **RsaContext + ); + +/** + Retrieve the RSA Public Key from one DER-encoded X509 certificate. + + If Cert is NULL, then return FALSE. + If RsaContext is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] RsaContext Pointer to new-generated RSA context which contain the retrieved + RSA public key component. Use RsaFree() function to free the + resource. + + @retval TRUE RSA Public Key was retrieved successfully. + @retval FALSE Fail to retrieve RSA public key from X509 certificate. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_RSA_GetPublicKeyFromX509) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT VOID **RsaContext + ); + +//---------------------------------------- +// SHA +//---------------------------------------- + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for SHA-1 hash operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_SHA1_GET_CONTEXT_SIZE ) ( + VOID + ); + +/** + Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for + subsequent use. + + If Sha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Sha1Context Pointer to SHA-1 context being initialized. + + @retval TRUE SHA-1 context initialization succeeded. + @retval FALSE SHA-1 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA1_INIT ) ( + OUT VOID *Sha1Context + ); + +/** + Makes a copy of an existing SHA-1 context. + + If Sha1Context is NULL, then return FALSE. + If NewSha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha1Context Pointer to SHA-1 context being copied. + @param[out] NewSha1Context Pointer to new SHA-1 context. + + @retval TRUE SHA-1 context copy succeeded. + @retval FALSE SHA-1 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA1_DUPLICATE ) ( + IN CONST VOID *Sha1Context, + OUT VOID *NewSha1Context + ); + +/** + Digests the input data and updates SHA-1 context. + + This function performs SHA-1 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized + by Sha1Final(). Behavior with invalid context is undefined. + + If Sha1Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Sha1Context Pointer to the SHA-1 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-1 data digest succeeded. + @retval FALSE SHA-1 data digest failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA1_UPDATE ) ( + IN OUT VOID *Sha1Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + +/** + Completes computation of the SHA-1 digest value. + + This function completes SHA-1 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-1 context cannot + be used again. + SHA-1 context should be already correctly initialized by Sha1Init(), and should not be + finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined. + + If Sha1Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Sha1Context Pointer to the SHA-1 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest + value (20 bytes). + + @retval TRUE SHA-1 digest computation succeeded. + @retval FALSE SHA-1 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA1_FINAL ) ( + IN OUT VOID *Sha1Context, + OUT UINT8 *HashValue + ); + +/** + Computes the SHA-1 message digest of a input data buffer. + + This function performs the SHA-1 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-1 digest + value (20 bytes). + + @retval TRUE SHA-1 digest computation succeeded. + @retval FALSE SHA-1 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA1_HASH_ALL ) ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue + ); + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-256 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-256 hash operations. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_SHA256_GET_CONTEXT_SIZE ) ( + VOID +); + +/** + Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for + subsequent use. + + If Sha256Context is NULL, then return FALSE. + + @param[out] Sha256Context Pointer to SHA-256 context being initialized. + + @retval TRUE SHA-256 context initialization succeeded. + @retval FALSE SHA-256 context initialization failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA256_INIT ) ( + OUT VOID *Sha256Context + ); + +/** + Makes a copy of an existing SHA-256 context. + + If Sha256Context is NULL, then return FALSE. + If NewSha256Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha256Context Pointer to SHA-256 context being copied. + @param[out] NewSha256Context Pointer to new SHA-256 context. + + @retval TRUE SHA-256 context copy succeeded. + @retval FALSE SHA-256 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA256_DUPLICATE ) ( + IN CONST VOID *Sha256Context, + OUT VOID *NewSha256Context + ); + +/** + Digests the input data and updates SHA-256 context. + + This function performs SHA-256 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-256 context should be already correctly initialized by Sha256Init(), and should not be finalized + by Sha256Final(). Behavior with invalid context is undefined. + + If Sha256Context is NULL, then return FALSE. + + @param[in, out] Sha256Context Pointer to the SHA-256 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-256 data digest succeeded. + @retval FALSE SHA-256 data digest failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA256_UPDATE ) ( + IN OUT VOID *Sha256Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + +/** + Completes computation of the SHA-256 digest value. + + This function completes SHA-256 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-256 context cannot + be used again. + SHA-256 context should be already correctly initialized by Sha256Init(), and should not be + finalized by Sha256Final(). Behavior with invalid SHA-256 context is undefined. + + If Sha256Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha256Context Pointer to the SHA-256 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest + value (32 bytes). + + @retval TRUE SHA-256 digest computation succeeded. + @retval FALSE SHA-256 digest computation failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA256_FINAL ) ( + IN OUT VOID *Sha256Context, + OUT UINT8 *HashValue + ); + +/** + Computes the SHA-256 message digest of a input data buffer. + + This function performs the SHA-256 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest + value (32 bytes). + + @retval TRUE SHA-256 digest computation succeeded. + @retval FALSE SHA-256 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA256_HASH_ALL ) ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue + ); + + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-384 hash operations. + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for SHA-384 hash operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_SHA384_GetContextSize) ( + VOID + ); + + +/** + Initializes user-supplied memory pointed by Sha384Context as SHA-384 hash context for + subsequent use. + + If Sha384Context is NULL, then return FALSE. + + @param[out] Sha384Context Pointer to SHA-384 context being initialized. + + @retval TRUE SHA-384 context initialization succeeded. + @retval FALSE SHA-384 context initialization failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA384_Init) ( + OUT VOID *Sha384Context + ); + + +/** + Makes a copy of an existing SHA-384 context. + + If Sha384Context is NULL, then return FALSE. + If NewSha384Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha384Context Pointer to SHA-384 context being copied. + @param[out] NewSha384Context Pointer to new SHA-384 context. + + @retval TRUE SHA-384 context copy succeeded. + @retval FALSE SHA-384 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA384_Duplicate) ( + IN CONST VOID *Sha384Context, + OUT VOID *NewSha384Context + ); + + +/** + Digests the input data and updates SHA-384 context. + + This function performs SHA-384 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-384 context should be already correctly initialized by Sha384Init(), and should not be finalized + by Sha384Final(). Behavior with invalid context is undefined. + + If Sha384Context is NULL, then return FALSE. + + @param[in, out] Sha384Context Pointer to the SHA-384 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-384 data digest succeeded. + @retval FALSE SHA-384 data digest failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA384_Update) ( + IN OUT VOID *Sha384Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + + +/** + Completes computation of the SHA-384 digest value. + + This function completes SHA-384 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-384 context cannot + be used again. + SHA-384 context should be already correctly initialized by Sha384Init(), and should not be + finalized by Sha384Final(). Behavior with invalid SHA-384 context is undefined. + + If Sha384Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha384Context Pointer to the SHA-384 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest + value (48 bytes). + + @retval TRUE SHA-384 digest computation succeeded. + @retval FALSE SHA-384 digest computation failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA384_Final) ( + IN OUT VOID *Sha384Context, + OUT UINT8 *HashValue + ); + + +/** + Computes the SHA-384 message digest of a input data buffer. + + This function performs the SHA-384 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-384 digest + value (48 bytes). + + @retval TRUE SHA-384 digest computation succeeded. + @retval FALSE SHA-384 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA384_HashAll) ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue + ); + +/** + Retrieves the size, in bytes, of the context buffer required for SHA-512 hash operations. + + @return The size, in bytes, of the context buffer required for SHA-512 hash operations. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_SHA512_GetContextSize) ( + VOID + ); + + +/** + Initializes user-supplied memory pointed by Sha512Context as SHA-512 hash context for + subsequent use. + + If Sha512Context is NULL, then return FALSE. + + @param[out] Sha512Context Pointer to SHA-512 context being initialized. + + @retval TRUE SHA-512 context initialization succeeded. + @retval FALSE SHA-512 context initialization failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA512_Init) ( + OUT VOID *Sha512Context + ); + + +/** + Makes a copy of an existing SHA-512 context. + + If Sha512Context is NULL, then return FALSE. + If NewSha512Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Sha512Context Pointer to SHA-512 context being copied. + @param[out] NewSha512Context Pointer to new SHA-512 context. + + @retval TRUE SHA-512 context copy succeeded. + @retval FALSE SHA-512 context copy failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA512_Duplicate) ( + IN CONST VOID *Sha512Context, + OUT VOID *NewSha512Context + ); + +/** + Digests the input data and updates SHA-512 context. + + This function performs SHA-512 digest on a data buffer of the specified size. + It can be called multiple times to compute the digest of long or discontinuous data streams. + SHA-512 context should be already correctly initialized by Sha512Init(), and should not be finalized + by Sha512Final(). Behavior with invalid context is undefined. + + If Sha512Context is NULL, then return FALSE. + + @param[in, out] Sha512Context Pointer to the SHA-512 context. + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + + @retval TRUE SHA-512 data digest succeeded. + @retval FALSE SHA-512 data digest failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA512_Update) ( + IN OUT VOID *Sha512Context, + IN CONST VOID *Data, + IN UINTN DataSize + ); + + +/** + Completes computation of the SHA-512 digest value. + + This function completes SHA-512 hash computation and retrieves the digest value into + the specified memory. After this function has been called, the SHA-512 context cannot + be used again. + SHA-512 context should be already correctly initialized by Sha512Init(), and should not be + finalized by Sha512Final(). Behavior with invalid SHA-512 context is undefined. + + If Sha512Context is NULL, then return FALSE. + If HashValue is NULL, then return FALSE. + + @param[in, out] Sha512Context Pointer to the SHA-512 context. + @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest + value (64 bytes). + + @retval TRUE SHA-512 digest computation succeeded. + @retval FALSE SHA-512 digest computation failed. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA512_Final) ( + IN OUT VOID *Sha512Context, + OUT UINT8 *HashValue + ); + +/** + Computes the SHA-512 message digest of a input data buffer. + + This function performs the SHA-512 message digest of a given data buffer, and places + the digest value into the specified memory. + + If this interface is not supported, then return FALSE. + + @param[in] Data Pointer to the buffer containing the data to be hashed. + @param[in] DataSize Size of Data buffer in bytes. + @param[out] HashValue Pointer to a buffer that receives the SHA-512 digest + value (64 bytes). + + @retval TRUE SHA-512 digest computation succeeded. + @retval FALSE SHA-512 digest computation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_SHA512_HashAll) ( + IN CONST VOID *Data, + IN UINTN DataSize, + OUT UINT8 *HashValue + ); + +//---------------------------------------------------------------------------- +// X509 +//---------------------------------------------------------------------------- + +/** + Retrieve the subject bytes from one X.509 certificate. + + If Cert is NULL, then return FALSE. + If SubjectSize is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] CertSubject Pointer to the retrieved certificate subject bytes. + @param[in, out] SubjectSize The size in bytes of the CertSubject buffer on input, + and the size of buffer returned CertSubject on output. + + @retval TRUE The certificate subject retrieved successfully. + @retval FALSE Invalid certificate, or the SubjectSize is too small for the result. + The SubjectSize will be updated with the required size. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_X509_GET_SUBJECT_NAME) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 *CertSubject, + IN OUT UINTN *SubjectSize + ); + +/** + Retrieve the common name (CN) string from one X.509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] CommonName Buffer to contain the retrieved certificate common + name string (UTF8). At most CommonNameSize bytes will be + written and the string will be null terminated. May be + NULL in order to determine the size buffer needed. + @param[in,out] CommonNameSize The size in bytes of the CommonName buffer on input, + and the size of buffer returned CommonName on output. + If CommonName is NULL then the amount of space needed + in buffer (including the final null) is returned. + + @retval RETURN_SUCCESS The certificate CommonName retrieved successfully. + @retval RETURN_INVALID_PARAMETER If Cert is NULL. + If CommonNameSize is NULL. + If CommonName is not NULL and *CommonNameSize is 0. + If Certificate is invalid. + @retval RETURN_NOT_FOUND If no CommonName entry exists. + @retval RETURN_BUFFER_TOO_SMALL If the CommonName is NULL. The required buffer size + (including the final null) is returned in the + CommonNameSize parameter. + @retval RETURN_UNSUPPORTED The operation is not supported. + +**/ +typedef +EFI_STATUS +(EFIAPI *SHAREDCRYPTO_X509_GET_COMMON_NAME) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT CHAR8 *CommonName, OPTIONAL + IN OUT UINTN *CommonNameSize + ); + +/** + Retrieve the organization name (O) string from one X.509 certificate. + + @param[in] Cert Pointer to the DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] NameBuffer Buffer to contain the retrieved certificate organization + name string. At most NameBufferSize bytes will be + written and the string will be null terminated. May be + NULL in order to determine the size buffer needed. + @param[in,out] NameBufferSiz e The size in bytes of the Name buffer on input, + and the size of buffer returned Name on output. + If NameBuffer is NULL then the amount of space needed + in buffer (including the final null) is returned. + + @retval RETURN_SUCCESS The certificate Organization Name retrieved successfully. + @retval RETURN_INVALID_PARAMETER If Cert is NULL. + If NameBufferSize is NULL. + If NameBuffer is not NULL and *CommonNameSize is 0. + If Certificate is invalid. + @retval RETURN_NOT_FOUND If no Organization Name entry exists. + @retval RETURN_BUFFER_TOO_SMALL If the NameBuffer is NULL. The required buffer size + (including the final null) is returned in the + CommonNameSize parameter. + @retval RETURN_UNSUPPORTED The operation is not supported. + +**/ +typedef +EFI_STATUS +(EFIAPI *SHAREDCRYPTO_X509_GET_ORGANIZATION_NAME) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT CHAR8 *NameBuffer, OPTIONAL + IN OUT UINTN *NameBufferSize + ); + +/** + Verify one X509 certificate was issued by the trusted CA. + + If Cert is NULL, then return FALSE. + If CACert is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded X509 certificate to be verified. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[in] CACert Pointer to the DER-encoded trusted CA certificate. + @param[in] CACertSize Size of the CA Certificate in bytes. + + @retval TRUE The certificate was issued by the trusted CA. + @retval FALSE Invalid certificate or the certificate was not issued by the given + trusted CA. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_X509_VerifyCert) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + IN CONST UINT8 *CACert, + IN UINTN CACertSize + ); + +/** + Construct a X509 object from DER-encoded certificate data. + + If Cert is NULL, then return FALSE. + If SingleX509Cert is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] Cert Pointer to the DER-encoded certificate data. + @param[in] CertSize The size of certificate data in bytes. + @param[out] SingleX509Cert The generated X509 object. + + @retval TRUE The X509 object generation succeeded. + @retval FALSE The operation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_X509_ConstructCertificate) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 **SingleX509Cert + ); + +/** + Construct a X509 stack object from a list of DER-encoded certificate data. + + If X509Stack is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] X509Stack On input, pointer to an existing or NULL X509 stack object. + On output, pointer to the X509 stack object with new + inserted X509 certificate. + @param ... A list of DER-encoded single certificate data followed + by certificate size. A NULL terminates the list. The + pairs are the arguments to X509ConstructCertificate(). + + @retval TRUE The X509 stack construction succeeded. + @retval FALSE The construction operation failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_X509_ConstructCertificateStack) ( + IN OUT UINT8 **X509Stack, + ... + ); + +/** + Release the specified X509 object. + + If the interface is not supported, then ASSERT(). + + @param[in] X509Cert Pointer to the X509 object to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_X509_Free) ( + IN VOID *X509Cert + ); + +/** + Release the specified X509 stack object. + + If the interface is not supported, then ASSERT(). + + @param[in] X509Stack Pointer to the X509 stack object to be released. + +**/ +typedef +VOID +(EFIAPI *SHAREDCRYPTO_X509_StackFree) ( + IN VOID *X509Stack + ); + +/** + Retrieve the TBSCertificate from one given X.509 certificate. + + @param[in] Cert Pointer to the given DER-encoded X509 certificate. + @param[in] CertSize Size of the X509 certificate in bytes. + @param[out] TBSCert DER-Encoded To-Be-Signed certificate. + @param[out] TBSCertSize Size of the TBS certificate in bytes. + + If Cert is NULL, then return FALSE. + If TBSCert is NULL, then return FALSE. + If TBSCertSize is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @retval TRUE The TBSCertificate was retrieved successfully. + @retval FALSE Invalid X.509 certificate. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_X509_GetTBSCert) ( + IN CONST UINT8 *Cert, + IN UINTN CertSize, + OUT UINT8 **TBSCert, + OUT UINTN *TBSCertSize + ); + + + +//===================================================================================== +// Symmetric Cryptography Primitive +//===================================================================================== + +/** + Retrieves the size, in bytes, of the context buffer required for TDES operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for TDES operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_TDES_GetContextSize) ( + VOID + ); + +/** + Initializes user-supplied memory as TDES context for subsequent use. + + This function initializes user-supplied memory pointed by TdesContext as TDES context. + In addition, it sets up all TDES key materials for subsequent encryption and decryption + operations. + There are 3 key options as follows: + KeyLength = 64, Keying option 1: K1 == K2 == K3 (Backward compatibility with DES) + KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security) + KeyLength = 192 Keying option 3: K1 != K2 != K3 (Strongest) + + If TdesContext is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeyLength is not valid, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] TdesContext Pointer to TDES context being initialized. + @param[in] Key Pointer to the user-supplied TDES key. + @param[in] KeyLength Length of TDES key in bits. + + @retval TRUE TDES context initialization succeeded. + @retval FALSE TDES context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_TDES_Init) ( + OUT VOID *TdesContext, + IN CONST UINT8 *Key, + IN UINTN KeyLength + ); + +/** + Performs TDES encryption on a data buffer of the specified size in ECB mode. + + This function performs TDES encryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the TDES encryption output. + + @retval TRUE TDES encryption succeeded. + @retval FALSE TDES encryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_TDES_EcbEncrypt) ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output + ); + +/** + Performs TDES decryption on a data buffer of the specified size in ECB mode. + + This function performs TDES decryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be decrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the TDES decryption output. + + @retval TRUE TDES decryption succeeded. + @retval FALSE TDES decryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_TDES_EcbDecrypt) ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output + ); + +/** + Performs TDES encryption on a data buffer of the specified size in CBC mode. + + This function performs TDES encryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (8 bytes). + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the TDES encryption output. + + @retval TRUE TDES encryption succeeded. + @retval FALSE TDES encryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_TDES_CbcEncrypt) ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output + ); + +/** + Performs TDES decryption on a data buffer of the specified size in CBC mode. + + This function performs TDES decryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (8 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (8 bytes). + TdesContext should be already correctly initialized by TdesInit(). Behavior with + invalid TDES context is undefined. + + If TdesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (8 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] TdesContext Pointer to the TDES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the TDES encryption output. + + @retval TRUE TDES decryption succeeded. + @retval FALSE TDES decryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_TDES_CbcDecrypt) ( + IN VOID *TdesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output + ); + +/** + Retrieves the size, in bytes, of the context buffer required for AES operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for AES operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_AES_GetContextSize) ( + VOID + ); + +/** + Initializes user-supplied memory as AES context for subsequent use. + + This function initializes user-supplied memory pointed by AesContext as AES context. + In addition, it sets up all AES key materials for subsequent encryption and decryption + operations. + There are 3 options for key length, 128 bits, 192 bits, and 256 bits. + + If AesContext is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeyLength is not valid, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] AesContext Pointer to AES context being initialized. + @param[in] Key Pointer to the user-supplied AES key. + @param[in] KeyLength Length of AES key in bits. + + @retval TRUE AES context initialization succeeded. + @retval FALSE AES context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_AES_Init) ( + OUT VOID *AesContext, + IN CONST UINT8 *Key, + IN UINTN KeyLength + ); + +/** + Performs AES encryption on a data buffer of the specified size in ECB mode. + + This function performs AES encryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_AES_EcbEncrypt) ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output + ); + +/** + Performs AES decryption on a data buffer of the specified size in ECB mode. + + This function performs AES decryption on data buffer pointed by Input, of specified + size of InputSize, in ECB mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be decrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the AES decryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_AES_EcbDecrypt) ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output + ); + +/** + Performs AES encryption on a data buffer of the specified size in CBC mode. + + This function performs AES encryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (16 bytes). + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES encryption succeeded. + @retval FALSE AES encryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_AES_CbcEncrypt) ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output + ); + +/** + Performs AES decryption on a data buffer of the specified size in CBC mode. + + This function performs AES decryption on data buffer pointed by Input, of specified + size of InputSize, in CBC mode. + InputSize must be multiple of block size (16 bytes). This function does not perform + padding. Caller must perform padding, if necessary, to ensure valid input data size. + Initialization vector should be one block size (16 bytes). + AesContext should be already correctly initialized by AesInit(). Behavior with + invalid AES context is undefined. + + If AesContext is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If InputSize is not multiple of block size (16 bytes), then return FALSE. + If Ivec is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in] AesContext Pointer to the AES context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[in] Ivec Pointer to initialization vector. + @param[out] Output Pointer to a buffer that receives the AES encryption output. + + @retval TRUE AES decryption succeeded. + @retval FALSE AES decryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_AES_CbcDecrypt) ( + IN VOID *AesContext, + IN CONST UINT8 *Input, + IN UINTN InputSize, + IN CONST UINT8 *Ivec, + OUT UINT8 *Output + ); + +/** + Retrieves the size, in bytes, of the context buffer required for ARC4 operations. + + If this interface is not supported, then return zero. + + @return The size, in bytes, of the context buffer required for ARC4 operations. + @retval 0 This interface is not supported. + +**/ +typedef +UINTN +(EFIAPI *SHAREDCRYPTO_ARC4_GetContextSize) ( + VOID + ); + +/** + Initializes user-supplied memory as ARC4 context for subsequent use. + + This function initializes user-supplied memory pointed by Arc4Context as ARC4 context. + In addition, it sets up all ARC4 key materials for subsequent encryption and decryption + operations. + + If Arc4Context is NULL, then return FALSE. + If Key is NULL, then return FALSE. + If KeySize does not in the range of [5, 256] bytes, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[out] Arc4Context Pointer to ARC4 context being initialized. + @param[in] Key Pointer to the user-supplied ARC4 key. + @param[in] KeySize Size of ARC4 key in bytes. + + @retval TRUE ARC4 context initialization succeeded. + @retval FALSE ARC4 context initialization failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_ARC4_Init) ( + OUT VOID *Arc4Context, + IN CONST UINT8 *Key, + IN UINTN KeySize + ); + +/** + Performs ARC4 encryption on a data buffer of the specified size. + + This function performs ARC4 encryption on data buffer pointed by Input, of specified + size of InputSize. + Arc4Context should be already correctly initialized by Arc4Init(). Behavior with + invalid ARC4 context is undefined. + + If Arc4Context is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Arc4Context Pointer to the ARC4 context. + @param[in] Input Pointer to the buffer containing the data to be encrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the ARC4 encryption output. + + @retval TRUE ARC4 encryption succeeded. + @retval FALSE ARC4 encryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_ARC4_Encrypt) ( + IN OUT VOID *Arc4Context, + IN CONST UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output + ); + +/** + Performs ARC4 decryption on a data buffer of the specified size. + + This function performs ARC4 decryption on data buffer pointed by Input, of specified + size of InputSize. + Arc4Context should be already correctly initialized by Arc4Init(). Behavior with + invalid ARC4 context is undefined. + + If Arc4Context is NULL, then return FALSE. + If Input is NULL, then return FALSE. + If Output is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Arc4Context Pointer to the ARC4 context. + @param[in] Input Pointer to the buffer containing the data to be decrypted. + @param[in] InputSize Size of the Input buffer in bytes. + @param[out] Output Pointer to a buffer that receives the ARC4 decryption output. + + @retval TRUE ARC4 decryption succeeded. + @retval FALSE ARC4 decryption failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_ARC4_Decrypt) ( + IN OUT VOID *Arc4Context, + IN UINT8 *Input, + IN UINTN InputSize, + OUT UINT8 *Output + ); + +/** + Resets the ARC4 context to the initial state. + + The function resets the ARC4 context to the state it had immediately after the + ARC4Init() function call. + Contrary to ARC4Init(), Arc4Reset() requires no secret key as input, but ARC4 context + should be already correctly initialized by ARC4Init(). + + If Arc4Context is NULL, then return FALSE. + If this interface is not supported, then return FALSE. + + @param[in, out] Arc4Context Pointer to the ARC4 context. + + @retval TRUE ARC4 reset succeeded. + @retval FALSE ARC4 reset failed. + @retval FALSE This interface is not supported. + +**/ +typedef +BOOLEAN +(EFIAPI *SHAREDCRYPTO_ARC4_Reset) ( + IN OUT VOID *Arc4Context + ); + +/// +struct _SHARED_CRYPTO_FUNCTIONS +{ + /// Shared Crypto Functions + SHAREDCRYPTO_GET_VERSION SharedCrypto_GetLowestSupportedVersion; + /// HMAC + SHAREDCRYPTO_HMAC_MD5_GetContextSize HMAC_MD5_GetContextSize; + SHAREDCRYPTO_HMAC_MD5_New HMAC_MD5_New; + SHAREDCRYPTO_HMAC_MD5_Free HMAC_MD5_Free; + SHAREDCRYPTO_HMAC_MD5_Init HMAC_MD5_Init; + SHAREDCRYPTO_HMAC_MD5_Duplicate HMAC_MD5_Duplicate; + SHAREDCRYPTO_HMAC_MD5_Update HMAC_MD5_Update; + SHAREDCRYPTO_HMAC_MD5_Final HMAC_MD5_Final; + SHAREDCRYPTO_HMAC_SHA1_GetContextSize HMAC_SHA1_GetContextSize; + SHAREDCRYPTO_HMAC_SHA1_New HMAC_SHA1_New; + SHAREDCRYPTO_HMAC_SHA1_Free HMAC_SHA1_Free; + SHAREDCRYPTO_HMAC_SHA1_Init HMAC_SHA1_Init; + SHAREDCRYPTO_HMAC_SHA1_Duplicate HMAC_SHA1_Duplicate; + SHAREDCRYPTO_HMAC_SHA1_Update HMAC_SHA1_Update; + SHAREDCRYPTO_HMAC_SHA1_Final HMAC_SHA1_Final; + SHAREDCRYPTO_HMAC_SHA256_GetContextSize HMAC_SHA256_GetContextSize; + SHAREDCRYPTO_HMAC_SHA256_New HMAC_SHA256_New; + SHAREDCRYPTO_HMAC_SHA256_Free HMAC_SHA256_Free; + SHAREDCRYPTO_HMAC_SHA256_Init HMAC_SHA256_Init; + SHAREDCRYPTO_HMAC_SHA256_Duplicate HMAC_SHA256_Duplicate; + SHAREDCRYPTO_HMAC_SHA256_Update HMAC_SHA256_Update; + SHAREDCRYPTO_HMAC_SHA256_Final HMAC_SHA256_Final; + /// Md4 + SHAREDCRYPTO_MD4_GetContextSize MD4_GetContextSize; + SHAREDCRYPTO_MD4_Init MD4_Init; + SHAREDCRYPTO_MD4_Duplicate MD4_Duplicate; + SHAREDCRYPTO_MD4_Update MD4_Update; + SHAREDCRYPTO_MD4_Final MD4_Final; + SHAREDCRYPTO_MD4_HashAll MD4_HashAll; + /// Md5 + SHAREDCRYPTO_MD5_GetContextSize MD5_GetContextSize; + SHAREDCRYPTO_MD5_Init MD5_Init; + SHAREDCRYPTO_MD5_Duplicate MD5_Duplicate; + SHAREDCRYPTO_MD5_Update MD5_Update; + SHAREDCRYPTO_MD5_Final MD5_Final; + SHAREDCRYPTO_MD5_HashAll MD5_HashAll; + /// Pkcs + SHAREDCRYPTO_PKCS1_ENCRYPT_V2 PKCS1_ENCRYPT_V2; + SHAREDCRYPTO_PKCS5_PW_HASH PKCS5_PW_HASH; + SHAREDCRYPTO_PKCS7_VERIFY PKCS7_VERIFY; + SHAREDCRYPTO_PKCS7_VERIFY_EKU PKCS7_VERIFY_EKU; + SHAREDCRYPTO_PKCS7_GetSigners PKCS7_GetSigners; + SHAREDCRYPTO_PKCS7_FreeSigners PKCS7_FreeSigners; + SHAREDCRYPTO_PKCS7_Sign PKCS7_Sign; + SHAREDCRYPTO_PKCS7_GetAttachedContent PKCS7_GetAttachedContent; + SHAREDCRYPTO_PKCS7_GetCertificatesList PKCS7_GetCertificatesList; + SHAREDCRYPTO_AuthenticodeVerify Authenticode_Verify; + SHAREDCRYPTO_ImageTimestampVerify Image_TimestampVerify; + /// DH + SHAREDCRYPTO_DH_New DH_New; + SHAREDCRYPTO_DH_Free DH_Free; + SHAREDCRYPTO_DH_GenerateParameter DH_GenerateParameter; + SHAREDCRYPTO_DH_SetParameter DH_SetParameter; + SHAREDCRYPTO_DH_GenerateKey DH_GenerateKey; + SHAREDCRYPTO_DH_ComputeKey DH_ComputeKey; + /// Random + SHAREDCRYPTO_RANDOM_Seed RANDOM_Seed; + SHAREDCRYPTO_RANDOM_Bytes RANDOM_Bytes; + /// RSA + SHAREDCRYPTO_RSA_VERIFY_PKCS1 RSA_VERIFY_PKCS1; + SHAREDCRYPTO_RSA_FREE RSA_FREE; + SHAREDCRYPTO_RSA_GET_PUBLIC_KEY_FROM_X509 RSA_GET_PUBLIC_KEY_FROM_X509; + SHAREDCRYPTO_RSA_New RSA_New; + SHAREDCRYPTO_RSA_Free RSA_Free; + SHAREDCRYPTO_RSA_SetKey RSA_SetKey; + SHAREDCRYPTO_RSA_GetKey RSA_GetKey; + SHAREDCRYPTO_RSA_GenerateKey RSA_GenerateKey; + SHAREDCRYPTO_RSA_CheckKey RSA_CheckKey; + SHAREDCRYPTO_RSA_Pkcs1Sign RSA_Pkcs1Sign; + SHAREDCRYPTO_RSA_Pkcs1Verify RSA_Pkcs1Verify; + SHAREDCRYPTO_RSA_GetPrivateKeyFromPem RSA_GetPrivateKeyFromPem; + SHAREDCRYPTO_RSA_GetPublicKeyFromX509 RSA_GetPublicKeyFromX509; + /// Sha protocol + SHAREDCRYPTO_SHA1_GET_CONTEXT_SIZE SHA1_GET_CONTEXT_SIZE; + SHAREDCRYPTO_SHA1_INIT SHA1_INIT; + SHAREDCRYPTO_SHA1_DUPLICATE SHA1_DUPLICATE; + SHAREDCRYPTO_SHA1_UPDATE SHA1_UPDATE; + SHAREDCRYPTO_SHA1_FINAL SHA1_FINAL; + SHAREDCRYPTO_SHA1_HASH_ALL SHA1_HASH_ALL; + SHAREDCRYPTO_SHA256_GET_CONTEXT_SIZE SHA256_GET_CONTEXT_SIZE; + SHAREDCRYPTO_SHA256_INIT SHA256_INIT; + SHAREDCRYPTO_SHA256_DUPLICATE SHA256_DUPLICATE; + SHAREDCRYPTO_SHA256_UPDATE SHA256_UPDATE; + SHAREDCRYPTO_SHA256_FINAL SHA256_FINAL; + SHAREDCRYPTO_SHA256_HASH_ALL SHA256_HASH_ALL; + SHAREDCRYPTO_SHA384_GetContextSize SHA384_GetContextSize; + SHAREDCRYPTO_SHA384_Init SHA384_Init; + SHAREDCRYPTO_SHA384_Duplicate SHA384_Duplicate; + SHAREDCRYPTO_SHA384_Update SHA384_Update; + SHAREDCRYPTO_SHA384_Final SHA384_Final; + SHAREDCRYPTO_SHA384_HashAll SHA384_HashAll; + SHAREDCRYPTO_SHA512_GetContextSize SHA512_GetContextSize; + SHAREDCRYPTO_SHA512_Init SHA512_Init; + SHAREDCRYPTO_SHA512_Duplicate SHA512_Duplicate; + SHAREDCRYPTO_SHA512_Update SHA512_Update; + SHAREDCRYPTO_SHA512_Final SHA512_Final; + SHAREDCRYPTO_SHA512_HashAll SHA512_HashAll; + /// X509 + SHAREDCRYPTO_X509_GET_SUBJECT_NAME X509_GET_SUBJECT_NAME; + SHAREDCRYPTO_X509_GET_COMMON_NAME X509_GET_COMMON_NAME; + SHAREDCRYPTO_X509_GET_ORGANIZATION_NAME X509_GET_ORGANIZATION_NAME; + SHAREDCRYPTO_X509_VerifyCert X509_VerifyCert; + SHAREDCRYPTO_X509_ConstructCertificate X509_ConstructCertificate; + SHAREDCRYPTO_X509_ConstructCertificateStack X509_ConstructCertificateStack; + SHAREDCRYPTO_X509_Free X509_Free; + SHAREDCRYPTO_X509_StackFree X509_StackFree; + SHAREDCRYPTO_X509_GetTBSCert X509_GetTBSCert; + /// TDES + SHAREDCRYPTO_TDES_GetContextSize TDES_GetContextSize; + SHAREDCRYPTO_TDES_Init TDES_Init; + SHAREDCRYPTO_TDES_EcbEncrypt TDES_EcbEncrypt; + SHAREDCRYPTO_TDES_EcbDecrypt TDES_EcbDecrypt; + SHAREDCRYPTO_TDES_CbcEncrypt TDES_CbcEncrypt; + SHAREDCRYPTO_TDES_CbcDecrypt TDES_CbcDecrypt; + /// AES + SHAREDCRYPTO_AES_GetContextSize AES_GetContextSize; + SHAREDCRYPTO_AES_Init AES_Init; + SHAREDCRYPTO_AES_EcbEncrypt AES_EcbEncrypt; + SHAREDCRYPTO_AES_EcbDecrypt AES_EcbDecrypt; + SHAREDCRYPTO_AES_CbcEncrypt AES_CbcEncrypt; + SHAREDCRYPTO_AES_CbcDecrypt AES_CbcDecrypt; + /// Arc4 + SHAREDCRYPTO_ARC4_GetContextSize ARC4_GetContextSize; + SHAREDCRYPTO_ARC4_Init ARC4_Init; + SHAREDCRYPTO_ARC4_Encrypt ARC4_Encrypt; + SHAREDCRYPTO_ARC4_Decrypt ARC4_Decrypt; + SHAREDCRYPTO_ARC4_Reset ARC4_Reset; +}; + +#endif \ No newline at end of file diff --git a/SharedCryptoPkg/Private/Protocol/SharedCryptoProtocol.h b/SharedCryptoPkg/Private/Protocol/SharedCryptoProtocol.h new file mode 100644 index 0000000000..fe6ea6d244 --- /dev/null +++ b/SharedCryptoPkg/Private/Protocol/SharedCryptoProtocol.h @@ -0,0 +1,38 @@ +/** @file +This Protocol is for Shared Crypto (DXE, SMM) + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: +1. Redistributions of source code must retain the above copyright notice, +this list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation +and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +**/ + +#include + +#ifndef __SHARED_CRYPTO_PROTOCOL_H__ +#define __SHARED_CRYPTO_PROTOCOL_H__ + +typedef struct _SHARED_CRYPTO_FUNCTIONS SHARED_CRYPTO_PROTOCOL; + +extern GUID gSharedCryptoSmmProtocolGuid; +extern GUID gSharedCryptoProtocolGuid; + +#endif diff --git a/SharedCryptoPkg/PublishDrivers.py b/SharedCryptoPkg/PublishDrivers.py new file mode 100644 index 0000000000..2b11363dda --- /dev/null +++ b/SharedCryptoPkg/PublishDrivers.py @@ -0,0 +1,133 @@ +## +# Tool to publish the cryptobin drivers to the nuget feed +# +# +# Copyright (c) 2018, Microsoft Corporation + +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +import sys +import os +from MuPythonLibrary import UtilityFunctions +from MuEnvironment import MuLogging +import logging +from shutil import copyfile +import shutil +import glob + +version = "20190411.0.2" + + +def CopyFile(srcDir, destDir, file_name): + copyfile(os.path.join(srcDir, file_name), os.path.join(destDir, file_name)) + + +def GetArchitecture(path: str): + path = os.path.normpath(path) + path_parts = path.split(os.path.sep) + return path_parts[1] + + +def GetTarget(path: str): + path = os.path.normpath(path) + path_parts = path.split(os.path.sep) + target = path_parts[0] + + if "_" in target: + return target.split("_")[0] + + return None + + +def MoveArchTargetSpecificFile(binary, offset, output_dir): + binary_path = binary[offset:] + binary_name = os.path.basename(binary) + binary_folder = os.path.dirname(binary) + arch = GetArchitecture(binary_path) + target = GetTarget(binary_path) + if target is None: + raise FileExistsError("Unknown file {0}".format(binary)) + dest_path = os.path.join(output_dir, target, arch) + dest_filepath = os.path.join(dest_path, binary_name) + if os.path.exists(dest_filepath): + logging.warning("Skipping {0}: {1} from {2}".format(binary_name, dest_filepath, binary)) + return + + if not os.path.exists(dest_path): + os.makedirs(dest_path) + # logging.warning("Copying {0}: {1}".format(binary_name,binary)) + CopyFile(binary_folder, dest_path, binary_name) + + +if __name__ == "__main__": + # get the root directory of mu_plus + scriptDir = os.path.dirname(os.path.realpath(__file__)) + driverDir = os.path.join(scriptDir, "Driver") + rootDir = os.path.dirname(scriptDir) + os.chdir(rootDir) # set ourselves to there + rootPath = os.path.realpath(os.path.join(rootDir, "ci.mu.yaml")) # get our yaml file + args = sys.argv + + if len(args) != 2: + raise RuntimeError("You need to include your API key as the first argument") + + api_key = args[1] + MuLogging.setup_console_logging(use_color=False, logging_level=logging.DEBUG) + # move the EFI's we generated to a folder to upload + NugetPath = os.path.join(rootDir, "MU_BASECORE", "BaseTools", "NugetPublishing") + NugetFilePath = os.path.join(NugetPath, "NugetPublishing.py") + if not os.path.exists(NugetFilePath): + raise FileNotFoundError(NugetFilePath) + + logging.info("Running NugetPackager") + output_dir = os.path.join(rootDir, "Build", ".NugetOutput") + + try: + if os.path.exists(output_dir): + shutil.rmtree(output_dir, ignore_errors=True) + os.makedirs(output_dir) + except: + logging.error("Ran into trouble getting Nuget Output Path setup") + + # copy the md file + CopyFile(driverDir, output_dir, "Mu-SharedCrypto.md") + + sharedcrypto_build_dir = os.path.realpath(os.path.join(rootDir, "Build", "SharedCryptoPkg")) + sharedcrypto_build_dir_offset = len(sharedcrypto_build_dir) + 1 + build_dir_efi_search = os.path.join(sharedcrypto_build_dir, "**", "SharedCrypto*.efi") + build_dir_dpx_search = os.path.join(sharedcrypto_build_dir, "**", "SharedCrypto*.depex") + build_dir_pdb_search = os.path.join(sharedcrypto_build_dir, "**", "SharedCrypto*.pdb") + logging.info("Searching {0}".format(build_dir_efi_search)) + for binary in glob.iglob(build_dir_efi_search, recursive=True): + MoveArchTargetSpecificFile(binary, sharedcrypto_build_dir_offset, output_dir) + + for depex in glob.iglob(build_dir_dpx_search, recursive=True): + MoveArchTargetSpecificFile(depex, sharedcrypto_build_dir_offset, output_dir) + + for pdb in glob.iglob(build_dir_pdb_search, recursive=True): + MoveArchTargetSpecificFile(pdb, sharedcrypto_build_dir_offset, output_dir) + + params = "--Operation PackAndPush --ConfigFilePath Mu-SharedCrypto.config.json --Version {2} --InputFolderPath {0} --ApiKey {1}".format(output_dir, api_key, version) + UtilityFunctions.RunPythonScript(NugetFilePath, params, capture=True, workingdir=driverDir) + + logging.critical("Finished") + # make sure diff --git a/SharedCryptoPkg/Readme.md b/SharedCryptoPkg/Readme.md new file mode 100644 index 0000000000..33df6859c3 --- /dev/null +++ b/SharedCryptoPkg/Readme.md @@ -0,0 +1,113 @@ +# Shared Crypto Package + +## Copyright + +Copyright (c) 2019, Microsoft Corporation + +All rights reserved. Redistribution and use in source and binary forms, with or +without modification, are permitted provided that the following conditions are +met: +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. +2. Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED +OF THE POSSIBILITY OF SUCH DAMAGE. + +## About + +The purpose of this package is to provide a wrapper around BaseCryptLib without having to compile the underlying Crypto Library. In the past, this was a source of pain in both compile times and FV size. + +The package is comprised of a Library Instance that is called SharedCryptoLib. It is contains all of the functions included by BaseCryptLib as well as a few more (mainly X509 related stuff). The library simply locates the protocol and then calls the protocol version of BaseCryptLib (SharedCryptoProtocol). It should be a drop in replacement for the BaseCryptLib. We have decided to hide the protocol headers to discourage users from directly accessing the protocol. The goal of this is to be a drop in replacement for BaseCryptLib. + +The protocol is installed by several prebuilt EFI that gets downloaded via nuget. The EFI is packaged for consumption via an INF that is loaded and installed. + +![Diagram showing dependencies](SharedCryptoPkg.png "Diagram") + + +## Flavors + +Additionally there are a few different "flavors" of SharedCrypto. The three main flavors are ShaOnly, Mu, and Full. ShaOnly only supports functions related to Sha1 and Sha256 and results in a very small EFI binary. The Mu flavor is the functions that are utilized in the platforms that depend on Project Mu and what we believe are the most practical functions. The full flavor supports all functions that BaseCryptLib does. When a function is called that a flavor doesn't have, the ProtocolFunctionNotFound method from the library is called and an assert is generated. + + +## Reproducibility + +For those wishing to verify for themselves that the packaged EFI's in the Nuget Feed match the code in this package can compile the Driver themselves by sing the SharedCryptoDriver.dsc or PublishDrivers.py. PublishDrivers is the same exact script that we run to update the package in Nuget. + +## Modifying + +If you wish to swap the underlying CryptoLibrary, replace the BaseCryptLib dependency in the DriverDSC with another version of BaseCryptLib that utilizes another library but conforms to the same interface. + +If you wish to use a different flavor or make a new flavor, create two new INF's. One for the Binary compilation (in the /Driver folder) and one for the Binary package that is consumed by the platform (in the /Package folder). By examining existing INF's, it should be fairly trival to create new ones. + +## Using Different Pre-built EFI's + +If you wish to use your own PreBuild EFI's, they can be placed in the /Package folder and have INF's point to them. Or the INF can be overridden fairly easily. + +## Building SharedCryptoPkg + +There are two pieces to be build: the library and the driver. The library is to be included in your project as BaseCryptLib. + +There are 24 different versions of the prebuild driver. One for each arch (X86, AARCH64, ARM, X64) and for each phase (DXE, PEI, SMM) and for mode (DEBUG, RELEASE). The nuget system should take care of downloading the correct version for your project. + +## Supported Architectures +This currently supports x86, x64, AARCH64, and ARM. + +## Including in your platform + +There are two ways to include this in your project: getting the protocol directly or using SharedCryptoLib. SharedCryptoLib is a wrapper that has the same API as BaseCryptLib so you can just drop it in. + + +## Sample DSC change + +This would replace where you would normally include BaseCryptLib. + +``` +[LibraryClasses.X64] + BaseCryptLib|SharedCryptoPkg/Library/SharedCryptoLib/SharedCryptoLibDxe.inf + ... + +[LibraryClasses.IA32.PEIM] + BaseCryptLib|SharedCryptoPkg/Library/SharedCryptoLib/SharedCryptoLibPei.inf + ... + +[LibraryClasses.DXE_SMM] + BaseCryptLib|SharedCryptoPkg/Library/SharedCryptoLib/SharedCryptoLibSmm.inf + ... +``` + +Unfortunatly, due to the way that the EDK build system works, you'll also need to include the package in your component section. + +``` +[Components.IA32] + SharedCryptoPkg/Package/SharedCryptoPkgPei.inf + ... + +[Components.X64] + SharedCryptoPkg/Package/SharedCryptoPkgDxe.inf + ... +``` + +Make sure that the flavor you're using in your FDF matches the flavor you include in your DSC. + +## Sample FDF change + +TODO: re-evluate this once nuget dependency is live +Include this file in your FV and the module will get loaded. + +``` +[FV.FVDXE] + INF SharedCryptoPkg/Package/SharedCryptoPkgDxe.inf + ... + ... +``` diff --git a/SharedCryptoPkg/SharedCryptoPkg.dec b/SharedCryptoPkg/SharedCryptoPkg.dec new file mode 100644 index 0000000000..7e47347de4 --- /dev/null +++ b/SharedCryptoPkg/SharedCryptoPkg.dec @@ -0,0 +1,51 @@ +## @file +# Package declaration file for SharedCryptoPkg Library and Driver +# +# Copyright (c) 2019, Microsoft Corporation + +# All rights reserved. +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + +[Defines] + DEC_SPECIFICATION = 0x00010005 + PACKAGE_NAME = SharedCryptoPkg + PACKAGE_UNI_FILE = SharedCryptoPkg.uni + PACKAGE_GUID = 0E9D6868-7D81-4A21-9785-BA1021F3F63B + PACKAGE_VERSION = 0.10 + + +[Includes.common.Private] + Private + +[Protocols] + ## Shared Crypto Dxe protocol + # 2C2275C9-3A7B-426F-BE54-2D22BD9D1092 + gSharedCryptoProtocolGuid = { 0x2C2275C9, 0x3A7B, 0x426F, { 0xBE, 0x54, 0x2D, 0x22, 0xBD, 0x9D, 0x10, 0x92 }} + + ## Shared Crypto SMM protocol + # F46B2EB2-E0D7-4C96-A3B1-CB7C572EB300 + gSharedCryptoSmmProtocolGuid = { 0xF46B2EB2, 0xE0D7, 0x4C96, { 0xA3, 0xB1, 0xc, 0x61, 0xbb, 0x24, 0x5c, 0x42 }} + + +[Ppis] + ## Shared Crypto PPI protocol + # 7DCE671B-C223-446A-A705-ED637AAF6771 + gSharedCryptoPpiGuid = { 0x7DCE671B, 0xC223, 0x446A, { 0xA7, 0x05, 0xED, 0x63, 0x7A, 0xAF, 0x67, 0x71 }} diff --git a/SharedCryptoPkg/SharedCryptoPkg.dsc b/SharedCryptoPkg/SharedCryptoPkg.dsc new file mode 100644 index 0000000000..553f3995e5 --- /dev/null +++ b/SharedCryptoPkg/SharedCryptoPkg.dsc @@ -0,0 +1,181 @@ + +## @file +# SharedCrypto Library and driver CI Build DSC +# +# This DSC is only for CI builds +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + PLATFORM_NAME = SharedCrypto + PLATFORM_GUID = A8692B37-52B7-4188-B75E-360E32D1EFB4 + PLATFORM_VERSION = .10 + DSC_SPECIFICATION = 0x0001001A + OUTPUT_DIRECTORY = Build/SharedCryptoPkg + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 + BUILD_TARGETS = DEBUG|RELEASE + SKUID_IDENTIFIER = DEFAULT + +[LibraryClasses] + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf + ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + + # unit test dependencies + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + + +[LibraryClasses.common.PEIM] + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf + DebugLib|MsCorePkg/Library/PeiDebugLib/PeiDebugLib.inf + BaseCryptLib|SharedCryptoPkg/Library/CryptLibSharedDriver/PeiCryptLibSharedDriver.inf + +[LibraryClasses.common.DXE_CORE] + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf + BaseCryptLib|SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.inf + CryptLibSharedDriver|SharedCryptoPkg/Library/CryptLibSharedDriver/DxeCryptLibSharedDriver.inf + +[LibraryClasses.common.DXE_SMM_DRIVER] + BaseCryptLib|SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.inf + CryptLibSharedDriver|SharedCryptoPkg/Library/CryptLibSharedDriver/SmmCryptLibSharedDriver.inf + + +[LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_RUNTIME_DRIVER,LibraryClasses.common.DXE_SMM_DRIVER] + BaseBinSecurityLibRng|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + +[LibraryClasses.common.DXE_SMM_DRIVER] + SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf + MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf + ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf + + +[LibraryClasses.IA32] + NULL|MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf + + +# build the test app if needed +[LibraryClasses.X64] + NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf + BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf + +[LibraryClasses.X64.UEFI_APPLICATION] + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + + UnitTestLib|MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf + UnitTestLogLib|MsUnitTestPkg/Library/UnitTestLogLib/UnitTestLogLib.inf + UnitTestAssertLib|MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssertLib.inf + UnitTestPersistenceLib|MsUnitTestPkg/Library/UnitTestPersistenceFileSystemLib/UnitTestPersistenceFileSystemLib.inf + UnitTestBootUsbLib|MsUnitTestPkg/Library/UnitTestBootUsbClassLib/UnitTestBootUsbClassLib.inf + UnitTestResultReportLib|MsUnitTestPkg/Library/UnitTestResultReportPlainTextOutputLib/UnitTestResultReportLib.inf + + + +[Components.X64, Components.AARCH64, Components.ARM, Components.AARCH64] + #SharedCryptoPkg/UnitTests/PkcsUnitTestApp/PkcsUnitTestApp.inf + #SharedCryptoPkg/UnitTests/HmacUnitTestApp/UnitTestApp.inf + #SharedCryptoPkg/UnitTests/RandomUnitTestApp/UnitTestApp.inf + #SharedCryptoPkg/UnitTests/ShaUnitTestApp/UnitTestApp.inf + #SharedCryptoPkg/UnitTests/RsaUnitTestApp/UnitTestApp.inf + #SharedCryptoPkg/UnitTests/X509UnitTestApp/UnitTestApp.inf + +[Components.IA32, Components.ARM, Components.X64, Components.AARCH64] + SharedCryptoPkg/Driver/SharedCryptoPeiShaOnly.inf { + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + } + +[Components.X64, Components.AARCH64, Components.IA32] + SharedCryptoPkg/Driver/SharedCryptoDxe.inf { + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + } + + SharedCryptoPkg/Driver/SharedCryptoDxeMu.inf { + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + } + +[Components.X64.DXE_SMM_DRIVER] + SharedCryptoPkg/Driver/SharedCryptoSmm.inf { + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + } + + SharedCryptoPkg/Driver/SharedCryptoSmmMu.inf { + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + } + + +[BuildOptions.X64] + MSFT:*_*_*_CC_FLAGS = /FAcs /X /GS diff --git a/SharedCryptoPkg/SharedCryptoPkg.mu.yaml b/SharedCryptoPkg/SharedCryptoPkg.mu.yaml new file mode 100644 index 0000000000..e441ec62c9 --- /dev/null +++ b/SharedCryptoPkg/SharedCryptoPkg.mu.yaml @@ -0,0 +1,18 @@ +{ + "CompilerPlugin": { + "IgnoreInf": [] + }, + "DependencyCheck": { + "AcceptableDependencies": [ + "MdePkg/MdePkg.dec", + "MdeModulePkg/MdeModulePkg.dec", + "CryptoPkg/CryptoPkg.dec" + ], + "IgnoreInf": [] + }, + "DSCCheck": { + "skip":"true", + "IgnoreInf": [] + + } +} \ No newline at end of file diff --git a/SharedCryptoPkg/SharedCryptoPkg.png b/SharedCryptoPkg/SharedCryptoPkg.png new file mode 100644 index 0000000000..6fa178981e Binary files /dev/null and b/SharedCryptoPkg/SharedCryptoPkg.png differ diff --git a/SharedCryptoPkg/SharedCryptoPkg.uni b/SharedCryptoPkg/SharedCryptoPkg.uni new file mode 100644 index 0000000000..3340dfba11 --- /dev/null +++ b/SharedCryptoPkg/SharedCryptoPkg.uni @@ -0,0 +1,34 @@ +// /** @file +// This Package provides all definitions, library classes and libraries instances for SharedCryptoPkg. +// SharedCryptoPkg has both a driver and a library that supports Crypto Functions +// It conforms to the same interface as BaseCryptLib +// This is targetted at promoting to open source and should be aligned with +// Tianocore standards +// +// Copyright (c) 2019, Microsoft Corporation +// +// All rights reserved. +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// 1. Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. + +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +// IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +// OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// **/ + + +#string STR_PACKAGE_ABSTRACT #language en-US "This Package provides all definitions, library classes and libraries instances for Shared Crypto." + +#string STR_PACKAGE_DESCRIPTION #language en-US "Shared Crypto is common code used in the Microsoft UEFI Core code base" \ No newline at end of file diff --git a/SharedCryptoPkg/SharedCryptoPkgDriver.dsc b/SharedCryptoPkg/SharedCryptoPkgDriver.dsc new file mode 100644 index 0000000000..7e6f887066 --- /dev/null +++ b/SharedCryptoPkg/SharedCryptoPkgDriver.dsc @@ -0,0 +1,154 @@ + +## @file +# SharedCrypto Library and driver +# +# Copyright (c) 2019, Microsoft Corporation +# +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE +# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +## + + +[Defines] + PLATFORM_NAME = SharedCryptoDrivers + PLATFORM_GUID = FA7B48DB-316A-45D6-A52F-5CD9662F4565 + PLATFORM_VERSION = .10 + DSC_SPECIFICATION = 0x0001001A + OUTPUT_DIRECTORY = Build/SharedCryptoPkg_Driver + SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64 + BUILD_TARGETS = DEBUG|RELEASE + SKUID_IDENTIFIER = DEFAULT +# DEBUG_OUTPUT_ENABLED = TRUE + + +[LibraryClasses] + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf + DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + ReportStatusCodeLib|MdePkg/Library/BaseReportStatusCodeLibNull/BaseReportStatusCodeLibNull.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + SharedCryptoLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf + IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf + BaseBinSecurityLibRng|MdePkg/Library/BaseBinSecurityLibNull/BaseBinSecurityLibNull.inf + RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf + +[LibraryClasses.common.PEIM] + PeimEntryPoint|MdePkg/Library/PeimEntryPoint/PeimEntryPoint.inf + MemoryAllocationLib|MdePkg/Library/PeiMemoryAllocationLib/PeiMemoryAllocationLib.inf + PeiServicesTablePointerLib|MdePkg/Library/PeiServicesTablePointerLib/PeiServicesTablePointerLib.inf + ExtractGuidedSectionLib|MdePkg/Library/PeiExtractGuidedSectionLib/PeiExtractGuidedSectionLib.inf + PeiServicesLib|MdePkg/Library/PeiServicesLib/PeiServicesLib.inf + HobLib|MdePkg/Library/PeiHobLib/PeiHobLib.inf + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/SecPeiDebugAgentLib.inf + DebugLib|MsCorePkg/Library/PeiDebugLib/PeiDebugLib.inf + PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf + +[LibraryClasses.common.DXE_CORE] + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf + DebugAgentLib|SourceLevelDebugPkg/Library/DebugAgent/DxeDebugAgentLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf + + +[LibraryClasses.common.DXE_DRIVER, LibraryClasses.common.DXE_RUNTIME_DRIVER,LibraryClasses.common.DXE_SMM_DRIVER] + BaseBinSecurityLibRng|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf + +[LibraryClasses.common.DXE_SMM_DRIVER] + SmmServicesTableLib|MdePkg/Library/SmmServicesTableLib/SmmServicesTableLib.inf + MemoryAllocationLib|MdePkg/Library/SmmMemoryAllocationLib/SmmMemoryAllocationLib.inf + BaseMemoryLib|MdePkg/Library/BaseMemoryLibOptDxe/BaseMemoryLibOptDxe.inf + ReportStatusCodeLib|MdeModulePkg/Library/SmmReportStatusCodeLib/SmmReportStatusCodeLib.inf + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + DebugLib|MdeModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf + +[LibraryClasses.X64, LibraryClasses.IA32] + NULL|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf + BaseBinSecurityLib|MdePkg/Library/BaseBinSecurityLibRng/BaseBinSecurityLibRng.inf + +!ifdef DEBUG_OUTPUT_ENABLED +[LibraryClasses] + OemHookStatusCodeLib|MdeModulePkg/Library/OemHookStatusCodeLibNull/OemHookStatusCodeLibNull.inf +[LibraryClasses.common.DXE_CORE] + DebugLib|MdePkg/Library/UefiDebugLibDebugPortProtocol/UefiDebugLibDebugPortProtocol.inf +[LibraryClasses.common.PEIM] + DebugLib|MsCorePkg/Library/PeiDebugLib/PeiDebugLib.inf + ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf +[LibraryClasses.X64] + ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf + +[PcdsFixedAtBuild] + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x3F + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x7 + gEfiMdePkgTokenSpaceGuid.PcdFixedDebugPrintErrorLevel|0x800802C6 +!endif + + +[LibraryClasses.common] + +[LibraryClasses.IA32] + NULL|MdePkg/Library/VsIntrinsicLib/VsIntrinsicLib.inf + +[LibraryClasses.ARM] + ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf + +[LibraryClasses.common.PEIM] + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf + +[LibraryClasses.common.DXE_DRIVER] + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + +[LibraryClasses.common.DXE_RUNTIME_DRIVER] + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf + +[LibraryClasses.common.DXE_SMM_DRIVER] + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf + +[LibraryClasses.common.UEFI_DRIVER] + BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf + +[Components.IA32, Components.ARM, Components.X64, Components.AARCH64] + SharedCryptoPkg/Driver/SharedCryptoPeiShaOnly.inf + +[Components.X64, Components.AARCH64, Components.IA32] + SharedCryptoPkg/Driver/SharedCryptoDxe.inf + SharedCryptoPkg/Driver/SharedCryptoDxeMu.inf + +[Components.X64.DXE_SMM_DRIVER] + SharedCryptoPkg/Driver/SharedCryptoSmm.inf + SharedCryptoPkg/Driver/SharedCryptoSmmMu.inf + +[BuildOptions.X64] + #MSFT:*_*_*_CC_FLAGS = /FAcs /X /GS diff --git a/SharedCryptoPkg/tools_def.txt b/SharedCryptoPkg/tools_def.txt new file mode 100644 index 0000000000..12572b710d --- /dev/null +++ b/SharedCryptoPkg/tools_def.txt @@ -0,0 +1,703 @@ +# +# Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
+# Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.
+# Portions copyright (c) 2011 - 2014, ARM Ltd. All rights reserved.
+# Copyright (c) 2015, Hewlett-Packard Development Company, L.P.
+# (C) Copyright 2016 Hewlett Packard Enterprise Development LP
+# Copyright (c) 2017, Microsoft Corporation +# +# 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 +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +# +#Increase this version tag any time you want user to get warning about updating this file in the Conf dir. By default it does not do update existing conf dirs. +# +# +# 1.06 - Updated VS2015 64 dlink flags to set to 4kb aligned for MAT support. This matches changes needed for vs2013 made earlier +# 1.07 - Updated VS2015 & VS2013 Build flags to remove /GS- option for DEBUG builds, thus enabling StackCookies +# +# 1.08 - Updated Iasl and Link16.exe path +# 1.09 - ARM/ARM64 tools update +# 1.10 - VS2017 + Gw +# 1.13 - Updated SDK Ver with version currently installed from microsoft website +# 1.14 - Created VSLATESTx86 for supporting latest VS version +# 1.15 - Added ARM,ARM64 proper for prerelease of VS2017 tools. +# 1.16 - Changed /DEBUG to FULL mode for VS2017+ +# 1.17 - Asl compilers should be on the path +# 1.18 - Remove VS2013 support +# 1.19 - RC.exe from Windows 10 Kit + +#!VERSION=1.19 + +IDENTIFIER = Default TOOL_CHAIN_CONF + +# +# VS2015 +DEFINE VS2015x86_BIN = ENV(VS140COMNTOOLS)\..\..\Vc\Bin +#//C:\Program Files (x86)\Microsoft Visual Studio 14.0\Vc\bin +DEFINE VS2015x86_DLL = ENV(VS140COMNTOOLS)\..\IDE;DEF(VS2015x86_BIN) +#//C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE;DEF(VS2015x86_BIN) +DEFINE VS2015x86_BINX64 = DEF(VS2015x86_BIN)\x86_amd64 + +# +# VS2017 - New model for VS2017 where there is potential for many versions of the tools. +# If a specific version is required then the user must set both env variables: +## VS150INSTALLPATH: base install path on system to VC install dir. Here you will find the Common7 folder, VC folder, etc +## VS150TOOLVER: version number for the VC compiler tools +## VS2017x86_DLL - x86 tools dir must come first before common7/ide folder. + +DEFINE VS2017x86_BIN = ENV(VS150INSTALLPATH)\VC\Tools\MSVC\ENV(VS150TOOLVER)\bin\HostX86\x86 +DEFINE VS2017x86_DLL = DEF(VS2017x86_BIN);ENV(VS150INSTALLPATH)\Common7\IDE +DEFINE VS2017x86_BINX64 = ENV(VS150INSTALLPATH)\VC\Tools\MSVC\ENV(VS150TOOLVER)\bin\HostX86\x64 +DEFINE VS2017x86_BINARM = ENV(VS150INSTALLPATH)\VC\Tools\MSVC\ENV(VS150TOOLVER)\bin\HostX86\arm +DEFINE VS2017x86_BINA64 = ENV(VS150INSTALLPATH)\VC\Tools\MSVC\ENV(VS150TOOLVER)\bin\HostX86\arm64 + +DEFINE WINSDK_VERSION = 10.0.17134.0 +DEFINE WINSDK_BIN = c:\Program Files (x86)\Windows Kits\10\bin\DEF(WINSDK_VERSION)\x64 +DEFINE WINSDKx86_BIN = c:\Program Files (x86)\Windows Kits\10\bin\DEF(WINSDK_VERSION)\x86 + +DEFINE WIN_IASL_BIN = iasl.exe +DEFINE WIN_ASL_BIN = asl.exe + +DEFINE IASL_FLAGS = +DEFINE IASL_OUTFLAGS = -p +DEFINE MS_ASL_OUTFLAGS = /Fo= +DEFINE MS_ASL_FLAGS = + +#Intel +DEFINE DEFAULT_WIN_ASL_BIN = DEF(WIN_IASL_BIN) +DEFINE DEFAULT_WIN_ASL_FLAGS = DEF(IASL_FLAGS) +DEFINE DEFAULT_WIN_ASL_OUTFLAGS = DEF(IASL_OUTFLAGS) +#DEFINE DEFAULT_WIN_ASL_BIN = DEF(WIN_ASL_BIN) +#DEFINE DEFAULT_WIN_ASL_FLAGS = DEF(MS_ASL_FLAGS) +#DEFINE DEFAULT_WIN_ASL_OUTFLAGS = DEF(MS_ASL_OUTFLAGS) + +DEFINE MSFT_ASLPP_FLAGS = /nologo /E /C /FIAutoGen.h +DEFINE MSFT_ASLCC_FLAGS = /nologo /c /FIAutoGen.h /TC /Dmain=ReferenceAcpiTable +DEFINE MSFT_ASLDLINK_FLAGS = /NODEFAULTLIB /ENTRY:ReferenceAcpiTable /SUBSYSTEM:CONSOLE + + +#################################################################################### +# +# format: TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE = +# priority: +# TARGET_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE (Highest) +# ******_TOOLCHAIN_ARCH_COMMANDTYPE_ATTRIBUTE +# TARGET_*********_ARCH_COMMANDTYPE_ATTRIBUTE +# ******_*********_ARCH_COMMANDTYPE_ATTRIBUTE +# TARGET_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE +# ******_TOOLCHAIN_****_COMMANDTYPE_ATTRIBUTE +# TARGET_*********_****_COMMANDTYPE_ATTRIBUTE +# ******_*********_****_COMMANDTYPE_ATTRIBUTE +# TARGET_TOOLCHAIN_ARCH_***********_ATTRIBUTE +# ******_TOOLCHAIN_ARCH_***********_ATTRIBUTE +# TARGET_*********_ARCH_***********_ATTRIBUTE +# ******_*********_ARCH_***********_ATTRIBUTE +# TARGET_TOOLCHAIN_****_***********_ATTRIBUTE +# ******_TOOLCHAIN_****_***********_ATTRIBUTE +# TARGET_*********_****_***********_ATTRIBUTE +# ******_*********_****_***********_ATTRIBUTE (Lowest) +# +#################################################################################### +#################################################################################### +# +# Supported Tool Chains +# ===================== +# VS2015x86 -win64- Requires: +# Microsoft Visual Studio 2015 (x86) Professional Edition +# Microsoft Windows Server 2003 Driver Development Kit (Microsoft WINDDK) version 3790.1830 +# Optional: +# Required to build platforms or ACPI tables: +# Intel(r) ACPI Compiler (iasl.exe) from +# https://acpica.org/downloads +# +#################################################################################### +#################################################################################### +# +# Supported Tool Chain Family +# =========================== +# MSFT - Microsoft +# GCC - GNU GCC +# INTEL - INTEL +# RVCT - ARM RealView Toolchain +#################################################################################### +#################################################################################### +# +# Other Supported Tools +# ===================== +# NASM -- http://www.nasm.us/ +# - NASM 2.10 or later for use with the GCC toolchain family +# - NASM 2.12.01 or later for use with all other toolchain families +# +#################################################################################### +#################################################################################### +# +# Intel EFI Byte Code Compiler (Template) +# +#################################################################################### +# *_*_EBC_*_FAMILY = INTEL +# +# *_*_EBC_PP_PATH = C:\Program Files\Intel\EBC\Bin\iec.exe +# *_*_EBC_CC_PATH = C:\Program Files\Intel\EBC\Bin\iec.exe +# *_*_EBC_SLINK_PATH = C:\Program Files\Intel\EBC\Bin\link.exe +# +# *_*_EBC_SLINK_FLAGS = /lib /NOLOGO /MACHINE:EBC +# *_*_EBC_PP_FLAGS = /nologo /E /TC /FI$(DEST_DIR_DEBUG)/AutoGen.h +# *_*_EBC_CC_FLAGS = /nologo /FAcs /c /W3 /WX /FI$(DEST_DIR_DEBUG)/AutoGen.h +# *_*_EBC_DLINK_FLAGS = "C:\Program Files\Intel\EBC\Lib\EbcLib.lib" /NOLOGO /MACHINE:EBC /OPT:REF /NODEFAULTLIB /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /ALIGN:32 /DRIVER +# +#################################################################################### + +#################################################################################### +# VS2015x86 - Microsoft Visual Studio 2015 (x86) professional with Intel ASL +# ASL - Intel ACPI Source Language Compiler (iasl.exe) +#################################################################################### +# VS2015x86 - Microsoft Visual Studio 2015 (x86) professional Edition with Intel ASL +*_VS2015x86_*_*_FAMILY = MSFT + +*_VS2015x86_*_MAKE_PATH = DEF(VS2015x86_BIN)\nmake.exe +*_VS2015x86_*_MAKE_FLAG = /nologo +*_VS2015x86_*_RC_PATH = DEF(WINSDKx86_BIN)\rc.exe + +*_VS2015x86_*_MAKE_FLAGS = /nologo +*_VS2015x86_*_SLINK_FLAGS = /NOLOGO /LTCG +*_VS2015x86_*_APP_FLAGS = /nologo /E /TC +*_VS2015x86_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h +*_VS2015x86_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h + +*_VS2015x86_*_ASM16_PATH = DEF(VS2015x86_BIN)\ml.exe + +################## +# ASL definitions +################## +*_VS2015x86_*_ASL_PATH = DEF(WIN_IASL_BIN) +*_VS2015x86_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) +*_VS2015x86_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) +*_VS2015x86_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) +*_VS2015x86_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) +*_VS2015x86_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) + +################## +# IA32 definitions +################## +*_VS2015x86_IA32_*_DLL = DEF(VS2015x86_DLL) + +*_VS2015x86_IA32_MAKE_PATH = DEF(VS2015x86_BIN)\nmake.exe +*_VS2015x86_IA32_CC_PATH = DEF(VS2015x86_BIN)\cl.exe +*_VS2015x86_IA32_VFRPP_PATH = DEF(VS2015x86_BIN)\cl.exe +*_VS2015x86_IA32_ASLCC_PATH = DEF(VS2015x86_BIN)\cl.exe +*_VS2015x86_IA32_ASLPP_PATH = DEF(VS2015x86_BIN)\cl.exe +*_VS2015x86_IA32_SLINK_PATH = DEF(VS2015x86_BIN)\lib.exe +*_VS2015x86_IA32_DLINK_PATH = DEF(VS2015x86_BIN)\link.exe +*_VS2015x86_IA32_ASLDLINK_PATH= DEF(VS2015x86_BIN)\link.exe +*_VS2015x86_IA32_APP_PATH = DEF(VS2015x86_BIN)\cl.exe +*_VS2015x86_IA32_PP_PATH = DEF(VS2015x86_BIN)\cl.exe +*_VS2015x86_IA32_ASM_PATH = DEF(VS2015x86_BIN)\ml.exe + + *_VS2015x86_IA32_MAKE_FLAGS = /nologo + DEBUG_VS2015x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Gw +RELEASE_VS2015x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VS2015x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Od /Gw + + DEBUG_VS2015x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi +RELEASE_VS2015x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd +NOOPT_VS2015x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi + + DEBUG_VS2015x86_IA32_NASM_FLAGS = -Ox -f win32 -g +RELEASE_VS2015x86_IA32_NASM_FLAGS = -Ox -f win32 +NOOPT_VS2015x86_IA32_NASM_FLAGS = -O0 -f win32 -g + + DEBUG_VS2015x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG +RELEASE_VS2015x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG /MERGE:.rdata=.data +NOOPT_VS2015x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG + +################## +# X64 definitions +################## +*_VS2015x86_X64_*_DLL = DEF(VS2015x86_DLL) + +*_VS2015x86_X64_CC_PATH = DEF(VS2015x86_BINX64)\cl.exe +*_VS2015x86_X64_PP_PATH = DEF(VS2015x86_BINX64)\cl.exe +*_VS2015x86_X64_APP_PATH = DEF(VS2015x86_BINX64)\cl.exe +*_VS2015x86_X64_VFRPP_PATH = DEF(VS2015x86_BINX64)\cl.exe +*_VS2015x86_X64_ASLCC_PATH = DEF(VS2015x86_BINX64)\cl.exe +*_VS2015x86_X64_ASLPP_PATH = DEF(VS2015x86_BINX64)\cl.exe +*_VS2015x86_X64_ASM_PATH = DEF(VS2015x86_BINX64)\ml64.exe +*_VS2015x86_X64_SLINK_PATH = DEF(VS2015x86_BINX64)\lib.exe +*_VS2015x86_X64_DLINK_PATH = DEF(VS2015x86_BINX64)\link.exe +*_VS2015x86_X64_ASLDLINK_PATH = DEF(VS2015x86_BINX64)\link.exe + + DEBUG_VS2015x86_X64_CC_FLAGS = /nologo /c /WX /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Gw +RELEASE_VS2015x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VS2015x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /Gw + + DEBUG_VS2015x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi +RELEASE_VS2015x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd +NOOPT_VS2015x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi + + DEBUG_VS2015x86_X64_NASM_FLAGS = -Ox -f win64 -g +RELEASE_VS2015x86_X64_NASM_FLAGS = -Ox -f win64 +NOOPT_VS2015x86_X64_NASM_FLAGS = -O0 -f win64 -g + + DEBUG_VS2015x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG +RELEASE_VS2015x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG +NOOPT_VS2015x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG + + +#################################################################################### +# VS2017x86 - Microsoft Visual Studio 2017 (x86) professional with Intel ASL +# ASL - Intel ACPI Source Language Compiler (iasl.exe) +#################################################################################### +# VS2017x86 - Microsoft Visual Studio 2017 (x86) professional Edition with Intel ASL +*_VS2017x86_*_*_FAMILY = MSFT + +*_VS2017x86_*_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VS2017x86_*_MAKE_FLAG = /nologo +*_VS2017x86_*_RC_PATH = DEF(WINSDKx86_BIN)\rc.exe + +*_VS2017x86_*_MAKE_FLAGS = /nologo +*_VS2017x86_*_SLINK_FLAGS = /NOLOGO /LTCG +*_VS2017x86_*_APP_FLAGS = /nologo /E /TC +*_VS2017x86_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h +*_VS2017x86_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h + +*_VS2017x86_*_ASM16_PATH = DEF(VS2017x86_BIN)\ml.exe + +################## +# ASL definitions +################## +*_VS2017x86_*_ASL_PATH = DEF(WIN_IASL_BIN) +*_VS2017x86_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) +*_VS2017x86_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) +*_VS2017x86_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) +*_VS2017x86_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) +*_VS2017x86_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) + +################## +# IA32 definitions +################## +#*_VS2017x86_IA32_*_DLL = DEF(VS2017x86_DLL) + +*_VS2017x86_IA32_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VS2017x86_IA32_CC_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VS2017x86_IA32_VFRPP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VS2017x86_IA32_ASLCC_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VS2017x86_IA32_ASLPP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VS2017x86_IA32_SLINK_PATH = DEF(VS2017x86_BIN)\lib.exe +*_VS2017x86_IA32_DLINK_PATH = DEF(VS2017x86_BIN)\link.exe +*_VS2017x86_IA32_ASLDLINK_PATH= DEF(VS2017x86_BIN)\link.exe +*_VS2017x86_IA32_APP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VS2017x86_IA32_PP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VS2017x86_IA32_ASM_PATH = DEF(VS2017x86_BIN)\ml.exe + + *_VS2017x86_IA32_MAKE_FLAGS = /nologo + DEBUG_VS2017x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Gw +RELEASE_VS2017x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VS2017x86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Od /Gw + + DEBUG_VS2017x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi +RELEASE_VS2017x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd +NOOPT_VS2017x86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi + + DEBUG_VS2017x86_IA32_NASM_FLAGS = -Ox -f win32 -g +RELEASE_VS2017x86_IA32_NASM_FLAGS = -Ox -f win32 +NOOPT_VS2017x86_IA32_NASM_FLAGS = -O0 -f win32 -g + + DEBUG_VS2017x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VS2017x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL /MERGE:.rdata=.data +NOOPT_VS2017x86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + +################## +# X64 definitions +################## +*_VS2017x86_X64_*_DLL = DEF(VS2017x86_DLL) + +*_VS2017x86_X64_CC_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VS2017x86_X64_PP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VS2017x86_X64_APP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VS2017x86_X64_VFRPP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VS2017x86_X64_ASLCC_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VS2017x86_X64_ASLPP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VS2017x86_X64_ASM_PATH = DEF(VS2017x86_BINX64)\ml64.exe +*_VS2017x86_X64_SLINK_PATH = DEF(VS2017x86_BINX64)\lib.exe +*_VS2017x86_X64_DLINK_PATH = DEF(VS2017x86_BINX64)\link.exe +*_VS2017x86_X64_ASLDLINK_PATH = DEF(VS2017x86_BINX64)\link.exe + + DEBUG_VS2017x86_X64_CC_FLAGS = /nologo /c /WX /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Gw +RELEASE_VS2017x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VS2017x86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /GL /Gw + + DEBUG_VS2017x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi +RELEASE_VS2017x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd +NOOPT_VS2017x86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi + + DEBUG_VS2017x86_X64_NASM_FLAGS = -Ox -f win64 -g +RELEASE_VS2017x86_X64_NASM_FLAGS = -Ox -f win64 +NOOPT_VS2017x86_X64_NASM_FLAGS = -O0 -f win64 -g + + DEBUG_VS2017x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VS2017x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER +NOOPT_VS2017x86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + +################## +# ARM definitions +################## +*_VS2017x86_ARM_*_DLL = DEF(VS2017x86_DLL) + +*_VS2017x86_ARM_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VS2017x86_ARM_CC_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VS2017x86_ARM_PP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VS2017x86_ARM_APP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VS2017x86_ARM_VFRPP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VS2017x86_ARM_ASLCC_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VS2017x86_ARM_ASLPP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VS2017x86_ARM_ASM_PATH = DEF(VS2017x86_BINARM)\armasm.exe +*_VS2017x86_ARM_SLINK_PATH = DEF(VS2017x86_BINARM)\link.exe +*_VS2017x86_ARM_DLINK_PATH = DEF(VS2017x86_BINARM)\link.exe +*_VS2017x86_ARM_ASLDLINK_PATH = DEF(VS2017x86_BINARM)\link.exe + +*_VS2017x86_ARM_SLINK_FLAGS = /LIB /machine:ARM /SUBSYSTEM:WINDOWSCE + + *_VS2017x86_ARM_MAKE_FLAGS = /nologo + DEBUG_VS2017x86_ARM_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /wd4127 /wd4214 /wd4100 /wd4201 /wd4702 +RELEASE_VS2017x86_ARM_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /wd4127 /wd4214 /wd4100 /wd4201 /wd4702 +NOOPT_VS2017x86_ARM_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Od /wd4127 /wd4214 /wd4100 /wd4201 /wd4702 + + DEBUG_VS2017x86_ARM_ASM_FLAGS = -nologo -g -32 -machine ARMCE +RELEASE_VS2017x86_ARM_ASM_FLAGS = -nologo -32 -machine ARMCE +NOOPT_VS2017x86_ARM_ASM_FLAGS = -nologo -g -32 -machine ARMCE + +# +# for SEC file/section alignment and XIP, use file type buildoptions +# +# ex: [BuildOptions.common.EDKII.SEC] +# + DEBUG_VS2017x86_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VS2017x86_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VS2017x86_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + + +################## +# AARCH64 definitions +################## + +*_VS2017x86_AARCH64_*_DLL = DEF(VS2017x86_DLL) + +*_VS2017x86_AARCH64_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VS2017x86_AARCH64_CC_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VS2017x86_AARCH64_PP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VS2017x86_AARCH64_APP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VS2017x86_AARCH64_VFRPP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VS2017x86_AARCH64_ASLCC_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VS2017x86_AARCH64_ASLPP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VS2017x86_AARCH64_ASM_PATH = DEF(VS2017x86_BINA64)\armasm64.exe +*_VS2017x86_AARCH64_SLINK_PATH = DEF(VS2017x86_BINA64)\lib.exe +*_VS2017x86_AARCH64_DLINK_PATH = DEF(VS2017x86_BINA64)\link.exe +*_VS2017x86_AARCH64_ASLDLINK_PATH = DEF(VS2017x86_BINA64)\link.exe + + DEBUG_VS2017x86_AARCH64_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /wd4214 /wd4127 /wd4100 /wd4312 /wd4702 +RELEASE_VS2017x86_AARCH64_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /wd4214 /wd4127 /wd4100 /wd4312 /wd4702 +NOOPT_VS2017x86_AARCH64_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /wd4702 + + DEBUG_VS2017x86_AARCH64_ASM_FLAGS = -g +RELEASE_VS2017x86_AARCH64_ASM_FLAGS = +NOOPT_VS2017x86_AARCH64_ASM_FLAGS = -g + +# +# for SEC file/section alignment and XIP, use file type buildoptions +# +# ex: [BuildOptions.common.EDKII.SEC] +# + DEBUG_VS2017x86_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /RunBelow4GB /IGNORE:4001 /IGNORE:4226 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /Machine:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VS2017x86_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /RunBelow4GB /IGNORE:4001 /IGNORE:4254 /IGNORE:4226 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /Machine:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VS2017x86_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /RunBelow4GB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /Machine:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + +#################################################################################### +# VSLATESTx86 - Microsoft Visual Studio Latest with Intel ASL (always moving to latest tools) +# ASL - Intel ACPI Source Language Compiler (iasl.exe) +#################################################################################### +*_VSLATESTx86_*_*_FAMILY = MSFT + +*_VSLATESTx86_*_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VSLATESTx86_*_MAKE_FLAG = /nologo +*_VSLATESTx86_*_RC_PATH = DEF(WINSDKx86_BIN)\rc.exe + +*_VSLATESTx86_*_MAKE_FLAGS = /nologo +*_VSLATESTx86_*_SLINK_FLAGS = /NOLOGO /LTCG +*_VSLATESTx86_*_APP_FLAGS = /nologo /E /TC +*_VSLATESTx86_*_PP_FLAGS = /nologo /E /TC /FIAutoGen.h +*_VSLATESTx86_*_VFRPP_FLAGS = /nologo /E /TC /DVFRCOMPILE /FI$(MODULE_NAME)StrDefs.h + +*_VSLATESTx86_*_ASM16_PATH = DEF(VS2017x86_BIN)\ml.exe + +################## +# ASL definitions +################## +*_VSLATESTx86_*_ASL_PATH = DEF(WIN_IASL_BIN) +*_VSLATESTx86_*_ASL_FLAGS = DEF(DEFAULT_WIN_ASL_FLAGS) +*_VSLATESTx86_*_ASL_OUTFLAGS = DEF(DEFAULT_WIN_ASL_OUTFLAGS) +*_VSLATESTx86_*_ASLCC_FLAGS = DEF(MSFT_ASLCC_FLAGS) +*_VSLATESTx86_*_ASLPP_FLAGS = DEF(MSFT_ASLPP_FLAGS) +*_VSLATESTx86_*_ASLDLINK_FLAGS = DEF(MSFT_ASLDLINK_FLAGS) + +################## +# IA32 definitions +################## +#*_VSLATESTx86_IA32_*_DLL = DEF(VS2017x86_DLL) + +*_VSLATESTx86_IA32_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VSLATESTx86_IA32_CC_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VSLATESTx86_IA32_VFRPP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VSLATESTx86_IA32_ASLCC_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VSLATESTx86_IA32_ASLPP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VSLATESTx86_IA32_SLINK_PATH = DEF(VS2017x86_BIN)\lib.exe +*_VSLATESTx86_IA32_DLINK_PATH = DEF(VS2017x86_BIN)\link.exe +*_VSLATESTx86_IA32_ASLDLINK_PATH= DEF(VS2017x86_BIN)\link.exe +*_VSLATESTx86_IA32_APP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VSLATESTx86_IA32_PP_PATH = DEF(VS2017x86_BIN)\cl.exe +*_VSLATESTx86_IA32_ASM_PATH = DEF(VS2017x86_BIN)\ml.exe + + *_VSLATESTx86_IA32_MAKE_FLAGS = /nologo + DEBUG_VSLATESTx86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Gw +RELEASE_VSLATESTx86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VSLATESTx86_IA32_CC_FLAGS = /nologo /arch:IA32 /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Od /Gw + + DEBUG_VSLATESTx86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi +RELEASE_VSLATESTx86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd +NOOPT_VSLATESTx86_IA32_ASM_FLAGS = /nologo /c /WX /W3 /Cx /coff /Zd /Zi + + DEBUG_VSLATESTx86_IA32_NASM_FLAGS = -Ox -f win32 -g +RELEASE_VSLATESTx86_IA32_NASM_FLAGS = -Ox -f win32 +NOOPT_VSLATESTx86_IA32_NASM_FLAGS = -O0 -f win32 -g + + DEBUG_VSLATESTx86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VSLATESTx86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VSLATESTx86_IA32_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:32 /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:X86 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + +################## +# X64 definitions +################## +*_VSLATESTx86_X64_*_DLL = DEF(VS2017x86_DLL) + +*_VSLATESTx86_X64_CC_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VSLATESTx86_X64_PP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VSLATESTx86_X64_APP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VSLATESTx86_X64_VFRPP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VSLATESTx86_X64_ASLCC_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VSLATESTx86_X64_ASLPP_PATH = DEF(VS2017x86_BINX64)\cl.exe +*_VSLATESTx86_X64_ASM_PATH = DEF(VS2017x86_BINX64)\ml64.exe +*_VSLATESTx86_X64_SLINK_PATH = DEF(VS2017x86_BINX64)\lib.exe +*_VSLATESTx86_X64_DLINK_PATH = DEF(VS2017x86_BINX64)\link.exe +*_VSLATESTx86_X64_ASLDLINK_PATH = DEF(VS2017x86_BINX64)\link.exe + + DEBUG_VSLATESTx86_X64_CC_FLAGS = /nologo /c /WX /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Gw +RELEASE_VSLATESTx86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Gw +NOOPT_VSLATESTx86_X64_CC_FLAGS = /nologo /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /GL /Gw + + DEBUG_VSLATESTx86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi +RELEASE_VSLATESTx86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd +NOOPT_VSLATESTx86_X64_ASM_FLAGS = /nologo /c /WX /W3 /Cx /Zd /Zi + + DEBUG_VSLATESTx86_X64_NASM_FLAGS = -Ox -f win64 -g +RELEASE_VSLATESTx86_X64_NASM_FLAGS = -Ox -f win64 +NOOPT_VSLATESTx86_X64_NASM_FLAGS = -O0 -f win64 -g + + DEBUG_VSLATESTx86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VSLATESTx86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER +NOOPT_VSLATESTx86_X64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /ALIGN:4096 /SECTION:.xdata,D /SECTION:.pdata,D /Machine:X64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + +################## +# ARM definitions +################## +*_VSLATESTx86_ARM_*_DLL = DEF(VS2017x86_DLL) + +*_VSLATESTx86_ARM_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VSLATESTx86_ARM_CC_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VSLATESTx86_ARM_PP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VSLATESTx86_ARM_APP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VSLATESTx86_ARM_VFRPP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VSLATESTx86_ARM_ASLCC_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VSLATESTx86_ARM_ASLPP_PATH = DEF(VS2017x86_BINARM)\cl.exe +*_VSLATESTx86_ARM_ASM_PATH = DEF(VS2017x86_BINARM)\armasm.exe +*_VSLATESTx86_ARM_SLINK_PATH = DEF(VS2017x86_BINARM)\link.exe +*_VSLATESTx86_ARM_DLINK_PATH = DEF(VS2017x86_BINARM)\link.exe +*_VSLATESTx86_ARM_ASLDLINK_PATH = DEF(VS2017x86_BINARM)\link.exe + +*_VSLATESTx86_ARM_SLINK_FLAGS = /LIB /machine:ARM /SUBSYSTEM:WINDOWSCE + + *_VSLATESTx86_ARM_MAKE_FLAGS = /nologo + DEBUG_VSLATESTx86_ARM_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /wd4127 /wd4214 /wd4100 /wd4201 /wd4702 +RELEASE_VSLATESTx86_ARM_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2 /GL /FIAutoGen.h /EHs-c- /GR- /GF /wd4127 /wd4214 /wd4100 /wd4201 /wd4702 +NOOPT_VSLATESTx86_ARM_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /FIAutoGen.h /EHs-c- /GR- /GF /Gy /Zi /Gm /Od /wd4127 /wd4214 /wd4100 /wd4201 /wd4702 + + DEBUG_VSLATESTx86_ARM_ASM_FLAGS = -nologo -g -32 -machine ARMCE +RELEASE_VSLATESTx86_ARM_ASM_FLAGS = -nologo -32 -machine ARMCE +NOOPT_VSLATESTx86_ARM_ASM_FLAGS = -nologo -g -32 -machine ARMCE + +# +# for SEC file/section alignment and XIP, use file type buildoptions +# +# ex: [BuildOptions.common.EDKII.SEC] +# + DEBUG_VSLATESTx86_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VSLATESTx86_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /IGNORE:4254 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VSLATESTx86_ARM_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /MACHINE:ARM /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + +################## +# AARCH64 definitions +################## + +*_VSLATESTx86_AARCH64_*_DLL = DEF(VS2017x86_DLL) + +*_VSLATESTx86_AARCH64_MAKE_PATH = DEF(VS2017x86_BIN)\nmake.exe +*_VSLATESTx86_AARCH64_CC_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VSLATESTx86_AARCH64_PP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VSLATESTx86_AARCH64_APP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VSLATESTx86_AARCH64_VFRPP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VSLATESTx86_AARCH64_ASLCC_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VSLATESTx86_AARCH64_ASLPP_PATH = DEF(VS2017x86_BINA64)\cl.exe +*_VSLATESTx86_AARCH64_ASM_PATH = DEF(VS2017x86_BINA64)\armasm64.exe +*_VSLATESTx86_AARCH64_SLINK_PATH = DEF(VS2017x86_BINA64)\lib.exe +*_VSLATESTx86_AARCH64_DLINK_PATH = DEF(VS2017x86_BINA64)\link.exe +*_VSLATESTx86_AARCH64_ASLDLINK_PATH = DEF(VS2017x86_BINA64)\link.exe + + DEBUG_VSLATESTx86_AARCH64_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /wd4214 /wd4127 /wd4100 /wd4312 /wd4702 +RELEASE_VSLATESTx86_AARCH64_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /O1ib2s /GL /Gy /FIAutoGen.h /EHs-c- /GR- /GF /wd4214 /wd4127 /wd4100 /wd4312 /wd4702 +NOOPT_VSLATESTx86_AARCH64_CC_FLAGS = /X /nologo $(PLATFORM_FLAGS) /c /WX /GS- /W4 /Gs32768 /D UNICODE /Gy /FIAutoGen.h /EHs-c- /GR- /GF /Zi /Gm /Od /wd4702 + + DEBUG_VSLATESTx86_AARCH64_ASM_FLAGS = -g +RELEASE_VSLATESTx86_AARCH64_ASM_FLAGS = +NOOPT_VSLATESTx86_AARCH64_ASM_FLAGS = -g + +# +# for SEC file/section alignment and XIP, use file type buildoptions +# +# ex: [BuildOptions.common.EDKII.SEC] +# + DEBUG_VSLATESTx86_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /RunBelow4GB /IGNORE:4001 /IGNORE:4226 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /Machine:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL +RELEASE_VSLATESTx86_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /RunBelow4GB /IGNORE:4001 /IGNORE:4254 /IGNORE:4226 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /Machine:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /MERGE:.rdata=.data +NOOPT_VSLATESTx86_AARCH64_DLINK_FLAGS = /NOLOGO /NODEFAULTLIB /RunBelow4GB /IGNORE:4001 /OPT:REF /OPT:ICF=10 /MAP /SECTION:.xdata,D /SECTION:.pdata,D /Machine:ARM64 /LTCG /DLL /ENTRY:$(IMAGE_ENTRY_POINT) /SUBSYSTEM:EFI_BOOT_SERVICE_DRIVER /SAFESEH:NO /BASE:0 /DRIVER /DEBUG:FULL + + + + + +################# +# ASM 16 linker defintions +################# +*_*_*_ASMLINK_PATH = link16.exe +*_*_*_ASMLINK_FLAGS = /nologo /tiny + +################## +# VfrCompiler definitions +################## +*_*_*_VFR_PATH = VfrCompile +*_*_*_VFR_FLAGS = -l -n + +################## +# OptionRom tool definitions +################## +*_*_*_OPTROM_PATH = EfiRom +*_*_*_OPTROM_FLAGS = -e + +################## +# GenFw tool definitions +################## +*_*_*_GENFW_PATH = GenFw +*_*_*_GENFW_FLAGS = + +################## +# Asl Compiler definitions +################## +*_*_*_ASLCC_FLAGS = /nologo /c /FIAutoGen.h /TC /Dmain=ReferenceAcpiTable +*_*_*_ASLDLINK_FLAGS = /NODEFAULTLIB /ENTRY:ReferenceAcpiTable /SUBSYSTEM:CONSOLE +*_*_*_ASLPP_FLAGS = /nologo /EP /C +*_*_*_ASL_FLAGS = + +################## +# GenCrc32 tool definitions +################## +*_*_*_CRC32_PATH = GenCrc32 +*_*_*_CRC32_GUID = FC1BCDB0-7D31-49AA-936A-A4600D9DD083 + +################## +# Rsa2048Sha256Sign tool definitions +# +# Notes: This tool defintion uses a test signing key for development purposes only. +# The tool Rsa2048Sha256GenerateKeys can be used to generate a new private/public key +# and the gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer PCD value. +# A custom tool/script can be implemented using the new private/public key with +# the Rsa2048Sha256Sign tool and this tool defintiion can be updated to use a +# custom tool/script. +# +# Generate new private/public key and gEfiSecurityPkgTokenSpaceGuid.PcdRsa2048Sha256PublicKeyBuffer PCD value +# +# Rsa2048Sha256GenerateKeys.py -o MyKey.pem --public-key-hash-c MyKey.pcd +# +# Custom script example (MyRsa2048Sha256Sign.cmd): +# +# Rsa2048Sha256Sign --private-key MyKey.pem %1 %2 %3 %4 %5 %6 %7 %8 %9 +# +# WARNING: Vendors that uses private keys are responsible for proper management and protection +# of private keys. Vendors may choose to use infrastructure such as signing servers +# or signing portals to support the management and protection of private keys. +# +################## +*_*_*_RSA2048SHA256SIGN_PATH = Rsa2048Sha256Sign +*_*_*_RSA2048SHA256SIGN_GUID = A7717414-C616-4977-9420-844712A735BF + +################## +# BrotliCompress tool definitions +################## +*_*_*_BROTLI_PATH = BrotliCompress +*_*_*_BROTLI_GUID = 3D532050-5CDA-4FD0-879E-0F7F630D5AFB + +################## +# LzmaCompress tool definitions +################## +*_*_*_LZMA_PATH = LzmaCompress +*_*_*_LZMA_GUID = EE4E5898-3914-4259-9D6E-DC7BD79403CF + +################## +# LzmaF86Compress tool definitions with converter for x86 code. +# It can improve the compression ratio if the input file is IA32 or X64 PE image. +# Notes: If X64 PE image is built based on GCC44, it may not get the better compression. +################## +*_*_*_LZMAF86_PATH = LzmaF86Compress +*_*_*_LZMAF86_GUID = D42AE6BD-1352-4bfb-909A-CA72A6EAE889 + +################## +# TianoCompress tool definitions +################## +*_*_*_TIANO_PATH = TianoCompress +*_*_*_TIANO_GUID = A31280AD-481E-41B6-95E8-127F4C984779 + +################## +# BPDG tool definitions +################## +*_*_*_VPDTOOL_PATH = BPDG +*_*_*_VPDTOOL_GUID = 8C3D856A-9BE6-468E-850A-24F7A8D38E08 + +################## +# SignFv tool definitions -- INTEL TOOL IN BDW +################## +*_*_*_SIGNFV_PATH = SignFvPlatform +*_*_*_SIGNFV_GUID = 0f9d89e8-9259-4f76-a5af-0c89e34023df + +################## +# NASM tool definitions +################## +*_*_*_NASM_PATH = ENV(NASM_PREFIX)\nasm +# NASMB uses NASM produce a .bin from a .nasmb NASM source file +*_*_*_NASMB_FLAGS = -f bin + +################# +# Build rule order +################# +*_*_*_*_BUILDRULEORDER = nasm asm Asm ASM S s diff --git a/azure-pipelines-pr-gate.yml b/azure-pipelines-pr-gate.yml index b3877b6873..6a09d7a487 100644 --- a/azure-pipelines-pr-gate.yml +++ b/azure-pipelines-pr-gate.yml @@ -3,6 +3,8 @@ strategy: matrix: TARGET_DFCI: Build.Pkgs: 'DfciPkg ZeroTouchPkg XmlSupportPkg' + TARGET_SHARED_CRYPTO: + Build.Pkgs: 'SharedCryptoPkg' TARGET_OTHER1: Build.Pkgs: 'MsGraphicsPkg UefiTestingPkg PcBdsPkg' TARGET_OTHER2: @@ -16,7 +18,7 @@ steps: clean: true fetchDepth: 10 submodules: recursive - + - task: UsePythonVersion@0 inputs: versionSpec: '3.7.x' @@ -43,14 +45,14 @@ steps: condition: succeededOrFailed() inputs: testResultsFormat: 'JUnit' # Options: JUnit, NUnit, VSTest, xUnit - testResultsFiles: 'Build/BuildLogs/TestSuites.xml' + testResultsFiles: 'Build/BuildLogs/TestSuites.xml' #searchFolder: '$(System.DefaultWorkingDirectory)' # Optional mergeTestResults: true # Optional #testRunTitle: # Optional #buildPlatform: # Optional #buildConfiguration: # Optional publishRunAttachments: true # Optional - + # Publish Build Artifacts # Publish build artifacts to Azure Artifacts/TFS or a file share @@ -59,8 +61,8 @@ steps: continueOnError: true condition: succeededOrFailed() inputs: - pathtoPublish: 'Build/BuildLogs' - artifactName: 'Build Logs $(Build.Pkgs)' + pathtoPublish: 'Build/BuildLogs' + artifactName: 'Build Logs $(Build.Pkgs)' #publishLocation: 'Container' # Options: container, filePath #targetPath: # Required when publishLocation == FilePath #parallel: false # Optional diff --git a/ci.mu.yaml b/ci.mu.yaml index 96baf51e67..dc4ed38674 100644 --- a/ci.mu.yaml +++ b/ci.mu.yaml @@ -34,6 +34,7 @@ "MsCorePkg", "MsGraphicsPkg", "MsWheaPkg", + "SharedCryptoPkg", "PcBdsPkg", "UefiTestingPkg", "XmlSupportPkg",