Use a simpler formula for Kyber division by q#3959
Merged
Conversation
Simpler approach than #3898
FAlbertDev
approved these changes
Apr 2, 2024
Collaborator
FAlbertDev
left a comment
There was a problem hiding this comment.
I'm okay with using this more straightforward approach. We can stay with this simple method until we need other CT divisions in the future.
Since we already have a test for our ct_div function in #3898, we may also want to apply it here.
// src/tests/test_kyber.cpp
namespace {
std::vector<Test::Result> test_kyber_utilities() {
return {
Botan_Tests::CHECK("constant-time division",
[](Test::Result& result) {
constexpr auto Q = Botan::KyberConstants::Q;
// Check ct_int_div_kyber_q with all possible inputs that may appear in Kyber.
for(uint32_t i = 0; i < (1 << 18); ++i) {
result.test_is_eq(
Botan::fmt("{}/Q", i), Botan::ct_int_div_kyber_q(i), i / Q);
}
}),
};
}
} // namespace
BOTAN_REGISTER_TEST_FN("kyber", "kyber_utils", test_kyber_utilities);
Owner
Author
|
The function isn't currently exposed anywhere and I'm inclined not to expose it simply to test it, considering it is quite small and should already be very well tested as a side effect of the Kyber tests themselves. I did do an offline test that the expression works for all integers < 2**20. |
This was referenced Apr 5, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Simpler approach than #3898