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

#[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();

    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,
                data_encoding::HEXLOWER.encode(&test.key),
                data_encoding::HEXLOWER.encode(&test.aad),
                data_encoding::HEXLOWER.encode(&test.pt),
                data_encoding::HEXLOWER.encode(&test.ct),
                data_encoding::HEXLOWER.encode(&test.tag)
            );
        }
    }
}
// Iterate over all of the AEAD tests
#[cfg(feature = "aead")]
for aead in wycheproof::aead::TestName::all() {
   println!("{:?}", aead);
}

Modules§

aead
AEAD tests
cipher
IND-CPA cipher tests
dsa
DSA verification tests
ec_curve
Elliptic Curve Information
ecdh
ECDH key agreement tests
ecdsa
ECDSA tests
eddsa
EdDSA verification tests
fpe_list
Format Preseverving Encryption
fpe_str
Format Preseverving Encryption
hkdf
HKDF tests
keywrap
NIST keywrapping tests
mac
Message Authentication Code tests
mac_with_nonce
Message Authentication Code tests
primality
Primality checking tests
rsa_oaep
RSA OAEP decryption tests
rsa_pkcs1_decrypt
RSA PKCS1v1.5 decryption tests
rsa_pkcs1_verify
RSA PKCS1v1.5 verification tests
rsa_pss_verify
RSA PSS verification tests
xdh
Montgomery curve ECDH tests

Structs§

ByteString
CVE
DsaPublic
EcdsaPublic
EcdsaPublicJwk
EddsaPublic
EddsaPublicJwk
LargeInteger
RsaPrivate
RsaPrivateJwk
RsaPublic
RsaPublicJwk
TestFlagInfo
URL

Enums§

BugType
EdwardsCurve
Edwards curves
EllipticCurve
Prime order elliptic curves
HashFunction
Hash Function identifiers
Mgf
MGF identifiers
MontgomeryCurve
Montgomery curves
TestResult
The expected result of a Wycheproof test
WycheproofError
The error type