Crate wycheproof

source ·
Expand description

Wycheproof test vectors

Wycheproof is a set of cryptographic tests created by a team at Google which checks for common bugs and corner cases in cryptographic code.

This crate is a convenient repacking of the Wycheproof JSON-formatted test data with deserialization to easily usable structs.

Hex and base64 encoded data is decoded to binary in the BinaryString struct which is a light wrapper around Vec<u8>.

Large integers (such as those used in the RSA test data) are decoded as big-endian byte arrays into a LargeInteger struct, which is again a light wrapper around Vec<u8>. Additionally if the num-bigint feature is enabled, this type also gains a conversion function to num_bigint::BigUint.

Each submodule of this crate includes a set of structs: a TestName which specifies which individual test is desired, a TestSet which is the set of data associated with the TestName. Each TestSet contains one or more TestGroups, which in turn contain some amount of test-specific configuration information along with a list of Test which are the actual tests.

Each test has an expected result which is either Valid, Invalid, or Acceptable. Acceptable just means that the test is technically valid but might still be rejected for various reasons, for instance because the hash function that was used is too weak for proper security.

Examples

fn print_gcm() {
    // Print all AES-GCM test vector data
    let test_set = wycheproof::aead::TestSet::load(wycheproof::aead::TestName::AesGcm).unwrap();

    for test_group in test_set.test_groups {
        println!(
            "* Group key size:{} tag size:{} nonce size:{}",
            test_group.key_size, test_group.tag_size, test_group.nonce_size,
        );
        for test in test_group.tests {
            println!(
                "Test:{} Key:{} AAD:{} PT:{} CT:{} Tag:{}",
                test.tc_id,
                hex::encode(test.key),
                hex::encode(test.aad),
                hex::encode(test.pt),
                hex::encode(test.ct),
                hex::encode(test.tag)
            );
        }
    }
}
// Iterate over all of the AEAD tests
for aead in wycheproof::aead::TestName::all() {
   println!("{:?}", aead);
}

Modules

Structs

Enums