### Motivation:
The comment we have in our package manifest was a bit ambiguous about
Foundation linking and caused some confusion (reported in #496). As
discussed on that issue, I don't think there's anything we want to do
differently here, but we can try and improve the comment so other
adopters don't waste time on a misunderstanding.
### Modifications:
Clarify the privacy manifest comment in the package manifest.
### Result:
Fixes#496.
## Motivation
Xcode 27 is now available[^1] so it's time to merge in our 5.x branch to
main and release 5.0.
## Modifications
See "Release Notes" section below for overview of changes and links to
the PRs that landed on the 5.x branch during the beta period.
## Result
The main branch will be ready to tag a 5.0 release.
[^1]: https://developer.apple.com/download/all/?q=Xcode%2027
---
## Release Notes
Swift Crypto 5.0 aligns the cross-platform API surface with CryptoKit as
shipped in Xcode 27 (CryptoKit-383.2.1), and takes the opportunity to
streamline the package for both adopters and maintainers.
Most users will be able to depend on the 1.0.0, 2.0.0, 3.0.0, 4.0.0, or
5.0.0 series of releases.
To do so, please use the following dependency in your `Package.swift`:
```swift
.package(url: "https://github.com/apple/swift-crypto.git", "1.0.0" ..< "6.0.0"),
```
### Requires Swift 6.2
The package now declares 6.2 as the minimum Swift version in its package
manifest.
### New span-based API
CryptoKit's new non-allocating, span-based entry points are now
available cross-platform:
- `SymmetricKey` gains `bytes: RawSpan`, `init(copying: RawSpan)`,
`init(copyingWithZeroing: inout MutableRawSpan)`, and
`init(size:initializingWith:)` which initializes the key through an
`inout OutputRawSpan`.
- `HashFunction` gains `update(bytes: RawSpan)` and `hash(bytes:
RawSpan)`, and `Digest` gains `init?(copying: RawSpan)`.
- `HMAC` gains `authenticationCode(for: RawSpan, using:)`.
- `HKDF` gains `deriveKey(inputKeyMaterial:salt:info:output:)` writing
into an `inout OutputRawSpan`, along with span-based `extract` and
`expand`. The existing `DataProtocol` overload now has a fast path for
contiguous salt and info.
- `AES.GCM` and `ChaChaPoly` gain in-place
`seal(inPlace:using:nonce:authenticating:tag:)` and
`open(inPlace:using:nonce:authenticating:tag:)` over `MutableRawSpan`,
and their `Nonce` types gain `bytes: RawSpan` and `init(copying:
RawSpan)`.
### Single-use KEM keys
A new `KEMOneTimePrivateKey` protocol, refining `~Copyable` and
`Sendable`, provides a `consuming func decapsulate(_:)` so a
decapsulation key cannot be reused. Conforming types are
`MLKEM768.OneTimePrivateKey`, `MLKEM1024.OneTimePrivateKey`, and
`XWingMLKEM768X25519.OneTimePrivateKey`.
### Extensible enums
Historically Swift Crypto needed a new major version each time CryptoKit
added a case to a non-frozen enum, because Swift Crypto is not built
with library evolution. All public non-frozen enums are now marked
`@nonexhaustive` (SE-0487), which should remove that reason for future
major bumps. Adopters who do not switch over these enums should not need
to widen their version constraints again.
### Other changes
- Symbols that were previously marked `@_spi(...) public` have been made
internal; they were never intended to be available.
- `@available` annotations have been removed from `Crypto`; they are
unused in all supported compilation modes.
- Some internal reference types are now marked `final`
- Some unused code, e.g. `ECDSASignature.derBytes`, is removed.
### Build and packaging
- The `CCryptoBoringSSLShims` target is removed, along with all
`bindMemory(to:)` calls.
- The `.gyb` templates for nonces, digests, ECDH, ECDSA, MLDSA, and
MLKEM are removed and the generated Swift is checked in. The BoringSSL
backend templates for MLDSA and MLKEM remain.
- Conditional compilation is simplified to `#if canImport(CryptoKit)`;
branches that could never be taken are gone.
- Developing the BoringSSL backend on macOS is no longer supported. Use
the Dev Container configuration now shipped in the repository, or build
on the target platform.
- Warnings are silenced for vendored C sources: `-Wshorten-64-to-32` for
BoringSSL and `macro-redefined` for XKCP. CI builds with
`-warnings-as-errors`.
### Commits
The changes in this release were reviewed and merged to the 5.x branch
during the beta period:
- 0a26a9e3 [5.x] Align with CryptoKit APIs from Xcode 27 beta 1 (#442)
- 8ee9962f [5.x] Align with CryptoKit APIs from Xcode 27 beta 2 (#444)
- ce8db476 [5.x] Align with CryptoKit APIs from Xcode 27 beta 4 (#453)
- 15b0fb5b [5.x] Adopt CheckImplementationOnly and CI with
-warnings-as-errors (#454)
- b3746b14 [5.x] Remove bindMemory(to:) calls and the
CCryptoBoringSSLShims target (#455)
- 57782dc6 [5.x] Remove duplicate imports from gyb-generated MLDSA
backend code (#458)
- 2c45ca2f [5.x] Remove unused internal code path:
ECDSASignature.derBytes (#457)
- 33785f67 [5.x] Mark some class types as final (#456)
- 2e074efb [5.x] Remove native SwiftPM build-system workaround in CI
(#461)
- 20f90497 [5.x] Align with CryptoKit from Xcode 27 beta 6 (#462)
---------
Co-authored-by: Dmitry <45711841+darkdi@users.noreply.github.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
Swift 6.0 is no longer supported, we should bump the tools version and
remove it from our CI.
Modifications:
* Bump the Swift tools version to Swift 6.1
* Remove Swift 6.0 jobs where appropriate in main.yml, pull_request.yml
Result:
Code reflects our support window.
Fix multiple issues in the BoringSSL vendoring script and update
BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6
### Checklist
- [x] I've run tests to see all new and existing tests pass
- [x] I've followed the code style of the rest of the project
- [x] I've read the [Contribution Guidelines](CONTRIBUTING.md)
- [x] I've updated the documentation if necessary
### Motivation:
The `vendor-boringssl.sh` script is currently broken in a number of
ways, both in general and relative to the latest BoringSSL version:
- `--enable-test-discovery` is still in use
- The Linux Swift SDKs being generated are out of date (5.10-jammy)
- The script does not prefix exported C++ symbols
- Invoking the script without a `BORINGSSL_REVISION` results in an
unconditional error
- The `PATTERNS` list is out of date for the latest BoringSSL
- The latest BoringSSL contains a bug which fails to apply `extern "C"`
to two exported symbols, allowing for collisions.
In addition, the latest BoringSSL has made `BN_MONT_CTX` opaque,
necessitating that it be referenced with `OpaquePointer` rather than
`UnsafePointer<>`.
### Modifications:
The following changes are included:
- `--enable-test-discovery` has been removed
- `vendor-boringssl.sh` and `generate-linux-sdks.sh` have been updated
to use Swift 6.1.2 SDKs built for Ubuntu Noble
- The `mangle_cpp_structures` function from `swift-nio-ssl`'s version
of `vendor-boringssl.sh` has been copied over (thanks @Lukasa!)
- `BORINGSSL_REVISION` is now allowed to be an empty string
- The `PATTERNS` array has been updated
- A patch has been added which applies `extern "C"` to the functions
which should have it
- `s/UnsafePointer<BN_MONT_CTX>/OpaquePointer/g`
- Updated `CMakeLists.txt` per `update-cmake-lists.sh`
- Update BoringSSL to
`0226f30467f540a3f62ef48d453f93927da199b6`
### Result:
Vendoring the latest BoringSSL will work again.
The latest BoringSSL is vendored.
Updates for the `scripts/vendor-boringssl.h` script that make it a bit
easier to use and ensure you don't accidentally get an update of
BoringSSL you don't want.
### Motivation:
I was working on investigating building a Swift SDK for #223 and ran
into a couple of things that I saw could be improved. Not all need to be
done, but at the very least I feel the boringssl revision lock should be
considered. @Lukasa
### Modifications:
- Add missing invocation of `$sed` in the script- `gsed` was being
invoked instead, although everywhere else `$sed` was used (typo).
- Support locking `BORINGSSL_REVISION` to a specific revision number
through an argument to the script. This way the script can be re-run
without unintentionally upgrading boringssl.
- Remove the non-existent `boringssl_prefix_symbols_nasm.inc` exclude
from the `CCryptoBoringSSL` target. I'm guessing it was there for an
older version of boringssl, but no longer there with the current
revision?
### Result:
The `scripts/vendor_boringssl.sh` script behaves a bit better and can be
run without upgrading the boringssl version unless explicitly desired.
This patch updates BoringSSL to
035e720641f385e82c72b7b0a9e1d89e58cb5ed5. As with all of our patch
updates to BoringSSL, this comes in multiple commits. The first contains
the changes to the vendoring script, and the last contains the tweaks to
product code. The middle commit can be ignored for review purposes.
Motivation:
Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.
Modifications:
* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml
Result:
Code reflects our support window.
OpenBSD support.
### Checklist
- [X] I've run tests to see all new and existing tests pass
- [X] I've followed the code style of the rest of the project
- [X] I've read the [Contribution Guidelines](CONTRIBUTING.md)
- [X] I've updated the documentation if necessary (_not necessary_)
#### If you've made changes to `gyb` files
- [X] I've run `.script/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request (_not
applicable_)
### Motivation:
swift-crypto is a required dependency for swift-package-manager, and
must build and run on OpenBSD.
### Modifications:
OpenBSD support for cmake/swiftpm.
* Add to patterns for CMakeLists. Also provide a helpful error so future
porters have a slightly better idea of what might need to be updated.
* Proactively reverse sense in some system name checks so they read as
"if not Darwin". This is likely safer to do here than elsewhere since
there are likely not going to be other platforms for which swift-crypto
already exists.
* Add to Package.swift
ManagedBuffer.capacity is unavailable on OpenBSD.
ManagedBuffer.capacity depends on malloc introspection (e.g.,
`malloc_size`), which is not available on this platform -- and is thus
marked as such.
Here, SecureBytes uses a ManagedBuffer in Backing. We have capacity
tracked in the BackingHeader, and most of the references to the
ManagedBuffer.capacity property can be replaced with references to the
capacity in the header. However, since capacity in the header is marked
as internal which conflicts with some of the @inline functions, so we
must change those to @usableFromInline for the platform as well.
Add conditional for RandomBytes.
Required for tests to build on OpenBSD.
### Result:
swift-crypto builds and runs on OpenBSD.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Minimum deployment versions in package manifests can be problematic for
libraries, because changing them or adding them to an existing package
that doesn't already use them forces SemVer breaking majors.
Furthermore, depending on a new library that specifies minimum
deployment targets would force the adopting library to also have to add
these platforms to its manifest (which would in turn force a major).
This PR removes the platforms stanza from the package manifest and
replaces them with availability guards.
This will allow more packages to use swift-crypto, without forcing them
to mint new majors to support the appropriate platforms.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
This change prepares swift-crypto for use on Windows with CMake and also
the Package.swift for use in the Swift toolchain CI system.
### Checklist
- [X] I've run tests to see all new and existing tests pass
- [X] I've followed the code style of the rest of the project
- [X] I've read the [Contribution Guidelines](CONTRIBUTING.md)
- [X] I've updated the documentation if necessary
#### If you've made changes to `gyb` files
- [X] I've run `.script/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request
### Motivation:
Upgrading swift-crypto from an older version requires that Windows works
properly with CMake, and also SwiftPM.
### Modifications:
Modify the CMakeLists.txt files and the generator script so that it
conditionally adds assembly files for non-Windows platforms. Prepare the
Package.swift file for use in Swift CI pipelines, by consulting an
environment to either use the absolute URL, or a prepared version of the
swift-asn1 dependency.
### Result:
After this change it should be possible to build with the newest
swift-crypto in the Swift CI system.
Enable MemberImportVisibility check on all targets. Use a standard
string header and footer to bracket the new block for ease of updating
in the future with scripts.
Fix FreeBSD support
### Checklist
- [x] I've run tests to see all new and existing tests pass
- [x] I've followed the code style of the rest of the project
- [x] I've read the [Contribution Guidelines](CONTRIBUTING.md)
- [x] I've updated the documentation if necessary
### Motivation:
To add FreeBSD support to Swift, we must ensure that swift crypto builds
on FreeBSD since it's a dependency of swiftpm and several essential
packages.
### Modifications:
- `Package.swift` - Ideally FreeBSD should use `.when(platforms:)` to
set the corresponding swift settings and dependencies. However,
`Platform.freebsd` is not yet available on swiftpm and therefore use
guard the settings behind a `isFreeBSD` boolean flag. This is chosen
because it minimize the diff and maintains the maximum readability.
- `cmake/modules/SwiftSupport.cmake` - add `amd64` arch support, maps to
`x86_64`.
- `**/CMakeLists.txt` - Use the Linux assembly files for FreeBSD. Both
Linux and FreeBSD uses SysV ABI, and there're no syscalls involved
(after all, they're supposed to be "pure") so there are no ABI
compatibility problem. After all, all the tests are passing on FreeBSD
with this PR.
### Result:
All the tests (via `swift test`) passed on x86_64 FreeBSD 14.1-p6, and
passed on aarch64 macOS.
Test log available here:
[swift-test-result.txt](https://github.com/user-attachments/files/18147920/swift-test-result.txt)
## Motivation
We would like to provide support for the P384-SHA384 Verifiable Oblivious Pseudorandom Function (VOPRF) as defined in [RFC 9497: VOPRF Protocol](https://www.rfc-editor.org/rfc/rfc9497.html#name-voprf-protocol).
## Modifications
- Add protocols for some "ECToolbox" abstractions: `Group`, `GroupElement`, `GroupScalar`, `HashToGroup`.
- Add implementations backed by BoringSSL.
- Duplicate some utilities from Crypto into _CryptoExtras: hexadecimal bytes and I2OSP.
- Add VOPRF API, rooted at `enum P384._VOPRF`.
## Results
- New internal abstractions that make it easier to bring up new implementations.
- New API for `OPRF(P-384, SHA-384)` in VOPRF mode.
## Tests
- Test vectors for internal `HashToField` implementation.
- Test vectors for internal VOPRF implementation.
- Tests of the VOPRF public API.
* Support loading RSAPSS public keys with parameters
Parameters are stripped and the key is treated as a regular public key.
* address review + reset algorithm as well
* run update_cmakelists.sh
* attempt to fix the cmake build
* include FetchContent
* early return for non-PSS keys
* simplify code
Motivation:
The privacy manifest is only required on Darwin. It's currently included
on all platforms which results in build warnings.
Modifications:
- Only include manifest on Darwin
- Exclude the privacy manifest from the build on other platforms
Result:
- Fewer warnings
- Resolves#256
* 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 e02700e07c.
* Fix CMakeLists.txt
* Make most public symbols @inlinable
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation:
Now that Swift 5.9 is GM we should update the supported versions and
remove 5.6
Modifications:
* Update `Package.swift`
* Delete the 5.6 docker compose file and make a 5.10 one
* Update docs
Result:
Remove support for Swift 5.6, add 5.10
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation
We need a few extra Windows defines to match what BoringSSL does, and
to suppress warnings.
Modifications
Add the missing defines.
Result
Fewer warnings.
Resolves#195.
Co-authored-by: Saleem Abdulrasool <compnerd@compnerd.org>
Motivation
WWDC has arrived! 🎉 As part of the celebration, let's
bring Crypto up to speed with the new CryptoKit API surface.
Modifications
Substantial new docstrings
HPKE support
Result
WWDC 2023 support.
# Motivation
BoringSSL exposes AES-GCM-SIV algorithms which are in general useful to have and provide a nonce-misuse resistant mode of AES-GCM. Since, `CryptoKit` is not exposing AES-GCM-SIV we need to add this to `_CryptoExtras`
# Modification
Exposes `AES-GCM-SIV` through `_CryptoExtras`.
# Result
We can now use `AES-GCM-SIV` through `_CryptoExtras`.
Motivation:
Old Swift versions are periodically dropped. Now that 5.7 has been
released, 5.4 will be dropped.
Modifications:
- Update tools version
- Remove 5.4 docker-compose
- Update 5.7 docker-compose to use released image and move from focal to
jammy
- Update docs
Result:
Swift 5.5 is the minimum supported Swift version