aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWill Dillon <william@housedillon.com>2025-11-06 19:29:47 +0000
committerWill Dillon <william@housedillon.com>2025-11-06 19:29:47 +0000
commit0024a422ba6e4459d50dca87deb369cb1d2906af (patch)
tree0e0e60909c604ca42bfbc7b5a53c52c53e6a45f9
parentTry to pivot from Dalek to RustCrypto (diff)
downloadmeshcore-rs-0024a422ba6e4459d50dca87deb369cb1d2906af.tar.gz
meshcore-rs-0024a422ba6e4459d50dca87deb369cb1d2906af.zip
Finally building again; what a nightmare
-rw-r--r--Cargo.lock54
-rw-r--r--Cargo.toml11
-rw-r--r--src/crypto.rs28
-rw-r--r--src/packet.rs2
4 files changed, 20 insertions, 75 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 5da6def..e9722a9 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,17 +3,6 @@
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"
@@ -85,16 +74,6 @@ 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"
@@ -136,8 +115,6 @@ dependencies = [
"curve25519-dalek-derive",
"digest",
"fiat-crypto",
- "group",
- "rand_core",
"rustc_version",
"subtle",
"zeroize",
@@ -200,16 +177,6 @@ dependencies = [
]
[[package]]
-name = "ff"
-version = "0.13.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c0b50bfb653653f9ca9095b427bed08ab8d75a137839d9ad64eb11810d5b6393"
-dependencies = [
- "rand_core",
- "subtle",
-]
-
-[[package]]
name = "fiat-crypto"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -255,17 +222,6 @@ dependencies = [
]
[[package]]
-name = "group"
-version = "0.13.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63"
-dependencies = [
- "ff",
- "rand_core",
- "subtle",
-]
-
-[[package]]
name = "hex"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -305,15 +261,6 @@ 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"
@@ -339,7 +286,6 @@ checksum = "34080505efa8e45a4b816c349525ebe327ceaa8559756f0356cba97ef3bf7432"
name = "meshcore"
version = "0.1.0"
dependencies = [
- "aes",
"chrono",
"curve25519-dalek",
"ed25519-dalek",
diff --git a/Cargo.toml b/Cargo.toml
index 9001bcb..f4d75a3 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,9 +10,8 @@ structdiff = { version = "*", features = ["debug_diffs"] }
chrono = "*"
# 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
+sha2 = { version = "0.10", default-features = false }
+hmac = { version = "0.12", default-features = false }
+ed25519-dalek = { version = "2.2.0", features = ["hazmat"]}
+x25519-dalek = { version = "2.0.1", features = ["static_secrets"]}
+curve25519-dalek = "4.1.3" \ No newline at end of file
diff --git a/src/crypto.rs b/src/crypto.rs
index 8bad0e6..d967f50 100644
--- a/src/crypto.rs
+++ b/src/crypto.rs
@@ -1,18 +1,17 @@
use std::str::FromStr;
+use tokio_util::bytes::{Buf, BufMut, Bytes, BytesMut};
+use hex::{decode, decode_to_slice};
use ed25519_dalek::hazmat::ExpandedSecretKey;
use curve25519_dalek::{constants, edwards::CompressedEdwardsY};
-use tokio_util::bytes::{Buf, BufMut, Bytes, BytesMut};
use x25519_dalek::StaticSecret;
+// use aes::{Aes256, cipher::{Block, BlockDecryptMut, KeyInit}};
+
use sha2::{Sha256};
use hmac::{Hmac, Mac};
-
-use aes::{Aes256, cipher::{Block, BlockDecryptMut, KeyInit}};
-
type HmacSha256 = Hmac<Sha256>;
-use hex::{decode, decode_to_slice};
#[derive(Debug)]
pub enum MeshcoreCryptoError {
@@ -56,7 +55,7 @@ impl SharedSecret {
}
pub fn get_hmac(&self, ciphertext: Bytes) -> Result<u16, MeshcoreCryptoError> {
- if let Ok(mut mac) = HmacSha256::new_from_slice(&self.0) {
+ if let Ok(mut mac) = HmacSha256::new_from_slice(&self.0) {
mac.update(&ciphertext);
let result = mac.finalize();
let mut bytes = Bytes::copy_from_slice(&result.into_bytes());
@@ -68,12 +67,13 @@ impl SharedSecret {
}
pub fn decrypt(&self, ciphertext: Bytes) -> Bytes {
- let mut aes = Aes256::new((&self.0).into());
+ // let mut aes = Aes256::new((&self.0).into());
- let mut block = Block::clone_from_slice(&ciphertext);
- aes.decrypt_block_mut(&mut block);
+ // let mut block = Block::clone_from_slice(&ciphertext);
+ // aes.decrypt_block_mut(&mut block);
- Bytes::copy_from_slice(&block)
+ // Bytes::copy_from_slice(&block)
+ ciphertext
}
}
@@ -98,7 +98,7 @@ impl TryFrom<Bytes> for PublicKey {
return Err(MeshcoreCryptoError::TryFromSliceError)
}
- Ok(PublicKey(CompressedEdwardsY(slice)))
+ Ok(PublicKey(curve25519_dalek::edwards::CompressedEdwardsY(slice)))
}
}
@@ -157,15 +157,15 @@ impl SharedSecret {
}
pub struct Keychain {
- pub private_keys: Vec<PrivateKey>,
- pub public_keys: Vec<PublicKey>,
+ // pub private_keys: Vec<PrivateKey>,
+ // pub public_keys: Vec<PublicKey>,
// secrets: HashMap<String, Ha>
}
#[cfg(test)]
mod tests {
- use curve25519_dalek::Scalar;
+ // use curve25519_dalek::Scalar;
use hex::{decode_to_slice, encode};
use super::*;
diff --git a/src/packet.rs b/src/packet.rs
index 1c37513..5788100 100644
--- a/src/packet.rs
+++ b/src/packet.rs
@@ -4,7 +4,7 @@ use chrono::{DateTime, Local, Utc};
use hex::decode;
use tokio_util::bytes::{Buf, Bytes};
use structdiff::{Difference, StructDiff};
-use crate::crypto::{PrivateKey, PublicKey, SharedSecret};
+use crate::crypto::{PublicKey, SharedSecret};
#[derive(PartialEq, Debug, Clone, Difference)]
#[difference(expose)]