Motivation
AES CMAC is a standardised albeit somewhat uncommon MAC built on top of
the AES block cipher. CMAC pops up in a few places, mostly where it is
convenient to assume that you have access to AES, but not to a hash
function. For example, AES-SIV is built on CMAC.
Modifications
Add CMAC support
Add tests and test vectors
Result
CMAC is supported
Add Sequence conformance to `AES._CBC.IV` where `Element` is `UInt8`.
<!-- Thanks for contributing to Swift Crypto! Before you submit your
issue, please make sure you followed our checklist and check the
appropriate boxes by putting an x in the [ ]: [x] -->
### Checklist
- [ ] I've run tests to see all new and existing tests pass
> PKCS8DERRepresentationTests do not compile on master branch with Error
`'pkcs8DERRepresentation' is only available in iOS 14.0 or newer`. All
the other tests pass after my changes.
- [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
- [ ] I've run `.script/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request
### Motivation:
No convenient API for converting `AES._CBC.IV` into `Data`.
### Modifications:
Added `Sequence` conformance to `AES._CBC.IV` similarly how it is done
for `AES.GCM._SIV.Nonce`.
### Result:
It will be possible to create `Data` instance with `AES._CBC.IV` passed
as init argument.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation
We shouldn't repeatedly reconstruct static data
Modifications
- Turn the groups into static lets instead of computed properties
Result
Fewer allocations
Motivation:
Version 3.13.0 hits a compiler assertion when compiling in release mode
on Linux with Swift 6.1. This appears to stem from missing inlinable
annotations.
Modifications:
- Add a few more `@inlinable` and `@usableFromInline` annotations
Result:
Builds on 6.1+ in release mode
Make swift-crypto build on Windows
### 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
- [N/A] I've run `.script/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request
### Motivation:
Currently, swift-crypto on the main branch does not build on Windows.
### Modifications:
* Add the Windows Arm64 assembly files to the CMake build.
* Add appropriate CMake options for swift-crypto to build on Windows.
### Result:
swift-crypto can be built on Windows from main
Fixes#369
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Provides a typealias for `CryptoKitError` to hide the implementation
detail of CryptoKit. Resolves#274
### Motivation:
CryptoKit is an implementation detail on Apple platforms - this makes it
clearer for users coming from other platforms
### Modifications:
Added a type alias and updated documentation
Co-authored-by: Cory Benfield <lukasa@apple.com>
## Motivation
The ARC IETF draft has been updated to now support P256 and drop support
for P384.
## Modifications
- Update the internal ARC implementation to accommodate multiple curves
- Add API surface for P256
- Deprecate API for P384
- Add tests for P256 with test vectors from the draft
- Move over the end-to-end API tests to P256
- Add benchmarks for P256
## Result
- New API `P256._ARCV1`, which provides an implementation of ARC(P-256).
- Deprecate `P384._ARCV1`, which provides an implementation of
ARC(P-256).
[^1]:
https://chris-wood.github.io/draft-arc/draft-yun-cfrg-arc.html#name-arcv1-p256
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
### 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>
### Motivation
PKCS#8 is pretty widely used. Currently getting a key in PKCS#8 DER
representations requires going through a PKCS8 PEM document and then get
its DER bytes.
### Modifications
Add a computed property to RSA private keys that calls into BoringSSL or
Security.framework to get the PKCS8 DER representation of the key.
ECDH keys use the existing `derRepresentation` property to provide a
property of the same name.
A small ASN1 encoder adds the functionality to ed25519/x25519 keys.
### Result
The representation can be accessed directly.
*The identifiers for MLKEM are [still a
draft](https://datatracker.ietf.org/doc/draft-ietf-lamps-kyber-certificates/).
As such MLKEM is not included in the PR.*
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Motivation
Both of these types should be CoW data structures that are inherently
Sendable. This will make programming with them substantially easier.
Modifications
- ArbitraryPrecisionInteger gets marked @unchecked Sendable
- Refactor EllipticCurvePoint to become a CoW value type
- Make EllipticCurvePoint @unchecked Sendable
Results
Easier to use types
Fixed the documentation comment for the constructors
* `init(unsafePEMRepresentation:)`
* `init(unsafeDERRepresentation:)`
of **`_RSA.Signing.PrivateKey`** which said "*public* key" instead of
"*private* key".
### Modifications:
No code changes.
Add ML-DSA-87
### 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:
See #355
### Modifications:
Add the "87" parameter set in MLDSA_boring.swift.gyb, add tests for
`MLDSA87` and update the test vectors for both ML-DSA 65 and 87
### Result:
`MLDSA87` is now available
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.
Generalises the definition of ML-DSA algorithms with GYB to allow the
addition of other parameter sets in the future
### 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:
BoringSSL recently [made ML-DSA-87
public](https://boringssl.googlesource.com/boringssl/+/2a514a51baebd5a232fc64f7b082f7a8b28cd29d)
in its API, in addition to ML-DSA-65 which has already been [integrated
into Swift Crypto](https://github.com/apple/swift-crypto/pull/267).
By generating the code with GYB we will be able to add support for
ML-DSA-87 very easily in the future when the vendored version of
BoringSSL is updated.
### Modifications:
Generate the code for `MLDSA65` (and in future also for `MLDSA87`) with
GYB.
### Result:
Nothing changes in the public API, but adding `MLDSA87` in the future
will be instantaneous.
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.
Add support for ML-KEM post-quantum key encapsulation mechanism inside
`_CryptoExtras`.
<!-- Thanks for contributing to Swift Crypto! Before you submit your
issue, please make sure you followed our checklist and check the
appropriate boxes by putting an x in the [ ]: [x] -->
### 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:
With the advent of quantum computing, the mathematical foundations on
which the cryptographic protocols in use today are based have been
questioned, as they can easily be circumvented and violated by quantum
computers.
While waiting for the creation of quantum computers that work at full
capacity, and to protect network communications from "[Harvest Now,
Decrypt
Later](https://en.wikipedia.org/wiki/Harvest_now,_decrypt_later)"
attacks, the cryptographic community is working on post-quantum
cryptography algorithms, which work on the traditional computers we use
today, but are resistant to future attacks by quantum computers.
One of these algorithms is ML-KEM (AKA Kyber), a module lattice-based
key encapsulation mechanism standardized by NIST in [FIPS
203](https://csrc.nist.gov/pubs/fips/203/final), that is available
inside BoringSSL.
By including ML-KEM inside Swift Crypto, we can get closer to
normalizing quantum secure algorithms and start implementing them into
our apps and libraries to make them quantum-proof.
### Modifications:
Added `MLKEM768` and `MLKEM1024` enums (generated with `gyb`) inside the
`_CryptoExtras` module with corresponding `PrivateKey` and `PublicKey`
structs that use BoringSSL methods to decapsulate and encapsulate
ML-KEM-768 and ML-KEM-1024 ciphertexts, with the code style of other
KEMs in the library (they also conform to `KEMPrivateKey` and
`KEMPublicKey` protocols).
### Result:
ML-KEM key agreements can be handled with Swift Crypto.
Add support for ML-DSA post-quantum digital signatures inside
`_CryptoExtras`.
### Motivation:
With the advent of quantum computing, the mathematical foundations on
which the cryptographic protocols in use today are based have been
questioned, as they can easily be circumvented and violated by quantum
computers.
While waiting for the creation of quantum computers that work at full
capacity, and to protect network communications from "[Harvest Now,
Decrypt
Later](https://en.wikipedia.org/wiki/Harvest_now,_decrypt_later)"
attacks, the cryptographic community is working on post-quantum
cryptography algorithms, which work on the traditional computers we use
today, but are resistant to future attacks by quantum computers.
One of these algorithms is ML-DSA (AKA Dilithium), a module
lattice-based signature scheme standardized by NIST in [FIPS
204](https://csrc.nist.gov/pubs/fips/204/final), that is available
inside BoringSSL.
By including ML-DSA inside Swift Crypto, we can get closer to
normalizing quantum secure algorithms and start implementing them into
our apps and libraries to make them quantum-proof.
### Modifications:
Added a `MLDSA65` enum inside the `_CryptoExtras` module with
corresponding `PrivateKey`, `PublicKey` and `Signature` structs that use
BoringSSL methods to produce and verify ML-DSA-65 digital signatures,
with the code style of other signature schemes in the library.
Added tests that cover use cases of the ML-DSA scheme, including [test
vectors taken from the BoringSSL
repo](https://boringssl.googlesource.com/boringssl/+/refs/heads/master/crypto/mldsa/mldsa_nist_keygen_tests.txt)
(extracted from a `.txt` file and encoded in JSON).
### Result:
ML-DSA-65 digital signatures can be created and verified with Swift
Crypto.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
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>
https://github.com/apple/swift-crypto/issues/338 pointed to some
availability guard platform mismatches on `ARC` and its extensions. This
PR aims to fix these and make sure all platforms build correctly.
### Motivation
When developing code that uses the BoringSSL backend on macOS,
developers set a `development` boolean flag in the Package.swift. We
recently switched from declaring minimum platform versions to annotating
symbols with availability annotations. However, when `development =
true`, it flushes out some annotations that were missing in the first
pass. The result is that `main` currently doesn't build on macOS with
this flag set.
### Modifications
- Add missing availability guards required when development mode
enabled.
### Result:
Code builds macOS with `development = true` in Package.swift.
### Motivation
The use of `Data.subdata(in:)` results in needless copies when decoding
fields from bytes. Additionally, the use of a long chain of
`Data.append(_:)` without a call to `Data.init(capacity:)` or
`Data.reserveCapacity(_:)` can result in needless reallocations.
### Modifications
- Remove unused `EncodeInt` and `DecodeInt` functions. They were unused
before this PR but are there from when ARC credential serialization
included the presentation limit. `DecodeInt` also happened to be
incorrect and would crash when called with a slice.
- Add some useful utility methods for popping bytes from a view without
copying.
- Add some generic functions for encoding and decoding
`FixedWidthInteger` types along with tests for concrete types over
`Data` and slices.
- In ARC decoding, replace the use of `Data.subdata(in:)` with code that
uses the `Data.Subsequence` slice (which happens to be `Data` since the
type is self-slicing).
- In ARC encoding, reserve enough capacity in the resulting `Data` when
the sizes are known to reduce allocations.
## Results
More performant serialization and deserialization for ARC types.
### Motivation
The ARC API surface had no Sendable conformance.
### Modifications
Add Sendable conformance to ARC API types, which are all value types.
### Result
Easier to use ARC API types in concurrent contexts.
### Motivation
The latest draft of the ARC spec[0] includes moving where the
presentation limit is used. Before it was baked in when a client
constructed a credential request, but now it has moved to when a client
makes a presentation from a finalized credential. This PR updates the
internals and API surface to reflect this change.
### Modifications
- Defer passing the presentation limit until a presentation is made.
### Result
Align more closely with the published draft.
### API breakage
It's expected that this will result in the following _breaking_ API
changes:
```diff
- P384._ARCV1.PublicKey.prepareCredentialRequest(requestContext:presentationLimit:)
+ P384._ARCV1.PublicKey.prepareCredentialRequest(requestContext:)
```
```diff
- P384._ARCV1.Credential.makePresentation(context:)
+ P384._ARCV1.Credential.makePresentation(context:presentationLimit:)
```
As this is behind an underscored namespace, we deem this an acceptable
break.
[0]: https://datatracker.ietf.org/doc/draft-yun-cfrg-arc/
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>
Motivation
We should have proper availability annotations.
Modifications
Propagate the availability annotations we need.
Result
Compiles correctly on non-macOS platforms.
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.
## Motivation
We would like to provide support for ARCV1(P-384), as defined in [IETF
Internet Draft: Anonymous Rate-Limited
Credentials](https://datatracker.ietf.org/doc/draft-yun-cfrg-arc/).
## Modifications
- Add internal implementation, generic over the NIST curves.
- Add public API for ARC(P-384), under `P384._ARCV1`.
## Result
New API for current draft of ARC.
## Tests
- End to end tests of internal implementation and API surface.
- Test vector tests of internal implementation and API surface, from the
spec draft.
When building using CMake with Windows, there is an error regarding
missing MultithreadedDLL support. Work around this by setting the
MSVC_RUNTIME_LIBRARY on that platform to a supported option.
### 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:
I'm trying to build swift-crypto on Windows with CMake.
### Modifications:
I've modified the CMakelists.txt such that the clang can compile the
assembly files on Windows.
### Result:
Hopefully, Windows builds of swift-crypto are working.
Remove the extra true values for the swift defines in the CryptoExtras
modules CMakeLists.txt file.
### 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:
The defines don't take effect with a value. Remove the value "true" from
them.
### Modifications:
Modified the CMakeLists.txt file in the CryptoExtras module.
### Result:
After the change the swift defines will hopefully be defined correctly.
### 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:
When building SwiftPM with CMake and the swift-crypto package there are
errors being produced on macOS relating to missing imports provided by
the CryptoKit package.
### Modifications:
Modify the CMakeLists.txt file for the Crypto target so that the defines
are set like they are in the Package.swift.
### Result:
After the change, building SwiftPM with CMake on macOS should work.
Update both the CMakeLists.txt for CCryptoBoringSSL and the
CMakeLists.txt generator so that it can add platform-independent
assembly files.
### 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 `./scripts/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request
### Motivation:
There are downstream linker failures due to missing symbols from certain
platform neutral assembly files.
### Modifications:
The `scripts/update-cmake-lists.sh` has an updated find expression to
discover platform-independent assembly files and includes them in the
`CMakeLists.txt` files.
### Result:
There will be more symbols included from third-parties such as
BoringSSL.
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.
Improve DocC landing pages by mimicking Apple's CryptoKit docs
### Motivation:
Right now the DocC docs group all APIs by protocols, structures and
enums.
By adding a topics section in the landing page we can group them by type
("Ciphers", "Public key cryptography", etc.) exactly in the way Apple
does in [CryptoKit
docs](https://developer.apple.com/documentation/cryptokit/).
### Modifications:
- Fix DocC compilation errors in `_CryptoExtras`
- Add topics section in `_CryptoExtras` landing page
- Add topics section in `Crypto` landing page
### Result:
APIs will be grouped by type.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
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)
Fix DocC generation. Force Linux build on SPI to get it to render the
Crypto docs
### Motivation:
Currently the Crypto docs are empty on SPI because they're built on
macOS where there are no symbols. CryptoExtras index page also doesn't
work because of a name mismatch
### Modifications:
Force Linux build on SPI, fix name for extras documentation
### Result:
Working Docs
Adds some additional documentation. I don't know how far you want me to
go with documenting everything so let me know. This should at least get
the current APIs rendered on SPI. As an aside I'm not a huge fan of
linking out to the CryptoKit docs since not everything is available
here, all the code is already documented here and most of the tutorials
and articles on developer.apple.com for CryptoKit refer to Apple
Platform specific stuff, like interacting with the keychain, that is not
applicable here.
Resolves#273
### 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:
Currently Swift Crypto has no documentation which is not great
### Modifications:
Adds additional DocC scaffolding to take advantage of the DocC comments
in Crypto and CryptoExtras. Adds an SPI config file for Swift Package
Index
### Result:
We will have some documentation
## Motivation
As part of the Github Actions CI migration we held off enabling the
format check and moving to the same formatting rules as Swift NIO, but
we'd like to do that now.
## Modifications
- Add a script to generate (and update) the `.swiftformatignore` file
since this repo only wants to format a specific set of files matching a
pattern.
- Generate and commit the `.swiftformatignore` file.
- Run the fomatter and commit the results.
- Additional commits to satisfy the remaining linter rules that weren't
auto-fixed by swift-format.
- Enable the format check in CI.
## Result
- Code that's not shared is formatted with a style consistent with the
other repos this team maintain.
- CI is now checking code format again.
---------
Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
## 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.
* Replaced potentially unexpected accesses to coordinate slices with consistent ranges no matter if the raw representation is a root or a slice of data
* Updated uses of `.suffix(from:)` with `.dropFirst()` to prevent issues with potential non-0 start indexes
Motivation:
I've added a proposed implementation of PBKDF2, as per proposal in issue #59 to allow easy creation of SymmetricKey from relatively low entropy data sets, such as user provided passwords.
Importance:
This API change is attempting to simplify the creation of SymmetricKeys from user entered passwords.
It uses an ageing algorithm – PBKDF2, but it is still widely supported and popular. A newer algorithm – scrypt is added as a better, more secure alternative.
Modifications:
I've proposed a new API: KDF namespace with Scrypt struct and an Insecure namespace with PBKDF2 struct with associated hash function and a single static method which takes a passphrase and salt, the size of the resulting key in bytes and optionally the number of rounds to use in the PBKDF2 algorithm.
In the case of scrypt algorithm there is no associated hash function due to the nature of the algorithm, the single static method takes passphrase and salt, the size of the resulting key in bytes and optionally: the number of rounds, block size and parallelism factor.
I implemented this functions using both CommonCrypto and BoringSSL where available.
The function names and parameters are heavily influenced by current HKDF implementation.
Additionally, I've added test cases to test the proposed API. I've decided to use test vectors described in RFC6070 for PBKDF2 and test vectors described in RFC7914 for scrypt.
Result:
This will add a new API to _CryptoKitExtras.
It follows the naming conventions from CryptoKit's HKDF implementation.