Expand description
THIS CRATE HAS NOT UNDERGONE AUDITS AND SHOULD NOT BE USED FOR SECURE PURPOSES BUT ONLY FOR EDUCATIONAL AND SCIENTIFIC PURPOSES THIS CRATE USES SAFE_PQC_KYBER BECAUSE OF https://github.com/rustsec/advisory-db/pull/1872/files
§KEM generation
use safe_pqc_kyber::*;
use kyberauth::*;
use std::net::SocketAddr;
fn createkeys() -> Keypair {
let mut rng = rand::thread_rng();
keypair(&mut rng)
}
§Server and client interface
§Client
use safe_pqc_kyber::*;
use std::net::{IpAddr,SocketAddr,Ipv4Addr};
use kyberauth::*;
const TEST: &str="HELLO WORLD";
async fn server() -> Result<(), KyberError> {
let mut rng = rand::thread_rng();
let keys = keypair(&mut rng);
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 43050);
let listener = server::startlistener(addr).await;
let listener = match listener {
Ok(listener) => listener,
Err(_) => {
return Err(KyberError::InvalidInput);
}
};
let _ = match server::listener(&keys, listener, false).await {
Ok(mut elem) => {
elem.senddata(TEST.as_bytes()).await.unwrap();
return Ok(());
}
Err(e) => {
return Err(KyberError::InvalidInput);
}
};
}
§Server
use safe_pqc_kyber::*;
use std::net::{Ipv4Addr,SocketAddr,IpAddr};
use kyberauth::client;
const TEST: &str="HELLO WORLD";
async fn client() -> Result<(), KyberError> {
let mut rng = rand::thread_rng();
let keys = keypair(&mut rng);
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 43050);
let _ = match client::connecter(&keys, addr).await {
Ok(mut elem) => {
let text = elem.receivedata().await.unwrap();
if text.len() == 0 {
eprintln!("Invalid response!");
return Err(KyberError::InvalidInput);
}
let info = String::from_utf8(text).unwrap();
assert_eq!(info, TEST);
println!("The peer is {} and public key is {}",elem.getpeer(),String::from_utf8(elem.getpeerkey(false).unwrap()).unwrap());
()
}
Err(e) => {
eprintln!("Error is {}", e);
return Err(KyberError::InvalidInput);
}
};
Ok(())
}
Modules§
Functions§
- Extract keys from public or private file containing the key
- Print private key and public key to a file. Keep your private key safe. Keys is the keypair, privatekey is the first to write the private key and publickey the file to create public key. Ex: