Compare commits

..
Author SHA1 Message Date
Si Beaumont 226c73e725 Revert "(split: benchmarks) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 0f0b20b965.
2026-08-07 09:19:47 +01:00
Si Beaumont 6bed8c0239 Only enable CheckImplementationOnly for Swift 6.4+ 2026-08-07 09:18:15 +01:00
Si Beaumont bc748e9db5 Revert "(split: SHA512256) Enable CheckImplementationOnly and box properties where needed"
This reverts commit d6384ee4548e797894add480dfc0ea2b2e55ba1a.
2026-08-07 09:06:21 +01:00
Si Beaumont dbc7ea1646 Revert "(split: XWing) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 1f780b4d25c02733d1433581c3b7e4d8b657d7a5.
2026-08-07 09:06:21 +01:00
Si Beaumont e08fd36acd Revert "(split: MLKEM) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 02688bd534232b63581dbfa1a8d39476a0429f19.
2026-08-07 09:06:21 +01:00
Si Beaumont 1c92c8063d Revert "(split: ECDSASignature) Enable CheckImplementationOnly and box properties where needed"
This reverts commit af44bc64c0c87e92933a677a5b8e77f0602157f3.
2026-08-07 09:06:21 +01:00
Si Beaumont 5932f787f8 Revert "(split: MLDSA) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 25fbb8efaf823becd0a3c52e3ba3db93d123e2fe.
2026-08-07 09:06:21 +01:00
Si Beaumont 6e917b8a0c Revert "(split: AEAD) Enable CheckImplementationOnly and box properties where needed"
This reverts commit af3e61654b5d3a0e36ce575d15e27d79b6bd7184.
2026-08-07 09:06:21 +01:00
Si Beaumont 9650914954 Revert "(split: BIGNUM) Enable CheckImplementationOnly and box properties where needed"
This reverts commit d2a3a8dd752f59e2e838a28afaa5c7c4f7f48f5a.
2026-08-07 09:06:21 +01:00
Si Beaumont 529e520206 Reapply "(split: SHA512256) Enable CheckImplementationOnly and box properties where needed"
This reverts commit dcb8db367de313cfb98acb3f52b3d83eeb81e4f5.
2026-08-06 14:16:47 +01:00
Si Beaumont 86a77f7140 Reapply "(split: XWing) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 3f4136ae8d8bf06851ee12ada60a8759a5f62a62.
2026-08-06 14:16:47 +01:00
Si Beaumont 549795f323 Reapply "(split: MLKEM) Enable CheckImplementationOnly and box properties where needed"
This reverts commit f5b3e148e546740dc926a4f133fdac918c79bda1.
2026-08-06 14:16:47 +01:00
Si Beaumont 74c924555e Reapply "(split: ECDSASignature) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 7f3eaa188ad5d5f1441f701a8c0302ee92cbb09f.
2026-08-06 14:16:47 +01:00
Si Beaumont 0fe7a8e839 Reapply "(split: MLDSA) Enable CheckImplementationOnly and box properties where needed"
This reverts commit ca023c479b7e268dacdb3a5d2265c41532230d7f.
2026-08-06 14:16:47 +01:00
Si Beaumont f0f7a965e0 Reapply "(split: AEAD) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 0dd9f706777cad2b10526087519c0d01d321a65a.
2026-08-06 14:16:47 +01:00
Si Beaumont 88c237b314 Reapply "(split: BIGNUM) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 32d7b6edae15d232d6f6fa7043443832e18249c3.
2026-08-06 14:16:47 +01:00
Si Beaumont c7b6553a08 Revert "(split: SHA512256) Enable CheckImplementationOnly and box properties where needed"
This reverts commit d6384ee4548e797894add480dfc0ea2b2e55ba1a.
2026-08-06 14:16:47 +01:00
Si Beaumont 56f26fd233 Revert "(split: XWing) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 1f780b4d25c02733d1433581c3b7e4d8b657d7a5.
2026-08-06 14:16:47 +01:00
Si Beaumont 9d8037097c Revert "(split: MLKEM) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 02688bd534232b63581dbfa1a8d39476a0429f19.
2026-08-06 14:16:47 +01:00
Si Beaumont 3c7d51f9df Revert "(split: ECDSASignature) Enable CheckImplementationOnly and box properties where needed"
This reverts commit af44bc64c0c87e92933a677a5b8e77f0602157f3.
2026-08-06 14:16:47 +01:00
Si Beaumont c1718e4722 Revert "(split: MLDSA) Enable CheckImplementationOnly and box properties where needed"
This reverts commit 25fbb8efaf823becd0a3c52e3ba3db93d123e2fe.
2026-08-06 14:16:47 +01:00
Si Beaumont c78a61b4d0 Revert "(split: AEAD) Enable CheckImplementationOnly and box properties where needed"
This reverts commit af3e61654b5d3a0e36ce575d15e27d79b6bd7184.
2026-08-06 14:16:47 +01:00
Si Beaumont 10cec03e61 Revert "(split: BIGNUM) Enable CheckImplementationOnly and box properties where needed"
This reverts commit d2a3a8dd752f59e2e838a28afaa5c7c4f7f48f5a.
2026-08-06 14:16:47 +01:00
Si Beaumont bc7a820fd8 Update swiftlang/github-workflows to 0.0.13 2026-08-06 14:16:47 +01:00
Si Beaumont db7a5b2863 Build with -warnings-as-errors in CI (exclude ImplementationOnlyDeprecated)
We want to lock in the win of getting this package warnings-clean. We
usually do this by building with `-warnings-as-errors` in CI. We still
have one warning, which we need to tolerate until we drop support for
6.3, which is `ImplementationOnlyDeprecated`, but we can still lock in
the win by building with the following flags in CI to downgrade
`ImplementationOnlyDeprecated` back to a warning:

    -Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated

