Skip to content

Generalise ML-DSA with GYB #355

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

Merged
merged 3 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/_CryptoExtras/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ add_library(_CryptoExtras
"Key Derivation/PBKDF2/PBKDF2.swift"
"Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift"
"Key Derivation/Scrypt/Scrypt.swift"
"MLDSA/MLDSA65_boring.swift"
"MLDSA/MLDSA_boring.swift"
"MLKEM/MLKEM_boring.swift"
"OPRFs/OPRF.swift"
"OPRFs/OPRFClient.swift"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
//
//===----------------------------------------------------------------------===//

// MARK: - Generated file, do NOT edit
// any edits of this file WILL be overwritten and thus discarded
// see section `gyb` in `README` for details.

@_implementationOnly import CCryptoBoringSSL
import Crypto
import Foundation
Expand Down Expand Up @@ -86,7 +90,7 @@ extension MLDSA65 {

self.seed = try withUnsafeTemporaryAllocation(
of: UInt8.self,
capacity: MLDSA65.seedByteCount
capacity: MLDSA.seedByteCount
) { seedPtr in
try withUnsafeTemporaryAllocation(
of: UInt8.self,
Expand All @@ -102,7 +106,7 @@ extension MLDSA65 {
throw CryptoKitError.internalBoringSSLError()
}

return Data(bytes: seedPtr.baseAddress!, count: MLDSA65.seedByteCount)
return Data(bytes: seedPtr.baseAddress!, count: MLDSA.seedByteCount)
}
}
}
Expand All @@ -113,7 +117,7 @@ extension MLDSA65 {
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 32 bytes long.
init(seedRepresentation: some DataProtocol) throws {
guard seedRepresentation.count == MLDSA65.seedByteCount else {
guard seedRepresentation.count == MLDSA.seedByteCount else {
throw CryptoKitError.incorrectKeySize
}

Expand All @@ -125,7 +129,7 @@ extension MLDSA65 {
CCryptoBoringSSL_MLDSA65_private_key_from_seed(
&self.key,
seedPtr.baseAddress,
MLDSA65.seedByteCount
MLDSA.seedByteCount
)
}) == 1
else {
Expand Down Expand Up @@ -172,7 +176,7 @@ extension MLDSA65 {
}

/// The size of the private key in bytes.
static let byteCount = 4032
static let byteCount = Int(MLDSA65_PRIVATE_KEY_BYTES)
}
}
}
Expand Down Expand Up @@ -311,16 +315,18 @@ extension MLDSA65 {
}

/// The size of the public key in bytes.
static let byteCount = 1952
static let byteCount = Int(MLDSA65_PUBLIC_KEY_BYTES)
}
}
}

@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension MLDSA65 {
/// The size of the seed in bytes.
private static let seedByteCount = 32

/// The size of the signature in bytes.
private static let signatureByteCount = 3309
private static let signatureByteCount = Int(MLDSA65_SIGNATURE_BYTES)
}

private enum MLDSA {
/// The size of the seed in bytes.
fileprivate static let seedByteCount = 32
}
Loading
Loading