-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make aes_hw_ctr32_encrypt_blocks handle len=0 correctly #1690
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1690 +/- ##
==========================================
- Coverage 78.35% 78.34% -0.01%
==========================================
Files 573 573
Lines 96123 96129 +6
Branches 13780 13780
==========================================
- Hits 75318 75317 -1
- Misses 20200 20205 +5
- Partials 605 607 +2 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test that calls aes_hw_ctr32_encrypt_blocks
with a length of zero and verifies the input/output buffers aren't modified. Does address sanitizer find this original issue without this change?
Yeah, I had added the test here 69b858a with printouts to verify for myself. I reverted that commit which included the fix for x86 (due to performance regression). I can add back the test |
Showing also printing the first 4 blocks. This commit is to be reverted.
This reverts commit 69b858a.
amazonlinux2023_gcc11x_aarch_valgrind complained
and still complained after comparing |
in amazonlinux2023_gcc11x_aarch_valgrind.
Prior to the fix, the first block was written to when the number of input blocks is 0. The test for this case is no longer restricted to AArch64. It should not actually affect the performance.
crypto/fipsmodule/aes/aes_test.cc
Outdated
for (size_t i = 0; i < 64; i++) { | ||
buf[i] = i; | ||
} | ||
Bytes buf_before = Bytes(buf,64); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bytes/span doesn't create a copy of the data, they reference the original memory. So this test passes even if aes_hw_encrypt touches buf. For example this passes:
TEST(BytesTest, copyOrClone) {
uint8_t buf[64] = {0};
Bytes buf_before = Bytes(buf,64);
buf[0] = 1;
ASSERT_EQ(buf_before, Bytes(buf, 64));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Andrew. I brought back the string comparison I had when I was testing in 110ab16.
@@ -1234,6 +1234,7 @@ sub aesni_generate8 { | |||
|
|||
.align 16 | |||
.Lctr32_bulk: | |||
jb .Lctr32_epilogue # if $len < 1, go to done |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this be right after cmp
in line 1216?
### Description: This PR updates program and tests for `aes_hw_ctr32_encrypt_blocks` based on the fix of a bug from the PR aws/aws-lc#1690 ### Testing: What tests have been run? Did `make all` succeed for your changes? Was conformance testing successful on an Aarch64 machine? Yes for both. ### License: By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Issues:
Resolves #CryptoAlg-2498
Description of changes:
aes_hw_ctr32_encrypt_blocks
encrypts (and writes to the output) 2 blocks when the input length is 0 blocks in the case of AArch64 and 1 block in the case of x86_64 and x86.The function is guarded wherever it's called by checks that
len != 0
.This change fixes this behaviour without taxing the performance.
Testing:
Tested the performance on Graviton3 and on Mac x86_64.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license and the ISC license.