blob: 6a7a35e0764fa350b711b8bbf77f1b8c6db8fcfc [file] [log] [blame]
Alex Stapletonc5fffd32014-03-18 15:29:00 +00001Test vectors
Paul Kehrer1681a692014-02-11 23:43:51 -06002============
3
4Testing the correctness of the primitives implemented in each ``cryptography``
Alex Stapletona39a3192014-03-14 20:03:12 +00005backend requires trusted test vectors. Where possible these vectors are
6obtained from official sources such as `NIST`_ or `IETF`_ RFCs. When this is
7not possible ``cryptography`` has chosen to create a set of custom vectors
8using an official vector file as input to verify consistency between
9implemented backends.
10
11Vectors are kept in the `cryptography_vectors` package rather than within our
12main test suite.
Paul Kehrer1681a692014-02-11 23:43:51 -060013
14Sources
15-------
16
Alex Stapletonc5fffd32014-03-18 15:29:00 +000017Asymmetric ciphers
Paul Kehrer1681a692014-02-11 23:43:51 -060018~~~~~~~~~~~~~~~~~~
19
Alex Stapletonabec8a12014-02-22 16:33:24 +000020* RSA PKCS #1 from the RSA FTP site (ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-1/
Paul Kehrer1681a692014-02-11 23:43:51 -060021 and ftp://ftp.rsa.com/pub/rsalabs/tmp/).
Paul Kehrer7f0039c2014-03-03 22:32:11 -040022* RSA FIPS 186-2 and PKCS1 v1.5 vulnerability test vectors from `NIST CAVP`_.
Alex Stapleton07c6a392014-04-02 11:05:30 +010023* FIPS 186-2 and FIPS 186-3 DSA test vectors from `NIST CAVP`_.
24* FIPS 186-2 and FIPS 186-3 ECDSA test vectors from `NIST CAVP`_.
Alex Stapleton23fef0a2014-07-13 13:57:24 +010025* DH and ECDH test vectors from `NIST CAVP`_.
Alex Stapleton833a8ea2014-04-02 14:50:56 +010026* Ed25519 test vectors from the `Ed25519 website_`.
Alex Stapletone7da0ab2014-03-02 14:04:33 +000027* OpenSSL PEM RSA serialization vectors from the `OpenSSL example key`_ and
28 `GnuTLS key parsing tests`_.
29* OpenSSL PEM DSA serialization vectors from the `GnuTLS example keys`_.
Alex Stapletonabec8a12014-02-22 16:33:24 +000030* PKCS #8 PEM serialization vectors from
31
Paul Kehrerb525adf2014-09-29 15:18:23 -050032 * GnuTLS: `enc-rsa-pkcs8.pem`_, `enc2-rsa-pkcs8.pem`_,
Alex Gaynor899c3ac2014-11-18 18:45:24 -080033 `unenc-rsa-pkcs8.pem`_, `pkcs12_s2k_pem.c`_. The contents of
34 `enc2-rsa-pkcs8.pem`_ was re-encrypted using a stronger PKCS#8 cipher.
Alex Stapletonabec8a12014-02-22 16:33:24 +000035 * `Botan's ECC private keys`_.
Paul Kehrerb07a0c92015-03-02 13:21:27 -060036* `asymmetric/public/PKCS1/dsa.pub.pem`_ is a PKCS1 DSA public key from the
37 Ruby test suite.
38
Paul Kehrer1681a692014-02-11 23:43:51 -060039
Paul Kehrerebc26502014-11-26 19:18:56 -100040Custom Asymmetric Vectors
41~~~~~~~~~~~~~~~~~~~~~~~~~
42
Paul Kehrer10831a02015-01-03 18:45:04 -060043* ``asymmetric/PEM_Serialization/ec_private_key.pem`` and
44 ``asymmetric/DER_Serialization/ec_private_key.der`` - Contains an Elliptic
Paul Kehrer0498d4c2015-01-01 22:29:12 -060045 Curve key generated by OpenSSL from the curve ``secp256r1``.
Paul Kehrer10831a02015-01-03 18:45:04 -060046* ``asymmetric/PEM_Serialization/ec_private_key_encrypted.pem`` and
47 ``asymmetric/DER_Serialization/ec_private_key_encrypted.der``- Contains the
Paul Kehrer0498d4c2015-01-01 22:29:12 -060048 same Elliptic Curve key as ``ec_private_key.pem``, except that it is
49 encrypted with AES-128 with the password "123456".
Paul Kehrer10831a02015-01-03 18:45:04 -060050* ``asymmetric/PEM_Serialization/ec_public_key.pem`` and
51 ``asymmetric/DER_Serialization/ec_public_key.der``- Contains the public key
Paul Kehrer0498d4c2015-01-01 22:29:12 -060052 corresponding to ``ec_private_key.pem``, generated using OpenSSL.
53* ``asymmetric/PEM_Serialization/rsa_private_key.pem`` - Contains an RSA 2048
54 bit key generated using OpenSSL, protected by the secret "123456" with DES3
55 encryption.
Paul Kehrer10831a02015-01-03 18:45:04 -060056* ``asymmetric/PEM_Serialization/rsa_public_key.pem`` and
57 ``asymmetric/DER_Serialization/rsa_public_key.der``- Contains an RSA 2048
Paul Kehrer0498d4c2015-01-01 22:29:12 -060058 bit public generated using OpenSSL from ``rsa_private_key.pem``.
59* ``asymmetric/PEM_Serialization/dsaparam.pem`` - Contains 2048-bit DSA
60 parameters generated using OpenSSL; contains no keys.
61* ``asymmetric/PEM_Serialization/dsa_private_key.pem`` - Contains a DSA 2048
62 bit key generated using OpenSSL from the parameters in ``dsaparam.pem``,
63 protected by the secret "123456" with DES3 encryption.
Paul Kehrer10831a02015-01-03 18:45:04 -060064* ``asymmetric/PEM_Serialization/dsa_public_key.pem`` and
65 ``asymmetric/DER_Serialization/dsa_public_key.der`` - Contains a DSA 2048 bit
Paul Kehrer0498d4c2015-01-01 22:29:12 -060066 key generated using OpenSSL from ``dsa_private_key.pem``.
Paul Kehrer4b8abc32015-01-06 14:46:15 +000067* ``asymmetric/PKCS8/unenc-dsa-pkcs8.pem`` and
Paul Kehrer10831a02015-01-03 18:45:04 -060068 ``asymmetric/DER_Serialization/unenc-dsa-pkcs8.der`` - Contains a DSA 1024
Paul Kehrera36661e2015-01-04 07:57:40 -060069 bit key generated using OpenSSL.
Paul Kehrer4b8abc32015-01-06 14:46:15 +000070* ``asymmetric/PKCS8/unenc-dsa-pkcs8.pub.pem`` and
Paul Kehrer10831a02015-01-03 18:45:04 -060071 ``asymmetric/DER_Serialization/unenc-dsa-pkcs8.pub.der`` - Contains a DSA
Paul Kehrera673dcc2015-01-03 23:26:01 -060072 2048 bit public key generated using OpenSSL from ``unenc-dsa-pkcs8.pem``.
Paul Kehrer10831a02015-01-03 18:45:04 -060073* DER conversions of the `GnuTLS example keys`_ for DSA as well as the
74 `OpenSSL example key`_ for RSA.
75* DER conversions of `enc-rsa-pkcs8.pem`_, `enc2-rsa-pkcs8.pem`_, and
76 `unenc-rsa-pkcs8.pem`_.
Paul Kehrer6d977422015-03-02 19:38:34 -060077* ``asymmetric/public/PKCS1/rsa.pub.pem`` and
78 ``asymmetric/public/PKCS1/rsa.pub.der`` are PKCS1 conversions of the public
79 key from ``asymmetric/PKCS8/unenc-rsa-pkcs8.pem`` using PEM and DER encoding.
Paul Kehrerebc26502014-11-26 19:18:56 -100080
Paul Kehrerbab4e392014-11-24 11:48:17 -100081X.509
82~~~~~
83
84* PKITS test suite from `NIST PKI Testing`_.
Paul Kehrerebc26502014-11-26 19:18:56 -100085* ``v1_cert.pem`` from the OpenSSL source tree (`testx509.pem`_).
86* ``ecdsa_root.pem`` - `DigiCert Global Root G3`_, a ``secp384r1`` ECDSA root
87 certificate.
Paul Kehrerb01622d2015-02-13 11:59:15 -060088* ``verisign-md2-root.pem`` - A legacy Verisign public root signed using the
Paul Kehrer2b6ba0c2015-02-14 18:58:20 -060089 MD2 algorithm. This is a PEM conversion of the `root data`_ in the NSS source
90 tree.
Paul Kehrere0eafaa2015-03-20 22:33:37 -050091* ``cryptography.io.pem`` - A leaf certificate issued by RapidSSL for the
92 cryptography website.
Paul Kehrerebc26502014-11-26 19:18:56 -100093
94Custom X.509 Vectors
95~~~~~~~~~~~~~~~~~~~~
96
97* ``invalid_version.pem`` - Contains an RSA 2048 bit certificate with the
98 X.509 version field set to ``0x7``.
99* ``post2000utctime.pem`` - Contains an RSA 2048 bit certificate with the
100 ``notBefore`` and ``notAfter`` fields encoded as post-2000 ``UTCTime``.
Paul Kehrera850c612014-12-12 14:21:18 -0600101* ``dsa_selfsigned_ca.pem`` - Contains a DSA self-signed CA certificate
102 generated using OpenSSL.
Paul Kehrerd317bae2014-12-12 11:42:31 -0600103* ``ec_no_named_curve.pem`` - Contains an ECDSA certificate that does not have
104 an embedded OID defining the curve.
Paul Kehrer22217202015-01-17 21:26:28 -0600105* ``all_supported_names.pem`` - An RSA 2048 bit certificate generated using
106 OpenSSL that contains a subject and issuer that have two of each supported
107 attribute type from :rfc:`5280`.
Paul Kehrer1207d152015-01-17 21:31:42 -0600108* ``unsupported_subject_name.pem`` - An RSA 2048 bit self-signed CA certificate
109 generated using OpenSSL that contains the unsupported "initials" name.
Paul Kehrer6392b4b2015-01-17 22:20:01 -0600110* ``utf8_common_name.pem`` - An RSA 2048 bit self-signed CA certificate
111 generated using OpenSSL that contains a UTF8String common name with the value
112 "We heart UTF8!â„¢".
Paul Kehrere0eafaa2015-03-20 22:33:37 -0500113* ``two_basic_constraints.pem`` - An RSA 2048 bit self-signed certificate
114 containing two basic constraints extensions.
115* ``basic_constraints_not_critical.pem`` - An RSA 2048 bit self-signed
116 certificate containing a basic constraints extension that is not marked as
117 critical.
Paul Kehrerd1ed6732015-03-25 00:17:36 -0500118* ``bc_path_length_zero.pem`` - An RSA 2048 bit self-signed
119 certificate containing a basic constraints extension with a path length of
120 zero.
Paul Kehrerb2e6c832015-03-27 22:19:13 -0500121* ``unsupported_extension.pem`` - An RSA 2048 bit self-signed certificate
122 containing an unsupported extension type. The OID was encoded as
123 "1.2.3.4" with an ``extnValue`` of "value".
Paul Kehrerff2167a2015-02-24 10:45:41 -0600124
125Custom X.509 Request Vectors
126~~~~~~~~~~~~~~~~~~~~~~~~~~~~
127
Paul Kehrer62bd3862015-02-24 10:38:43 -0600128* ``dsa_sha1.pem`` - Contains a certificate request using 1024-bit DSA
129 parameters and SHA1 generated using OpenSSL.
Paul Kehrerff2167a2015-02-24 10:45:41 -0600130* ``rsa_md4.pem`` - Contains a certificate request using 2048 bit RSA and MD4
131 generated using OpenSSL.
Paul Kehrer62bd3862015-02-24 10:38:43 -0600132* ``rsa_sha1.pem`` - Contains a certificate request using 2048 bit RSA and
133 SHA1 generated using OpenSSL.
134* ``rsa_sha256.pem`` - Contains a certificate request using 2048 bit RSA and
135 SHA256 generated using OpenSSL.
136* ``ec_sha256.pem`` - Contains a certificate request using EC (``secp384r1``)
137 and SHA256 generated using OpenSSL.
Paul Kehrerbab4e392014-11-24 11:48:17 -1000138
Paul Kehrer1681a692014-02-11 23:43:51 -0600139Hashes
140~~~~~~
141
142* MD5 from :rfc:`1321`.
143* RIPEMD160 from the `RIPEMD website`_.
144* SHA1 from `NIST CAVP`_.
145* SHA2 (224, 256, 384, 512) from `NIST CAVP`_.
146* Whirlpool from the `Whirlpool website`_.
147
148HMAC
149~~~~
150
151* HMAC-MD5 from :rfc:`2202`.
152* HMAC-SHA1 from :rfc:`2202`.
153* HMAC-RIPEMD160 from :rfc:`2286`.
154* HMAC-SHA2 (224, 256, 384, 512) from :rfc:`4231`.
155
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000156Key derivation functions
Paul Kehrer1681a692014-02-11 23:43:51 -0600157~~~~~~~~~~~~~~~~~~~~~~~~
158
159* HKDF (SHA1, SHA256) from :rfc:`5869`.
160* PBKDF2 (HMAC-SHA1) from :rfc:`6070`.
Alex Gaynor75e72ea2014-03-01 12:18:27 -0800161* scrypt from the `draft RFC`_.
Paul Kehrer1681a692014-02-11 23:43:51 -0600162
Paul Kehrer16430f92015-03-15 09:06:25 -0500163Key wrapping
164~~~~~~~~~~~~
165
166* AES key wrap (AESKW) and 3DES key wrap test vectors from `NIST CAVP`_.
167
Paul Kehrer1681a692014-02-11 23:43:51 -0600168Recipes
169~~~~~~~
170
171* Fernet from its `specification repository`_.
172
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000173Symmetric ciphers
Paul Kehrer1681a692014-02-11 23:43:51 -0600174~~~~~~~~~~~~~~~~~
175
Paul Kehrere547d8f2014-02-15 21:37:52 -0600176* AES (CBC, CFB, ECB, GCM, OFB) from `NIST CAVP`_.
177* AES CTR from :rfc:`3686`.
Paul Kehrer1681a692014-02-11 23:43:51 -0600178* 3DES (CBC, CFB, ECB, OFB) from `NIST CAVP`_.
179* ARC4 from :rfc:`6229`.
180* Blowfish (CBC, CFB, ECB, OFB) from `Bruce Schneier's vectors`_.
181* Camellia (ECB) from NTT's `Camellia page`_ as linked by `CRYPTREC`_.
182* Camellia (CBC, CFB, OFB) from `OpenSSL's test vectors`_.
183* CAST5 (ECB) from :rfc:`2144`.
Paul Kehrercf6ffb52014-02-12 16:17:04 -0600184* CAST5 (CBC, CFB, OFB) generated by this project.
185 See: :doc:`/development/custom-vectors/cast5`
Paul Kehrerb09622c2014-02-16 19:32:04 -0600186* IDEA (ECB) from the `NESSIE IDEA vectors`_ created by `NESSIE`_.
187* IDEA (CBC, CFB, OFB) generated by this project.
188 See: :doc:`/development/custom-vectors/idea`
Paul Kehrer1d0f9732014-04-08 08:44:25 -0500189* SEED (ECB) from :rfc:`4269`.
Paul Kehrerf0e12ac2014-04-08 08:59:40 -0500190* SEED (CBC) from :rfc:`4196`.
Paul Kehrer6d8f9b02014-04-08 09:17:02 -0500191* SEED (CFB, OFB) generated by this project.
192 See: :doc:`/development/custom-vectors/seed`
Paul Kehrer1681a692014-02-11 23:43:51 -0600193
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000194Two factor authentication
Ayrx933dd682014-02-18 23:26:11 +0800195~~~~~~~~~~~~~~~~~~~~~~~~~
196
197* HOTP from :rfc:`4226`
Alex Gaynor75e72ea2014-03-01 12:18:27 -0800198* TOTP from :rfc:`6238` (Note that an `errata`_ for the test vectors in RFC
199 6238 exists)
Ayrx933dd682014-02-18 23:26:11 +0800200
Ayrx1d6b77b2014-04-10 23:11:03 +0800201CMAC
202~~~~
203
Ayrxfa52e6a2014-04-14 22:26:21 +0800204* AES-128, AES-192, AES-256, 3DES from `NIST SP-800-38B`_
Ayrx1d6b77b2014-04-10 23:11:03 +0800205
Alex Stapletonc5fffd32014-03-18 15:29:00 +0000206Creating test vectors
Paul Kehrercf6ffb52014-02-12 16:17:04 -0600207---------------------
208
209When official vectors are unavailable ``cryptography`` may choose to build
Paul Kehrer9f7ad192014-09-24 21:54:39 -0500210its own using existing vectors as source material.
michael-hart59f72192014-09-24 11:31:20 +0100211
Paul Kehrerebc26502014-11-26 19:18:56 -1000212Custom Symmetric Vectors
213~~~~~~~~~~~~~~~~~~~~~~~~
Paul Kehrercf6ffb52014-02-12 16:17:04 -0600214
215.. toctree::
216 :maxdepth: 1
217
218 custom-vectors/cast5
Paul Kehrerb09622c2014-02-16 19:32:04 -0600219 custom-vectors/idea
Paul Kehrer6d8f9b02014-04-08 09:17:02 -0500220 custom-vectors/seed
Paul Kehrercf6ffb52014-02-12 16:17:04 -0600221
222If official test vectors appear in the future the custom generated vectors
223should be discarded.
224
225Any vectors generated by this method must also be prefixed with the following
226header format (substituting the correct information):
227
228.. code-block:: python
229
230 # CAST5 CBC vectors built for https://github.com/pyca/cryptography
231 # Derived from the AESVS MMT test data for CBC
232 # Verified against the CommonCrypto and Go crypto packages
233 # Key Length : 128
234
Paul Kehrer1681a692014-02-11 23:43:51 -0600235.. _`NIST`: http://www.nist.gov/
236.. _`IETF`: https://www.ietf.org/
237.. _`NIST CAVP`: http://csrc.nist.gov/groups/STM/cavp/
238.. _`Bruce Schneier's vectors`: https://www.schneier.com/code/vectors.txt
239.. _`Camellia page`: http://info.isl.ntt.co.jp/crypt/eng/camellia/
240.. _`CRYPTREC`: http://www.cryptrec.go.jp
241.. _`OpenSSL's test vectors`: https://github.com/openssl/openssl/blob/97cf1f6c2854a3a955fd7dd3a1f113deba00c9ef/crypto/evp/evptests.txt#L232
242.. _`RIPEMD website`: http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
243.. _`Whirlpool website`: http://www.larc.usp.br/~pbarreto/WhirlpoolPage.html
Alex Gaynor75e72ea2014-03-01 12:18:27 -0800244.. _`draft RFC`: https://tools.ietf.org/html/draft-josefsson-scrypt-kdf-01
Paul Kehrer1681a692014-02-11 23:43:51 -0600245.. _`Specification repository`: https://github.com/fernet/spec
Ayrx933dd682014-02-18 23:26:11 +0800246.. _`errata`: http://www.rfc-editor.org/errata_search.php?rfc=6238
Paul Kehrer5e9a8a32015-03-02 13:25:45 -0600247.. _`OpenSSL example key`: https://github.com/openssl/openssl/blob/d02b48c63a58ea4367a0e905979f140b7d090f86/test/testrsa.pem
Paul Kehrerdac86a92015-03-06 08:36:07 -0600248.. _`GnuTLS key parsing tests`: https://gitlab.com/gnutls/gnutls/commit/f16ef39ef0303b02d7fa590a37820440c466ce8d
249.. _`enc-rsa-pkcs8.pem`: https://gitlab.com/gnutls/gnutls/blob/f8d943b38bf74eaaa11d396112daf43cb8aa82ae/tests/pkcs8-decode/encpkcs8.pem
250.. _`enc2-rsa-pkcs8.pem`: https://gitlab.com/gnutls/gnutls/blob/f8d943b38bf74eaaa11d396112daf43cb8aa82ae/tests/pkcs8-decode/enc2pkcs8.pem
251.. _`unenc-rsa-pkcs8.pem`: https://gitlab.com/gnutls/gnutls/blob/f8d943b38bf74eaaa11d396112daf43cb8aa82ae/tests/pkcs8-decode/unencpkcs8.pem
252.. _`pkcs12_s2k_pem.c`: https://gitlab.com/gnutls/gnutls/blob/f8d943b38bf74eaaa11d396112daf43cb8aa82ae/tests/pkcs12_s2k_pem.c
Alex Stapletonabec8a12014-02-22 16:33:24 +0000253.. _`Botan's ECC private keys`: https://github.com/randombit/botan/tree/4917f26a2b154e841cd27c1bcecdd41d2bdeb6ce/src/tests/data/ecc
Alex Gaynor3efbf492015-03-09 07:13:22 -0400254.. _`GnuTLS example keys`: https://gitlab.com/gnutls/gnutls/commit/ad2061deafdd7db78fd405f9d143b0a7c579da7b
Paul Kehrerb09622c2014-02-16 19:32:04 -0600255.. _`NESSIE IDEA vectors`: https://www.cosic.esat.kuleuven.be/nessie/testvectors/bc/idea/Idea-128-64.verified.test-vectors
256.. _`NESSIE`: https://en.wikipedia.org/wiki/NESSIE
Alex Stapleton833a8ea2014-04-02 14:50:56 +0100257.. _`Ed25519 website`: http://ed25519.cr.yp.to/software.html
Ayrx40afce02014-04-13 19:17:52 +0800258.. _`NIST SP-800-38B`: http://csrc.nist.gov/publications/nistpubs/800-38B/Updated_CMAC_Examples.pdf
Paul Kehrerbab4e392014-11-24 11:48:17 -1000259.. _`NIST PKI Testing`: http://csrc.nist.gov/groups/ST/crypto_apps_infra/pki/pkitesting.html
Paul Kehrerebc26502014-11-26 19:18:56 -1000260.. _`testx509.pem`: https://github.com/openssl/openssl/blob/master/test/testx509.pem
261.. _`DigiCert Global Root G3`: http://cacerts.digicert.com/DigiCertGlobalRootG3.crt
Paul Kehrer2b6ba0c2015-02-14 18:58:20 -0600262.. _`root data`: https://hg.mozilla.org/projects/nss/file/25b2922cc564/security/nss/lib/ckfw/builtins/certdata.txt#l2053
Paul Kehrerb07a0c92015-03-02 13:21:27 -0600263.. _`asymmetric/public/PKCS1/dsa.pub.pem`: https://github.com/ruby/ruby/blob/4ccb387f3bc436a08fc6d72c4931994f5de95110/test/openssl/test_pkey_dsa.rb#L53