fix having fixed size key

This commit is contained in:
Maple 2026-02-01 21:31:32 +01:00
commit dad8ac498c
2 changed files with 6 additions and 12 deletions

View file

@ -26,7 +26,7 @@ pub const SESSION_KEY_LENGTH: usize = SESSION_KEY_LENGTH_TY::USIZE;
type Md5Hmac = Hmac<md5::Md5>;
pub fn derive_key(pid: u32, password: &[u8]) -> [u8; 16] {
let iteration_count = 65000 + pid % 1024 - 1;
let iteration_count = 65000 + pid % 1024;
// we do one iteration out here to ensure the key is always 16 bytes
let mut key: [u8; 16] = {
@ -35,7 +35,7 @@ pub fn derive_key(pid: u32, password: &[u8]) -> [u8; 16] {
md5.finalize().try_into().unwrap()
};
for _ in 0..iteration_count {
for _ in 1..iteration_count {
let mut md5 = Md5::new();
md5.update(key);
key = md5.finalize().try_into().unwrap();