From 16cd664aa859e3e728a6cb20ec8cece8e12c8b00 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Mon, 18 Jan 2021 22:59:59 -0800 Subject: [PATCH 01/29] Add CMake build files Motivation: This is to support https://github.com/apple/swift-package-manager/pull/3202, which adds swift-crypto as a dependency to SwiftPM. Modifications: Add CMake files. Result: Can build swift-crypto with cmake. --- .gitignore | 5 + CMakeLists.txt | 31 ++++++ Sources/CCryptoBoringSSL/CMakeLists.txt | 16 +++ Sources/CCryptoBoringSSLShims/CMakeLists.txt | 19 ++++ Sources/CMakeLists.txt | 13 +++ Sources/Crypto/CMakeLists.txt | 81 +++++++++++++++ cmake/modules/CMakeLists.txt | 16 +++ cmake/modules/CryptoConfig.cmake.in | 13 +++ cmake/modules/SwiftSupport.cmake | 104 +++++++++++++++++++ 9 files changed, 298 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 Sources/CCryptoBoringSSL/CMakeLists.txt create mode 100644 Sources/CCryptoBoringSSLShims/CMakeLists.txt create mode 100644 Sources/CMakeLists.txt create mode 100644 Sources/Crypto/CMakeLists.txt create mode 100644 cmake/modules/CMakeLists.txt create mode 100644 cmake/modules/CryptoConfig.cmake.in create mode 100644 cmake/modules/SwiftSupport.cmake diff --git a/.gitignore b/.gitignore index e10443cc0..11dddfc45 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,8 @@ DerivedData **/gyb.pyc .*.sw[nop] + +CMakeFiles +CMakeCache.txt +cmake_*.cmake +*.ninja diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 000000000..55cb71c2a --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,31 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.15.1) + +project(swift-crypto + LANGUAGES C Swift) + +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) + +include(SwiftSupport) + +if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows) + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +else() + set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) + set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib) +endif() +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) +set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) + +add_subdirectory(Sources) +add_subdirectory(cmake/modules) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt new file mode 100644 index 000000000..146eae0ee --- /dev/null +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -0,0 +1,16 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +add_library(CCryptoBoringSSL INTERFACE) + +target_include_directories(CCryptoBoringSSL INTERFACE + include) + +set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSL) diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt new file mode 100644 index 000000000..c4682d7a0 --- /dev/null +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -0,0 +1,19 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +add_library(CCryptoBoringSSLShims STATIC shims.c) + +target_include_directories(CCryptoBoringSSLShims PUBLIC + include) + +target_link_libraries(CCryptoBoringSSLShims PUBLIC + CCryptoBoringSSL) + +set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSLShims) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt new file mode 100644 index 000000000..6279558f5 --- /dev/null +++ b/Sources/CMakeLists.txt @@ -0,0 +1,13 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +add_subdirectory(CCryptoBoringSSL) +add_subdirectory(CCryptoBoringSSLShims) +add_subdirectory(Crypto) diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt new file mode 100644 index 000000000..e21d347c9 --- /dev/null +++ b/Sources/Crypto/CMakeLists.txt @@ -0,0 +1,81 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +add_library(Crypto + AEADs/AES/GCM/AES-GCM.swift + AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift + AEADS/ChachaPoly/ChaChaPoly.swift + AEADS/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift + AEADS/Cipher.swift + AEADS/Nonces.swift + ASN1/ASN1.swift + "ASN1/Basic ASN1 Types/ArraySliceBigint.swift" + "ASN1/Basic ASN1 Types/ASN1BitString.swift" + "ASN1/Basic ASN1 Types/ASN1Identifier.swift" + "ASN1/Basic ASN1 Types/ASN1Integer.swift" + "ASN1/Basic ASN1 Types/ASN1OctetString.swift" + "ASN1/Basic ASN1 Types/ObjectIdentifier.swift" + ASN1/ECDSASignature.swift + ASN1/PEMDocument.swift + ASN1/PKCS8PrivateKey.swift + ASN1/SEC1PrivateKey.swift + ASN1/SubjectPublicKeyInfo.swift + CryptoKitErrors.swift + Digests/BoringSSL/Digest_boring.swift + Digests/Digest.swift + Digests/Digests.swift + Digests/HashFunctions_SHA2.swift + Digests/HashFunctions.swift + Insecure/Insecure_HashFunctions.swift + Insecure/Insecure.swift + "Key Agreement/BoringSSL/ECDH_boring.swift" + "Key Agreement/DH.swift" + "Key Agreement/ECDH.swift" + "Key Derivation/HKDF.swift" + Keys/EC/BoringSSL/Ed25519_boring.swift + Keys/EC/BoringSSL/EllipticCurve_boring.swift + Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift + Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift + Keys/EC/BoringSSL/X25519Keys_boring.swift + Keys/EC/Curve25519.swift + Keys/EC/Ed25519.swift + Keys/EC/NISTCurvesKeys.swift + Keys/EC/X25519Keys.swift + Keys/Symmetric/SymmetricKeys.swift + "Message Authentication Codes/HMAC/HMAC.swift" + "Message Authentication Codes/MACFunctions.swift" + "Message Authentication Codes/MessageAuthenticationCode.swift" + PRF/AES.swift + Signatures/BoringSSL/ECDSA_boring.swift + Signatures/BoringSSL/ECDSASignature_boring.swift + Signatures/BoringSSL/EdDSA_boring.swift + Signatures/ECDSA.swift + Signatures/EdDSA.swift + Signatures/Signature.swift + Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift + Util/BoringSSL/CryptoKitErrors_boring.swift + Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift + Util/BoringSSL/RNG_boring.swift + Util/BoringSSL/SafeCompare_boring.swift + Util/BoringSSL/Zeroization_boring.swift + Util/PrettyBytes.swift + Util/SafeCompare.swift + Util/SecureBytes.swift + Util/Zeroization.swift) + +target_link_libraries(Crypto PUBLIC + CCryptoBoringSSL + CCryptoBoringSSLShims) + +set_target_properties(Crypto PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +_install_target(Crypto) +set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS Crypto) diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt new file mode 100644 index 000000000..3b58c39eb --- /dev/null +++ b/cmake/modules/CMakeLists.txt @@ -0,0 +1,16 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +set(CRYPTO_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/CryptoExports.cmake) +configure_file(CryptoConfig.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/CryptoConfig.cmake) + +get_property(CRYPTO_EXPORTS GLOBAL PROPERTY CRYPTO_EXPORTS) +export(TARGETS ${CRYPTO_EXPORTS} FILE ${CRYPTO_EXPORTS_FILE}) diff --git a/cmake/modules/CryptoConfig.cmake.in b/cmake/modules/CryptoConfig.cmake.in new file mode 100644 index 000000000..d4d43ddf2 --- /dev/null +++ b/cmake/modules/CryptoConfig.cmake.in @@ -0,0 +1,13 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +if(NOT TARGET Crypto) + include(@CRYPTO_EXPORTS_FILE@) +endif() diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake new file mode 100644 index 000000000..8aa3f76e1 --- /dev/null +++ b/cmake/modules/SwiftSupport.cmake @@ -0,0 +1,104 @@ +# This source file is part of the SwiftCrypto open source project +# +# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +# Licensed under Apache License v2.0 +# +# See LICENSE.txt for license information +# See CONTRIBUTORS.md for the list of SwiftCrypto project authors +# +# SPDX-License-Identifier: Apache-2.0 + +# Returns the architecture name in a variable +# +# Usage: +# get_swift_host_arch(result_var_name) +# +# Sets ${result_var_name} with the converted architecture name derived from +# CMAKE_SYSTEM_PROCESSOR. +function(get_swift_host_arch result_var_name) + if("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86_64") + set("${result_var_name}" "x86_64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64") + set("${result_var_name}" "aarch64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "arm64") + set("${result_var_name}" "aarch64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64") + set("${result_var_name}" "powerpc64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "ppc64le") + set("${result_var_name}" "powerpc64le" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "s390x") + set("${result_var_name}" "s390x" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv6l") + set("${result_var_name}" "armv6" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7l") + set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "armv7-a") + set("${result_var_name}" "armv7" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "AMD64") + set("${result_var_name}" "x86_64" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "IA64") + set("${result_var_name}" "itanium" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "x86") + set("${result_var_name}" "i686" PARENT_SCOPE) + elseif("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "i686") + set("${result_var_name}" "i686" PARENT_SCOPE) + else() + message(FATAL_ERROR "Unrecognized architecture on host system: ${CMAKE_SYSTEM_PROCESSOR}") + endif() +endfunction() + +# Returns the os name in a variable +# +# Usage: +# get_swift_host_os(result_var_name) +# +# +# Sets ${result_var_name} with the converted OS name derived from +# CMAKE_SYSTEM_NAME. +function(get_swift_host_os result_var_name) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(${result_var_name} macosx PARENT_SCOPE) + else() + string(TOLOWER ${CMAKE_SYSTEM_NAME} cmake_system_name_lc) + set(${result_var_name} ${cmake_system_name_lc} PARENT_SCOPE) + endif() +endfunction() + +function(_install_target module) + get_swift_host_os(swift_os) + get_target_property(type ${module} TYPE) + + if(type STREQUAL STATIC_LIBRARY) + set(swift swift_static) + else() + set(swift swift) + endif() + + install(TARGETS ${module} + ARCHIVE DESTINATION lib/${swift}/${swift_os} + LIBRARY DESTINATION lib/${swift}/${swift_os} + RUNTIME DESTINATION bin) + if(type STREQUAL EXECUTABLE) + return() + endif() + + get_swift_host_arch(swift_arch) + get_target_property(module_name ${module} Swift_MODULE_NAME) + if(NOT module_name) + set(module_name ${module}) + endif() + + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + install(FILES $/${module_name}.swiftdoc + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule + RENAME ${swift_arch}.swiftdoc) + install(FILES $/${module_name}.swiftmodule + DESTINATION lib/${swift}/${swift_os}/${module_name}.swiftmodule + RENAME ${swift_arch}.swiftmodule) + else() + install(FILES + $/${module_name}.swiftdoc + $/${module_name}.swiftmodule + DESTINATION lib/${swift}/${swift_os}/${swift_arch}) + endif() +endfunction() From 84c5d3346b88ec47f832f31c48dfb39e0bc18658 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Wed, 20 Jan 2021 14:04:27 -0800 Subject: [PATCH 02/29] Specify list of files for CCryptoBoringSSL --- Sources/CCryptoBoringSSL/CMakeLists.txt | 310 ++++++++++++++++++- Sources/CCryptoBoringSSLShims/CMakeLists.txt | 8 +- 2 files changed, 315 insertions(+), 3 deletions(-) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 146eae0ee..0cf6dc761 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -8,9 +8,315 @@ # # SPDX-License-Identifier: Apache-2.0 -add_library(CCryptoBoringSSL INTERFACE) +add_library(CCryptoBoringSSL STATIC + crypto/asn1/a_bitstr.c + crypto/asn1/a_bool.c + crypto/asn1/a_d2i_fp.c + crypto/asn1/a_dup.c + crypto/asn1/a_enum.c + crypto/asn1/a_gentm.c + crypto/asn1/a_i2d_fp.c + crypto/asn1/a_int.c + crypto/asn1/a_mbstr.c + crypto/asn1/a_object.c + crypto/asn1/a_octet.c + crypto/asn1/a_print.c + crypto/asn1/a_strnid.c + crypto/asn1/a_time.c + crypto/asn1/a_type.c + crypto/asn1/a_utctm.c + crypto/asn1/a_utf8.c + crypto/asn1/asn1_lib.c + crypto/asn1/asn1_par.c + crypto/asn1/asn_pack.c + crypto/asn1/f_enum.c + crypto/asn1/f_int.c + crypto/asn1/f_string.c + crypto/asn1/tasn_dec.c + crypto/asn1/tasn_enc.c + crypto/asn1/tasn_fre.c + crypto/asn1/tasn_new.c + crypto/asn1/tasn_typ.c + crypto/asn1/tasn_utl.c + crypto/asn1/time_support.c + crypto/base64/base64.c + crypto/bio/bio.c + crypto/bio/bio_mem.c + crypto/bio/connect.c + crypto/bio/fd.c + crypto/bio/file.c + crypto/bio/hexdump.c + crypto/bio/pair.c + crypto/bio/printf.c + crypto/bio/socket.c + crypto/bio/socket_helper.c + crypto/bn_extra/bn_asn1.c + crypto/bn_extra/convert.c + crypto/buf/buf.c + crypto/bytestring/asn1_compat.c + crypto/bytestring/ber.c + crypto/bytestring/cbb.c + crypto/bytestring/cbs.c + crypto/bytestring/unicode.c + crypto/chacha/chacha.c + crypto/cipher_extra/cipher_extra.c + crypto/cipher_extra/derive_key.c + crypto/cipher_extra/e_aesccm.c + crypto/cipher_extra/e_aesctrhmac.c + crypto/cipher_extra/e_aesgcmsiv.c + crypto/cipher_extra/e_chacha20poly1305.c + crypto/cipher_extra/e_null.c + crypto/cipher_extra/e_rc2.c + crypto/cipher_extra/e_rc4.c + crypto/cipher_extra/e_tls.c + crypto/cipher_extra/tls_cbc.c + crypto/cmac/cmac.c + crypto/conf/conf.c + crypto/cpu-aarch64-fuchsia.c + crypto/cpu-aarch64-linux.c + crypto/cpu-arm-linux.c + crypto/cpu-arm.c + crypto/cpu-intel.c + crypto/cpu-ppc64le.c + crypto/crypto.c + crypto/curve25519/curve25519.c + crypto/curve25519/spake25519.c + crypto/dh/check.c + crypto/dh/dh.c + crypto/dh/dh_asn1.c + crypto/dh/params.c + crypto/digest_extra/digest_extra.c + crypto/dsa/dsa.c + crypto/dsa/dsa_asn1.c + crypto/ec_extra/ec_asn1.c + crypto/ec_extra/ec_derive.c + crypto/ec_extra/hash_to_curve.c + crypto/ecdh_extra/ecdh_extra.c + crypto/ecdsa_extra/ecdsa_asn1.c + crypto/engine/engine.c + crypto/err/err.c + crypto/err/err_data.c + crypto/evp/digestsign.c + crypto/evp/evp.c + crypto/evp/evp_asn1.c + crypto/evp/evp_ctx.c + crypto/evp/p_dsa_asn1.c + crypto/evp/p_ec.c + crypto/evp/p_ec_asn1.c + crypto/evp/p_ed25519.c + crypto/evp/p_ed25519_asn1.c + crypto/evp/p_rsa.c + crypto/evp/p_rsa_asn1.c + crypto/evp/p_x25519.c + crypto/evp/p_x25519_asn1.c + crypto/evp/pbkdf.c + crypto/evp/print.c + crypto/evp/scrypt.c + crypto/evp/sign.c + crypto/ex_data.c + crypto/fipsmodule/aes/aes.c + crypto/fipsmodule/aes/aes_nohw.c + crypto/fipsmodule/aes/key_wrap.c + crypto/fipsmodule/aes/mode_wrappers.c + crypto/fipsmodule/bn/add.c + crypto/fipsmodule/bn/asm/x86_64-gcc.c + crypto/fipsmodule/bn/bn.c + crypto/fipsmodule/bn/bytes.c + crypto/fipsmodule/bn/cmp.c + crypto/fipsmodule/bn/ctx.c + crypto/fipsmodule/bn/div.c + crypto/fipsmodule/bn/div_extra.c + crypto/fipsmodule/bn/exponentiation.c + crypto/fipsmodule/bn/gcd.c + crypto/fipsmodule/bn/gcd_extra.c + crypto/fipsmodule/bn/generic.c + crypto/fipsmodule/bn/jacobi.c + crypto/fipsmodule/bn/montgomery.c + crypto/fipsmodule/bn/montgomery_inv.c + crypto/fipsmodule/bn/mul.c + crypto/fipsmodule/bn/prime.c + crypto/fipsmodule/bn/random.c + crypto/fipsmodule/bn/rsaz_exp.c + crypto/fipsmodule/bn/shift.c + crypto/fipsmodule/bn/sqrt.c + crypto/fipsmodule/cipher/aead.c + crypto/fipsmodule/cipher/cipher.c + crypto/fipsmodule/cipher/e_aes.c + crypto/fipsmodule/cipher/e_des.c + crypto/fipsmodule/des/des.c + crypto/fipsmodule/digest/digest.c + crypto/fipsmodule/digest/digests.c + crypto/fipsmodule/ec/ec.c + crypto/fipsmodule/ec/ec_key.c + crypto/fipsmodule/ec/ec_montgomery.c + crypto/fipsmodule/ec/felem.c + crypto/fipsmodule/ec/oct.c + crypto/fipsmodule/ec/p224-64.c + crypto/fipsmodule/ec/p256-x86_64.c + crypto/fipsmodule/ec/p256.c + crypto/fipsmodule/ec/scalar.c + crypto/fipsmodule/ec/simple.c + crypto/fipsmodule/ec/simple_mul.c + crypto/fipsmodule/ec/util.c + crypto/fipsmodule/ec/wnaf.c + crypto/fipsmodule/ecdh/ecdh.c + crypto/fipsmodule/ecdsa/ecdsa.c + crypto/fipsmodule/fips_shared_support.c + crypto/fipsmodule/hmac/hmac.c + crypto/fipsmodule/is_fips.c + crypto/fipsmodule/md4/md4.c + crypto/fipsmodule/md5/md5.c + crypto/fipsmodule/modes/cbc.c + crypto/fipsmodule/modes/cfb.c + crypto/fipsmodule/modes/ctr.c + crypto/fipsmodule/modes/gcm.c + crypto/fipsmodule/modes/gcm_nohw.c + crypto/fipsmodule/modes/ofb.c + crypto/fipsmodule/modes/polyval.c + crypto/fipsmodule/rand/ctrdrbg.c + crypto/fipsmodule/rand/fork_detect.c + crypto/fipsmodule/rand/rand.c + crypto/fipsmodule/rand/urandom.c + crypto/fipsmodule/rsa/blinding.c + crypto/fipsmodule/rsa/padding.c + crypto/fipsmodule/rsa/rsa.c + crypto/fipsmodule/rsa/rsa_impl.c + crypto/fipsmodule/self_check/self_check.c + crypto/fipsmodule/sha/sha1-altivec.c + crypto/fipsmodule/sha/sha1.c + crypto/fipsmodule/sha/sha256.c + crypto/fipsmodule/sha/sha512.c + crypto/fipsmodule/tls/kdf.c + crypto/hkdf/hkdf.c + crypto/hpke/hpke.c + crypto/hrss/hrss.c + crypto/lhash/lhash.c + crypto/mem.c + crypto/obj/obj.c + crypto/obj/obj_xref.c + crypto/pem/pem_all.c + crypto/pem/pem_info.c + crypto/pem/pem_lib.c + crypto/pem/pem_oth.c + crypto/pem/pem_pk8.c + crypto/pem/pem_pkey.c + crypto/pem/pem_x509.c + crypto/pem/pem_xaux.c + crypto/pkcs7/pkcs7.c + crypto/pkcs7/pkcs7_x509.c + crypto/pkcs8/p5_pbev2.c + crypto/pkcs8/pkcs8.c + crypto/pkcs8/pkcs8_x509.c + crypto/poly1305/poly1305.c + crypto/poly1305/poly1305_arm.c + crypto/poly1305/poly1305_vec.c + crypto/pool/pool.c + crypto/rand_extra/deterministic.c + crypto/rand_extra/forkunsafe.c + crypto/rand_extra/fuchsia.c + crypto/rand_extra/rand_extra.c + crypto/rand_extra/windows.c + crypto/rc4/rc4.c + crypto/refcount_c11.c + crypto/refcount_lock.c + crypto/rsa_extra/rsa_asn1.c + crypto/rsa_extra/rsa_print.c + crypto/siphash/siphash.c + crypto/stack/stack.c + crypto/thread.c + crypto/thread_none.c + crypto/thread_pthread.c + crypto/thread_win.c + crypto/trust_token/pmbtoken.c + crypto/trust_token/trust_token.c + crypto/trust_token/voprf.c + crypto/x509/a_digest.c + crypto/x509/a_sign.c + crypto/x509/a_strex.c + crypto/x509/a_verify.c + crypto/x509/algorithm.c + crypto/x509/asn1_gen.c + crypto/x509/by_dir.c + crypto/x509/by_file.c + crypto/x509/i2d_pr.c + crypto/x509/rsa_pss.c + crypto/x509/t_crl.c + crypto/x509/t_req.c + crypto/x509/t_x509.c + crypto/x509/t_x509a.c + crypto/x509/x509.c + crypto/x509/x509_att.c + crypto/x509/x509_cmp.c + crypto/x509/x509_d2.c + crypto/x509/x509_def.c + crypto/x509/x509_ext.c + crypto/x509/x509_lu.c + crypto/x509/x509_obj.c + crypto/x509/x509_r2x.c + crypto/x509/x509_req.c + crypto/x509/x509_set.c + crypto/x509/x509_trs.c + crypto/x509/x509_txt.c + crypto/x509/x509_v3.c + crypto/x509/x509_vfy.c + crypto/x509/x509_vpm.c + crypto/x509/x509cset.c + crypto/x509/x509name.c + crypto/x509/x509rset.c + crypto/x509/x509spki.c + crypto/x509/x_algor.c + crypto/x509/x_all.c + crypto/x509/x_attrib.c + crypto/x509/x_crl.c + crypto/x509/x_exten.c + crypto/x509/x_info.c + crypto/x509/x_name.c + crypto/x509/x_pkey.c + crypto/x509/x_pubkey.c + crypto/x509/x_req.c + crypto/x509/x_sig.c + crypto/x509/x_spki.c + crypto/x509/x_val.c + crypto/x509/x_x509.c + crypto/x509/x_x509a.c + crypto/x509v3/pcy_cache.c + crypto/x509v3/pcy_data.c + crypto/x509v3/pcy_lib.c + crypto/x509v3/pcy_map.c + crypto/x509v3/pcy_node.c + crypto/x509v3/pcy_tree.c + crypto/x509v3/v3_akey.c + crypto/x509v3/v3_akeya.c + crypto/x509v3/v3_alt.c + crypto/x509v3/v3_bcons.c + crypto/x509v3/v3_bitst.c + crypto/x509v3/v3_conf.c + crypto/x509v3/v3_cpols.c + crypto/x509v3/v3_crld.c + crypto/x509v3/v3_enum.c + crypto/x509v3/v3_extku.c + crypto/x509v3/v3_genn.c + crypto/x509v3/v3_ia5.c + crypto/x509v3/v3_info.c + crypto/x509v3/v3_int.c + crypto/x509v3/v3_lib.c + crypto/x509v3/v3_ncons.c + crypto/x509v3/v3_ocsp.c + crypto/x509v3/v3_pci.c + crypto/x509v3/v3_pcia.c + crypto/x509v3/v3_pcons.c + crypto/x509v3/v3_pmaps.c + crypto/x509v3/v3_prn.c + crypto/x509v3/v3_purp.c + crypto/x509v3/v3_skey.c + crypto/x509v3/v3_utl.c) -target_include_directories(CCryptoBoringSSL INTERFACE +target_include_directories(CCryptoBoringSSL PUBLIC include) + +set_target_properties(CCryptoBoringSSL PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +_install_target(CCryptoBoringSSL) set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSL) diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt index c4682d7a0..2a688e0a4 100644 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -8,12 +8,18 @@ # # SPDX-License-Identifier: Apache-2.0 -add_library(CCryptoBoringSSLShims STATIC shims.c) +add_library(CCryptoBoringSSLShims STATIC + shims.c) target_include_directories(CCryptoBoringSSLShims PUBLIC include) target_link_libraries(CCryptoBoringSSLShims PUBLIC CCryptoBoringSSL) + +set_target_properties(CCryptoBoringSSLShims PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) + +_install_target(CCryptoBoringSSLShims) set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSLShims) From 2a842bd39f74228a6e97f0aa8b9f70821b2bb11c Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 16:52:08 -0800 Subject: [PATCH 03/29] Set BUILD_SHARED_LIBS --- .gitignore | 2 +- CMakeLists.txt | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 11dddfc45..0acc47bb7 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ DerivedData CMakeFiles CMakeCache.txt cmake_*.cmake -*.ninja +*.ninja* diff --git a/CMakeLists.txt b/CMakeLists.txt index 55cb71c2a..39cd050e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,5 +27,9 @@ endif() set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift) +if(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin) + option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) +endif() + add_subdirectory(Sources) add_subdirectory(cmake/modules) From ba7fad3f31a9dcdde10c190c0875d432b7f52c43 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 16:54:21 -0800 Subject: [PATCH 04/29] Set WIN32_LEAN_AND_MEAN --- Sources/CCryptoBoringSSL/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 0cf6dc761..72899f390 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -317,6 +317,9 @@ target_include_directories(CCryptoBoringSSL PUBLIC set_target_properties(CCryptoBoringSSL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_compile_definitions(CCryptoBoringSSL PRIVATE + $<$:WIN32_LEAN_AND_MEAN>) + _install_target(CCryptoBoringSSL) set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSL) From 5c1c060430f715233913aa5387b69a2b8de0e752 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 17:08:00 -0800 Subject: [PATCH 05/29] don't install CCryptoBoringSSL --- Sources/CCryptoBoringSSL/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 72899f390..7ddade58e 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -319,7 +319,5 @@ set_target_properties(CCryptoBoringSSL PROPERTIES target_compile_definitions(CCryptoBoringSSL PRIVATE $<$:WIN32_LEAN_AND_MEAN>) - -_install_target(CCryptoBoringSSL) set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSL) From 10ef3bd6b66ee688b90d95f9db0ac8f4aba086ea Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 17:18:46 -0800 Subject: [PATCH 06/29] don't install CCryptoBoringSSLShims --- Sources/CCryptoBoringSSLShims/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt index 2a688e0a4..c12c018e5 100644 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -19,7 +19,5 @@ target_link_libraries(CCryptoBoringSSLShims PUBLIC set_target_properties(CCryptoBoringSSLShims PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) - -_install_target(CCryptoBoringSSLShims) set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSLShims) From e7a37329db21d9f95a6efd4c651c47a63d7cf24b Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 17:23:15 -0800 Subject: [PATCH 07/29] rename project --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 39cd050e6..e334edaa6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ cmake_minimum_required(VERSION 3.15.1) -project(swift-crypto +project(SwiftCrypto LANGUAGES C Swift) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) From 638a69ce2db683ea2327ceea8aadcaa2bf0b5c57 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 21 Jan 2021 18:34:23 -0800 Subject: [PATCH 08/29] build: remove bleeding whitespace (NFC) --- CMakeLists.txt | 2 +- Sources/CCryptoBoringSSL/CMakeLists.txt | 2 +- Sources/CCryptoBoringSSLShims/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e334edaa6..b2f420bd1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ cmake_minimum_required(VERSION 3.15.1) project(SwiftCrypto LANGUAGES C Swift) - + list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(SwiftSupport) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 7ddade58e..1a5159cb1 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -313,7 +313,7 @@ add_library(CCryptoBoringSSL STATIC target_include_directories(CCryptoBoringSSL PUBLIC include) - + set_target_properties(CCryptoBoringSSL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt index c12c018e5..26897f913 100644 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -16,7 +16,7 @@ target_include_directories(CCryptoBoringSSLShims PUBLIC target_link_libraries(CCryptoBoringSSLShims PUBLIC CCryptoBoringSSL) - + set_target_properties(CCryptoBoringSSLShims PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) From 2f6c1ac91ddf6c51191aa0b535d370dac3e1d76b Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 21 Jan 2021 18:34:43 -0800 Subject: [PATCH 09/29] CCryptoBoringSSL: repair the Windows build Windows requires that `WIN32_LEAN_AND_MEAN` is defined. This replicates the behaviour from `Package.swift`. --- Sources/CCryptoBoringSSL/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 1a5159cb1..4e8e20264 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -314,6 +314,8 @@ add_library(CCryptoBoringSSL STATIC target_include_directories(CCryptoBoringSSL PUBLIC include) +target_compile_definitions(CCryptoBoringSSL PRIVATE + $<$:WIN32_LEAN_AND_MEAN>) set_target_properties(CCryptoBoringSSL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) From ad9691370af5ac64b8d2477e139fa9c6edd279d4 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 20:45:36 -0800 Subject: [PATCH 10/29] remove my WIN32_LEAN_AND_MEAN change --- Sources/CCryptoBoringSSL/CMakeLists.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 4e8e20264..728260469 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -318,8 +318,5 @@ target_compile_definitions(CCryptoBoringSSL PRIVATE $<$:WIN32_LEAN_AND_MEAN>) set_target_properties(CCryptoBoringSSL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) - -target_compile_definitions(CCryptoBoringSSL PRIVATE - $<$:WIN32_LEAN_AND_MEAN>) set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSL) From 13951e6e539f617601135deb9f3ce20aaa6aa381 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 21 Jan 2021 18:35:36 -0800 Subject: [PATCH 11/29] build: explicitly propagate include paths The include path for static libraries does not seem to propagate via the `link_libraries` for other static libraries (and Swift libraries). This explicitly passes them along to resolve header search paths. --- Sources/CCryptoBoringSSLShims/CMakeLists.txt | 3 ++- Sources/Crypto/CMakeLists.txt | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt index 26897f913..c67b57268 100644 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -12,7 +12,8 @@ add_library(CCryptoBoringSSLShims STATIC shims.c) target_include_directories(CCryptoBoringSSLShims PUBLIC - include) + include + $) target_link_libraries(CCryptoBoringSSLShims PUBLIC CCryptoBoringSSL) diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index e21d347c9..46aa6747a 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -73,7 +73,9 @@ add_library(Crypto target_link_libraries(Crypto PUBLIC CCryptoBoringSSL CCryptoBoringSSLShims) - +target_include_directories(Crypto PRIVATE + $ + $) set_target_properties(Crypto PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) From fd1eaab961e7764b1a05c1318540e7bd27a458c2 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Thu, 21 Jan 2021 18:51:29 -0800 Subject: [PATCH 12/29] CCryptoBoringSSL,CCryptoBoringSSLShims: add modulemaps This adds modulemaps to allow building with CMake. --- Sources/CCryptoBoringSSL/include/module.modulemap | 4 ++++ Sources/CCryptoBoringSSLShims/include/module.modulemap | 4 ++++ 2 files changed, 8 insertions(+) create mode 100644 Sources/CCryptoBoringSSL/include/module.modulemap create mode 100644 Sources/CCryptoBoringSSLShims/include/module.modulemap diff --git a/Sources/CCryptoBoringSSL/include/module.modulemap b/Sources/CCryptoBoringSSL/include/module.modulemap new file mode 100644 index 000000000..fd956fd6d --- /dev/null +++ b/Sources/CCryptoBoringSSL/include/module.modulemap @@ -0,0 +1,4 @@ +module CCryptoBoringSSL { + umbrella header "CCryptoBoringSSL.h" + export * +} diff --git a/Sources/CCryptoBoringSSLShims/include/module.modulemap b/Sources/CCryptoBoringSSLShims/include/module.modulemap new file mode 100644 index 000000000..d6e82d6f7 --- /dev/null +++ b/Sources/CCryptoBoringSSLShims/include/module.modulemap @@ -0,0 +1,4 @@ +module CCryptoBoringSSLShims { + umbrella header "CCryptoBoringSSLShims.h" + export * +} From c47a205b6af90a162e23025f60cd6f84916ee670 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 21:14:01 -0800 Subject: [PATCH 13/29] Fix modulemap files For build errors like this: ``` umbrella for module 'CCryptoBoringSSL' already covers this directory umbrella header "/Users/ylee/apple/swift-crypto/Sources/CCryptoBoringSSL/include/CCryptoBoringSSL.h" ``` --- Sources/CCryptoBoringSSL/include/module.modulemap | 2 +- Sources/CCryptoBoringSSLShims/include/module.modulemap | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/CCryptoBoringSSL/include/module.modulemap b/Sources/CCryptoBoringSSL/include/module.modulemap index fd956fd6d..6c5352d53 100644 --- a/Sources/CCryptoBoringSSL/include/module.modulemap +++ b/Sources/CCryptoBoringSSL/include/module.modulemap @@ -1,4 +1,4 @@ module CCryptoBoringSSL { - umbrella header "CCryptoBoringSSL.h" + header "CCryptoBoringSSL.h" export * } diff --git a/Sources/CCryptoBoringSSLShims/include/module.modulemap b/Sources/CCryptoBoringSSLShims/include/module.modulemap index d6e82d6f7..533962ae3 100644 --- a/Sources/CCryptoBoringSSLShims/include/module.modulemap +++ b/Sources/CCryptoBoringSSLShims/include/module.modulemap @@ -1,4 +1,4 @@ module CCryptoBoringSSLShims { - umbrella header "CCryptoBoringSSLShims.h" + header "CCryptoBoringSSLShims.h" export * } From 5aa1ff2e80dbcd6ad3cbfdfaccf91648dc26196f Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 23:05:21 -0800 Subject: [PATCH 14/29] Builds on ubuntu-focal --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index b2f420bd1..0f6d472d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,9 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(SwiftSupport) +# Fixes error: "requires dynamic R_X86_64_PC32 reloc against 'XXX' which may overflow at runtime" +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") + if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) From b3fa9111d7f15e2563d7dd1e7ee1dbf642cfb08d Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Thu, 21 Jan 2021 23:37:47 -0800 Subject: [PATCH 15/29] Trying finding and linking CryptoKit on Apple platforms --- CMakeLists.txt | 7 +++++++ Sources/Crypto/CMakeLists.txt | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f6d472d8..65229fedd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,5 +34,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin) option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) endif() +if(APPLE) + find_library(CRYPTO_KIT CryptoKit) + if(NOT CRYPTO_KIT) + message(FATAL_ERROR "CryptoKit not found") + endif() +endif() + add_subdirectory(Sources) add_subdirectory(cmake/modules) diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index 46aa6747a..8bb707946 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -73,6 +73,12 @@ add_library(Crypto target_link_libraries(Crypto PUBLIC CCryptoBoringSSL CCryptoBoringSSLShims) + +if(APPLE AND CRYPTO_KIT) + target_link_libraries(Crypto PRIVATE + ${CRYPTO_KIT}) +endif() + target_include_directories(Crypto PRIVATE $ $) From 69512b9311236f69bc456e8b796ac128f180820c Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Fri, 22 Jan 2021 09:01:03 -0800 Subject: [PATCH 16/29] Set '-fPIC' the correct way --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 65229fedd..0f9fe7589 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,9 +17,6 @@ list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) include(SwiftSupport) -# Fixes error: "requires dynamic R_X86_64_PC32 reloc against 'XXX' which may overflow at runtime" -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - if(CMAKE_VERSION VERSION_LESS 3.16 AND CMAKE_SYSTEM_NAME STREQUAL Windows) set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) @@ -34,6 +31,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Windows OR CMAKE_SYSTEM_NAME STREQUAL Darwin) option(BUILD_SHARED_LIBS "Build shared libraries by default" YES) endif() +if(BUILD_SHARED_LIBS) + set(CMAKE_POSITION_INDEPENDENT_CODE YES) +endif() + if(APPLE) find_library(CRYPTO_KIT CryptoKit) if(NOT CRYPTO_KIT) From 56c512e76cecf4eb66f9d28d6945492cfd7cf23a Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Fri, 22 Jan 2021 09:20:32 -0800 Subject: [PATCH 17/29] build: build macOS against BoringSSL Make the BoringSSL based build for macOS complete enough. We can now build a shared library version of SwiftCrypto on macOS without CryptoKit. --- CMakeLists.txt | 9 +-------- Sources/CCryptoBoringSSL/CMakeLists.txt | 23 +++++++++++++++++++++++ Sources/Crypto/CMakeLists.txt | 14 +++++--------- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f9fe7589..57f357387 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ cmake_minimum_required(VERSION 3.15.1) project(SwiftCrypto - LANGUAGES C Swift) + LANGUAGES ASM C Swift) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules) @@ -35,12 +35,5 @@ if(BUILD_SHARED_LIBS) set(CMAKE_POSITION_INDEPENDENT_CODE YES) endif() -if(APPLE) - find_library(CRYPTO_KIT CryptoKit) - if(NOT CRYPTO_KIT) - message(FATAL_ERROR "CryptoKit not found") - endif() -endif() - add_subdirectory(Sources) add_subdirectory(cmake/modules) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 728260469..41df7471d 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -310,6 +310,29 @@ add_library(CCryptoBoringSSL STATIC crypto/x509v3/v3_purp.c crypto/x509v3/v3_skey.c crypto/x509v3/v3_utl.c) +if(APPLE) + if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") + target_sources(CCryptoBoringSSL PRIVATE + crypto/chacha/chacha-x86_64.mac.x86_64.S + crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S + crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S + crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S + crypto/fipsmodule/aesni-x86_64.mac.x86_64.S + crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S + crypto/fipsmodule/ghash-x86_64.mac.x86_64.S + crypto/fipsmodule/md5-x86_64.mac.x86_64.S + crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S + crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S + crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S + crypto/fipsmodule/rsaz-avx2.mac.x86_64.S + crypto/fipsmodule/sha1-x86_64.mac.x86_64.S + crypto/fipsmodule/sha256-x86_64.mac.x86_64.S + crypto/fipsmodule/sha512-x86_64.mac.x86_64.S + crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S + crypto/fipsmodule/x86_64-mont.mac.x86_64.S + crypto/fipsmodule/x86_64-mont5.mac.x86_64.S) + endif() +endif() target_include_directories(CCryptoBoringSSL PUBLIC include) diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index 8bb707946..f24f2f082 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -70,18 +70,14 @@ add_library(Crypto Util/SecureBytes.swift Util/Zeroization.swift) -target_link_libraries(Crypto PUBLIC - CCryptoBoringSSL - CCryptoBoringSSLShims) - -if(APPLE AND CRYPTO_KIT) - target_link_libraries(Crypto PRIVATE - ${CRYPTO_KIT}) -endif() - +target_compile_definitions(Crypto PRIVATE + CRYPTO_IN_SWIFTPM_FORCE_BUILD_API) target_include_directories(Crypto PRIVATE $ $) +target_link_libraries(Crypto PUBLIC + CCryptoBoringSSL + CCryptoBoringSSLShims) set_target_properties(Crypto PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) From bf80ab885991acb88614fb8395b47a1297ad493e Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Fri, 22 Jan 2021 16:04:50 -0800 Subject: [PATCH 18/29] Fix check_no_api_breakages script Script was failing at "build_and_do" steps. Order seems to matter. - When build new then old, build fails. - When build old then new, build succeeds. This might be because "new" build adds files to `.build` that "old" doesn't expect? Probably because of the `.modulemap` files that were added as part of the PR. Cleaning up `.build` in between builds seems to fix the problem. --- scripts/check_no_api_breakages.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_no_api_breakages.sh b/scripts/check_no_api_breakages.sh index c6bff9eea..64303a577 100755 --- a/scripts/check_no_api_breakages.sh +++ b/scripts/check_no_api_breakages.sh @@ -36,6 +36,7 @@ function build_and_do() { ( cd "$repodir" git checkout -q "$tag" + rm -rf .build swift build while read -r module; do swift api-digester -sdk "$sdk" -dump-sdk -module "$module" \ From 2e0bae22bbfeecea7998f7ca45eb1dca871addda Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Sun, 24 Jan 2021 16:16:04 -0800 Subject: [PATCH 19/29] Script to update CMakeLists.txt Regenerate CMakeLists.txt using script --- Sources/CCryptoBoringSSL/CMakeLists.txt | 602 +++++++++---------- Sources/CCryptoBoringSSLShims/CMakeLists.txt | 2 +- Sources/Crypto/CMakeLists.txt | 96 +-- scripts/update_cmakelists.sh | 62 ++ 4 files changed, 412 insertions(+), 350 deletions(-) create mode 100755 scripts/update_cmakelists.sh diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 41df7471d..afac3b2d3 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -9,307 +9,307 @@ # SPDX-License-Identifier: Apache-2.0 add_library(CCryptoBoringSSL STATIC - crypto/asn1/a_bitstr.c - crypto/asn1/a_bool.c - crypto/asn1/a_d2i_fp.c - crypto/asn1/a_dup.c - crypto/asn1/a_enum.c - crypto/asn1/a_gentm.c - crypto/asn1/a_i2d_fp.c - crypto/asn1/a_int.c - crypto/asn1/a_mbstr.c - crypto/asn1/a_object.c - crypto/asn1/a_octet.c - crypto/asn1/a_print.c - crypto/asn1/a_strnid.c - crypto/asn1/a_time.c - crypto/asn1/a_type.c - crypto/asn1/a_utctm.c - crypto/asn1/a_utf8.c - crypto/asn1/asn1_lib.c - crypto/asn1/asn1_par.c - crypto/asn1/asn_pack.c - crypto/asn1/f_enum.c - crypto/asn1/f_int.c - crypto/asn1/f_string.c - crypto/asn1/tasn_dec.c - crypto/asn1/tasn_enc.c - crypto/asn1/tasn_fre.c - crypto/asn1/tasn_new.c - crypto/asn1/tasn_typ.c - crypto/asn1/tasn_utl.c - crypto/asn1/time_support.c - crypto/base64/base64.c - crypto/bio/bio.c - crypto/bio/bio_mem.c - crypto/bio/connect.c - crypto/bio/fd.c - crypto/bio/file.c - crypto/bio/hexdump.c - crypto/bio/pair.c - crypto/bio/printf.c - crypto/bio/socket.c - crypto/bio/socket_helper.c - crypto/bn_extra/bn_asn1.c - crypto/bn_extra/convert.c - crypto/buf/buf.c - crypto/bytestring/asn1_compat.c - crypto/bytestring/ber.c - crypto/bytestring/cbb.c - crypto/bytestring/cbs.c - crypto/bytestring/unicode.c - crypto/chacha/chacha.c - crypto/cipher_extra/cipher_extra.c - crypto/cipher_extra/derive_key.c - crypto/cipher_extra/e_aesccm.c - crypto/cipher_extra/e_aesctrhmac.c - crypto/cipher_extra/e_aesgcmsiv.c - crypto/cipher_extra/e_chacha20poly1305.c - crypto/cipher_extra/e_null.c - crypto/cipher_extra/e_rc2.c - crypto/cipher_extra/e_rc4.c - crypto/cipher_extra/e_tls.c - crypto/cipher_extra/tls_cbc.c - crypto/cmac/cmac.c - crypto/conf/conf.c - crypto/cpu-aarch64-fuchsia.c - crypto/cpu-aarch64-linux.c - crypto/cpu-arm-linux.c - crypto/cpu-arm.c - crypto/cpu-intel.c - crypto/cpu-ppc64le.c - crypto/crypto.c - crypto/curve25519/curve25519.c - crypto/curve25519/spake25519.c - crypto/dh/check.c - crypto/dh/dh.c - crypto/dh/dh_asn1.c - crypto/dh/params.c - crypto/digest_extra/digest_extra.c - crypto/dsa/dsa.c - crypto/dsa/dsa_asn1.c - crypto/ec_extra/ec_asn1.c - crypto/ec_extra/ec_derive.c - crypto/ec_extra/hash_to_curve.c - crypto/ecdh_extra/ecdh_extra.c - crypto/ecdsa_extra/ecdsa_asn1.c - crypto/engine/engine.c - crypto/err/err.c - crypto/err/err_data.c - crypto/evp/digestsign.c - crypto/evp/evp.c - crypto/evp/evp_asn1.c - crypto/evp/evp_ctx.c - crypto/evp/p_dsa_asn1.c - crypto/evp/p_ec.c - crypto/evp/p_ec_asn1.c - crypto/evp/p_ed25519.c - crypto/evp/p_ed25519_asn1.c - crypto/evp/p_rsa.c - crypto/evp/p_rsa_asn1.c - crypto/evp/p_x25519.c - crypto/evp/p_x25519_asn1.c - crypto/evp/pbkdf.c - crypto/evp/print.c - crypto/evp/scrypt.c - crypto/evp/sign.c - crypto/ex_data.c - crypto/fipsmodule/aes/aes.c - crypto/fipsmodule/aes/aes_nohw.c - crypto/fipsmodule/aes/key_wrap.c - crypto/fipsmodule/aes/mode_wrappers.c - crypto/fipsmodule/bn/add.c - crypto/fipsmodule/bn/asm/x86_64-gcc.c - crypto/fipsmodule/bn/bn.c - crypto/fipsmodule/bn/bytes.c - crypto/fipsmodule/bn/cmp.c - crypto/fipsmodule/bn/ctx.c - crypto/fipsmodule/bn/div.c - crypto/fipsmodule/bn/div_extra.c - crypto/fipsmodule/bn/exponentiation.c - crypto/fipsmodule/bn/gcd.c - crypto/fipsmodule/bn/gcd_extra.c - crypto/fipsmodule/bn/generic.c - crypto/fipsmodule/bn/jacobi.c - crypto/fipsmodule/bn/montgomery.c - crypto/fipsmodule/bn/montgomery_inv.c - crypto/fipsmodule/bn/mul.c - crypto/fipsmodule/bn/prime.c - crypto/fipsmodule/bn/random.c - crypto/fipsmodule/bn/rsaz_exp.c - crypto/fipsmodule/bn/shift.c - crypto/fipsmodule/bn/sqrt.c - crypto/fipsmodule/cipher/aead.c - crypto/fipsmodule/cipher/cipher.c - crypto/fipsmodule/cipher/e_aes.c - crypto/fipsmodule/cipher/e_des.c - crypto/fipsmodule/des/des.c - crypto/fipsmodule/digest/digest.c - crypto/fipsmodule/digest/digests.c - crypto/fipsmodule/ec/ec.c - crypto/fipsmodule/ec/ec_key.c - crypto/fipsmodule/ec/ec_montgomery.c - crypto/fipsmodule/ec/felem.c - crypto/fipsmodule/ec/oct.c - crypto/fipsmodule/ec/p224-64.c - crypto/fipsmodule/ec/p256-x86_64.c - crypto/fipsmodule/ec/p256.c - crypto/fipsmodule/ec/scalar.c - crypto/fipsmodule/ec/simple.c - crypto/fipsmodule/ec/simple_mul.c - crypto/fipsmodule/ec/util.c - crypto/fipsmodule/ec/wnaf.c - crypto/fipsmodule/ecdh/ecdh.c - crypto/fipsmodule/ecdsa/ecdsa.c - crypto/fipsmodule/fips_shared_support.c - crypto/fipsmodule/hmac/hmac.c - crypto/fipsmodule/is_fips.c - crypto/fipsmodule/md4/md4.c - crypto/fipsmodule/md5/md5.c - crypto/fipsmodule/modes/cbc.c - crypto/fipsmodule/modes/cfb.c - crypto/fipsmodule/modes/ctr.c - crypto/fipsmodule/modes/gcm.c - crypto/fipsmodule/modes/gcm_nohw.c - crypto/fipsmodule/modes/ofb.c - crypto/fipsmodule/modes/polyval.c - crypto/fipsmodule/rand/ctrdrbg.c - crypto/fipsmodule/rand/fork_detect.c - crypto/fipsmodule/rand/rand.c - crypto/fipsmodule/rand/urandom.c - crypto/fipsmodule/rsa/blinding.c - crypto/fipsmodule/rsa/padding.c - crypto/fipsmodule/rsa/rsa.c - crypto/fipsmodule/rsa/rsa_impl.c - crypto/fipsmodule/self_check/self_check.c - crypto/fipsmodule/sha/sha1-altivec.c - crypto/fipsmodule/sha/sha1.c - crypto/fipsmodule/sha/sha256.c - crypto/fipsmodule/sha/sha512.c - crypto/fipsmodule/tls/kdf.c - crypto/hkdf/hkdf.c - crypto/hpke/hpke.c - crypto/hrss/hrss.c - crypto/lhash/lhash.c - crypto/mem.c - crypto/obj/obj.c - crypto/obj/obj_xref.c - crypto/pem/pem_all.c - crypto/pem/pem_info.c - crypto/pem/pem_lib.c - crypto/pem/pem_oth.c - crypto/pem/pem_pk8.c - crypto/pem/pem_pkey.c - crypto/pem/pem_x509.c - crypto/pem/pem_xaux.c - crypto/pkcs7/pkcs7.c - crypto/pkcs7/pkcs7_x509.c - crypto/pkcs8/p5_pbev2.c - crypto/pkcs8/pkcs8.c - crypto/pkcs8/pkcs8_x509.c - crypto/poly1305/poly1305.c - crypto/poly1305/poly1305_arm.c - crypto/poly1305/poly1305_vec.c - crypto/pool/pool.c - crypto/rand_extra/deterministic.c - crypto/rand_extra/forkunsafe.c - crypto/rand_extra/fuchsia.c - crypto/rand_extra/rand_extra.c - crypto/rand_extra/windows.c - crypto/rc4/rc4.c - crypto/refcount_c11.c - crypto/refcount_lock.c - crypto/rsa_extra/rsa_asn1.c - crypto/rsa_extra/rsa_print.c - crypto/siphash/siphash.c - crypto/stack/stack.c - crypto/thread.c - crypto/thread_none.c - crypto/thread_pthread.c - crypto/thread_win.c - crypto/trust_token/pmbtoken.c - crypto/trust_token/trust_token.c - crypto/trust_token/voprf.c - crypto/x509/a_digest.c - crypto/x509/a_sign.c - crypto/x509/a_strex.c - crypto/x509/a_verify.c - crypto/x509/algorithm.c - crypto/x509/asn1_gen.c - crypto/x509/by_dir.c - crypto/x509/by_file.c - crypto/x509/i2d_pr.c - crypto/x509/rsa_pss.c - crypto/x509/t_crl.c - crypto/x509/t_req.c - crypto/x509/t_x509.c - crypto/x509/t_x509a.c - crypto/x509/x509.c - crypto/x509/x509_att.c - crypto/x509/x509_cmp.c - crypto/x509/x509_d2.c - crypto/x509/x509_def.c - crypto/x509/x509_ext.c - crypto/x509/x509_lu.c - crypto/x509/x509_obj.c - crypto/x509/x509_r2x.c - crypto/x509/x509_req.c - crypto/x509/x509_set.c - crypto/x509/x509_trs.c - crypto/x509/x509_txt.c - crypto/x509/x509_v3.c - crypto/x509/x509_vfy.c - crypto/x509/x509_vpm.c - crypto/x509/x509cset.c - crypto/x509/x509name.c - crypto/x509/x509rset.c - crypto/x509/x509spki.c - crypto/x509/x_algor.c - crypto/x509/x_all.c - crypto/x509/x_attrib.c - crypto/x509/x_crl.c - crypto/x509/x_exten.c - crypto/x509/x_info.c - crypto/x509/x_name.c - crypto/x509/x_pkey.c - crypto/x509/x_pubkey.c - crypto/x509/x_req.c - crypto/x509/x_sig.c - crypto/x509/x_spki.c - crypto/x509/x_val.c - crypto/x509/x_x509.c - crypto/x509/x_x509a.c - crypto/x509v3/pcy_cache.c - crypto/x509v3/pcy_data.c - crypto/x509v3/pcy_lib.c - crypto/x509v3/pcy_map.c - crypto/x509v3/pcy_node.c - crypto/x509v3/pcy_tree.c - crypto/x509v3/v3_akey.c - crypto/x509v3/v3_akeya.c - crypto/x509v3/v3_alt.c - crypto/x509v3/v3_bcons.c - crypto/x509v3/v3_bitst.c - crypto/x509v3/v3_conf.c - crypto/x509v3/v3_cpols.c - crypto/x509v3/v3_crld.c - crypto/x509v3/v3_enum.c - crypto/x509v3/v3_extku.c - crypto/x509v3/v3_genn.c - crypto/x509v3/v3_ia5.c - crypto/x509v3/v3_info.c - crypto/x509v3/v3_int.c - crypto/x509v3/v3_lib.c - crypto/x509v3/v3_ncons.c - crypto/x509v3/v3_ocsp.c - crypto/x509v3/v3_pci.c - crypto/x509v3/v3_pcia.c - crypto/x509v3/v3_pcons.c - crypto/x509v3/v3_pmaps.c - crypto/x509v3/v3_prn.c - crypto/x509v3/v3_purp.c - crypto/x509v3/v3_skey.c - crypto/x509v3/v3_utl.c) + "crypto/asn1/a_bitstr.c" + "crypto/asn1/a_bool.c" + "crypto/asn1/a_d2i_fp.c" + "crypto/asn1/a_dup.c" + "crypto/asn1/a_enum.c" + "crypto/asn1/a_gentm.c" + "crypto/asn1/a_i2d_fp.c" + "crypto/asn1/a_int.c" + "crypto/asn1/a_mbstr.c" + "crypto/asn1/a_object.c" + "crypto/asn1/a_octet.c" + "crypto/asn1/a_print.c" + "crypto/asn1/a_strnid.c" + "crypto/asn1/a_time.c" + "crypto/asn1/a_type.c" + "crypto/asn1/a_utctm.c" + "crypto/asn1/a_utf8.c" + "crypto/asn1/asn1_lib.c" + "crypto/asn1/asn1_par.c" + "crypto/asn1/asn_pack.c" + "crypto/asn1/f_enum.c" + "crypto/asn1/f_int.c" + "crypto/asn1/f_string.c" + "crypto/asn1/tasn_dec.c" + "crypto/asn1/tasn_enc.c" + "crypto/asn1/tasn_fre.c" + "crypto/asn1/tasn_new.c" + "crypto/asn1/tasn_typ.c" + "crypto/asn1/tasn_utl.c" + "crypto/asn1/time_support.c" + "crypto/base64/base64.c" + "crypto/bio/bio.c" + "crypto/bio/bio_mem.c" + "crypto/bio/connect.c" + "crypto/bio/fd.c" + "crypto/bio/file.c" + "crypto/bio/hexdump.c" + "crypto/bio/pair.c" + "crypto/bio/printf.c" + "crypto/bio/socket.c" + "crypto/bio/socket_helper.c" + "crypto/bn_extra/bn_asn1.c" + "crypto/bn_extra/convert.c" + "crypto/buf/buf.c" + "crypto/bytestring/asn1_compat.c" + "crypto/bytestring/ber.c" + "crypto/bytestring/cbb.c" + "crypto/bytestring/cbs.c" + "crypto/bytestring/unicode.c" + "crypto/chacha/chacha.c" + "crypto/cipher_extra/cipher_extra.c" + "crypto/cipher_extra/derive_key.c" + "crypto/cipher_extra/e_aesccm.c" + "crypto/cipher_extra/e_aesctrhmac.c" + "crypto/cipher_extra/e_aesgcmsiv.c" + "crypto/cipher_extra/e_chacha20poly1305.c" + "crypto/cipher_extra/e_null.c" + "crypto/cipher_extra/e_rc2.c" + "crypto/cipher_extra/e_rc4.c" + "crypto/cipher_extra/e_tls.c" + "crypto/cipher_extra/tls_cbc.c" + "crypto/cmac/cmac.c" + "crypto/conf/conf.c" + "crypto/cpu-aarch64-fuchsia.c" + "crypto/cpu-aarch64-linux.c" + "crypto/cpu-arm-linux.c" + "crypto/cpu-arm.c" + "crypto/cpu-intel.c" + "crypto/cpu-ppc64le.c" + "crypto/crypto.c" + "crypto/curve25519/curve25519.c" + "crypto/curve25519/spake25519.c" + "crypto/dh/check.c" + "crypto/dh/dh.c" + "crypto/dh/dh_asn1.c" + "crypto/dh/params.c" + "crypto/digest_extra/digest_extra.c" + "crypto/dsa/dsa.c" + "crypto/dsa/dsa_asn1.c" + "crypto/ec_extra/ec_asn1.c" + "crypto/ec_extra/ec_derive.c" + "crypto/ec_extra/hash_to_curve.c" + "crypto/ecdh_extra/ecdh_extra.c" + "crypto/ecdsa_extra/ecdsa_asn1.c" + "crypto/engine/engine.c" + "crypto/err/err.c" + "crypto/err/err_data.c" + "crypto/evp/digestsign.c" + "crypto/evp/evp.c" + "crypto/evp/evp_asn1.c" + "crypto/evp/evp_ctx.c" + "crypto/evp/p_dsa_asn1.c" + "crypto/evp/p_ec.c" + "crypto/evp/p_ec_asn1.c" + "crypto/evp/p_ed25519.c" + "crypto/evp/p_ed25519_asn1.c" + "crypto/evp/p_rsa.c" + "crypto/evp/p_rsa_asn1.c" + "crypto/evp/p_x25519.c" + "crypto/evp/p_x25519_asn1.c" + "crypto/evp/pbkdf.c" + "crypto/evp/print.c" + "crypto/evp/scrypt.c" + "crypto/evp/sign.c" + "crypto/ex_data.c" + "crypto/fipsmodule/aes/aes.c" + "crypto/fipsmodule/aes/aes_nohw.c" + "crypto/fipsmodule/aes/key_wrap.c" + "crypto/fipsmodule/aes/mode_wrappers.c" + "crypto/fipsmodule/bn/add.c" + "crypto/fipsmodule/bn/asm/x86_64-gcc.c" + "crypto/fipsmodule/bn/bn.c" + "crypto/fipsmodule/bn/bytes.c" + "crypto/fipsmodule/bn/cmp.c" + "crypto/fipsmodule/bn/ctx.c" + "crypto/fipsmodule/bn/div.c" + "crypto/fipsmodule/bn/div_extra.c" + "crypto/fipsmodule/bn/exponentiation.c" + "crypto/fipsmodule/bn/gcd.c" + "crypto/fipsmodule/bn/gcd_extra.c" + "crypto/fipsmodule/bn/generic.c" + "crypto/fipsmodule/bn/jacobi.c" + "crypto/fipsmodule/bn/montgomery.c" + "crypto/fipsmodule/bn/montgomery_inv.c" + "crypto/fipsmodule/bn/mul.c" + "crypto/fipsmodule/bn/prime.c" + "crypto/fipsmodule/bn/random.c" + "crypto/fipsmodule/bn/rsaz_exp.c" + "crypto/fipsmodule/bn/shift.c" + "crypto/fipsmodule/bn/sqrt.c" + "crypto/fipsmodule/cipher/aead.c" + "crypto/fipsmodule/cipher/cipher.c" + "crypto/fipsmodule/cipher/e_aes.c" + "crypto/fipsmodule/cipher/e_des.c" + "crypto/fipsmodule/des/des.c" + "crypto/fipsmodule/digest/digest.c" + "crypto/fipsmodule/digest/digests.c" + "crypto/fipsmodule/ec/ec.c" + "crypto/fipsmodule/ec/ec_key.c" + "crypto/fipsmodule/ec/ec_montgomery.c" + "crypto/fipsmodule/ec/felem.c" + "crypto/fipsmodule/ec/oct.c" + "crypto/fipsmodule/ec/p224-64.c" + "crypto/fipsmodule/ec/p256-x86_64.c" + "crypto/fipsmodule/ec/p256.c" + "crypto/fipsmodule/ec/scalar.c" + "crypto/fipsmodule/ec/simple.c" + "crypto/fipsmodule/ec/simple_mul.c" + "crypto/fipsmodule/ec/util.c" + "crypto/fipsmodule/ec/wnaf.c" + "crypto/fipsmodule/ecdh/ecdh.c" + "crypto/fipsmodule/ecdsa/ecdsa.c" + "crypto/fipsmodule/fips_shared_support.c" + "crypto/fipsmodule/hmac/hmac.c" + "crypto/fipsmodule/is_fips.c" + "crypto/fipsmodule/md4/md4.c" + "crypto/fipsmodule/md5/md5.c" + "crypto/fipsmodule/modes/cbc.c" + "crypto/fipsmodule/modes/cfb.c" + "crypto/fipsmodule/modes/ctr.c" + "crypto/fipsmodule/modes/gcm.c" + "crypto/fipsmodule/modes/gcm_nohw.c" + "crypto/fipsmodule/modes/ofb.c" + "crypto/fipsmodule/modes/polyval.c" + "crypto/fipsmodule/rand/ctrdrbg.c" + "crypto/fipsmodule/rand/fork_detect.c" + "crypto/fipsmodule/rand/rand.c" + "crypto/fipsmodule/rand/urandom.c" + "crypto/fipsmodule/rsa/blinding.c" + "crypto/fipsmodule/rsa/padding.c" + "crypto/fipsmodule/rsa/rsa.c" + "crypto/fipsmodule/rsa/rsa_impl.c" + "crypto/fipsmodule/self_check/self_check.c" + "crypto/fipsmodule/sha/sha1-altivec.c" + "crypto/fipsmodule/sha/sha1.c" + "crypto/fipsmodule/sha/sha256.c" + "crypto/fipsmodule/sha/sha512.c" + "crypto/fipsmodule/tls/kdf.c" + "crypto/hkdf/hkdf.c" + "crypto/hpke/hpke.c" + "crypto/hrss/hrss.c" + "crypto/lhash/lhash.c" + "crypto/mem.c" + "crypto/obj/obj.c" + "crypto/obj/obj_xref.c" + "crypto/pem/pem_all.c" + "crypto/pem/pem_info.c" + "crypto/pem/pem_lib.c" + "crypto/pem/pem_oth.c" + "crypto/pem/pem_pk8.c" + "crypto/pem/pem_pkey.c" + "crypto/pem/pem_x509.c" + "crypto/pem/pem_xaux.c" + "crypto/pkcs7/pkcs7.c" + "crypto/pkcs7/pkcs7_x509.c" + "crypto/pkcs8/p5_pbev2.c" + "crypto/pkcs8/pkcs8.c" + "crypto/pkcs8/pkcs8_x509.c" + "crypto/poly1305/poly1305.c" + "crypto/poly1305/poly1305_arm.c" + "crypto/poly1305/poly1305_vec.c" + "crypto/pool/pool.c" + "crypto/rand_extra/deterministic.c" + "crypto/rand_extra/forkunsafe.c" + "crypto/rand_extra/fuchsia.c" + "crypto/rand_extra/rand_extra.c" + "crypto/rand_extra/windows.c" + "crypto/rc4/rc4.c" + "crypto/refcount_c11.c" + "crypto/refcount_lock.c" + "crypto/rsa_extra/rsa_asn1.c" + "crypto/rsa_extra/rsa_print.c" + "crypto/siphash/siphash.c" + "crypto/stack/stack.c" + "crypto/thread.c" + "crypto/thread_none.c" + "crypto/thread_pthread.c" + "crypto/thread_win.c" + "crypto/trust_token/pmbtoken.c" + "crypto/trust_token/trust_token.c" + "crypto/trust_token/voprf.c" + "crypto/x509/a_digest.c" + "crypto/x509/a_sign.c" + "crypto/x509/a_strex.c" + "crypto/x509/a_verify.c" + "crypto/x509/algorithm.c" + "crypto/x509/asn1_gen.c" + "crypto/x509/by_dir.c" + "crypto/x509/by_file.c" + "crypto/x509/i2d_pr.c" + "crypto/x509/rsa_pss.c" + "crypto/x509/t_crl.c" + "crypto/x509/t_req.c" + "crypto/x509/t_x509.c" + "crypto/x509/t_x509a.c" + "crypto/x509/x509.c" + "crypto/x509/x509_att.c" + "crypto/x509/x509_cmp.c" + "crypto/x509/x509_d2.c" + "crypto/x509/x509_def.c" + "crypto/x509/x509_ext.c" + "crypto/x509/x509_lu.c" + "crypto/x509/x509_obj.c" + "crypto/x509/x509_r2x.c" + "crypto/x509/x509_req.c" + "crypto/x509/x509_set.c" + "crypto/x509/x509_trs.c" + "crypto/x509/x509_txt.c" + "crypto/x509/x509_v3.c" + "crypto/x509/x509_vfy.c" + "crypto/x509/x509_vpm.c" + "crypto/x509/x509cset.c" + "crypto/x509/x509name.c" + "crypto/x509/x509rset.c" + "crypto/x509/x509spki.c" + "crypto/x509/x_algor.c" + "crypto/x509/x_all.c" + "crypto/x509/x_attrib.c" + "crypto/x509/x_crl.c" + "crypto/x509/x_exten.c" + "crypto/x509/x_info.c" + "crypto/x509/x_name.c" + "crypto/x509/x_pkey.c" + "crypto/x509/x_pubkey.c" + "crypto/x509/x_req.c" + "crypto/x509/x_sig.c" + "crypto/x509/x_spki.c" + "crypto/x509/x_val.c" + "crypto/x509/x_x509.c" + "crypto/x509/x_x509a.c" + "crypto/x509v3/pcy_cache.c" + "crypto/x509v3/pcy_data.c" + "crypto/x509v3/pcy_lib.c" + "crypto/x509v3/pcy_map.c" + "crypto/x509v3/pcy_node.c" + "crypto/x509v3/pcy_tree.c" + "crypto/x509v3/v3_akey.c" + "crypto/x509v3/v3_akeya.c" + "crypto/x509v3/v3_alt.c" + "crypto/x509v3/v3_bcons.c" + "crypto/x509v3/v3_bitst.c" + "crypto/x509v3/v3_conf.c" + "crypto/x509v3/v3_cpols.c" + "crypto/x509v3/v3_crld.c" + "crypto/x509v3/v3_enum.c" + "crypto/x509v3/v3_extku.c" + "crypto/x509v3/v3_genn.c" + "crypto/x509v3/v3_ia5.c" + "crypto/x509v3/v3_info.c" + "crypto/x509v3/v3_int.c" + "crypto/x509v3/v3_lib.c" + "crypto/x509v3/v3_ncons.c" + "crypto/x509v3/v3_ocsp.c" + "crypto/x509v3/v3_pci.c" + "crypto/x509v3/v3_pcia.c" + "crypto/x509v3/v3_pcons.c" + "crypto/x509v3/v3_pmaps.c" + "crypto/x509v3/v3_prn.c" + "crypto/x509v3/v3_purp.c" + "crypto/x509v3/v3_skey.c" + "crypto/x509v3/v3_utl.c") if(APPLE) if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") target_sources(CCryptoBoringSSL PRIVATE diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt index c67b57268..492d279cc 100644 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -9,7 +9,7 @@ # SPDX-License-Identifier: Apache-2.0 add_library(CCryptoBoringSSLShims STATIC - shims.c) + "shims.c") target_include_directories(CCryptoBoringSSLShims PUBLIC include diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index f24f2f082..5c9189d48 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -9,66 +9,66 @@ # SPDX-License-Identifier: Apache-2.0 add_library(Crypto - AEADs/AES/GCM/AES-GCM.swift - AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift - AEADS/ChachaPoly/ChaChaPoly.swift - AEADS/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift - AEADS/Cipher.swift - AEADS/Nonces.swift - ASN1/ASN1.swift - "ASN1/Basic ASN1 Types/ArraySliceBigint.swift" + "AEADs/AES/GCM/AES-GCM.swift" + "AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift" + "AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift" + "AEADs/ChachaPoly/ChaChaPoly.swift" + "AEADs/Cipher.swift" + "AEADs/Nonces.swift" + "ASN1/ASN1.swift" "ASN1/Basic ASN1 Types/ASN1BitString.swift" "ASN1/Basic ASN1 Types/ASN1Identifier.swift" "ASN1/Basic ASN1 Types/ASN1Integer.swift" "ASN1/Basic ASN1 Types/ASN1OctetString.swift" + "ASN1/Basic ASN1 Types/ArraySliceBigint.swift" "ASN1/Basic ASN1 Types/ObjectIdentifier.swift" - ASN1/ECDSASignature.swift - ASN1/PEMDocument.swift - ASN1/PKCS8PrivateKey.swift - ASN1/SEC1PrivateKey.swift - ASN1/SubjectPublicKeyInfo.swift - CryptoKitErrors.swift - Digests/BoringSSL/Digest_boring.swift - Digests/Digest.swift - Digests/Digests.swift - Digests/HashFunctions_SHA2.swift - Digests/HashFunctions.swift - Insecure/Insecure_HashFunctions.swift - Insecure/Insecure.swift + "ASN1/ECDSASignature.swift" + "ASN1/PEMDocument.swift" + "ASN1/PKCS8PrivateKey.swift" + "ASN1/SEC1PrivateKey.swift" + "ASN1/SubjectPublicKeyInfo.swift" + "CryptoKitErrors.swift" + "Digests/BoringSSL/Digest_boring.swift" + "Digests/Digest.swift" + "Digests/Digests.swift" + "Digests/HashFunctions.swift" + "Digests/HashFunctions_SHA2.swift" + "Insecure/Insecure.swift" + "Insecure/Insecure_HashFunctions.swift" "Key Agreement/BoringSSL/ECDH_boring.swift" "Key Agreement/DH.swift" "Key Agreement/ECDH.swift" "Key Derivation/HKDF.swift" - Keys/EC/BoringSSL/Ed25519_boring.swift - Keys/EC/BoringSSL/EllipticCurve_boring.swift - Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift - Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift - Keys/EC/BoringSSL/X25519Keys_boring.swift - Keys/EC/Curve25519.swift - Keys/EC/Ed25519.swift - Keys/EC/NISTCurvesKeys.swift - Keys/EC/X25519Keys.swift - Keys/Symmetric/SymmetricKeys.swift + "Keys/EC/BoringSSL/Ed25519_boring.swift" + "Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift" + "Keys/EC/BoringSSL/EllipticCurve_boring.swift" + "Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift" + "Keys/EC/BoringSSL/X25519Keys_boring.swift" + "Keys/EC/Curve25519.swift" + "Keys/EC/Ed25519.swift" + "Keys/EC/NISTCurvesKeys.swift" + "Keys/EC/X25519Keys.swift" + "Keys/Symmetric/SymmetricKeys.swift" "Message Authentication Codes/HMAC/HMAC.swift" "Message Authentication Codes/MACFunctions.swift" "Message Authentication Codes/MessageAuthenticationCode.swift" - PRF/AES.swift - Signatures/BoringSSL/ECDSA_boring.swift - Signatures/BoringSSL/ECDSASignature_boring.swift - Signatures/BoringSSL/EdDSA_boring.swift - Signatures/ECDSA.swift - Signatures/EdDSA.swift - Signatures/Signature.swift - Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift - Util/BoringSSL/CryptoKitErrors_boring.swift - Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift - Util/BoringSSL/RNG_boring.swift - Util/BoringSSL/SafeCompare_boring.swift - Util/BoringSSL/Zeroization_boring.swift - Util/PrettyBytes.swift - Util/SafeCompare.swift - Util/SecureBytes.swift - Util/Zeroization.swift) + "PRF/AES.swift" + "Signatures/BoringSSL/ECDSASignature_boring.swift" + "Signatures/BoringSSL/ECDSA_boring.swift" + "Signatures/BoringSSL/EdDSA_boring.swift" + "Signatures/ECDSA.swift" + "Signatures/EdDSA.swift" + "Signatures/Signature.swift" + "Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift" + "Util/BoringSSL/CryptoKitErrors_boring.swift" + "Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift" + "Util/BoringSSL/RNG_boring.swift" + "Util/BoringSSL/SafeCompare_boring.swift" + "Util/BoringSSL/Zeroization_boring.swift" + "Util/PrettyBytes.swift" + "Util/SafeCompare.swift" + "Util/SecureBytes.swift" + "Util/Zeroization.swift") target_compile_definitions(Crypto PRIVATE CRYPTO_IN_SWIFTPM_FORCE_BUILD_API) diff --git a/scripts/update_cmakelists.sh b/scripts/update_cmakelists.sh new file mode 100755 index 000000000..33f0e425a --- /dev/null +++ b/scripts/update_cmakelists.sh @@ -0,0 +1,62 @@ +#!/bin/bash +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## + +set -eu + +here=$(pwd) + +case "$(uname -s)" in + Darwin) + sed=gsed + ;; + *) + sed=sed + ;; +esac + +function update_cmakelists() { + src_root="$here/Sources/$1" + + # Build an array with the rest of the arguments + shift + src_exts=("$@") + echo "Finding source files (${src_exts[@]}) under $src_root" + + num_exts=${#src_exts[@]} + + # Build file extensions argument for `find` + declare -a exts_arg + exts_arg+=(-name ${src_exts[0]}) + for (( i=1; i<$num_exts; i++ )); + do + exts_arg+=(-o -name ${src_exts[$i]}) + done + + cd $src_root + + # Wrap quotes around each filename since it might contain spaces + srcs=$(find . -type f \( "${exts_arg[@]}" \) | sort | $sed 's/\.\///g;s/\(.*\)/ "\1"/g') + echo "$srcs" + + # Update list of source files in CMakeLists.txt + # The first part in `BEGIN` (i.e., `undef $/;`) is for working with multi-line; + # the second is so that we can pass in a variable to replace with. + perl -pi -e 'BEGIN { undef $/; $replace = shift } s/add_library\(([^\n]+)\n([^\)]+)/add_library\($1\n$replace/' "$srcs" "$src_root/CMakeLists.txt" + echo "Updated $src_root/CMakeLists.txt" +} + +update_cmakelists "CCryptoBoringSSL" "*.c" +update_cmakelists "CCryptoBoringSSLShims" "*.c" +update_cmakelists "Crypto" "*.swift" From d8a12950ccd4daec8dec11a3946c4574504bf5d3 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Sun, 24 Jan 2021 21:21:18 -0800 Subject: [PATCH 20/29] Update gitignore per Saleem's feedback --- .gitignore | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 0acc47bb7..e7b477883 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ .DS_Store /.build +/out /Packages /*.xcodeproj Package.pins @@ -14,7 +15,3 @@ DerivedData .*.sw[nop] -CMakeFiles -CMakeCache.txt -cmake_*.cmake -*.ninja* From 146f23b563d4eb4d7518c9ec3e263a59d6047b7f Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Sun, 24 Jan 2021 21:27:14 -0800 Subject: [PATCH 21/29] Add code comment --- scripts/check_no_api_breakages.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/check_no_api_breakages.sh b/scripts/check_no_api_breakages.sh index 64303a577..293bd26f6 100755 --- a/scripts/check_no_api_breakages.sh +++ b/scripts/check_no_api_breakages.sh @@ -36,6 +36,7 @@ function build_and_do() { ( cd "$repodir" git checkout -q "$tag" + # Clean up output from previous build to prevent potential interference rm -rf .build swift build while read -r module; do From f73947a74803e8f4a683e3bd22d7ec88a2e683cc Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Mon, 25 Jan 2021 22:20:03 -0800 Subject: [PATCH 22/29] Improved 'find' --- scripts/update_cmakelists.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/scripts/update_cmakelists.sh b/scripts/update_cmakelists.sh index 33f0e425a..484eeecd3 100755 --- a/scripts/update_cmakelists.sh +++ b/scripts/update_cmakelists.sh @@ -19,10 +19,10 @@ here=$(pwd) case "$(uname -s)" in Darwin) - sed=gsed + find=gfind # brew install findutils ;; *) - sed=sed + find=find ;; esac @@ -38,16 +38,14 @@ function update_cmakelists() { # Build file extensions argument for `find` declare -a exts_arg - exts_arg+=(-name ${src_exts[0]}) + exts_arg+=(-name "${src_exts[0]}") for (( i=1; i<$num_exts; i++ )); do - exts_arg+=(-o -name ${src_exts[$i]}) + exts_arg+=(-o -name "${src_exts[$i]}") done - cd $src_root - # Wrap quotes around each filename since it might contain spaces - srcs=$(find . -type f \( "${exts_arg[@]}" \) | sort | $sed 's/\.\///g;s/\(.*\)/ "\1"/g') + srcs=$($find "${src_root}" -type f \( "${exts_arg[@]}" \) -printf ' "%P"\n' | sort) echo "$srcs" # Update list of source files in CMakeLists.txt From 2f3091f5845ec73138544c021aededf04241c930 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Mon, 25 Jan 2021 23:23:26 -0800 Subject: [PATCH 23/29] Add assembly files for Apple and Linux --- Sources/CCryptoBoringSSL/CMakeLists.txt | 53 +++++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index afac3b2d3..7c6681dd1 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -310,29 +310,38 @@ add_library(CCryptoBoringSSL STATIC "crypto/x509v3/v3_purp.c" "crypto/x509v3/v3_skey.c" "crypto/x509v3/v3_utl.c") -if(APPLE) - if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") - target_sources(CCryptoBoringSSL PRIVATE - crypto/chacha/chacha-x86_64.mac.x86_64.S - crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S - crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S - crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S - crypto/fipsmodule/aesni-x86_64.mac.x86_64.S - crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S - crypto/fipsmodule/ghash-x86_64.mac.x86_64.S - crypto/fipsmodule/md5-x86_64.mac.x86_64.S - crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S - crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S - crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S - crypto/fipsmodule/rsaz-avx2.mac.x86_64.S - crypto/fipsmodule/sha1-x86_64.mac.x86_64.S - crypto/fipsmodule/sha256-x86_64.mac.x86_64.S - crypto/fipsmodule/sha512-x86_64.mac.x86_64.S - crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S - crypto/fipsmodule/x86_64-mont.mac.x86_64.S - crypto/fipsmodule/x86_64-mont5.mac.x86_64.S) + +function(add_assembly_files) + if(CMAKE_SYSTEM_NAME STREQUAL Darwin) + set(platform_name mac) + elseif(CMAKE_SYSTEM_NAME STREQUAL Linux) + set(platform_name linux) + else() + return() endif() -endif() + + target_sources(CCryptoBoringSSL PRIVATE + crypto/chacha/chacha-x86_64.${platform_name}.x86_64.S + crypto/cipher_extra/aes128gcmsiv-x86_64.${platform_name}.x86_64.S + crypto/cipher_extra/chacha20_poly1305_x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/aesni-gcm-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/aesni-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/ghash-ssse3-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/ghash-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/md5-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/p256-x86_64-asm.${platform_name}.x86_64.S + crypto/fipsmodule/p256_beeu-x86_64-asm.${platform_name}.x86_64.S + crypto/fipsmodule/rdrand-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/rsaz-avx2.${platform_name}.x86_64.S + crypto/fipsmodule/sha1-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/sha256-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/sha512-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/vpaes-x86_64.${platform_name}.x86_64.S + crypto/fipsmodule/x86_64-mont.${platform_name}.x86_64.S + crypto/fipsmodule/x86_64-mont5.${platform_name}.x86_64.S) +endfunction() + +add_assembly_files() target_include_directories(CCryptoBoringSSL PUBLIC include) From c2b84ba722bdf4ae6b2fb9348f0e50a2a7a15646 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Tue, 26 Jan 2021 09:49:19 -0800 Subject: [PATCH 24/29] Allow year 2021 in copyright header --- scripts/soundness.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 52601ca41..80c13d887 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -17,7 +17,7 @@ set -eu here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" function replace_acceptable_years() { # this needs to replace all acceptable forms with 'YEARS' - sed -e 's/20[12][890]-20[12][90]/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' + sed -e 's/20[12][890]-20[12][190]/YEARS/' -e 's/2019/YEARS/' -e 's/2020/YEARS/' -e 's/2021/YEARS/' } printf "=> Checking for unacceptable language... " From 5b2e9c6bc1ffca2af0ee9b700400679b592cf66c Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Tue, 26 Jan 2021 10:03:37 -0800 Subject: [PATCH 25/29] Add cmake files to license header check --- CMakeLists.txt | 22 ++++++++++++-------- Sources/CCryptoBoringSSL/CMakeLists.txt | 22 ++++++++++++-------- Sources/CCryptoBoringSSLShims/CMakeLists.txt | 22 ++++++++++++-------- Sources/CMakeLists.txt | 22 ++++++++++++-------- Sources/Crypto/CMakeLists.txt | 22 ++++++++++++-------- cmake/modules/CMakeLists.txt | 22 ++++++++++++-------- cmake/modules/SwiftSupport.cmake | 22 ++++++++++++-------- scripts/soundness.sh | 22 ++++++++++++++++++-- 8 files changed, 111 insertions(+), 65 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f357387..6c5314192 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## cmake_minimum_required(VERSION 3.15.1) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index 7c6681dd1..f821553d2 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## add_library(CCryptoBoringSSL STATIC "crypto/asn1/a_bitstr.c" diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt index 492d279cc..5550b15e9 100644 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ b/Sources/CCryptoBoringSSLShims/CMakeLists.txt @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## add_library(CCryptoBoringSSLShims STATIC "shims.c") diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 6279558f5..7f1909f72 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## add_subdirectory(CCryptoBoringSSL) add_subdirectory(CCryptoBoringSSLShims) diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index 5c9189d48..683528f1f 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## add_library(Crypto "AEADs/AES/GCM/AES-GCM.swift" diff --git a/cmake/modules/CMakeLists.txt b/cmake/modules/CMakeLists.txt index 3b58c39eb..3a91f84f7 100644 --- a/cmake/modules/CMakeLists.txt +++ b/cmake/modules/CMakeLists.txt @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## set(CRYPTO_EXPORTS_FILE ${CMAKE_CURRENT_BINARY_DIR}/CryptoExports.cmake) configure_file(CryptoConfig.cmake.in diff --git a/cmake/modules/SwiftSupport.cmake b/cmake/modules/SwiftSupport.cmake index 8aa3f76e1..889edcd8b 100644 --- a/cmake/modules/SwiftSupport.cmake +++ b/cmake/modules/SwiftSupport.cmake @@ -1,12 +1,16 @@ -# This source file is part of the SwiftCrypto open source project -# -# Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors -# Licensed under Apache License v2.0 -# -# See LICENSE.txt for license information -# See CONTRIBUTORS.md for the list of SwiftCrypto project authors -# -# SPDX-License-Identifier: Apache-2.0 +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) 2021 Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## # Returns the architecture name in a variable # diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 80c13d887..c5a387ae8 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -3,7 +3,7 @@ ## ## This source file is part of the SwiftCrypto open source project ## -## Copyright (c) 2019 Apple Inc. and the SwiftCrypto project authors +## Copyright (c) 2019-2021 Apple Inc. and the SwiftCrypto project authors ## Licensed under Apache License v2.0 ## ## See LICENSE.txt for license information @@ -85,7 +85,7 @@ fi printf "=> Checking license headers\n" tmp=$(mktemp /tmp/.swift-crypto-soundness_XXXXXX) -for language in swift-or-c bash dtrace; do +for language in swift-or-c bash dtrace cmake; do printf " * $language... " declare -a matching_files declare -a exceptions @@ -147,6 +147,24 @@ EOF * SPDX-License-Identifier: Apache-2.0 * *===----------------------------------------------------------------------===*/ +EOF + ;; + cmake) + matching_files=( -name 'SwiftSupport.cmake' -o -name 'CMakeLists.txt' ) + cat > "$tmp" <<"EOF" +##===----------------------------------------------------------------------===## +## +## This source file is part of the SwiftCrypto open source project +## +## Copyright (c) YEARS Apple Inc. and the SwiftCrypto project authors +## Licensed under Apache License v2.0 +## +## See LICENSE.txt for license information +## See CONTRIBUTORS.md for the list of SwiftCrypto project authors +## +## SPDX-License-Identifier: Apache-2.0 +## +##===----------------------------------------------------------------------===## EOF ;; *) From 064a2cbff11f9f735487536cfbaf199e5ce53adb Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Tue, 26 Jan 2021 11:32:35 -0800 Subject: [PATCH 26/29] Add check for source file changes that would impact CMakeLists.txt --- scripts/soundness.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/scripts/soundness.sh b/scripts/soundness.sh index c5a387ae8..04f368cf8 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -48,7 +48,17 @@ if [ "$out" == *"error"* ]; then exit 1 fi if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then - printf "\033[0;31mRunning gyb results in changes! Have you manually editted the generated swift files? Or did you forget to run gyb and commit changes?\033[0m\n" + printf "\033[0;31mRunning gyb results in changes! Have you manually edited the generated Swift files? Or did you forget to run gyb and commit changes?\033[0m\n" + exit 1 +fi +printf "\033[0;32mokay.\033[0m\n" + +printf "=> Detecting changes in source files for CMake build\n" +FIRST_OUT="$(git status --porcelain)" +out=$($here/update_cmakelists.sh 2>&1) +SECOND_OUT="$(git status --porcelain)" +if [[ "$FIRST_OUT" != "$SECOND_OUT" ]]; then + printf "\033[0;31mThere are source file changes! Have you added or renamed source files? Or did you forget to run 'update_cmakelists.sh' and commit changes?\033[0m\n" exit 1 fi printf "\033[0;32mokay.\033[0m\n" From 909315014d47a6ca39e5b3f28b27426a171e4687 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Tue, 26 Jan 2021 12:21:38 -0800 Subject: [PATCH 27/29] Make sort consistent across platforms --- scripts/soundness.sh | 2 +- scripts/update_cmakelists.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/soundness.sh b/scripts/soundness.sh index 04f368cf8..cf3237be5 100755 --- a/scripts/soundness.sh +++ b/scripts/soundness.sh @@ -65,7 +65,7 @@ printf "\033[0;32mokay.\033[0m\n" printf "=> Checking format\n" FIRST_OUT="$(git status --porcelain)" -# only checking direcotry named BoringSSL, rest is shared code and we need to preserve original format +# only checking directory named BoringSSL, rest is shared code and we need to preserve original format shopt -u dotglob find Sources/* Tests/* -name BoringSSL -type d | while IFS= read -r d; do printf " * checking $d... " diff --git a/scripts/update_cmakelists.sh b/scripts/update_cmakelists.sh index 484eeecd3..bc157b2a3 100755 --- a/scripts/update_cmakelists.sh +++ b/scripts/update_cmakelists.sh @@ -45,7 +45,7 @@ function update_cmakelists() { done # Wrap quotes around each filename since it might contain spaces - srcs=$($find "${src_root}" -type f \( "${exts_arg[@]}" \) -printf ' "%P"\n' | sort) + srcs=$($find "${src_root}" -type f \( "${exts_arg[@]}" \) -printf ' "%P"\n' | LC_ALL=POSIX sort) echo "$srcs" # Update list of source files in CMakeLists.txt From ace376561402e87a4d754d4040c2df22b44dbaa9 Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Wed, 27 Jan 2021 09:45:18 -0800 Subject: [PATCH 28/29] Missing 'CMAKE_SYSTEM_PROCESSOR MATCHES' check --- Sources/CCryptoBoringSSL/CMakeLists.txt | 70 +++++++++++++++---------- 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/Sources/CCryptoBoringSSL/CMakeLists.txt b/Sources/CCryptoBoringSSL/CMakeLists.txt index f821553d2..0a47c0886 100644 --- a/Sources/CCryptoBoringSSL/CMakeLists.txt +++ b/Sources/CCryptoBoringSSL/CMakeLists.txt @@ -314,38 +314,50 @@ add_library(CCryptoBoringSSL STATIC "crypto/x509v3/v3_purp.c" "crypto/x509v3/v3_skey.c" "crypto/x509v3/v3_utl.c") - -function(add_assembly_files) + +if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|amd64") if(CMAKE_SYSTEM_NAME STREQUAL Darwin) - set(platform_name mac) + target_sources(CCryptoBoringSSL PRIVATE + crypto/chacha/chacha-x86_64.mac.x86_64.S + crypto/cipher_extra/aes128gcmsiv-x86_64.mac.x86_64.S + crypto/cipher_extra/chacha20_poly1305_x86_64.mac.x86_64.S + crypto/fipsmodule/aesni-gcm-x86_64.mac.x86_64.S + crypto/fipsmodule/aesni-x86_64.mac.x86_64.S + crypto/fipsmodule/ghash-ssse3-x86_64.mac.x86_64.S + crypto/fipsmodule/ghash-x86_64.mac.x86_64.S + crypto/fipsmodule/md5-x86_64.mac.x86_64.S + crypto/fipsmodule/p256-x86_64-asm.mac.x86_64.S + crypto/fipsmodule/p256_beeu-x86_64-asm.mac.x86_64.S + crypto/fipsmodule/rdrand-x86_64.mac.x86_64.S + crypto/fipsmodule/rsaz-avx2.mac.x86_64.S + crypto/fipsmodule/sha1-x86_64.mac.x86_64.S + crypto/fipsmodule/sha256-x86_64.mac.x86_64.S + crypto/fipsmodule/sha512-x86_64.mac.x86_64.S + crypto/fipsmodule/vpaes-x86_64.mac.x86_64.S + crypto/fipsmodule/x86_64-mont.mac.x86_64.S + crypto/fipsmodule/x86_64-mont5.mac.x86_64.S) elseif(CMAKE_SYSTEM_NAME STREQUAL Linux) - set(platform_name linux) - else() - return() + target_sources(CCryptoBoringSSL PRIVATE + crypto/chacha/chacha-x86_64.linux.x86_64.S + crypto/cipher_extra/aes128gcmsiv-x86_64.linux.x86_64.S + crypto/cipher_extra/chacha20_poly1305_x86_64.linux.x86_64.S + crypto/fipsmodule/aesni-gcm-x86_64.linux.x86_64.S + crypto/fipsmodule/aesni-x86_64.linux.x86_64.S + crypto/fipsmodule/ghash-ssse3-x86_64.linux.x86_64.S + crypto/fipsmodule/ghash-x86_64.linux.x86_64.S + crypto/fipsmodule/md5-x86_64.linux.x86_64.S + crypto/fipsmodule/p256-x86_64-asm.linux.x86_64.S + crypto/fipsmodule/p256_beeu-x86_64-asm.linux.x86_64.S + crypto/fipsmodule/rdrand-x86_64.linux.x86_64.S + crypto/fipsmodule/rsaz-avx2.linux.x86_64.S + crypto/fipsmodule/sha1-x86_64.linux.x86_64.S + crypto/fipsmodule/sha256-x86_64.linux.x86_64.S + crypto/fipsmodule/sha512-x86_64.linux.x86_64.S + crypto/fipsmodule/vpaes-x86_64.linux.x86_64.S + crypto/fipsmodule/x86_64-mont.linux.x86_64.S + crypto/fipsmodule/x86_64-mont5.linux.x86_64.S) endif() - - target_sources(CCryptoBoringSSL PRIVATE - crypto/chacha/chacha-x86_64.${platform_name}.x86_64.S - crypto/cipher_extra/aes128gcmsiv-x86_64.${platform_name}.x86_64.S - crypto/cipher_extra/chacha20_poly1305_x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/aesni-gcm-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/aesni-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/ghash-ssse3-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/ghash-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/md5-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/p256-x86_64-asm.${platform_name}.x86_64.S - crypto/fipsmodule/p256_beeu-x86_64-asm.${platform_name}.x86_64.S - crypto/fipsmodule/rdrand-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/rsaz-avx2.${platform_name}.x86_64.S - crypto/fipsmodule/sha1-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/sha256-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/sha512-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/vpaes-x86_64.${platform_name}.x86_64.S - crypto/fipsmodule/x86_64-mont.${platform_name}.x86_64.S - crypto/fipsmodule/x86_64-mont5.${platform_name}.x86_64.S) -endfunction() - -add_assembly_files() +endif() target_include_directories(CCryptoBoringSSL PUBLIC include) From 4a1b8643268c9a7be5bbef2861bfad0d0fc5e1bd Mon Sep 17 00:00:00 2001 From: Yim Lee Date: Wed, 27 Jan 2021 10:25:48 -0800 Subject: [PATCH 29/29] Generate .S list --- scripts/update_cmakelists.sh | 37 +++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/scripts/update_cmakelists.sh b/scripts/update_cmakelists.sh index bc157b2a3..7e45f2392 100755 --- a/scripts/update_cmakelists.sh +++ b/scripts/update_cmakelists.sh @@ -26,16 +26,16 @@ case "$(uname -s)" in ;; esac -function update_cmakelists() { +function update_cmakelists_source() { src_root="$here/Sources/$1" - + # Build an array with the rest of the arguments shift src_exts=("$@") echo "Finding source files (${src_exts[@]}) under $src_root" - + num_exts=${#src_exts[@]} - + # Build file extensions argument for `find` declare -a exts_arg exts_arg+=(-name "${src_exts[0]}") @@ -43,11 +43,11 @@ function update_cmakelists() { do exts_arg+=(-o -name "${src_exts[$i]}") done - + # Wrap quotes around each filename since it might contain spaces srcs=$($find "${src_root}" -type f \( "${exts_arg[@]}" \) -printf ' "%P"\n' | LC_ALL=POSIX sort) echo "$srcs" - + # Update list of source files in CMakeLists.txt # The first part in `BEGIN` (i.e., `undef $/;`) is for working with multi-line; # the second is so that we can pass in a variable to replace with. @@ -55,6 +55,25 @@ function update_cmakelists() { echo "Updated $src_root/CMakeLists.txt" } -update_cmakelists "CCryptoBoringSSL" "*.c" -update_cmakelists "CCryptoBoringSSLShims" "*.c" -update_cmakelists "Crypto" "*.swift" +function update_cmakelists_assembly() { + src_root="$here/Sources/$1" + echo "Finding assembly files (.S) under $src_root" + + mac_asms=$($find "${src_root}" -type f -name "*.mac.x86_64.S" -printf ' %P\n' | LC_ALL=POSIX sort) + linux_asms=$($find "${src_root}" -type f -name "*.linux.x86_64.S" -printf ' %P\n' | LC_ALL=POSIX sort) + echo "$mac_asms" + echo "$linux_asms" + + # Update list of assembly files in CMakeLists.txt + # The first part in `BEGIN` (i.e., `undef $/;`) is for working with multi-line; + # the second is so that we can pass in a variable to replace with. + perl -pi -e 'BEGIN { undef $/; $replace = shift } s/Darwin\)\n(.+)target_sources\(([^\n]+)\n([^\)]+)/Darwin\)\n$1target_sources\($2\n$replace/' "$mac_asms" "$src_root/CMakeLists.txt" + perl -pi -e 'BEGIN { undef $/; $replace = shift } s/Linux\)\n(.+)target_sources\(([^\n]+)\n([^\)]+)/Linux\)\n$1target_sources\($2\n$replace/' "$linux_asms" "$src_root/CMakeLists.txt" + echo "Updated $src_root/CMakeLists.txt" +} + +update_cmakelists_source "CCryptoBoringSSL" "*.c" +update_cmakelists_source "CCryptoBoringSSLShims" "*.c" +update_cmakelists_source "Crypto" "*.swift" + +update_cmakelists_assembly "CCryptoBoringSSL"