Test vectors

Testing the correctness of the primitives implemented in each cryptography backend requires trusted test vectors. Where possible these vectors are obtained from official sources such as NIST or IETF RFCs. When this is not possible cryptography has chosen to create a set of custom vectors using an official vector file as input to verify consistency between implemented backends.

Vectors are kept in the cryptography_vectors package rather than within our main test suite.

Sources

Asymmetric ciphers

Custom asymmetric vectors

  • asymmetric/PEM_Serialization/ec_private_key.pem and asymmetric/DER_Serialization/ec_private_key.der - Contains an Elliptic Curve key generated by OpenSSL from the curve secp256r1.
  • asymmetric/PEM_Serialization/ec_private_key_encrypted.pem and asymmetric/DER_Serialization/ec_private_key_encrypted.der- Contains the same Elliptic Curve key as ec_private_key.pem, except that it is encrypted with AES-128 with the password “123456”.
  • asymmetric/PEM_Serialization/ec_public_key.pem and asymmetric/DER_Serialization/ec_public_key.der- Contains the public key corresponding to ec_private_key.pem, generated using OpenSSL.
  • asymmetric/PEM_Serialization/rsa_private_key.pem - Contains an RSA 2048 bit key generated using OpenSSL, protected by the secret “123456” with DES3 encryption.
  • asymmetric/PEM_Serialization/rsa_public_key.pem and asymmetric/DER_Serialization/rsa_public_key.der- Contains an RSA 2048 bit public generated using OpenSSL from rsa_private_key.pem.
  • asymmetric/PEM_Serialization/dsaparam.pem - Contains 2048-bit DSA parameters generated using OpenSSL; contains no keys.
  • asymmetric/PEM_Serialization/dsa_private_key.pem - Contains a DSA 2048 bit key generated using OpenSSL from the parameters in dsaparam.pem, protected by the secret “123456” with DES3 encryption.
  • asymmetric/PEM_Serialization/dsa_public_key.pem and asymmetric/DER_Serialization/dsa_public_key.der - Contains a DSA 2048 bit key generated using OpenSSL from dsa_private_key.pem.
  • asymmetric/PKCS8/unenc-dsa-pkcs8.pem and asymmetric/DER_Serialization/unenc-dsa-pkcs8.der - Contains a DSA 1024 bit key generated using OpenSSL.
  • asymmetric/PKCS8/unenc-dsa-pkcs8.pub.pem and asymmetric/DER_Serialization/unenc-dsa-pkcs8.pub.der - Contains a DSA 2048 bit public key generated using OpenSSL from unenc-dsa-pkcs8.pem.
  • DER conversions of the GnuTLS example keys for DSA as well as the OpenSSL example key for RSA.
  • DER conversions of enc-rsa-pkcs8.pem, enc2-rsa-pkcs8.pem, and unenc-rsa-pkcs8.pem.
  • asymmetric/public/PKCS1/rsa.pub.pem and asymmetric/public/PKCS1/rsa.pub.der are PKCS1 conversions of the public key from asymmetric/PKCS8/unenc-rsa-pkcs8.pem using PEM and DER encoding.

Key exchange

  • vectors/cryptography_vectors/asymmetric/DH/RFC5114.txt contains Diffie-Hellman examples from appendix A.1, A.2 and A.3 of RFC 5114.
  • vectors/cryptography_vectors/asymmetric/DH/vec.txt contains Diffie-Hellman examples from botan.
  • vectors/cryptography_vectors/asymmetric/DH/bad_exchange.txt contains Diffie-Hellman vector pairs that were generated using OpenSSL DH_generate_parameters_ex and DH_generate_key.
  • vectors/cryptography_vectors/asymmetric/DH/dhp.pem, vectors/cryptography_vectors/asymmetric/DH/dhkey.pem and vectors/cryptography_vectors/asymmetric/DH/dhpub.pem contains Diffie-Hellman parameters and key respectively. The keys were generated using OpenSSL following DHKE guide. vectors/cryptography_vectors/asymmetric/DH/dhkey.txt contains all parameter in text. vectors/cryptography_vectors/asymmetric/DH/dhp.der, vectors/cryptography_vectors/asymmetric/DH/dhkey.der and vectors/cryptography_vectors/asymmetric/DH/dhpub.der contains are the above parameters and keys in DER format.
  • vectors/cryptography_vectors/asymmetric/DH/dhp_rfc5114_2.pem, vectors/cryptography_vectors/asymmetric/DH/dhkey_rfc5114_2.pem and vectors/cryptography_vectors/asymmetric/DH/dhpub_rfc5114_2.pem contains Diffie-Hellman parameters and key respectively. The keys were generated using OpenSSL following DHKE guide. When creating the parameters we added the -pkeyopt dh_rfc5114:2 option to use RFC5114 2048 bit DH parameters with 224 bit subgroup. vectors/cryptography_vectors/asymmetric/DH/dhkey_rfc5114_2.txt contains all parameter in text. vectors/cryptography_vectors/asymmetric/DH/dhp_rfc5114_2.der, vectors/cryptography_vectors/asymmetric/DH/dhkey_rfc5114_2.der and vectors/cryptography_vectors/asymmetric/DH/dhpub_rfc5114_2.der contains are the above parameters and keys in DER format.

