Skip to content

Commit 9fb2fd8

Browse files
josephnoirLukasa
andauthored
Remove security backend (#373)
### Motivation: Depending on the platform Swift Crypto Extras might use an implementation backed by `Security.framework`, specifically for RSA. Since BoringSSL is a necessary dependency on all platforms, we can deduplicate the implementation and keep a single backend. ### Modifications: Remove the `Security.framework` implementation and tie the RSA backend to BoringSSL. ### Result: Swift Crypto Extras always uses the BoringSSL backend for RSA. --------- Co-authored-by: Cory Benfield <lukasa@apple.com>
1 parent 4ce1b9b commit 9fb2fd8

File tree

4 files changed

+4
-521
lines changed

4 files changed

+4
-521
lines changed

.swiftformatignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ Sources/_CryptoExtras/OPRFs/VOPRFClient.swift
9494
Sources/_CryptoExtras/OPRFs/VOPRFServer.swift
9595
Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift
9696
Sources/_CryptoExtras/RSA/RSA.swift
97-
Sources/_CryptoExtras/RSA/RSA_security.swift
9897
Sources/_CryptoExtras/Util/BoringSSLHelpers.swift
9998
Sources/_CryptoExtras/Util/DigestType.swift
10099
Sources/_CryptoExtras/Util/Error.swift

Sources/_CryptoExtras/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ add_library(_CryptoExtras
5656
"RSA/RSA+BlindSigning.swift"
5757
"RSA/RSA.swift"
5858
"RSA/RSA_boring.swift"
59-
"RSA/RSA_security.swift"
6059
"Util/BoringSSLHelpers.swift"
6160
"Util/CryptoKitErrors_boring.swift"
6261
"Util/Data+Extensions.swift"

Sources/_CryptoExtras/RSA/RSA.swift

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,10 @@ import Crypto
1616
import CryptoBoringWrapper
1717
import SwiftASN1
1818

19-
#if CRYPTO_IN_SWIFTPM && !CRYPTO_IN_SWIFTPM_FORCE_BUILD_API
20-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
21-
fileprivate typealias BackingPublicKey = SecurityRSAPublicKey
22-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
23-
fileprivate typealias BackingPrivateKey = SecurityRSAPrivateKey
24-
#else
2519
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
2620
fileprivate typealias BackingPublicKey = BoringSSLRSAPublicKey
2721
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
2822
fileprivate typealias BackingPrivateKey = BoringSSLRSAPrivateKey
29-
#endif
3023

3124
/// Types associated with the RSA algorithm
3225
///
@@ -120,14 +113,8 @@ extension _RSA.Signing {
120113
}
121114

122115
/// Construct an RSA public key with the specified parameters.
123-
///
124-
/// Only the BoringSSL backend provides APIs to create a key from its parameters so we first create a BoringSSL
125-
/// key, and then pass it to the platform-specific initializer that accepts a BoringSSL key.
126-
///
127-
/// On Darwin platforms, this will serialize it to PEM format, and then construct a platform-specific key from
128-
/// the PEM representation.
129116
public init(n: some ContiguousBytes, e: some ContiguousBytes) throws {
130-
self.backing = try BackingPublicKey(BoringSSLRSAPublicKey(n: n, e: e))
117+
self.backing = try BackingPublicKey(n: n, e: e)
131118
}
132119

133120
public var pkcs1DERRepresentation: Data {
@@ -218,14 +205,8 @@ extension _RSA.Signing {
218205
}
219206

220207
/// Construct an RSA private key with the specified parameters.
221-
///
222-
/// Only the BoringSSL backend provides APIs to create a key from its parameters so we first create a BoringSSL
223-
/// key, and then pass it to the platform-specific initializer that accepts a BoringSSL key.
224-
///
225-
/// On Darwin platforms, this will serialize it to DER format, and then construct a platform-specific key from
226-
/// the DER representation.
227208
public init(n: some ContiguousBytes, e: some ContiguousBytes, d: some ContiguousBytes, p: some ContiguousBytes, q: some ContiguousBytes) throws {
228-
self.backing = try BackingPrivateKey(BoringSSLRSAPrivateKey(n: n, e: e, d: d, p: p, q: q))
209+
self.backing = try BackingPrivateKey(n: n, e: e, d: d, p: p, q: q)
229210
}
230211

231212
/// Randomly generate a new RSA private key of a given size.
@@ -546,14 +527,8 @@ extension _RSA.Encryption {
546527
}
547528

548529
/// Construct an RSA public key with the specified parameters.
549-
///
550-
/// Only the BoringSSL backend provides APIs to create a key from its parameters so we first create a BoringSSL
551-
/// key, and then pass it to the platform-specific initializer that accepts a BoringSSL key.
552-
///
553-
/// On Darwin platforms, this will serialize it to DER format, and then construct a platform-specific key from
554-
/// the DER representation.
555530
public init(n: some ContiguousBytes, e: some ContiguousBytes) throws {
556-
self.backing = try BackingPublicKey(BoringSSLRSAPublicKey(n: n, e: e))
531+
self.backing = try BackingPublicKey(n: n, e: e)
557532
}
558533

559534
public var pkcs1DERRepresentation: Data { self.backing.pkcs1DERRepresentation }
@@ -614,14 +589,8 @@ extension _RSA.Encryption {
614589

615590

616591
/// Construct an RSA private key with the specified parameters.
617-
///
618-
/// Only the BoringSSL backend provides APIs to create a key from its parameters so we first create a BoringSSL
619-
/// key, and then pass it to the platform-specific initializer that accepts a BoringSSL key.
620-
///
621-
/// On Darwin platforms, this will serialize it to PEM format, and then construct a platform-specific key from
622-
/// the PEM representation.
623592
public init(n: some ContiguousBytes, e: some ContiguousBytes, d: some ContiguousBytes, p: some ContiguousBytes, q: some ContiguousBytes) throws {
624-
self.backing = try BackingPrivateKey(BoringSSLRSAPrivateKey(n: n, e: e, d: d, p: p, q: q))
593+
self.backing = try BackingPrivateKey(n: n, e: e, d: d, p: p, q: q)
625594
}
626595

627596
/// Randomly generate a new RSA private key of a given size.

0 commit comments

Comments
 (0)