From a438e83267a428e4e25305da6fa650f7c0b36043 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 19 Oct 2014 19:47:05 -0700 Subject: Document the change in ``p`` and ``q``s lengths in the CHANGELOG --- CHANGELOG.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index e1f8b115..70e30e66 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -6,6 +6,9 @@ Changelog .. note:: This version is not yet released and is under active development. +* More bit-lengths are now support for ``p`` and ``q`` when loading DSA keys + from numbers. + 0.6.1 - 2014-10-15 ~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3 From 0d7439d171c0692959de175aa1040d5bba2313a0 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sat, 11 Oct 2014 22:35:58 +0800 Subject: Add MACContext and make HMAC and CMAC to use it. --- cryptography/hazmat/backends/interfaces.py | 4 +-- cryptography/hazmat/backends/openssl/cmac.py | 1 + cryptography/hazmat/primitives/cmac.py | 1 + cryptography/hazmat/primitives/hmac.py | 1 + cryptography/hazmat/primitives/interfaces.py | 37 +++++++++++++++++++++++++++- 5 files changed, 41 insertions(+), 3 deletions(-) diff --git a/cryptography/hazmat/backends/interfaces.py b/cryptography/hazmat/backends/interfaces.py index 69d776ff..ecb5bf48 100644 --- a/cryptography/hazmat/backends/interfaces.py +++ b/cryptography/hazmat/backends/interfaces.py @@ -66,7 +66,7 @@ class HMACBackend(object): @abc.abstractmethod def create_hmac_ctx(self, key, algorithm): """ - Create a HashContext for calculating a message authentication code. + Create a MACContext for calculating a message authentication code. """ @@ -81,7 +81,7 @@ class CMACBackend(object): @abc.abstractmethod def create_cmac_ctx(self, algorithm): """ - Create a CMACContext for calculating a message authentication code. + Create a MACContext for calculating a message authentication code. """ diff --git a/cryptography/hazmat/backends/openssl/cmac.py b/cryptography/hazmat/backends/openssl/cmac.py index 7acf4391..f1d068eb 100644 --- a/cryptography/hazmat/backends/openssl/cmac.py +++ b/cryptography/hazmat/backends/openssl/cmac.py @@ -20,6 +20,7 @@ from cryptography.hazmat.primitives import interfaces from cryptography.hazmat.primitives.ciphers.modes import CBC +@utils.register_interface(interfaces.MACContext) @utils.register_interface(interfaces.CMACContext) class _CMACContext(object): def __init__(self, backend, algorithm, ctx=None): diff --git a/cryptography/hazmat/primitives/cmac.py b/cryptography/hazmat/primitives/cmac.py index fa463ae0..968fa463 100644 --- a/cryptography/hazmat/primitives/cmac.py +++ b/cryptography/hazmat/primitives/cmac.py @@ -21,6 +21,7 @@ from cryptography.hazmat.backends.interfaces import CMACBackend from cryptography.hazmat.primitives import constant_time, interfaces +@utils.register_interface(interfaces.MACContext) @utils.register_interface(interfaces.CMACContext) class CMAC(object): def __init__(self, algorithm, backend, ctx=None): diff --git a/cryptography/hazmat/primitives/hmac.py b/cryptography/hazmat/primitives/hmac.py index 026ad3b3..23292432 100644 --- a/cryptography/hazmat/primitives/hmac.py +++ b/cryptography/hazmat/primitives/hmac.py @@ -21,6 +21,7 @@ from cryptography.hazmat.backends.interfaces import HMACBackend from cryptography.hazmat.primitives import constant_time, interfaces +@utils.register_interface(interfaces.MACContext) @utils.register_interface(interfaces.HashContext) class HMAC(object): def __init__(self, key, algorithm, backend, ctx=None): diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index 6ae0a4c5..dacabb2e 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -393,11 +393,12 @@ class KeyDerivationFunction(object): @six.add_metaclass(abc.ABCMeta) class CMACContext(object): @abc.abstractmethod - def update(self, data): + def update(self): """ Processes the provided bytes. """ + @abc.abstractmethod def finalize(self): """ Returns the message authentication code as bytes. @@ -486,3 +487,37 @@ class EllipticCurvePublicKeyWithNumbers(EllipticCurvePublicKey): """ Returns an EllipticCurvePublicNumbers. """ + + +@six.add_metaclass(abc.ABCMeta) +class MACContext(object): + @abc.abstractproperty + def algorithm(self): + """ + The algorithm that will be used by this context. + """ + + @abc.abstractmethod + def update(self, data): + """ + Processes the provided bytes. + """ + + @abc.abstractmethod + def finalize(self): + """ + Returns the message authentication code as bytes. + """ + + @abc.abstractmethod + def copy(self): + """ + Return a MACContext that is a copy of the current context. + """ + + @abc.abstractmethod + def verify(self): + """ + Checks if the generated message authentication code matches the + signature. + """ -- cgit v1.2.3 From 9985ff7a63fe6fa087ff14a961833c30da302999 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 12 Oct 2014 13:05:34 +0800 Subject: Ooops. --- cryptography/hazmat/primitives/interfaces.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index dacabb2e..295f5282 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -393,7 +393,7 @@ class KeyDerivationFunction(object): @six.add_metaclass(abc.ABCMeta) class CMACContext(object): @abc.abstractmethod - def update(self): + def update(self, data): """ Processes the provided bytes. """ -- cgit v1.2.3 From cc5e44578e040f552bb1b5f94d1b484f0a59bd47 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 12 Oct 2014 15:35:21 +0800 Subject: Add docs. --- cryptography/hazmat/primitives/interfaces.py | 2 +- docs/hazmat/primitives/interfaces.rst | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index 295f5282..dde0a3b6 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -516,7 +516,7 @@ class MACContext(object): """ @abc.abstractmethod - def verify(self): + def verify(self, signature): """ Checks if the generated message authentication code matches the signature. diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index 2d594c8d..bffd3e2d 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -643,8 +643,8 @@ Key derivation functions stored derived key. -`CMAC`_ -------- +`Message Authentication Code`_ +------------------------------ .. class:: CMACContext @@ -663,6 +663,29 @@ Key derivation functions :return: A :class:`~cryptography.hazmat.primitives.interfaces.CMACContext` that is a copy of the current context. +.. class:: MACContext + + .. versionadded:: 0.7 + + .. method:: update(data) + + :param data bytes: The data you want to authenticate + + .. method:: finalize() + + :return: The message authentication code. + + .. method:: copy() + + :return: A :class:`~cryptography.hazmat.primitives.interfaces.MACContext` + that is a copy of the current context. + + .. method:: verify() + + :param signature bytes: The signature to verify. + + :raises cryptography.exceptions.InvalidSignature: This is raised when + the provided signature does not match the expected signature. .. _`RSA`: https://en.wikipedia.org/wiki/RSA_(cryptosystem) .. _`Chinese remainder theorem`: https://en.wikipedia.org/wiki/Chinese_remainder_theorem -- cgit v1.2.3 From 0fc591f609004de9b531fdd165ffa0b99c58d7c5 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Sun, 12 Oct 2014 22:21:01 +0800 Subject: Add missing period. --- docs/hazmat/primitives/interfaces.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index bffd3e2d..2ee2017c 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -669,7 +669,7 @@ Key derivation functions .. method:: update(data) - :param data bytes: The data you want to authenticate + :param data bytes: The data you want to authenticate. .. method:: finalize() -- cgit v1.2.3 From 73cb687bcf87fbb7d392c998bd3ad619b58fa6b0 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Mon, 20 Oct 2014 10:34:02 +0800 Subject: Remove algorithm property from MACContext and alias CMACContext. --- cryptography/hazmat/primitives/interfaces.py | 29 ++-------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index dde0a3b6..c09a9618 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -390,27 +390,6 @@ class KeyDerivationFunction(object): """ -@six.add_metaclass(abc.ABCMeta) -class CMACContext(object): - @abc.abstractmethod - def update(self, data): - """ - Processes the provided bytes. - """ - - @abc.abstractmethod - def finalize(self): - """ - Returns the message authentication code as bytes. - """ - - @abc.abstractmethod - def copy(self): - """ - Return a CMACContext that is a copy of the current context. - """ - - @six.add_metaclass(abc.ABCMeta) class EllipticCurve(object): @abc.abstractproperty @@ -491,12 +470,6 @@ class EllipticCurvePublicKeyWithNumbers(EllipticCurvePublicKey): @six.add_metaclass(abc.ABCMeta) class MACContext(object): - @abc.abstractproperty - def algorithm(self): - """ - The algorithm that will be used by this context. - """ - @abc.abstractmethod def update(self, data): """ @@ -521,3 +494,5 @@ class MACContext(object): Checks if the generated message authentication code matches the signature. """ + +CMACContext = MACContext -- cgit v1.2.3 From c7c82f3849f33d34637fa133fc906efbc4fd6aef Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Mon, 20 Oct 2014 12:15:22 +0800 Subject: Add to changelog. Document deprecation. --- CHANGELOG.rst | 4 ++++ cryptography/hazmat/backends/openssl/cmac.py | 1 - cryptography/hazmat/primitives/cmac.py | 1 - cryptography/hazmat/primitives/interfaces.py | 1 + docs/hazmat/primitives/interfaces.rst | 2 ++ 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 70e30e66..689fcfc9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -9,6 +9,10 @@ Changelog * More bit-lengths are now support for ``p`` and ``q`` when loading DSA keys from numbers. +* Added `~cryptography.hazmat.primitives.interfaces.MACContext` as a common + interface for CMAC and HMAC and deprecated + `~cryptography.hazmat.primitives.interfaces.CMACContext`. + 0.6.1 - 2014-10-15 ~~~~~~~~~~~~~~~~~~ diff --git a/cryptography/hazmat/backends/openssl/cmac.py b/cryptography/hazmat/backends/openssl/cmac.py index f1d068eb..da7b7484 100644 --- a/cryptography/hazmat/backends/openssl/cmac.py +++ b/cryptography/hazmat/backends/openssl/cmac.py @@ -21,7 +21,6 @@ from cryptography.hazmat.primitives.ciphers.modes import CBC @utils.register_interface(interfaces.MACContext) -@utils.register_interface(interfaces.CMACContext) class _CMACContext(object): def __init__(self, backend, algorithm, ctx=None): if not backend.cmac_algorithm_supported(algorithm): diff --git a/cryptography/hazmat/primitives/cmac.py b/cryptography/hazmat/primitives/cmac.py index 968fa463..7ae5c118 100644 --- a/cryptography/hazmat/primitives/cmac.py +++ b/cryptography/hazmat/primitives/cmac.py @@ -22,7 +22,6 @@ from cryptography.hazmat.primitives import constant_time, interfaces @utils.register_interface(interfaces.MACContext) -@utils.register_interface(interfaces.CMACContext) class CMAC(object): def __init__(self, algorithm, backend, ctx=None): if not isinstance(backend, CMACBackend): diff --git a/cryptography/hazmat/primitives/interfaces.py b/cryptography/hazmat/primitives/interfaces.py index c09a9618..370fd68a 100644 --- a/cryptography/hazmat/primitives/interfaces.py +++ b/cryptography/hazmat/primitives/interfaces.py @@ -495,4 +495,5 @@ class MACContext(object): signature. """ +# DeprecatedIn07 CMACContext = MACContext diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index 2ee2017c..931aa962 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -648,6 +648,8 @@ Key derivation functions .. class:: CMACContext + `CMACContext` has been deprecated in favor of `MACContext`. + .. versionadded:: 0.4 .. method:: update(data) -- cgit v1.2.3 From ff5ec86837be8eefb6f7cb819433cf1878e31d26 Mon Sep 17 00:00:00 2001 From: Terry Chia Date: Mon, 20 Oct 2014 12:15:22 +0800 Subject: Add to changelog. Document deprecation. --- CHANGELOG.rst | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 689fcfc9..c8cec58d 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,10 +8,9 @@ Changelog * More bit-lengths are now support for ``p`` and ``q`` when loading DSA keys from numbers. - -* Added `~cryptography.hazmat.primitives.interfaces.MACContext` as a common - interface for CMAC and HMAC and deprecated - `~cryptography.hazmat.primitives.interfaces.CMACContext`. +* Added :class:`~cryptography.hazmat.primitives.interfaces.MACContext` as a + common interface for CMAC and HMAC and deprecated + :class:`~cryptography.hazmat.primitives.interfaces.CMACContext`. 0.6.1 - 2014-10-15 ~~~~~~~~~~~~~~~~~~ -- cgit v1.2.3 From 7d15688fe0c64d324691fc3886bcc9a5cdba62d1 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Mon, 20 Oct 2014 10:40:34 -0700 Subject: A few docs formatting nits --- docs/hazmat/primitives/interfaces.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/hazmat/primitives/interfaces.rst b/docs/hazmat/primitives/interfaces.rst index 931aa962..4cb64c83 100644 --- a/docs/hazmat/primitives/interfaces.rst +++ b/docs/hazmat/primitives/interfaces.rst @@ -648,7 +648,7 @@ Key derivation functions .. class:: CMACContext - `CMACContext` has been deprecated in favor of `MACContext`. + :class:`CMACContext` has been deprecated in favor of :class:`MACContext`. .. versionadded:: 0.4 @@ -679,10 +679,11 @@ Key derivation functions .. method:: copy() - :return: A :class:`~cryptography.hazmat.primitives.interfaces.MACContext` - that is a copy of the current context. + :return: A + :class:`~cryptography.hazmat.primitives.interfaces.MACContext` that + is a copy of the current context. - .. method:: verify() + .. method:: verify(signature) :param signature bytes: The signature to verify. -- cgit v1.2.3