X.509

  • PKITS test suite from NIST PKI Testing.
  • v1_cert.pem from the OpenSSL source tree (testx509.pem).
  • ecdsa_root.pem - DigiCert Global Root G3, a secp384r1 ECDSA root certificate.
  • verisign-md2-root.pem - A legacy Verisign public root signed using the MD2 algorithm. This is a PEM conversion of the root data in the NSS source tree.
  • cryptography.io.pem - A leaf certificate issued by RapidSSL for the cryptography website.
  • rapidssl_sha256_ca_g3.pem - The intermediate CA that issued the cryptography.io.pem certificate.
  • wildcard_san.pem - A leaf certificate issued by a public CA for langui.sh that contains wildcard entries in the SAN extension.
  • san_edipartyname.der - A DSA certificate from a Mozilla bug containing a SAN extension with an ediPartyName general name.
  • san_x400address.der - A DSA certificate from a Mozilla bug containing a SAN extension with an x400Address general name.
  • department-of-state-root.pem - The intermediary CA for the Department of State, issued by the United States Federal Government’s Common Policy CA. Notably has a critical policy constraints extensions.
  • e-trust.ru.der - A certificate from a Russian CA signed using the GOST cipher and containing numerous unusual encodings such as NUMERICSTRING in the subject DN.
  • alternate-rsa-sha1-oid.pem - A certificate from an unknown signature OID Mozilla bug that uses an alternate signature OID for RSA with SHA1.
  • badssl-sct.pem - A certificate with the certificate transparency signed certificate timestamp extension.

Custom X.509 Vectors

  • invalid_version.pem - Contains an RSA 2048 bit certificate with the X.509 version field set to 0x7.
  • post2000utctime.pem - Contains an RSA 2048 bit certificate with the notBefore and notAfter fields encoded as post-2000 UTCTime.
  • dsa_selfsigned_ca.pem - Contains a DSA self-signed CA certificate generated using OpenSSL.
  • ec_no_named_curve.pem - Contains an ECDSA certificate that does not have an embedded OID defining the curve.
  • all_supported_names.pem - An RSA 2048 bit certificate generated using OpenSSL that contains a subject and issuer that have two of each supported attribute type from RFC 5280.
  • unsupported_subject_name.pem - An RSA 2048 bit self-signed CA certificate generated using OpenSSL that contains the unsupported “initials” name.
  • utf8_common_name.pem - An RSA 2048 bit self-signed CA certificate generated using OpenSSL that contains a UTF8String common name with the value “We heart UTF8!™”.
  • two_basic_constraints.pem - An RSA 2048 bit self-signed certificate containing two basic constraints extensions.
  • basic_constraints_not_critical.pem - An RSA 2048 bit self-signed certificate containing a basic constraints extension that is not marked as critical.
  • bc_path_length_zero.pem - An RSA 2048 bit self-signed certificate containing a basic constraints extension with a path length of zero.
  • unsupported_extension.pem - An RSA 2048 bit self-signed certificate containing an unsupported extension type. The OID was encoded as “1.2.3.4” with an extnValue of “value”.
  • unsupported_extension_2.pem - A secp256r1 certificate containing two unsupported extensions. The OIDs are 1.3.6.1.4.1.41482.2 with an extnValue of 1.3.6.1.4.1.41482.1.2 and 1.3.6.1.4.1.45724.2.1.1 with an extnValue of \x03\x02\x040
  • unsupported_extension_critical.pem - An RSA 2048 bit self-signed certificate containing an unsupported extension type marked critical. The OID was encoded as “1.2.3.4” with an extnValue of “value”.
  • san_email_dns_ip_dirname_uri.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with the following general names: rfc822Name, dNSName, iPAddress, directoryName, and uniformResourceIdentifier.
  • san_empty_hostname.pem - An RSA 2048 bit self-signed certificate containing a subject alternative extension with an empty dNSName general name.
  • san_other_name.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with the otherName general name.
  • san_registered_id.pem - An RSA 1024 bit certificate containing a subject alternative name extension with the registeredID general name.
  • all_key_usages.pem - An RSA 2048 bit self-signed certificate containing a key usage extension with all nine purposes set to true.
  • extended_key_usage.pem - An RSA 2048 bit self-signed certificate containing an extended key usage extension with eight usages.
  • san_idna_names.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with rfc822Name, dNSName, and uniformResourceIdentifier general names with IDNA (RFC 5895) encoding.
  • san_wildcard_idna.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with a dNSName general name with a wildcard IDNA (RFC 5895) domain.
  • san_idna2003_dnsname.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with an IDNA 2003 (RFC 3490) dNSName.
  • san_rfc822_names.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with various rfc822Name values.
  • san_rfc822_idna.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with an IDNA rfc822Name.
  • san_uri_with_port.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with various uniformResourceIdentifier values.
  • san_ipaddr.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with an iPAddress value.
  • san_dirname.pem - An RSA 2048 bit self-signed certificate containing a subject alternative name extension with a directoryName value.
  • inhibit_any_policy_5.pem - An RSA 2048 bit self-signed certificate containing an inhibit any policy extension with the value 5.
  • inhibit_any_policy_negative.pem - An RSA 2048 bit self-signed certificate containing an inhibit any policy extension with the value -1.
  • authority_key_identifier.pem - An RSA 2048 bit self-signed certificate containing an authority key identifier extension with key identifier, authority certificate issuer, and authority certificate serial number fields.
  • authority_key_identifier_no_keyid.pem - An RSA 2048 bit self-signed certificate containing an authority key identifier extension with authority certificate issuer and authority certificate serial number fields.
  • aia_ocsp_ca_issuers.pem - An RSA 2048 bit self-signed certificate containing an authority information access extension with two OCSP and one CA issuers entry.
  • aia_ocsp.pem - An RSA 2048 bit self-signed certificate containing an authority information access extension with an OCSP entry.
  • aia_ca_issuers.pem - An RSA 2048 bit self-signed certificate containing an authority information access extension with a CA issuers entry.
  • cdp_empty_hostname.pem - An RSA 2048 bit self-signed certificate containing a CRL distribution point extension with fullName URI without a hostname.
  • cdp_fullname_reasons_crl_issuer.pem - An RSA 1024 bit certificate containing a CRL distribution points extension with fullName, cRLIssuer, and reasons data.
  • cdp_crl_issuer.pem - An RSA 1024 bit certificate containing a CRL distribution points extension with cRLIssuer data.
  • cdp_all_reasons.pem - An RSA 1024 bit certificate containing a CRL distribution points extension with all reasons bits set.
  • cdp_reason_aa_compromise.pem - An RSA 1024 bit certificate containing a CRL distribution points extension with the AACompromise reasons bit set.
  • nc_permitted_excluded.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with both permitted and excluded elements. Contains IPv4 and IPv6 addresses with network mask as well as dNSName with a leading period.
  • nc_permitted_excluded_2.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with both permitted and excluded elements. Unlike nc_permitted_excluded.pem, the general names do not contain any name constraints specific values.
  • nc_permitted.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with permitted elements.
  • nc_permitted_2.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with permitted elements that do not contain any name constraints specific values.
  • nc_excluded.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with excluded elements.
  • nc_invalid_ip_netmask.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with a permitted element that has an IPv6 IP and an invalid network mask.
  • nc_single_ip_netmask.pem - An RSA 2048 bit self-signed certificate containing a name constraints extension with a permitted element that has two IPs with /32 and /128 network masks.
  • cp_user_notice_with_notice_reference.pem - An RSA 2048 bit self-signed certificate containing a certificate policies extension with a notice reference in the user notice.
  • cp_user_notice_with_explicit_text.pem - An RSA 2048 bit self-signed certificate containing a certificate policies extension with explicit text and no notice reference.
  • cp_cps_uri.pem - An RSA 2048 bit self-signed certificate containing a certificate policies extension with a CPS URI and no user notice.
  • cp_user_notice_no_explicit_text.pem - An RSA 2048 bit self-signed certificate containing a certificate policies extension with a user notice with no explicit text.
  • cp_invalid.pem - An RSA 2048 bit self-signed certificate containing a certificate policies extension with invalid data.
  • ian_uri.pem - An RSA 2048 bit certificate containing an issuer alternative name extension with a URI general name.
  • ocsp_nocheck.pem - An RSA 2048 bit self-signed certificate containing an OCSPNoCheck extension.
  • pc_inhibit_require.pem - An RSA 2048 bit self-signed certificate containing a policy constraints extension with both inhibit policy mapping and require explicit policy elements.
  • pc_inhibit.pem - An RSA 2048 bit self-signed certificate containing a policy constraints extension with an inhibit policy mapping element.
  • pc_require.pem - An RSA 2048 bit self-signed certificate containing a policy constraints extension with a require explicit policy element.
  • unsupported_subject_public_key_info.pem - A certificate whose public key is an unknown OID (1.3.6.1.4.1.8432.1.1.2).
  • policy_constraints_explicit.pem - A self-signed certificate containing a policyConstraints extension with a requireExplicitPolicy value.

Custom X.509 Request Vectors

  • dsa_sha1.pem and dsa_sha1.der - Contain a certificate request using 1024-bit DSA parameters and SHA1 generated using OpenSSL.
  • rsa_md4.pem and rsa_md4.der - Contain a certificate request using 2048 bit RSA and MD4 generated using OpenSSL.
  • rsa_sha1.pem and rsa_sha1.der - Contain a certificate request using 2048 bit RSA and SHA1 generated using OpenSSL.
  • rsa_sha256.pem and rsa_sha256.der - Contain a certificate request using 2048 bit RSA and SHA256 generated using OpenSSL.
  • ec_sha256.pem and ec_sha256.der - Contain a certificate request using EC (secp384r1) and SHA256 generated using OpenSSL.
  • san_rsa_sha1.pem and san_rsa_sha1.der - Contain a certificate request using RSA and SHA1 with a subject alternative name extension generated using OpenSSL.
  • two_basic_constraints.pem - A certificate signing request for an RSA 2048 bit key containing two basic constraints extensions.
  • unsupported_extension.pem - A certificate signing request for an RSA 2048 bit key containing containing an unsupported extension type. The OID was encoded as “1.2.3.4” with an extnValue of “value”.
  • unsupported_extension_critical.pem - A certificate signing request for an RSA 2048 bit key containing containing an unsupported extension type marked critical. The OID was encoded as “1.2.3.4” with an extnValue of “value”.
  • basic_constraints.pem - A certificate signing request for an RSA 2048 bit key containing a basic constraints extension marked as critical.
  • invalid_signature.pem - A certificate signing request for an RSA 1024 bit key containing an invalid signature with correct padding.

Custom X.509 Certificate Revocation List Vectors

  • crl_all_reasons.pem - Contains a CRL with 12 revoked certificates, whose serials match their list position. It includes one revocation without any entry extensions, 10 revocations with every supported reason code and one revocation with an unsupported, non-critical entry extension with the OID value set to “1.2.3.4”.
  • crl_dup_entry_ext.pem - Contains a CRL with one revocation which has a duplicate entry extension.
  • crl_md2_unknown_crit_entry_ext.pem - Contains a CRL with one revocation which contains an unsupported critical entry extension with the OID value set to “1.2.3.4”. The CRL uses an unsupported MD2 signature algorithm.
  • crl_unsupported_reason.pem - Contains a CRL with one revocation which has an unsupported reason code.
  • crl_inval_cert_issuer_entry_ext.pem - Contains a CRL with one revocation which has one entry extension for certificate issuer with an empty value.
  • crl_empty.pem - Contains a CRL with no revoked certificates.
  • crl_ian_aia_aki.pem - Contains a CRL with IssuerAlternativeName, AuthorityInformationAccess, AuthorityKeyIdentifier and CRLNumber extensions.

Hashes

HMAC

Key derivation functions

  • HKDF (SHA1, SHA256) from RFC 5869.
  • PBKDF2 (HMAC-SHA1) from RFC 6070.
  • scrypt from the draft RFC.
  • X9.63 KDF from NIST CAVP.
  • SP 800-108 Counter Mode KDF (HMAC-SHA1, HMAC-SHA224, HMAC-SHA256, HMAC-SHA384, HMAC-SHA512) from NIST CAVP.

Key wrapping

  • AES key wrap (AESKW) and 3DES key wrap test vectors from NIST CAVP.

Recipes

Symmetric ciphers

Two factor authentication

CMAC

Creating test vectors

When official vectors are unavailable cryptography may choose to build its own using existing vectors as source material.

Custom Symmetric Vectors

If official test vectors appear in the future the custom generated vectors should be discarded.

Any vectors generated by this method must also be prefixed with the following header format (substituting the correct information):

# CAST5 CBC vectors built for https://github.com/pyca/cryptography
# Derived from the AESVS MMT test data for CBC
# Verified against the CommonCrypto and Go crypto packages
# Key Length : 128