From 416f526a3d809d330b4a990bdf4a742384bde8f8 Mon Sep 17 00:00:00 2001 From: Paul Kehrer Date: Tue, 23 May 2017 23:38:59 -0700 Subject: add convenience methods for key_size on EC{Public,Private}Key (#3587) --- src/cryptography/hazmat/backends/openssl/ec.py | 8 ++++++++ src/cryptography/hazmat/primitives/asymmetric/ec.py | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/cryptography/hazmat/backends/openssl/ec.py b/src/cryptography/hazmat/backends/openssl/ec.py index 68a35b21..3a81f919 100644 --- a/src/cryptography/hazmat/backends/openssl/ec.py +++ b/src/cryptography/hazmat/backends/openssl/ec.py @@ -135,6 +135,10 @@ class _EllipticCurvePrivateKey(object): curve = utils.read_only_property("_curve") + @property + def key_size(self): + return self.curve.key_size + def signer(self, signature_algorithm): _check_signature_algorithm(signature_algorithm) return _ECDSASignatureContext( @@ -231,6 +235,10 @@ class _EllipticCurvePublicKey(object): curve = utils.read_only_property("_curve") + @property + def key_size(self): + return self.curve.key_size + def verifier(self, signature, signature_algorithm): if not isinstance(signature, bytes): raise TypeError("signature must be bytes.") diff --git a/src/cryptography/hazmat/primitives/asymmetric/ec.py b/src/cryptography/hazmat/primitives/asymmetric/ec.py index a527387b..7931b086 100644 --- a/src/cryptography/hazmat/primitives/asymmetric/ec.py +++ b/src/cryptography/hazmat/primitives/asymmetric/ec.py @@ -22,7 +22,7 @@ class EllipticCurve(object): @abc.abstractproperty def key_size(self): """ - The bit length of the base point of the curve. + Bit size of a secret scalar for the curve. """ @@ -62,6 +62,12 @@ class EllipticCurvePrivateKey(object): The EllipticCurve that this key is on. """ + @abc.abstractproperty + def key_size(self): + """ + Bit size of a secret scalar for the curve. + """ + @abc.abstractproperty def sign(self, data, signature_algorithm): """ @@ -98,6 +104,12 @@ class EllipticCurvePublicKey(object): The EllipticCurve that this key is on. """ + @abc.abstractproperty + def key_size(self): + """ + Bit size of a secret scalar for the curve. + """ + @abc.abstractmethod def public_numbers(self): """ -- cgit v1.2.3