quick n fixn. handshakin next
This commit is contained in:
parent
611ae05913
commit
04e25fa5b3
|
@ -57,12 +57,7 @@ impl GenericDriver for TunDevice {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&mut self, packet: TunPacket) -> Result<(), Box<dyn Error>> {
|
fn write(&mut self, packet: TunPacket) -> Result<(), Box<dyn Error>> {
|
||||||
loop {
|
let _ = self.device.write(&packet.packet)?;
|
||||||
let written = self.device.write(&packet.packet)?;
|
|
||||||
if written == 0 {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
use chacha20poly1305::{ChaCha20Poly1305, Error, Key, KeyInit, XChaCha20Poly1305};
|
use chacha20poly1305::{ChaCha20Poly1305, Error, KeyInit, XChaCha20Poly1305};
|
||||||
use chacha20poly1305::aead::{Aead, Payload, Nonce};
|
use chacha20poly1305::aead::{Aead, Payload, Nonce};
|
||||||
|
|
||||||
pub fn qcrypto_aead(key: &[u8; 32], counter: u64, plaintext: &[u8], authtext: &[u8]) -> Result<Vec<u8>, Error> {
|
pub fn qcrypto_aead(key: &[u8; 32], counter: u64, plaintext: &[u8], authtext: &[u8]) -> Result<Vec<u8>, Error> {
|
||||||
|
|
|
@ -9,8 +9,8 @@ pub fn qcrypto_hkdf<const N: usize>(key: &[u8], input: &[u8]) -> Result<[[u8; 32
|
||||||
|
|
||||||
result_array[0] = t1;
|
result_array[0] = t1;
|
||||||
|
|
||||||
for n in 0..N {
|
for n in 1..N {
|
||||||
result_array[n-1] = qcrypto_hmac_twice(&t0, &result_array[n-2], &[n as u8]);
|
result_array[n] = qcrypto_hmac_twice(&t0, &result_array[n-1], &[n as u8]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(result_array)
|
Ok(result_array)
|
||||||
|
|
|
@ -2,6 +2,7 @@ use hex_lit::hex;
|
||||||
use x25519_dalek::PublicKey;
|
use x25519_dalek::PublicKey;
|
||||||
use crate::qcrypto::aead::{qcrypto_aead, qcrypto_aead_decrypt, qcrypto_xaead, qcrypto_xaead_decrypt};
|
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::hashes::{qcrypto_hash, qcrypto_hmac, qcrypto_mac};
|
||||||
|
use crate::qcrypto::hkdf::qcrypto_hkdf;
|
||||||
use crate::qcrypto::pki::{qcrypto_dh, qcrypto_dh_generate};
|
use crate::qcrypto::pki::{qcrypto_dh, qcrypto_dh_generate};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -42,3 +43,8 @@ fn qcrypto_xaead_test() {
|
||||||
let ciphertext = qcrypto_xaead(&[0u8; 32], &[0u8; 24], &[0u8; 32], &[0u8; 32]).unwrap();
|
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())
|
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")])
|
||||||
|
}
|
Loading…
Reference in New Issue