diff options
| author | Will Dillon <william@housedillon.com> | 2025-11-06 18:16:30 +0000 |
|---|---|---|
| committer | Will Dillon <william@housedillon.com> | 2025-11-06 18:16:30 +0000 |
| commit | e26c28bc6be6f24b1532bc19acaa39ecba5f9fec (patch) | |
| tree | 26460e93c6983a10ad7af84d3320d7c5263ff5b3 /src | |
| parent | Switching over to the mac for mac (diff) | |
| download | meshcore-rs-e26c28bc6be6f24b1532bc19acaa39ecba5f9fec.tar.gz meshcore-rs-e26c28bc6be6f24b1532bc19acaa39ecba5f9fec.zip | |
Try to pivot from Dalek to RustCrypto
Diffstat (limited to 'src')
| -rw-r--r-- | src/crypto.rs | 19 | ||||
| -rw-r--r-- | src/packet.rs | 1 |
2 files changed, 15 insertions, 5 deletions
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<Sha256>; 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 } } |
