mirror of
https://github.com/apple/swift-crypto
synced 2026-11-22 04:30:39 +00:00
[5.x] Remove bindMemory(to:) calls and the CCryptoBoringSSLShims target (#455)
## Motivation Some of our calls to our C library dependencies use either a C shim layer or the use of `bindMemory(to:)`, neither of which are still required. The shims themselves cite that once SR-11087 lands, they are no longer needed. That issue was addressed and has been available in all the Swift versions this package currently supports. We can now remove most of these workarounds that add complexity to the C interop. ## Modifications - Remove uses of `bindMemory(to:)` calls since we can now pass the buffer pointer directly to these C functions now. - Replace use of `BN_mod` (macro, needed shim) with `BN_div` (no shim required). - Replace all other shims with call to corresponding un-shimmed function directly. - Remove shim target entirely from package. ## Result Less hand-rolled code for C interop, reducing complexity for project.
This commit is contained in:
1 parent
15b0fb5b45
commit
b3746b1441
33 files changed
+70
-532
No files matched your search
@@ -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": [] },
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>)
|
||||
|
||||
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)
|
||||
@@ -1,15 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>NSPrivacyTracking</key>
|
||||
<false/>
|
||||
<key>NSPrivacyAccessedAPITypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyCollectedDataTypes</key>
|
||||
<array/>
|
||||
<key>NSPrivacyTrackingDomains</key>
|
||||
<array/>
|
||||
</dict>
|
||||
</plist>
|
||||
|
||||
@@ -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(<CCryptoBoringSSL/CCryptoBoringSSL.h>)
|
||||
#include <CCryptoBoringSSL/CCryptoBoringSSL.h>
|
||||
#else
|
||||
#include <CCryptoBoringSSL.h>
|
||||
#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
|
||||
@@ -1,4 +0,0 @@
|
||||
module CCryptoBoringSSLShims {
|
||||
header "CCryptoBoringSSLShims.h"
|
||||
export *
|
||||
}
|
||||
@@ -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 <CCryptoBoringSSLShims.h>
|
||||
|
||||
// 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);
|
||||
}
|
||||
@@ -13,7 +13,6 @@
|
||||
##===----------------------------------------------------------------------===##
|
||||
|
||||
add_subdirectory(CCryptoBoringSSL)
|
||||
add_subdirectory(CCryptoBoringSSLShims)
|
||||
add_subdirectory(CXKCP)
|
||||
add_subdirectory(CXKCPShims)
|
||||
add_subdirectory(CryptoBoringWrapper)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -117,7 +117,6 @@ target_compile_definitions(Crypto PRIVATE
|
||||
|
||||
target_include_directories(Crypto PRIVATE
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSLShims,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CryptoBoringWrapper,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CXKCP,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CXKCPShims,INCLUDE_DIRECTORIES>)
|
||||
@@ -125,7 +124,6 @@ target_link_libraries(Crypto PUBLIC
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:dispatch>
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
|
||||
CCryptoBoringSSL
|
||||
CCryptoBoringSSLShims
|
||||
CryptoBoringWrapper
|
||||
CXKCP
|
||||
CXKCPShims)
|
||||
|
||||
@@ -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<AES_KEY>) 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)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<Curve: OpenSSLSupportedNISTCurve>: @unchecked
|
||||
func sign<D: Digest>(digest: D) throws -> ECDSASignature {
|
||||
let optionalRawSignature: UnsafeMutablePointer<ECDSA_SIG>? = 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<Curve: OpenSSLSupportedNISTCurve>: @unchecked
|
||||
func isValidSignature<D: Digest>(_ 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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -71,7 +71,7 @@ extension MessageAuthenticationCode {
|
||||
|
||||
public func makeIterator() -> Array<UInt8>.Iterator {
|
||||
self.withUnsafeBytes({ (buffPtr) in
|
||||
return Array(buffPtr.bindMemory(to: UInt8.self)).makeIterator()
|
||||
return Array(buffPtr).makeIterator()
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<ContiguousBuffer: ContiguousBytes>(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()
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -24,13 +24,11 @@ add_library(CryptoBoringWrapper STATIC
|
||||
)
|
||||
|
||||
target_include_directories(CryptoBoringWrapper PUBLIC
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSLShims,INCLUDE_DIRECTORIES>)
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>)
|
||||
|
||||
target_link_libraries(CryptoBoringWrapper PUBLIC
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
|
||||
CCryptoBoringSSL
|
||||
CCryptoBoringSSLShims)
|
||||
CCryptoBoringSSL)
|
||||
|
||||
target_compile_options(CryptoBoringWrapper PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS})
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<BIGNUM>? = 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!)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -86,15 +86,13 @@ add_library(CryptoExtras
|
||||
target_compile_options(CryptoExtras PRIVATE -DCRYPTO_IN_SWIFTPM)
|
||||
|
||||
target_include_directories(CryptoExtras PRIVATE
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSLShims,INCLUDE_DIRECTORIES>)
|
||||
$<TARGET_PROPERTY:CCryptoBoringSSL,INCLUDE_DIRECTORIES>)
|
||||
|
||||
target_link_libraries(CryptoExtras PUBLIC
|
||||
$<$<NOT:$<PLATFORM_ID:Darwin>>:Foundation>
|
||||
Crypto
|
||||
CryptoBoringWrapper
|
||||
CCryptoBoringSSL
|
||||
CCryptoBoringSSLShims)
|
||||
CCryptoBoringSSL)
|
||||
|
||||
target_compile_options(CryptoExtras PRIVATE ${SWIFT_CRYPTO_COMPILE_OPTIONS})
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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, *)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user