Skip to content

Commit

Permalink
Move ArbitraryPrecisionInteger type to CryptoBoringWrapper module (#236)
Browse files Browse the repository at this point in the history
* 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 e02700e.

* Fix CMakeLists.txt

* Make most public symbols @inlinable

---------

Co-authored-by: Cory Benfield <[email protected]>
  • Loading branch information
simonjbeaumont and Lukasa authored Jun 21, 2024
1 parent 5fb3819 commit a3866d4
Show file tree
Hide file tree
Showing 35 changed files with 150 additions and 147 deletions.
1 change: 1 addition & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ let package = Package(
swiftSettings: swiftSettings
),
.testTarget(name: "_CryptoExtrasTests", dependencies: ["_CryptoExtras"]),
.testTarget(name: "CryptoBoringWrapperTests", dependencies: ["CryptoBoringWrapper"]),
],
cxxLanguageStandard: .cxx11
)
4 changes: 2 additions & 2 deletions Sources/Crypto/AEADs/AES/GCM/BoringSSL/AES-GCM_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions Sources/Crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion Sources/Crypto/Digests/BoringSSL/Digest_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Crypto/Key Agreement/BoringSSL/ECDH_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion Sources/Crypto/Keys/EC/BoringSSL/EllipticCurve_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 3 additions & 2 deletions Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Crypto/Signatures/BoringSSL/ECDSA_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Crypto/Util/BoringSSL/CryptoKitErrors_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Sources/Crypto/Util/BoringSSL/Zeroization_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
//===----------------------------------------------------------------------===//
#if !canImport(Darwin)
@_implementationOnly import CCryptoBoringSSL
import CCryptoBoringSSL

typealias errno_t = CInt

Expand Down
4 changes: 2 additions & 2 deletions Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
//
//===----------------------------------------------------------------------===//

@_implementationOnly import CCryptoBoringSSL
@_implementationOnly import CCryptoBoringSSLShims
import CCryptoBoringSSL
import CCryptoBoringSSLShims
import Foundation

/// An abstraction over a BoringSSL AEAD
Expand Down
Loading

0 comments on commit a3866d4

Please sign in to comment.