aboutsummaryrefslogtreecommitdiffstats
path: root/cryptography
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-09-11 18:04:48 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-09-11 18:04:48 -0500
commit270b9d46efdfdff9faea86a48ccb98147348418b (patch)
tree7b97e76a12d13c38f3c40f0a17c5904dea2af6fa /cryptography
parentb8599c085d3e295f460f0117f7df9288a4841d7f (diff)
downloadcryptography-270b9d46efdfdff9faea86a48ccb98147348418b.tar.gz
cryptography-270b9d46efdfdff9faea86a48ccb98147348418b.tar.bz2
cryptography-270b9d46efdfdff9faea86a48ccb98147348418b.zip
Fix two bugs with CommonCrypto GCM that can result in invalid output.
Bug #1: Call to AAD but no call to update. Get null tag bytes. Bug #2: Call to update without call to AAD. Get null ciphertext bytes. Fixes #1329
Diffstat (limited to 'cryptography')
-rw-r--r--cryptography/hazmat/backends/commoncrypto/ciphers.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/cryptography/hazmat/backends/commoncrypto/ciphers.py b/cryptography/hazmat/backends/commoncrypto/ciphers.py
index 525500c8..4f723487 100644
--- a/cryptography/hazmat/backends/commoncrypto/ciphers.py
+++ b/cryptography/hazmat/backends/commoncrypto/ciphers.py
@@ -151,6 +151,11 @@ class _GCMCipherContext(object):
len(mode.initialization_vector)
)
self._backend._check_cipher_response(res)
+ # CommonCrypto has a bug where calling update without at least one
+ # call to authenticate_additional_data will result in null byte output
+ # for ciphertext. The following empty byte string call prevents the
+ # issue, which is present in at least 10.8 and 10.9.
+ self.authenticate_additional_data(b"")
def update(self, data):
buf = self._backend._ffi.new("unsigned char[]", len(data))
@@ -164,6 +169,11 @@ class _GCMCipherContext(object):
return self._backend._ffi.buffer(buf)[:]
def finalize(self):
+ # CommonCrypto has a yet another bug where you must make at least one
+ # call to update. If you pass just AAD and call finalize without a call
+ # to update you'll get null bytes for tag. The following update call
+ # prevents this issue, which is present in at least 10.8 and 10.9.
+ self.update(b"")
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)