-
Notifications
You must be signed in to change notification settings - Fork 151
AES-XTS Enc Dec test on rand incremental length inputs #2795
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
base: main
Are you sure you want to change the base?
Conversation
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.
clang-tidy made some suggestions
crypto/fipsmodule/modes/xts_test.cc
Outdated
|
|
||
| SCOPED_TRACE(plaintext.size()); | ||
|
|
||
| int len; |
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.
warning: variable 'len' is not initialized [cppcoreguidelines-init-variables]
| int len; | |
| int len = 0; |
crypto/fipsmodule/modes/xts_test.cc
Outdated
| SCOPED_TRACE(plaintext.size()); | ||
|
|
||
| int len; | ||
| uint8_t *in_p, *out_p; |
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.
warning: variable 'in_p' is not initialized [cppcoreguidelines-init-variables]
| uint8_t *in_p, *out_p; | |
| uint8_t *in_p = nullptr, *out_p; |
crypto/fipsmodule/modes/xts_test.cc
Outdated
| SCOPED_TRACE(plaintext.size()); | ||
|
|
||
| int len; | ||
| uint8_t *in_p, *out_p; |
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.
warning: variable 'out_p' is not initialized [cppcoreguidelines-init-variables]
| uint8_t *in_p, *out_p; | |
| uint8_t *in_p, *out_p = nullptr; |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2795 +/- ##
==========================================
+ Coverage 78.42% 78.44% +0.02%
==========================================
Files 683 683
Lines 116283 116336 +53
Branches 16404 16410 +6
==========================================
+ Hits 91194 91261 +67
+ Misses 24213 24199 -14
Partials 876 876 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
nebeid
left a comment
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.
Looks good. Thank you @manastasova.
crypto/fipsmodule/modes/xts_test.cc
Outdated
| iv.data())); | ||
| ASSERT_TRUE( | ||
| EVP_EncryptUpdate(ctx.get(), out_p, &len, in_p, plaintext.size())); | ||
| OPENSSL_memcpy(ciphertext.data(), out_p, plaintext.size()); |
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.
Is this line, and more so ciphertext, used?
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.
Indeed, not used. Thanks, Nevine. Updated.
crypto/fipsmodule/modes/xts_test.cc
Outdated
| #endif | ||
| } | ||
|
|
||
| TEST(XTSTest, EncryptDecyptRand) { |
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.
| TEST(XTSTest, EncryptDecyptRand) { | |
| TEST(XTSTest, EncryptDecryptRand) { |
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!
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.
clang-tidy made some suggestions
|
|
||
| // Test encryption. | ||
|
|
||
| OPENSSL_memcpy(in_p, plaintext.data(), plaintext.size()); |
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.
warning: Use of memory after it is freed [clang-analyzer-cplusplus.NewDelete]
OPENSSL_memcpy(in_p, plaintext.data(), plaintext.size());
^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.
Not sure why this warning appears. in_p is used as the input message for the encryption function later on.
Add incremental length random input message tests for AES-XTS encryption/decryption
Issues:
N/A
Description of changes:
AWS-LC's current AES-XTS tests use fixed-size test vectors but do not systematically verify that encryption and decryption work correctly across different message lengths.
This PR adds a new test that generates random inputs of incremental lengths and verify that
encrypt(decrypt(input)) == inputfor each length. This ensures that AES-XTS correctly handles messages of varying sizes, particularly:The tests also add explicit length equality checks between plaintext and ciphertext to catch potential length-related bugs early.
Call-outs:
The test provides better confidence in correctness across different input sizes.
Testing:
./crypto/crypto_test --gtest_filter=XTSTest.EncryptDecryptRand.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.