Crate pqx

Source
Expand description

Implement PQC-Kyber with X25519 to shared a secret key in a post-quantum resistant way. The test implements a way to implement the communication between Alice and bob. Be careful though, verification of public key is not performed here.

This crate has not undergo any security audit and should be used with caution!
use std::sync::mpsc::channel;
use std::time::Duration;
use std::thread;
use pqx::*;
let (sender1, receiver1) = channel();
let (sender2, receiver2) = channel();
let thread = thread::spawn(move || {
    let bob_s = Combinedkey::default();
    let bob_p = Combinedpub::new(&bob_s);
    sender1.send(bob_p.to_string()).unwrap();
    let cipher = receiver2.recv_timeout(Duration::new(20,0)).unwrap();
    let cipher = Combinedcipher::from(cipher);
    Combinedshared::new(bob_s, cipher).unwrap()
});
let alice_s = Combinedkey::default();
let pubkey = receiver1.recv_timeout(Duration::new(20,0)).unwrap();
let pubkey = Combinedpub::try_from(pubkey.as_str()).unwrap();
let kyberelem = Combinedcipher::new(&alice_s,&pubkey).unwrap();
sender2.send(kyberelem.getcipher()).unwrap();
let shared = Combinedshared::getfromshared(kyberelem, pubkey, alice_s).unwrap().getshared(SHAREDSIZE::Med);
let result = thread.join().unwrap().getshared(SHAREDSIZE::Med);
assert!(shared==result,"Invalid shared, got {:#?} and {:#?}",shared,result);
//println!("Valid shared, got {}",hex::encode(shared.get()))

Modules§

key

Structs§

Combinedcipher
The combinated shared to share between persons to obtain the secret key as well as the shared_key on server side
Combinedkey
The combinated key containing private key for X25519 and Kyber, should not be transferred
Combinedpub
The combination key containing public key for X25519 and Kyber.
Combinedshared
Generation of the shared key
Finalkey
Final shared key after rounds of sha256

Enums§

PqxError
PqxError gathers every error that can happen on this crate. There are opaque by design and distinguishs bad input or error in generation.
SHAREDSIZE
Size of shared key wanted