python-cryptoplus
python-cryptoplus copied to clipboard
XTS upper bound assertion is wrong
On line 454 of blockcipher.py, the assertion:
assert len(data) < 128*pow(2,20)
should be
assert len(data) < 16*pow(2,20)
The NIST recommendation reads:
The length of the data unit for any instance of an implementation of XTS-AES shall not exceed 2^20 AES blocks
An AES block is 16 bytes, or 128 bits, and the data in the code at this point is bytes, not bits, so the number 16 should be used, not 128. Or even better, a constant AES_BLK_BYTES should be created with the value of 16, and all the 16's in this section could be replaced with that constant.
I would suggest the expression <= 16 * 2**20 because "shall not exceed"