You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At the beginning of the CBC encrypt/decrypt functions the contents of the input buffer is copied to the output buffer, this is also done for ECB mode. The initial copy in ECB mode is necessary, but seems to be redundant in the CBC functions. The exact same copy is later made in the for loop iterating through the AES blocks.
A visual inspection of AES128_CBC_encrypt_buffer() and AES128_CBC_decrypt_buffer() should confirm the issue.
Testing
The tests pass with the redundant copy removed.
Fix
Remove redundant call to BlockCopy() in AES128_CBC_encrypt_buffer() and AES128_CBC_decrypt_buffer().
Existing Fixes
I had a hunt through the pull requests and found the following un-merged requests that address this issue:
Summary
At the beginning of the CBC encrypt/decrypt functions the contents of the input buffer is copied to the output buffer, this is also done for ECB mode. The initial copy in ECB mode is necessary, but seems to be redundant in the CBC functions. The exact same copy is later made in the for loop iterating through the AES blocks.
A visual inspection of
AES128_CBC_encrypt_buffer()
andAES128_CBC_decrypt_buffer()
should confirm the issue.Testing
The tests pass with the redundant copy removed.
Fix
Remove redundant call to
BlockCopy()
inAES128_CBC_encrypt_buffer()
andAES128_CBC_decrypt_buffer()
.Existing Fixes
I had a hunt through the pull requests and found the following un-merged requests that address this issue:
fix off-by-one in CBC de-/encrypt; don't touch input buffer during CBC encryption #18 Removes redundant copy, as well as other changes.
Fixes a number of issues with CBC implementation #23 Lots of fixes to CBC implementation including this redundant block copy.
Conclusion
This is a simple fix that can shave off a few redundant CPU cycles, unless the compiler is already optimising it out for you 😄
I am happy to prepare a pull request addressing this issue only, if there's interest.
The text was updated successfully, but these errors were encountered: