diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index e511476d..0455c8f6 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -53,7 +53,6 @@ jobs: { "targets": [ { "name": "CCryptoBoringSSL", "type": "source", "exceptions": [] }, - { "name": "CCryptoBoringSSLShims", "type": "source", "exceptions": [] }, { "name": "CryptoBoringWrapper", "type": "source", "exceptions": [] }, { "name": "CXKCP", "type": "source", "exceptions": [] }, { "name": "CXKCPShims", "type": "source", "exceptions": [] }, diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9b4c6ded..f8ad0fbf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -69,7 +69,7 @@ act --container-architecture linux/amd64 pull_request -j cmake-lists -W ./.githu You can find the underlying script at https://github.com/apple/swift-nio/blob/main/scripts/update-cmake-lists.sh . Using the script directly is less straightforwards because it requires you to pass the JSON config from the `pull_request.yml` file into the script, such as: ``` -curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON='{"targets":[{"name":"CCryptoBoringSSL","type":"source","exceptions":[]},{"name":"CCryptoBoringSSLShims","type":"source","exceptions":[]},{"name":"CryptoBoringWrapper","type":"source","exceptions":[]},{"name":"Crypto","type":"source","exceptions":[]},{"name":"CryptoExtras","type":"source","exceptions":[]},{"name":"CCryptoBoringSSL","type":"assembly","exceptions":["*/AES/*.swift"]}]}' bash +curl -s https://raw.githubusercontent.com/apple/swift-nio/main/scripts/update-cmake-lists.sh | CONFIG_JSON='{"targets":[{"name":"CCryptoBoringSSL","type":"source","exceptions":[]},{"name":"CryptoBoringWrapper","type":"source","exceptions":[]},{"name":"Crypto","type":"source","exceptions":[]},{"name":"CryptoExtras","type":"source","exceptions":[]},{"name":"CCryptoBoringSSL","type":"assembly","exceptions":["*/AES/*.swift"]}]}' bash ``` ## API Evolution diff --git a/Package.swift b/Package.swift index 5dedf462..13c452ef 100644 --- a/Package.swift +++ b/Package.swift @@ -126,14 +126,6 @@ let package = Package( .disableWarning("macro-redefined"), ] ), - .target( - name: "CCryptoBoringSSLShims", - dependencies: ["CCryptoBoringSSL"], - exclude: privacyManifestExclude + [ - "CMakeLists.txt" - ], - resources: privacyManifestResource - ), .target( name: "CXKCPShims", dependencies: ["CXKCP"], @@ -146,7 +138,6 @@ let package = Package( name: "Crypto", dependencies: [ .target(name: "CCryptoBoringSSL", condition: .when(platforms: nonDarwinPlatforms)), - .target(name: "CCryptoBoringSSLShims", condition: .when(platforms: nonDarwinPlatforms)), .target(name: "CryptoBoringWrapper", condition: .when(platforms: nonDarwinPlatforms)), .target(name: "CXKCP", condition: .when(platforms: nonDarwinPlatforms)), .target(name: "CXKCPShims", condition: .when(platforms: nonDarwinPlatforms)), @@ -164,7 +155,6 @@ let package = Package( name: "CryptoExtras", dependencies: [ "CCryptoBoringSSL", - "CCryptoBoringSSLShims", "CryptoBoringWrapper", "Crypto", .product(name: "SwiftASN1", package: "swift-asn1"), @@ -186,7 +176,6 @@ let package = Package( name: "CryptoBoringWrapper", dependencies: [ "CCryptoBoringSSL", - "CCryptoBoringSSLShims", ], exclude: privacyManifestExclude + [ "CMakeLists.txt" diff --git a/Sources/CCryptoBoringSSLShims/CMakeLists.txt b/Sources/CCryptoBoringSSLShims/CMakeLists.txt deleted file mode 100644 index 73d5e085..00000000 --- a/Sources/CCryptoBoringSSLShims/CMakeLists.txt +++ /dev/null @@ -1,29 +0,0 @@ -##===----------------------------------------------------------------------===## -## -## This source file is part of the SwiftCrypto open source project -## -## Copyright (c) 2021 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 -## -##===----------------------------------------------------------------------===## - -add_library(CCryptoBoringSSLShims STATIC - "shims.c" -) - -target_include_directories(CCryptoBoringSSLShims PUBLIC - include - $) - -target_link_libraries(CCryptoBoringSSLShims PUBLIC - CCryptoBoringSSL) - -set_target_properties(CCryptoBoringSSLShims PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) - -set_property(GLOBAL APPEND PROPERTY SWIFT_CRYPTO_EXPORTS CCryptoBoringSSLShims) diff --git a/Sources/CCryptoBoringSSLShims/PrivacyInfo.xcprivacy b/Sources/CCryptoBoringSSLShims/PrivacyInfo.xcprivacy deleted file mode 100644 index 1a71db6f..00000000 --- a/Sources/CCryptoBoringSSLShims/PrivacyInfo.xcprivacy +++ /dev/null @@ -1,15 +0,0 @@ - - - - - NSPrivacyTracking - - NSPrivacyAccessedAPITypes - - NSPrivacyCollectedDataTypes - - NSPrivacyTrackingDomains - - - - diff --git a/Sources/CCryptoBoringSSLShims/include/CCryptoBoringSSLShims.h b/Sources/CCryptoBoringSSLShims/include/CCryptoBoringSSLShims.h deleted file mode 100644 index c99ff507..00000000 --- a/Sources/CCryptoBoringSSLShims/include/CCryptoBoringSSLShims.h +++ /dev/null @@ -1,155 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftCrypto open source project -// -// Copyright (c) 2019 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 -// -//===----------------------------------------------------------------------===// -#ifndef C_CRYPTO_BORINGSSL_SHIMS_H -#define C_CRYPTO_BORINGSSL_SHIMS_H - -// This is for instances when `swift package generate-xcodeproj` is used as CCryptoBoringSSL -// is treated as a framework and requires the framework's name as a prefix. -#if __has_include() -#include -#else -#include -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -// MARK:- Pointer type shims -// This section of the code handles shims that change uint8_t* pointers to -// void *s. This is done because Swift does not have the rule that C does, that -// pointers to uint8_t can safely alias any other pointer. That means that Swift -// Unsafe[Mutable]RawPointer cannot be passed to uint8_t * APIs, which is very -// awkward, so we shim these to avoid the need to call bindMemory in Swift (which is -// wrong). -// -// Our relevant citation is: https://github.com/apple/swift-nio-extras/pull/56#discussion_r329330295. -// We want this to land: https://bugs.swift.org/browse/SR-11087. Once that lands we can remove these -// shims. -int CCryptoBoringSSLShims_EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, - const void *key, size_t key_len, size_t tag_len, - ENGINE *impl); - -int CCryptoBoringSSLShims_EVP_AEAD_CTX_seal_scatter( - const EVP_AEAD_CTX *ctx, - void *out, - void *out_tag, - size_t *out_tag_len, - size_t max_out_tag_len, - const void *nonce, - size_t nonce_len, - const void *in, - size_t in_len, - const void *extra_in, - size_t extra_in_len, - const void *ad, - size_t ad_len); - -int CCryptoBoringSSLShims_EVP_AEAD_CTX_open_gather(const EVP_AEAD_CTX *ctx, void *out, - const void *nonce, size_t nonce_len, - const void *in, size_t in_len, - const void *in_tag, size_t in_tag_len, - const void *ad, size_t ad_len); - - -int CCryptoBoringSSLShims_EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, void *out, size_t *out_len, size_t max_out_len, - const void *nonce, size_t nonce_len, - const void *in, size_t in_len, - const void *ad, size_t ad_len); - - -void CCryptoBoringSSLShims_ED25519_keypair(void *out_public_key, void *out_private_key); - -void CCryptoBoringSSLShims_ED25519_keypair_from_seed(void *out_public_key, - void *out_private_key, - const void *seed); - -ECDSA_SIG *CCryptoBoringSSLShims_ECDSA_do_sign(const void *digest, size_t digest_len, - const EC_KEY *eckey); - -int CCryptoBoringSSLShims_ECDSA_do_verify(const void *digest, size_t digest_len, - const ECDSA_SIG *sig, const EC_KEY *eckey); - -void CCryptoBoringSSLShims_X25519_keypair(void *out_public_value, void *out_private_key); - -void CCryptoBoringSSLShims_X25519_public_from_private(void *out_public_value, - const void *private_key); - -int CCryptoBoringSSLShims_X25519(void *out_shared_key, const void *private_key, - const void *peer_public_value); - -ECDSA_SIG *CCryptoBoringSSLShims_ECDSA_SIG_from_bytes(const void *in, size_t in_len); - -int CCryptoBoringSSLShims_ED25519_verify(const void *message, size_t message_len, - const void *signature, const void *public_key); - -int CCryptoBoringSSLShims_ED25519_sign(void *out_sig, const void *message, - size_t message_len, const void *private_key); - -BIGNUM *CCryptoBoringSSLShims_BN_bin2bn(const void *in, size_t len, BIGNUM *ret); - -size_t CCryptoBoringSSLShims_BN_bn2bin(const BIGNUM *in, void *out); - -int CCryptoBoringSSLShims_BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx); - -int CCryptoBoringSSLShims_RSA_verify(int hash_nid, const void *msg, size_t msg_len, - const void *sig, size_t sig_len, RSA *rsa); - -int CCryptoBoringSSLShims_RSA_verify_pss_mgf1(RSA *rsa, const void *msg, - size_t msg_len, const EVP_MD *md, - const EVP_MD *mgf1_md, int salt_len, - const void *sig, size_t sig_len); - -int CCryptoBoringSSLShims_RSA_sign(int hash_nid, const void *in, - unsigned int in_len, void *out, - unsigned int *out_len, RSA *rsa); - -int CCryptoBoringSSLShims_RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, void *out, - size_t max_out, const void *in, - size_t in_len, const EVP_MD *md, - const EVP_MD *mgf1_md, int salt_len); - -int CCryptoBoringSSLShims_RSA_public_encrypt(int flen, const void *from, void *to, - RSA *rsa, int padding); - -int CCryptoBoringSSLShims_RSA_private_decrypt(int flen, const void *from, void *to, - RSA *rsa, int padding); - -int CCryptoBoringSSLShims_EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, void *out, - size_t *out_len, const void *in, - size_t in_len); - -int CCryptoBoringSSLShims_EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, void *out, - size_t *out_len, const void *in, - size_t in_len); - -int CCryptoBoringSSLShims_EC_hash_to_curve_p256_xmd_sha256_sswu(const EC_GROUP *group, EC_POINT *out, - const void *dst, size_t dst_len, - const void *msg, size_t msg_len); - -int CCryptoBoringSSLShims_EC_hash_to_curve_p384_xmd_sha384_sswu(const EC_GROUP *group, EC_POINT *out, - const void *dst, size_t dst_len, - const void *msg, size_t msg_len); - -size_t CCryptoBoringSSLShims_EC_POINT_point2oct(const EC_GROUP *group, - const EC_POINT *point, - point_conversion_form_t form, - void *buf, size_t max_out, - BN_CTX *ctx); - -#if defined(__cplusplus) -} -#endif // defined(__cplusplus) - -#endif // C_CRYPTO_BORINGSSL_SHIMS_H diff --git a/Sources/CCryptoBoringSSLShims/include/module.modulemap b/Sources/CCryptoBoringSSLShims/include/module.modulemap deleted file mode 100644 index 533962ae..00000000 --- a/Sources/CCryptoBoringSSLShims/include/module.modulemap +++ /dev/null @@ -1,4 +0,0 @@ -module CCryptoBoringSSLShims { - header "CCryptoBoringSSLShims.h" - export * -} diff --git a/Sources/CCryptoBoringSSLShims/shims.c b/Sources/CCryptoBoringSSLShims/shims.c deleted file mode 100644 index df8178c4..00000000 --- a/Sources/CCryptoBoringSSLShims/shims.c +++ /dev/null @@ -1,190 +0,0 @@ -//===----------------------------------------------------------------------===// -// -// This source file is part of the SwiftCrypto open source project -// -// Copyright (c) 2019 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 -// -//===----------------------------------------------------------------------===// -#include - -// MARK:- Pointer type shims -// This section of the code handles shims that change uint8_t* pointers to -// void *s. This is done because Swift does not have the rule that C does, that -// pointers to uint8_t can safely alias any other pointer. That means that Swift -// Unsafe[Mutable]RawPointer cannot be passed to uint8_t * APIs, which is very -// awkward, so we shim these to avoid the need to call bindMemory in Swift (which is -// wrong). -// -// Our relevant citation is: https://github.com/apple/swift-nio-extras/pull/56#discussion_r329330295. -// We want this to land: https://bugs.swift.org/browse/SR-11087. Once that lands we can remove these -// shims. -int CCryptoBoringSSLShims_EVP_AEAD_CTX_init(EVP_AEAD_CTX *ctx, const EVP_AEAD *aead, - const void *key, size_t key_len, size_t tag_len, - ENGINE *impl) { - return CCryptoBoringSSL_EVP_AEAD_CTX_init(ctx, aead, key, key_len, tag_len, impl); -} - -int CCryptoBoringSSLShims_EVP_AEAD_CTX_seal_scatter( - const EVP_AEAD_CTX *ctx, - void *out, - void *out_tag, - size_t *out_tag_len, - size_t max_out_tag_len, - const void *nonce, - size_t nonce_len, - const void *in, - size_t in_len, - const void *extra_in, - size_t extra_in_len, - const void *ad, - size_t ad_len) { - return CCryptoBoringSSL_EVP_AEAD_CTX_seal_scatter(ctx, out, out_tag, out_tag_len, max_out_tag_len, nonce, nonce_len, in, in_len, extra_in, extra_in_len, ad, ad_len); -} - -int CCryptoBoringSSLShims_EVP_AEAD_CTX_open_gather(const EVP_AEAD_CTX *ctx, void *out, - const void *nonce, size_t nonce_len, - const void *in, size_t in_len, - const void *in_tag, size_t in_tag_len, - const void *ad, size_t ad_len) { - return CCryptoBoringSSL_EVP_AEAD_CTX_open_gather(ctx, out, nonce, nonce_len, in, in_len, in_tag, in_tag_len, ad, ad_len); -} - -int CCryptoBoringSSLShims_EVP_AEAD_CTX_open(const EVP_AEAD_CTX *ctx, void *out, size_t *out_len, size_t max_out_len, - const void *nonce, size_t nonce_len, - const void *in, size_t in_len, - const void *ad, size_t ad_len) { - return CCryptoBoringSSL_EVP_AEAD_CTX_open(ctx, out, out_len, max_out_len, nonce, nonce_len, in, in_len, ad, ad_len); -} - -void CCryptoBoringSSLShims_ED25519_keypair(void *out_public_key, void *out_private_key) { - CCryptoBoringSSL_ED25519_keypair(out_public_key, out_private_key); -} - -void CCryptoBoringSSLShims_ED25519_keypair_from_seed(void *out_public_key, - void *out_private_key, - const void *seed) { - CCryptoBoringSSL_ED25519_keypair_from_seed(out_public_key, out_private_key, seed); -} - -ECDSA_SIG *CCryptoBoringSSLShims_ECDSA_do_sign(const void *digest, size_t digest_len, - const EC_KEY *eckey) { - return CCryptoBoringSSL_ECDSA_do_sign(digest, digest_len, eckey); -} - -int CCryptoBoringSSLShims_ECDSA_do_verify(const void *digest, size_t digest_len, - const ECDSA_SIG *sig, const EC_KEY *eckey) { - return CCryptoBoringSSL_ECDSA_do_verify(digest, digest_len, sig, eckey); -} - -void CCryptoBoringSSLShims_X25519_keypair(void *out_public_value, void *out_private_key) { - CCryptoBoringSSL_X25519_keypair(out_public_value, out_private_key); -} - -void CCryptoBoringSSLShims_X25519_public_from_private(void *out_public_value, - const void *private_key) { - CCryptoBoringSSL_X25519_public_from_private(out_public_value, private_key); -} - -int CCryptoBoringSSLShims_X25519(void *out_shared_key, const void *private_key, - const void *peer_public_value) { - return CCryptoBoringSSL_X25519(out_shared_key, private_key, peer_public_value); -} - -ECDSA_SIG *CCryptoBoringSSLShims_ECDSA_SIG_from_bytes(const void *in, size_t in_len) { - return CCryptoBoringSSL_ECDSA_SIG_from_bytes(in, in_len); -} - -int CCryptoBoringSSLShims_ED25519_verify(const void *message, size_t message_len, - const void *signature, const void *public_key) { - return CCryptoBoringSSL_ED25519_verify(message, message_len, signature, public_key); -} - -int CCryptoBoringSSLShims_ED25519_sign(void *out_sig, const void *message, - size_t message_len, const void *private_key) { - return CCryptoBoringSSL_ED25519_sign(out_sig, message, message_len, private_key); -} - -BIGNUM *CCryptoBoringSSLShims_BN_bin2bn(const void *in, size_t len, BIGNUM *ret) { - return CCryptoBoringSSL_BN_bin2bn(in, len, ret); -} - -size_t CCryptoBoringSSLShims_BN_bn2bin(const BIGNUM *in, void *out) { - return CCryptoBoringSSL_BN_bn2bin(in, out); -} - -int CCryptoBoringSSLShims_BN_mod(BIGNUM *rem, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) { - return BN_mod(rem, a, m, ctx); -} - -int CCryptoBoringSSLShims_RSA_verify(int hash_nid, const void *msg, size_t msg_len, - const void *sig, size_t sig_len, RSA *rsa) { - return CCryptoBoringSSL_RSA_verify(hash_nid, msg, msg_len, sig, sig_len, rsa); -} - -int CCryptoBoringSSLShims_RSA_verify_pss_mgf1(RSA *rsa, const void *msg, - size_t msg_len, const EVP_MD *md, - const EVP_MD *mgf1_md, int salt_len, - const void *sig, size_t sig_len) { - return CCryptoBoringSSL_RSA_verify_pss_mgf1(rsa, msg, msg_len, md, mgf1_md, salt_len, sig, sig_len); -} - -int CCryptoBoringSSLShims_RSA_sign(int hash_nid, const void *in, - unsigned int in_len, void *out, - unsigned int *out_len, RSA *rsa) { - return CCryptoBoringSSL_RSA_sign(hash_nid, in, in_len, out, out_len, rsa); -} - -int CCryptoBoringSSLShims_RSA_sign_pss_mgf1(RSA *rsa, size_t *out_len, void *out, - size_t max_out, const void *in, - size_t in_len, const EVP_MD *md, - const EVP_MD *mgf1_md, int salt_len) { - return CCryptoBoringSSL_RSA_sign_pss_mgf1(rsa, out_len, out, max_out, in, in_len, md, mgf1_md, salt_len); -} - -int CCryptoBoringSSLShims_RSA_public_encrypt(int flen, const void *from, void *to, - RSA *rsa, int padding) { - return CCryptoBoringSSL_RSA_public_encrypt(flen, from, to, rsa, padding); -} - -int CCryptoBoringSSLShims_RSA_private_decrypt(int flen, const void *from, void *to, - RSA *rsa, int padding) { - return CCryptoBoringSSL_RSA_private_decrypt(flen, from, to, rsa, padding); -} - -int CCryptoBoringSSLShims_EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, void *out, - size_t *out_len, const void *in, - size_t in_len) { - return CCryptoBoringSSL_EVP_PKEY_encrypt(ctx, out, out_len, in, in_len); -} - -int CCryptoBoringSSLShims_EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, void *out, - size_t *out_len, const void *in, - size_t in_len) { - return CCryptoBoringSSL_EVP_PKEY_decrypt(ctx, out, out_len, in, in_len); -} - -int CCryptoBoringSSLShims_EC_hash_to_curve_p256_xmd_sha256_sswu(const EC_GROUP *group, EC_POINT *out, - const void *dst, size_t dst_len, - const void *msg, size_t msg_len) { - return CCryptoBoringSSL_EC_hash_to_curve_p256_xmd_sha256_sswu(group, out, dst, dst_len, msg, msg_len); -} - -int CCryptoBoringSSLShims_EC_hash_to_curve_p384_xmd_sha384_sswu(const EC_GROUP *group, EC_POINT *out, - const void *dst, size_t dst_len, - const void *msg, size_t msg_len) { - return CCryptoBoringSSL_EC_hash_to_curve_p384_xmd_sha384_sswu(group, out, dst, dst_len, msg, msg_len); -} - -size_t CCryptoBoringSSLShims_EC_POINT_point2oct(const EC_GROUP *group, - const EC_POINT *point, - point_conversion_form_t form, - void *buf, size_t max_out, - BN_CTX *ctx) { - return CCryptoBoringSSL_EC_POINT_point2oct(group, point, form, buf, max_out, ctx); -} diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 4616a1f1..3803cfe6 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -13,7 +13,6 @@ ##===----------------------------------------------------------------------===## add_subdirectory(CCryptoBoringSSL) -add_subdirectory(CCryptoBoringSSLShims) add_subdirectory(CXKCP) add_subdirectory(CXKCPShims) add_subdirectory(CryptoBoringWrapper) diff --git a/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift b/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift index 215fb6bd..3e27bb1a 100644 --- a/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift +++ b/Sources/Crypto/AEADs/ChachaPoly/BoringSSL/ChaChaPoly_boring.swift @@ -16,10 +16,8 @@ #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) diff --git a/Sources/Crypto/CMakeLists.txt b/Sources/Crypto/CMakeLists.txt index 9800af02..c528ab9d 100644 --- a/Sources/Crypto/CMakeLists.txt +++ b/Sources/Crypto/CMakeLists.txt @@ -117,7 +117,6 @@ target_compile_definitions(Crypto PRIVATE target_include_directories(Crypto PRIVATE $ - $ $ $ $) @@ -125,7 +124,6 @@ target_link_libraries(Crypto PUBLIC $<$>:dispatch> $<$>:Foundation> CCryptoBoringSSL - CCryptoBoringSSLShims CryptoBoringWrapper CXKCP CXKCPShims) diff --git a/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift b/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift index 52ff9fbd..29b74c42 100644 --- a/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift +++ b/Sources/Crypto/Key Wrapping/BoringSSL/AESWrap_boring.swift @@ -33,12 +33,8 @@ enum BoringSSLAESWRAPImpl { let rc = try key.withUnsafeAESKEY(mode: .encrypting) { aesKey in output.withUnsafeMutableBytes { outputPtr -> CInt in - // Memory bind is safe: we cannot alias the pointer here. - let outputPtr = outputPtr.bindMemory(to: UInt8.self) - return keyToWrap.withUnsafeBytes { keyToWrapPtr -> CInt in - // Memory bind is safe: we cannot alias the pointer here. - let keyToWrapPtr = keyToWrapPtr.bindMemory(to: UInt8.self) - return CCryptoBoringSSL_AES_wrap_key( + keyToWrap.withUnsafeBytes { keyToWrapPtr -> CInt in + CCryptoBoringSSL_AES_wrap_key( aesKey, nil, outputPtr.baseAddress, @@ -78,8 +74,6 @@ enum BoringSSLAESWRAPImpl { ) throws -> SymmetricKey { let unwrapped = try contiguousWrappedKey.withUnsafeBytes { inPtr in try [UInt8](unsafeUninitializedCapacity: inPtr.count) { outputPtr, count in - // Bind is safe: we cannot violate the aliasing rules here as we never call to arbitrary code. - let inPtr = inPtr.bindMemory(to: UInt8.self) let rc = try key.withUnsafeAESKEY(mode: .decrypting) { aesKey in CCryptoBoringSSL_AES_unwrap_key( aesKey, @@ -117,8 +111,6 @@ extension SymmetricKey { _ body: (UnsafePointer) throws -> ResultType ) throws -> ResultType { try self.withUnsafeBytes { bytesPointer in - // Bind is safe: cannot alias the pointer here. - let bytesPointer = bytesPointer.bindMemory(to: UInt8.self) var aesKey = AES_KEY() let bitsInKey = UInt32(bytesPointer.count * 8) diff --git a/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift index 466e8d68..504ba903 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/Ed25519_boring.swift @@ -16,10 +16,8 @@ #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 @@ -46,7 +44,7 @@ extension Curve25519.Signing { privateKeyBytes in privateKeyBytes = 64 publicKey.withUnsafeMutableBytes { publicKeyPtr in - CCryptoBoringSSLShims_ED25519_keypair( + CCryptoBoringSSL_ED25519_keypair( publicKeyPtr.baseAddress, privateKeyPtr.baseAddress ) @@ -80,7 +78,7 @@ extension Curve25519.Signing { privateKeyBytes in privateKeyBytes = 64 publicKey.withUnsafeMutableBytes { publicKeyPtr in - CCryptoBoringSSLShims_ED25519_keypair_from_seed( + CCryptoBoringSSL_ED25519_keypair_from_seed( publicKeyPtr.baseAddress, privateKeyPtr.baseAddress, seedPtr.baseAddress diff --git a/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift index 1443e4d0..810b63cc 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/NISTCurvesKeys_boring.swift @@ -16,10 +16,8 @@ #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) @@ -335,7 +333,7 @@ class BoringSSLECPrivateKeyWrapper: @unchecked func sign(digest: D) throws -> ECDSASignature { let optionalRawSignature: UnsafeMutablePointer? = digest.withUnsafeBytes { digestPtr in - CCryptoBoringSSLShims_ECDSA_do_sign(digestPtr.baseAddress, digestPtr.count, self.key) + CCryptoBoringSSL_ECDSA_do_sign(digestPtr.baseAddress, digestPtr.count, self.key) } guard let rawSignature = optionalRawSignature else { throw CryptoKitError.internalBoringSSLError() @@ -575,7 +573,7 @@ class BoringSSLECPublicKeyWrapper: @unchecked func isValidSignature(_ signature: ECDSASignature, for digest: D) -> Bool { let rc: CInt = signature.withUnsafeSignaturePointer { signaturePointer in digest.withUnsafeBytes { digestPointer in - CCryptoBoringSSLShims_ECDSA_do_verify( + CCryptoBoringSSL_ECDSA_do_verify( digestPointer.baseAddress, digestPointer.count, signaturePointer, diff --git a/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift b/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift index 981c5de8..91c8ffc7 100644 --- a/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift +++ b/Sources/Crypto/Keys/EC/BoringSSL/X25519Keys_boring.swift @@ -16,10 +16,8 @@ #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 @@ -77,7 +75,7 @@ extension Curve25519.KeyAgreement { publicKey.withUnsafeMutableBytes { publicKeyBytes in precondition(publicKeyBytes.count >= Curve25519.KeyAgreement.keySizeBytes) precondition(privateKeyBytes.count >= Curve25519.KeyAgreement.keySizeBytes) - CCryptoBoringSSLShims_X25519_keypair( + CCryptoBoringSSL_X25519_keypair( publicKeyBytes.baseAddress, privateKeyBytes.baseAddress ) @@ -105,7 +103,7 @@ extension Curve25519.KeyAgreement { publicKeyBytes, publicKeySize in precondition(publicKeyBytes.count >= Curve25519.KeyAgreement.keySizeBytes) - CCryptoBoringSSLShims_X25519_public_from_private( + CCryptoBoringSSL_X25519_public_from_private( publicKeyBytes.baseAddress, privatePointer.baseAddress ) @@ -140,7 +138,7 @@ extension Curve25519.KeyAgreement { // politely describe as a "lack of consensus" as to whether crypto libraries should reject this secret. CryptoKit on Apple // platforms currently does not, so for the sake of conformance with our peer implementation I will also refuse to check it. // We may elect to revisit this decision if the security best-practice thinking changes. - CCryptoBoringSSLShims_X25519( + CCryptoBoringSSL_X25519( secretPointer.baseAddress, privateKeyPointer.baseAddress, publicKeyShare.keyBytes diff --git a/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift b/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift index a69baf20..15605ad4 100644 --- a/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift +++ b/Sources/Crypto/Message Authentication Codes/MessageAuthenticationCode.swift @@ -71,7 +71,7 @@ extension MessageAuthenticationCode { public func makeIterator() -> Array.Iterator { self.withUnsafeBytes({ (buffPtr) in - return Array(buffPtr.bindMemory(to: UInt8.self)).makeIterator() + return Array(buffPtr).makeIterator() }) } diff --git a/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift b/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift index a6b88eb8..6f39eda6 100644 --- a/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/ECDSASignature_boring.swift @@ -16,10 +16,8 @@ #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) @@ -36,7 +34,7 @@ class ECDSASignature { init(contiguousDERBytes derBytes: ContiguousBuffer) throws { self._baseSig = try derBytes.withUnsafeBytes { bytesPtr in guard - let sig = CCryptoBoringSSLShims_ECDSA_SIG_from_bytes(bytesPtr.baseAddress, bytesPtr.count) + let sig = CCryptoBoringSSL_ECDSA_SIG_from_bytes(bytesPtr.baseAddress, bytesPtr.count) else { throw CryptoKitError.internalBoringSSLError() } diff --git a/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift b/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift index 89d2e5be..ed012236 100644 --- a/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift +++ b/Sources/Crypto/Signatures/BoringSSL/EdDSA_boring.swift @@ -16,10 +16,8 @@ #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 @@ -94,7 +92,7 @@ extension Curve25519.Signing.PublicKey { precondition(signaturePointer.count == Curve25519.Signing.PublicKey.signatureByteCount) precondition(self.keyBytes.count == 32) let rc: CInt = self.keyBytes.withUnsafeBytes { keyBytesPtr in - CCryptoBoringSSLShims_ED25519_verify( + CCryptoBoringSSL_ED25519_verify( dataPointer.baseAddress, dataPointer.count, signaturePointer.baseAddress, @@ -133,7 +131,7 @@ extension Curve25519.Signing.PrivateKey { precondition(signaturePointer.count == Curve25519.Signing.PublicKey.signatureByteCount) precondition(keyPointer.count == ED25519_PRIVATE_KEY_LEN) - return CCryptoBoringSSLShims_ED25519_sign( + return CCryptoBoringSSL_ED25519_sign( signaturePointer.baseAddress, dataPointer.baseAddress, dataPointer.count, diff --git a/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift b/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift index fa716701..b30b121b 100644 --- a/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift +++ b/Sources/CryptoBoringWrapper/AEAD/BoringSSLAEAD.swift @@ -14,10 +14,8 @@ #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) @@ -52,7 +50,7 @@ extension BoringSSLAEAD { let rc: CInt = key.withUnsafeBytes { keyPointer in withUnsafeMutablePointer(to: &self.context) { contextPointer in // Create the AEAD context with a default tag length using the given key. - CCryptoBoringSSLShims_EVP_AEAD_CTX_init( + CCryptoBoringSSL_EVP_AEAD_CTX_init( contextPointer, cipher.boringSSLCipher, keyPointer.baseAddress, @@ -177,7 +175,7 @@ extension BoringSSLAEAD.AEADContext { return authenticatedData.withUnsafeBytes { authenticatedDataBuffer in nonce.withUnsafeBytes { nonceBuffer in - CCryptoBoringSSLShims_EVP_AEAD_CTX_seal_scatter( + CCryptoBoringSSL_EVP_AEAD_CTX_seal_scatter( contextPointer, messageBuffer.baseAddress, tagBuffer.baseAddress! + tagInitializedCount, @@ -319,7 +317,7 @@ extension BoringSSLAEAD.AEADContext { nonce.withUnsafeBytes { nonceBuffer in tag.withUnsafeBytes { tagBuffer in authenticatedData.withUnsafeBytes { adBuffer in - CCryptoBoringSSLShims_EVP_AEAD_CTX_open_gather( + CCryptoBoringSSL_EVP_AEAD_CTX_open_gather( contextPointer, messageBuffer.baseAddress, nonceBuffer.baseAddress, @@ -430,7 +428,7 @@ extension BoringSSLAEAD.AEADContext { var writtenBytes = 0 let rc = withUnsafePointer(to: &self.context) { contextPointer in - CCryptoBoringSSLShims_EVP_AEAD_CTX_open( + CCryptoBoringSSL_EVP_AEAD_CTX_open( contextPointer, outputBuffer.baseAddress, &writtenBytes, diff --git a/Sources/CryptoBoringWrapper/CMakeLists.txt b/Sources/CryptoBoringWrapper/CMakeLists.txt index 2dd5b575..bd9b9129 100644 --- a/Sources/CryptoBoringWrapper/CMakeLists.txt +++ b/Sources/CryptoBoringWrapper/CMakeLists.txt @@ -24,13 +24,11 @@ add_library(CryptoBoringWrapper STATIC ) target_include_directories(CryptoBoringWrapper PUBLIC - $ - $) + $) target_link_libraries(CryptoBoringWrapper PUBLIC $<$>:Foundation> - CCryptoBoringSSL - CCryptoBoringSSLShims) + CCryptoBoringSSL) target_compile_options(CryptoBoringWrapper PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS}) diff --git a/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift b/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift index 1ed46bb4..98fbea01 100644 --- a/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift +++ b/Sources/CryptoBoringWrapper/EC/EllipticCurvePoint.swift @@ -13,10 +13,8 @@ //===----------------------------------------------------------------------===// #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) @@ -494,29 +492,35 @@ extension EllipticCurvePoint { to group: BoringSSLEllipticCurveGroup, domainSeparationTag: DSTBytes ) throws { - let hashToCurveFunction = - switch group.curveName { - case .p256: CCryptoBoringSSLShims_EC_hash_to_curve_p256_xmd_sha256_sswu - case .p384: CCryptoBoringSSLShims_EC_hash_to_curve_p384_xmd_sha384_sswu - // BoringSSL has no P521 hash_to_curve API. - case .p521: throw CryptoBoringWrapperError.invalidParameter - case .none: throw CryptoBoringWrapperError.internalBoringSSLError() - } - try self.init(_pointAtInfinityOn: group) try msg.withUnsafeBytes { msgPtr in try group.withUnsafeGroupPointer { groupPtr in try domainSeparationTag.withUnsafeBytes { dstPtr in - guard - hashToCurveFunction( + let rc: CInt + switch group.curveName { + case .p256: + rc = CCryptoBoringSSL_EC_hash_to_curve_p256_xmd_sha256_sswu( groupPtr, self._basePoint, dstPtr.baseAddress, dstPtr.count, msgPtr.baseAddress, msgPtr.count - ) == 1 - else { throw CryptoBoringWrapperError.internalBoringSSLError() } + ) + case .p384: + rc = CCryptoBoringSSL_EC_hash_to_curve_p384_xmd_sha384_sswu( + groupPtr, + self._basePoint, + dstPtr.baseAddress, + dstPtr.count, + msgPtr.baseAddress, + msgPtr.count + ) + // BoringSSL has no P521 hash_to_curve API. + case .p521: throw CryptoBoringWrapperError.invalidParameter + case .none: throw CryptoBoringWrapperError.internalBoringSSLError() + } + guard rc == 1 else { throw CryptoBoringWrapperError.internalBoringSSLError() } } } } @@ -603,7 +607,7 @@ extension EllipticCurvePoint { let numBytesWritten = group.withUnsafeGroupPointer { groupPtr in buf.withUnsafeMutableBytes { bufPtr in - CCryptoBoringSSLShims_EC_POINT_point2oct( + CCryptoBoringSSL_EC_POINT_point2oct( groupPtr, self._basePoint, compressed ? POINT_CONVERSION_COMPRESSED : POINT_CONVERSION_UNCOMPRESSED, diff --git a/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift b/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift index 4e817f42..cf8673d4 100644 --- a/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift +++ b/Sources/CryptoBoringWrapper/Util/ArbitraryPrecisionInteger.swift @@ -14,10 +14,8 @@ #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) @@ -123,7 +121,7 @@ extension ArbitraryPrecisionInteger.BackingStorage { self.init() let rc: UnsafeMutablePointer? = bytes.withUnsafeBytes { bytesPointer in - CCryptoBoringSSLShims_BN_bin2bn( + CCryptoBoringSSL_BN_bin2bn( bytesPointer.baseAddress, bytesPointer.count, &self._backing @@ -459,7 +457,8 @@ extension ArbitraryPrecisionInteger { if nonNegative { CCryptoBoringSSL_BN_nnmod(resultPtr, selfPtr, modPtr, bnCtx) } else { - CCryptoBoringSSLShims_BN_mod(resultPtr, selfPtr, modPtr, bnCtx) + // BN_mod is a C macro for BN_div with a nil quotient; call that directly. + CCryptoBoringSSL_BN_div(nil, resultPtr, selfPtr, modPtr, bnCtx) } } } @@ -718,7 +717,7 @@ extension Data { assert(bytesPtr.count == byteCount) return integer.withUnsafeBignumPointer { bnPtr in - CCryptoBoringSSLShims_BN_bn2bin(bnPtr, bytesPtr.baseAddress!) + CCryptoBoringSSL_BN_bn2bin(bnPtr, bytesPtr.baseAddress!) } } diff --git a/Sources/CryptoExtras/AES/AES_GCM_SIV.swift b/Sources/CryptoExtras/AES/AES_GCM_SIV.swift index 5bf5b95f..92816be7 100644 --- a/Sources/CryptoExtras/AES/AES_GCM_SIV.swift +++ b/Sources/CryptoExtras/AES/AES_GCM_SIV.swift @@ -15,10 +15,8 @@ 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) diff --git a/Sources/CryptoExtras/AES/Block Function.swift b/Sources/CryptoExtras/AES/Block Function.swift index e90385a4..fed1ab67 100644 --- a/Sources/CryptoExtras/AES/Block Function.swift +++ b/Sources/CryptoExtras/AES/Block Function.swift @@ -15,10 +15,8 @@ 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) @@ -99,24 +97,18 @@ extension AES { precondition(payload.count == Int(Self.blockSize)) key.withUnsafeBytes { keyPtr in - // We bind both pointers here. These binds are not technically safe, but because we - // know the pointers don't persist they can't violate the aliasing rules. We really - // want a "with memory rebound" function but we don't have it yet. - let keyBytes = keyPtr.bindMemory(to: UInt8.self) - let blockBytes = payload.bindMemory(to: UInt8.self) - var key = AES_KEY() if permutation == .forward { - let rc = CCryptoBoringSSL_AES_set_encrypt_key(keyBytes.baseAddress, UInt32(keyBytes.count * 8), &key) + let rc = CCryptoBoringSSL_AES_set_encrypt_key(keyPtr.baseAddress, UInt32(keyPtr.count * 8), &key) precondition(rc == 0) - CCryptoBoringSSL_AES_encrypt(blockBytes.baseAddress, blockBytes.baseAddress, &key) + CCryptoBoringSSL_AES_encrypt(payload.baseAddress, payload.baseAddress, &key) } else { - let rc = CCryptoBoringSSL_AES_set_decrypt_key(keyBytes.baseAddress, UInt32(keyBytes.count * 8), &key) + let rc = CCryptoBoringSSL_AES_set_decrypt_key(keyPtr.baseAddress, UInt32(keyPtr.count * 8), &key) precondition(rc == 0) - CCryptoBoringSSL_AES_decrypt(blockBytes.baseAddress, blockBytes.baseAddress, &key) + CCryptoBoringSSL_AES_decrypt(payload.baseAddress, payload.baseAddress, &key) } } } diff --git a/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift b/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift index afa427b3..c28bac9e 100644 --- a/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift +++ b/Sources/CryptoExtras/AES/BoringSSL/AES_GCM_SIV_boring.swift @@ -19,10 +19,8 @@ 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) diff --git a/Sources/CryptoExtras/CMakeLists.txt b/Sources/CryptoExtras/CMakeLists.txt index 1a71ae68..edd56076 100644 --- a/Sources/CryptoExtras/CMakeLists.txt +++ b/Sources/CryptoExtras/CMakeLists.txt @@ -86,15 +86,13 @@ add_library(CryptoExtras target_compile_options(CryptoExtras PRIVATE -DCRYPTO_IN_SWIFTPM) target_include_directories(CryptoExtras PRIVATE - $ - $) + $) target_link_libraries(CryptoExtras PUBLIC $<$>:Foundation> Crypto CryptoBoringWrapper - CCryptoBoringSSL - CCryptoBoringSSLShims) + CCryptoBoringSSL) target_compile_options(CryptoExtras PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS}) diff --git a/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift b/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift index 45b13e7a..fa96b54c 100644 --- a/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift +++ b/Sources/CryptoExtras/ChaCha20CTR/BoringSSL/ChaCha20CTR_boring.swift @@ -17,10 +17,8 @@ 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) @@ -72,22 +70,15 @@ enum OpenSSLChaCha20CTRImpl { key.withUnsafeBytes { keyPtr in nonce.withUnsafeBytes { noncePtr in message.withUnsafeBytes { plaintextPtr in - // We bind all three pointers here. These binds are not technically safe, but because we - // know the pointers don't persist they can't violate the aliasing rules. We really - // want a "with memory rebound" function but we don't have it yet. - let keyBytes = keyPtr.bindMemory(to: UInt8.self) - let nonceBytes = noncePtr.bindMemory(to: UInt8.self) - let plaintext = plaintextPtr.bindMemory(to: UInt8.self) - - var ciphertext = Data(repeating: 0, count: plaintext.count) + var ciphertext = Data(repeating: 0, count: plaintextPtr.count) ciphertext.withUnsafeMutableBytes { ciphertext in CCryptoBoringSSL_CRYPTO_chacha_20( ciphertext.baseAddress, - plaintext.baseAddress, - plaintext.count, - keyBytes.baseAddress, - nonceBytes.baseAddress, + plaintextPtr.baseAddress, + plaintextPtr.count, + keyPtr.baseAddress, + noncePtr.baseAddress, counter ) } diff --git a/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift b/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift index c9fd91b1..4551189b 100644 --- a/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift +++ b/Sources/CryptoExtras/ChaCha20CTR/ChaCha20CTR.swift @@ -14,10 +14,8 @@ #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 diff --git a/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift b/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift index e096ddc8..2fce41a0 100644 --- a/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift +++ b/Sources/CryptoExtras/Key Derivation/PBKDF2/BoringSSL/PBKDF2_boring.swift @@ -22,10 +22,8 @@ import Foundation #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, *) diff --git a/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift b/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift index 719f295f..ce7cbca0 100644 --- a/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift +++ b/Sources/CryptoExtras/Key Derivation/Scrypt/BoringSSL/Scrypt_boring.swift @@ -16,10 +16,8 @@ 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 #if canImport(FoundationEssentials) diff --git a/Sources/CryptoExtras/RSA/RSA_boring.swift b/Sources/CryptoExtras/RSA/RSA_boring.swift index 2a8a1d4c..1b9fb274 100644 --- a/Sources/CryptoExtras/RSA/RSA_boring.swift +++ b/Sources/CryptoExtras/RSA/RSA_boring.swift @@ -18,10 +18,8 @@ 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) @@ -376,7 +374,7 @@ extension BoringSSLRSAPublicKey { let rc: CInt = digest.withUnsafeBytes { digestPtr in switch padding.backing { case .pkcs1v1_5: - return CCryptoBoringSSLShims_RSA_verify( + return CCryptoBoringSSL_RSA_verify( hashDigestType.nid, digestPtr.baseAddress, digestPtr.count, @@ -385,7 +383,7 @@ extension BoringSSLRSAPublicKey { rsaPublicKey ) case .pss: - return CCryptoBoringSSLShims_RSA_verify_pss_mgf1( + return CCryptoBoringSSL_RSA_verify_pss_mgf1( rsaPublicKey, digestPtr.baseAddress, digestPtr.count, @@ -396,7 +394,7 @@ extension BoringSSLRSAPublicKey { signaturePtr.count ) case .pssZero: - return CCryptoBoringSSLShims_RSA_verify_pss_mgf1( + return CCryptoBoringSSL_RSA_verify_pss_mgf1( rsaPublicKey, digestPtr.baseAddress, digestPtr.count, @@ -448,7 +446,7 @@ extension BoringSSLRSAPublicKey { } var writtenLength = bufferPtr.count - let rc = CCryptoBoringSSLShims_EVP_PKEY_encrypt( + let rc = CCryptoBoringSSL_EVP_PKEY_encrypt( ctx, bufferPtr.baseAddress, &writtenLength, @@ -863,10 +861,10 @@ extension BoringSSLRSAPrivateKey { switch padding.backing { case .pkcs1v1_5: var writtenLength = CUnsignedInt(0) - let rc = CCryptoBoringSSLShims_RSA_sign( + let rc = CCryptoBoringSSL_RSA_sign( hashDigestType.nid, digestPtr.baseAddress, - CUnsignedInt(digestPtr.count), + digestPtr.count, bufferPtr.baseAddress, &writtenLength, rsaPrivateKey @@ -874,7 +872,7 @@ extension BoringSSLRSAPrivateKey { outputLength = Int(writtenLength) return rc case .pss: - return CCryptoBoringSSLShims_RSA_sign_pss_mgf1( + return CCryptoBoringSSL_RSA_sign_pss_mgf1( rsaPrivateKey, &outputLength, bufferPtr.baseAddress, @@ -886,7 +884,7 @@ extension BoringSSLRSAPrivateKey { CInt(hashDigestType.digestLength) ) case .pssZero: - return CCryptoBoringSSLShims_RSA_sign_pss_mgf1( + return CCryptoBoringSSL_RSA_sign_pss_mgf1( rsaPrivateKey, &outputLength, bufferPtr.baseAddress, @@ -943,7 +941,7 @@ extension BoringSSLRSAPrivateKey { var writtenLength = bufferPtr.count - let rc = CCryptoBoringSSLShims_EVP_PKEY_decrypt( + let rc = CCryptoBoringSSL_EVP_PKEY_decrypt( ctx, bufferPtr.baseAddress, &writtenLength, diff --git a/Sources/CryptoExtras/Util/BoringSSLHelpers.swift b/Sources/CryptoExtras/Util/BoringSSLHelpers.swift index 5d4f4381..ddab8c82 100644 --- a/Sources/CryptoExtras/Util/BoringSSLHelpers.swift +++ b/Sources/CryptoExtras/Util/BoringSSLHelpers.swift @@ -15,10 +15,8 @@ // 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 diff --git a/Tests/CXKCPTests/CXKCPTests.swift b/Tests/CXKCPTests/CXKCPTests.swift index 652467ec..b9b1f432 100644 --- a/Tests/CXKCPTests/CXKCPTests.swift +++ b/Tests/CXKCPTests/CXKCPTests.swift @@ -24,7 +24,7 @@ final class CXKCPTests: XCTestCase { var output = [UInt8](repeating: 0, count: 32) let result = input.withUnsafeBytes { inputBytes in - SHA3_256(&output, inputBytes.bindMemory(to: UInt8.self).baseAddress, inputBytes.count) + SHA3_256(&output, inputBytes.baseAddress, inputBytes.count) } // Should return 0 on success @@ -43,7 +43,7 @@ final class CXKCPTests: XCTestCase { var output = [UInt8](repeating: 0, count: 28) let result = input.withUnsafeBytes { inputBytes in - SHA3_224(&output, inputBytes.bindMemory(to: UInt8.self).baseAddress, inputBytes.count) + SHA3_224(&output, inputBytes.baseAddress, inputBytes.count) } // Should return 0 on success @@ -62,7 +62,7 @@ final class CXKCPTests: XCTestCase { var output = [UInt8](repeating: 0, count: 48) let result = input.withUnsafeBytes { inputBytes in - SHA3_384(&output, inputBytes.bindMemory(to: UInt8.self).baseAddress, inputBytes.count) + SHA3_384(&output, inputBytes.baseAddress, inputBytes.count) } // Should return 0 on success @@ -82,7 +82,7 @@ final class CXKCPTests: XCTestCase { var output = [UInt8](repeating: 0, count: 64) let result = input.withUnsafeBytes { inputBytes in - SHA3_512(&output, inputBytes.bindMemory(to: UInt8.self).baseAddress, inputBytes.count) + SHA3_512(&output, inputBytes.baseAddress, inputBytes.count) } // Should return 0 on success @@ -102,7 +102,7 @@ final class CXKCPTests: XCTestCase { var output = [UInt8](repeating: 0, count: 32) // 256 bits output let result = input.withUnsafeBytes { inputBytes in - SHAKE128(&output, output.count, inputBytes.bindMemory(to: UInt8.self).baseAddress, inputBytes.count) + SHAKE128(&output, output.count, inputBytes.baseAddress, inputBytes.count) } // Should return 0 on success @@ -121,7 +121,7 @@ final class CXKCPTests: XCTestCase { var output = [UInt8](repeating: 0, count: 32) // 256 bits output let result = input.withUnsafeBytes { inputBytes in - SHAKE256(&output, output.count, inputBytes.bindMemory(to: UInt8.self).baseAddress, inputBytes.count) + SHAKE256(&output, output.count, inputBytes.baseAddress, inputBytes.count) } // Should return 0 on success