more progress on friends

This commit is contained in:
Maple 2026-01-31 13:48:06 +01:00
commit 7918e54487
19 changed files with 320 additions and 205 deletions

View file

@ -33,7 +33,7 @@ impl CryptoInstance for InsecureInstance {
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4] {
if types_flags.get_types() == DATA {
if data.len() == 0 {
[0x12, 0x34, 0x56, 0x78]
[0x78, 0x56, 0x34, 0x12]
} else {
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
.expect("unable to create hmac md5");

View file

@ -1,6 +1,9 @@
use hmac::Mac;
use rc4::Rc4;
use rnex_core::prudp::{encryption::EncryptionPair, types_flags::TypesFlags};
use rc4::{Rc4, StreamCipher};
use rnex_core::prudp::{
encryption::EncryptionPair,
types_flags::{TypesFlags, types::DATA},
};
use typenum::U32;
use crate::crypto::{
@ -11,23 +14,34 @@ use crate::crypto::{
pub struct SecureInstance {
pair: EncryptionPair<Rc4<U32>>,
uid: u32,
self_signat: [u8; 4],
remote_signat: [u8; 4],
}
impl CryptoInstance for SecureInstance {
fn decrypt_incoming(&mut self, data: &mut [u8]) {
todo!()
self.pair.recv.apply_keystream(data);
}
fn encrypt_outgoing(&mut self, data: &mut [u8]) {
todo!()
self.pair.send.apply_keystream(data);
}
fn get_user_id(&self) -> u32 {
todo!()
self.uid
}
fn generate_signature(&self, types_flags: TypesFlags, data: &[u8]) -> [u8; 4] {
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
.expect("unable to create hmac md5");
hmac.update(data);
hmac.finalize().into_bytes()[0..4].try_into().unwrap()
if types_flags.get_types() == DATA {
if data.len() == 0 {
[0x78, 0x56, 0x34, 0x12]
} else {
let mut hmac = <HmacMd5 as Mac>::new_from_slice(ACCESS_KEY.as_bytes())
.expect("unable to create hmac md5");
hmac.update(data);
hmac.finalize().into_bytes()[0..4].try_into().unwrap()
}
} else {
self.self_signat
}
}
}