awslc: report FIPS mode only for a FIPS build

fips_mode() is true only with the fips feature (AWS-LC-FIPS) and when
aws_lc_rs::try_fips_mode() succeeds; an open-source build never asks.

Refs: R3
This commit is contained in:
JohnE 2026-11-16 20:22:50 -05:00
parent aba0763b3f
commit feaecad922
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,50 @@
//! FIPS 140-3 status of the linked AWS-LC.
//!
//! Only a build with the `fips` feature links AWS-LC-FIPS; every other build
//! reports `false` without asking the library, so an open-source AWS-LC can
//! never claim FIPS mode.
/// `Some(Ok(()))` when built with `fips` and AWS-LC reports FIPS mode,
/// `Some(Err(reason))` when built with `fips` but the module is not in FIPS
/// mode, `None` without the `fips` feature.
pub fn fips_status() -> Option<Result<(), &'static str>> {
if cfg!(feature = "fips") {
Some(aws_lc_rs::try_fips_mode())
} else {
None
}
}
/// `true` only when built with the `fips` feature and AWS-LC-FIPS reports
/// FIPS mode at runtime.
pub fn fips_mode() -> bool {
matches!(fips_status(), Some(Ok(())))
}
/// The linked AWS-LC version, for logs and diagnostics.
pub fn awslc_version() -> &'static str {
aws_lc_rs::awslc_version()
}
#[cfg(test)]
mod tests {
use super::*;
#[cfg(not(feature = "fips"))]
#[test]
fn open_source_build_is_not_fips() {
assert_eq!(fips_status(), None);
assert!(!fips_mode());
}
#[cfg(feature = "fips")]
#[test]
fn fips_build_is_in_fips_mode() {
assert!(fips_mode(), "status {:?}", fips_status());
}
#[test]
fn version_is_reported() {
assert!(!awslc_version().is_empty());
}
}

View File

@ -7,6 +7,7 @@
#![forbid(unsafe_code)] #![forbid(unsafe_code)]
pub mod aead; pub mod aead;
pub mod fips;
pub mod hash; pub mod hash;
pub mod kdf; pub mod kdf;
pub mod kem; pub mod kem;