Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
46eca5f
Fix typo in documentation for RSA private key constructors (#362)
YourMJK Jun 16, 2025
dbb4559
Make EllipticCurvePoint and ArbitraryPrecisionInteger Sendable (#366)
Lukasa Jun 19, 2025
6214426
Add static SDK CI workflow (#340)
rnro Jun 26, 2025
7416764
Enable Windows CI on main (#371)
Lukasa Jun 27, 2025
4ce1b9b
Add a PKCS#8 DER property to private keys (#372)
josephnoir Jul 2, 2025
9fb2fd8
Remove security backend (#373)
josephnoir Jul 2, 2025
93a2ebf
Add API for ARC(P-256) and deprecate ARC(P-384) (#374)
simonjbeaumont Jul 2, 2025
af6be72
CMake: Declare ASN1 dependency (#376)
etcwilde Jul 3, 2025
871f95d
Typealias CryptoKitError (#285)
0xTim Jul 7, 2025
e5f10a7
Mention Windows in README (#378)
gjcairo Jul 15, 2025
75475b8
Back out changes post-quantum changes for release (#379)
glbrntt Jul 21, 2025
9934678
build: Make swift-crypto build on Windows (#370)
Steelskin Jul 21, 2025
88b9c9b
Work around Swift compiler issue with consuming and TSAN (#384)
Lukasa Jul 22, 2025
84b1d49
Add a few more inlinability annotation (#383)
glbrntt Jul 22, 2025
64a4de0
Add some benchmarks for EC key agreement (#390)
Lukasa Jul 30, 2025
176abc2
Cache curves to avoid repeatedly reallocating state (#391)
Lukasa Jul 30, 2025
8c9d27a
Enable release mode builds in CI (#388)
josephnoir Jul 30, 2025
c68a7a7
Add Sequence conformance to AES._CBC.IV (#389) (#392)
wnagrodzki Jul 31, 2025
334e682
Add AES CMAC support (#394)
Lukasa Aug 5, 2025
2347f20
Use Thread.threadDictionary instead of TaskLocal for thread-local (#395)
simonjbeaumont Aug 8, 2025
c066b05
Improve vendor-boringssl.sh script to make it work better (#396)
xtremekforever Aug 11, 2025
b7c303d
Use Swift SDKs to generate symbols for Linux targets and armv7 (using…
xtremekforever Aug 15, 2025
d1c6b70
Avoid TSAN issue in _CryptoExtras/AES/CMAC (#402)
aryan-25 Aug 27, 2025
143c896
Catch-up merge main into wwdc25 branch
Lukasa Aug 29, 2025
2b7be8b
Fix merge error
Lukasa Aug 29, 2025
c462502
Move away from Foundation.Thread (#404)
Lukasa Sep 9, 2025
0e02512
Merge remote-tracking branch 'origin/main' into cb-catchup-merge-2025…
Lukasa Sep 9, 2025
a519b5d
Re-add accidentally deleted files
Lukasa Sep 9, 2025
9552067
Fix script path in PR template (#408)
0xTim Sep 9, 2025
141f5b4
Make the tests Swift 6 ready. (#409)
Lukasa Sep 9, 2025
2e6518c
Merge remote-tracking branch 'origin/main' into cb-catchup-merge-2025…
Lukasa Sep 9, 2025
0717f67
Speculative fix to get Sendable warnings solved in Xcode 16.2
Lukasa Sep 9, 2025
6e36370
Appease the formatter
Lukasa Sep 9, 2025
0bb59c8
Formatter finally appeased
Lukasa Sep 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _[One line description of your change]_
- [ ] I've updated the documentation if necessary

#### If you've made changes to `gyb` files
- [ ] I've run `.script/generate_boilerplate_files_with_gyb` and included updated generated files in a commit of this pull request
- [ ] I've run `./scripts/generate_boilerplate_files_with_gyb.sh` and included updated generated files in a commit of this pull request

### Motivation:

Expand All @@ -21,4 +21,4 @@ _[Describe the modifications you've done.]_

### Result:

_[After your change, what will change.]_
_[After your change, what will change.]_
21 changes: 21 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,32 @@ jobs:
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
windows_6_0_enabled: true
windows_6_1_enabled: true
windows_nightly_next_enabled: true
windows_nightly_main_enabled: true
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
windows_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"

release-builds:
name: Release builds
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
with:
windows_6_0_enabled: true
windows_6_1_enabled: true
windows_nightly_next_enabled: true
windows_nightly_main_enabled: true

cxx-interop:
name: Cxx interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main

static-sdk:
name: Static SDK
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main

macos-tests:
name: macOS tests
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main
Expand Down
13 changes: 13 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ jobs:
windows_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"

release-builds:
name: Release builds
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
with:
windows_6_0_enabled: true
windows_6_1_enabled: true
windows_nightly_next_enabled: true
windows_nightly_main_enabled: true

cxx-interop:
name: Cxx interop
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
Expand Down Expand Up @@ -58,3 +67,7 @@ jobs:
with:
runner_pool: general
build_scheme: swift-crypto-Package

static-sdk:
name: Static SDK
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
1 change: 0 additions & 1 deletion .swiftformatignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ Sources/_CryptoExtras/OPRFs/VOPRFClient.swift
Sources/_CryptoExtras/OPRFs/VOPRFServer.swift
Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift
Sources/_CryptoExtras/RSA/RSA.swift
Sources/_CryptoExtras/RSA/RSA_security.swift
Sources/_CryptoExtras/Util/BoringSSLHelpers.swift
Sources/_CryptoExtras/Util/DigestType.swift
Sources/_CryptoExtras/Util/Error.swift
Expand Down
104 changes: 104 additions & 0 deletions Benchmarks/Benchmarks/Benchmarks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,65 @@ import Foundation
let benchmarks = {
let defaultMetrics: [BenchmarkMetric] = [.mallocCountTotal, .cpuTotal]

Benchmark(
"arc-issue-p256",
configuration: Benchmark.Configuration(
metrics: defaultMetrics,
scalingFactor: .kilo,
maxDuration: .seconds(10_000_000),
maxIterations: 3
)
) { benchmark in
let privateKey = P256._ARCV1.PrivateKey()
let publicKey = privateKey.publicKey
let requestContext = Data("shared request context".utf8)
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
let credentialRequest = precredential.credentialRequest

benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(try privateKey.issue(credentialRequest))
}
}

Benchmark(
"arc-verify-p256",
configuration: Benchmark.Configuration(
metrics: defaultMetrics,
scalingFactor: .kilo,
maxDuration: .seconds(10_000_000),
maxIterations: 10
)
) { benchmark in
let privateKey = P256._ARCV1.PrivateKey()
let publicKey = privateKey.publicKey
let requestContext = Data("shared request context".utf8)
let (presentationContext, presentationLimit) = (Data("shared presentation context".utf8), 2)
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
let credentialRequest = precredential.credentialRequest
let credentialResponse = try privateKey.issue(credentialRequest)
var credential = try publicKey.finalize(credentialResponse, for: precredential)
let (presentation, nonce) = try credential.makePresentation(
context: presentationContext,
presentationLimit: presentationLimit
)

benchmark.startMeasurement()

for _ in benchmark.scaledIterations {
blackHole(
try privateKey.verify(
presentation,
requestContext: requestContext,
presentationContext: presentationContext,
presentationLimit: presentationLimit,
nonce: nonce
)
)
}
}

Benchmark(
"arc-issue-p384",
configuration: Benchmark.Configuration(
Expand Down Expand Up @@ -104,4 +163,49 @@ let benchmarks = {
blackHole(try privateKey.evaluate(blindedElement))
}
}

Benchmark(
"key-exchange-p256",
configuration: Benchmark.Configuration(
metrics: defaultMetrics,
scalingFactor: .kilo,
maxDuration: .seconds(10_000_000),
maxIterations: 10
)
) { benchmark in
for _ in benchmark.scaledIterations {
let (key1, key2) = (P256.KeyAgreement.PrivateKey(), P256.KeyAgreement.PrivateKey())
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
}
}

Benchmark(
"key-exchange-p384",
configuration: Benchmark.Configuration(
metrics: defaultMetrics,
scalingFactor: .kilo,
maxDuration: .seconds(10_000_000),
maxIterations: 10
)
) { benchmark in
for _ in benchmark.scaledIterations {
let (key1, key2) = (P384.KeyAgreement.PrivateKey(), P384.KeyAgreement.PrivateKey())
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
}
}

Benchmark(
"key-exchange-p521",
configuration: Benchmark.Configuration(
metrics: defaultMetrics,
scalingFactor: .kilo,
maxDuration: .seconds(10_000_000),
maxIterations: 10
)
) { benchmark in
for _ in benchmark.scaledIterations {
let (key1, key2) = (P521.KeyAgreement.PrivateKey(), P521.KeyAgreement.PrivateKey())
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
}
}
}
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@

cmake_minimum_required(VERSION 3.15.1)

if(POLICY CMP0157)
cmake_policy(SET CMP0157 NEW)
endif()

project(SwiftCrypto
LANGUAGES ASM C CXX Swift)

Expand Down Expand Up @@ -47,6 +51,18 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND NOT CMAKE_CROSSCOMPILING)
set(CMAKE_RANLIB "/usr/bin/ranlib")
endif()

set(CMAKE_CXX_STANDARD 17)
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
# We need to ensure that we don't include the min/max macros from the Windows SDK.
add_compile_definitions(NOMINMAX)
# We can only link against the DLL version of the MSVC runtime library for now.
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
# We need to set the static library prefix to "lib" so that we can link against the static libraries.
set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib")
endif()
endif()

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
find_package(dispatch CONFIG)
find_package(Foundation CONFIG)
Expand Down
2 changes: 1 addition & 1 deletion NOTICE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ This product contains test vectors from Google's wycheproof project.

---

This product contains a derivation of various scripts from SwiftNIO.
This product contains a derivation of various files from SwiftNIO.

* LICENSE (Apache License 2.0):
* https://www.apache.org/licenses/LICENSE-2.0
Expand Down
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ let package = Package(
name: "CCryptoBoringSSL",
exclude: privacyManifestExclude + [
"hash.txt",
"include/boringssl_prefix_symbols_nasm.inc",
"CMakeLists.txt",
/*
* These files are excluded to support WASI libc which doesn't provide <netdb.h>.
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Swift Crypto

Swift Crypto is an open-source implementation of a substantial portion of the API of [Apple CryptoKit](https://developer.apple.com/documentation/cryptokit) suitable for use on Linux platforms. It enables cross-platform or server applications with the advantages of CryptoKit.
Swift Crypto is an open-source implementation of a substantial portion of the API of [Apple CryptoKit](https://developer.apple.com/documentation/cryptokit) suitable for use on Linux and ARM64 Windows platforms. It enables cross-platform or server applications with the advantages of CryptoKit.

## Using Swift Crypto

Expand Down Expand Up @@ -28,7 +28,7 @@ Swift Crypto compiles in two distinct modes depending on the platform for which

When building Swift Crypto for use on an Apple platform where CryptoKit is already available, Swift Crypto compiles its entire API surface down to nothing and simply re-exports the API of CryptoKit. This means that when using Apple platforms Swift Crypto simply delegates all work to the core implementation of CryptoKit, as though Swift Crypto was not even there.

When building Swift Crypto for use on Linux, Swift Crypto builds substantially more code. In particular, we build:
When building Swift Crypto for use on Linux or Windows, Swift Crypto builds substantially more code. In particular, we build:

1. A vendored copy of BoringSSL's libcrypto.
2. The common API of Swift Crypto and CryptoKit.
Expand Down Expand Up @@ -129,7 +129,7 @@ What this means for you is that you should depend on Swift Crypto with a version
In SwiftPM that can be easily done specifying for example `from: "1.0.0"` meaning that you support Swift Crypto in every version starting from 1.0.0 up to (excluding) 2.0.0.
SemVer and Swift Crypto's Public API guarantees should result in a working program without having to worry about testing every single version for compatibility.

Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoKitError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think some find-replace went a little off here.

Suggested change
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoKitError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.


To do so, please use the following dependency in your `Package.swift`:

Expand Down
21 changes: 20 additions & 1 deletion Sources/CCryptoBoringSSL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,27 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTE
gen/bcm/vpaes-armv8-linux.S
gen/crypto/chacha-armv8-linux.S
gen/crypto/chacha20_poly1305_armv8-linux.S)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64")
target_sources(CCryptoBoringSSL PRIVATE
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|arm64|aarch64")
target_sources(CCryptoBoringSSL PRIVATE
gen/bcm/aesv8-armv8-win.S
gen/bcm/aesv8-gcm-armv8-win.S
gen/bcm/armv8-mont-win.S
gen/bcm/bn-armv8-win.S
gen/bcm/ghash-neon-armv8-win.S
gen/bcm/ghashv8-armv8-win.S
gen/bcm/p256-armv8-asm-win.S
gen/bcm/p256_beeu-armv8-asm-win.S
gen/bcm/sha1-armv8-win.S
gen/bcm/sha256-armv8-win.S
gen/bcm/sha512-armv8-win.S
gen/bcm/vpaes-armv8-win.S
gen/crypto/chacha-armv8-win.S
gen/crypto/chacha20_poly1305_armv8-win.S)
else()
message(FATAL_ERROR "platform sources are not defined here")
message(FATAL_ERROR "platform sources are not defined here for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
endif()

target_include_directories(CCryptoBoringSSL PUBLIC
Expand Down
Loading
Loading