Skip to content

Commit 890595d

Browse files
LukasaYourMJKrnrojosephnoirsimonjbeaumont
authored
Catch-up merge main into wwdc25 branch (#403)
Co-authored-by: YourMJK <37852512+YourMJK@users.noreply.github.com> Co-authored-by: Rick Newton-Rogers <rnro@apple.com> Co-authored-by: Raphael <josephnoir@users.noreply.github.com> Co-authored-by: Si Beaumont <beaumont@apple.com> Co-authored-by: Evan Wilde <ewilde@apple.com> Co-authored-by: Tim Condon <0xTim@users.noreply.github.com> Co-authored-by: Gus Cairo <gus.cairo@apple.com> Co-authored-by: George Barnett <gbarnett@apple.com> Co-authored-by: Fabrice de Gans <Steelskin@users.noreply.github.com> Co-authored-by: Wojciech Nagrodzki <278594+wnagrodzki@users.noreply.github.com> Co-authored-by: Jesse L. Zamora <xtremekforever@gmail.com> Co-authored-by: aryan-25 <aryan_shah@apple.com>
1 parent d9f3641 commit 890595d

File tree

58 files changed

+5548
-767
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5548
-767
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ _[One line description of your change]_
99
- [ ] I've updated the documentation if necessary
1010

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

1414
### Motivation:
1515

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

2222
### Result:
2323

24-
_[After your change, what will change.]_
24+
_[After your change, what will change.]_

.github/workflows/main.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,32 @@ jobs:
1616
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error"
1717
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
1818
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
19+
windows_6_0_enabled: true
20+
windows_6_1_enabled: true
21+
windows_nightly_next_enabled: true
22+
windows_nightly_main_enabled: true
23+
windows_6_0_arguments_override: "--explicit-target-dependency-import-check error"
24+
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
25+
windows_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
26+
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
27+
28+
release-builds:
29+
name: Release builds
30+
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
31+
with:
32+
windows_6_0_enabled: true
33+
windows_6_1_enabled: true
34+
windows_nightly_next_enabled: true
35+
windows_nightly_main_enabled: true
1936

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

41+
static-sdk:
42+
name: Static SDK
43+
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main
44+
2445
macos-tests:
2546
name: macOS tests
2647
uses: apple/swift-nio/.github/workflows/macos_tests.yml@main

.github/workflows/pull_request.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ jobs:
3030
windows_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
3131
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
3232

33+
release-builds:
34+
name: Release builds
35+
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
36+
with:
37+
windows_6_0_enabled: true
38+
windows_6_1_enabled: true
39+
windows_nightly_next_enabled: true
40+
windows_nightly_main_enabled: true
41+
3342
cxx-interop:
3443
name: Cxx interop
3544
uses: apple/swift-nio/.github/workflows/cxx_interop.yml@main
@@ -58,3 +67,7 @@ jobs:
5867
with:
5968
runner_pool: general
6069
build_scheme: swift-crypto-Package
70+
71+
static-sdk:
72+
name: Static SDK
73+
uses: apple/swift-nio/.github/workflows/static_sdk.yml@main

.swiftformatignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ Sources/_CryptoExtras/OPRFs/VOPRFClient.swift
100100
Sources/_CryptoExtras/OPRFs/VOPRFServer.swift
101101
Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift
102102
Sources/_CryptoExtras/RSA/RSA.swift
103-
Sources/_CryptoExtras/RSA/RSA_security.swift
104103
Sources/_CryptoExtras/Util/BoringSSLHelpers.swift
105104
Sources/_CryptoExtras/Util/DigestType.swift
106105
Sources/_CryptoExtras/Util/Error.swift

Benchmarks/Benchmarks/Benchmarks.swift

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,65 @@ import Foundation
2424
let benchmarks = {
2525
let defaultMetrics: [BenchmarkMetric] = [.mallocCountTotal, .cpuTotal]
2626

27+
Benchmark(
28+
"arc-issue-p256",
29+
configuration: Benchmark.Configuration(
30+
metrics: defaultMetrics,
31+
scalingFactor: .kilo,
32+
maxDuration: .seconds(10_000_000),
33+
maxIterations: 3
34+
)
35+
) { benchmark in
36+
let privateKey = P256._ARCV1.PrivateKey()
37+
let publicKey = privateKey.publicKey
38+
let requestContext = Data("shared request context".utf8)
39+
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
40+
let credentialRequest = precredential.credentialRequest
41+
42+
benchmark.startMeasurement()
43+
44+
for _ in benchmark.scaledIterations {
45+
blackHole(try privateKey.issue(credentialRequest))
46+
}
47+
}
48+
49+
Benchmark(
50+
"arc-verify-p256",
51+
configuration: Benchmark.Configuration(
52+
metrics: defaultMetrics,
53+
scalingFactor: .kilo,
54+
maxDuration: .seconds(10_000_000),
55+
maxIterations: 10
56+
)
57+
) { benchmark in
58+
let privateKey = P256._ARCV1.PrivateKey()
59+
let publicKey = privateKey.publicKey
60+
let requestContext = Data("shared request context".utf8)
61+
let (presentationContext, presentationLimit) = (Data("shared presentation context".utf8), 2)
62+
let precredential = try publicKey.prepareCredentialRequest(requestContext: requestContext)
63+
let credentialRequest = precredential.credentialRequest
64+
let credentialResponse = try privateKey.issue(credentialRequest)
65+
var credential = try publicKey.finalize(credentialResponse, for: precredential)
66+
let (presentation, nonce) = try credential.makePresentation(
67+
context: presentationContext,
68+
presentationLimit: presentationLimit
69+
)
70+
71+
benchmark.startMeasurement()
72+
73+
for _ in benchmark.scaledIterations {
74+
blackHole(
75+
try privateKey.verify(
76+
presentation,
77+
requestContext: requestContext,
78+
presentationContext: presentationContext,
79+
presentationLimit: presentationLimit,
80+
nonce: nonce
81+
)
82+
)
83+
}
84+
}
85+
2786
Benchmark(
2887
"arc-issue-p384",
2988
configuration: Benchmark.Configuration(
@@ -104,4 +163,49 @@ let benchmarks = {
104163
blackHole(try privateKey.evaluate(blindedElement))
105164
}
106165
}
166+
167+
Benchmark(
168+
"key-exchange-p256",
169+
configuration: Benchmark.Configuration(
170+
metrics: defaultMetrics,
171+
scalingFactor: .kilo,
172+
maxDuration: .seconds(10_000_000),
173+
maxIterations: 10
174+
)
175+
) { benchmark in
176+
for _ in benchmark.scaledIterations {
177+
let (key1, key2) = (P256.KeyAgreement.PrivateKey(), P256.KeyAgreement.PrivateKey())
178+
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
179+
}
180+
}
181+
182+
Benchmark(
183+
"key-exchange-p384",
184+
configuration: Benchmark.Configuration(
185+
metrics: defaultMetrics,
186+
scalingFactor: .kilo,
187+
maxDuration: .seconds(10_000_000),
188+
maxIterations: 10
189+
)
190+
) { benchmark in
191+
for _ in benchmark.scaledIterations {
192+
let (key1, key2) = (P384.KeyAgreement.PrivateKey(), P384.KeyAgreement.PrivateKey())
193+
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
194+
}
195+
}
196+
197+
Benchmark(
198+
"key-exchange-p521",
199+
configuration: Benchmark.Configuration(
200+
metrics: defaultMetrics,
201+
scalingFactor: .kilo,
202+
maxDuration: .seconds(10_000_000),
203+
maxIterations: 10
204+
)
205+
) { benchmark in
206+
for _ in benchmark.scaledIterations {
207+
let (key1, key2) = (P521.KeyAgreement.PrivateKey(), P521.KeyAgreement.PrivateKey())
208+
blackHole(try key1.sharedSecretFromKeyAgreement(with: key2.publicKey))
209+
}
210+
}
107211
}

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
cmake_minimum_required(VERSION 3.15.1)
1616

17+
if(POLICY CMP0157)
18+
cmake_policy(SET CMP0157 NEW)
19+
endif()
20+
1721
project(SwiftCrypto
1822
LANGUAGES ASM C CXX Swift)
1923

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

54+
set(CMAKE_CXX_STANDARD 17)
55+
if(CMAKE_SYSTEM_NAME STREQUAL Windows)
56+
# We need to ensure that we don't include the min/max macros from the Windows SDK.
57+
add_compile_definitions(NOMINMAX)
58+
# We can only link against the DLL version of the MSVC runtime library for now.
59+
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreadedDLL")
60+
if(CMAKE_Swift_COMPILER_VERSION VERSION_EQUAL 0.0.0 OR CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 6.2)
61+
# We need to set the static library prefix to "lib" so that we can link against the static libraries.
62+
set(CMAKE_STATIC_LIBRARY_PREFIX_Swift "lib")
63+
endif()
64+
endif()
65+
5066
if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
5167
find_package(dispatch CONFIG)
5268
find_package(Foundation CONFIG)

NOTICE.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ This product contains test vectors from Google's wycheproof project.
3434

3535
---
3636

37-
This product contains a derivation of various scripts from SwiftNIO.
37+
This product contains a derivation of various files from SwiftNIO.
3838

3939
* LICENSE (Apache License 2.0):
4040
* https://www.apache.org/licenses/LICENSE-2.0

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ let package = Package(
102102
name: "CCryptoBoringSSL",
103103
exclude: privacyManifestExclude + [
104104
"hash.txt",
105-
"include/boringssl_prefix_symbols_nasm.inc",
106105
"CMakeLists.txt",
107106
/*
108107
* These files are excluded to support WASI libc which doesn't provide <netdb.h>.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Swift Crypto
22

3-
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.
3+
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.
44

55
## Using Swift Crypto
66

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

2929
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.
3030

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

3333
1. A vendored copy of BoringSSL's libcrypto.
3434
2. The common API of Swift Crypto and CryptoKit.
@@ -129,7 +129,7 @@ What this means for you is that you should depend on Swift Crypto with a version
129129
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.
130130
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.
131131

132-
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.
132+
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.
133133

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

Sources/CCryptoBoringSSL/CMakeLists.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,27 @@ elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTE
342342
gen/bcm/vpaes-armv8-linux.S
343343
gen/crypto/chacha-armv8-linux.S
344344
gen/crypto/chacha20_poly1305_armv8-linux.S)
345+
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "AMD64|amd64|x86_64")
346+
target_sources(CCryptoBoringSSL PRIVATE
347+
)
348+
elseif(CMAKE_SYSTEM_NAME MATCHES "Windows" AND CMAKE_SYSTEM_PROCESSOR MATCHES "ARM64|arm64|aarch64")
349+
target_sources(CCryptoBoringSSL PRIVATE
350+
gen/bcm/aesv8-armv8-win.S
351+
gen/bcm/aesv8-gcm-armv8-win.S
352+
gen/bcm/armv8-mont-win.S
353+
gen/bcm/bn-armv8-win.S
354+
gen/bcm/ghash-neon-armv8-win.S
355+
gen/bcm/ghashv8-armv8-win.S
356+
gen/bcm/p256-armv8-asm-win.S
357+
gen/bcm/p256_beeu-armv8-asm-win.S
358+
gen/bcm/sha1-armv8-win.S
359+
gen/bcm/sha256-armv8-win.S
360+
gen/bcm/sha512-armv8-win.S
361+
gen/bcm/vpaes-armv8-win.S
362+
gen/crypto/chacha-armv8-win.S
363+
gen/crypto/chacha20_poly1305_armv8-win.S)
345364
else()
346-
message(FATAL_ERROR "platform sources are not defined here")
365+
message(FATAL_ERROR "platform sources are not defined here for ${CMAKE_SYSTEM_NAME} on ${CMAKE_SYSTEM_PROCESSOR}")
347366
endif()
348367

349368
target_include_directories(CCryptoBoringSSL PUBLIC

0 commit comments

Comments
 (0)