Now checking the hashes in constant time
This commit is contained in:
		
							
								
								
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										1
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@@ -473,6 +473,7 @@ dependencies = [
 | 
				
			|||||||
 "scrypt",
 | 
					 "scrypt",
 | 
				
			||||||
 "sea-orm",
 | 
					 "sea-orm",
 | 
				
			||||||
 "sha2",
 | 
					 "sha2",
 | 
				
			||||||
 | 
					 "subtle",
 | 
				
			||||||
 "thiserror",
 | 
					 "thiserror",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,3 +16,4 @@ rand = { version = "0.8.5", default-features = false, features = ["std_rng"] }
 | 
				
			|||||||
sea-orm = "0.11.3"
 | 
					sea-orm = "0.11.3"
 | 
				
			||||||
bitflags = "2.3.1"
 | 
					bitflags = "2.3.1"
 | 
				
			||||||
arrayvec = "0.7.2"
 | 
					arrayvec = "0.7.2"
 | 
				
			||||||
 | 
					subtle = "2.5.0"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,6 +2,7 @@ use entity::master_pass;
 | 
				
			|||||||
use rand::{rngs::OsRng, RngCore};
 | 
					use rand::{rngs::OsRng, RngCore};
 | 
				
			||||||
use scrypt::{scrypt, Params};
 | 
					use scrypt::{scrypt, Params};
 | 
				
			||||||
use sea_orm::ActiveValue::Set;
 | 
					use sea_orm::ActiveValue::Set;
 | 
				
			||||||
 | 
					use subtle::ConstantTimeEq;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Hashes the password with Scrypt with the given salt
 | 
					/// Hashes the password with Scrypt with the given salt
 | 
				
			||||||
#[inline]
 | 
					#[inline]
 | 
				
			||||||
@@ -21,7 +22,7 @@ impl VerifyMasterPassExt for master_pass::Model {
 | 
				
			|||||||
    #[inline]
 | 
					    #[inline]
 | 
				
			||||||
    fn verify(&self, password: &str) -> bool {
 | 
					    fn verify(&self, password: &str) -> bool {
 | 
				
			||||||
        let hashed = hash_password(password.as_bytes(), &self.salt);
 | 
					        let hashed = hash_password(password.as_bytes(), &self.salt);
 | 
				
			||||||
        hashed == self.password_hash.as_slice()
 | 
					        hashed.ct_eq(&self.password_hash).into()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user