From b3c832839c63c6a6203915e7cdc16fa30a1dcc66 Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino Date: Fri, 18 Oct 2024 19:53:49 +0200 Subject: [PATCH] Update from seed init --- Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift | 4 ++-- Tests/_CryptoExtrasTests/MLDSATests.swift | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift b/Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift index bdaa7960..8b451fdd 100644 --- a/Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift +++ b/Sources/_CryptoExtras/MLDSA/MLDSA_boring.swift @@ -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. @@ -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 } diff --git a/Tests/_CryptoExtrasTests/MLDSATests.swift b/Tests/_CryptoExtrasTests/MLDSATests.swift index 4cf3dc02..b2d608f6 100644 --- a/Tests/_CryptoExtrasTests/MLDSATests.swift +++ b/Tests/_CryptoExtrasTests/MLDSATests.swift @@ -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 { @@ -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) @@ -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..