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.
106 lines
4.4 KiB
C
106 lines
4.4 KiB
C
// Copyright 2020 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.
|
|
|
|
#ifndef OPENSSL_HEADER_CRYPTO_EC_INTERNAL_H
|
|
#define OPENSSL_HEADER_CRYPTO_EC_INTERNAL_H
|
|
|
|
#include <CCryptoBoringSSL_ec.h>
|
|
|
|
#include <CCryptoBoringSSL_span.h>
|
|
|
|
#include "../fipsmodule/ec/internal.h"
|
|
|
|
#if defined(__cplusplus)
|
|
extern "C" {
|
|
#endif
|
|
|
|
|
|
// Parsing functions.
|
|
|
|
// ec_key_parse_curve_name behaves like |EC_KEY_parse_curve_name| but only
|
|
// supports the groups in |allowed_groups|. If no syntax errors were found but
|
|
// the group is unknown, it will fail with an error of |EC_R_UNKNOWN_GROUP|.
|
|
const EC_GROUP *ec_key_parse_curve_name(
|
|
CBS *cbs, bssl::Span<const EC_GROUP *const> allowed_groups);
|
|
|
|
// ec_key_parse_parameters behaves like |EC_KEY_parse_parameters| but only
|
|
// supports the groups in |allowed_groups|. If no syntax errors were found but
|
|
// the group is unknown, it will fail with an error of |EC_R_UNKNOWN_GROUP|.
|
|
const EC_GROUP *ec_key_parse_parameters(
|
|
CBS *cbs, bssl::Span<const EC_GROUP *const> allowed_groups);
|
|
|
|
// ec_key_parse_private_key behaves like |EC_KEY_parse_private_key| but only
|
|
// supports the groups in |allowed_groups|. If |group| is non-NULL,
|
|
// |allowed_groups| is ignored and instead only |group| is supported.
|
|
//
|
|
// TODO(crbug.com/boringssl/414361735): This should return a bssl::UniquePtr,
|
|
// but cannot until it is made C++ linkage.
|
|
EC_KEY *ec_key_parse_private_key(
|
|
CBS *cbs, const EC_GROUP *group,
|
|
bssl::Span<const EC_GROUP *const> allowed_groups);
|
|
|
|
|
|
// Hash-to-curve.
|
|
//
|
|
// Internal |EC_JACOBIAN| versions of the corresponding public APIs.
|
|
|
|
// ec_hash_to_curve_p256_xmd_sha256_sswu hashes |msg| to a point on |group| and
|
|
// writes the result to |out|, implementing the P256_XMD:SHA-256_SSWU_RO_ suite
|
|
// from RFC 9380. It returns one on success and zero on error.
|
|
OPENSSL_EXPORT int ec_hash_to_curve_p256_xmd_sha256_sswu(
|
|
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
|
const uint8_t *msg, size_t msg_len);
|
|
|
|
// ec_hash_to_curve_p384_xmd_sha384_sswu hashes |msg| to a point on |group| and
|
|
// writes the result to |out|, implementing the P384_XMD:SHA-384_SSWU_RO_ suite
|
|
// from RFC 9380. It returns one on success and zero on error.
|
|
OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha384_sswu(
|
|
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
|
const uint8_t *msg, size_t msg_len);
|
|
|
|
// ec_hash_to_scalar_p384_xmd_sha384 hashes |msg| to a scalar on |group|
|
|
// and writes the result to |out|, using the hash_to_field operation from the
|
|
// P384_XMD:SHA-384_SSWU_RO_ suite from RFC 9380, but generating a value modulo
|
|
// the group order rather than a field element.
|
|
OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha384(
|
|
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
|
const uint8_t *msg, size_t msg_len);
|
|
|
|
// ec_hash_to_curve_p384_xmd_sha512_sswu_draft07 hashes |msg| to a point on
|
|
// |group| and writes the result to |out|, implementing the
|
|
// P384_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-07. It
|
|
// returns one on success and zero on error.
|
|
//
|
|
// TODO(https://crbug.com/1414562): Migrate this to the final version.
|
|
OPENSSL_EXPORT int ec_hash_to_curve_p384_xmd_sha512_sswu_draft07(
|
|
const EC_GROUP *group, EC_JACOBIAN *out, const uint8_t *dst, size_t dst_len,
|
|
const uint8_t *msg, size_t msg_len);
|
|
|
|
// ec_hash_to_scalar_p384_xmd_sha512_draft07 hashes |msg| to a scalar on |group|
|
|
// and writes the result to |out|, using the hash_to_field operation from the
|
|
// P384_XMD:SHA-512_SSWU_RO_ suite from draft-irtf-cfrg-hash-to-curve-07, but
|
|
// generating a value modulo the group order rather than a field element.
|
|
//
|
|
// TODO(https://crbug.com/1414562): Migrate this to the final version.
|
|
OPENSSL_EXPORT int ec_hash_to_scalar_p384_xmd_sha512_draft07(
|
|
const EC_GROUP *group, EC_SCALAR *out, const uint8_t *dst, size_t dst_len,
|
|
const uint8_t *msg, size_t msg_len);
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
} // extern C
|
|
#endif
|
|
|
|
#endif // OPENSSL_HEADER_CRYPTO_EC_INTERNAL_H
|