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

[util] Remove expand_seed routine. #24571

Merged
merged 1 commit into from
Sep 24, 2024

Conversation

jadephilipoom
Copy link
Contributor

This routine wasn't currently affecting the logic, but would have weakened certain seeds that happened to have low values. Ideally this should all be refactored to use byte strings so it's clearer what range the value is sampled from, but for now just removing the harmful logic should suffice.

log.error("ERROR: Seed shorter than 256 bits.")
sys.exit(1)

if seed.bit_length() < 250:
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is to fail %1 of the time whenever we change seeds, how do you feel about reporting an error instead? I think the Makefile output is too verbose, so there is a good chance this warning will be missed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's two issues:

  • Eliminating seeds below a certain lower bound would reduce the input distribution, so the actual seed would not be able to be fully randomly sampled. The loss in security bound is only marginal, but it's still not ideal; we want to sample from the full distribution of 0..2^256-1.
  • The DV setup always passes a 32-bit seed. It uses the command-line override, though, so we could error only if the value is from HJSON.

The fix for this that I prefer long-term is to:

  • make the values in the HJSON files byte-strings, so their length is easy to check and can include leading 0s, and error if the length is not exactly 32 bytes
  • add a command-line argument for "allow small seeds" so the DV setup can override the error

However, when I was trying to make bigger fixes to the PRNG and surrounding logic the change quickly became pretty big, so here I wanted to start with as narrow a hotfix as possible to remove the biggest issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @jadephilipoom, this explanation makes sense and I agree with your approach in this PR. Thanks for the additional details.

This routine wasn't currently affecting the logic, but would have weakened
certain seeds that happened to have low values. Ideally this should all be
refactored to use byte strings so it's clearer what range the value is sampled
from, but for now just removing the harmful logic should suffice.

Signed-off-by: Jade Philipoom <[email protected]>
@moidx
Copy link
Contributor

moidx commented Sep 19, 2024

LGTM

@jadephilipoom
Copy link
Contributor Author

jadephilipoom commented Sep 24, 2024

I confirmed that the single test that is failing is also failing on master with the same error (consistently and locally as well as on CI). Since it seems to be unrelated, I'll merge this now.

@jadephilipoom jadephilipoom merged commit 8cfe060 into lowRISC:master Sep 24, 2024
36 of 38 checks passed
@jadephilipoom jadephilipoom deleted the expand-seed-fix branch September 24, 2024 08:21
@timothytrippel timothytrippel added the CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0 label Oct 29, 2024
Copy link

Successfully created backport PR for earlgrey_1.0.0:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CherryPick:earlgrey_1.0.0 This PR should be cherry-picked to earlgrey_1.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants