Skip to content

Commit 23a1b4c

Browse files
committed
Fixed Blockfeeder incorrectly accepted empty string as input termiations (Issue 15).
1 parent 012ea24 commit 23a1b4c

3 files changed

Lines changed: 35 additions & 2 deletions

File tree

pyaes/blockfeeder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ def feed(self, data = None):
165165
raise ValueError('already finished feeder')
166166

167167
# Finalize; process the spare bytes we were keeping
168-
if not data:
168+
if data is None:
169169
result = self._final(self._buffer, self._padding)
170170
self._buffer = None
171171
return result

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
for API reference and details.'''
99

1010
setup(name = 'pyaes',
11-
version = '1.6.0',
11+
version = '1.6.1',
1212
description = 'Pure-Python Implementation of the AES block-cipher and common modes of operation',
1313
long_description = LONG_DESCRIPTION,
1414
author = 'Richard Moore',

tests/test-blockfeeder.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,36 @@
146146
passed = decrypted == plaintext
147147
cipher_length = len(ciphertext)
148148
print(" cipher-length=%(cipher_length)s passed=%(passed)s" % locals())
149+
150+
# Issue #15
151+
# https://github.com/ricmoo/pyaes/issues/15
152+
# @TODO: These tests need a severe overhaul; they should use deterministic input, keys and IVs...
153+
def TestIssue15():
154+
print('Issue #15')
155+
156+
key = b"abcdefghijklmnop"
157+
iv = b"0123456789012345"
158+
encrypter = pyaes.Encrypter(pyaes.AESModeOfOperationCBC(key, iv))
159+
160+
plaintext = b"Hello World!!!!!"
161+
162+
ciphertext = to_bufferable('')
163+
164+
ciphertext += encrypter.feed(plaintext)
165+
ciphertext += encrypter.feed('')
166+
ciphertext += encrypter.feed(plaintext)
167+
ciphertext += encrypter.feed(None)
168+
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'
169+
170+
decrypter = pyaes.Decrypter(pyaes.AESModeOfOperationCBC(key, iv))
171+
172+
output = to_bufferable('')
173+
174+
output += decrypter.feed('')
175+
output += decrypter.feed(ciphertext)
176+
output += decrypter.feed('')
177+
output += decrypter.feed(None)
178+
179+
print(" passed=%(passed)s" % dict(passed = (ciphertext == expected and output == (plaintext + plaintext))))
180+
181+
TestIssue15()

0 commit comments

Comments
 (0)