boring: add BoringSSL provider crate with SHA-2

Second native provider after the move off wolfSSL, backed by boring 5.5.0.
Starts with the crate skeleton and SHA-256/384/512.

Refs: R3
This commit is contained in:
JohnE 2026-11-16 20:16:08 -05:00
parent f8bca636b5
commit 0ed4d9bb19
5 changed files with 236 additions and 8 deletions

139
Cargo.lock generated
View File

@ -196,7 +196,7 @@ dependencies = [
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -216,7 +216,7 @@ dependencies = [
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -262,6 +262,31 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "boring"
version = "5.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a3b3f402e3438173549c546e23b7fdd94d6f699b6e96ee10140edabcfc43dcfa"
dependencies = [
"bitflags",
"boring-sys",
"foreign-types",
"libc",
"openssl-macros",
]
[[package]]
name = "boring-sys"
version = "5.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "666b6d090823b306ff043582051c10afd83ad4170cb5d677cb33f45c475d6feb"
dependencies = [
"bindgen 0.72.1",
"cmake",
"fs_extra",
"fslock",
]
[[package]] [[package]]
name = "build-deps" name = "build-deps"
version = "0.1.4" version = "0.1.4"
@ -310,6 +335,17 @@ dependencies = [
"serde_json", "serde_json",
] ]
[[package]]
name = "ccc-crypto-boring"
version = "0.2.0"
dependencies = [
"boring",
"ccc-crypto-core",
"hex",
"log",
"zeroize",
]
[[package]] [[package]]
name = "ccc-crypto-core" name = "ccc-crypto-core"
version = "0.2.0" version = "0.2.0"
@ -578,7 +614,7 @@ checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -656,6 +692,49 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582"
[[package]]
name = "foreign-types"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
dependencies = [
"foreign-types-macros",
"foreign-types-shared",
]
[[package]]
name = "foreign-types-macros"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ea5190182e6915eb873ddbc16e23b711b6eb1f9c00a0d0a3a91b5f6228475225"
dependencies = [
"proc-macro2",
"quote",
"syn 3.0.10",
]
[[package]]
name = "foreign-types-shared"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"
[[package]]
name = "fslock"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "04412b8935272e3a9bae6f48c7bfff74c2911f60525404edfdd28e49884c3bfb"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "0.14.7" version = "0.14.7"
@ -804,7 +883,7 @@ checksum = "a17c2b211d863c7fde02cbea8a3c1a439b98e109286554f2860bdded7ff83818"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -929,6 +1008,17 @@ version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
[[package]]
name = "openssl-macros"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.117",
]
[[package]] [[package]]
name = "oqs" name = "oqs"
version = "0.11.0" version = "0.11.0"
@ -1043,7 +1133,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -1168,7 +1258,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -1269,6 +1359,17 @@ dependencies = [
"unicode-ident", "unicode-ident",
] ]
[[package]]
name = "syn"
version = "3.0.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]] [[package]]
name = "thiserror" name = "thiserror"
version = "1.0.69" version = "1.0.69"
@ -1286,7 +1387,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]
@ -1334,6 +1435,28 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-link" name = "windows-link"
version = "0.2.1" version = "0.2.1"
@ -1391,7 +1514,7 @@ checksum = "85a5b4158499876c763cb03bc4e49185d3cccbabb15b33c627f7884f43db852e"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn", "syn 2.0.117",
] ]
[[package]] [[package]]

View File

@ -6,6 +6,7 @@ members = [
"crates/ccc-crypto-wolfssl", "crates/ccc-crypto-wolfssl",
"crates/ccc-crypto-rustcrypto", "crates/ccc-crypto-rustcrypto",
"crates/ccc-crypto-oqs", "crates/ccc-crypto-oqs",
"crates/ccc-crypto-boring",
"tests/conformance", "tests/conformance",
] ]

View File

@ -0,0 +1,24 @@
[package]
name = "ccc-crypto-boring"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true
description = "BoringSSL provider for the CCC crypto system, via Cloudflare's boring crate. Licences: boring Apache-2.0, boring-sys MIT, BoringSSL Apache-2.0."
[dependencies]
ccc-crypto-core.workspace = true
zeroize.workspace = true
log.workspace = true
# Pinned exactly: a BoringSSL bump changes the native code we vouch for.
# `mlkem` exposes BoringSSL's ML-KEM-768/1024 (FIPS 203).
boring = { version = "=5.5.0", features = ["mlkem"] }
[features]
default = []
# Build BoringCrypto, the FIPS 140 validated module (boring/fips). Needs the
# exact clang, Go and CMake versions of its security policy.
fips = ["boring/fips"]
[dev-dependencies]
hex = "0.4"

View File

@ -0,0 +1,58 @@
//! Hash functions: SHA-256, SHA-384 and SHA-512 from BoringSSL.
//!
//! BoringSSL has no SHA-3 or BLAKE2b, so those IDs return
//! [`CryptoError::FeatureNotCompiled`].
use boring::sha;
use ccc_crypto_core::{algorithms::HashAlgorithm, error::CryptoError};
/// Compute the digest of `data`.
pub fn hash(algo: HashAlgorithm, data: &[u8]) -> Result<Vec<u8>, CryptoError> {
match algo {
HashAlgorithm::Sha256 => Ok(sha::sha256(data).to_vec()),
HashAlgorithm::Sha384 => Ok(sha::sha384(data).to_vec()),
HashAlgorithm::Sha512 => Ok(sha::sha512(data).to_vec()),
HashAlgorithm::Blake2b512 | HashAlgorithm::Sha3_256 | HashAlgorithm::Sha3_512 => Err(
CryptoError::FeatureNotCompiled(format!("{} is not in BoringSSL", algo.name())),
),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn digest_lengths_match_registry() {
for algo in [
HashAlgorithm::Sha256,
HashAlgorithm::Sha384,
HashAlgorithm::Sha512,
] {
assert_eq!(hash(algo, b"abc").unwrap().len(), algo.digest_len());
}
}
#[test]
fn sha256_abc() {
assert_eq!(
hex::encode(hash(HashAlgorithm::Sha256, b"abc").unwrap()),
"ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"
);
}
#[test]
fn missing_hashes_are_not_compiled() {
for algo in [
HashAlgorithm::Blake2b512,
HashAlgorithm::Sha3_256,
HashAlgorithm::Sha3_512,
] {
assert!(matches!(
hash(algo, b""),
Err(CryptoError::FeatureNotCompiled(_))
));
}
}
}

View File

@ -0,0 +1,22 @@
//! # ccc-crypto-boring
//!
//! BoringSSL implementation of the CCC provider traits, through Cloudflare's
//! [`boring`] crate. It adds a native library family next to wolfSSL and
//! RustCrypto (design: "Provider diversity"). Built with the `fips`
//! feature it links BoringCrypto, the FIPS 140 validated module, and can
//! supply a suite's vetted layer; otherwise `fips_mode()` is `false`.
//!
//! Licences: `boring` is Apache-2.0 and `boring-sys` is MIT. The vendored
//! BoringSSL (libcrypto) is Apache-2.0 throughout, including the files that
//! came from OpenSSL; only its Go test harness, which is not linked, is under
//! the Go licence.
//!
//! The crate is independent of the AWS-LC provider (itself a BoringSSL fork):
//! the two never share a build or a symbol namespace.
#![forbid(unsafe_code)]
pub mod hash;
/// The provider's registry name.
pub const PROVIDER_NAME: &str = "boring";