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

View file

@ -4,29 +4,23 @@ use macros::RmcSerialize;
pub struct Account { pub struct Account {
pub pid: u32, pub pid: u32,
pub username: String, pub username: String,
pub kerbros_password: [u8; 16], pub kerbros_password: Box<[u8]>,
} }
impl Account { impl Account {
pub fn new(pid: u32, username: &str, passwd: &str) -> Self { pub fn new(pid: u32, username: &str, passwd: &str) -> Self {
let passwd_data = passwd.as_bytes(); let passwd_data = passwd.as_bytes();
let mut passwd = [0u8; 16];
for (idx, byte) in passwd_data.iter().enumerate() {
passwd[idx] = *byte;
}
Self { Self {
kerbros_password: passwd, kerbros_password: passwd.as_bytes().into(),
username: username.into(), username: username.into(),
pid, pid,
} }
} }
pub fn new_raw_password(pid: u32, username: &str, passwd: [u8; 16]) -> Self { pub fn new_raw_password(pid: u32, username: &str, passwd: &[u8]) -> Self {
Self { Self {
kerbros_password: passwd, kerbros_password: passwd.into(),
username: username.into(), username: username.into(),
pid, pid,
} }