diff options
author | Paul Kehrer <paul.l.kehrer@gmail.com> | 2018-11-12 21:41:26 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2018-11-12 21:41:26 -0500 |
commit | d67fa8251f71f7cf5e9709f1e6be27ee7fbf028a (patch) | |
tree | a0bde609ea9163b162c0641eb46f6c5785baaeb8 | |
parent | 13365ef858bc045ef2d3358c27f8a8bc6cf9cb0b (diff) | |
download | cryptography-d67fa8251f71f7cf5e9709f1e6be27ee7fbf028a.tar.gz cryptography-d67fa8251f71f7cf5e9709f1e6be27ee7fbf028a.tar.bz2 cryptography-d67fa8251f71f7cf5e9709f1e6be27ee7fbf028a.zip |
add SHA512/224 and SHA512/256 support (#4575)
* add SHA512/224 and SHA512/256 support
* add missing docs
-rw-r--r-- | CHANGELOG.rst | 4 | ||||
-rw-r--r-- | docs/hazmat/primitives/cryptographic-hashes.rst | 14 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/hashes.py | 14 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_hash_vectors.py | 34 |
4 files changed, 66 insertions, 0 deletions
diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 262c1f27..b95df955 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,10 @@ Changelog .. note:: This version is not yet released and is under active development. +* Added support for :class:`~cryptography.hazmat.primitives.hashes.SHA512_224` + and :class:`~cryptography.hazmat.primitives.hashes.SHA512_256` when using + OpenSSL 1.1.1. + .. _v2-4-1: 2.4.1 - 2018-11-11 diff --git a/docs/hazmat/primitives/cryptographic-hashes.rst b/docs/hazmat/primitives/cryptographic-hashes.rst index a73785d4..1a96fc2d 100644 --- a/docs/hazmat/primitives/cryptographic-hashes.rst +++ b/docs/hazmat/primitives/cryptographic-hashes.rst @@ -102,6 +102,20 @@ SHA-2 family SHA-512 is a cryptographic hash function from the SHA-2 family and is standardized by NIST. It produces a 512-bit message digest. +.. class:: SHA512_224() + + .. versionadded:: 2.5 + + SHA-512/224 is a cryptographic hash function from the SHA-2 family and is + standardized by NIST. It produces a 224-bit message digest. + +.. class:: SHA512_256() + + .. versionadded:: 2.5 + + SHA-512/256 is a cryptographic hash function from the SHA-2 family and is + standardized by NIST. It produces a 256-bit message digest. + BLAKE2 ~~~~~~ diff --git a/src/cryptography/hazmat/primitives/hashes.py b/src/cryptography/hazmat/primitives/hashes.py index 3f3aadd6..79029937 100644 --- a/src/cryptography/hazmat/primitives/hashes.py +++ b/src/cryptography/hazmat/primitives/hashes.py @@ -109,6 +109,20 @@ class SHA1(object): @utils.register_interface(HashAlgorithm) +class SHA512_224(object): # noqa: N801 + name = "sha512-224" + digest_size = 28 + block_size = 128 + + +@utils.register_interface(HashAlgorithm) +class SHA512_256(object): # noqa: N801 + name = "sha512-256" + digest_size = 32 + block_size = 128 + + +@utils.register_interface(HashAlgorithm) class SHA224(object): name = "sha224" digest_size = 28 diff --git a/tests/hazmat/primitives/test_hash_vectors.py b/tests/hazmat/primitives/test_hash_vectors.py index 2db9e906..33c5f8e1 100644 --- a/tests/hazmat/primitives/test_hash_vectors.py +++ b/tests/hazmat/primitives/test_hash_vectors.py @@ -101,6 +101,40 @@ class TestSHA512(object): @pytest.mark.supported( + only_if=lambda backend: backend.hash_supported(hashes.SHA512_224()), + skip_message="Does not support SHA512/224", +) +@pytest.mark.requires_backend_interface(interface=HashBackend) +class TestSHA512224(object): + test_SHA512_224 = generate_hash_test( + load_hash_vectors, + os.path.join("hashes", "SHA2"), + [ + "SHA512_224LongMsg.rsp", + "SHA512_224ShortMsg.rsp", + ], + hashes.SHA512_224(), + ) + + +@pytest.mark.supported( + only_if=lambda backend: backend.hash_supported(hashes.SHA512_256()), + skip_message="Does not support SHA512/256", +) +@pytest.mark.requires_backend_interface(interface=HashBackend) +class TestSHA512256(object): + test_SHA512_256 = generate_hash_test( + load_hash_vectors, + os.path.join("hashes", "SHA2"), + [ + "SHA512_256LongMsg.rsp", + "SHA512_256ShortMsg.rsp", + ], + hashes.SHA512_256(), + ) + + +@pytest.mark.supported( only_if=lambda backend: backend.hash_supported(hashes.MD5()), skip_message="Does not support MD5", ) |