diff --git a/crates/ccc-crypto-awslc/src/fips.rs b/crates/ccc-crypto-awslc/src/fips.rs new file mode 100644 index 0000000..a62d9f8 --- /dev/null +++ b/crates/ccc-crypto-awslc/src/fips.rs @@ -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> { + 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()); + } +} diff --git a/crates/ccc-crypto-awslc/src/lib.rs b/crates/ccc-crypto-awslc/src/lib.rs index 2f95dfe..c0e4e22 100644 --- a/crates/ccc-crypto-awslc/src/lib.rs +++ b/crates/ccc-crypto-awslc/src/lib.rs @@ -7,6 +7,7 @@ #![forbid(unsafe_code)] pub mod aead; +pub mod fips; pub mod hash; pub mod kdf; pub mod kem;