Skip to content

Typealias CryptoKitError #285

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ What this means for you is that you should depend on Swift Crypto with a version
In SwiftPM that can be easily done specifying for example `from: "1.0.0"` meaning that you support Swift Crypto in every version starting from 1.0.0 up to (excluding) 2.0.0.
SemVer and Swift Crypto's Public API guarantees should result in a working program without having to worry about testing every single version for compatibility.

Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoKitError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.
Swift Crypto 2.0.0 was released in September 2021. The only breaking change between Swift Crypto 2.0.0 and 1.0.0 was the addition of new cases in the `CryptoError` enumeration. For most users, then, it's safe to depend on either the 1.0.0 _or_ 2.0.0 series of releases.

To do so, please use the following dependency in your `Package.swift`:

Expand Down
70 changes: 4 additions & 66 deletions Sources/CCryptoBoringSSL/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -262,78 +262,16 @@ add_library(CCryptoBoringSSL STATIC

if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
target_sources(CCryptoBoringSSL PRIVATE
gen/bcm/aes-gcm-avx10-x86_64-apple.S
gen/bcm/aesni-gcm-x86_64-apple.S
gen/bcm/aesni-x86_64-apple.S
gen/bcm/ghash-ssse3-x86_64-apple.S
gen/bcm/ghash-x86_64-apple.S
gen/bcm/p256-x86_64-asm-apple.S
gen/bcm/p256_beeu-x86_64-asm-apple.S
gen/bcm/rdrand-x86_64-apple.S
gen/bcm/rsaz-avx2-apple.S
gen/bcm/sha1-x86_64-apple.S
gen/bcm/sha256-x86_64-apple.S
gen/bcm/sha512-x86_64-apple.S
gen/bcm/vpaes-x86_64-apple.S
gen/bcm/x86_64-mont-apple.S
gen/bcm/x86_64-mont5-apple.S
gen/crypto/aes128gcmsiv-x86_64-apple.S
gen/crypto/chacha-x86_64-apple.S
gen/crypto/chacha20_poly1305_x86_64-apple.S
gen/crypto/md5-x86_64-apple.S)
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "amd64|x86_64")
target_sources(CCryptoBoringSSL PRIVATE
gen/bcm/aes-gcm-avx10-x86_64-linux.S
gen/bcm/aesni-gcm-x86_64-linux.S
gen/bcm/aesni-x86_64-linux.S
gen/bcm/ghash-ssse3-x86_64-linux.S
gen/bcm/ghash-x86_64-linux.S
gen/bcm/p256-x86_64-asm-linux.S
gen/bcm/p256_beeu-x86_64-asm-linux.S
gen/bcm/rdrand-x86_64-linux.S
gen/bcm/rsaz-avx2-linux.S
gen/bcm/sha1-x86_64-linux.S
gen/bcm/sha256-x86_64-linux.S
gen/bcm/sha512-x86_64-linux.S
gen/bcm/vpaes-x86_64-linux.S
gen/bcm/x86_64-mont-linux.S
gen/bcm/x86_64-mont5-linux.S
gen/crypto/aes128gcmsiv-x86_64-linux.S
gen/crypto/chacha-x86_64-linux.S
gen/crypto/chacha20_poly1305_x86_64-linux.S
gen/crypto/md5-x86_64-linux.S)
)
elseif(CMAKE_SYSTEM_NAME STREQUAL Darwin AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
target_sources(CCryptoBoringSSL PRIVATE
gen/bcm/aesv8-armv8-apple.S
gen/bcm/aesv8-gcm-armv8-apple.S
gen/bcm/armv8-mont-apple.S
gen/bcm/bn-armv8-apple.S
gen/bcm/ghash-neon-armv8-apple.S
gen/bcm/ghashv8-armv8-apple.S
gen/bcm/p256-armv8-asm-apple.S
gen/bcm/p256_beeu-armv8-asm-apple.S
gen/bcm/sha1-armv8-apple.S
gen/bcm/sha256-armv8-apple.S
gen/bcm/sha512-armv8-apple.S
gen/bcm/vpaes-armv8-apple.S
gen/crypto/chacha-armv8-apple.S
gen/crypto/chacha20_poly1305_armv8-apple.S)
)
elseif(CMAKE_SYSTEM_NAME MATCHES "Linux|Android|FreeBSD|OpenBSD" AND CMAKE_SYSTEM_PROCESSOR MATCHES "arm64|aarch64")
target_sources(CCryptoBoringSSL PRIVATE
gen/bcm/aesv8-armv8-linux.S
gen/bcm/aesv8-gcm-armv8-linux.S
gen/bcm/armv8-mont-linux.S
gen/bcm/bn-armv8-linux.S
gen/bcm/ghash-neon-armv8-linux.S
gen/bcm/ghashv8-armv8-linux.S
gen/bcm/p256-armv8-asm-linux.S
gen/bcm/p256_beeu-armv8-asm-linux.S
gen/bcm/sha1-armv8-linux.S
gen/bcm/sha256-armv8-linux.S
gen/bcm/sha512-armv8-linux.S
gen/bcm/vpaes-armv8-linux.S
gen/crypto/chacha-armv8-linux.S
gen/crypto/chacha20_poly1305_armv8-linux.S)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this looks incorrect. Oh shoot, I think we did some upstream work on this. Try this one? https://github.com/apple/swift-nio/blob/main/scripts/update-cmake-lists.sh

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the script I copied from when running. Do you get the same result running the script?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I had the same problem, do you also get the error scripts/update_cmakelists.sh: line 58: gfind: command not found or something similar? In my case the solution was to download GNU find with brew install findutils

)
else()
message(FATAL_ERROR "platform sources are not defined here")
endif()
Expand Down
1 change: 1 addition & 0 deletions Sources/Crypto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ add_library(Crypto
"ASN1/PKCS8PrivateKey.swift"
"ASN1/SEC1PrivateKey.swift"
"ASN1/SubjectPublicKeyInfo.swift"
"CryptoError_boring.swift"
"CryptoKitErrors.swift"
"Digests/BoringSSL/Digest_boring.swift"
"Digests/Digest.swift"
Expand Down
18 changes: 18 additions & 0 deletions Sources/Crypto/CryptoError_boring.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftCrypto open source project
//
// Copyright (c) 2019-2025 Apple Inc. and the SwiftCrypto project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftCrypto project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//

@available(iOS 13.0, macOS 10.15, watchOS 6.0, tvOS 13.0, *)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to be a bore here, but you'll need the license header on this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point, added

public typealias CryptoError = CryptoKitError
@available(iOS 14, macOS 11, tvOS 14, watchOS 7, *)
public typealias CryptoASN1Error = CryptoKitASN1Error
8 changes: 4 additions & 4 deletions Sources/_CryptoExtras/MLDSA/MLDSA65_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension MLDSA65 {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 32 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 32 bytes long.
public init(seedRepresentation: some DataProtocol) throws {
self.backing = try Backing(seedRepresentation: seedRepresentation)
}
Expand Down Expand Up @@ -111,7 +111,7 @@ extension MLDSA65 {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 32 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 32 bytes long.
init(seedRepresentation: some DataProtocol) throws {
guard seedRepresentation.count == MLDSA65.seedByteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down Expand Up @@ -191,7 +191,7 @@ extension MLDSA65 {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
public init(rawRepresentation: some DataProtocol) throws {
self.backing = try Backing(rawRepresentation: rawRepresentation)
}
Expand Down Expand Up @@ -244,7 +244,7 @@ extension MLDSA65 {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
init(rawRepresentation: some DataProtocol) throws {
guard rawRepresentation.count == MLDSA65.PublicKey.Backing.byteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down
24 changes: 12 additions & 12 deletions Sources/_CryptoExtras/MLKEM/MLKEM_boring.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extension MLKEM768 {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
public init(seedRepresentation: some DataProtocol) throws {
self.backing = try Backing(seedRepresentation: seedRepresentation)
}
Expand All @@ -65,7 +65,7 @@ extension MLKEM768 {
///
/// - Parameter encapsulated: The encapsulated shared secret.
///
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
///
/// - Returns: The symmetric key.
public func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
Expand Down Expand Up @@ -104,7 +104,7 @@ extension MLKEM768 {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
init(seedRepresentation: some DataProtocol) throws {
guard seedRepresentation.count == MLKEM.seedByteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down Expand Up @@ -135,7 +135,7 @@ extension MLKEM768 {
///
/// - Parameter encapsulated: The encapsulated shared secret.
///
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
///
/// - Returns: The symmetric key.
func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
Expand Down Expand Up @@ -184,7 +184,7 @@ extension MLKEM768 {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
public init(rawRepresentation: some DataProtocol) throws {
self.backing = try Backing(rawRepresentation: rawRepresentation)
}
Expand Down Expand Up @@ -216,7 +216,7 @@ extension MLKEM768 {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
init(rawRepresentation: some DataProtocol) throws {
guard rawRepresentation.count == MLKEM768.PublicKey.byteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down Expand Up @@ -317,7 +317,7 @@ extension MLKEM1024 {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
public init(seedRepresentation: some DataProtocol) throws {
self.backing = try Backing(seedRepresentation: seedRepresentation)
}
Expand All @@ -336,7 +336,7 @@ extension MLKEM1024 {
///
/// - Parameter encapsulated: The encapsulated shared secret.
///
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
///
/// - Returns: The symmetric key.
public func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
Expand Down Expand Up @@ -375,7 +375,7 @@ extension MLKEM1024 {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
init(seedRepresentation: some DataProtocol) throws {
guard seedRepresentation.count == MLKEM.seedByteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down Expand Up @@ -406,7 +406,7 @@ extension MLKEM1024 {
///
/// - Parameter encapsulated: The encapsulated shared secret.
///
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
///
/// - Returns: The symmetric key.
func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
Expand Down Expand Up @@ -455,7 +455,7 @@ extension MLKEM1024 {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
public init(rawRepresentation: some DataProtocol) throws {
self.backing = try Backing(rawRepresentation: rawRepresentation)
}
Expand Down Expand Up @@ -487,7 +487,7 @@ extension MLKEM1024 {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
init(rawRepresentation: some DataProtocol) throws {
guard rawRepresentation.count == MLKEM1024.PublicKey.byteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down
12 changes: 6 additions & 6 deletions Sources/_CryptoExtras/MLKEM/MLKEM_boring.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extension MLKEM${parameter_set} {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
public init(seedRepresentation: some DataProtocol) throws {
self.backing = try Backing(seedRepresentation: seedRepresentation)
}
Expand All @@ -69,7 +69,7 @@ extension MLKEM${parameter_set} {
///
/// - Parameter encapsulated: The encapsulated shared secret.
///
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
///
/// - Returns: The symmetric key.
public func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
Expand Down Expand Up @@ -108,7 +108,7 @@ extension MLKEM${parameter_set} {
///
/// - Parameter seedRepresentation: The seed to use to generate the private key.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the seed is not 64 bytes long.
/// - Throws: `CryptoError.incorrectKeySize` if the seed is not 64 bytes long.
init(seedRepresentation: some DataProtocol) throws {
guard seedRepresentation.count == MLKEM.seedByteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down Expand Up @@ -139,7 +139,7 @@ extension MLKEM${parameter_set} {
///
/// - Parameter encapsulated: The encapsulated shared secret.
///
/// - Throws: `CryptoKitError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
/// - Throws: `CryptoError.incorrectParameterSize` if the encapsulated shared secret is not 1088 bytes long.
///
/// - Returns: The symmetric key.
func decapsulate(_ encapsulated: some DataProtocol) throws -> SymmetricKey {
Expand Down Expand Up @@ -188,7 +188,7 @@ extension MLKEM${parameter_set} {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
public init(rawRepresentation: some DataProtocol) throws {
self.backing = try Backing(rawRepresentation: rawRepresentation)
}
Expand Down Expand Up @@ -220,7 +220,7 @@ extension MLKEM${parameter_set} {
///
/// - Parameter rawRepresentation: The public key bytes.
///
/// - Throws: `CryptoKitError.incorrectKeySize` if the raw representation is not the correct size.
/// - Throws: `CryptoError.incorrectKeySize` if the raw representation is not the correct size.
init(rawRepresentation: some DataProtocol) throws {
guard rawRepresentation.count == MLKEM${parameter_set}.PublicKey.byteCount else {
throw CryptoKitError.incorrectKeySize
Expand Down
4 changes: 2 additions & 2 deletions Sources/_CryptoExtras/RSA/RSA+BlindSigning.swift
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ extension _RSA.BlindSigning.PublicKey {
extension _RSA.BlindSigning {
/// Errors defined in the RSA Blind Signatures protocol.
///
/// - NOTE: This type does not conform to `Swift.Error`, it is used to construct a `CryptoKitError`.
/// - NOTE: This type does not conform to `Swift.Error`, it is used to construct a `CryptoError`.
///
/// - Seealso: [RFC 9474: Errors](https://www.rfc-editor.org/rfc/rfc9474.html#name-errors).
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
Expand All @@ -512,7 +512,7 @@ extension _RSA.BlindSigning {

@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, macCatalyst 13, visionOS 1.0, *)
extension CryptoKitError {
/// Map an error from the RSA Blind Signatures protocol to a CryptoKitError.
/// Map an error from the RSA Blind Signatures protocol to a CryptoError.
init(_ error: _RSA.BlindSigning.ProtocolError) {
switch error {
case .messageTooLong:
Expand Down