From 2120a8e090ff8974d727f76aae5f2f9eac56656c Mon Sep 17 00:00:00 2001 From: Aviv Palivoda Date: Sat, 2 Jul 2016 19:43:06 +0300 Subject: One shot sign/verification ECDSA (#3029) * Add sign and verify methods to ECDSA * Documented ECDSA sign/verify methods * Added CHANGELOG entry * Skipping test verify and sign if curve is not supported * Fixed typo in documentation return type * Removed provider language from EllipticCurvePrivateKey and EllipticCurvePublicKey --- src/cryptography/hazmat/backends/openssl/ec.py | 10 ++++++++++ src/cryptography/hazmat/primitives/asymmetric/ec.py | 12 ++++++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/cryptography/hazmat/backends/openssl/ec.py b/src/cryptography/hazmat/backends/openssl/ec.py index 2f476031..1e45e402 100644 --- a/src/cryptography/hazmat/backends/openssl/ec.py +++ b/src/cryptography/hazmat/backends/openssl/ec.py @@ -240,6 +240,11 @@ class _EllipticCurvePrivateKey(object): self._ec_key ) + def sign(self, data, signature_algorithm): + signer = self.signer(signature_algorithm) + signer.update(data) + return signer.finalize() + @utils.register_interface(ec.EllipticCurvePublicKeyWithSerialization) class _EllipticCurvePublicKey(object): @@ -303,3 +308,8 @@ class _EllipticCurvePublicKey(object): self._evp_pkey, None ) + + def verify(self, signature, data, signature_algorithm): + verifier = self.verifier(signature, signature_algorithm) + verifier.update(data) + verifier.verify() diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py index 907a6358..1c576c6d 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/ec.py +++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py @@ -62,6 +62,12 @@ class EllipticCurvePrivateKey(object): The EllipticCurve that this key is on. """ + @abc.abstractproperty + def sign(self, data, signature_algorithm): + """ + Signs the data + """ + @six.add_metaclass(abc.ABCMeta) class EllipticCurvePrivateKeyWithSerialization(EllipticCurvePrivateKey): @@ -104,6 +110,12 @@ class EllipticCurvePublicKey(object): Returns the key serialized as bytes. """ + @abc.abstractmethod + def verify(self, signature, data, signature_algorithm): + """ + Verifies the signature of the data. + """ + EllipticCurvePublicKeyWithSerialization = EllipticCurvePublicKey -- cgit v1.2.3