mirror of
https://github.com/apple/swift-crypto
synced 2026-11-26 04:47:49 +00:00
Final catchup merge (#415)
This is the last catchup merge into the WWDC-25 branch required to get the two branches to line up. From here, it's a straightforward merge to `main` to get the WWDC-25 branch in. --------- Co-authored-by: YourMJK <37852512+YourMJK@users.noreply.github.com> Co-authored-by: Rick Newton-Rogers <rnro@apple.com> Co-authored-by: Raphael <josephnoir@users.noreply.github.com> Co-authored-by: Si Beaumont <beaumont@apple.com> Co-authored-by: Evan Wilde <ewilde@apple.com> Co-authored-by: Tim Condon <0xTim@users.noreply.github.com> Co-authored-by: Gus Cairo <gus.cairo@apple.com> Co-authored-by: George Barnett <gbarnett@apple.com> Co-authored-by: Fabrice de Gans <Steelskin@users.noreply.github.com> Co-authored-by: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Co-authored-by: Jesse L. Zamora <xtremekforever@gmail.com> Co-authored-by: aryan-25 <aryan_shah@apple.com> Co-authored-by: Gwynne Raskind <gwynne@vapor.codes> Co-authored-by: 3405691582 <dsk@google.com> Co-authored-by: Paul Toffoloni <69189821+ptoffy@users.noreply.github.com>
This commit is contained in:
188 files changed
+8167
-4457
No files matched your search
@@ -25,10 +25,10 @@
|
||||
|
||||
set -e
|
||||
|
||||
SWIFT_VERSION=5.10
|
||||
SWIFT_VERSION=6.1.2
|
||||
DISTRO_NAME=ubuntu
|
||||
DISTRO_VERSION=jammy
|
||||
DISTRO_VERSION_GENERATOR=22.04
|
||||
DISTRO_VERSION=noble
|
||||
DISTRO_VERSION_GENERATOR=24.04
|
||||
TMPDIR=$(mktemp -d /tmp/.workingXXXXXX)
|
||||
|
||||
function generate_swift_sdk {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
diff --git a/Sources/CCryptoBoringSSL/crypto/fipsmodule/service_indicator/internal.h b/Sources/CCryptoBoringSSL/crypto/fipsmodule/service_indicator/internal.h
|
||||
index c5a8113..27f8060 100644
|
||||
--- a/Sources/CCryptoBoringSSL/crypto/fipsmodule/service_indicator/internal.h
|
||||
+++ b/Sources/CCryptoBoringSSL/crypto/fipsmodule/service_indicator/internal.h
|
||||
@@ -17,6 +17,9 @@
|
||||
|
||||
#include <openssl/base.h>
|
||||
|
||||
+#if defined(__cplusplus)
|
||||
+extern "C" {
|
||||
+#endif
|
||||
|
||||
// FIPS_service_indicator_before_call and |FIPS_service_indicator_after_call|
|
||||
// both currently return the same local thread counter which is slowly
|
||||
@@ -37,6 +40,10 @@
|
||||
OPENSSL_EXPORT uint64_t FIPS_service_indicator_before_call(void);
|
||||
OPENSSL_EXPORT uint64_t FIPS_service_indicator_after_call(void);
|
||||
|
||||
+#if defined(__cplusplus)
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#if defined(BORINGSSL_FIPS)
|
||||
|
||||
// FIPS_service_indicator_update_state records that an approved service has been
|
||||
+48
-12
@@ -87,8 +87,8 @@ function mangle_symbols {
|
||||
|
||||
# Begin by building for macOS. We build for two target triples, Intel
|
||||
# and Apple Silicon.
|
||||
swift build --triple "x86_64-apple-macosx" --product CCryptoBoringSSL --enable-test-discovery
|
||||
swift build --triple "arm64-apple-macosx" --product CCryptoBoringSSL --enable-test-discovery
|
||||
swift build --triple "x86_64-apple-macosx" --product CCryptoBoringSSL
|
||||
swift build --triple "arm64-apple-macosx" --product CCryptoBoringSSL
|
||||
(
|
||||
cd "${SRCROOT}"
|
||||
go mod tidy -modcacherw
|
||||
@@ -107,9 +107,9 @@ function mangle_symbols {
|
||||
|
||||
# Now cross compile for our targets.
|
||||
# NOTE: This requires running the `generate-linux-sdks.sh` script first to generate the Swift SDKs.
|
||||
swift build --swift-sdk 5.10-RELEASE_ubuntu_jammy_x86_64 --product CCryptoBoringSSL
|
||||
swift build --swift-sdk 5.10-RELEASE_ubuntu_jammy_aarch64 --product CCryptoBoringSSL
|
||||
swift build --swift-sdk 5.10-RELEASE_ubuntu_jammy_armv7 --product CCryptoBoringSSL
|
||||
swift build --swift-sdk 6.1.2-RELEASE_ubuntu_noble_x86_64 --product CCryptoBoringSSL
|
||||
swift build --swift-sdk 6.1.2-RELEASE_ubuntu_noble_aarch64 --product CCryptoBoringSSL
|
||||
swift build --swift-sdk 6.1.2-RELEASE_ubuntu_noble_armv7 --product CCryptoBoringSSL
|
||||
|
||||
# Now we need to generate symbol mangles for Linux. We can do this in
|
||||
# one go for all of them.
|
||||
@@ -147,6 +147,34 @@ function mangle_symbols {
|
||||
namespace_inlines "$DSTROOT"
|
||||
}
|
||||
|
||||
function mangle_cpp_structures {
|
||||
echo "MANGLING C++ structures"
|
||||
(
|
||||
# We need a .a: may as well get SwiftPM to give it to us.
|
||||
# Temporarily enable the product we need.
|
||||
$sed -i -e 's/MANGLE_START/MANGLE_START*\//' -e 's/MANGLE_END/\/*MANGLE_END/' "${HERE}/Package.swift"
|
||||
|
||||
# Build for macOS.
|
||||
swift build --product CCryptoBoringSSL
|
||||
|
||||
# Woah, this is a hell of a command! What does it do?
|
||||
#
|
||||
# The nm command grabs all global defined symbols. We then run the C++ demangler over them and look for methods with '::' in them:
|
||||
# these are C++ methods. We then exclude any that contain CCryptoBoringSSL (as those are already namespaced!) and any that contain swift
|
||||
# (as those were put there by the Swift runtime, not us). This gives us a list of symbols. The following cut command
|
||||
# grabs the type name from each of those (the bit preceding the '::'). Then, we sort and uniqify that list.
|
||||
# Finally, we remove any symbol that ends in std. This gives us all the structures that need to be renamed.
|
||||
structures=$(nm -gUj "$(swift build --show-bin-path)/libCCryptoBoringSSL.a" | c++filt | grep "::" | grep -v -e "CCryptoBoringSSL" -e "swift" | cut -d : -f1 | grep -v "std$" | $sed -E -e 's/([^<>]*)(<[^<>]*>)?/\1/' | sort | uniq)
|
||||
|
||||
for struct in ${structures}; do
|
||||
echo "#define ${struct} BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, ${struct})" >> "${DSTROOT}/include/CCryptoBoringSSL_boringssl_prefix_symbols.h"
|
||||
done
|
||||
|
||||
# Remove the product, as we no longer need it.
|
||||
$sed -i -e 's/MANGLE_START\*\//MANGLE_START/' -e 's/\/\*MANGLE_END/MANGLE_END/' "${HERE}/Package.swift"
|
||||
)
|
||||
}
|
||||
|
||||
case "$(uname -s)" in
|
||||
Darwin)
|
||||
sed=gsed
|
||||
@@ -175,10 +203,10 @@ echo "CLONING boringssl"
|
||||
mkdir -p "$SRCROOT"
|
||||
git clone https://boringssl.googlesource.com/boringssl "$SRCROOT"
|
||||
cd "$SRCROOT"
|
||||
if [ "$BORINGSSL_REVISION" ]; then
|
||||
if [ "${BORINGSSL_REVISION:-}" ]; then
|
||||
echo "CHECKING OUT boringssl@${BORINGSSL_REVISION}"
|
||||
git checkout "$BORINGSSL_REVISION"
|
||||
else
|
||||
else
|
||||
BORINGSSL_REVISION=$(git rev-parse HEAD)
|
||||
echo "CLONED boringssl@${BORINGSSL_REVISION}"
|
||||
fi
|
||||
@@ -200,7 +228,6 @@ echo "GENERATING assembly helpers"
|
||||
|
||||
PATTERNS=(
|
||||
'include/openssl/*.h'
|
||||
'include/openssl/experimental/*.h'
|
||||
'ssl/*.h'
|
||||
'ssl/*.cc'
|
||||
'crypto/*.h'
|
||||
@@ -218,7 +245,7 @@ PATTERNS=(
|
||||
'gen/bcm/*.S'
|
||||
'third_party/fiat/*.h'
|
||||
'third_party/fiat/asm/*.S'
|
||||
#'third_party/fiat/*.c'
|
||||
'third_party/fiat/*.c.inc'
|
||||
)
|
||||
|
||||
EXCLUDES=(
|
||||
@@ -262,6 +289,11 @@ echo "DISABLING assembly on x86 Windows"
|
||||
|
||||
)
|
||||
|
||||
# Unfortunately, this patch for an upstream bug which incorrectly leaves C symbol using C++ mangling must be
|
||||
# applied before we mangle symbols, so we can't place it with the others below.
|
||||
echo "PATCHING BoringSSL (early)"
|
||||
git apply "${HERE}/scripts/patch-3-missing-extern-c.patch"
|
||||
|
||||
mangle_symbols
|
||||
|
||||
echo "RENAMING header files"
|
||||
@@ -295,6 +327,10 @@ echo "RENAMING header files"
|
||||
popd
|
||||
)
|
||||
|
||||
echo "PATCHING BoringSSL"
|
||||
git apply "${HERE}/scripts/patch-1-inttypes.patch"
|
||||
git apply "${HERE}/scripts/patch-2-more-inttypes.patch"
|
||||
|
||||
# We need to avoid having the stack be executable. BoringSSL does this in its build system, but we can't.
|
||||
echo "PROTECTING against executable stacks"
|
||||
(
|
||||
@@ -303,9 +339,7 @@ echo "PROTECTING against executable stacks"
|
||||
find . -name "*.S" | xargs $sed -i '$ a #if defined(__linux__) && defined(__ELF__)\n.section .note.GNU-stack,"",%progbits\n#endif\n'
|
||||
)
|
||||
|
||||
echo "PATCHING BoringSSL"
|
||||
git apply "${HERE}/scripts/patch-1-inttypes.patch"
|
||||
git apply "${HERE}/scripts/patch-2-more-inttypes.patch"
|
||||
mangle_cpp_structures
|
||||
|
||||
# We need BoringSSL to be modularised
|
||||
echo "MODULARISING BoringSSL"
|
||||
@@ -357,6 +391,8 @@ cat << EOF > "$DSTROOT/include/CCryptoBoringSSL.h"
|
||||
#include "CCryptoBoringSSL_hrss.h"
|
||||
#include "CCryptoBoringSSL_md4.h"
|
||||
#include "CCryptoBoringSSL_md5.h"
|
||||
#include "CCryptoBoringSSL_mldsa.h"
|
||||
#include "CCryptoBoringSSL_mlkem.h"
|
||||
#include "CCryptoBoringSSL_obj_mac.h"
|
||||
#include "CCryptoBoringSSL_objects.h"
|
||||
#include "CCryptoBoringSSL_opensslv.h"
|
||||
|
||||
Reference in new issue
Block a user