diff options
| author | Will Dillon <william@housedillon.com> | 2025-11-06 19:29:47 +0000 |
|---|---|---|
| committer | Will Dillon <william@housedillon.com> | 2025-11-06 19:29:47 +0000 |
| commit | 0024a422ba6e4459d50dca87deb369cb1d2906af (patch) | |
| tree | 0e0e60909c604ca42bfbc7b5a53c52c53e6a45f9 /src | |
| parent | Try to pivot from Dalek to RustCrypto (diff) | |
| download | meshcore-rs-0024a422ba6e4459d50dca87deb369cb1d2906af.tar.gz meshcore-rs-0024a422ba6e4459d50dca87deb369cb1d2906af.zip | |
Finally building again; what a nightmare
Diffstat (limited to 'src')
| -rw-r--r-- | src/crypto.rs | 28 | ||||
| -rw-r--r-- | src/packet.rs | 2 |
2 files changed, 15 insertions, 15 deletions
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)] |
