Skip to content
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

Remove NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE #645

Merged
merged 3 commits into from
Jan 13, 2025
Merged

Conversation

hanno-becker
Copy link
Contributor

@hanno-becker hanno-becker commented Jan 12, 2025

The numeric macros NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE could be used by backends to specify an output bound for the forward and inverse NTT. We would then use STATIC_ASSERT's to check that those backend-specific bounds would imply the bounds (NTT_BOUND and INVNTT_BOUND) that the CBMC proofs work against.

The added value of NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE is questionable. In the end, what we care about is that the native NTT and invNTT adhere to the bounds that CBMC relies on. Any strengthening of the bounds may be good to know, but is otherwise an unnecessary complication of the code.

This commit removes NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE and uses the contractual bounds NTT_BOUND and INVNT_BOUND in their place.


Also, remove the need for STATIC_ASSERT by rewriting its use using a plain #if.

@hanno-becker hanno-becker marked this pull request as ready for review January 12, 2025 20:22
@hanno-becker hanno-becker requested a review from a team January 12, 2025 20:22
@hanno-becker hanno-becker force-pushed the bound_native branch 3 times, most recently from dcec93e to 3ead8ca Compare January 13, 2025 05:59
Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with removing the native bounds as there is no real value in them.
Should we also move the static bound assertions?

mlkem/indcpa.c Outdated Show resolved Hide resolved
The numeric macros NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE could be
used by backends to specify an output bound for the forward and
inverse NTT. We would then use STATIC_ASSERT's to check that those
backend-specific bounds would imply the bounds (NTT_BOUND and
INVNTT_BOUND) that the CBMC proofs work against.

The added value of NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE is
questionable. In the end, what we care about is that the native
NTT and invNTT adhere to the bounds that CBMC relies on. Any
strengthening of the bounds may be good to know, but is otherwise
an unnecessary complication of the code.

This commit removes NTT_BOUND_NATIVE and INVNTT_BOUND_NATIVE
and uses the contractual bounds NTT_BOUND and INVNT_BOUND in
their place.

Similarly, INVNTT_BOUND_REF is removed, which is finer bound
for the reference invNTT.

Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
We conduct some basic static sanity checks on the values of
NTT_BOUND and INVNTT_BOUND. Previously, those checks were done
using a `STATIC_ASSERT` macro. The `STATIC_ASSERT` macro was
otherwise not used.

This commit rewrites said bounds checks using plain `#if ...`.
It therefore eliminates the need for `STATIC_ASSERT`, which is
removed.

Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
Those assertions are already checked by CBMC. Repeating them does not
add value but impedes readability.

Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
Copy link
Contributor

@mkannwischer mkannwischer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the changes. LGTM.

@mkannwischer mkannwischer merged commit eede403 into main Jan 13, 2025
122 checks passed
@mkannwischer mkannwischer deleted the bound_native branch January 13, 2025 11:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants