From c9ff1cb34ca799e0722208619495a27f63efb4ca Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 29 Jun 2014 11:24:29 -0700 Subject: Fixed accidental use of the global backend name --- cryptography/hazmat/backends/openssl/backend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index cfd1078b..4991177a 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -912,7 +912,7 @@ class Backend(object): Generate a new private key on the named curve. """ - if backend.elliptic_curve_supported(curve): + if self.elliptic_curve_supported(curve): curve_nid = self._elliptic_curve_to_nid(curve) ctx = self._lib.EC_KEY_new_by_curve_name(curve_nid) -- cgit v1.2.3 From d9d472b8b18344862056f88c8b8df7cd8e76f00c Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 29 Jun 2014 11:26:22 -0700 Subject: CommonCrypto as well --- cryptography/hazmat/backends/commoncrypto/backend.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cryptography/hazmat/backends/commoncrypto/backend.py b/cryptography/hazmat/backends/commoncrypto/backend.py index 41be11f9..9f63cb7b 100644 --- a/cryptography/hazmat/backends/commoncrypto/backend.py +++ b/cryptography/hazmat/backends/commoncrypto/backend.py @@ -238,7 +238,7 @@ class Backend(object): ) -def _release_cipher_ctx(ctx): +def _release_cipher_ctx(backend, ctx): """ Called by the garbage collector and used to safely dereference and release the context. @@ -358,7 +358,8 @@ class _GCMCipherContext(object): ) ctx = self._backend._ffi.new("CCCryptorRef *") - ctx = self._backend._ffi.gc(ctx, _release_cipher_ctx) + ctx = self._backend._ffi.gc( + ctx, lambda ctx: _release_cipher_ctx(self._backend, ctx)) self._ctx = ctx @@ -393,9 +394,10 @@ class _GCMCipherContext(object): tag_size = self._cipher.block_size // 8 tag_buf = self._backend._ffi.new("unsigned char[]", tag_size) tag_len = self._backend._ffi.new("size_t *", tag_size) - res = backend._lib.CCCryptorGCMFinal(self._ctx[0], tag_buf, tag_len) + res = self.backend._lib.CCCryptorGCMFinal( + self._ctx[0], tag_buf, tag_len) self._backend._check_response(res) - _release_cipher_ctx(self._ctx) + _release_cipher_ctx(self.backend, self._ctx) self._tag = self._backend._ffi.buffer(tag_buf)[:] if (self._operation == self._backend._lib.kCCDecrypt and not constant_time.bytes_eq( -- cgit v1.2.3 From 985676e7cc2276195b7dce355e340a9880150f0b Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 29 Jun 2014 11:44:50 -0700 Subject: Refactor for cleanliness --- .../hazmat/backends/commoncrypto/backend.py | 30 ++++++++++------------ 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/cryptography/hazmat/backends/commoncrypto/backend.py b/cryptography/hazmat/backends/commoncrypto/backend.py index 9f63cb7b..6c366c3c 100644 --- a/cryptography/hazmat/backends/commoncrypto/backend.py +++ b/cryptography/hazmat/backends/commoncrypto/backend.py @@ -237,16 +237,15 @@ class Backend(object): " Code: {0}.".format(response) ) - -def _release_cipher_ctx(backend, ctx): - """ - Called by the garbage collector and used to safely dereference and - release the context. - """ - if ctx[0] != backend._ffi.NULL: - res = backend._lib.CCCryptorRelease(ctx[0]) - backend._check_response(res) - ctx[0] = backend._ffi.NULL + def _release_cipher_ctx(self, ctx): + """ + Called by the garbage collector and used to safely dereference and + release the context. + """ + if ctx[0] != self._ffi.NULL: + res = self._lib.CCCryptorRelease(ctx[0]) + self._check_response(res) + ctx[0] = self._ffi.NULL @utils.register_interface(interfaces.CipherContext) @@ -284,7 +283,7 @@ class _CipherContext(object): ) ctx = self._backend._ffi.new("CCCryptorRef *") - ctx = self._backend._ffi.gc(ctx, _release_cipher_ctx) + ctx = self._backend._ffi.gc(ctx, self._backend._release_cipher_ctx) if isinstance(mode, interfaces.ModeWithInitializationVector): iv_nonce = mode.initialization_vector @@ -332,7 +331,7 @@ class _CipherContext(object): res = self._backend._lib.CCCryptorFinal( self._ctx[0], buf, len(buf), outlen) self._backend._check_response(res) - _release_cipher_ctx(self._ctx) + self._backend._release_cipher_ctx(self._ctx) return self._backend._ffi.buffer(buf)[:outlen[0]] @@ -358,8 +357,7 @@ class _GCMCipherContext(object): ) ctx = self._backend._ffi.new("CCCryptorRef *") - ctx = self._backend._ffi.gc( - ctx, lambda ctx: _release_cipher_ctx(self._backend, ctx)) + ctx = self._backend._ffi.gc(ctx, self._backend._release_cipher_ctx) self._ctx = ctx @@ -394,10 +392,10 @@ class _GCMCipherContext(object): tag_size = self._cipher.block_size // 8 tag_buf = self._backend._ffi.new("unsigned char[]", tag_size) tag_len = self._backend._ffi.new("size_t *", tag_size) - res = self.backend._lib.CCCryptorGCMFinal( + res = self._backend._lib.CCCryptorGCMFinal( self._ctx[0], tag_buf, tag_len) self._backend._check_response(res) - _release_cipher_ctx(self.backend, self._ctx) + self._backend._release_cipher_ctx(self._ctx) self._tag = self._backend._ffi.buffer(tag_buf)[:] if (self._operation == self._backend._lib.kCCDecrypt and not constant_time.bytes_eq( -- cgit v1.2.3