mirror of
https://github.com/apple/swift-crypto
synced 2026-11-25 04:47:47 +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.
116 lines
4.7 KiB
C
116 lines
4.7 KiB
C
// Copyright Amazon.com, Inc. or its affiliates. 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.
|
|
|
|
#ifndef OPENSSL_HEADER_CRYPTO_FIPSMODULE_SERVICE_INDICATOR_INTERNAL_H
|
|
#define OPENSSL_HEADER_CRYPTO_FIPSMODULE_SERVICE_INDICATOR_INTERNAL_H
|
|
|
|
#include <CCryptoBoringSSL_base.h>
|
|
|
|
#if defined(__cplusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
// FIPS_service_indicator_before_call and |FIPS_service_indicator_after_call|
|
|
// both currently return the same local thread counter which is slowly
|
|
// incremented whenever approved services are called. The
|
|
// |CALL_SERVICE_AND_CHECK_APPROVED| macro is strongly recommended over calling
|
|
// these functions directly.
|
|
//
|
|
// |FIPS_service_indicator_before_call| is intended to be called immediately
|
|
// before an approved service, while |FIPS_service_indicator_after_call| should
|
|
// be called immediately after. If the values returned from these two functions
|
|
// are not equal, this means that the service called inbetween is deemed to be
|
|
// approved. If the values are still the same, this means the counter has not
|
|
// been incremented, and the service called is not approved for FIPS.
|
|
//
|
|
// In non-FIPS builds, |FIPS_service_indicator_before_call| always returns zero
|
|
// and |FIPS_service_indicator_after_call| always returns one. Thus calls always
|
|
// appear to be approved. This is intended to simplify testing.
|
|
OPENSSL_EXPORT uint64_t FIPS_service_indicator_before_call(void);
|
|
OPENSSL_EXPORT uint64_t FIPS_service_indicator_after_call(void);
|
|
|
|
#if defined(__cplusplus)
|
|
}
|
|
#endif
|
|
|
|
#if defined(BORINGSSL_FIPS)
|
|
|
|
// FIPS_service_indicator_update_state records that an approved service has been
|
|
// invoked.
|
|
void FIPS_service_indicator_update_state(void);
|
|
|
|
// FIPS_service_indicator_lock_state and |FIPS_service_indicator_unlock_state|
|
|
// stop |FIPS_service_indicator_update_state| from actually updating the service
|
|
// indicator. This is used when a primitive calls a potentially approved
|
|
// primitive to avoid false positives. For example, just because a key
|
|
// generation calls |BCM_rand_bytes| (and thus the approved DRBG) doesn't mean
|
|
// that the key generation operation itself is approved.
|
|
//
|
|
// This lock nests: i.e. locking twice is fine so long as each lock is paired
|
|
// with an unlock. If the (64-bit) counter overflows, the process aborts.
|
|
void FIPS_service_indicator_lock_state(void);
|
|
void FIPS_service_indicator_unlock_state(void);
|
|
|
|
// The following functions may call |FIPS_service_indicator_update_state| if
|
|
// their parameter specifies an approved operation.
|
|
|
|
void AEAD_GCM_verify_service_indicator(const EVP_AEAD_CTX *ctx);
|
|
void AEAD_CCM_verify_service_indicator(const EVP_AEAD_CTX *ctx);
|
|
void EC_KEY_keygen_verify_service_indicator(const EC_KEY *eckey);
|
|
void ECDH_verify_service_indicator(const EC_KEY *ec_key);
|
|
void EVP_Cipher_verify_service_indicator(const EVP_CIPHER_CTX *ctx);
|
|
void EVP_DigestSign_verify_service_indicator(const EVP_MD_CTX *ctx);
|
|
void EVP_DigestVerify_verify_service_indicator(const EVP_MD_CTX *ctx);
|
|
void HMAC_verify_service_indicator(const EVP_MD *evp_md);
|
|
void TLSKDF_verify_service_indicator(const EVP_MD *dgst);
|
|
|
|
#else
|
|
|
|
// Service indicator functions are no-ops in non-FIPS builds.
|
|
|
|
inline void FIPS_service_indicator_update_state(void) {}
|
|
inline void FIPS_service_indicator_lock_state(void) {}
|
|
inline void FIPS_service_indicator_unlock_state(void) {}
|
|
|
|
inline void AEAD_GCM_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_AEAD_CTX *ctx) {}
|
|
|
|
inline void AEAD_CCM_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_AEAD_CTX *ctx) {}
|
|
|
|
inline void EC_KEY_keygen_verify_service_indicator(
|
|
[[maybe_unused]] const EC_KEY *eckey) {}
|
|
|
|
inline void ECDH_verify_service_indicator(
|
|
[[maybe_unused]] const EC_KEY *ec_key) {}
|
|
|
|
inline void EVP_Cipher_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_CIPHER_CTX *ctx) {}
|
|
|
|
inline void EVP_DigestSign_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_MD_CTX *ctx) {}
|
|
|
|
inline void EVP_DigestVerify_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_MD_CTX *ctx) {}
|
|
|
|
inline void HMAC_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_MD *evp_md) {}
|
|
|
|
inline void TLSKDF_verify_service_indicator(
|
|
[[maybe_unused]] const EVP_MD *dgst) {}
|
|
|
|
#endif // BORINGSSL_FIPS
|
|
|
|
#endif // OPENSSL_HEADER_CRYPTO_FIPSMODULE_SERVICE_INDICATOR_INTERNAL_H
|