diff --git a/README.md b/README.md index cf8210a..5c9fa13 100644 --- a/README.md +++ b/README.md @@ -93,8 +93,8 @@ fn main() { // Move to transport state let mut alice = alice.finalize().unwrap(); - // All done! Use .send() and .receive() on the transport state to communicate - // with the peer + // All done! Use .send() and .receive() on the transport state to encrypt + // and decrypt communication with the peer let n = alice.send(b"Hello from Alice", &mut buf_alice_send).unwrap(); my_send_function(&buf_alice_send[..n]); } diff --git a/src/lib.rs b/src/lib.rs index e449233..c8f6557 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -64,7 +64,7 @@ //! Simplified example with the most straightforward (and unsecure) PQ handshake pattern and //! no handshake payload data at all: //! -//! ```ignore +//! ```no_run //! use clatter::crypto::cipher::ChaChaPoly; //! use clatter::crypto::hash::Sha512; //! use clatter::crypto::kem::rust_crypto_kyber::Kyber512; @@ -72,44 +72,41 @@ //! use clatter::traits::Handshaker; //! use clatter::PqHandshake; //! -//! fn main() { -//! let mut rng_alice = rand::thread_rng(); -//! -//! // Instantiate initiator handshake -//! let mut alice = PqHandshake::::new( -//! noise_pqnn(), // Handshake pattern -//! &[], // Prologue data -//! true, // Are we the initiator -//! None, // Pre-shared keys.. -//! None, // .. -//! None, // .. -//! None, // .. -//! &mut rng_alice, // RNG instance -//! ).unwrap(); -//! -//! let mut buf_alice_send = [0u8; 4096]; -//! let mut buf_alice_receive = [0u8; 4096]; -//! -//! // Write handshake message and deliver to peer -//! let n = alice.write_message(&[], &mut buf_alice_send).unwrap(); -//! my_send_function(&buf_alice_send[..n]); -//! -//! // Receive handshake message and process it -//! let n = my_receive_function(&mut buf_alice_receive); -//! let _ = alice.read_message(&buf_alice_receive[..n], &mut[]).unwrap(); -//! -//! assert!(alice.is_finished()); -//! -//! // Move to transport state -//! let mut alice = alice.finalize().unwrap(); -//! -//! // All done! Use .send() and .receive() on the transport state to communicate -//! // with the peer -//! let n = alice.send(b"Hello from Alice", &mut buf_alice_send).unwrap(); -//! my_send_function(& buf_alice_send[..n]); -//! } +//! let mut rng_alice = rand::thread_rng(); +//! +//! // Instantiate initiator handshake +//! let mut alice = PqHandshake::::new( +//! noise_pqnn(), // Handshake pattern +//! &[], // Prologue data +//! true, // Are we the initiator +//! None, // Pre-shared keys.. +//! None, // .. +//! None, // .. +//! None, // .. +//! &mut rng_alice, // RNG instance +//! ).unwrap(); +//! +//! let mut buf_alice_send = [0u8; 4096]; +//! let mut buf_alice_receive = [0u8; 4096]; +//! +//! // Write handshake message and deliver to peer +//! let n = alice.write_message(&[], &mut buf_alice_send).unwrap(); +//! // --> Send &buf_alice_send[..n]) to peer +//! +//! // Receive handshake message and process it +//! // <-- Receive message from peer to &buf_alice_receive +//! let _ = alice.read_message(&buf_alice_receive[..n], &mut[]).unwrap(); +//! +//! assert!(alice.is_finished()); +//! +//! // Move to transport state +//! let mut alice = alice.finalize().unwrap(); +//! +//! // All done! Use .send() and .receive() on the transport state to encrypt +//! // and decrypt communication with the peer +//! let n = alice.send(b"Hello from Alice", &mut buf_alice_send).unwrap(); +//! // --> Send &buf_alice_send[..n]) to peer //! ``` -#![allow(clippy::needless_doctest_main)] // Not really used for now #[cfg(feature = "alloc")] diff --git a/test.sh b/test.sh index c29774d..71d56b6 100755 --- a/test.sh +++ b/test.sh @@ -1,4 +1,4 @@ -cargo test --features=\ +cargo test --release --features=\ use-sha,\ use-blake2,\ use-aes-gcm,\ diff --git a/tests/smoke.rs b/tests/smoke.rs index db251eb..44eb248 100644 --- a/tests/smoke.rs +++ b/tests/smoke.rs @@ -3,7 +3,7 @@ use clatter::bytearray::ByteArray; use clatter::crypto::cipher::{AesGcm, ChaChaPoly}; use clatter::crypto::dh::X25519; -use clatter::crypto::hash::{Blake2b, Sha512}; +use clatter::crypto::hash::{Blake2b, Blake2s, Sha256, Sha512}; #[cfg(feature = "use-argyle-kyber768")] use clatter::crypto::kem::argyle_software_kyber::Kyber768 as ArgyleKyber; use clatter::crypto::kem::{pqclean_kyber, rust_crypto_kyber}; @@ -56,7 +56,14 @@ fn smoke_nq_handshakes() { for pattern in handshakes { nq_handshake::(pattern.clone()); - nq_handshake::(pattern); + nq_handshake::(pattern.clone()); + nq_handshake::(pattern.clone()); + nq_handshake::(pattern.clone()); + + nq_handshake::(pattern.clone()); + nq_handshake::(pattern.clone()); + nq_handshake::(pattern.clone()); + nq_handshake::(pattern.clone()); } } @@ -95,15 +102,40 @@ fn smoke_pq_handshakes() { noise_pqxx_psk3(), ]; + fn cipher_hash_combos(pattern: HandshakePattern) { + pq_handshake::(pattern.clone()); + pq_handshake::(pattern.clone()); + pq_handshake::(pattern.clone()); + pq_handshake::(pattern.clone()); + + pq_handshake::(pattern.clone()); + pq_handshake::(pattern.clone()); + pq_handshake::(pattern.clone()); + pq_handshake::(pattern.clone()); + } + for pattern in handshakes { - pq_handshake::( + // Rust crypto + cipher_hash_combos::( + pattern.clone(), + ); + cipher_hash_combos::( pattern.clone(), ); - pq_handshake::( + cipher_hash_combos::( pattern.clone(), ); + + // PQCLean + cipher_hash_combos::(pattern.clone()); + cipher_hash_combos::(pattern.clone()); + cipher_hash_combos::(pattern.clone()); + + // One cross-use test just in case + cipher_hash_combos::(pattern.clone()); + #[cfg(feature = "use-argyle-kyber768")] - pq_handshake::(pattern); + cipher_hash_combos::(pattern); } } @@ -217,8 +249,8 @@ fn pq_handshake(pattern: HandshakePatt bob.push_psk(psk); } - let mut alice_buf = [0u8; 4096]; - let mut bob_buf = [0u8; 4096]; + let mut alice_buf = [0u8; 8182]; + let mut bob_buf = [0u8; 8182]; loop { let n = alice.write_message(&[], &mut alice_buf).unwrap();