This patch updates the pull request GitHub workflow to build with these
flags.
2026-08-06 14:16:47 +01:00
Si Beaumont ad74759b96 Silence ImplementationOnlyDeprecated for Swift 6.4+
This project is currently warnings-as-errors clean, but only because we
suppress `ImplementationOnlyDeprecated` warnings, using the following:

```
-Xswiftc -warnings-as-errors -Xswiftc -Wwarning -Xswiftc ImplementationOnlyDeprecated
```

With this setup, the warnings are still generated and are noisy.

Swift 6.4 introduces `SourceWarningControl`, which we can use to
actually _silence_ these warnings, using `@diagnose(_:as:)`.

This patch adds a dance around the `@_implementationOnly imports`:

    #if hasFeature(SourceWarningControl)
    @diagnose(ImplementationOnlyDeprecated, as: ignored)
    #endif
    @_implementationOnly import ...

On Swift 6.4, this project is now warnings free.

When we raise the minimum supported Swift compiler version to one that
supports `SourceWarningControl`, we can remove the `#if hasFeature`
guards.
2026-08-06 14:16:47 +01:00
Si Beaumont 70712b39f7 (split: SHA512256) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont 451fdb305b (split: XWing) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont eca81332d9 (split: MLKEM) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont 4304fd7dcf (split: ECDSASignature) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont 61e60e023b (split: MLDSA) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont 2cf2acbd9b (split: AEAD) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont b810e1a634 (split: BIGNUM) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 14:16:47 +01:00
Si Beaumont 1416991053 (split: setting) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 07:34:22 +01:00
Si Beaumont 0f0b20b965 (split: benchmarks) Enable CheckImplementationOnly and box properties where needed
We've long since used `@_implementationOnly import` (IOI) for our
vendored C modules (BoringSSL and libXKCP) in an attempt to not leak our
dependency into downstream builds. This is important because leaking
might cause symbol collisions (build failures) or, worse, layout
mismatches (latent runtime failures).

IOI was intended to be used with library evolution, which this project
does not support, and use of IOI without library evolution has been
soft-deprecated. Users are encouraged to move to `internal import` (II),
which is usually the right choice for Swift packages. But II does _not_
provide the same guarantees as IOI and, for this project, we really need
the protections given by IOI so we will continue to use it, even with
library evolution disabled.

One of the reasons for the soft-deprecation was the implementation of
IOI used an incomplete checker, that won't catch all interface leaks
without library evolution. However, Swift has also introduced a new
feature, `CheckImplementationOnly` (CIO), which enables the stricter
interface checking that we need.

Enabling CIO for this project today actually exposes a number of places
where we _are_ leaking the C types into our interface in ways that could
cause build- or runtime problems in downstream projects, and rightly
causes the build to fail. These types will need to have their C struct
members boxed behind an `OpaquePointer`.

This patch enables CIO, and adds the required boxing to the offending
types.

The public API is unchanged.

Additional refactoring is also done to ensure a single designated
initializer, responsible for the allocation, forcing all convenience
initializers through an `init(takingOwnershipOf:)` spelling, to reduce
the chances of introducing future double free bugs in complex
initializers.

This patch also adds some benchmarks for some of the paths that would be
implicated by these changes. While they show the expected increase in
allocations, there's only a modest-to-negligible performance regression,
since the majority of the compute is dominated by the time spent doing
the crypto routines in the C library themselves.
2026-08-06 07:33:46 +01:00
Si Beaumont 60572672b1 Add vendored-sources.txt to excludes to remove SwiftPM warning 2026-08-05 13:25:40 +01:00
Si Beaumont ff138e8694 Drop public import where needed to resolve UnusedImportAccess warning 2026-08-05 13:23:59 +01:00
Si Beaumont 4ebd26ddef Use ExistentialAny keyword in tests to resolve warning in 6.4 2026-08-05 13:23:00 +01:00
Si Beaumont 8979b7465c Remove try keywords to resolve UnnecessaryEffectMarker warnings 2026-08-05 13:22:07 +01:00
Si Beaumont 9fc4058c1d Disable macro-redefined warnings in CXKCP target 2026-08-05 13:22:07 +01:00
Si Beaumont cc50346097 Disable shorten-64-to-32 warnings in BoringSSL target 2026-08-05 10:11:35 +01:00
7 changed files with 105 additions and 91 deletions

