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 | |
| 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
| -rw-r--r-- | Cargo.lock | 35 | ||||
| -rw-r--r-- | Cargo.toml | 17 | ||||
| -rw-r--r-- | src/crypto.rs | 19 | ||||
| -rw-r--r-- | src/packet.rs | 1 |
4 files changed, 58 insertions, 14 deletions
@@ -3,6 +3,17 @@ version = 4 [[package]] +name = "aes" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0" +dependencies = [ + "cfg-if", + "cipher", + "cpufeatures", +] + +[[package]] name = "android_system_properties" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -74,6 +85,16 @@ dependencies = [ ] [[package]] +name = "cipher" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad" +dependencies = [ + "crypto-common", + "inout", +] + +[[package]] name = "const-oid" version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -284,6 +305,15 @@ dependencies = [ ] [[package]] +name = "inout" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01" +dependencies = [ + "generic-array", +] + +[[package]] name = "js-sys" version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -309,6 +339,7 @@ checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432" name = "meshcore" version = "0.1.0" dependencies = [ + "aes", "chrono", "curve25519-dalek", "ed25519-dalek", @@ -488,9 +519,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" [[package]] name = "syn" -version = "2.0.108" +version = "2.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917" +checksum = "2f17c7e013e88258aa9543dcbe81aca68a667a9ac37cd69c9fbc07858bfe0e2f" dependencies = [ "proc-macro2", "quote", @@ -4,12 +4,15 @@ version = "0.1.0" edition = "2024" [dependencies] -ed25519-dalek = { version = "2.2.0", features = ["hazmat", "pkcs8"] } -curve25519-dalek = { version = "4.1.3", features = ["group"] } -x25519-dalek = { version = "*", features = ["static_secrets"] } -hex = "0.4" +hex = "*" tokio-util = "*" -structdiff = { version = "0.7.3", features = ["debug_diffs"] } +structdiff = { version = "*", features = ["debug_diffs"] } chrono = "*" -hmac = "0.12.1" -sha2 = "*"
\ No newline at end of file + +# Crypto functions needed for packet signatures and (en|de)cryption +ed25519-dalek = { version = "*", features = ["hazmat", "pkcs8"] } +curve25519-dalek = { version = "*", features = ["group"] } +x25519-dalek = { version = "*", features = ["static_secrets"] } +hmac = "*" +sha2 = "*" +aes = "*"
\ No newline at end of file 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 } } |
