diff options
-rw-r--r-- | docs/hazmat/primitives/key-derivation-functions.rst | 3 | ||||
-rw-r--r-- | src/cryptography/hazmat/primitives/kdf/kbkdf.py | 2 | ||||
-rw-r--r-- | tests/hazmat/primitives/test_kbkdf.py | 8 |
3 files changed, 11 insertions, 2 deletions
diff --git a/docs/hazmat/primitives/key-derivation-functions.rst b/docs/hazmat/primitives/key-derivation-functions.rst index 64a22c0e..be03b19c 100644 --- a/docs/hazmat/primitives/key-derivation-functions.rst +++ b/docs/hazmat/primitives/key-derivation-functions.rst @@ -690,7 +690,8 @@ Different KDFs are suitable for different tasks such as: .. method:: derive(key_material) - :param bytes key_material: The input key material. + :param key_material: The input key material. + :type key_material: :term:`bytes-like` :return bytes: The derived key. :raises TypeError: This exception is raised if ``key_material`` is not ``bytes``. diff --git a/src/cryptography/hazmat/primitives/kdf/kbkdf.py b/src/cryptography/hazmat/primitives/kdf/kbkdf.py index 74fe9e29..56783a85 100644 --- a/src/cryptography/hazmat/primitives/kdf/kbkdf.py +++ b/src/cryptography/hazmat/primitives/kdf/kbkdf.py @@ -100,7 +100,7 @@ class KBKDFHMAC(object): if self._used: raise AlreadyFinalized - utils._check_bytes("key_material", key_material) + utils._check_byteslike("key_material", key_material) self._used = True # inverse floor division (equivalent to ceiling) diff --git a/tests/hazmat/primitives/test_kbkdf.py b/tests/hazmat/primitives/test_kbkdf.py index 875cd692..a16f1768 100644 --- a/tests/hazmat/primitives/test_kbkdf.py +++ b/tests/hazmat/primitives/test_kbkdf.py @@ -148,3 +148,11 @@ class TestKBKDFHMAC(object): CounterLocation.BeforeFixed, b'label', b'context', None, backend=backend) kdf.derive(u'material') + + def test_buffer_protocol(self, backend): + kdf = KBKDFHMAC(hashes.SHA256(), Mode.CounterMode, 10, 4, 4, + CounterLocation.BeforeFixed, b'label', b'context', + None, backend=backend) + + key = kdf.derive(bytearray(b"material")) + assert key == b'\xb7\x01\x05\x98\xf5\x1a\x12L\xc7.' |