@@ -353,11 +353,8 @@ pub fn create_encrypted_certificate_pem(
353353}
354354
355355pub fn create_checksum ( password : & str ) -> String {
356- let rng = rand:: thread_rng ( ) ;
357- let salt = SaltString :: generate ( rng) ;
358- let password_hash = pbkdf2:: Pbkdf2
359- . hash_password ( password. as_bytes ( ) , & salt)
360- . unwrap ( ) ;
356+ let salt = SaltString :: generate ( & mut OsRng ) ;
357+ let password_hash = Pbkdf2 . hash_password ( password. as_bytes ( ) , & salt) . unwrap ( ) ;
361358
362359 password_hash. to_string ( )
363360}
@@ -397,7 +394,8 @@ pub fn decrypt(data: &[u8], password: &str, iterations: u32) -> Result<Vec<u8>,
397394
398395pub fn gcm_encrypt ( data : & [ u8 ] , password : & str , iterations : u32 ) -> Result < Vec < u8 > , ChainError > {
399396 // Derive key from password
400- let salt: [ u8 ; 32 ] = rand:: thread_rng ( ) . gen ( ) ;
397+ let mut salt = [ 0u8 ; 32 ] ;
398+ rand:: rng ( ) . fill_bytes ( & mut salt) ;
401399 let derived_key = derive_key ( & salt, password, iterations) ;
402400 let key = Key :: < Aes256Gcm > :: from_slice ( & derived_key) ;
403401 let cipher = Aes256Gcm :: new ( key) ;
@@ -441,7 +439,8 @@ pub fn gcm_decrypt(
441439type Aes256CbcEnc = cbc:: Encryptor < aes:: Aes256 > ;
442440type Aes256CbcDec = cbc:: Decryptor < aes:: Aes256 > ;
443441pub fn cbc_encrypt ( data : & [ u8 ] , password : & str , iterations : u32 ) -> Result < Vec < u8 > , ChainError > {
444- let iv: [ u8 ; IV_SIZE ] = rand:: thread_rng ( ) . gen ( ) ;
442+ let mut iv = [ 0u8 ; IV_SIZE ] ;
443+ rand:: rng ( ) . fill_bytes ( & mut iv) ;
445444 let derived_key = derive_key ( & iv, password, iterations) ; // KeySize [u8; 32]
446445 let key = GenericArray :: from_slice ( & derived_key) ;
447446
@@ -460,7 +459,8 @@ pub fn cbc_encrypt(data: &[u8], password: &str, iterations: u32) -> Result<Vec<u
460459 hmac_input. extend_from_slice ( & iv) ;
461460 hmac_input. extend_from_slice ( ct) ;
462461
463- let hmac_salt: [ u8 ; 32 ] = rand:: thread_rng ( ) . gen ( ) ;
462+ let mut hmac_salt = [ 0u8 ; 32 ] ;
463+ rand:: rng ( ) . fill_bytes ( & mut hmac_salt) ;
464464 let hmac_key = derive_key ( & hmac_salt, password, iterations) ;
465465
466466 let mut mac: Hmac < Sha256 > = <Hmac < Sha256 > as KeyInit >:: new_from_slice ( & hmac_key)
@@ -523,7 +523,8 @@ pub fn cbc_decrypt(
523523type Aes256CfbEnc = cfb_mode:: Encryptor < aes:: Aes256 > ;
524524type Aes256CfbDec = cfb_mode:: Decryptor < aes:: Aes256 > ;
525525pub fn cfb_encrypt ( data : & [ u8 ] , password : & str , iterations : u32 ) -> Result < Vec < u8 > , ChainError > {
526- let iv: [ u8 ; IV_SIZE ] = rand:: thread_rng ( ) . gen ( ) ;
526+ let mut iv = [ 0u8 ; IV_SIZE ] ;
527+ rand:: rng ( ) . fill_bytes ( & mut iv) ;
527528 let derived_key = derive_key ( & iv, password, iterations) ; // KeySize [u8; 32]
528529 let key = GenericArray :: from_slice ( & derived_key) ;
529530
0 commit comments