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

imported fix from CROSS upstream: endianness-aware csprng #1983

Merged
merged 7 commits into from
Nov 11, 2024

Conversation

rtjk
Copy link
Contributor

@rtjk rtjk commented Nov 8, 2024

Fixes #1961.

The rejection sampling functions in CROSS rely on pointer casting, which caused the CSPRNG to generate different numbers on big-endian versus little-endian architectures, resulting in different KATs. This fix uses the compiler flag __BYTE_ORDER__ to detect endianness and swap the bytes when necessary. Thank you @bhess for pointing us in the right direction!

  • Does this PR change the input/output behaviour of a cryptographic algorithm (i.e., does it change known answer test values)? (If so, a version bump will be required from x.y.z to x.(y+1).0.)
  • Does this PR change the list of algorithms available -- either adding, removing, or renaming? Does this PR otherwise change an API? (If so, PRs in fully supported downstream projects dependent on these, i.e., oqs-provider will also need to be ready for review and merge by the time this is merged.)

bhess added 3 commits November 5, 2024 10:42
This reverts commit b59d78c.

Signed-off-by: Basil Hess <[email protected]>
Signed-off-by: Basil Hess <[email protected]>
Signed-off-by: Basil Hess <[email protected]>
@SWilson4
Copy link
Member

SWilson4 commented Nov 8, 2024

Thanks for making the fix, @rtjk! I suggest that we hold merge for #1960 so that the s390x tests run on this PR. Perhaps you could rebase on @bhess's branch for that PR for now in case there are CI errors that need to be resolved (e.g., due to a gcc or clang version).

@rtjk rtjk force-pushed the CROSS-fix-endianness branch from 0d5b3e6 to d29be80 Compare November 8, 2024 16:20
@rtjk rtjk requested a review from SWilson4 as a code owner November 8, 2024 16:20
@rtjk rtjk force-pushed the CROSS-fix-endianness branch from d29be80 to 46e8b2a Compare November 8, 2024 16:24
@rtjk
Copy link
Contributor Author

rtjk commented Nov 8, 2024

@SWilson4 I rebased on branch bhe-reenable-travis and turned s390x back on for CROSS. It looks like Travis is running.

@rtjk
Copy link
Contributor Author

rtjk commented Nov 8, 2024

Ouch! It still failed ... time to debug some more.

@SWilson4
Copy link
Member

SWilson4 commented Nov 8, 2024

Ouch! It still failed ... time to debug some more.

FYI, looks like the s390x build uses gcc 9—does this older version support all the features you're using?

@rtjk
Copy link
Contributor Author

rtjk commented Nov 9, 2024

It turns out there were a few more instances where type punning was used, causing an endianness issue. I've fixed these, so Travis CI should now pass. I also added two lines to copy_from_upstream.py to create template files if they aren’t already in place. Is this okay?

Copy link
Member

@baentsch baentsch left a comment

Choose a reason for hiding this comment

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

I also added two lines to copy_from_upstream.py to create template files if they aren’t already in place. Is this okay?

Thanks for highlighting this @rtjk ! I don't think this is a good approach: Missing files in code generation imo are indicative of an incorrect code base and should lead to an error condition triggering a proper fix (manually adding the file(s) in question): Reason for my caution is that the code generation is so central to the proper operation of liboqs that I'm very wary of too much automation in this area.

@baentsch baentsch dismissed their stale review November 9, 2024 15:13

Automated template file generation removed: Thanks @rtjk!

Copy link
Member

@baentsch baentsch 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 fix @rtjk. I can't claim to have read all changes but defer to the tests passing as this code being OK: As with all core crypto code in liboqs the ultimate responsibility for correctness is with the upstream. Allow me to ask the question when/whether this code is going to flow upstream again (such as to get rid of the various "fix" statements in the version)?

Copy link
Member

@bhess bhess 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 update @rtjk!

@rtjk
Copy link
Contributor Author

rtjk commented Nov 11, 2024

Allow me to ask the question when/whether this code is going to flow upstream again (such as to get rid of the various "fix" statements in the version)?

The plan is to release a new version of CROSS before moving on to NIST's second round (deadline January 17, 2025). This will consolidate all the changes we made since CROSS 1.2.

Copy link
Member

@SWilson4 SWilson4 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 fix @rtjk!

@SWilson4 SWilson4 merged commit 1dfb70b into open-quantum-safe:main Nov 11, 2024
67 checks passed
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.

CROSS KAT failures / potential endianness issue
4 participants