From e26c28bc6be6f24b1532bc19acaa39ecba5f9fec Mon Sep 17 00:00:00 2001 From: Will Dillon Date: Thu, 6 Nov 2025 10:16:30 -0800 Subject: Try to pivot from Dalek to RustCrypto --- src/crypto.rs | 19 ++++++++++++++----- src/packet.rs | 1 + 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/crypto.rs b/src/crypto.rs index 2661f38..8bad0e6 100644 --- a/src/crypto.rs +++ b/src/crypto.rs @@ -8,6 +8,8 @@ use x25519_dalek::StaticSecret; use sha2::{Sha256}; use hmac::{Hmac, Mac}; +use aes::{Aes256, cipher::{Block, BlockDecryptMut, KeyInit}}; + type HmacSha256 = Hmac; use hex::{decode, decode_to_slice}; @@ -64,6 +66,15 @@ impl SharedSecret { Err(MeshcoreCryptoError::KeyLengthError) } } + + pub fn decrypt(&self, ciphertext: Bytes) -> Bytes { + let mut aes = Aes256::new((&self.0).into()); + + let mut block = Block::clone_from_slice(&ciphertext); + aes.decrypt_block_mut(&mut block); + + Bytes::copy_from_slice(&block) + } } // This is just for creating placeholders @@ -207,11 +218,9 @@ mod tests { let test_group_secret =SharedSecret::from_str("8b3387e9c5cdea6ac9e5edbaa115cd7200000000000000000000000000000000").unwrap(); assert!(group_secret == test_group_secret); - // Test using the secret and ciphertext to make a MAC and ensure it matches an example - let sample_data = Bytes::copy_from_slice(&decode("150011C3C1354D619BAE9590E4D177DB7EEAF982F5BDCF78005D75157D9535FA90178F785D").unwrap()); + // Test using the secret and ciphertext to make a MAC and ensure it matches an example for a group secret + let sample_data = Bytes::copy_from_slice(&decode("354D619BAE9590E4D177DB7EEAF982F5BDCF78005D75157D9535FA90178F785D").unwrap()); let mac = group_secret.get_hmac(sample_data).unwrap(); - // assert!(0xC3C1 == mac); - - + assert!(0xC3C1 == mac); } } \ No newline at end of file diff --git a/src/packet.rs b/src/packet.rs index 090b3ec..1c37513 100644 --- a/src/packet.rs +++ b/src/packet.rs @@ -135,6 +135,7 @@ impl Default for Packet { impl Packet { fn try_decrypt(&mut self, key: SharedSecret) -> bool { + false } } -- cgit v1.2.3