No files matched your search

@@ -88,6 +88,21 @@ 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.
///
@@ -146,6 +161,28 @@ 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
)
}
}
}
@@ -83,6 +83,21 @@ 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.
///
@@ -136,6 +151,21 @@ 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 {
+6 -27
View File
@@ -23,7 +23,6 @@ public import Foundation
typealias MLKEMPublicKeyImpl = OpenSSLMLKEMPublicKeyImpl
typealias MLKEMPrivateKeyImpl = OpenSSLMLKEMPrivateKeyImpl
typealias MLKEMOneTimePrivateKeyImpl = OpenSSLMLKEMPrivateKeyImpl
/// The Module-Lattice key encapsulation mechanism (KEM).
@@ -151,25 +150,15 @@ 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: MLKEMOneTimePrivateKeyImpl<MLKEM768>
internal let impl: MLKEMPrivateKeyImpl<MLKEM768>
internal init(_ impl: MLKEMOneTimePrivateKeyImpl<MLKEM768>) {
internal init(_ impl: MLKEMPrivateKeyImpl<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 MLKEMOneTimePrivateKeyImpl<MLKEM768>.generatePrivateKey()
let impl = try MLKEMPrivateKeyImpl<MLKEM768>.generatePrivateKey()
return OneTimePrivateKey(impl)
}
@@ -322,25 +311,15 @@ 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: MLKEMOneTimePrivateKeyImpl<MLKEM1024>
internal let impl: MLKEMPrivateKeyImpl<MLKEM1024>
internal init(_ impl: MLKEMOneTimePrivateKeyImpl<MLKEM1024>) {
internal init(_ impl: MLKEMPrivateKeyImpl<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 MLKEMOneTimePrivateKeyImpl<MLKEM1024>.generatePrivateKey()
let impl = try MLKEMPrivateKeyImpl<MLKEM1024>.generatePrivateKey()
return OneTimePrivateKey(impl)
}
+1 -8
View File
@@ -58,7 +58,7 @@ extension XWingMLKEM768X25519 {
}
public struct PrivateKey: KEMPrivateKey {
var impl: XWingPrivateKeyImpl
private var impl: XWingPrivateKeyImpl
public var seedRepresentation: Data {
get {
@@ -106,13 +106,6 @@ 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()
@@ -12,9 +12,8 @@
//
//===----------------------------------------------------------------------===//
import Crypto
@_implementationOnly import CCryptoBoringSSL
import Crypto
struct BoringSSLSHA512256HashFunction {
static var digestSize: Int {
+14 -36
View File
@@ -19,34 +19,6 @@ 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
@@ -59,7 +31,7 @@ final class MLKEMTests: XCTestCase {
try XCTAssert(privateKey.integrityCheckedRepresentation == MLKEM768.PrivateKey(integrityCheckedRepresentation: privateKey.integrityCheckedRepresentation).integrityCheckedRepresentation)
let er = try publicKey.encapsulate()
let ss = try decapsulate(with: privateKey, er.encapsulated)
let ss = try privateKey.decapsulate(er.encapsulated)
XCTAssert(er.sharedSecret == ss)
}
@@ -76,18 +48,24 @@ final class MLKEMTests: XCTestCase {
try XCTAssert(privateKey.integrityCheckedRepresentation == MLKEM1024.PrivateKey(integrityCheckedRepresentation: privateKey.integrityCheckedRepresentation).integrityCheckedRepresentation)
let er = try publicKey.encapsulate()
let ss = try decapsulate(with: privateKey, er.encapsulated)
let ss = try privateKey.decapsulate(er.encapsulated)
XCTAssert(er.sharedSecret == ss)
}
// Test that the private key API function throws on an invalid seed
func testPrivateKeyInitThrowsOnInvalidSeedLength768() {
XCTAssertThrowsError(try MLKEM768.PrivateKey(seedRepresentation: Data(count: 1), publicKey: nil))
}
func testOneTimeKeys() throws {
let privateKey = try MLKEM1024.OneTimePrivateKey.generate()
let publicKey = privateKey.publicKey
func testPrivateKeyInitThrowsOnInvalidSeedLength1024() {
XCTAssertThrowsError(try MLKEM1024.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 processKATFile(filename: String) throws -> [MLKEMKAT] {
+16 -18
View File
@@ -19,22 +19,6 @@ 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()
@@ -46,10 +30,24 @@ final class XWingTests: XCTestCase {
try XCTAssert(privateKey.integrityCheckedRepresentation == XWingMLKEM768X25519.PrivateKey(integrityCheckedRepresentation: privateKey.integrityCheckedRepresentation).integrityCheckedRepresentation)
let er = try privateKey.publicKey.encapsulate()
let ss = try decapsulate(with: privateKey, er.encapsulated)
let ss = try privateKey.decapsulate(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
@@ -71,7 +69,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 decapsulate(with: privateKey, encapsulatedKey.encapsulated)
let retrievedSharedSecret = try privateKey.decapsulate(encapsulatedKey.encapsulated)
XCTAssertEqual(retrievedSharedSecret.dataRepresentation, katTest.ss)
}
}