Skip to content

Commit

Permalink
CryptoPkg/OpensslLib: Create SM3-only version of the library
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ardbiesheuvel authored and mergify[bot] committed Sep 23, 2024
1 parent 1815f35 commit 1a89c69
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CryptoPkg/CryptoPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@
CryptoPkg/Library/OpensslLib/OpensslLibCrypto.inf
CryptoPkg/Library/OpensslLib/OpensslLib.inf
CryptoPkg/Library/OpensslLib/OpensslLibFull.inf
CryptoPkg/Library/OpensslLib/OpensslLibSm3.inf
CryptoPkg/Library/BaseHashApiLib/BaseHashApiLib.inf
CryptoPkg/Library/BaseCryptLibOnProtocolPpi/PeiCryptLib.inf
CryptoPkg/Library/BaseCryptLibOnProtocolPpi/DxeCryptLib.inf
Expand Down
30 changes: 30 additions & 0 deletions CryptoPkg/Library/OpensslLib/OpensslLibSm3.inf
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## @file
# Minimal OpensslLib implementation that only provides SM3 and nothing else.
# Needed by MbedTlsLib.
#
# Copyright (c) 2024, Google LLC. All rights reserved.<BR>
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 1.30
BASE_NAME = OpensslLibSm3
FILE_GUID = 96469bab-9c3f-4a60-a583-71a8bda64ec9
MODULE_TYPE = BASE
VERSION_STRING = 1.0
LIBRARY_CLASS = OpensslLib

DEFINE OPENSSL_PATH = openssl

[Sources]
$(OPENSSL_PATH)/crypto/sm3/sm3.c
OpensslStub/OpensslCleanse.c

[Packages]
MdePkg/MdePkg.dec
CryptoPkg/CryptoPkg.dec

[LibraryClasses]
BaseMemoryLib
20 changes: 20 additions & 0 deletions CryptoPkg/Library/OpensslLib/OpensslStub/OpensslCleanse.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @file
Minimal implementation of OPENSSL_cleanse for OpensslLibSm3.inf.
Copyright (c) 2024, Google LLC. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <Base.h>
#include <Library/BaseMemoryLib.h>

VOID
OPENSSL_cleanse (
VOID *Buffer,
UINTN Size
)
{
ZeroMem (Buffer, Size);
}

0 comments on commit 1a89c69

Please sign in to comment.