@@ -4,6 +4,8 @@ use core::mem;
44use crypto_bigint:: { ArrayDecoding , ArrayEncoding , NonZero } ;
55use digest:: generic_array:: GenericArray ;
66use digest:: { Digest , FixedOutputReset } ;
7+
8+ #[ cfg( feature = "zeroize" ) ]
79use zeroize:: Zeroize ;
810
911pub fn balloon < D : Digest + FixedOutputReset > (
3840 let mut output = hash_internal :: < D > ( pwd, salt, secret, params, memory_blocks, Some ( 1 ) ) ?;
3941
4042 for thread in 2 ..=u64:: from ( params. p_cost . get ( ) ) {
43+ #[ cfg_attr( not( feature = "zeroize" ) , allow( unused_mut) ) ]
4144 let mut hash =
4245 hash_internal :: < D > ( pwd, salt, secret, params, memory_blocks, Some ( thread) ) ?;
4346 output. iter_mut ( ) . zip ( & hash) . for_each ( |( a, b) | * a ^= b) ;
47+ #[ cfg( feature = "zeroize" ) ]
4448 hash. zeroize ( ) ;
4549 }
4650
@@ -65,12 +69,16 @@ where
6569 . map_with ( ( params, secret) , |( params, secret) , ( thread, memory) | {
6670 hash_internal :: < D > ( pwd, salt, * secret, * params, memory, Some ( thread) )
6771 } )
68- . try_reduce ( GenericArray :: default, |mut a, mut b| {
69- a. iter_mut ( ) . zip ( & b) . for_each ( |( a, b) | * a ^= b) ;
70- b. zeroize ( ) ;
71-
72- Ok ( a)
73- } )
72+ . try_reduce (
73+ GenericArray :: default,
74+ |mut a, #[ cfg_attr( not( feature = "zeroize" ) , allow( unused_mut) ) ] mut b| {
75+ a. iter_mut ( ) . zip ( & b) . for_each ( |( a, b) | * a ^= b) ;
76+ #[ cfg( feature = "zeroize" ) ]
77+ b. zeroize ( ) ;
78+
79+ Ok ( a)
80+ } ,
81+ )
7482 } ?
7583 } ;
7684
@@ -206,6 +214,7 @@ where
206214 // Step 3. Extract output from buffer.
207215 // return buf[s_cost-1]
208216 let out = buf. last ( ) . unwrap ( ) . clone ( ) ;
217+ #[ cfg( feature = "zeroize" ) ]
209218 buf. iter_mut ( ) . for_each ( |block| block. zeroize ( ) ) ;
210219
211220 Ok ( out)
0 commit comments