Skip to content

Conversation

fpseverino
Copy link
Contributor

@fpseverino fpseverino commented Jun 4, 2025

Add an "external mu" variant of the ML-DSA API (65 and 87 variants) in _CryptoExtras.

Checklist

  • I've run tests to see all new and existing tests pass
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • 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:

BoringSSL now has an “external mu” variant of the ML-DSA API, which makes it possible to calculate the hash (called “mu”) of the message, context and public key separately, and then pass this “mu” to a signing function.
Basically, it is the same process as the traditional signature function, but separated into two steps.
This is supposed to be the alternative to the HashML-DSA algorithm, which does pure pre-hashing.

Modifications:

Add the "external mu" API to MLDSA65 and MLDSA87 when importing _CryptoExtras, add tests.

Result:

The "external mu" variant of ML-DSA is now available in _CryptoExtras.

fpseverino and others added 2 commits June 4, 2025 17:36
This PR sets swift-crypto up for alignment with the WWDC 2025 CryptoKit
APIs. This includes the parity APIs for MLKEM and MLDSA, as well as
XWing.

At this time the SHA3 APIs are disabled, as they require a novel
implementation strategy. This will come later in the summer. All API
features that require SHA3 are therefore also disabled at runtime.
@fpseverino fpseverino changed the base branch from main to wwdc-25 June 16, 2025 13:57
@fpseverino fpseverino marked this pull request as draft June 16, 2025 16:12
@fpseverino fpseverino marked this pull request as draft June 16, 2025 16:12
@fpseverino fpseverino marked this pull request as ready for review June 16, 2025 18:37
@fpseverino fpseverino changed the title Add "external mu" variant of ML-DSA (65 and 87) Add "external mu" variant of ML-DSA (65 and 87) in _CryptoExtras Jun 16, 2025
fpseverino and others added 4 commits June 17, 2025 12:03
### Motivation:

FoundationEssentials produces smaller binaries on most platforms.

### Modifications:

Where FoundationEssentials is available, import that.

### Result:

Improved binary size
To keep the WWDC-25 branch from rotting too badly, we'll be doing
regular catch-up merges. This is the first.

Co-authored-by: YourMJK <[email protected]>
Comment on lines -28 to -34

@_implementationOnly import CCryptoBoringSSL
#if canImport(FoundationEssentials)
import FoundationEssentials
#else
import Foundation
#endif
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These imports were duplicated in the same file

Comment on lines 35 to 36
public func signature(forPrehashedMessageRepresentative mu: some DataProtocol) throws -> Data {
try self.signature_boring(forPrehashedMessageRepresentative: mu)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The public method here and the equivalent package one defined in Crypto/Signatures/MLDSA.swift must have different names, otherwise the compiler thinks we are calling the same method and throws the warning Function call causes an infinite recursion.


private var boringSSLKey: OpenSSLMLDSAPublicKeyImpl<MLDSA65> {
get throws {
self.impl is OpenSSLMLDSAPublicKeyImpl<MLDSA65>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This throws the warning 'is' test is always true, should we use #if checks instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated it to use #if checks

fpseverino and others added 6 commits June 19, 2025 18:59
Motivation

The Swift 6 language mode adopts data-race safety by default. While
Swift Crypto itself has no concurrent code, it is still useful to force
us to ensure that our code is properly Sendable-correct.

Modifications

- @unchecked Sendable on several CoW data types
- Some necessary Sendable constraints on ECToolbox protocols
- Add some missing protocol constraints on ARC types.

Result

Swift 6 clean.
fpseverino and others added 6 commits September 9, 2025 17:14
This patch brings us up-to-date with the RC SDK. There are a couple of
tweaks to the MLDSA code and the XWing code, mostly a few minor
interface changes. I've adopted those in the backing code, and also
wired up the SHA3 integrity checks.
self.impl
#endif
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these pieces be moved into another file in this project and declared as extension methods? Ideally they'd stay out of the shared code, and in a BoringSSL directory instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Lukasa done!

@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label Sep 12, 2025
0xTim and others added 5 commits September 15, 2025 15:07
Following on from apple#281, opened as a new PR as the conflicts were too
many

### 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
- [ ] I've run `.script/generate_boilerplate_files_with_gyb` and
included updated generated files in a commit of this pull request

### Motivation:

_[Explain here the context, and why you're making that change. What is
the problem you're trying to solve.]_

### Modifications:

_[Describe the modifications you've done.]_

### Result:

_[After your change, what will change.]_
This convinience method will be used by SLHDSA, which will be located in `CryptoExtras`, and could also be used by `MLDSA44`, also to be located in `CryptoExtras`
@@ -19,7 +19,9 @@ import Foundation
#endif

extension Optional where Wrapped: DataProtocol {
func withUnsafeBytes<ReturnValue>(_ body: (UnsafeRawBufferPointer) throws -> ReturnValue) rethrows -> ReturnValue {
package func withUnsafeBytes<ReturnValue>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This convinience method will be used by SLHDSA, which will be located in CryptoExtras, and could also be used in the future by MLDSA44, which will also need to be located in CryptoExtras.

fpseverino and others added 7 commits September 16, 2025 12:05
This is the last catchup merge into the WWDC-25 branch required to get
the two branches to line up. From here, it's a straightforward merge to
`main` to get the WWDC-25 branch in.

---------

Co-authored-by: YourMJK <[email protected]>
Co-authored-by: Rick Newton-Rogers <[email protected]>
Co-authored-by: Raphael <[email protected]>
Co-authored-by: Si Beaumont <[email protected]>
Co-authored-by: Evan Wilde <[email protected]>
Co-authored-by: Tim Condon <[email protected]>
Co-authored-by: Gus Cairo <[email protected]>
Co-authored-by: George Barnett <[email protected]>
Co-authored-by: Fabrice de Gans <[email protected]>
Co-authored-by: Wojciech Nagrodzki <[email protected]>
Co-authored-by: Jesse L. Zamora <[email protected]>
Co-authored-by: aryan-25 <[email protected]>
Co-authored-by: Gwynne Raskind <[email protected]>
Co-authored-by: 3405691582 <[email protected]>
Co-authored-by: Paul Toffoloni <[email protected]>
@fpseverino fpseverino changed the base branch from wwdc-25 to main September 29, 2025 14:02
@fpseverino fpseverino changed the base branch from main to wwdc-25 September 29, 2025 14:03
@fpseverino fpseverino changed the base branch from wwdc-25 to main September 29, 2025 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🆕 semver/minor Adds new public API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants