Skip to content

Commit

Permalink
Fixed Blockfeeder incorrectly accepted empty string as input termiati…
Browse files Browse the repository at this point in the history
…ons (Issue 15).
  • Loading branch information
ricmoo committed Sep 20, 2017
1 parent 012ea24 commit 23a1b4c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pyaes/blockfeeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def feed(self, data = None):
raise ValueError('already finished feeder')

# Finalize; process the spare bytes we were keeping
if not data:
if data is None:
result = self._final(self._buffer, self._padding)
self._buffer = None
return result
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
for API reference and details.'''

setup(name = 'pyaes',
version = '1.6.0',
version = '1.6.1',
description = 'Pure-Python Implementation of the AES block-cipher and common modes of operation',
long_description = LONG_DESCRIPTION,
author = 'Richard Moore',
Expand Down
33 changes: 33 additions & 0 deletions tests/test-blockfeeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,36 @@
passed = decrypted == plaintext
cipher_length = len(ciphertext)
print(" cipher-length=%(cipher_length)s passed=%(passed)s" % locals())

# Issue #15
# https://github.com/ricmoo/pyaes/issues/15
# @TODO: These tests need a severe overhaul; they should use deterministic input, keys and IVs...
def TestIssue15():
print('Issue #15')

key = b"abcdefghijklmnop"
iv = b"0123456789012345"
encrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(key, iv))

plaintext = b"Hello World!!!!!"

ciphertext = to_bufferable('')

ciphertext += encrypter.feed(plaintext)
ciphertext += encrypter.feed('')
ciphertext += encrypter.feed(plaintext)
ciphertext += encrypter.feed(None)
expected = b'(Ob\xe5\xae"\xdc\xb0\x84\xc5\x04\x04GQ\xd8.\x0e4\xd2b\xc1\x15\xe5\x11M\xfc\x9a\xd2\xd5\xc8xP\x00[\xd57\x92\x01\xbb\xc42\x18\xbc\xbf\x1ay\x19P'

decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv))

output = to_bufferable('')

output += decrypter.feed('')
output += decrypter.feed(ciphertext)
output += decrypter.feed('')
output += decrypter.feed(None)

print(" passed=%(passed)s" % dict(passed = (ciphertext == expected and output == (plaintext + plaintext))))

TestIssue15()

0 comments on commit 23a1b4c

Please sign in to comment.