aes-js icon indicating copy to clipboard operation
aes-js copied to clipboard

CFB encryption/decryption segment size error may be incorrect

Open rderwin opened this issue 8 years ago • 8 comments

I am using this library to decrypt a CFB cipher 40 characters long, with a segment size of 16. It fails from this error:

if ((plaintext.length % this.segmentSize) != 0) { throw new Error('invalid plaintext size (must be segmentSize bytes)'); }

However, when removing these line I am able to successfully decode the string.

Is this error incorrect? I was thinking segmentSize would be in bits and not bytes, so 40 bytes should be divisible into 16 bits without issue.

rderwin avatar Feb 24 '17 00:02 rderwin

The library (and my python implementation) have made the assumption it is measured in bytes, but looking at it, I believe you are right, it should absolutely be in bits.

I will update the test cases and adjust the code as needed to support bits. The test cases were specifically generated on byte alignments, but I see now the intention of CBF.

This will be a major version bump.

Thanks! I'll get to this soon.

ricmoo avatar Feb 24 '17 18:02 ricmoo

What's the status of this?

johnrickman avatar May 27 '17 20:05 johnrickman

I haven't had time to get to this yet... It's been a crazy time with Ethereum.

If you create a pull request with the changes and add test cases though, I will verify and commit. Otherwise, it will probably still be a week or so before I can get to this.

ricmoo avatar May 30 '17 21:05 ricmoo

I actually realized that this is no longer an issue of mine, as I can use the pkcs7 padding as my input has already been padded.

johnrickman avatar May 31 '17 15:05 johnrickman

Any news on this one?

jvallar avatar Feb 14 '18 15:02 jvallar

Sorry, haven't had a chance to get to this, and this weekend is big hackathon. I will add something to my calendar to look into this next week.

ricmoo avatar Feb 15 '18 00:02 ricmoo

A fix for this would be much appreciated.

mikkelvp avatar Jan 15 '19 14:01 mikkelvp

Any progress? I can't use CFB properly - it just returns me a clear random instead of encrypted/decrypted buffer

Saiv46 avatar Jun 27 '20 18:06 Saiv46