`getKeyPrimitives` is marked as throws but is not actually throwing
errors and this is yielding warnings. This fixes the warnings.
### 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 `./scripts/generate_boilerplate_files_with_gyb.sh` and
included updated generated files in a commit of this pull request
### Motivation:
Currently there's a warning
```
/swift-crypto/Sources/_CryptoExtras/RSA/RSA_boring.swift:67:9: warning: no calls to throwing functions occur within 'try' expression
```
because we're using `try` on a non throwing function. This escalates to
all of the functions that use it.
I'm not sure if removing `throws` from a non-actually-throwing public
function is breaking, as using `try` on a non throwing function only
yields a warning (if not in warnings-as-errors mode) but it actively is
a signature change so it might still be breaking. In case we don't want
to merge this as is, the warning can be removed by simply removing
useless `try`s and we can wait for the next major version to remove the
false-throwers.
### Modifications:
Remove the useless `try` and `throws` where they're not needed.
### Result:
The warning is gone.
The threading changes missed an `os(OpenBSD)`, causing the Swift
toolchain build to fail.
### Checklist
- [ ] 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)
- [ ] I've updated the documentation if necessary
#### If you've made changes to `gyb` files
- [ ] I've run `./scripts/generate_boilerplate_files_with_gyb.sh` and
included updated generated files in a commit of this pull request
### Motivation:
Buildfix the upstream Swift toolchain on OpenBSD.
### Modifications:
Added an `os(OpenBSD)` conditional, much like FreeBSD.
### Result:
The Swift toolchain will build successfully again.
Motivation
In preparation for adopting FoundationEssentials where available, we
need to avoid using Thread as that isn't available. To that end, let's
bring over NIO's ThreadSpecificVariable wrapper.
Modifications
Bring over NIO's ThreadSpecificVariable wrapper and supporting code.
Result
No need for Thread anymore.
### Motivation:
swift-crypto currently fails to compile with TSAN enabled in 5.10 and
6.0 due to a TSAN error stemming from the use of `consuming` in the
`finalize()` method of `_CryptoExtras/AES/CMAC`.
### Modifications:
Like #384, the `consuming finalize()` method in `_CryptoExtras/AES/CMAC`
is now wrapped inside a `#if compiler(>=6.1)` condition. A non-consuming
variant is used otherwise.
### Result:
`swift-crypto` can successfully compile with TSAN enabled in 5.10 and
6.0.
## Motivation
We were using a `@TaskLocal static var` to hold the
`FiniteFieldArithmeticContext` (FFAC) on each of the curve types. The
intention here was this would operate as a thread-local value, since
task-locals behave like thread locals when the caller is not part of a
task context. However, they still require binding, (i.e. the use of e.g.
`P256.$__ffac.withValue { ... }`[^1], otherwise they just return the
_default_ value, which is globally shared. We were not doing that, nor
do we have a sensible place where we could.
This causes crashes when using these values in a multithreaded
environment since the same value will be used across threads.
## Modifications
- Use an explicit thread-local API from Foundation to store and read the
per-curve FFAC.
- Add a test that shows each thread gets the same value on each read,
but distinct from all other threads.
## Result
Fixes crash when using ECToolbox-based APIs in multithreaded code.
[^1]:
https://developer.apple.com/documentation/swift/tasklocal#Using-task-local-values-outside-of-tasks
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>
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>
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
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.
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.
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 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.
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.
* wrapper: Remove _boring suffix from files in CryptoBoringWrapper
* wrapper: Move EC types and random bytes into CryptoBoringWrapper
* tests: Remove unused conditional compilation conditions in wrapper tests
* 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
This adds a _createFromNumbers API which creates an RSA key generating p and q primes based on n, e and d
Motivation:
There might be cases where private RSA keys have to be generated based on their raw elements (modulus n, exponent e and private exponent d) without p and q. These are random primes which are integral parts of the key but can be generated based on the former numbers, and are not always included when representing RSA keys, for example these parameters are not required in JWKs
Modifications:
This adds a static _createFromNumbers method which creates a new RSA key given its raw modulus, exponent and private exponent, generating the needed p and q primes without having to provide them as parameters. The algorithm to generate primes is based on a hybrid approach of the Miller Rabin primality test and the proof of Fact 1 in Dan Boneh's Twenty Years of Attacks on the RSA Cryptosystem paper. To write this algorithm, some additions had to be made to the ArbitraryPrecisionInteger
Result:
Private RSA keys can now be generated without providing p and q