aboutsummaryrefslogtreecommitdiffstats
path: root/src/cryptography/hazmat/primitives/hashes.py
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2019-01-19 00:52:43 -0600
committerAlex Gaynor <alex.gaynor@gmail.com>2019-01-19 00:52:43 -0600
commit5fe88ea0500c6e418492f4b166c0d4a24e9632cc (patch)
tree4e63ba2759c0801646314a0b87056b66198217e2 /src/cryptography/hazmat/primitives/hashes.py
parentfdc61a26ea32e2563dfcbe17484b6e662d7f1e0a (diff)
downloadcryptography-5fe88ea0500c6e418492f4b166c0d4a24e9632cc.tar.gz
cryptography-5fe88ea0500c6e418492f4b166c0d4a24e9632cc.tar.bz2
cryptography-5fe88ea0500c6e418492f4b166c0d4a24e9632cc.zip
shake128/256 support (#4611)
* shake128/256 support * remove block_size * doc an exception * change how we detect XOF by adding _xof attribute * interface! * review feedback
Diffstat (limited to 'src/cryptography/hazmat/primitives/hashes.py')
-rw-r--r--src/cryptography/hazmat/primitives/hashes.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/cryptography/hazmat/primitives/hashes.py b/src/cryptography/hazmat/primitives/hashes.py
index 0d6e47fb..9be2b600 100644
--- a/src/cryptography/hazmat/primitives/hashes.py
+++ b/src/cryptography/hazmat/primitives/hashes.py
@@ -57,6 +57,13 @@ class HashContext(object):
"""
+@six.add_metaclass(abc.ABCMeta)
+class ExtendableOutputFunction(object):
+ """
+ An interface for extendable output functions.
+ """
+
+
@utils.register_interface(HashContext)
class Hash(object):
def __init__(self, algorithm, backend, ctx=None):
@@ -174,6 +181,40 @@ class SHA3_512(object): # noqa: N801
@utils.register_interface(HashAlgorithm)
+@utils.register_interface(ExtendableOutputFunction)
+class SHAKE128(object):
+ name = "shake128"
+
+ def __init__(self, digest_size):
+ if not isinstance(digest_size, six.integer_types):
+ raise TypeError("digest_size must be an integer")
+
+ if digest_size < 1:
+ raise ValueError("digest_size must be a positive integer")
+
+ self._digest_size = digest_size
+
+ digest_size = utils.read_only_property("_digest_size")
+
+
+@utils.register_interface(HashAlgorithm)
+@utils.register_interface(ExtendableOutputFunction)
+class SHAKE256(object):
+ name = "shake256"
+
+ def __init__(self, digest_size):
+ if not isinstance(digest_size, six.integer_types):
+ raise TypeError("digest_size must be an integer")
+
+ if digest_size < 1:
+ raise ValueError("digest_size must be a positive integer")
+
+ self._digest_size = digest_size
+
+ digest_size = utils.read_only_property("_digest_size")
+
+
+@utils.register_interface(HashAlgorithm)
class MD5(object):
name = "md5"
digest_size = 16