Skip to content

Commit

Permalink
Add secp benches, kat_tests, aead tests, lib docs example
Browse files Browse the repository at this point in the history
  • Loading branch information
DanGould committed Aug 10, 2024
1 parent 6794f1c commit 359b506
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 5 deletions.
5 changes: 5 additions & 0 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,11 @@ pub fn benches() {
hpke::kdf::HkdfSha256,
hpke::kem::X25519HkdfSha256,
>("Non-NIST[seclevel=128]", &mut c);

#[cfg(feature = "secp")]
bench_ciphersuite::<hpke::aead::AesGcm128, hpke::kdf::HkdfSha256, hpke::kem::SecpK256HkdfSha256>(
"secp", &mut c,
);
}

criterion_main!(benches);
29 changes: 29 additions & 0 deletions src/aead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,35 @@ mod test {
);
}

#[cfg(all(feature = "secp", any(feature = "alloc", feature = "std")))]
mod secp_tests {
use super::*;

test_export_idempotence!(test_export_idempotence_k256, crate::kem::DhP256HkdfSha256);
test_exportonly_panics!(
test_exportonly_panics_k256_seal,
test_exportonly_panics_k256_open,
crate::kem::DhK256HkdfSha256
);
test_overflow!(test_overflow_k256, crate::kem::DhK256HkdfSha256);

test_ctx_correctness!(
test_ctx_correctness_aes128_k256,
AesGcm128,
crate::kem::DhK256HkdfSha256
);
test_ctx_correctness!(
test_ctx_correctness_aes256_k256,
AesGcm256,
crate::kem::DhK256HkdfSha256
);
test_ctx_correctness!(
test_ctx_correctness_chacha_k256,
ChaCha20Poly1305,
crate::kem::DhK256HkdfSha256
);
}

/// Tests that Serialize::write_exact() panics when given a buffer of incorrect length
#[should_panic]
#[test]
Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@
//!
//! ```
//! # #[cfg(any(feature = "alloc", feature = "std"))] {
//! # #[cfg(feature = "x25519")]
//! # #[cfg(feature = "secp")]
//! # {
//! # use rand::{rngs::StdRng, SeedableRng};
//! # use hpke::{
//! # aead::ChaCha20Poly1305,
//! # kdf::HkdfSha384,
//! # kem::X25519HkdfSha256,
//! # kdf::HkdfSha256,
//! # kem::SecpK256HkdfSha256,
//! # Kem as KemTrait, OpModeR, OpModeS, setup_receiver, setup_sender,
//! # };
//! // These types define the ciphersuite Alice and Bob will be using
//! type Kem = X25519HkdfSha256;
//! type Kem = SecpK256HkdfSha256;
//! type Aead = ChaCha20Poly1305;
//! type Kdf = HkdfSha384;
//! type Kdf = HkdfSha256;
//!
//! let mut csprng = StdRng::from_entropy();
//! # let (bob_sk, bob_pk) = Kem::gen_keypair(&mut csprng);
Expand Down

0 comments on commit 359b506

Please sign in to comment.