diff options
author | Alex Gaynor <alex.gaynor@gmail.com> | 2015-12-26 20:38:11 -0500 |
---|---|---|
committer | Alex Gaynor <alex.gaynor@gmail.com> | 2015-12-26 20:38:11 -0500 |
commit | eefd3a8b51c8219f2c8a5d921b8266dee7d82d9b (patch) | |
tree | f6387bcecb9a6f85411f90bfe41987fb1a445f76 | |
parent | 3a6631c3db6d1c40912a6152b4c435e9fb99f422 (diff) | |
download | cryptography-eefd3a8b51c8219f2c8a5d921b8266dee7d82d9b.tar.gz cryptography-eefd3a8b51c8219f2c8a5d921b8266dee7d82d9b.tar.bz2 cryptography-eefd3a8b51c8219f2c8a5d921b8266dee7d82d9b.zip |
Simplify code slightly by adding a new binding
-rw-r--r-- | src/_cffi_src/openssl/bignum.py | 2 | ||||
-rw-r--r-- | src/cryptography/hazmat/backends/openssl/backend.py | 5 |
2 files changed, 3 insertions, 4 deletions
diff --git a/src/_cffi_src/openssl/bignum.py b/src/_cffi_src/openssl/bignum.py index ae035007..455afdc1 100644 --- a/src/_cffi_src/openssl/bignum.py +++ b/src/_cffi_src/openssl/bignum.py @@ -71,6 +71,8 @@ int BN_mask_bits(BIGNUM *, int); """ MACROS = """ +int BN_num_bytes(const BIGNUM *); + int BN_zero(BIGNUM *); int BN_one(BIGNUM *); int BN_mod(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py index 0dd9a2e3..c0c9ebe2 100644 --- a/src/cryptography/hazmat/backends/openssl/backend.py +++ b/src/cryptography/hazmat/backends/openssl/backend.py @@ -919,17 +919,14 @@ class Backend(object): assert bn != self._ffi.NULL if six.PY3: # Python 3 has constant time from_bytes, so use that. - - bn_num_bytes = (self._lib.BN_num_bits(bn) + 7) // 8 + bn_num_bytes = self._lib.BN_num_bytes(bn) bin_ptr = self._ffi.new("unsigned char[]", bn_num_bytes) bin_len = self._lib.BN_bn2bin(bn, bin_ptr) # A zero length means the BN has value 0 self.openssl_assert(bin_len >= 0) return int.from_bytes(self._ffi.buffer(bin_ptr)[:bin_len], "big") - else: # Under Python 2 the best we can do is hex() - hex_cdata = self._lib.BN_bn2hex(bn) self.openssl_assert(hex_cdata != self._ffi.NULL) hex_str = self._ffi.string(hex_cdata) |