@@ -233,14 +233,42 @@ pub fn fips_mode() {
233
233
/// Indicates whether the underlying implementation is FIPS.
234
234
///
235
235
/// # Errors
236
- /// Return an error if the underlying implementation is not FIPS, otherwise ok
236
+ /// Return an error if the underlying implementation is not FIPS, otherwise Ok.
237
237
pub fn try_fips_mode ( ) -> Result < ( ) , & ' static str > {
238
238
init ( ) ;
239
- unsafe {
240
- match FIPS_mode ( ) {
241
- 1 => Ok ( ( ) ) ,
242
- _ => Err ( "FIPS mode not enabled!" ) ,
243
- }
239
+ match unsafe { FIPS_mode ( ) } {
240
+ 1 => Ok ( ( ) ) ,
241
+ _ => Err ( "FIPS mode not enabled!" ) ,
242
+ }
243
+ }
244
+
245
+ #[ cfg( feature = "fips" ) ]
246
+ /// Panics if the underlying implementation is not using CPU jitter entropy, otherwise it returns.
247
+ ///
248
+ /// # Panics
249
+ /// Panics if the underlying implementation is not using CPU jitter entropy.
250
+ pub fn fips_cpu_jitter_entropy ( ) {
251
+ try_fips_cpu_jitter_entropy ( ) . unwrap ( ) ;
252
+ }
253
+
254
+ /// Indicates whether the underlying implementation is FIPS.
255
+ ///
256
+ /// # Errors
257
+ /// Return an error if the underlying implementation is not using CPU jitter entropy, otherwise Ok.
258
+ pub fn try_fips_cpu_jitter_entropy ( ) -> Result < ( ) , & ' static str > {
259
+ init ( ) ;
260
+ // TODO: Delete once FIPS_is_entropy_cpu_jitter() available on FIPS branch
261
+ // https://github.com/aws/aws-lc/pull/2088
262
+ #[ cfg( feature = "fips" ) ]
263
+ if aws_lc:: CFG_CPU_JITTER_ENTROPY ( ) {
264
+ Ok ( ( ) )
265
+ } else {
266
+ Err ( "FIPS CPU Jitter Entropy not enabled!" )
267
+ }
268
+ #[ cfg( not( feature = "fips" ) ) ]
269
+ match unsafe { aws_lc:: FIPS_is_entropy_cpu_jitter ( ) } {
270
+ 1 => Ok ( ( ) ) ,
271
+ _ => Err ( "FIPS CPU Jitter Entropy not enabled!" ) ,
244
272
}
245
273
}
246
274
@@ -292,12 +320,17 @@ mod tests {
292
320
#[ test]
293
321
fn test_fips ( ) {
294
322
assert ! ( { crate :: try_fips_mode( ) . is_err( ) } ) ;
323
+ assert ! ( { crate :: try_fips_cpu_jitter_entropy( ) . is_err( ) } ) ;
295
324
}
296
325
297
326
#[ test]
298
327
// FIPS mode is disabled for an ASAN build
299
- #[ cfg( all ( feature = "fips" , not ( feature = "asan" ) ) ) ]
328
+ #[ cfg( feature = "fips" ) ]
300
329
fn test_fips ( ) {
330
+ #[ cfg( not( feature = "asan" ) ) ]
301
331
crate :: fips_mode ( ) ;
332
+ if aws_lc:: CFG_CPU_JITTER_ENTROPY ( ) {
333
+ crate :: fips_cpu_jitter_entropy ( ) ;
334
+ }
302
335
}
303
336
}
0 commit comments