From 78c4130fd1fe5b872c47e0f6349c8d9819e2055f Mon Sep 17 00:00:00 2001 From: Cole Moore Date: Sun, 2 Nov 2025 07:45:39 +0800 Subject: [PATCH 1/3] Set Package.swift swift tools version to 6.1 in order to enable package traits, Added package trait to enable using the swift crypto api on apple platforms in favor of CryptoKit. --- Package.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Package.swift b/Package.swift index 04b79568..7d92d23d 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:6.0 +// swift-tools-version:6.1 //===----------------------------------------------------------------------===// // // This source file is part of the SwiftCrypto open source project @@ -62,14 +62,14 @@ if development || isFreeBSD { ] swiftSettings = [ .define("CRYPTO_IN_SWIFTPM"), - .define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(platforms: platforms)), + .define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), ] dependencies = [ - .target(name: "CCryptoBoringSSL", condition: .when(platforms: platforms)), - .target(name: "CCryptoBoringSSLShims", condition: .when(platforms: platforms)), - .target(name: "CryptoBoringWrapper", condition: .when(platforms: platforms)), - .target(name: "CXKCP", condition: .when(platforms: platforms)), - .target(name: "CXKCPShims", condition: .when(platforms: platforms)), + .target(name: "CCryptoBoringSSL", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CCryptoBoringSSLShims", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CryptoBoringWrapper", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CXKCP", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CXKCPShims", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), ] } @@ -96,6 +96,7 @@ let package = Package( .library(name: "CCryptoBoringSSL", type: .static, targets: ["CCryptoBoringSSL"]), MANGLE_END */ ], + traits: [.trait(name: "FORCE_BUILD_SWIFT_CRYPTO_API")], dependencies: [ // Dependencies are added below so that they can be switched between local and absolute URLs ], From ba7dc1f389bdcbf1ad855bd7d21281a1fd55173e Mon Sep 17 00:00:00 2001 From: Cole Moore Date: Mon, 3 Nov 2025 09:07:27 +0800 Subject: [PATCH 2/3] Specifying FORCE_BUILD_SWIFT_CRYPTO_API trait only on Darwin --- Package.swift | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/Package.swift b/Package.swift index 7d92d23d..3bb16ded 100644 --- a/Package.swift +++ b/Package.swift @@ -53,6 +53,7 @@ if development || isFreeBSD { "CXKCPShims", ] } else { +#if !canImport(Darwin) let platforms: [Platform] = [ Platform.linux, Platform.android, @@ -62,15 +63,28 @@ if development || isFreeBSD { ] swiftSettings = [ .define("CRYPTO_IN_SWIFTPM"), - .define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(platforms: platforms)), ] dependencies = [ - .target(name: "CCryptoBoringSSL", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), - .target(name: "CCryptoBoringSSLShims", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), - .target(name: "CryptoBoringWrapper", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), - .target(name: "CXKCP", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), - .target(name: "CXKCPShims", condition: .when(platforms: platforms, traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CCryptoBoringSSL", condition: .when(platforms: platforms)), + .target(name: "CCryptoBoringSSLShims", condition: .when(platforms: platforms)), + .target(name: "CryptoBoringWrapper", condition: .when(platforms: platforms)), + .target(name: "CXKCP", condition: .when(platforms: platforms)), + .target(name: "CXKCPShims", condition: .when(platforms: platforms)), ] +#else + swiftSettings = [ + .define("CRYPTO_IN_SWIFTPM"), + .define("CRYPTO_IN_SWIFTPM_FORCE_BUILD_API", .when(traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + ] + dependencies = [ + .target(name: "CCryptoBoringSSL", condition: .when(traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CCryptoBoringSSLShims", condition: .when(traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CryptoBoringWrapper", condition: .when(traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CXKCP", condition: .when(traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + .target(name: "CXKCPShims", condition: .when(traits: ["FORCE_BUILD_SWIFT_CRYPTO_API"])), + ] +#endif } // This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and From 63bff550740e524201d9ba183642f25ea0c255eb Mon Sep 17 00:00:00 2001 From: Cole Moore Date: Tue, 4 Nov 2025 08:16:12 +0800 Subject: [PATCH 3/3] Added compile time checks to force swift-crypto api build in CryptoExtras --- Sources/CryptoExtras/AES/AES_CBC.swift | 4 ++++ Sources/CryptoExtras/AES/AES_CFB.swift | 4 ++++ Sources/CryptoExtras/AES/AES_CTR.swift | 4 ++++ Sources/CryptoExtras/AES/AES_GCM_SIV.swift | 4 ++++ Sources/CryptoExtras/AES/Block Function.swift | 4 ++++ Sources/CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift | 4 ++++ Sources/CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift | 4 ++++ Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift | 4 ++++ Sources/CryptoExtras/AES/CMAC.swift | 6 +++++- Sources/CryptoExtras/ARC/ARC+API.swift | 4 ++++ Sources/CryptoExtras/ARC/ARC.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCCredential.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCEncoding.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCPrecredential.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCPresentation.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCRequest.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCResponse.swift | 4 ++++ Sources/CryptoExtras/ARC/ARCServer.swift | 4 ++++ .../ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift | 4 ++++ Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift | 4 ++++ Sources/CryptoExtras/EC/Curve25519+PEM.swift | 4 ++++ Sources/CryptoExtras/EC/PKCS8DERRepresentation.swift | 4 ++++ Sources/CryptoExtras/EC/PKCS8PrivateKey.swift | 4 ++++ .../CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift | 4 ++++ Sources/CryptoExtras/ECToolbox/ECToolbox.swift | 4 ++++ Sources/CryptoExtras/H2G/HashToField.swift | 4 ++++ Sources/CryptoExtras/Key Derivation/KDF.swift | 4 ++++ .../Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift | 4 ++++ .../PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift | 4 ++++ Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift | 4 ++++ .../Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift | 4 ++++ Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift | 4 ++++ Sources/CryptoExtras/OPRFs/OPRF.swift | 4 ++++ Sources/CryptoExtras/OPRFs/OPRFClient.swift | 4 ++++ Sources/CryptoExtras/OPRFs/OPRFServer.swift | 4 ++++ Sources/CryptoExtras/OPRFs/VOPRF+API.swift | 4 ++++ Sources/CryptoExtras/OPRFs/VOPRFClient.swift | 4 ++++ Sources/CryptoExtras/OPRFs/VOPRFServer.swift | 4 ++++ Sources/CryptoExtras/RSA/RSA+BlindSigning.swift | 4 ++++ Sources/CryptoExtras/RSA/RSA.swift | 4 ++++ Sources/CryptoExtras/RSA/RSA_boring.swift | 4 ++++ Sources/CryptoExtras/Reexport.swift | 4 ++++ Sources/CryptoExtras/Util/BoringSSLHelpers.swift | 4 ++++ Sources/CryptoExtras/Util/CryptoKitErrors_boring.swift | 4 ++++ Sources/CryptoExtras/Util/DigestType.swift | 4 ++++ Sources/CryptoExtras/Util/PEMDocument.swift | 4 ++++ Sources/CryptoExtras/ZKPs/DLEQ.swift | 5 ++++- Sources/CryptoExtras/ZKPs/Prover.swift | 4 ++++ Sources/CryptoExtras/ZKPs/Verifier.swift | 4 ++++ Sources/CryptoExtras/ZKPs/ZKPToolbox.swift | 4 ++++ 50 files changed, 201 insertions(+), 2 deletions(-) diff --git a/Sources/CryptoExtras/AES/AES_CBC.swift b/Sources/CryptoExtras/AES/AES_CBC.swift index f94910bf..ce7dc48f 100644 --- a/Sources/CryptoExtras/AES/AES_CBC.swift +++ b/Sources/CryptoExtras/AES/AES_CBC.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/AES/AES_CFB.swift b/Sources/CryptoExtras/AES/AES_CFB.swift index 0334f2a4..3efbb7b3 100644 --- a/Sources/CryptoExtras/AES/AES_CFB.swift +++ b/Sources/CryptoExtras/AES/AES_CFB.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/AES/AES_CTR.swift b/Sources/CryptoExtras/AES/AES_CTR.swift index 416b0c31..8b33580e 100644 --- a/Sources/CryptoExtras/AES/AES_CTR.swift +++ b/Sources/CryptoExtras/AES/AES_CTR.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/AES/AES_GCM_SIV.swift b/Sources/CryptoExtras/AES/AES_GCM_SIV.swift index 33d0c7ed..27455a7c 100644 --- a/Sources/CryptoExtras/AES/AES_GCM_SIV.swift +++ b/Sources/CryptoExtras/AES/AES_GCM_SIV.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper diff --git a/Sources/CryptoExtras/AES/Block Function.swift b/Sources/CryptoExtras/AES/Block Function.swift index 0bf0ccbc..80ab35eb 100644 --- a/Sources/CryptoExtras/AES/Block Function.swift +++ b/Sources/CryptoExtras/AES/Block Function.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims import CryptoBoringWrapper diff --git a/Sources/CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift b/Sources/CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift index 69e57dda..4184fdb0 100644 --- a/Sources/CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift +++ b/Sources/CryptoExtras/AES/BoringSSL/AES_CFB_boring.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// @_implementationOnly import CCryptoBoringSSL +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials diff --git a/Sources/CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift b/Sources/CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift index 2ed03be5..63d83b52 100644 --- a/Sources/CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift +++ b/Sources/CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// @_implementationOnly import CCryptoBoringSSL +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials diff --git a/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift b/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift index 3bc7aff3..ffafa16a 100644 --- a/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift +++ b/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift @@ -16,7 +16,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper #if canImport(FoundationEssentials) diff --git a/Sources/CryptoExtras/AES/CMAC.swift b/Sources/CryptoExtras/AES/CMAC.swift index c9629334..b0a7ea93 100644 --- a/Sources/CryptoExtras/AES/CMAC.swift +++ b/Sources/CryptoExtras/AES/CMAC.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// @_implementationOnly import CCryptoBoringSSL +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials @@ -47,7 +51,7 @@ extension AES { /// - outputSize: The number of bytes of MAC to generate. Must be in the range 0 to 16 inclusive. public init(key: SymmetricKey, outputSize: Int) throws { guard [128, 192, 256].contains(key.bitCount) else { - throw CryptoError.incorrectKeySize + throw CryptoKitError.incorrectKeySize } guard (0...16).contains(outputSize) else { throw CryptoKitError.incorrectParameterSize diff --git a/Sources/CryptoExtras/ARC/ARC+API.swift b/Sources/CryptoExtras/ARC/ARC+API.swift index b40b8c1b..262c86a5 100644 --- a/Sources/CryptoExtras/ARC/ARC+API.swift +++ b/Sources/CryptoExtras/ARC/ARC+API.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARC.swift b/Sources/CryptoExtras/ARC/ARC.swift index 087a1326..20ffa39e 100644 --- a/Sources/CryptoExtras/ARC/ARC.swift +++ b/Sources/CryptoExtras/ARC/ARC.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARCCredential.swift b/Sources/CryptoExtras/ARC/ARCCredential.swift index 915cbc3e..674d52ed 100644 --- a/Sources/CryptoExtras/ARC/ARCCredential.swift +++ b/Sources/CryptoExtras/ARC/ARCCredential.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARCEncoding.swift b/Sources/CryptoExtras/ARC/ARCEncoding.swift index e445f6f2..19916a90 100644 --- a/Sources/CryptoExtras/ARC/ARCEncoding.swift +++ b/Sources/CryptoExtras/ARC/ARCEncoding.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, macCatalyst 13.2, visionOS 1.2, *) typealias ARCP256 = HashToCurveImpl diff --git a/Sources/CryptoExtras/ARC/ARCPrecredential.swift b/Sources/CryptoExtras/ARC/ARCPrecredential.swift index 4259cb09..7bb8b647 100644 --- a/Sources/CryptoExtras/ARC/ARCPrecredential.swift +++ b/Sources/CryptoExtras/ARC/ARCPrecredential.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARCPresentation.swift b/Sources/CryptoExtras/ARC/ARCPresentation.swift index 6f710543..53dca2e8 100644 --- a/Sources/CryptoExtras/ARC/ARCPresentation.swift +++ b/Sources/CryptoExtras/ARC/ARCPresentation.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARCRequest.swift b/Sources/CryptoExtras/ARC/ARCRequest.swift index b36aacfd..df3f451c 100644 --- a/Sources/CryptoExtras/ARC/ARCRequest.swift +++ b/Sources/CryptoExtras/ARC/ARCRequest.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARCResponse.swift b/Sources/CryptoExtras/ARC/ARCResponse.swift index 059eefd2..de5e657e 100644 --- a/Sources/CryptoExtras/ARC/ARCResponse.swift +++ b/Sources/CryptoExtras/ARC/ARCResponse.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ARC/ARCServer.swift b/Sources/CryptoExtras/ARC/ARCServer.swift index c39daece..9266dd37 100644 --- a/Sources/CryptoExtras/ARC/ARCServer.swift +++ b/Sources/CryptoExtras/ARC/ARCServer.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift b/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift index 701bf8d8..5050044c 100644 --- a/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift +++ b/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift @@ -14,7 +14,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper #if canImport(FoundationEssentials) diff --git a/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift b/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift index 385fa6e6..34fef52f 100644 --- a/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift +++ b/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift @@ -14,7 +14,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper #if canImport(FoundationEssentials) import FoundationEssentials diff --git a/Sources/CryptoExtras/EC/Curve25519+PEM.swift b/Sources/CryptoExtras/EC/Curve25519+PEM.swift index 5e8071c8..e148a3b4 100644 --- a/Sources/CryptoExtras/EC/Curve25519+PEM.swift +++ b/Sources/CryptoExtras/EC/Curve25519+PEM.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import Foundation import SwiftASN1 diff --git a/Sources/CryptoExtras/EC/PKCS8DERRepresentation.swift b/Sources/CryptoExtras/EC/PKCS8DERRepresentation.swift index bfaf11f4..becc2740 100644 --- a/Sources/CryptoExtras/EC/PKCS8DERRepresentation.swift +++ b/Sources/CryptoExtras/EC/PKCS8DERRepresentation.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import Foundation import SwiftASN1 diff --git a/Sources/CryptoExtras/EC/PKCS8PrivateKey.swift b/Sources/CryptoExtras/EC/PKCS8PrivateKey.swift index 5de7a11e..5ee715c2 100644 --- a/Sources/CryptoExtras/EC/PKCS8PrivateKey.swift +++ b/Sources/CryptoExtras/EC/PKCS8PrivateKey.swift @@ -12,7 +12,11 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import SwiftASN1 @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) diff --git a/Sources/CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift b/Sources/CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift index 36cb3d73..72b6eef0 100644 --- a/Sources/CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift +++ b/Sources/CryptoExtras/ECToolbox/BoringSSL/ECToolbox_boring.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper #if canImport(FoundationEssentials) diff --git a/Sources/CryptoExtras/ECToolbox/ECToolbox.swift b/Sources/CryptoExtras/ECToolbox/ECToolbox.swift index a1eb80e9..f99e8457 100644 --- a/Sources/CryptoExtras/ECToolbox/ECToolbox.swift +++ b/Sources/CryptoExtras/ECToolbox/ECToolbox.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/H2G/HashToField.swift b/Sources/CryptoExtras/H2G/HashToField.swift index 3b9b55c8..c56f8d27 100644 --- a/Sources/CryptoExtras/H2G/HashToField.swift +++ b/Sources/CryptoExtras/H2G/HashToField.swift @@ -29,7 +29,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) extension Data { diff --git a/Sources/CryptoExtras/Key Derivation/KDF.swift b/Sources/CryptoExtras/Key Derivation/KDF.swift index 6990023d..75b55255 100644 --- a/Sources/CryptoExtras/Key Derivation/KDF.swift +++ b/Sources/CryptoExtras/Key Derivation/KDF.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift b/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift index 6bfbad71..031cebc0 100644 --- a/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift +++ b/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials diff --git a/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift b/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift index 5926bbc4..42df9af4 100644 --- a/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift +++ b/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_commoncrypto.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials diff --git a/Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift b/Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift index d222f141..59372ffe 100644 --- a/Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift +++ b/Sources/CryptoExtras/Key Derivation/PBKDF2/PBKDF2.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift b/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift index b89c9bd1..299c29e7 100644 --- a/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift +++ b/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift @@ -14,7 +14,11 @@ @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) #if os(Windows) diff --git a/Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift b/Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift index e0bc93b8..4a699da5 100644 --- a/Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift +++ b/Sources/CryptoExtras/Key Derivation/Scrypt/Scrypt.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/OPRFs/OPRF.swift b/Sources/CryptoExtras/OPRFs/OPRF.swift index 28336d12..963a09f1 100644 --- a/Sources/CryptoExtras/OPRFs/OPRF.swift +++ b/Sources/CryptoExtras/OPRFs/OPRF.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif /// (Verifiable Partly-)Oblivious Pseudorandom Functions /// https://cfrg.github.io/draft-irtf-cfrg-voprf/draft-irtf-cfrg-voprf.html diff --git a/Sources/CryptoExtras/OPRFs/OPRFClient.swift b/Sources/CryptoExtras/OPRFs/OPRFClient.swift index a3080821..a189f509 100644 --- a/Sources/CryptoExtras/OPRFs/OPRFClient.swift +++ b/Sources/CryptoExtras/OPRFs/OPRFClient.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/OPRFs/OPRFServer.swift b/Sources/CryptoExtras/OPRFs/OPRFServer.swift index baa3a419..373643fe 100644 --- a/Sources/CryptoExtras/OPRFs/OPRFServer.swift +++ b/Sources/CryptoExtras/OPRFs/OPRFServer.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, macCatalyst 13.2, visionOS 1.2, *) extension OPRF { diff --git a/Sources/CryptoExtras/OPRFs/VOPRF+API.swift b/Sources/CryptoExtras/OPRFs/VOPRF+API.swift index 44476b0e..0c1ca61b 100644 --- a/Sources/CryptoExtras/OPRFs/VOPRF+API.swift +++ b/Sources/CryptoExtras/OPRFs/VOPRF+API.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/OPRFs/VOPRFClient.swift b/Sources/CryptoExtras/OPRFs/VOPRFClient.swift index 299e00c1..a5789bd3 100644 --- a/Sources/CryptoExtras/OPRFs/VOPRFClient.swift +++ b/Sources/CryptoExtras/OPRFs/VOPRFClient.swift @@ -11,7 +11,11 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif #if canImport(FoundationEssentials) import FoundationEssentials #else diff --git a/Sources/CryptoExtras/OPRFs/VOPRFServer.swift b/Sources/CryptoExtras/OPRFs/VOPRFServer.swift index 1a20271f..da27e955 100644 --- a/Sources/CryptoExtras/OPRFs/VOPRFServer.swift +++ b/Sources/CryptoExtras/OPRFs/VOPRFServer.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13.2, tvOS 13.2, watchOS 6.1, macCatalyst 13.2, visionOS 1.2, *) extension OPRF { diff --git a/Sources/CryptoExtras/RSA/RSA+BlindSigning.swift b/Sources/CryptoExtras/RSA/RSA+BlindSigning.swift index 3f14da32..e80e3c84 100644 --- a/Sources/CryptoExtras/RSA/RSA+BlindSigning.swift +++ b/Sources/CryptoExtras/RSA/RSA+BlindSigning.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper // NOTE: RSABSSA API is implemented using BoringSSL on all platforms. diff --git a/Sources/CryptoExtras/RSA/RSA.swift b/Sources/CryptoExtras/RSA/RSA.swift index a6c13a89..b224a0f5 100644 --- a/Sources/CryptoExtras/RSA/RSA.swift +++ b/Sources/CryptoExtras/RSA/RSA.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper import SwiftASN1 diff --git a/Sources/CryptoExtras/RSA/RSA_boring.swift b/Sources/CryptoExtras/RSA/RSA_boring.swift index c0f3be1a..a47c5823 100644 --- a/Sources/CryptoExtras/RSA/RSA_boring.swift +++ b/Sources/CryptoExtras/RSA/RSA_boring.swift @@ -15,7 +15,11 @@ // NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms. @_implementationOnly import CCryptoBoringSSL @_implementationOnly import CCryptoBoringSSLShims +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif import CryptoBoringWrapper #if canImport(FoundationEssentials) diff --git a/Sources/CryptoExtras/Reexport.swift b/Sources/CryptoExtras/Reexport.swift index 5bfdabc0..725c334e 100644 --- a/Sources/CryptoExtras/Reexport.swift +++ b/Sources/CryptoExtras/Reexport.swift @@ -12,4 +12,8 @@ // //===----------------------------------------------------------------------===// +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else @_exported import Crypto +#endif diff --git a/Sources/CryptoExtras/Util/BoringSSLHelpers.swift b/Sources/CryptoExtras/Util/BoringSSLHelpers.swift index b560330c..9f86ec35 100644 --- a/Sources/CryptoExtras/Util/BoringSSLHelpers.swift +++ b/Sources/CryptoExtras/Util/BoringSSLHelpers.swift @@ -20,7 +20,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) internal enum BIOHelper { diff --git a/Sources/CryptoExtras/Util/CryptoKitErrors_boring.swift b/Sources/CryptoExtras/Util/CryptoKitErrors_boring.swift index 21d5da6f..d4a45b60 100644 --- a/Sources/CryptoExtras/Util/CryptoKitErrors_boring.swift +++ b/Sources/CryptoExtras/Util/CryptoKitErrors_boring.swift @@ -13,7 +13,11 @@ //===----------------------------------------------------------------------===// @_implementationOnly import CCryptoBoringSSL +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) extension CryptoKitError { diff --git a/Sources/CryptoExtras/Util/DigestType.swift b/Sources/CryptoExtras/Util/DigestType.swift index 469c5687..d36f2f57 100644 --- a/Sources/CryptoExtras/Util/DigestType.swift +++ b/Sources/CryptoExtras/Util/DigestType.swift @@ -14,7 +14,11 @@ // NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms. @_implementationOnly import CCryptoBoringSSL +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) struct DigestType: @unchecked Sendable { diff --git a/Sources/CryptoExtras/Util/PEMDocument.swift b/Sources/CryptoExtras/Util/PEMDocument.swift index 17467a85..b911891c 100644 --- a/Sources/CryptoExtras/Util/PEMDocument.swift +++ b/Sources/CryptoExtras/Util/PEMDocument.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) enum ASN1 { diff --git a/Sources/CryptoExtras/ZKPs/DLEQ.swift b/Sources/CryptoExtras/ZKPs/DLEQ.swift index 41cf271e..17ea360f 100644 --- a/Sources/CryptoExtras/ZKPs/DLEQ.swift +++ b/Sources/CryptoExtras/ZKPs/DLEQ.swift @@ -16,8 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto - +#endif /// A DLEQ Proof as described in https://cfrg.github.io/draft-irtf-cfrg-voprf/draft-irtf-cfrg-voprf.html#name-generateproof @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) struct DLEQProof { diff --git a/Sources/CryptoExtras/ZKPs/Prover.swift b/Sources/CryptoExtras/ZKPs/Prover.swift index ac5fa036..79148769 100644 --- a/Sources/CryptoExtras/ZKPs/Prover.swift +++ b/Sources/CryptoExtras/ZKPs/Prover.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) struct Prover: ProofParticipant { diff --git a/Sources/CryptoExtras/ZKPs/Verifier.swift b/Sources/CryptoExtras/ZKPs/Verifier.swift index 8a9a8445..057a5872 100644 --- a/Sources/CryptoExtras/ZKPs/Verifier.swift +++ b/Sources/CryptoExtras/ZKPs/Verifier.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) struct Verifier: ProofParticipant { diff --git a/Sources/CryptoExtras/ZKPs/ZKPToolbox.swift b/Sources/CryptoExtras/ZKPs/ZKPToolbox.swift index 8c7db5d1..e4fd62c3 100644 --- a/Sources/CryptoExtras/ZKPs/ZKPToolbox.swift +++ b/Sources/CryptoExtras/ZKPs/ZKPToolbox.swift @@ -16,7 +16,11 @@ import FoundationEssentials #else import Foundation #endif +#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API +@_exported import CryptoKit +#else import Crypto +#endif @available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *) struct ScalarVar {