Skip to content

Add "external mu" variant of ML-DSA (65 and 87) in _CryptoExtras #358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 20 commits into
base: wwdc-25
Choose a base branch
from

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 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
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant