mirror of
https://github.com/apple/swift-crypto
synced 2026-11-24 04:37:48 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
15b0fb5b45 | ||
|
|
ce8db4769d |
No files matched your search
@@ -10,7 +10,7 @@ on:
|
||||
jobs:
|
||||
soundness:
|
||||
name: Soundness
|
||||
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.7
|
||||
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@0.0.13
|
||||
with:
|
||||
license_header_check_project_name: "SwiftCrypto"
|
||||
docs_check_enabled: false
|
||||
@@ -19,28 +19,23 @@ jobs:
|
||||
name: Unit tests
|
||||
uses: apple/swift-nio/.github/workflows/unit_tests.yml@main
|
||||
with:
|
||||
linux_5_10_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_2_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_6_3_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_1_enabled: true
|
||||
linux_6_2_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
linux_6_3_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
linux_nightly_next_arguments_override: "--build-system native -Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
linux_nightly_main_arguments_override: "--build-system native --explicit-target-dependency-import-check error"
|
||||
windows_6_2_enabled: true
|
||||
windows_6_3_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
windows_nightly_main_enabled: true
|
||||
windows_6_1_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_2_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_3_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_nightly_next_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_nightly_main_arguments_override: "--explicit-target-dependency-import-check error"
|
||||
windows_6_2_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
windows_6_3_arguments_override: "-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
windows_nightly_next_arguments_override: "--build-system native -Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated --explicit-target-dependency-import-check error"
|
||||
windows_nightly_main_arguments_override: "--build-system native --explicit-target-dependency-import-check error"
|
||||
|
||||
release-builds:
|
||||
name: Release builds
|
||||
uses: apple/swift-nio/.github/workflows/release_builds.yml@main
|
||||
with:
|
||||
windows_6_1_enabled: true
|
||||
windows_6_2_enabled: true
|
||||
windows_6_3_enabled: true
|
||||
windows_nightly_next_enabled: true
|
||||
|
||||
+13
-1
@@ -38,11 +38,17 @@ let nonDarwinPlatforms: [Platform] = [
|
||||
.custom("freebsd"),
|
||||
]
|
||||
|
||||
let swiftSettings: [SwiftSetting] = [
|
||||
var swiftSettings: [SwiftSetting] = [
|
||||
.define("CRYPTO_IN_SWIFTPM"),
|
||||
.enableExperimentalFeature("Lifetimes"),
|
||||
.enableExperimentalFeature("SourceWarningControl"),
|
||||
]
|
||||
|
||||
// Only enable CheckImplementationOnly on 6.4 -- 6.3 has the feature, but produces many false positives.
|
||||
#if compiler(>=6.4)
|
||||
swiftSettings.append(.enableExperimentalFeature("CheckImplementationOnly"))
|
||||
#endif
|
||||
|
||||
// This doesn't work when cross-compiling: the privacy manifest will be included in the Bundle and
|
||||
// Foundation will be linked. This is, however, strictly better than unconditionally adding the
|
||||
// resource.
|
||||
@@ -98,6 +104,10 @@ let package = Package(
|
||||
.when(platforms: [Platform.wasi])
|
||||
),
|
||||
.define("OPENSSL_NO_ASM", .when(platforms: [Platform.wasi])),
|
||||
// BoringSSL is vendored verbatim; we don't fix its warnings. Xcode enables
|
||||
// -Wshorten-64-to-32 by default (SwiftPM does not), which produces dozens
|
||||
// of warnings. Silence that group here.
|
||||
.disableWarning("shorten-64-to-32"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
@@ -113,6 +123,7 @@ let package = Package(
|
||||
.headerSearchPath("low/KeccakP-1600"),
|
||||
.headerSearchPath("low/common"),
|
||||
.headerSearchPath("common"),
|
||||
.disableWarning("macro-redefined"),
|
||||
]
|
||||
),
|
||||
.target(
|
||||
@@ -141,6 +152,7 @@ let package = Package(
|
||||
.target(name: "CXKCPShims", condition: .when(platforms: nonDarwinPlatforms)),
|
||||
],
|
||||
exclude: privacyManifestExclude + [
|
||||
"vendored-sources.txt",
|
||||
"CMakeLists.txt",
|
||||
"Signatures/BoringSSL/MLDSA_boring.swift.gyb",
|
||||
"KEM/BoringSSL/MLKEM_boring.swift.gyb",
|
||||
|
||||
@@ -88,21 +88,6 @@ extension AES {
|
||||
)
|
||||
}
|
||||
|
||||
// Note: historical version of the above, which should be removed once
|
||||
// the above is API and clients move over to it.
|
||||
#if swift(<6.3)
|
||||
@_lifetime(message: copy message)
|
||||
#endif
|
||||
internal static func seal(
|
||||
inplace message: inout MutableRawSpan,
|
||||
using key: SymmetricKey,
|
||||
nonce: RawSpan,
|
||||
authenticating authenticatedData: RawSpan? = nil,
|
||||
tag: inout OutputRawSpan
|
||||
) throws(CryptoKitMetaError) {
|
||||
return try AESGCMImpl.seal(key: key, message: &message, nonce: nonce, authenticatedData: authenticatedData, tag: &tag)
|
||||
}
|
||||
|
||||
/// Decrypts the message and verifies the authenticity of both the
|
||||
/// encrypted message and additional data.
|
||||
///
|
||||
@@ -161,28 +146,6 @@ extension AES {
|
||||
tag: tag
|
||||
)
|
||||
}
|
||||
|
||||
// Note: historical version of the above, which should be removed once
|
||||
// the above is API and clients move over to it.
|
||||
#if swift(<6.3)
|
||||
@_lifetime(message: copy message)
|
||||
#endif
|
||||
internal static func open(
|
||||
inplace message: inout MutableRawSpan,
|
||||
using key: SymmetricKey,
|
||||
nonce: RawSpan,
|
||||
tag: RawSpan,
|
||||
authenticating authenticatedData: RawSpan? = nil
|
||||
) throws(CryptoKitMetaError) {
|
||||
try AESGCMImpl
|
||||
.open(
|
||||
key: key,
|
||||
message: &message,
|
||||
nonce: nonce,
|
||||
authenticatedData: authenticatedData,
|
||||
tag: tag
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -83,21 +83,6 @@ public enum ChaChaPoly: Cipher, Sendable {
|
||||
try ChaChaPolyImpl.encrypt(key: key, inPlace: &message, nonce: nonce.bytes, authenticatedData: authenticatedData, tag: &tag)
|
||||
}
|
||||
|
||||
// Note: historical version of the above, which should be removed once
|
||||
// the above is API and clients move over to it.
|
||||
#if swift(<6.3)
|
||||
@_lifetime(message: copy message)
|
||||
#endif
|
||||
internal static func seal(
|
||||
inplace message: inout MutableRawSpan,
|
||||
using key: SymmetricKey,
|
||||
nonce: RawSpan,
|
||||
authenticating authenticatedData: RawSpan? = nil,
|
||||
tag: inout OutputRawSpan
|
||||
) throws(CryptoKitMetaError) {
|
||||
try ChaChaPolyImpl.encrypt(key: key, inPlace: &message, nonce: nonce, authenticatedData: authenticatedData, tag: &tag)
|
||||
}
|
||||
|
||||
/// Decrypts the message and verifies the authenticity of both the encrypted
|
||||
/// message and additional data.
|
||||
///
|
||||
@@ -151,21 +136,6 @@ public enum ChaChaPoly: Cipher, Sendable {
|
||||
) throws(CryptoKitMetaError) {
|
||||
try ChaChaPolyImpl.decrypt(key: key, inPlace: &message, nonce: nonce.bytes, tag: tag, authenticatedData: authenticatedData)
|
||||
}
|
||||
|
||||
// Note: historical version of the above, which should be removed once
|
||||
// the above is API and clients move over to it.
|
||||
#if swift(<6.3)
|
||||
@_lifetime(message: copy message)
|
||||
#endif
|
||||
public static func open(
|
||||
inplace message: inout MutableRawSpan,
|
||||
using key: SymmetricKey,
|
||||
nonce: RawSpan,
|
||||
tag: RawSpan,
|
||||
authenticating authenticatedData: RawSpan? = nil
|
||||
) throws(CryptoKitMetaError) {
|
||||
try ChaChaPolyImpl.decrypt(key: key, inPlace: &message, nonce: nonce, tag: tag, authenticatedData: authenticatedData)
|
||||
}
|
||||
}
|
||||
|
||||
extension ChaChaPoly {
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
protocol HashFunctionImplementationDetails: HashFunction where Digest: DigestPrivate {}
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CXKCP
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CXKCPShims
|
||||
#else
|
||||
@_implementationOnly import CXKCP
|
||||
@_implementationOnly import CXKCPShims
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
protocol XKCPBackedHashFunction: HashFunctionImplementationDetails {
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -23,6 +23,7 @@ public import Foundation
|
||||
|
||||
typealias MLKEMPublicKeyImpl = OpenSSLMLKEMPublicKeyImpl
|
||||
typealias MLKEMPrivateKeyImpl = OpenSSLMLKEMPrivateKeyImpl
|
||||
typealias MLKEMOneTimePrivateKeyImpl = OpenSSLMLKEMPrivateKeyImpl
|
||||
|
||||
|
||||
/// The Module-Lattice key encapsulation mechanism (KEM).
|
||||
@@ -150,15 +151,25 @@ extension MLKEM768 {
|
||||
/// The associated decapsulation function can be multiple times faster than the one implemented for PrivateKey,
|
||||
/// but this private key can only be used to decapsulate a shared secret once.
|
||||
public struct OneTimePrivateKey: KEMOneTimePrivateKey, ~Copyable {
|
||||
internal let impl: MLKEMPrivateKeyImpl<MLKEM768>
|
||||
internal let impl: MLKEMOneTimePrivateKeyImpl<MLKEM768>
|
||||
|
||||
internal init(_ impl: MLKEMPrivateKeyImpl<MLKEM768>) {
|
||||
internal init(_ impl: MLKEMOneTimePrivateKeyImpl<MLKEM768>) {
|
||||
self.impl = impl
|
||||
}
|
||||
|
||||
/// Creates a one-time-use private key that reuses the key material of an existing private key.
|
||||
///
|
||||
/// This is used by the tests to check that the one-time decapsulation function is consistent with the regular one.
|
||||
internal init(reusingForTestingOnly privateKey: MLKEM768.PrivateKey) {
|
||||
self.impl = try! MLKEMOneTimePrivateKeyImpl<MLKEM768>(
|
||||
seedRepresentation: privateKey.impl.seedRepresentation,
|
||||
publicKeyRawRepresentation: privateKey.impl.publicKey.rawRepresentation
|
||||
)
|
||||
}
|
||||
|
||||
/// Generates a new, random one-time-use private key.
|
||||
public static func generate() throws -> MLKEM768.OneTimePrivateKey {
|
||||
let impl = try MLKEMPrivateKeyImpl<MLKEM768>.generatePrivateKey()
|
||||
let impl = try MLKEMOneTimePrivateKeyImpl<MLKEM768>.generatePrivateKey()
|
||||
return OneTimePrivateKey(impl)
|
||||
}
|
||||
|
||||
@@ -311,15 +322,25 @@ extension MLKEM1024 {
|
||||
/// The associated decapsulation function can be multiple times faster than the one implemented for PrivateKey,
|
||||
/// but this private key can only be used to decapsulate a shared secret once.
|
||||
public struct OneTimePrivateKey: KEMOneTimePrivateKey, ~Copyable {
|
||||
internal let impl: MLKEMPrivateKeyImpl<MLKEM1024>
|
||||
internal let impl: MLKEMOneTimePrivateKeyImpl<MLKEM1024>
|
||||
|
||||
internal init(_ impl: MLKEMPrivateKeyImpl<MLKEM1024>) {
|
||||
internal init(_ impl: MLKEMOneTimePrivateKeyImpl<MLKEM1024>) {
|
||||
self.impl = impl
|
||||
}
|
||||
|
||||
/// Creates a one-time-use private key that reuses the key material of an existing private key.
|
||||
///
|
||||
/// This is used by the tests to check that the one-time decapsulation function is consistent with the regular one.
|
||||
internal init(reusingForTestingOnly privateKey: MLKEM1024.PrivateKey) {
|
||||
self.impl = try! MLKEMOneTimePrivateKeyImpl<MLKEM1024>(
|
||||
seedRepresentation: privateKey.impl.seedRepresentation,
|
||||
publicKeyRawRepresentation: privateKey.impl.publicKey.rawRepresentation
|
||||
)
|
||||
}
|
||||
|
||||
/// Generates a new, random one-time-use private key.
|
||||
public static func generate() throws -> MLKEM1024.OneTimePrivateKey {
|
||||
let impl = try MLKEMPrivateKeyImpl<MLKEM1024>.generatePrivateKey()
|
||||
let impl = try MLKEMOneTimePrivateKeyImpl<MLKEM1024>.generatePrivateKey()
|
||||
return OneTimePrivateKey(impl)
|
||||
}
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ extension XWingMLKEM768X25519 {
|
||||
}
|
||||
|
||||
public struct PrivateKey: KEMPrivateKey {
|
||||
private var impl: XWingPrivateKeyImpl
|
||||
var impl: XWingPrivateKeyImpl
|
||||
|
||||
public var seedRepresentation: Data {
|
||||
get {
|
||||
@@ -106,6 +106,13 @@ extension XWingMLKEM768X25519 {
|
||||
self.impl = impl
|
||||
}
|
||||
|
||||
/// Creates a one-time-use private key that reuses the key material of an existing private key.
|
||||
///
|
||||
/// This is used by the tests to check that the one-time decapsulation function is consistent with the regular one.
|
||||
internal init(reusingForTestingOnly privateKey: XWingMLKEM768X25519.PrivateKey) {
|
||||
self.impl = privateKey.impl
|
||||
}
|
||||
|
||||
/// Generates a new, random one-time-use private key.
|
||||
public static func generate() throws -> XWingMLKEM768X25519.OneTimePrivateKey {
|
||||
let impl = try XWingPrivateKeyImpl.generate()
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
extension P256.KeyAgreement.PrivateKey {
|
||||
|
||||
@@ -17,9 +17,9 @@
|
||||
#else
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
public import FoundationEssentials
|
||||
import FoundationEssentials
|
||||
#else
|
||||
public import Foundation
|
||||
import Foundation
|
||||
#endif
|
||||
|
||||
internal struct ANSIKDFx963<H: HashFunction>: Sendable {
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -14,8 +14,13 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
@@ -26,7 +30,11 @@ import Foundation
|
||||
// any edits of this file WILL be overwritten and thus discarded
|
||||
// see section `gyb` in `README` for details.
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
@@ -26,7 +30,11 @@ import Foundation
|
||||
// any edits of this file WILL be overwritten and thus discarded
|
||||
// see section `gyb` in `README` for details.
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -15,7 +15,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -14,7 +14,11 @@
|
||||
#if canImport(CryptoKit)
|
||||
@_exported import CryptoKit
|
||||
#else
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
extension CryptoKitError {
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#if !canImport(Darwin)
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
typealias errno_t = CInt
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
public enum CryptoBoringWrapperError: Error {
|
||||
|
||||
@@ -11,7 +11,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
/// A wrapper around BoringSSL's EC_GROUP object that handles reference counting and
|
||||
/// liveness.
|
||||
|
||||
@@ -11,8 +11,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import protocol FoundationEssentials.ContiguousBytes
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -13,8 +13,13 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Crypto
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -13,8 +13,13 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Crypto
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
import Crypto
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
import Crypto
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -14,11 +14,17 @@
|
||||
|
||||
// This is a copy ChaChaPoly_boring just with a different set aes algos
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
import Crypto
|
||||
import CryptoBoringWrapper
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
@@ -92,7 +98,7 @@ enum OpenSSLAESGCMSIVImpl {
|
||||
)
|
||||
}
|
||||
|
||||
return try AES.GCM._SIV.SealedBox(combined: combined, nonceByteCount: nonce.bytes.count)
|
||||
return AES.GCM._SIV.SealedBox(combined: combined, nonceByteCount: nonce.bytes.count)
|
||||
}
|
||||
|
||||
@inlinable
|
||||
|
||||
@@ -11,9 +11,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
|
||||
import Crypto
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -12,11 +12,17 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
import Crypto
|
||||
import CryptoBoringWrapper
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -12,8 +12,13 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
import Crypto
|
||||
import CryptoBoringWrapper
|
||||
#if canImport(FoundationEssentials)
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
import Crypto
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
#if canImport(Darwin)
|
||||
import Darwin
|
||||
#endif
|
||||
|
||||
@@ -12,9 +12,10 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
import Crypto
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
|
||||
struct BoringSSLSHA512256HashFunction {
|
||||
static var digestSize: Int {
|
||||
Int(SHA256_DIGEST_LENGTH)
|
||||
|
||||
@@ -20,8 +20,13 @@ import Foundation
|
||||
#endif
|
||||
|
||||
#if !canImport(CommonCrypto)
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
internal struct BoringSSLPBKDF2 {
|
||||
|
||||
@@ -12,9 +12,15 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
import Crypto
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
import Crypto
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
#if os(Windows)
|
||||
|
||||
@@ -12,12 +12,18 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
import Crypto
|
||||
import CryptoBoringWrapper
|
||||
|
||||
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
|
||||
#if canImport(FoundationEssentials)
|
||||
#if os(Windows)
|
||||
import ucrt
|
||||
|
||||
@@ -12,7 +12,11 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
#if !canImport(Darwin)
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
typealias errno_t = CInt
|
||||
|
||||
@@ -13,8 +13,13 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSLShims
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
@_implementationOnly import CCryptoBoringSSLShims
|
||||
#endif
|
||||
#if canImport(FoundationEssentials)
|
||||
import FoundationEssentials
|
||||
#else
|
||||
|
||||
@@ -12,9 +12,14 @@
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
import Crypto
|
||||
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
extension CryptoKitError {
|
||||
/// A helper function that packs the value of `ERR_get_error` into the internal error field.
|
||||
|
||||
@@ -13,7 +13,11 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
// NOTE: This file is unconditionally compiled because RSABSSA is implemented using BoringSSL on all platforms.
|
||||
#if hasFeature(SourceWarningControl)
|
||||
@diagnose(ImplementationOnlyDeprecated, as: ignored) @_implementationOnly import CCryptoBoringSSL
|
||||
#else
|
||||
@_implementationOnly import CCryptoBoringSSL
|
||||
#endif
|
||||
import Crypto
|
||||
|
||||
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
|
||||
|
||||
@@ -45,7 +45,7 @@ final class AES_CFBTests: XCTestCase {
|
||||
|
||||
func testVector(_ vector: TestVector) throws {
|
||||
let (contiguousPlaintextData, discontiguousPlaintextData) = vector.plaintext.asDataProtocols()
|
||||
for plaintextData in [contiguousPlaintextData as DataProtocol, discontiguousPlaintextData as DataProtocol] {
|
||||
for plaintextData in [contiguousPlaintextData as (any DataProtocol), discontiguousPlaintextData as (any DataProtocol)] {
|
||||
let key = SymmetricKey(data: Data(vector.key))
|
||||
let iv = try AES._CFB.IV(ivBytes: vector.iv)
|
||||
let ciphertext = try AES._CFB.encrypt(plaintextData, using: key, iv: iv)
|
||||
|
||||
@@ -151,7 +151,7 @@ class AESGCMTests: XCTestCase {
|
||||
let ciphertext = Array("This pretty clearly isn't ciphertext, but sure why not".utf8)
|
||||
let (contiguousCiphertext, discontiguousCiphertext) = ciphertext.asDataProtocols()
|
||||
|
||||
let contiguousSB = try orFail { try AES.GCM.SealedBox(combined: contiguousCiphertext) }
|
||||
let contiguousSB = try orFail { AES.GCM.SealedBox(combined: contiguousCiphertext) }
|
||||
let discontiguousSB = try orFail { try AES.GCM.SealedBox(combined: discontiguousCiphertext) }
|
||||
XCTAssertEqual(contiguousSB.combined, discontiguousSB.combined)
|
||||
XCTAssertEqual(Array(contiguousSB.nonce), Array(discontiguousSB.nonce))
|
||||
|
||||
@@ -19,6 +19,34 @@ import XCTest
|
||||
@testable import Crypto
|
||||
|
||||
final class MLKEMTests: XCTestCase {
|
||||
/// Decapsulates with the regular private key and also with a one-time private key built from the
|
||||
/// same key material, asserting that both paths recover the same shared secret. Returns the shared
|
||||
/// secret so callers can run their own assertions (e.g. against a known-answer value), guaranteeing
|
||||
/// the one-time and regular decapsulation functions are tested identically everywhere.
|
||||
private func decapsulate(
|
||||
with privateKey: MLKEM768.PrivateKey,
|
||||
_ encapsulated: Data,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) throws -> SymmetricKey {
|
||||
let sharedSecret = try privateKey.decapsulate(encapsulated)
|
||||
let oneTimeSharedSecret = try MLKEM768.OneTimePrivateKey(reusingForTestingOnly: privateKey).decapsulate(encapsulated)
|
||||
XCTAssertEqual(sharedSecret, oneTimeSharedSecret, "one-time decapsulation diverged from regular decapsulation", file: file, line: line)
|
||||
return sharedSecret
|
||||
}
|
||||
|
||||
private func decapsulate(
|
||||
with privateKey: MLKEM1024.PrivateKey,
|
||||
_ encapsulated: Data,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) throws -> SymmetricKey {
|
||||
let sharedSecret = try privateKey.decapsulate(encapsulated)
|
||||
let oneTimeSharedSecret = try MLKEM1024.OneTimePrivateKey(reusingForTestingOnly: privateKey).decapsulate(encapsulated)
|
||||
XCTAssertEqual(sharedSecret, oneTimeSharedSecret, "one-time decapsulation diverged from regular decapsulation", file: file, line: line)
|
||||
return sharedSecret
|
||||
}
|
||||
|
||||
func testMLKEM768() throws {
|
||||
let privateKey = try MLKEM768.PrivateKey.generate()
|
||||
let publicKey = privateKey.publicKey
|
||||
@@ -31,7 +59,7 @@ final class MLKEMTests: XCTestCase {
|
||||
try XCTAssert(privateKey.integrityCheckedRepresentation == MLKEM768.PrivateKey(integrityCheckedRepresentation: privateKey.integrityCheckedRepresentation).integrityCheckedRepresentation)
|
||||
|
||||
let er = try publicKey.encapsulate()
|
||||
let ss = try privateKey.decapsulate(er.encapsulated)
|
||||
let ss = try decapsulate(with: privateKey, er.encapsulated)
|
||||
|
||||
XCTAssert(er.sharedSecret == ss)
|
||||
}
|
||||
@@ -48,24 +76,18 @@ final class MLKEMTests: XCTestCase {
|
||||
try XCTAssert(privateKey.integrityCheckedRepresentation == MLKEM1024.PrivateKey(integrityCheckedRepresentation: privateKey.integrityCheckedRepresentation).integrityCheckedRepresentation)
|
||||
|
||||
let er = try publicKey.encapsulate()
|
||||
let ss = try privateKey.decapsulate(er.encapsulated)
|
||||
let ss = try decapsulate(with: privateKey, er.encapsulated)
|
||||
|
||||
XCTAssert(er.sharedSecret == ss)
|
||||
}
|
||||
|
||||
func testOneTimeKeys() throws {
|
||||
let privateKey = try MLKEM1024.OneTimePrivateKey.generate()
|
||||
let publicKey = privateKey.publicKey
|
||||
// Test that the private key API function throws on an invalid seed
|
||||
func testPrivateKeyInitThrowsOnInvalidSeedLength768() {
|
||||
XCTAssertThrowsError(try MLKEM768.PrivateKey(seedRepresentation: Data(count: 1), publicKey: nil))
|
||||
}
|
||||
|
||||
// Test encapsulation and decapsulation
|
||||
let er = try publicKey.encapsulate()
|
||||
let ss = try privateKey.decapsulate(er.encapsulated)
|
||||
XCTAssert(er.sharedSecret == ss)
|
||||
|
||||
// The following would (and should) produce a compile-time error
|
||||
// let er2 = try publicKey.encapsulate()
|
||||
// let ss2 = try privateKey.decapsulate(er.encapsulated)
|
||||
// XCTAssert(er2.sharedSecret == ss2)
|
||||
func testPrivateKeyInitThrowsOnInvalidSeedLength1024() {
|
||||
XCTAssertThrowsError(try MLKEM1024.PrivateKey(seedRepresentation: Data(count: 1), publicKey: nil))
|
||||
}
|
||||
|
||||
func processKATFile(filename: String) throws -> [MLKEMKAT] {
|
||||
|
||||
@@ -19,6 +19,22 @@ import XCTest
|
||||
@testable import Crypto
|
||||
|
||||
final class XWingTests: XCTestCase {
|
||||
/// Decapsulates with the regular private key and also with a one-time private key built from the
|
||||
/// same key material, asserting that both paths recover the same shared secret. Returns the shared
|
||||
/// secret so callers can run their own assertions (e.g. against a known-answer value), guaranteeing
|
||||
/// the one-time and regular decapsulation functions are tested identically everywhere.
|
||||
private func decapsulate(
|
||||
with privateKey: XWingMLKEM768X25519.PrivateKey,
|
||||
_ encapsulated: Data,
|
||||
file: StaticString = #filePath,
|
||||
line: UInt = #line
|
||||
) throws -> SymmetricKey {
|
||||
let sharedSecret = try privateKey.decapsulate(encapsulated)
|
||||
let oneTimeSharedSecret = try XWingMLKEM768X25519.OneTimePrivateKey(reusingForTestingOnly: privateKey).decapsulate(encapsulated)
|
||||
XCTAssertEqual(sharedSecret, oneTimeSharedSecret, "one-time decapsulation diverged from regular decapsulation", file: file, line: line)
|
||||
return sharedSecret
|
||||
}
|
||||
|
||||
func testKEM() throws {
|
||||
let privateKey = try XWingMLKEM768X25519.PrivateKey.generate()
|
||||
|
||||
@@ -30,24 +46,10 @@ final class XWingTests: XCTestCase {
|
||||
try XCTAssert(privateKey.integrityCheckedRepresentation == XWingMLKEM768X25519.PrivateKey(integrityCheckedRepresentation: privateKey.integrityCheckedRepresentation).integrityCheckedRepresentation)
|
||||
|
||||
let er = try privateKey.publicKey.encapsulate()
|
||||
let ss = try privateKey.decapsulate(er.encapsulated)
|
||||
let ss = try decapsulate(with: privateKey, er.encapsulated)
|
||||
|
||||
XCTAssert(er.sharedSecret == ss)
|
||||
}
|
||||
|
||||
func testOneTimeKeys() throws {
|
||||
let privateKey = try XWingMLKEM768X25519.OneTimePrivateKey.generate()
|
||||
let publicKey = privateKey.publicKey
|
||||
|
||||
let er = try publicKey.encapsulate()
|
||||
let ss = try privateKey.decapsulate(er.encapsulated)
|
||||
XCTAssert(er.sharedSecret == ss)
|
||||
|
||||
// The following would (and should) produce a compile-time error
|
||||
// let er2 = try publicKey.encapsulate()
|
||||
// let ss2 = try privateKey.decapsulate(er.encapsulated)
|
||||
// XCTAssert(er2.sharedSecret == ss2)
|
||||
}
|
||||
|
||||
func processKATFile(filename: String) throws -> [XWingKAT] {
|
||||
let bundle = Bundle.module
|
||||
@@ -69,7 +71,7 @@ final class XWingTests: XCTestCase {
|
||||
let encapsulatedKey = try privateKey.publicKey.encapsulateWithRng(rngState: encapDrbg)
|
||||
XCTAssertEqual(encapsulatedKey.encapsulated, katTest.ct)
|
||||
XCTAssertEqual(encapsulatedKey.sharedSecret.dataRepresentation, katTest.ss)
|
||||
let retrievedSharedSecret = try privateKey.decapsulate(encapsulatedKey.encapsulated)
|
||||
let retrievedSharedSecret = try decapsulate(with: privateKey, encapsulatedKey.encapsulated)
|
||||
XCTAssertEqual(retrievedSharedSecret.dataRepresentation, katTest.ss)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user