aes: encrypt and decrypt one block at a time #64
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes a subtle issue in the AES cipher encryption and decryption functions. When the output buffer is smaller than the input buffer and both are larger than the AES block size (16 bytes), then
BCryptEncrypt
errors with theSTATUS_BUFFER_TOO_SMALL
code. This behavior is not what Go implementation expects, as it always encrypts and decrypts one full block at a time, even if the input buffer is larger than that.This issue is fixed by truncating the input and output buffers to the AES block size before calling
BCryptEncrypt
andBCryptDecrypt
.Added a new test to make sure that we don't regress and that our AES implementation is fully compatible with upstream AES.
This bug is worth backporting in the next patch release so our backend is more compatible with upstream.