Update private and public key

This commit is contained in:
2024-05-13 14:20:13 +02:00
parent ccb18075a5
commit 1cf91d08f1

View File

@@ -1,22 +1,18 @@
use anyhow::Result;
use blake2::{digest::Mac, Blake2s, Blake2sMac, Digest};
use byteorder::LittleEndian;
use rand::rngs::StdRng;
use rand::RngCore;
use rand::SeedableRng;
use snow::Builder;
use std::io; use std::io;
use std::net::UdpSocket; use std::net::UdpSocket;
use anyhow::Result;
use snow::Builder;
use x25519_dalek::PublicKey; use x25519_dalek::PublicKey;
use x25519_dalek::StaticSecret; use x25519_dalek::StaticSecret;
use zerocopy::{AsBytes,FromBytes,FromZeroes};
use byteorder::LittleEndian;
use zerocopy::byteorder::U32; use zerocopy::byteorder::U32;
use blake2::{Blake2sMac, Blake2s, Digest, digest::{Mac,KeyInit}}; use zerocopy::{AsBytes, FromBytes, FromZeroes};
use rand::rngs::StdRng;
use rand::SeedableRng;
use rand::RngCore;
use csv::Writer;
const SIZE_MAC: usize = 16;
const SIZE_TAG: usize = 16; // poly1305 tag const SIZE_TAG: usize = 16; // poly1305 tag
const SIZE_XNONCE: usize = 24; // xchacha20 nonce
const SIZE_COOKIE: usize = 16; //
const SIZE_X25519_POINT: usize = 32; // x25519 public key const SIZE_X25519_POINT: usize = 32; // x25519 public key
const SIZE_TIMESTAMP: usize = 12; const SIZE_TIMESTAMP: usize = 12;
@@ -34,9 +30,9 @@ pub struct NoiseInitiation {
pub f_timestamp: [u8; SIZE_TIMESTAMP + SIZE_TAG], pub f_timestamp: [u8; SIZE_TIMESTAMP + SIZE_TAG],
} }
use std::time::{Instant, SystemTime, UNIX_EPOCH};
use blake2::digest::typenum::U16; use blake2::digest::typenum::U16;
use serde::Serialize; use serde::Serialize;
use std::time::{Instant, SystemTime, UNIX_EPOCH};
pub type TAI64N = [u8; 12]; pub type TAI64N = [u8; 12];
@@ -61,10 +57,16 @@ pub fn now() -> TAI64N {
} }
fn perform_handshake() -> Result<u128> { fn perform_handshake() -> Result<u128> {
let private_key = StaticSecret::from([152, 54, 147, 217, 172, 232, 187, 88, 157, 200, 193, 94, 123, 74, 67, 104, 181, 18, 19, 244, 73, 108, 87, 152, 244, 100, 123, 188, 90, 121, 218, 96]); let private_key = StaticSecret::from([
let public_key = PublicKey::from(&private_key); 112, 3, 135, 100, 197, 196, 171, 109, 13, 243, 249, 30, 91, 137, 88, 174, 72, 94, 143, 122,
2, 21, 227, 21, 222, 226, 127, 221, 253, 182, 120, 100,
]);
let _ = PublicKey::from(&private_key);
let remote_public_key = PublicKey::from([52, 55, 49, 225, 89, 226, 78, 2, 30, 129, 213, 254, 101, 84, 124, 121, 14, 228, 251, 120, 124, 83, 215, 201, 213, 59, 68, 9, 209, 161, 62, 53]); let remote_public_key = PublicKey::from([
247, 61, 49, 57, 18, 173, 228, 54, 73, 122, 167, 57, 231, 254, 152, 22, 88, 209, 207, 114,
175, 247, 76, 143, 22, 194, 15, 128, 120, 200, 145, 59,
]);
let preshared_key: [u8; 32] = [0; 32]; let preshared_key: [u8; 32] = [0; 32];
@@ -104,7 +106,7 @@ fn perform_handshake() -> Result<u128> {
assert_eq!(size, initiation.len()); assert_eq!(size, initiation.len());
let mut buf = [0u8; 92]; let mut buf = [0u8; 92];
let (number_of_bytes, src_addr) = socket.recv_from(&mut buf)?; let (number_of_bytes, _) = socket.recv_from(&mut buf)?;
let end = Instant::now(); let end = Instant::now();
@@ -115,14 +117,16 @@ fn perform_handshake() -> Result<u128> {
#[derive(Serialize)] #[derive(Serialize)]
struct Record { struct Record {
time: u128 time: u128,
} }
fn main() -> Result<()> { fn main() -> Result<()> {
let mut wtr = csv::Writer::from_writer(io::stdout()); let mut wtr = csv::Writer::from_writer(io::stdout());
for _ in 0..1_000_000 { for _ in 0..1_000_000 {
wtr.serialize(Record {time: perform_handshake()?})?; wtr.serialize(Record {
time: perform_handshake()?,
})?;
} }
wtr.flush()?; wtr.flush()?;