Change nonce type to u128 for cross-platform compatibility

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/1/head
trivernis 4 years ago
parent 9da5931435
commit 68729d8dd2
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,7 +1,7 @@
[package] [package]
name = "vented" name = "vented"
description = "Event driven encrypted tcp communicaton" description = "Event driven encrypted tcp communicaton"
version = "0.4.2" version = "0.4.3"
authors = ["trivernis <trivernis@protonmail.com>"] authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018" edition = "2018"
readme = "README.md" readme = "README.md"

@ -108,7 +108,7 @@ where
T: Aead, T: Aead,
{ {
inner: T, inner: T,
counter: usize, counter: u128,
} }
impl<T> EncryptionBox<T> impl<T> EncryptionBox<T>
@ -161,8 +161,10 @@ impl EncryptionBox<ChaChaBox> {
} }
/// Generates a nonce by hashing the input number which is the message counter /// Generates a nonce by hashing the input number which is the message counter
fn generate_nonce(number: usize) -> GenericArray<u8, U24> { fn generate_nonce(number: u128) -> GenericArray<u8, U24> {
let result = sha2::Sha256::digest(&number.to_be_bytes()).to_vec(); let mut number_raw = [0u8; 16];
BigEndian::write_u128(&mut number_raw, number);
let result = sha2::Sha256::digest(&number_raw).to_vec();
let mut nonce = [0u8; 24]; let mut nonce = [0u8; 24];
nonce.copy_from_slice(&result[0..24]); nonce.copy_from_slice(&result[0..24]);

Loading…
Cancel
Save