-
Notifications
You must be signed in to change notification settings - Fork 0
cxx/random.hh: use uint8_t for random stream enum #1
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
Conversation
This makes sense since Random::seed only uses 8 bits from the stream enum anyway (and having more bits for stream numbers wouldn't make it "more secure"). Signed-off-by: Stefan Westerfeld <[email protected]>
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.
Summary of Changes
Hello @swesterfeld, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request introduces a targeted optimization to the Random::Stream enum definition within cxx/random.hh. The primary goal is to reduce the memory footprint and improve the clarity of the enum by aligning its underlying data type and member values with its actual usage requirements.
Highlights
- Enum Type Optimization: The underlying type of the
Random::Streamenum incxx/random.hhhas been changed fromuint32_ttouint8_t. This change is made because theRandom::seedfunction only utilizes 8 bits from the stream enum, making a 32-bit type unnecessarily large and not contributing to security. - Enum Value Simplification: The hexadecimal values assigned to the
Random::Streamenum members (wm_pattern,wm_mask,wm_convcode,img_comment) have been replaced with simple, sequential integer values (1, 2, 3, 4). This improves readability and aligns with the newuint8_tunderlying type.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
The pull request correctly identifies that the Random::Stream enum only requires 8 bits and changes its underlying type from uint32_t to uint8_t. However, the new enum values introduce a critical breaking change, as they will alter the generated random streams, making existing watermarks unreadable. My review includes a suggestion to preserve the original behavior by using the lower 8 bits of the old enum values, thus making the change safe and backward-compatible.
| wm_pattern = 1, | ||
| wm_mask = 2, | ||
| wm_convcode = 3, | ||
| img_comment = 4, |
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.
Changing the enum values will alter the generated pseudo-random sequences. This is a critical breaking change that will prevent watermarks created with older versions of this tool from being read correctly.
The Random::seed function was already using only the lower 8 bits of the Stream enum value by casting it to uint8_t.
To maintain backward compatibility, I suggest using the lower 8 bits of the original uint32_t values.
The original values and their lower 8 bits are:
wm_pattern:0xe58eb537->0x37wm_mask:0xfd19fc82->0x82wm_convcode:0x7ecf1f7a->0x7aimg_comment:0x7abcde01->0x01
These are all unique and would preserve the behavior of the random number generator, making this change non-breaking.
wm_pattern = 0x37,
wm_mask = 0x82,
wm_convcode = 0x7a,
img_comment = 0x01,
|
Thank you. |
This makes sense since Random::seed only uses 8 bits from the stream enum anyway (and having more bits for stream numbers wouldn't make it "more secure").