Skip to content

Commit

Permalink
Update from seed init
Browse files Browse the repository at this point in the history
  • Loading branch information
fpseverino committed Oct 18, 2024
1 parent d39ef72 commit b3c8328
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extension MLDSA {
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not at least 32 bytes long.
public init(seed: some DataProtocol) throws {
self.backing = try Backing(from: seed)
self.backing = try Backing(seed: seed)
}

/// Initialize a ML-DSA-65 private key from a DER representation.
Expand Down Expand Up @@ -106,7 +106,7 @@ extension MLDSA {
/// - Parameter seed: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not at least 32 bytes long.
init(from seed: some DataProtocol) throws {
init(seed: some DataProtocol) throws {
guard seed.count >= MLDSA.seedSizeInBytes else {
throw CryptoKitError.incorrectKeySize
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/_CryptoExtrasTests/MLDSATests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class MLDSATests: XCTestCase {
try testMLDSASigning(MLDSA.PrivateKey())
// The seed provided here is 64 bytes long, but the MLDSA implementation only uses the first 32 bytes.
let seed: [UInt8] = (0..<64).map { _ in UInt8.random(in: 0...255) }
try testMLDSASigning(MLDSA.PrivateKey(from: seed))
try testMLDSASigning(MLDSA.PrivateKey(seed: seed))
}

private func testMLDSASigning(_ key: MLDSA.PrivateKey) throws {
Expand Down Expand Up @@ -78,7 +78,7 @@ final class MLDSATests: XCTestCase {
let message = "Hello, world!".data(using: .utf8)!

let seed: [UInt8] = (0..<32).map { _ in UInt8.random(in: 0...255) }
let key = try MLDSA.PrivateKey(from: seed)
let key = try MLDSA.PrivateKey(seed: seed)
let publicKey = key.publicKey

let signature1 = try key.signature(for: message)
Expand All @@ -95,7 +95,7 @@ final class MLDSATests: XCTestCase {
// Encode a public key with a trailing 0 at the end.
var encodedPublicKey = [UInt8](repeating: 0, count: MLDSA.PublicKey.bytesCount + 1)
let seed: [UInt8] = (0..<32).map { _ in UInt8.random(in: 0...255) }
let key = try MLDSA.PrivateKey(from: seed)
let key = try MLDSA.PrivateKey(seed: seed)
let publicKey = key.publicKey
try encodedPublicKey.replaceSubrange(0..<MLDSA.PublicKey.bytesCount, with: publicKey.derRepresentation)

Expand All @@ -116,7 +116,7 @@ final class MLDSATests: XCTestCase {
let seed = try Data(hexString: testVector.seed)
let publicKey = try MLDSA.PublicKey(derRepresentation: Data(hexString: testVector.pub))

let expectedkey = try MLDSA.PrivateKey(from: seed).publicKey
let expectedkey = try MLDSA.PrivateKey(seed: seed).publicKey
try XCTAssertEqual(publicKey.derRepresentation, expectedkey.derRepresentation)
}
}
Expand Down

0 comments on commit b3c8328

Please sign in to comment.