Skip to content

Commit

Permalink
Add feature flags to selectively enable tests (#22)
Browse files Browse the repository at this point in the history
Since most users don't need everything...
  • Loading branch information
randombit authored Aug 27, 2024
1 parent c5b2b64 commit deba931
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ documentation = "https://docs.rs/wycheproof"
categories = [ "cryptography" ]
rust-version = "1.57"

[features]
# By default all tests are included
default = ["aead", "cipher", "dsa", "ec", "ecdh", "ecdsa", "eddsa", "fpe", "hkdf", "keywrap", "mac", "primality", "rsa_enc", "rsa_sig", "xdh"]

aead = []
cipher = []
dsa = []
ec = []
ecdh = []
ecdsa = []
eddsa = []
fpe = []
hkdf = []
keywrap = []
mac = []
primality = []
rsa_enc = []
rsa_sig = []
xdh = []

[dependencies]
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,23 @@ Comments and patches are welcome.
This crate is licensed Apache 2.0-only, just as Wycheproof itself is. The files
in `src/data` are taken from
[the latest Wycheproof commit](https://github.com/google/wycheproof/commit/b063b4aedae951c69df014cd25fa6d69ae9e8cb9)

By default all available tests are compiled in. If you only need to test a few
specific algorithms, you can do so with `no-default-features` plus one or more
feature flags

* `aead`
* `cipher`
* `dsa`
* `ec`
* `ecdh`
* `ecdsa`
* `eddsa`
* `fpe`
* `hkdf`
* `keywrap`
* `mac`
* `primality`
* `rsa_enc`
* `rsa_sig`
* `xdh`
41 changes: 41 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
//! # Examples
//!
//! ```
//! #[cfg(feature = "aead")]
//! fn print_gcm() {
//! // Print all AES-GCM test vector data
//! let test_set = wycheproof::aead::TestSet::load(wycheproof::aead::TestName::AesGcm).unwrap();
Expand All @@ -55,6 +56,7 @@
//!
//! ```
//! // Iterate over all of the AEAD tests
//! #[cfg(feature = "aead")]
//! for aead in wycheproof::aead::TestName::all() {
//! println!("{:?}", aead);
//! }
Expand Down Expand Up @@ -464,6 +466,7 @@ pub enum Mgf {
}

/// Edwards curves
#[cfg(feature = "eddsa")]
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Deserialize)]
pub enum EdwardsCurve {
#[serde(alias = "edwards25519")]
Expand All @@ -473,6 +476,7 @@ pub enum EdwardsCurve {
}

/// Montgomery curves
#[cfg(feature = "xdh")]
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Deserialize)]
pub enum MontgomeryCurve {
#[serde(alias = "curve25519")]
Expand Down Expand Up @@ -553,22 +557,59 @@ impl LargeInteger {
mod test_keys;
pub use test_keys::*;

#[cfg(feature = "aead")]
pub mod aead;

#[cfg(feature = "cipher")]
pub mod cipher;

#[cfg(feature = "dsa")]
pub mod dsa;

#[cfg(feature = "ec")]
pub mod ec_curve;

#[cfg(feature = "ecdh")]
pub mod ecdh;

#[cfg(feature = "ecdsa")]
pub mod ecdsa;

#[cfg(feature = "eddsa")]
pub mod eddsa;

#[cfg(feature = "fpe")]
pub mod fpe_list;

#[cfg(feature = "fpe")]
pub mod fpe_str;

#[cfg(feature = "hkdf")]
pub mod hkdf;

#[cfg(feature = "keywrap")]
pub mod keywrap;

#[cfg(feature = "mac")]
pub mod mac;

#[cfg(feature = "mac")]
pub mod mac_with_nonce;

#[cfg(feature = "primality")]
pub mod primality;

#[cfg(feature = "rsa_enc")]
pub mod rsa_oaep;

#[cfg(feature = "rsa_enc")]
pub mod rsa_pkcs1_decrypt;

#[cfg(feature = "rsa_sig")]
pub mod rsa_pkcs1_verify;

#[cfg(feature = "rsa_sig")]
pub mod rsa_pss_verify;

#[cfg(feature = "xdh")]
pub mod xdh;
9 changes: 9 additions & 0 deletions src/test_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn int_from_base64<'de, D: Deserializer<'de>>(deserializer: D) -> Result<LargeIn
Ok(LargeInteger::new(bytes))
}

#[cfg(feature = "ecdsa")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EcdsaPublicJwk {
Expand All @@ -21,6 +22,7 @@ pub struct EcdsaPublicJwk {
pub affine_y: LargeInteger,
}

#[cfg(feature = "rsa_sig")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RsaPublicJwk {
Expand All @@ -33,6 +35,7 @@ pub struct RsaPublicJwk {
pub n: LargeInteger,
}

#[cfg(feature = "rsa_enc")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RsaPrivateJwk {
Expand All @@ -57,6 +60,7 @@ pub struct RsaPrivateJwk {
pub qi: LargeInteger,
}

#[cfg(feature = "eddsa")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EddsaPublicJwk {
Expand All @@ -68,6 +72,7 @@ pub struct EddsaPublicJwk {
pub x: LargeInteger,
}

#[cfg(feature = "rsa_enc")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RsaPrivate {
Expand All @@ -89,6 +94,7 @@ pub struct RsaPrivate {
pub c: LargeInteger,
}

#[cfg(feature = "rsa_sig")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct RsaPublic {
Expand All @@ -100,6 +106,7 @@ pub struct RsaPublic {

define_typeid!(EcPublicKeyTypeId => "EcPublicKey");

#[cfg(feature = "ecdsa")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EcdsaPublic {
Expand All @@ -118,6 +125,7 @@ pub struct EcdsaPublic {

define_typeid!(DsaPublicKeyTypeId => "DsaPublicKey");

#[cfg(feature = "dsa")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct DsaPublic {
Expand All @@ -133,6 +141,7 @@ pub struct DsaPublic {

define_typeid!(EddsaPublicKeyTypeId => "EDDSAPublicKey");

#[cfg(feature = "eddsa")]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct EddsaPublic {
Expand Down
19 changes: 19 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "aead")]
#[test]
fn test_aead_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::aead::TestName::all() {
Expand All @@ -6,6 +7,7 @@ fn test_aead_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "cipher")]
#[test]
fn test_cipher_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::cipher::TestName::all() {
Expand All @@ -14,6 +16,7 @@ fn test_cipher_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "dsa")]
#[test]
fn test_dsa_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::dsa::TestName::all() {
Expand All @@ -22,6 +25,7 @@ fn test_dsa_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "ecdh")]
#[test]
fn test_ecdh_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::ecdh::TestName::all() {
Expand All @@ -30,6 +34,7 @@ fn test_ecdh_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "ecdsa")]
#[test]
fn test_ecdsa_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::ecdsa::TestName::all() {
Expand All @@ -38,6 +43,7 @@ fn test_ecdsa_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "eddsa")]
#[test]
fn test_eddsa_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::eddsa::TestName::all() {
Expand All @@ -46,6 +52,7 @@ fn test_eddsa_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "ec")]
#[test]
fn test_ec_curve_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::ec_curve::TestName::all() {
Expand All @@ -54,6 +61,7 @@ fn test_ec_curve_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "fpe")]
#[test]
fn test_fpe_str_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::fpe_str::TestName::all() {
Expand All @@ -62,6 +70,7 @@ fn test_fpe_str_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "fpe")]
#[test]
fn test_fpe_list_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::fpe_list::TestName::all() {
Expand All @@ -70,6 +79,7 @@ fn test_fpe_list_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "hkdf")]
#[test]
fn test_hkdf_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::hkdf::TestName::all() {
Expand All @@ -78,6 +88,7 @@ fn test_hkdf_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "keywrap")]
#[test]
fn test_keywrap_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::keywrap::TestName::all() {
Expand All @@ -86,6 +97,7 @@ fn test_keywrap_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "mac")]
#[test]
fn test_mac_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::mac::TestName::all() {
Expand All @@ -94,6 +106,7 @@ fn test_mac_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "mac")]
#[test]
fn test_mac_with_nonce_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::mac_with_nonce::TestName::all() {
Expand All @@ -102,6 +115,7 @@ fn test_mac_with_nonce_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "primality")]
#[test]
fn test_primality_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::primality::TestName::all() {
Expand All @@ -110,6 +124,7 @@ fn test_primality_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "rsa_enc")]
#[test]
fn test_rsa_oaep_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::rsa_oaep::TestName::all() {
Expand All @@ -118,6 +133,7 @@ fn test_rsa_oaep_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "rsa_enc")]
#[test]
fn test_rsa_pkcs1_decrypt_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::rsa_pkcs1_decrypt::TestName::all() {
Expand All @@ -126,6 +142,7 @@ fn test_rsa_pkcs1_decrypt_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "rsa_sig")]
#[test]
fn test_rsa_pkcs1_verify_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::rsa_pkcs1_verify::TestName::all() {
Expand All @@ -134,6 +151,7 @@ fn test_rsa_pkcs1_verify_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "rsa_sig")]
#[test]
fn test_rsa_pss_verify_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::rsa_pss_verify::TestName::all() {
Expand All @@ -142,6 +160,7 @@ fn test_rsa_pss_verify_parsing() -> Result<(), wycheproof::WycheproofError> {
Ok(())
}

#[cfg(feature = "xdh")]
#[test]
fn test_xdh_parsing() -> Result<(), wycheproof::WycheproofError> {
for test in wycheproof::xdh::TestName::all() {
Expand Down

0 comments on commit deba931

Please sign in to comment.