mirror of
https://github.com/apple/swift-crypto
synced 2026-11-27 04:54:21 +00:00
Fix multiple issues in the BoringSSL vendoring script and update BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6 ### Checklist - [x] I've run tests to see all new and existing tests pass - [x] I've followed the code style of the rest of the project - [x] I've read the [Contribution Guidelines](CONTRIBUTING.md) - [x] I've updated the documentation if necessary ### Motivation: The `vendor-boringssl.sh` script is currently broken in a number of ways, both in general and relative to the latest BoringSSL version: - `--enable-test-discovery` is still in use - The Linux Swift SDKs being generated are out of date (5.10-jammy) - The script does not prefix exported C++ symbols - Invoking the script without a `BORINGSSL_REVISION` results in an unconditional error - The `PATTERNS` list is out of date for the latest BoringSSL - The latest BoringSSL contains a bug which fails to apply `extern "C"` to two exported symbols, allowing for collisions. In addition, the latest BoringSSL has made `BN_MONT_CTX` opaque, necessitating that it be referenced with `OpaquePointer` rather than `UnsafePointer<>`. ### Modifications: The following changes are included: - `--enable-test-discovery` has been removed - `vendor-boringssl.sh` and `generate-linux-sdks.sh` have been updated to use Swift 6.1.2 SDKs built for Ubuntu Noble - The `mangle_cpp_structures` function from `swift-nio-ssl`'s version of `vendor-boringssl.sh` has been copied over (thanks @Lukasa!) - `BORINGSSL_REVISION` is now allowed to be an empty string - The `PATTERNS` array has been updated - A patch has been added which applies `extern "C"` to the functions which should have it - `s/UnsafePointer<BN_MONT_CTX>/OpaquePointer/g` - Updated `CMakeLists.txt` per `update-cmake-lists.sh` - Update BoringSSL to `0226f30467f540a3f62ef48d453f93927da199b6` ### Result: Vendoring the latest BoringSSL will work again. The latest BoringSSL is vendored.
183 lines
5.2 KiB
C++
183 lines
5.2 KiB
C++
// Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
#include <CCryptoBoringSSL_digest.h>
|
|
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
#include <CCryptoBoringSSL_nid.h>
|
|
|
|
#include "../../internal.h"
|
|
#include "../bcm_interface.h"
|
|
#include "../delocate.h"
|
|
#include "internal.h"
|
|
|
|
#if defined(NDEBUG)
|
|
#define CHECK(x) (void)(x)
|
|
#else
|
|
#define CHECK(x) assert(x)
|
|
#endif
|
|
|
|
|
|
static void sha1_init(EVP_MD_CTX *ctx) {
|
|
BCM_sha1_init(reinterpret_cast<SHA_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
static void sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
|
BCM_sha1_update(reinterpret_cast<SHA_CTX *>(ctx->md_data), data, count);
|
|
}
|
|
|
|
static void sha1_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
|
BCM_sha1_final(md, reinterpret_cast<SHA_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha1) {
|
|
out->type = NID_sha1;
|
|
out->md_size = BCM_SHA_DIGEST_LENGTH;
|
|
out->flags = 0;
|
|
out->init = sha1_init;
|
|
out->update = sha1_update;
|
|
out->final = sha1_final;
|
|
out->block_size = 64;
|
|
out->ctx_size = sizeof(SHA_CTX);
|
|
}
|
|
|
|
static_assert(sizeof(SHA_CTX) <= EVP_MAX_MD_DATA_SIZE);
|
|
|
|
|
|
static void sha224_init(EVP_MD_CTX *ctx) {
|
|
BCM_sha224_init(reinterpret_cast<SHA256_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
static void sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
|
BCM_sha224_update(reinterpret_cast<SHA256_CTX *>(ctx->md_data), data, count);
|
|
}
|
|
|
|
static void sha224_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
|
BCM_sha224_final(md, reinterpret_cast<SHA256_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha224) {
|
|
out->type = NID_sha224;
|
|
out->md_size = BCM_SHA224_DIGEST_LENGTH;
|
|
out->flags = 0;
|
|
out->init = sha224_init;
|
|
out->update = sha224_update;
|
|
out->final = sha224_final;
|
|
out->block_size = 64;
|
|
out->ctx_size = sizeof(SHA256_CTX);
|
|
}
|
|
|
|
static_assert(sizeof(SHA256_CTX) <= EVP_MAX_MD_DATA_SIZE);
|
|
|
|
static void sha256_init(EVP_MD_CTX *ctx) {
|
|
BCM_sha256_init(reinterpret_cast<SHA256_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
static void sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
|
BCM_sha256_update(reinterpret_cast<SHA256_CTX *>(ctx->md_data), data, count);
|
|
}
|
|
|
|
static void sha256_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
|
BCM_sha256_final(md, reinterpret_cast<SHA256_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha256) {
|
|
out->type = NID_sha256;
|
|
out->md_size = BCM_SHA256_DIGEST_LENGTH;
|
|
out->flags = 0;
|
|
out->init = sha256_init;
|
|
out->update = sha256_update;
|
|
out->final = sha256_final;
|
|
out->block_size = 64;
|
|
out->ctx_size = sizeof(SHA256_CTX);
|
|
}
|
|
|
|
|
|
static void sha384_init(EVP_MD_CTX *ctx) {
|
|
BCM_sha384_init(reinterpret_cast<SHA512_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
static void sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
|
BCM_sha384_update(reinterpret_cast<SHA512_CTX *>(ctx->md_data), data, count);
|
|
}
|
|
|
|
static void sha384_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
|
BCM_sha384_final(md, reinterpret_cast<SHA512_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha384) {
|
|
out->type = NID_sha384;
|
|
out->md_size = BCM_SHA384_DIGEST_LENGTH;
|
|
out->flags = 0;
|
|
out->init = sha384_init;
|
|
out->update = sha384_update;
|
|
out->final = sha384_final;
|
|
out->block_size = 128;
|
|
out->ctx_size = sizeof(SHA512_CTX);
|
|
}
|
|
|
|
static_assert(sizeof(SHA512_CTX) <= EVP_MAX_MD_DATA_SIZE);
|
|
|
|
static void sha512_init(EVP_MD_CTX *ctx) {
|
|
BCM_sha512_init(reinterpret_cast<SHA512_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
static void sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
|
BCM_sha512_update(reinterpret_cast<SHA512_CTX *>(ctx->md_data), data, count);
|
|
}
|
|
|
|
static void sha512_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
|
BCM_sha512_final(md, reinterpret_cast<SHA512_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512) {
|
|
out->type = NID_sha512;
|
|
out->md_size = BCM_SHA512_DIGEST_LENGTH;
|
|
out->flags = 0;
|
|
out->init = sha512_init;
|
|
out->update = sha512_update;
|
|
out->final = sha512_final;
|
|
out->block_size = 128;
|
|
out->ctx_size = sizeof(SHA512_CTX);
|
|
}
|
|
|
|
|
|
static void sha512_256_init(EVP_MD_CTX *ctx) {
|
|
BCM_sha512_256_init(reinterpret_cast<SHA512_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
static void sha512_256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
|
|
BCM_sha512_256_update(reinterpret_cast<SHA512_CTX *>(ctx->md_data), data,
|
|
count);
|
|
}
|
|
|
|
static void sha512_256_final(EVP_MD_CTX *ctx, uint8_t *md) {
|
|
BCM_sha512_256_final(md, reinterpret_cast<SHA512_CTX *>(ctx->md_data));
|
|
}
|
|
|
|
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512_256) {
|
|
out->type = NID_sha512_256;
|
|
out->md_size = BCM_SHA512_256_DIGEST_LENGTH;
|
|
out->flags = 0;
|
|
out->init = sha512_256_init;
|
|
out->update = sha512_256_update;
|
|
out->final = sha512_256_final;
|
|
out->block_size = 128;
|
|
out->ctx_size = sizeof(SHA512_CTX);
|
|
}
|
|
|
|
#undef CHECK
|