diff --git a/quicktap/src/drivers/linux.rs b/quicktap/src/drivers/linux.rs index b99aa62..dd7971e 100644 --- a/quicktap/src/drivers/linux.rs +++ b/quicktap/src/drivers/linux.rs @@ -57,12 +57,7 @@ impl GenericDriver for TunDevice { } fn write(&mut self, packet: TunPacket) -> Result<(), Box> { - loop { - let written = self.device.write(&packet.packet)?; - if written == 0 { - break; - } - } + let _ = self.device.write(&packet.packet)?; Ok(()) } } \ No newline at end of file diff --git a/quicktap/src/qcrypto/aead.rs b/quicktap/src/qcrypto/aead.rs index 9ce3cf8..5077517 100644 --- a/quicktap/src/qcrypto/aead.rs +++ b/quicktap/src/qcrypto/aead.rs @@ -1,4 +1,4 @@ -use chacha20poly1305::{ChaCha20Poly1305, Error, Key, KeyInit, XChaCha20Poly1305}; +use chacha20poly1305::{ChaCha20Poly1305, Error, KeyInit, XChaCha20Poly1305}; use chacha20poly1305::aead::{Aead, Payload, Nonce}; pub fn qcrypto_aead(key: &[u8; 32], counter: u64, plaintext: &[u8], authtext: &[u8]) -> Result, Error> { diff --git a/quicktap/src/qcrypto/hkdf.rs b/quicktap/src/qcrypto/hkdf.rs index b8af21d..83f7681 100644 --- a/quicktap/src/qcrypto/hkdf.rs +++ b/quicktap/src/qcrypto/hkdf.rs @@ -9,8 +9,8 @@ pub fn qcrypto_hkdf(key: &[u8], input: &[u8]) -> Result<[[u8; 32 result_array[0] = t1; - for n in 0..N { - result_array[n-1] = qcrypto_hmac_twice(&t0, &result_array[n-2], &[n as u8]); + for n in 1..N { + result_array[n] = qcrypto_hmac_twice(&t0, &result_array[n-1], &[n as u8]); } Ok(result_array) diff --git a/quicktap/src/qcrypto/tests.rs b/quicktap/src/qcrypto/tests.rs index 51c9f43..1246e32 100644 --- a/quicktap/src/qcrypto/tests.rs +++ b/quicktap/src/qcrypto/tests.rs @@ -2,6 +2,7 @@ use hex_lit::hex; use x25519_dalek::PublicKey; use crate::qcrypto::aead::{qcrypto_aead, qcrypto_aead_decrypt, qcrypto_xaead, qcrypto_xaead_decrypt}; use crate::qcrypto::hashes::{qcrypto_hash, qcrypto_hmac, qcrypto_mac}; +use crate::qcrypto::hkdf::qcrypto_hkdf; use crate::qcrypto::pki::{qcrypto_dh, qcrypto_dh_generate}; #[test] @@ -41,4 +42,9 @@ fn qcrypto_aead_test() { fn qcrypto_xaead_test() { let ciphertext = qcrypto_xaead(&[0u8; 32], &[0u8; 24], &[0u8; 32], &[0u8; 32]).unwrap(); assert_eq!(qcrypto_xaead_decrypt(&[0u8; 32], &[0u8; 24], &ciphertext, &[0u8; 32]).unwrap(), [0u8; 32].to_vec()) +} +#[test] +fn qcrypto_hkdf_test() { + let derived = qcrypto_hkdf::<1>(&[0u8; 32], &[0u8; 32]).unwrap(); + assert_eq!(derived, [hex!("1090894613df8aef670b0b867e222daebc0d3e436cdddbc16c65855ab93cc91a")]) } \ No newline at end of file