mirror of
https://github.com/YGGverse/aquatic.git
synced 2026-04-01 02:05:30 +00:00
udp: rename ConnectionValidator.hmac to .keyed_hasher
This commit is contained in:
parent
e8cb0c1618
commit
1e0559f384
1 changed files with 10 additions and 8 deletions
|
|
@ -29,7 +29,7 @@ pub const BUFFER_SIZE: usize = 8192;
|
||||||
pub struct ConnectionValidator {
|
pub struct ConnectionValidator {
|
||||||
start_time: Instant,
|
start_time: Instant,
|
||||||
max_connection_age: u32,
|
max_connection_age: u32,
|
||||||
hmac: blake3::Hasher,
|
keyed_hasher: blake3::Hasher,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ConnectionValidator {
|
impl ConnectionValidator {
|
||||||
|
|
@ -41,10 +41,10 @@ impl ConnectionValidator {
|
||||||
getrandom(&mut key)
|
getrandom(&mut key)
|
||||||
.with_context(|| "Couldn't get random bytes for ConnectionValidator key")?;
|
.with_context(|| "Couldn't get random bytes for ConnectionValidator key")?;
|
||||||
|
|
||||||
let hmac = blake3::Hasher::new_keyed(&key);
|
let keyed_hasher = blake3::Hasher::new_keyed(&key);
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
hmac,
|
keyed_hasher,
|
||||||
start_time: Instant::now(),
|
start_time: Instant::now(),
|
||||||
max_connection_age: config.cleaning.max_connection_age,
|
max_connection_age: config.cleaning.max_connection_age,
|
||||||
})
|
})
|
||||||
|
|
@ -83,15 +83,17 @@ impl ConnectionValidator {
|
||||||
|
|
||||||
(&mut connection_id_bytes[..4]).copy_from_slice(&valid_until);
|
(&mut connection_id_bytes[..4]).copy_from_slice(&valid_until);
|
||||||
|
|
||||||
self.hmac.update(&valid_until);
|
self.keyed_hasher.update(&valid_until);
|
||||||
|
|
||||||
match source_addr.get().ip() {
|
match source_addr.get().ip() {
|
||||||
IpAddr::V4(ip) => self.hmac.update(&ip.octets()),
|
IpAddr::V4(ip) => self.keyed_hasher.update(&ip.octets()),
|
||||||
IpAddr::V6(ip) => self.hmac.update(&ip.octets()),
|
IpAddr::V6(ip) => self.keyed_hasher.update(&ip.octets()),
|
||||||
};
|
};
|
||||||
|
|
||||||
self.hmac.finalize_xof().fill(&mut connection_id_bytes[4..]);
|
self.keyed_hasher
|
||||||
self.hmac.reset();
|
.finalize_xof()
|
||||||
|
.fill(&mut connection_id_bytes[4..]);
|
||||||
|
self.keyed_hasher.reset();
|
||||||
|
|
||||||
ConnectionId(i64::from_ne_bytes(connection_id_bytes))
|
ConnectionId(i64::from_ne_bytes(connection_id_bytes))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue