diff options
author | Ayrx <terrycwk1994@gmail.com> | 2014-04-18 20:20:05 +0800 |
---|---|---|
committer | Ayrx <terrycwk1994@gmail.com> | 2014-04-22 12:12:41 +0800 |
commit | a536085949f5bd1b479eb313ea1c0b114294c0fd (patch) | |
tree | aea580b7e0925df1af668b55b523e56ea4771ddd | |
parent | 2124324a4aa678dc885ac20c5ac203663ac5f966 (diff) | |
download | cryptography-a536085949f5bd1b479eb313ea1c0b114294c0fd.tar.gz cryptography-a536085949f5bd1b479eb313ea1c0b114294c0fd.tar.bz2 cryptography-a536085949f5bd1b479eb313ea1c0b114294c0fd.zip |
Various fixes
-rw-r--r-- | cryptography/hazmat/backends/openssl/backend.py | 13 | ||||
-rw-r--r-- | cryptography/hazmat/primitives/cmac.py | 6 |
2 files changed, 12 insertions, 7 deletions
diff --git a/cryptography/hazmat/backends/openssl/backend.py b/cryptography/hazmat/backends/openssl/backend.py index ae4b4a85..7cfdd284 100644 --- a/cryptography/hazmat/backends/openssl/backend.py +++ b/cryptography/hazmat/backends/openssl/backend.py @@ -556,8 +556,8 @@ class Backend(object): return self._ffi.buffer(buf)[:res] def cmac_algorithm_supported(self, algorithm): - return backend._lib.Cryptography_HAS_CMAC == 1 \ - and backend.cipher_supported(algorithm, CBC(0)) + return (backend._lib.Cryptography_HAS_CMAC == 1 + and backend.cipher_supported(algorithm, CBC(0))) def create_cmac_ctx(self, algorithm): return _CMACContext(self, algorithm) @@ -1278,6 +1278,10 @@ class _CMACContext(object): ) ctx = self._backend._lib.CMAC_CTX_new() + + assert ctx != self._backend._ffi.NULL + ctx = self._backend._ffi.gc(ctx, self._backend._lib.CMAC_CTX_free) + self._backend._lib.CMAC_Init( ctx, self._key, len(self._key), evp_cipher, self._backend._ffi.NULL @@ -1297,14 +1301,15 @@ class _CMACContext(object): ) assert res == 1 - self._backend._lib.CMAC_CTX_free(self._ctx) + self._ctx = None + return self._backend._ffi.buffer(buf)[:] def copy(self): copied_ctx = self._backend._lib.CMAC_CTX_new() self._backend._lib.CMAC_CTX_init(copied_ctx) copied_ctx = self._backend._ffi.gc( - copied_ctx, self._backend._lib.CMAC_CTX_free() + copied_ctx, self._backend._lib.CMAC_CTX_free ) res = self._backend._lib.CMAC_CTX_copy( copied_ctx, self._ctx diff --git a/cryptography/hazmat/primitives/cmac.py b/cryptography/hazmat/primitives/cmac.py index bbf0bf9c..7e7f65ab 100644 --- a/cryptography/hazmat/primitives/cmac.py +++ b/cryptography/hazmat/primitives/cmac.py @@ -36,11 +36,11 @@ class CMAC(object): raise TypeError( "Expected instance of interfaces.BlockCipherAlgorithm" ) - self.algorithm = algorithm + self._algorithm = algorithm self._backend = backend if ctx is None: - self._ctx = self._backend.create_cmac_ctx(self.algorithm) + self._ctx = self._backend.create_cmac_ctx(self._algorithm) else: self._ctx = ctx @@ -69,7 +69,7 @@ class CMAC(object): if self._ctx is None: raise AlreadyFinalized("Context was already finalized") return CMAC( - self.algorithm, + self._algorithm, backend=self._backend, ctx=self._ctx.copy() ) |