The host-based BaseCryptLib instance (UnitTestHostBaseCryptLib.inf) built
Rand/CryptRandTsc.c only for IA32/X64. Add Rand/CryptRand.c for AARCH64 so
the openssl-backed RandomSeed() is available when linking AARCH64 host
tests, and advertise AARCH64 in VALID_ARCHITECTURES.
Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
`TlsNew()` explicitly sets the default security level to 3. The current
default in OpenSSL is security level 2 which is inherited by Linux
distributions like Ubuntu 26.04. This is also the security level that
was announced in https://edk2.groups.io/g/devel/topic/115039926.
Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr>
In preparation for the MarkdownLintCheck plugin being added to the
repo, this change defaults the plugin to `AuditOnly` mode in each
package. This allows package maintainers to enable the plugin as they
see fit.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
Created SLH-DSA API functions to configure public and private keys for
SLH-DSA algorithm. This will allow users to sign and verify with
SLH-DSA. Unit tests were added to confirm operation of the API.
Signed-off-by: Michael G.A. Holland <michael.holland@intel.com>
Include validation check for Context and ContextSize in signature
function.
Updated ReadMe to show ML-DSA support
Signed-off-by: Michael G.A. Holland <michael.holland@intel.com>
Include validation checks for Context and ContextSize in
sign and verify functions.
Returned FALSE for EdDsaGeneratePubKey.
Updated ReadMe to show EdDsa support
Signed-off-by: Michael G.A. Holland <michael.holland@intel.com>
Created ML-DSA API functions to configure public and private keys for
ML-DSA algorithm. This will allow users to sign and verify with ML-DSA.
Unit tests were add to confirm operation of the API.
Signed-off-by: Michael G.A. Holland <michael.holland@intel.com>
Implemented signature and verification functions for ED448;
Updated documentation and unit tests to cover new verification functions
Signed-off-by: Michael G.A. Holland <michael.holland@intel.com>
Enable CryptSha256 hash in SecCryptLib as this
is required by Arm CCA.
The hash algorithm used by the Arm CCA Realm
Extensible Measurement (REM) registers is
either SHA256 or SHA512.
To enable measurements in the early boot phase
enable SHA256 hash algorithm in SecCryptLib.
Signed-off-by: Sami Mujawar <sami.mujawar@arm.com>
In TlsSetCipherList(), the OpensslCipher variable is initialized inside an
inner loop but accessed outside of that loop, which can lead to
uninitialized variable warnings.
Fix this issue by moving all accesses to OpensslCipher into the inner loop
where it is initialized.
Signed-off-by: Tuan Phan <tuan.phan@oss.qualcomm.com>
This update includes fixes for the following security vulnerabilities:
- CVE-2026-45447
- CVE-2026-34180
- CVE-2026-34181
- CVE-2025-69419
Fixes: #12658
Signed-off-by: Thamballi Sreelalitha <sreelali@qti.qualcomm.com>
Lite version OpensslLib
base on OpensslLibFull but no-camellia, no -ecx and no-dh.
It save the size about ~192KB.
REF:
Signed-off-by: Lee LonghaoX <longhaox.lee@intel.com>
When the TLS error is `SSL_R_CERTIFICATE_VERIFY_FAILED`, the
verification failure reason is reported by `SSL_get_verify_result`.
Adding this reason to the debug logs is valuable to pin-point
certificate rejection that are specific to EDK II.
Signed-off-by: Jean-Tiare Le Bigot <jt@yadutaf.fr>
RsaSetKey passed RSA-internal BIGNUMs (returned by RSA_get0_key /
RSA_get0_factors / RSA_get0_crt_params as const) directly to BN_bin2bn,
which mutates its destination in place. This violates the OpenSSL API
contract and can leave RsaContext in a partially modified state on
failure paths: BN_bin2bn has already overwritten one of
n / e / d / p / q / dp / dq / qInv, the function then returns FALSE
on a subsequent BN_dup or RSA_set0_* failure, and the caller has no
indication that the RSA object was silently changed. The same paths
also leaked temporary BIGNUMs allocated by BN_bin2bn or BN_new.
This patch splits RsaSetKey into a small input-validating dispatcher
plus three static helpers (RsaSetKeyNED, RsaSetKeyFactors,
RsaSetKeyCrtParams), one per RSA_set0_* setter. Each helper:
- Allocates a fresh BIGNUM for the slot being set via
BN_bin2bn(BigNumber, BnSize, NULL); the NULL destination forces
BN_bin2bn to allocate so no RSA-owned BIGNUM is mutated.
- Reads the current RSA state via RSA_get0_* purely for inspection.
- For slots not being set, passes NULL when RSA already has a value
(preserves it) or supplies an empty BN_new() placeholder when
RSA's slot is still NULL.
- Atomically installs via RSA_set0_*, which takes ownership of every
non-NULL argument on success and of none on failure.
- Routes all exits through a single label that frees any locally
held BIGNUM. Memory leaks in the early-return paths are fixed as
a consequence.
The previous BN_dup calls are no longer needed and are removed.
Signed-off-by: Mingjie Shen <shen497@purdue.edu>
Update the mbedtls submodule from v3.6.5 to v3.6.6 to mitigate
the CVEs CVE-2026-25833, CVE-2026-25834, CVE-2026-25835
CVE-2026-34874.
Signed-off-by: Richard Lyu <richard.lyu@suse.com>
Per
https://edk2.groups.io/g/devel/topic/move_armlib_to_baselib/118541649,
this commit moves ArmLib to MdePkg and updates all consumers.
The only change to ArmLib itself is to remove ArmPkg.dec from
the inf.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
Add RsaPssSignDigest() and RsaPssVerifyDigest() to BaseCryptLib for
signing/verifying precomputed digests. Provide OpenSSL/MbedTLS/Null
implementations, expose via EDKII_CRYPTO_PROTOCOL (v24), and add PCD
controls for independent service enabling. Include unit tests.
Signed-off-by: Anbazhagan Baraneedharan <anbazhagan@hp.com>
Explicitly reject zero-length X.509 certificate buffers when retrieving a
public key. For this invalid case, the input context pointer is set to
NULL as a defensive measure.
Signed-off-by: Kun Qin <kun.qin@microsoft.com>
This patch prepares the build infrastructure for
the TCG TPM 2.0 implementation [0].
By default, it uses the OpenSSL EC_* APIs.
When the TCG TPM 2.0 implementation [0] is used in StandaloneMm,
EC algorithm support is required in SmmCryptLib.
Link: https://github.com/TrustedComputingGroup/TPM [0]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
This is prepartion patch to build TCG TPM v2.0 Reference Library[0].
TCG TPM v2.0 implementation[0] uses below additional interfaces:
- EC_GROUP_new_curve_GFp()
- EC_GROUP_set_generator()
- EC_POINTs_mul()
and require EC_POINT_mul()'s n arguments
(Scalar multiplier for the generator G) but EDKII's
EcPointMul() interface always fix this value as NULL.
For TCG TPM v2.0 implementation, add new interfaces.
Link: https://github.com/TrustedComputingGroup/TPM [0]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
This is preparation patch to build TCG TPM v2.0 implementation [0].
TCG TPM v2.0 uses AES_encrypt()/AES_decrpyt() in openssl library to
implement its crypto operation.
For this, add wrapper for AES_encrypt()/AES_decrpyt().
Link: https://github.com/TrustedComputingGroup/TPM[0]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
To build TPM reference library[0] with CryptoPkg,
belows are required:
- define memcpy as a function instead of a macro because
memcpy is used as a function pointer in TPM reference library
- definitions of INT16_MAX/UINT16_MAX
Link: https://github.com/TrustedComputingGroup/TPM [0]
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
To build TPM 2.0 Reference Implementation library,
OpensslLib requires below features:
- camellia
- cmac
- elliptic curved algorithms
For thes, openssl should be configured without below two options:
- no-camellia
- no-cmac
Therefore, remove these two option for OpensslFullLib only
since TPM 2.0 Reference Library requires to use openssl built with ec
This increases OpensslFullLib size -- around 16K.
Except configure.py, other changed files are auto generated by
configure.py
Signed-off-by: Yeoreum Yun <yeoreum.yun@arm.com>
Replace traditional `#ifndef`/`#define`/`#endif` include guards with
`#pragma` once.
`#pragma once` is a widely supported preprocessor directive that
prevents header files from being included multiple times. It is
supported by all toolchains used to build edk2: GCC, Clang/LLVM, and
MSVC.
Does not include updates to OpenSSL generated header files checked
into the repo. Those in `CryptoPkg\Library\OpensslLib\OpensslGen\`.
Compared to macro-based include guards, `#pragma once`:
- Eliminates the risk of macro name collisions or copy/paste errors
where two headers inadvertently use the same guard macro.
- Eliminate inconsistency in the way include guard macros are named
(e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.).
- Reduces boilerplate (three lines replaced by one).
- Avoids polluting the macro namespace with guard symbols.
- Can improve build times as the preprocessor can skip re-opening the
file entirely, rather than re-reading it to find the matching
`#endif` ("multiple-include optimization").
- Note that some compilers may already optimize traditional include
guards, by recognzining the idiomatic pattern.
This change is made acknowledging that overall portability of the
code will technically be reduced, as `#pragma once` is not part of the
C/C++ standards.
However, this is considered acceptable given:
1. edk2 already defines a subset of supported compilers in
BaseTools/Conf/tools_def.template, all of which have supported
`#pragma once` for over two decades.
2. There have been concerns raised to the project about inconsistent
include guard naming and potential macro collisions.
Approximate compiler support dates:
- MSVC: Supported since Visual C++ 4.2 (1996)
- GCC: Supported since 3.4 (2004)
(http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html)
- Clang (LLVM based): Since initial release in 2007
Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
CLANGPDB does not support the same asm syntax as GCC/CLANGDWARF.
As a result, the autogenerated ASM files in CryptoPkg need a new
flavor for CLANGPDB, which is supported by OpenSSL.
This adds support to the autogeneration script to support the new
flavor, as well as running the script and checking in the generated
asm files. To reflect the intention better than toolchain name
(as AARCH64-GCC is already out of date), the directories are renamed
to AARCH64-ELF (the former AARCH64-GCC) and AARCH64-PE (what CLANGPDB
uses).
In order to support this, a new PCD is introduced in CryptoPkg,
gEfiCryptoPkgTokenSpaceGuid.PcdOpensslLibAssemblySourceStylePe which
instructs the build system to include the PE target asm files or
the ELF target asm files. GCC and CLANGDWARF will use the ELF target
files and CLANGPDB uses the PE target files. This matches the X64
behavior to toggle between the asm files.
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
CryptoPkg needed various updates to support CLANGPDB AARCH64:
- Scope a feature PCD to IA32/X64 only
- Ensure that OpenSSL and MbedTls have the Windows defines unset so
they don't try to build for Windows instead of UEFI
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
The optimized NASM assembly files from Openssl project for
IA32/X64 assume a Windows calling convention. Those NASM
files must be used for both firmware builds where the
default compiler calling convention is the Windows calling
convention and host-based unit tests built using any of the
compilers supported in Windows environment.
All the VS20xx tool chains in the MSFT tool family use a
Windows calling convention. The CLANGPDB tool chain under
both Windows and Linux environments also use a Windows
calling convention. Set PcdOpensslLibAssemblySourceStyleNasm
to TRUE for these conditions.
Host-based unit tests built in a Windows environment also
use a Windows calling convention. If WIN_HOST_BUILD is set
indicating a Windows build environment and
HOST_BASED_UNIT_TESTING_ENABLED is also set indicating
host-based unit tests, then
PcdOpensslLibAssemblySourceStyleNasm must be set to TRUE.
Otherwise a Linux calling convention is assumed and
PcdOpensslLibAssemblySourceStyleNasm uses its DEC default
value of FALSE that uses the Openssl project optimized
.S files that assume a Linux calling convention.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Intrinsic functions __aullrem and __alldiv are missing in
CLANGPDB IA32 builds due to these functions only being
implemented in ASM, and CLANGPDB builds require NASM.
* Convert MathLldiv.asm to MathLldiv.nasm
* Convert MathUllrem.asm to MathUllrem.nasm
* Update IntrinsicLib.inf to use NASM for MSFT and CLANGPDB
These missing functions were found with CLANGPDB IA32
build of the EmulatorPkg with -D SECURE_BOOT_ENABLE. Can
also be seen with CLANGPDB IA32 build of OpensslLib under
Windows and Linux by reviewing the external functions
in .lib.
Resolves a similar issue with __aulldiv addressed by
https://github.com/tianocore/edk2/pull/11266
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Undefine WIN32 for GCC family compilers in OpensslLib INF
files to remove use of GetLastError() and SetLastError()
in OpensslLib builds.
Mingw CLANG compilers have a builtin define called WIN32.
When building OpensslLib, this define causes the Windows
APIs GetLastError() and SetLastError() to be referenced
which causes compilers warnings for undefined functions.
Mingw CLANG NOOPT builds generate link errors not finding
GetLastError() and SetLastError().
The MSFT family compilers do not define WIN32. As a result,
this issue is not observed with VS20xx tool chains. Removing
the WIN32 define aligns the GCC family with the MSFT family.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Update GCC Family to undefined _MSC_VER to match settings used
by other compilers. This addresses clang compatibility issues
for host-based unit test builds.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Update GCC Family to undefined _MSC_VER to match settings used
by other compilers. This addresses clang compatibility issues
for host-based unit test builds.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
CI builds have started to fail with
ERROR - Compiler #2220 from D:\a\1\s\CryptoPkg\Library\OpensslLib\openssl\crypto\bn\bn_gcd.c(659): the following warning is treated as an error
WARNING - Compiler #4319 from D:\a\1\s\CryptoPkg\Library\OpensslLib\openssl\crypto\bn\bn_gcd.c(659): '~': zero extending 'unsigned int' to 'unsigned __int64' of greater size
WARNING - Compiler #4319 from D:\a\1\s\CryptoPkg\Library\OpensslLib\openssl\crypto\bn\bn_gcd.c(671): '~': zero extending 'unsigned int' to 'unsigned __int64' of greater size
which was not flagged before. Suppress the warning in CryptoPkg so the
builds will succeed again. If this is a real issue, it should be
reported to and fixed in the upstream project.
Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
The OpenSSL build system enables debug information by default
unless NDEBUG is defined. This results in debug symbols being
included in GCC Release builds.
Add the NDEBUG flag to the GCC Release build flags to properly
disable debug information and align with standard Release build
practices.
Signed-off-by: Zihan Qi <zihanqi@amazon.com>
MbebTls no support signature with content data.
test would be fail in below test case:
TestPkcs7Attached
TestPkcs7Detached
TestVerifyPkcs7ContentData
REF: https://github.com/tianocore/edk2/issues/11605
Signed-off-by: Longhaox Lee <longhaox.lee@intel.com>
1.Defended MBEDTLS_PLATFORM_MS_TIME_ALT
use alternative implement.
2.Defended MBEDTLS_TEST_SW_INET_PTON
use software version INET_PTON, not depend on OS.
REF: https://github.com/tianocore/edk2/issues/11605
Signed-off-by: Longhaox Lee <longhaox.lee@intel.com>
1. mbedtls_config.h header sync with 3.6.5 .
2. Implement mbedtls_ms_time() Get time in milliseconds.
3. Covert some CRT library to EDK Implement and CRT defined.
4. Added and remove file to sync.
REF: https://github.com/tianocore/edk2/issues/11605
Signed-off-by: Longhaox Lee <longhaox.lee@intel.com>
This was found building ArmVirtQemu using CLANGDWARF with
unused-but-set-variable warning enabled.
Fixes: 40fa5cf299
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>