diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2014-10-19 18:42:01 -0700 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2014-10-19 18:42:01 -0700 |
commit | b796621b2888f8573bfd42ed895c03667e3d5cb8 (patch) | |
tree | 5e273f8dd487f5966c1cb6fc2b001c2c184b486b /cryptography | |
parent | eccf37f6fe6b3af4c75ac6f2f432947c858fddcb (diff) | |
download | cryptography-b796621b2888f8573bfd42ed895c03667e3d5cb8.tar.gz cryptography-b796621b2888f8573bfd42ed895c03667e3d5cb8.tar.bz2 cryptography-b796621b2888f8573bfd42ed895c03667e3d5cb8.zip |
Do these checks in pure python eagerly.
We get errors in different places, depending on py2k vs. py3k if we don't.
Diffstat (limited to 'cryptography')
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index f1cf908a..bb1a3f3d 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -984,6 +984,11 @@ class Backend(object): values. """ + if x < 0 or y < 0: + raise ValueError( + "Invalid EC key. Both x and y must be non-negative." + ) + bn_x = self._int_to_bn(x) bn_y = self._int_to_bn(y) @@ -1005,11 +1010,8 @@ class Backend(object): res = get_func(group, point, check_x, check_y, bn_ctx) assert res == 1 - if self._lib.BN_cmp(bn_x, check_x) != 0: - raise ValueError("Invalid EC key.") - - if self._lib.BN_cmp(bn_y, check_y) != 0: - raise ValueError("Invalid EC key.") + assert self._lib.BN_cmp(bn_x, check_x) == 0 + assert self._lib.BN_cmp(bn_y, check_y) == 0 res = self._lib.EC_KEY_set_public_key(ctx, point) assert res == 1 |