Commit Graph

561 Commits

Author SHA1 Message Date
Kalavakolanu, Hema Anmisha 62de957185 CryptoPkg: Add sleep() function to BaseCryptLibMbedTls
In BaseCryptLib sleep() function is defined,
apply the same sleep function to BaseCryptLibMbedTls

Signed-off-by: "Kalavakolanu, Hema Anmisha" <hema.anmisha.kalavakolanu@intel.com>
2025-01-02 12:28:51 +00:00
Laszlo Ersek 89b527df17 CryptoPkg: revert BUFSIZ macro definition from commit 456dd8b99f
OpenSSL ticket <https://github.com/openssl/openssl/issues/8904> has been
fixed in OpenSSL commit 2e9d61ecd81a ("crypto/evp/evp_key.c: #define
BUFSIZ if <stdio.h> doesn't #define it", 2019-05-27).

We should simplify "CryptoPkg/Library/Include/CrtLibSupport.h" and back
out the change made to that file by edk2 commit 456dd8b99f ("CryptoPkg:
Upgrade OpenSSL to 1.1.1b", 2019-06-03).

Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1897
Signed-off-by: Laszlo Ersek <laszlo.ersek@posteo.net>
2024-12-16 02:22:36 +00:00
Oliver Smith-Denny bcbb709959 BaseTools: Add VS2022 XIPFLAGS
BaseTools has a limitation that modules in FVs that are force rebased
must have the same file and section alignment. This is intended for
XIP modules.

VS2019 and previous VS toolchains did not set 4k section alignment,
but VS2022 does, in order for memory protections to be applied to
images. This causes issues when building SEC and PEI modules on
VS2022 as the file alignment is 0x20 but the section alignment
is 0x1000, so BaseTools will fail to generate the FV. One option
is to set the file alignment to 0x1000 for all of these files, but
that is a large waste of space and is not feasible on some platforms
that have limited flash space. The other option is to selectively
set 0x20 as the section alignment for SEC and PEI modules, which is
the approach GCC ARM/AARCH64 took.

This is only an issue for building 64-bit PEI on x86 currently, as
other architectures are not supported by VS2022 in edk2 yet. For IA32,
the section alignment is set to 0x20 and so it matches the file
alignment, however x64 PEI uses the X64 DLINK flags which have 0x1000
set. For other architectures that don't have the PEI/DXE architecture
split, this is also an issue.

This commit is required to use VS2022 as the default CI in edk2, as
OvmfPkgX64.dsc will fail to build. Any platform with 64-bit PEI also
requires this.

This commit also updates CryptoPkg.dsc and SecurityPkg.dsc as they
are setting custom section alignments.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2024-12-10 23:42:09 +00:00
Gerd Hoffmann 73570d8ab6 openssl: disable visual studio warning #4189
4189 is "local variable is initialized but not referenced"

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann 99e18f2327 CryptoPkg: CI: update OpensslGen file list
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann 8c5dcecd24 CryptoPkg: gcc needs 4k section alignment too
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann 9895fe25ac CryptoPkg/BaseCryptLib: add next parameter to SHA3_squeeze
Needed for openssl 3.3.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann a801363249 CryptoPkg: add openssl/providers/fips/include to includes
Needed for openssl 3.4.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann 005f4c6b5e openssl: add more stubs for openssl 3.2.x
openssl-3.2.2 got a few more tls config hooks, add stubs for them.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann 53cea8efd1 openssl: adapt stubs to openssl 3.2.x
Function declarations have changed in openssl-3.2.x, adapt the stubs.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann 8f6c2ccc45 openssl: update generated files
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Gerd Hoffmann e584e865f8 openssl: update submodule to 3.4.0
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-12-06 08:01:25 +00:00
Ard Biesheuvel f73f7b2318 CryptoPkg/OpensslLib: Drop dependency on ArmSoftFloatLib
Drop the ArmSoftFloatLib dependency from the OpensslLib implementations,
so that we can retire this git submodule and associated dependencies in
other components.

The upshot of this is that OpenSSL can no longer be used on 32-bit ARM
by components that rely on the random number generation routines (which
is where the floating point usage resides). In practice, this means that
ARM platforms should use MbedTLs instead for things like signed
capsules, authenticated variables and TPM2 support. HTTPS boot is no
longer supported, as TlsDxe depends on OpensslLib directly.

Note that MbedTLS itself -surprisingly- depends on OpensslLib as well,
but only for the SM3 routines, and incorporating those does not require
softfloat support.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-11-26 22:00:36 +00:00
Amy Chan 065df32de3 CryptoPkg: Apply gettimeofday() solution to BaseCryptLibMbedTls
BaseCryptLib turn gettimeofday() from a Macro into a function call,
apply the same change to BaseCryptLibMbedTls

Signed-off-by: Amy Chan <amy.chan@intel.com>
2024-11-25 16:40:28 +00:00
Oliver Smith-Denny ef4f3aa3f7 MdePkg: MdeLibs.dsc.inc: Apply StackCheckLibNull to All Module Types
Now that the ResetVectors are USER_DEFINED modules, they will not
be linked against StackCheckLibNull, which were the only modules
causing issues. So, we can now remove the kludge we had before
and the requirement for every DSC to include StackCheckLibNull
for SEC modules and just apply StackCheckLibNull globally.

This also changes every DSC to drop the SEC definition of
StackCheckLibNull.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-11-13 21:01:46 +00:00
Michael D Kinney d5600f4f5a CryptoPkg/BaseCryptLib: Fix serial number read overrun
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2024-11-08 16:28:50 +00:00
INDIA\kanagavels 6f17fe30bf CryptoPkg: Added MM_STANDALONE support in CryptoPkg.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4867

Added MM_STANDALONE support in Driver and BaseCryptLibOnProtocolPpi.

Signed-off-by: Kanagavel S <kanagavels@ami.com>
2024-11-05 00:17:48 +00:00
Jorge Ramirez-Ortiz ccbe6f5030 CryptoPkg: Increase ScratchMemory buffer for openssl 3.0.15
Openssl 3.0.15 has a larger memory footprint.

Updating from EDK 2022.2 (openssl 1.1.j) to 2024.2 (openssl 3.0.15)
causes our EFI provisioning application[1] to fail due to an out of
memory condition.

On inspection, at the time of that fault, 2022.2 had an additional 900
pages. This is why this patch proposes the increase of the ScratchMemory
buffer by that same ammount.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/jejb/efitools.git

Signed-off-by: Jorge Ramirez-Ortiz <jorge@foundries.io>
2024-11-04 21:34:22 +00:00
INDIA\kanagavels 47ba459fc1 CryptoPkg: Updated the missed architectures.
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4838

Updated the missed architectures in PeiCryptLib.inf file.

Signed-off-by: Kanagavel S <kanagavels@ami.com>
2024-11-01 15:06:02 +00:00
Mike Beaton e548e1cd73 CryptoPkg: Fix unused variable in CryptX509.c
Without this change we get:

  error: variable 'Index' set but not used

when building on XCODE5.

Co-authored-by: Savva Mitrofanov <savvamtr@gmail.com>
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2024-09-27 16:57:36 +00:00
Mike Beaton 90fb3c6cfc CryptoPkg/OpensslLib: Fix build on XCODE5
REF: https://edk2.groups.io/g/devel/message/88179

Without this change, we get:

  fatal error: 'Availability.h' file not found

when building on XCODE5.

The workaround uses a define present in openssl/include/crypto/rand.h
which modifies openssl behaviour on Apple only, causing the library
to default to a non-system specific source of entropy in syscall_random()
in rand_unix.c.

Co-authored-by: Savva Mitrofanov <savvamtr@gmail.com>
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2024-09-27 16:57:36 +00:00
Li Yi 3ed4f43f83 CryptoPkg: Update generated files based on openssl 3.0.15
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4842

Signed-off-by: Li Yi <yi1.li@intel.com>
2024-09-27 04:24:25 +00:00
Li Yi c13f9de56d CryptoPkg: Update openssl submodule to 3.0.15
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4842

CVE-2024-6119 affects TLS-client implementation of EDK2. Fix it by
updating to 3.0.15.

Signed-off-by: Li Yi <yi1.li@intel.com>
2024-09-27 04:24:25 +00:00
Gerd Hoffmann 39462fcd99 openssl: add Library/OpensslLib/openssl to includes, drop e_os.h hack
Adding $(OPENSSL_PATH)/e_os.h to the list of source files had the effect
that $(OPENSSL_PATH)/ was added to the list of include directories.
With the file being gone in openssl-3.2.x this doesn't work any more.

Add the directory to the [Includes.Common.Private] section instead.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Gerd Hoffmann 67c303cb5f CrtLibSupport: add intptr_t
Will be needed by openssl-3.4.x

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Gerd Hoffmann c371460cb4 CrtLibSupport: add timezone
Will be needed by openssl-3.2.x

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Gerd Hoffmann 0ec54d8d0c CrtLibSupport: add mktime()
Will be needed by openssl-3.2.x

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Gerd Hoffmann af73d37741 CrtLibSupport: factor out EFI_TIME -> time_t calculation to new function
No functional change.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Gerd Hoffmann ebf7daa583 CrtLibSupport: fix gettimeofday()
Turn gettimeofday() into a proper function with return value.

Will be needed by openssl-3.2.x

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Gerd Hoffmann 609c7e8679 CrtLibSupport: add sleep()
Will be needed by openssl-3.2.x

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-09-25 16:08:35 +00:00
Ard Biesheuvel 1a89c690a1 CryptoPkg/OpensslLib: Create SM3-only version of the library
Create a special OpensslLib implementation that only exposes the SM3
routines that MbedTlsLib borrows from OpensslLib, to avoid having to
pull in other parts of OpenSSL that are not needed (e.g., via the
library constructor)

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-09-23 06:11:25 +00:00
Ard Biesheuvel 1815f35b87 CryptoPkg: Add unit testcase for SM3
SM3 needs to be tested so we can verify that alternative implementations
(such as the one I will be contributing to BaseCryptLibMbedTls) as well
as the reference implementation produce the expected value.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-09-23 06:11:25 +00:00
Ard Biesheuvel 89309fee81 CryptoPkg/MbedTls CLANGDWARF: Replace outdated CLANG3x references
The CLANG35 and CLANG38 toolchain specifiers have been phased out, and
replaced with CLANGDWARF. Update the MbedTls library definitions
accordingly.

While at it, switch to the gnu99 C dialect, which is a better match with
GCC in C99 mode, which includes GCC specific GNU extensions.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-09-23 06:11:25 +00:00
Oliver Smith-Denny c9320adf22 CryptoPkg: Add StackCheckLib
Remove the old stack check lib now that MdeLibs.inc includes
the new one.

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-13 03:58:46 +00:00
Oliver Smith-Denny 8f74b95a21 MdePkg: Move CompilerIntrinsicsLib from ArmPkg
As per the emailed RFC in
https://edk2.groups.io/g/devel/topic/rfc_move/107675828,
this patch moves CompilerIntrinsicsLib from ArmPkg to
MdePkg as this library provides compiler intrinsics, which
are industry standard.

This aligns with the goal of integrating ArmPkg into existing
packages: https://bugzilla.tianocore.org/show_bug.cgi?id=4121.

The newly placed CompilerIntrinsicsLib is added to MdeLibs.dsc.inc
as every DSC that builds ARM/AARCH64 needs this library added. The
old location is removed from every DSC in edk2 in this commit also
to not break bisectability with minimal hoop jumping.

Continuous-integration-options: PatchCheck.ignore-multi-package

Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
2024-09-12 19:36:59 +00:00
Ard Biesheuvel 90d861f63d CryptoPkg/BaseCryptLibMbedTls: Fix uninitialized variable errors
Clang complains about a couple of variables potentially being
uninitialized, and those complaints seem to be valid.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-08-31 02:46:51 +00:00
Ard Biesheuvel 468a36b22f CryptoPkg/OpensslLib CLANGDWARF: Use gnu99 C dialect for asm() support
'asm' is not a keyword in C99, but GCC supports it nonetheless as a GNU
extension. So when using Clang, we must specify the gnu99 dialect
explicitly, or inline asm blocks using asm() rather than __asm__() will
be rejected by the compiler.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
2024-08-31 01:30:23 +00:00
Michael G.A. Holland 9cd66aca1a CryptoPkg: Support BrainpoolP512r1 algorithm
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4830

Allow BrainpoolP512r1 to be leveraged when the corresponding curve ID
is passed to crypto libraries in EDK2

Signed-off-by: Michael G.A. Holland <michael.holland@intel.com>
2024-08-29 00:30:38 +00:00
Pierre Gondois a679ceca97 CryptoPkg: Enable Openssl Accel builds for AARCH64
Enable the following modules builds for AARCH64:
- OpensslLibAccel.inf
- OpensslLibFullAccel.inf

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2024-08-01 13:41:01 +00:00
Pierre Gondois 368f9b62a2 CryptoPkg/OpensslLib: Add AArch64Cap for arch specific hooks
Add AARCH64 specific implementations of:
- OPENSSL_cpuid_setup(), probing hardware capabilitie
  (presence of FEAT_AES, etc.)
- OPENSSL_rdtsc(), returning non-trusted entropy by accessing
  system counter.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2024-08-01 13:41:01 +00:00
Pierre Gondois 9403422f21 CryptoPkg/OpensslLib: Generate files for AARCH64 native support
Generate AARCH64 related files and update .inf files,
running:
  python CryptoPkg/Library/OpensslLib/configure.py

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2024-08-01 13:41:01 +00:00
Pierre Gondois 952ecf53f9 CryptoPkg/OpensslLib: Add native instruction support for AARCH64
Add native instruction support for AARCH64.

Signed-off-by: Pierre Gondois <pierre.gondois@arm.com>
2024-08-01 13:41:01 +00:00
Wenxing Hou dc002d4f2d CryptoPkg: Fix wrong comment for CryptoPkg
Fix the wrong comment.

Cc: Jiewen Yao <jiewen.yao@intel.com>
Cc: Yi Li <yi1.li@intel.com>
Signed-off-by: Wenxing Hou <wenxing.hou@intel.com>
2024-06-26 07:48:42 +00:00
Sebastian Witt dc93ff8a55 CryptoPkg: Extend TLS handshake debug output
The error codes during TLS handshake errors are sometimes
not enough to understand the root cause of the problem.
Extending the debug output by the function and optional data helps
in some cases.

Signed-off-by: Sebastian Witt <sebastian.witt@siemens.com>
2024-06-25 23:18:36 +00:00
Sebastian Witt 84d8eb08e1 CryptoPkg: Add SNI extension to TLS ClientHello
Webservers hosting multiple websites require the TLS SNI
(Server Name Indication) in the ClientHello to know which certificate
to return.
The current TLS code does not include the server name in the
ClientHello handshake, which leads to failed HTTPS boots when the
server does not return the correct certificate.

This sets the host name for SNI in TlsSetVerifyHost which receives the
host name also for verification against the certificates.

Signed-off-by: Sebastian Witt <sebastian.witt@siemens.com>
2024-06-25 21:46:50 +00:00
Wenxing Hou a7dbd2ac7b CryptoPkg: Fix strncpy for BaseCryptLibMbedTls
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2817

Because the change for strncpy, add the strncpy implementation.

Signed-off-by: Wenxing Hou <wenxing.hou@intel.com>
2024-06-17 01:16:17 +00:00
Gerd Hoffmann 94961b8817 CryptoPkg/Test: call ProcessLibraryConstructorList
Needed to properly initialize BaseRngLib.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2024-06-14 13:31:12 +00:00
Sebastian Witt 948f234170 CryptoPkg: Fix BaseCryptLib CrtWrapper strncpy and strcat
Following https://bugzilla.tianocore.org/show_bug.cgi?id=2817 this
bug could also apply to strncpy and strcat.

For strncpy use count+1 if smaller than MAX_STRING_SIZE. This still
restricts the destination size to MAX_STRING_SIZE as before but allows
a strncpy when the source is close after destination without triggering
the InternalSafeStringNoAsciiStrOverlap check in AsciiStrnCpyS.

For strcat use the destination string length + the size of the source
string including the terminator as destination size if smaller than
MAX_STRING_SIZE.

Also move both functions to CrtWrapper.c as they do not return the
correct return value. AsciiStrnCpyS and AsciiStrCatS return
RETURN_VALUE instead of a char * to the destination buffer.

Signed-off-by: Sebastian Witt <sebastian.witt@siemens.com>
2024-06-07 13:23:04 +00:00
Sebastian Witt df8c61e4c0 CryptoPkg: Fix BaseCryptLib CrtWrapper strcpy
strcpy fails when strSource is closer than 4096 bytes after strDest.

This is caused by an overlap check in AsciiStrCpyS:
  //
  // 5. Copying shall not take place between objects that overlap.
  //
  SAFE_STRING_CONSTRAINT_CHECK (InternalSafeStringNoAsciiStrOverlap
  (Destination, DestMax, (CHAR8 *)Source, SourceLen + 1),
  RETURN_ACCESS_DENIED);

Since DestMax is MAX_STRING_SIZE (0x1000) and with a Source
that is in this area behind Destination, AsciiStrCpyS will fail
and strcpy will do nothing.

When called by CRYPTO_strdup in openssl this leads to uninitialzed
memory that gets accessed instead of the copied string.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=2817

Signed-off-by: Sebastian Witt <sebastian.witt@siemens.com>
2024-06-07 13:23:04 +00:00
Wenxing Hou 71606314f8 CryptoPkg: Fix wrong logic in X509GetTBSCert
REF:
https://bugzilla.tianocore.org/show_bug.cgi?id=4509

Both return 0x80 value and
Asn1Tag != V_ASN1_SEQUENCE are wrong return.

Signed-off-by: Wenxing Hou <wenxing.hou@intel.com>
2024-06-06 14:49:44 +00:00