diff options
Diffstat (limited to 'docs/development')
-rw-r--r-- | docs/development/test-vectors.rst | 79 |
1 files changed, 0 insertions, 79 deletions
diff --git a/docs/development/test-vectors.rst b/docs/development/test-vectors.rst index 03e31f34..2a071d7c 100644 --- a/docs/development/test-vectors.rst +++ b/docs/development/test-vectors.rst @@ -56,85 +56,6 @@ Symmetric Ciphers * CAST5 (ECB) from :rfc:`2144`. -Creating Test Vectors ---------------------- - -To create test vectors for a block cipher the following code may be used as a -template: - -.. code-block:: python - - import binascii - - from cryptography.hazmat.backends.openssl.backend import backend - from cryptography.hazmat.primitives.ciphers import base, algorithms, modes - - - def encrypt(key, iv, plaintext): - cipher = base.Cipher( - algorithms.CAST5(binascii.unhexlify(key)), - modes.OFB(binascii.unhexlify(iv)), - backend - ) - encryptor = cipher.encryptor() - ct = encryptor.update(binascii.unhexlify(plaintext)) - ct += encryptor.finalize() - return binascii.hexlify(ct) - - - vector_file = open( - "tests/hazmat/primitives/vectors/ciphers/AES/OFB/OFBMMT128.rsp", - "r" - ) - - count = 0 - output = [] - key = None - iv = None - plaintext = None - ct = None - for line in vector_file: - line = line.strip() - if line.startswith("KEY"): - if count != 0: - output.append("CIPHERTEXT = {}".format(encrypt(key, iv, plaintext))) - output.append("\nCOUNT = {}".format(count)) - count += 1 - name, key = line.split(" = ") - output.append("KEY = {}".format(key)) - elif line.startswith("IV"): - name, iv = line.split(" = ") - iv = iv[0:16] - output.append("IV = {}".format(iv)) - elif line.startswith("PLAINTEXT"): - name, plaintext = line.split(" = ") - output.append("PLAINTEXT = {}".format(plaintext)) - - output.append("CIPHERTEXT = {}".format(encrypt(key, iv, plaintext))) - print("\n".join(output)) - -The algorithm, mode, and vector_file loaded must be modified to fit on a case -by case basis. Additionally, the IV must be truncated (if necessary) to the -length of the block size. - -The output generated by this script **must** be verified against at least one -other implementation. In the example above, the vectors were generated against -OpenSSL's implementation, so they must be verified against an implementation -such as ``CommonCrypto`` or ``Go``. - -Any vectors generated by this method must also be prefixed with the following -header format (substituting the correct information): - -.. code-block:: python - - # 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 - -If official test vectors appear in the future the custom generated vectors -should be discarded. - .. _`NIST`: http://www.nist.gov/ .. _`IETF`: https://www.ietf.org/ .. _`NIST CAVP`: http://csrc.nist.gov/groups/STM/cavp/ |