Blowfish pads an incoming stream improperly. This was seen and reported by Jim in this thread on comp.lang.tcl:


The improper padding happens in the procedure blowfish::Chunk which already contains a FIXME comment. The procedure needs to care about 2 things:

1. Data must always be processed in multiples of 8 bytes. However, it's not guaranteed that a multiple of 8 bytes is read even in the middle of a stream. Reasons can be an odd user provided chunk size or a nonblocking channel. My patch introduces a new variable state(remainder) to hold the modulo data.

2. Apply padding at the end of the stream, and only there. Don't pad an empty string. Unfortunately, blowfish::Pad is doing exactly this. I think an empty string should not be padded. Likewise an empty data set encrpyts to an empty data set. If this is not correct then extra care has to be taken with the remainig data at EOF. Also, blowfish::Chunk didn't call pad with the user provided pad character.

The attached patch takes care of both points.

Missing: A test for the input channel API.

-- Stephan Effelsberg