From 20f90497e52519a9d674fe45c3150cc5d295fe99 Mon Sep 17 00:00:00 2001 From: Si Beaumont Date: Thu, 27 Aug 2026 15:00:29 +0100 Subject: [PATCH] [5.x] Align with CryptoKit from Xcode 27 beta 6 (#462) ## Motivation Xcode 27 beta 6 is now available[^1] with so we can tag a compatible release with the cross-platform code here. ## Modifications - Resync with CryptoKit (CryptoKit-383.2.1) ## Result - Aligned with CryptoKit in latest Xcode beta release. [^1]: https://developer.apple.com/download/all/?q=Xcode%2027 --- Tests/CryptoTests/KEM/XWingTests.swift | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/Tests/CryptoTests/KEM/XWingTests.swift b/Tests/CryptoTests/KEM/XWingTests.swift index d1dc89f7..f7255f79 100644 --- a/Tests/CryptoTests/KEM/XWingTests.swift +++ b/Tests/CryptoTests/KEM/XWingTests.swift @@ -93,6 +93,37 @@ final class XWingTests: XCTestCase { let importedKey = try XWingMLKEM768X25519.PrivateKey.init(integrityCheckedRepresentation: exportedFormat) XCTAssertEqual(importedKey.seedRepresentation, privateKey.seedRepresentation) } + + func testDecapsulateInputValidation() throws { + let ciphersuite = HPKE.Ciphersuite.XWingMLKEM768X25519_SHA256_AES_GCM_256 + let skR = try XWingMLKEM768X25519.PrivateKey.generate() + + // Dummy key with the correct size fails with an error from the underlying implementation. + let corretlySizedKey = Data(repeating: 0x00, count: 1120) + XCTAssertThrowsError( + try HPKE.Recipient( + privateKey: skR, + ciphersuite: ciphersuite, + info: Data(), + encapsulatedKey: corretlySizedKey + ) + ) + + // Keys with the wrong size fail input validation. + let keySizesToTest = [0, 1, 1119, 1221, 2000] + for keySize in keySizesToTest { + let wronglySizedKey = Data(repeating: 0x00, count: keySize) + XCTAssertThrowsError( + try HPKE.Recipient( + privateKey: skR, + ciphersuite: ciphersuite, + info: Data(), + encapsulatedKey: wronglySizedKey + ), + "Unexpectedly returned from malformed decapsulation path for keySize \(keySize)" + ) + } + } } // Struct to parse KAT file