Skip to content

Commit a5a1f8a

Browse files
committed
Blowfish: remove buggy padding, this has nothing to do here anyway
1 parent 68a6e41 commit a5a1f8a

File tree

1 file changed

+3
-13
lines changed

1 file changed

+3
-13
lines changed

src/CryptoPlus/Cipher/pyblowfish.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def crypt(self, data, direction):
6060
Performs actual encryption/decryption of data
6161
depending on the direction. The data is broken
6262
up into 8 byte chunks for the ciphering
63-
process. If the data does not align on 8 byte
64-
chunks, then null padding is added. This is
65-
removed upon decryption.
63+
process. Data must be aligned on 8 byte chunks.
6664
6765
def cipher(self, xl, xr, direction):
6866
Encrypts a 64-bit block of data where xl is
@@ -439,12 +437,8 @@ def __round_func(self, xl):
439437
return int(f)
440438

441439
def crypt(self, data, direction):
442-
# Pad the data if need be so it has 8 byte chunks
443-
align = len(data) % 8
444-
if align != 0:
445-
padding = '\x00' * (8 - align)
446-
data += padding
447-
440+
# Data must be padded
441+
assert len(data) % 8 == 0
448442
result = ''
449443
for i in range(0, len(data), 8):
450444
# Use big endianess since that's what everyone else uses
@@ -457,10 +451,6 @@ def crypt(self, data, direction):
457451
(xr >> 24) & 0xFF, (xr >> 16) & 0xFF, (xr >> 8) & 0xFF, xr & 0xFF
458452
)
459453
result += ''.join(map(chr, chunk))
460-
461-
# Strip the padding if we decrypted
462-
if direction == self.DECRYPT:
463-
result = result.rstrip('\x00')
464454
return result
465455

466456
def encrypt(self, data):

0 commit comments

Comments
 (0)