Files
Gwynne Raskind c661debfc2 Update BoringSSL to 0226f30467f540a3f62ef48d453f93927da199b6 (#406)
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.
2025-09-15 15:21:20 +01:00

130 lines
2.9 KiB
C++

// Copyright 2017 The BoringSSL Authors
//
// 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_crypto.h>
#include "../../internal.h"
#include "../delocate.h"
int FIPS_mode(void) {
#if defined(BORINGSSL_FIPS) && !defined(OPENSSL_ASAN)
return 1;
#else
return 0;
#endif
}
int FIPS_mode_set(int on) { return on == FIPS_mode(); }
const char *FIPS_module_name(void) { return "BoringCrypto"; }
int CRYPTO_has_asm(void) {
#if defined(OPENSSL_NO_ASM)
return 0;
#else
return 1;
#endif
}
uint32_t FIPS_version(void) {
return 0;
}
int FIPS_query_algorithm_status(const char *algorithm) {
#if defined(BORINGSSL_FIPS)
static const char kApprovedAlgorithms[][13] = {
"AES-CBC",
"AES-CCM",
"AES-CTR",
"AES-ECB",
"AES-GCM",
"AES-KW",
"AES-KWP",
"ctrDRBG",
"ECC-SSC",
"ECDSA-sign",
"ECDSA-verify",
"FFC-SSC",
"HMAC",
"RSA-sign",
"RSA-verify",
"SHA-1",
"SHA2-224",
"SHA2-256",
"SHA2-384",
"SHA2-512",
"SHA2-512/256",
};
for (const char *approved : kApprovedAlgorithms) {
if (strcmp(algorithm, approved) == 0) {
return 1;
}
}
#endif // BORINGSSL_FIPS
return 0;
}
#if defined(BORINGSSL_FIPS_COUNTERS)
size_t FIPS_read_counter(enum fips_counter_t counter) {
size_t index = (size_t)counter;
if (index > fips_counter_max) {
abort();
}
const size_t *array = reinterpret_cast<const size_t *>(
CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_FIPS_COUNTERS));
if (!array) {
return 0;
}
return array[index];
}
void boringssl_fips_inc_counter(enum fips_counter_t counter) {
size_t index = (size_t)counter;
if (index > fips_counter_max) {
abort();
}
size_t *array = reinterpret_cast<size_t *>(
CRYPTO_get_thread_local(OPENSSL_THREAD_LOCAL_FIPS_COUNTERS));
if (!array) {
const size_t num_bytes = sizeof(size_t) * (fips_counter_max + 1);
array = reinterpret_cast<size_t *>(OPENSSL_zalloc(num_bytes));
if (!array) {
return;
}
if (!CRYPTO_set_thread_local(OPENSSL_THREAD_LOCAL_FIPS_COUNTERS, array,
OPENSSL_free)) {
// |OPENSSL_free| has already been called by |CRYPTO_set_thread_local|.
return;
}
}
array[index]++;
}
#else
size_t FIPS_read_counter(enum fips_counter_t counter) { return 0; }
// boringssl_fips_inc_counter is a no-op, inline function in internal.h in this
// case. That should let the compiler optimise away the callsites.
#endif