From a3866d45d9f736b948774f727f5b6b9761aae31b Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Fri, 21 Jun 2024 16:35:50 +0100 Subject: [PATCH] Move ArbitraryPrecisionInteger type to CryptoBoringWrapper module (#236) * Move ArbitraryPrecisionInteger_boring.swift to CryptoBoringWrapper * Remove conditional compilation guards for ArbitraryPrecisionInteger * Throw CryptoBoringWrapperError.internalBoringSSLError instead of CryptoKitError.internalBoringSSLError * Make most operations public and add raw pointer APIs * Move ArbitraryPrecisionIntegerTests to new CryptoBoringWrapperTests target * rename some files * Remove @_implementationOnly from imports and raw pointer APIs * Also move over FiniteFieldArithmeticContext to CryptoBoringWrapper * Add FiniteFieldArithmeticContext.inverse * Remove conditional compilation guards for FFAC * Update CMakeLists.txt for moved files * Revert "Add FiniteFieldArithmeticContext.inverse" This reverts commit e02700e07cfdfbdd6eab7335ccb04d0ece6a667e. * Fix CMakeLists.txt * Make most public symbols @inlinable --------- Co-authored-by: Cory Benfield --- Package.swift | 1 + .../AES/GCM/BoringSSL/AES-GCM_boring.swift | 4 +- .../BoringSSL/ChaChaPoly_boring.swift | 6 +- Sources/Crypto/CMakeLists.txt | 2 - .../Digests/BoringSSL/Digest_boring.swift | 2 +- .../Key Agreement/BoringSSL/ECDH_boring.swift | 2 +- .../BoringSSL/AESWrap_boring.swift | 2 +- .../Keys/EC/BoringSSL/Ed25519_boring.swift | 4 +- .../BoringSSL/EllipticCurvePoint_boring.swift | 3 +- .../EC/BoringSSL/EllipticCurve_boring.swift | 3 +- .../EC/BoringSSL/NISTCurvesKeys_boring.swift | 5 +- .../Keys/EC/BoringSSL/X25519Keys_boring.swift | 4 +- .../BoringSSL/ECDSASignature_boring.swift | 5 +- .../Signatures/BoringSSL/ECDSA_boring.swift | 2 +- .../Signatures/BoringSSL/EdDSA_boring.swift | 4 +- .../BoringSSL/CryptoKitErrors_boring.swift | 2 +- .../Util/BoringSSL/Zeroization_boring.swift | 2 +- .../AEAD/BoringSSLAEAD.swift | 4 +- .../ArbitraryPrecisionInteger.swift} | 129 +++++++++--------- Sources/CryptoBoringWrapper/CMakeLists.txt | 4 +- .../CryptoKitErrors_boring.swift | 3 +- .../FiniteFieldArithmeticContext.swift} | 51 ++++--- Sources/_CryptoExtras/AES/AES_GCM_SIV.swift | 6 +- .../_CryptoExtras/AES/Block Function.swift | 6 +- .../AES/BoringSSL/AES_CTR_boring.swift | 2 +- .../AES/BoringSSL/AES_GCM_SIV_boring.swift | 6 +- .../BoringSSL/ChaCha20CTR_boring.swift | 6 +- .../ChaCha20CTR/ChaCha20CTR.swift | 6 +- Sources/_CryptoExtras/RSA/RSA_boring.swift | 4 +- .../_CryptoExtras/Util/BoringSSLHelpers.swift | 2 +- .../Util/CryptoKitErrors_boring.swift | 2 +- Sources/_CryptoExtras/Util/DigestType.swift | 2 +- .../ArbitraryPrecisionIntegerTests.swift | 7 +- Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift | 2 +- .../BoringSSL/secpECDH_Runner_boring.swift | 2 +- 35 files changed, 150 insertions(+), 147 deletions(-) rename Sources/{Crypto/Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift => CryptoBoringWrapper/ArbitraryPrecisionInteger.swift} (78%) rename Sources/{Crypto/Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift => CryptoBoringWrapper/FiniteFieldArithmeticContext.swift} (75%) rename Tests/{CryptoTests/BoringSSL => CryptoBoringWrapperTests}/ArbitraryPrecisionIntegerTests.swift (94%) diff --git a/Package.swift b/Package.swift index 902c095d..665ffe02 100644 --- a/Package.swift +++ b/Package.swift @@ -168,6 +168,7 @@ let package = Package( swiftSettings: swiftSettings ), .testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]), + .testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]), ], cxxLanguageStandard: .cxx11 ) diff --git a/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift b/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift index c85ac49e..cd7458fe 100644 --- a/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift +++ b/Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift @@ -14,8 +14,8 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CryptoBoringWrapper +import CCryptoBoringSSL +import CryptoBoringWrapper import Foundation enum OpenSSLAESGCMImpl { diff --git a/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift b/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift index c4698aa1..f9c2ec0c 100644 --- a/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift +++ b/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift @@ -14,9 +14,9 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims -@_implementationOnly import CryptoBoringWrapper +import CCryptoBoringSSL +import CCryptoBoringSSLShims +import CryptoBoringWrapper import Foundation extension BoringSSLAEAD { diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index 89041043..aab7d236 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -86,9 +86,7 @@ add_library(Crypto "Signatures/ECDSA.swift" "Signatures/Ed25519.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" diff --git a/Sources/Crypto/Digests/BoringSSL/Digest_boring.swift b/Sources/Crypto/Digests/BoringSSL/Digest_boring.swift index 20a7a2c7..f50a6bdb 100644 --- a/Sources/Crypto/Digests/BoringSSL/Digest_boring.swift +++ b/Sources/Crypto/Digests/BoringSSL/Digest_boring.swift @@ -14,7 +14,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL protocol HashFunctionImplementationDetails: HashFunction where Digest: DigestPrivate {} diff --git a/Sources/Crypto/Key Agreement/BoringSSL/ECDH_boring.swift b/Sources/Crypto/Key Agreement/BoringSSL/ECDH_boring.swift index 98bf29ae..c6b98fbf 100644 --- a/Sources/Crypto/Key Agreement/BoringSSL/ECDH_boring.swift +++ b/Sources/Crypto/Key Agreement/BoringSSL/ECDH_boring.swift @@ -14,7 +14,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL extension P256.KeyAgreement.PrivateKey { internal func openSSLSharedSecretFromKeyAgreement(with publicKeyShare: P256.KeyAgreement.PublicKey) throws -> SharedSecret { diff --git a/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift b/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift index bb96bf87..f11d5fbf 100644 --- a/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift +++ b/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift @@ -14,7 +14,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL import Foundation enum BoringSSLAESWRAPImpl { diff --git a/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift index 17a4233b..02e73ade 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift @@ -14,8 +14,8 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Foundation // For signing and verifying, we use BoringSSL's Ed25519, not the X25519 stuff. diff --git a/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift index 84283ddf..ab1ca540 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurvePoint_boring.swift @@ -14,7 +14,8 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL +import CryptoBoringWrapper /// A wrapper around BoringSSL's EC_POINT with some lifetime management. @usableFromInline diff --git a/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurve_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurve_boring.swift index 3bfc6f2a..ba7dfda4 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurve_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/EllipticCurve_boring.swift @@ -14,7 +14,8 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL +import CryptoBoringWrapper /// A wrapper around BoringSSL's EC_GROUP object that handles reference counting and /// liveness. diff --git a/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift index d7439b99..2aa72453 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift @@ -14,8 +14,9 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims +import CryptoBoringWrapper import Foundation @usableFromInline diff --git a/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift index 51cbeced..6eb62475 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift @@ -14,8 +14,8 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Foundation extension Curve25519.KeyAgreement { diff --git a/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift b/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift index 87a9a31c..311761cb 100644 --- a/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift @@ -14,8 +14,9 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims +import CryptoBoringWrapper import Foundation /// A wrapper around BoringSSL's ECDSA_SIG with some lifetime management. diff --git a/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift b/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift index 7b0a79bf..49d48c60 100644 --- a/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift @@ -14,7 +14,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL import Foundation extension Data { diff --git a/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift b/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift index 5fd65e44..ff25f612 100644 --- a/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift @@ -14,8 +14,8 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Foundation extension Curve25519.Signing.PublicKey { diff --git a/Sources/Crypto/Util/BoringSSL/CryptoKitErrors_boring.swift b/Sources/Crypto/Util/BoringSSL/CryptoKitErrors_boring.swift index 62d3910b..f0003b1b 100644 --- a/Sources/Crypto/Util/BoringSSL/CryptoKitErrors_boring.swift +++ b/Sources/Crypto/Util/BoringSSL/CryptoKitErrors_boring.swift @@ -14,7 +14,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @_exported import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL extension CryptoKitError { /// A helper function that packs the value of `ERR_get_error` into the internal error field. diff --git a/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift b/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift index a4e1ecea..c9907581 100644 --- a/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift +++ b/Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// #if !canImport(Darwin) -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL typealias errno_t = CInt diff --git a/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift b/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift index 4299e561..08aa3d48 100644 --- a/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift +++ b/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift @@ -12,8 +12,8 @@ // //===----------------------------------------------------------------------===// -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Foundation /// An abstraction over a BoringSSL AEAD diff --git a/Sources/Crypto/Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift b/Sources/CryptoBoringWrapper/ArbitraryPrecisionInteger.swift similarity index 78% rename from Sources/Crypto/Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift rename to Sources/CryptoBoringWrapper/ArbitraryPrecisionInteger.swift index e55c78ff..495dc70c 100644 --- a/Sources/Crypto/Util/BoringSSL/ArbitraryPrecisionInteger_boring.swift +++ b/Sources/CryptoBoringWrapper/ArbitraryPrecisionInteger.swift @@ -11,35 +11,32 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API -@_exported import CryptoKit -#else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Foundation /// A wrapper around the OpenSSL BIGNUM object that is appropriately lifetime managed, /// and that provides better Swift types for this object. -@usableFromInline -struct ArbitraryPrecisionInteger { - private var _backing: BackingStorage +public struct ArbitraryPrecisionInteger { + /* private but @usableFromInline */ @usableFromInline var _backing: BackingStorage - @usableFromInline - init() { + @inlinable + public init() { self._backing = BackingStorage() } - init(copying original: UnsafePointer) throws { + @inlinable + public init(copying original: UnsafePointer) throws { self._backing = try BackingStorage(copying: original) } - @usableFromInline - init(_ original: ArbitraryPrecisionInteger) throws { + @inlinable + public init(_ original: ArbitraryPrecisionInteger) throws { self._backing = try BackingStorage(copying: original._backing) } - @usableFromInline - init(integerLiteral value: Int64) { + @inlinable + public init(integerLiteral value: Int64) { self._backing = BackingStorage(value) } } @@ -47,31 +44,36 @@ struct ArbitraryPrecisionInteger { // MARK: - BackingStorage extension ArbitraryPrecisionInteger { + @usableFromInline final class BackingStorage { - private var _backing: BIGNUM + /* private but @usableFromInline */ @usableFromInline var _backing: BIGNUM + @usableFromInline init() { self._backing = BIGNUM() CCryptoBoringSSL_BN_init(&self._backing) } + @usableFromInline init(copying original: UnsafePointer) throws { self._backing = BIGNUM() guard CCryptoBoringSSL_BN_copy(&self._backing, original) != nil else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } } + @usableFromInline init(copying original: BackingStorage) throws { self._backing = BIGNUM() try original.withUnsafeMutableBignumPointer { bnPtr in guard CCryptoBoringSSL_BN_copy(&self._backing, bnPtr) != nil else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } } } + @usableFromInline init(_ value: Int64) { self._backing = BIGNUM() let rc = CCryptoBoringSSL_BN_set_u64(&self._backing, value.magnitude) @@ -82,6 +84,7 @@ extension ArbitraryPrecisionInteger { } } + @inlinable deinit { CCryptoBoringSSL_BN_clear_free(&self._backing) } @@ -91,13 +94,14 @@ extension ArbitraryPrecisionInteger { // MARK: - Extra initializers extension ArbitraryPrecisionInteger { - @usableFromInline - init(bytes: Bytes) throws { + @inlinable + public init(bytes: Bytes) throws { self._backing = try BackingStorage(bytes: bytes) } } extension ArbitraryPrecisionInteger.BackingStorage { + @inlinable convenience init(bytes: Bytes) throws { self.init() @@ -105,7 +109,7 @@ extension ArbitraryPrecisionInteger.BackingStorage { CCryptoBoringSSLShims_BN_bin2bn(bytesPointer.baseAddress, bytesPointer.count, &self._backing) } guard rc != nil else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } } } @@ -113,11 +117,13 @@ extension ArbitraryPrecisionInteger.BackingStorage { // MARK: - Pointer helpers extension ArbitraryPrecisionInteger { - func withUnsafeBignumPointer(_ body: (UnsafePointer) throws -> T) rethrows -> T { + @inlinable + public func withUnsafeBignumPointer(_ body: (UnsafePointer) throws -> T) rethrows -> T { try self._backing.withUnsafeBignumPointer(body) } - mutating func withUnsafeMutableBignumPointer(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { + @inlinable + public mutating func withUnsafeMutableBignumPointer(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { if !isKnownUniquelyReferenced(&self._backing) { // Failing to CoW is a fatal error here. self._backing = try! BackingStorage(copying: self._backing) @@ -128,10 +134,12 @@ extension ArbitraryPrecisionInteger { } extension ArbitraryPrecisionInteger.BackingStorage { + @usableFromInline func withUnsafeBignumPointer(_ body: (UnsafePointer) throws -> T) rethrows -> T { try body(&self._backing) } + @usableFromInline func withUnsafeMutableBignumPointer(_ body: (UnsafeMutablePointer) throws -> T) rethrows -> T { try body(&self._backing) } @@ -155,8 +163,8 @@ extension ArbitraryPrecisionInteger { } } - @usableFromInline - func squared() -> ArbitraryPrecisionInteger { + @inlinable + public func squared() -> ArbitraryPrecisionInteger { var result = ArbitraryPrecisionInteger() let rc = result.withUnsafeMutableBignumPointer { resultPtr in self.withUnsafeBignumPointer { selfPtr in @@ -169,8 +177,8 @@ extension ArbitraryPrecisionInteger { return result } - @usableFromInline - func positiveSquareRoot() throws -> ArbitraryPrecisionInteger { + @inlinable + public func positiveSquareRoot() throws -> ArbitraryPrecisionInteger { var result = ArbitraryPrecisionInteger() let rc = result.withUnsafeMutableBignumPointer { resultPtr in self.withUnsafeBignumPointer { selfPtr in @@ -181,20 +189,20 @@ extension ArbitraryPrecisionInteger { } guard rc == 1 else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } return result } - @usableFromInline - var byteCount: Int { + @inlinable + public var byteCount: Int { self._backing.withUnsafeBignumPointer { Int(CCryptoBoringSSL_BN_num_bytes($0)) } } /// Some functions require a BN_CTX parameter: this obtains one with a scoped lifetime. - private static func withUnsafeBN_CTX(_ body: (OpaquePointer) throws -> T) rethrows -> T { + /* private but @usableFromInline */ @usableFromInline static func withUnsafeBN_CTX(_ body: (OpaquePointer) throws -> T) rethrows -> T { // We force unwrap here because this call can only fail if the allocator is broken, and if // the allocator fails we don't have long to live anyway. let bnCtx = CCryptoBoringSSL_BN_CTX_new()! @@ -210,7 +218,7 @@ extension ArbitraryPrecisionInteger { extension ArbitraryPrecisionInteger: Equatable { @inlinable - static func == (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { + public static func == (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { self._compare(lhs: lhs, rhs: rhs) == 0 } } @@ -219,22 +227,22 @@ extension ArbitraryPrecisionInteger: Equatable { extension ArbitraryPrecisionInteger: Comparable { @inlinable - static func < (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { + public static func < (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { self._compare(lhs: lhs, rhs: rhs) < 0 } @inlinable - static func <= (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { + public static func <= (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { self._compare(lhs: lhs, rhs: rhs) <= 0 } @inlinable - static func > (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { + public static func > (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { self._compare(lhs: lhs, rhs: rhs) > 0 } @inlinable - static func >= (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { + public static func >= (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> Bool { self._compare(lhs: lhs, rhs: rhs) >= 0 } } @@ -247,12 +255,12 @@ extension ArbitraryPrecisionInteger: ExpressibleByIntegerLiteral {} extension ArbitraryPrecisionInteger: AdditiveArithmetic { @inlinable - static var zero: ArbitraryPrecisionInteger { + public static var zero: ArbitraryPrecisionInteger { 0 } - @usableFromInline - static func + (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> ArbitraryPrecisionInteger { + @inlinable + public static func + (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> ArbitraryPrecisionInteger { var result = ArbitraryPrecisionInteger() let rc = result.withUnsafeMutableBignumPointer { resultPtr in @@ -267,8 +275,8 @@ extension ArbitraryPrecisionInteger: AdditiveArithmetic { return result } - @usableFromInline - static func += (lhs: inout ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) { + @inlinable + public static func += (lhs: inout ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) { let rc = lhs.withUnsafeMutableBignumPointer { lhsPtr in rhs.withUnsafeBignumPointer { rhsPtr in CCryptoBoringSSL_BN_add(lhsPtr, lhsPtr, rhsPtr) @@ -277,8 +285,8 @@ extension ArbitraryPrecisionInteger: AdditiveArithmetic { precondition(rc == 1, "Unable to allocate memory for new ArbitraryPrecisionInteger") } - @usableFromInline - static func - (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> ArbitraryPrecisionInteger { + @inlinable + public static func - (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> ArbitraryPrecisionInteger { var result = ArbitraryPrecisionInteger() let rc = result.withUnsafeMutableBignumPointer { resultPtr in @@ -293,8 +301,8 @@ extension ArbitraryPrecisionInteger: AdditiveArithmetic { return result } - @usableFromInline - static func -= (lhs: inout ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) { + @inlinable + public static func -= (lhs: inout ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) { let rc = lhs.withUnsafeMutableBignumPointer { lhsPtr in rhs.withUnsafeBignumPointer { rhsPtr in CCryptoBoringSSL_BN_sub(lhsPtr, lhsPtr, rhsPtr) @@ -307,11 +315,10 @@ extension ArbitraryPrecisionInteger: AdditiveArithmetic { // MARK: - Numeric extension ArbitraryPrecisionInteger: Numeric { - @usableFromInline - typealias Magnitude = Self + public typealias Magnitude = Self - @usableFromInline - var magnitude: Magnitude { + @inlinable + public var magnitude: Magnitude { if self._positive { return self } @@ -325,8 +332,8 @@ extension ArbitraryPrecisionInteger: Numeric { return copy } - @usableFromInline - static func * (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> ArbitraryPrecisionInteger { + @inlinable + public static func * (lhs: ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) -> ArbitraryPrecisionInteger { var result = ArbitraryPrecisionInteger() let rc = result.withUnsafeMutableBignumPointer { resultPtr in @@ -343,8 +350,8 @@ extension ArbitraryPrecisionInteger: Numeric { return result } - @usableFromInline - static func *= (lhs: inout ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) { + @inlinable + public static func *= (lhs: inout ArbitraryPrecisionInteger, rhs: ArbitraryPrecisionInteger) { let rc = lhs.withUnsafeMutableBignumPointer { lhsPtr in rhs.withUnsafeBignumPointer { rhsPtr in ArbitraryPrecisionInteger.withUnsafeBN_CTX { bnCtx in @@ -356,7 +363,7 @@ extension ArbitraryPrecisionInteger: Numeric { } @inlinable - init?(exactly integer: T) { + public init?(exactly integer: T) { fatalError("Not currently implemented") } } @@ -364,8 +371,8 @@ extension ArbitraryPrecisionInteger: Numeric { // MARK: - SignedNumeric extension ArbitraryPrecisionInteger: SignedNumeric { - @usableFromInline - mutating func negate() { + @inlinable + public mutating func negate() { let signBit: CInt = self._positive ? 1 : 0 self.withUnsafeMutableBignumPointer { @@ -378,12 +385,12 @@ extension ArbitraryPrecisionInteger: SignedNumeric { extension Data { /// Serializes an ArbitraryPrecisionInteger padded out to a certain minimum size. - @usableFromInline - mutating func append(bytesOf integer: ArbitraryPrecisionInteger, paddedToSize paddingSize: Int) throws { + @inlinable + public mutating func append(bytesOf integer: ArbitraryPrecisionInteger, paddedToSize paddingSize: Int) throws { let byteCount = integer.byteCount guard paddingSize >= byteCount else { - throw CryptoKitError.incorrectParameterSize + throw CryptoBoringWrapperError.incorrectParameterSize } // To extend the data we need to write some zeroes into it. @@ -406,8 +413,7 @@ extension Data { // MARK: - Printing extension ArbitraryPrecisionInteger: CustomDebugStringConvertible { - @usableFromInline - var debugDescription: String { + public var debugDescription: String { guard let bio = CCryptoBoringSSL_BIO_new(CCryptoBoringSSL_BIO_s_mem()) else { return "ArbitraryPrecisionInteger: (error generating representation)" } @@ -442,4 +448,3 @@ extension ArbitraryPrecisionInteger: CustomDebugStringConvertible { return String(decoding: UnsafeBufferPointer(start: stringPointer, count: length), as: Unicode.UTF8.self) } } -#endif // CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Sources/CryptoBoringWrapper/CMakeLists.txt b/Sources/CryptoBoringWrapper/CMakeLists.txt index 1de749f2..796315f9 100644 --- a/Sources/CryptoBoringWrapper/CMakeLists.txt +++ b/Sources/CryptoBoringWrapper/CMakeLists.txt @@ -14,7 +14,9 @@ add_library(CryptoBoringWrapper STATIC "AEAD/BoringSSLAEAD.swift" - "CryptoKitErrors_boring.swift") + "ArbitraryPrecisionInteger.swift" + "CryptoKitErrors_boring.swift" + "FiniteFieldArithmeticContext.swift") target_include_directories(CryptoBoringWrapper PUBLIC $ diff --git a/Sources/CryptoBoringWrapper/CryptoKitErrors_boring.swift b/Sources/CryptoBoringWrapper/CryptoKitErrors_boring.swift index 81f127b3..6fba42ed 100644 --- a/Sources/CryptoBoringWrapper/CryptoKitErrors_boring.swift +++ b/Sources/CryptoBoringWrapper/CryptoKitErrors_boring.swift @@ -12,10 +12,11 @@ // //===----------------------------------------------------------------------===// -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL public enum CryptoBoringWrapperError: Error { case underlyingCoreCryptoError(error: Int32) + case incorrectParameterSize } extension CryptoBoringWrapperError { diff --git a/Sources/Crypto/Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift b/Sources/CryptoBoringWrapper/FiniteFieldArithmeticContext.swift similarity index 75% rename from Sources/Crypto/Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift rename to Sources/CryptoBoringWrapper/FiniteFieldArithmeticContext.swift index 4041add5..cded39a5 100644 --- a/Sources/Crypto/Util/BoringSSL/FiniteFieldArithmeticContext_boring.swift +++ b/Sources/CryptoBoringWrapper/FiniteFieldArithmeticContext.swift @@ -11,11 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API -@_exported import CryptoKit -#else -@_implementationOnly import CCryptoBoringSSL -import Foundation +import CCryptoBoringSSL /// A context for performing mathematical operations on ArbitraryPrecisionIntegers over a finite field. /// @@ -28,21 +24,21 @@ import Foundation /// /// Annoyingly, because of the way we have implemented ArbitraryPrecisionInteger, we can't actually use these temporary bignums /// ourselves. -@usableFromInline -class FiniteFieldArithmeticContext { - private var fieldSize: ArbitraryPrecisionInteger - private var bnCtx: OpaquePointer +public final class FiniteFieldArithmeticContext { + /* private but @usableFromInline */ @usableFromInline var fieldSize: ArbitraryPrecisionInteger + /* private but @usableFromInline */ @usableFromInline var bnCtx: OpaquePointer - @usableFromInline - init(fieldSize: ArbitraryPrecisionInteger) throws { + @inlinable + public init(fieldSize: ArbitraryPrecisionInteger) throws { self.fieldSize = fieldSize guard let bnCtx = CCryptoBoringSSL_BN_CTX_new() else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } CCryptoBoringSSL_BN_CTX_start(bnCtx) self.bnCtx = bnCtx } + @inlinable deinit { CCryptoBoringSSL_BN_CTX_end(self.bnCtx) CCryptoBoringSSL_BN_CTX_free(self.bnCtx) @@ -52,8 +48,8 @@ class FiniteFieldArithmeticContext { // MARK: - Arithmetic operations extension FiniteFieldArithmeticContext { - @usableFromInline - func square(_ input: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { + @inlinable + public func square(_ input: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { var output = ArbitraryPrecisionInteger() let rc = input.withUnsafeBignumPointer { inputPointer in @@ -65,14 +61,14 @@ extension FiniteFieldArithmeticContext { } guard rc == 1 else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } return output } - @usableFromInline - func multiply(_ x: ArbitraryPrecisionInteger, _ y: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { + @inlinable + public func multiply(_ x: ArbitraryPrecisionInteger, _ y: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { var output = ArbitraryPrecisionInteger() let rc = x.withUnsafeBignumPointer { xPointer in @@ -86,14 +82,14 @@ extension FiniteFieldArithmeticContext { } guard rc == 1 else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } return output } - @usableFromInline - func add(_ x: ArbitraryPrecisionInteger, _ y: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { + @inlinable + public func add(_ x: ArbitraryPrecisionInteger, _ y: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { var output = ArbitraryPrecisionInteger() let rc = x.withUnsafeBignumPointer { xPointer in @@ -107,14 +103,14 @@ extension FiniteFieldArithmeticContext { } guard rc == 1 else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } return output } - @usableFromInline - func subtract(_ x: ArbitraryPrecisionInteger, from y: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { + @inlinable + public func subtract(_ x: ArbitraryPrecisionInteger, from y: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { var output = ArbitraryPrecisionInteger() let rc = x.withUnsafeBignumPointer { xPointer in @@ -129,14 +125,14 @@ extension FiniteFieldArithmeticContext { } guard rc == 1 else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } return output } - @usableFromInline - func positiveSquareRoot(_ x: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { + @inlinable + public func positiveSquareRoot(_ x: ArbitraryPrecisionInteger) throws -> ArbitraryPrecisionInteger { let outputPointer = x.withUnsafeBignumPointer { xPointer in self.fieldSize.withUnsafeBignumPointer { fieldSizePointer in // We can't pass a pointer in as BN_mod_sqrt may attempt to free it. @@ -145,7 +141,7 @@ extension FiniteFieldArithmeticContext { } guard let actualOutputPointer = outputPointer else { - throw CryptoKitError.internalBoringSSLError() + throw CryptoBoringWrapperError.internalBoringSSLError() } // Ok, we own this pointer now. @@ -156,4 +152,3 @@ extension FiniteFieldArithmeticContext { return try ArbitraryPrecisionInteger(copying: actualOutputPointer) } } -#endif // CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift b/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift index 527a91a3..43b3dd3c 100644 --- a/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift +++ b/Sources/_CryptoExtras/AES/AES_GCM_SIV.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// import Crypto -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims -@_implementationOnly import CryptoBoringWrapper +import CCryptoBoringSSL +import CCryptoBoringSSLShims +import CryptoBoringWrapper #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else diff --git a/Sources/_CryptoExtras/AES/Block Function.swift b/Sources/_CryptoExtras/AES/Block Function.swift index fc1fe23e..6e8c9e41 100644 --- a/Sources/_CryptoExtras/AES/Block Function.swift +++ b/Sources/_CryptoExtras/AES/Block Function.swift @@ -13,9 +13,9 @@ //===----------------------------------------------------------------------===// import Crypto -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims -@_implementationOnly import CryptoBoringWrapper +import CCryptoBoringSSL +import CCryptoBoringSSLShims +import CryptoBoringWrapper import Foundation extension AES { diff --git a/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift b/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift index 8ed5a9ef..084a6871 100644 --- a/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift +++ b/Sources/_CryptoExtras/AES/BoringSSL/AES_CTR_boring.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL import Crypto import Foundation diff --git a/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift b/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift index c291ddd9..72a403c4 100644 --- a/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift +++ b/Sources/_CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift @@ -14,10 +14,10 @@ // This is a copy ChaChaPoly_boring just with a different set aes algos -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Crypto -@_implementationOnly import CryptoBoringWrapper +import CryptoBoringWrapper import Foundation extension BoringSSLAEAD { diff --git a/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift b/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift index 14e2e90a..7d6c9221 100644 --- a/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift +++ b/Sources/_CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift @@ -12,10 +12,10 @@ // //===----------------------------------------------------------------------===// -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Crypto -@_implementationOnly import CryptoBoringWrapper +import CryptoBoringWrapper import Foundation enum OpenSSLChaCha20CTRImpl { diff --git a/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift b/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift index 975010ae..f23d8ccd 100644 --- a/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift +++ b/Sources/_CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift @@ -12,10 +12,10 @@ // //===----------------------------------------------------------------------===// -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims import Crypto -@_implementationOnly import CryptoBoringWrapper +import CryptoBoringWrapper #if canImport(Darwin) || swift(>=5.9.1) import Foundation #else diff --git a/Sources/_CryptoExtras/RSA/RSA_boring.swift b/Sources/_CryptoExtras/RSA/RSA_boring.swift index b4cc1963..0787b6af 100644 --- a/Sources/_CryptoExtras/RSA/RSA_boring.swift +++ b/Sources/_CryptoExtras/RSA/RSA_boring.swift @@ -17,8 +17,8 @@ import Crypto #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API // Nothing; this is implemented in RSA_security #else -@_implementationOnly import CCryptoBoringSSL -@_implementationOnly import CCryptoBoringSSLShims +import CCryptoBoringSSL +import CCryptoBoringSSLShims internal struct BoringSSLRSAPublicKey: Sendable { private var backing: Backing diff --git a/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift b/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift index f43ab4e0..e02b4cd1 100644 --- a/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift +++ b/Sources/_CryptoExtras/Util/BoringSSLHelpers.swift @@ -15,7 +15,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API // This is only used when bulding with BoringSSL. #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL import Foundation import Crypto diff --git a/Sources/_CryptoExtras/Util/CryptoKitErrors_boring.swift b/Sources/_CryptoExtras/Util/CryptoKitErrors_boring.swift index 55b3cb37..d083490f 100644 --- a/Sources/_CryptoExtras/Util/CryptoKitErrors_boring.swift +++ b/Sources/_CryptoExtras/Util/CryptoKitErrors_boring.swift @@ -12,7 +12,7 @@ // //===----------------------------------------------------------------------===// -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL import Crypto extension CryptoKitError { diff --git a/Sources/_CryptoExtras/Util/DigestType.swift b/Sources/_CryptoExtras/Util/DigestType.swift index a0ac2ba8..e9e0d7f3 100644 --- a/Sources/_CryptoExtras/Util/DigestType.swift +++ b/Sources/_CryptoExtras/Util/DigestType.swift @@ -14,7 +14,7 @@ #if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API // Nothing to do in this case #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL import Crypto struct DigestType { diff --git a/Tests/CryptoTests/BoringSSL/ArbitraryPrecisionIntegerTests.swift b/Tests/CryptoBoringWrapperTests/ArbitraryPrecisionIntegerTests.swift similarity index 94% rename from Tests/CryptoTests/BoringSSL/ArbitraryPrecisionIntegerTests.swift rename to Tests/CryptoBoringWrapperTests/ArbitraryPrecisionIntegerTests.swift index bf50dfa3..3ea9a1c6 100644 --- a/Tests/CryptoTests/BoringSSL/ArbitraryPrecisionIntegerTests.swift +++ b/Tests/CryptoBoringWrapperTests/ArbitraryPrecisionIntegerTests.swift @@ -11,9 +11,7 @@ // SPDX-License-Identifier: Apache-2.0 // //===----------------------------------------------------------------------===// -#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API -#else -@testable import Crypto +@testable import CryptoBoringWrapper import XCTest final class ArbitraryPrecisionIntegerTests: XCTestCase { @@ -43,7 +41,7 @@ final class ArbitraryPrecisionIntegerTests: XCTestCase { func testPositiveSquareRoot() { XCTAssertNoThrow(XCTAssertEqual(try ArbitraryPrecisionInteger(144).positiveSquareRoot(), 12)) XCTAssertThrowsError(try ArbitraryPrecisionInteger(101).positiveSquareRoot()) { error in - guard case .some(.underlyingCoreCryptoError) = error as? CryptoKitError else { + guard case .some(.underlyingCoreCryptoError) = error as? CryptoBoringWrapperError else { XCTFail("Unexpected error: \(error)") return } @@ -112,4 +110,3 @@ final class ArbitraryPrecisionIntegerTests: XCTestCase { XCTAssertTrue(two >= two) } } -#endif // CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API diff --git a/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift b/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift index a9c6ab2c..47cc3231 100644 --- a/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift +++ b/Tests/CryptoTests/ECDH/BoringSSL/ASN1.swift @@ -20,7 +20,7 @@ import XCTest #if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @testable import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL @testable import Crypto #endif diff --git a/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift b/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift index df7751b9..e5fbbd0d 100644 --- a/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift +++ b/Tests/CryptoTests/ECDH/BoringSSL/secpECDH_Runner_boring.swift @@ -20,7 +20,7 @@ import XCTest #if !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API @testable import CryptoKit #else -@_implementationOnly import CCryptoBoringSSL +import CCryptoBoringSSL @testable import Crypto #endif