mirror of
https://github.com/ratspeak/rsReticulum
synced 2026-11-22 23:10:33 +00:00
wire: hash each packet once, and size token buffers for their MAC
This commit is contained in:
1 parent
dfb229bb4e
commit
5dadbd44bd
2 files changed
+4
-6
No files matched your search
@@ -71,7 +71,7 @@ pub fn encrypt(plaintext: &[u8], key: &[u8]) -> Result<Vec<u8>, TokenError> {
|
||||
let ciphertext =
|
||||
aes_cbc::encrypt(encryption_key, &iv, &padded).map_err(|_| TokenError::EncryptionFailed)?;
|
||||
|
||||
let mut signed_parts = Vec::with_capacity(16 + ciphertext.len());
|
||||
let mut signed_parts = Vec::with_capacity(16 + ciphertext.len() + 32);
|
||||
signed_parts.extend_from_slice(&iv);
|
||||
signed_parts.extend_from_slice(&ciphertext);
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use alloc::vec::Vec;
|
||||
use thiserror::Error;
|
||||
|
||||
use crate::constants::MTU;
|
||||
use crate::hash::{packet_hash, truncated_packet_hash};
|
||||
use crate::hash::packet_hash_pair;
|
||||
use crate::header::{HeaderError, PacketHeader};
|
||||
|
||||
/// Errors surfaced by [`Packet::new`] and [`Packet::from_raw`].
|
||||
@@ -63,8 +63,7 @@ impl Packet {
|
||||
return Err(PacketError::ExceedsMtu(raw.len()));
|
||||
}
|
||||
|
||||
let hash = packet_hash(&raw, header.flags.header_type);
|
||||
let trunc = truncated_packet_hash(&raw, header.flags.header_type);
|
||||
let (hash, trunc) = packet_hash_pair(&raw, header.flags.header_type);
|
||||
|
||||
Ok(Self {
|
||||
header,
|
||||
@@ -95,8 +94,7 @@ impl Packet {
|
||||
}
|
||||
|
||||
let (header, data_offset) = PacketHeader::unpack(&raw)?;
|
||||
let hash = packet_hash(&raw, header.flags.header_type);
|
||||
let trunc = truncated_packet_hash(&raw, header.flags.header_type);
|
||||
let (hash, trunc) = packet_hash_pair(&raw, header.flags.header_type);
|
||||
|
||||
Ok(Self {
|
||||
header,
|
||||
|
||||
Reference in new issue
Block a user