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

feat: add SHAKE hash generator interfaces #27

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

st1020
Copy link
Contributor

@st1020 st1020 commented Jul 5, 2024

Thank you for your amazing work.

I noticed that in versions before 1.4.0, there used to be experimental functions called shake256generator and shake128generator for generating infinite-length hashes.

I think these two interfaces are very useful and necessary, especially for cryptography, so this PR hopes to restore them.

A typical application scenario is to generate high-quality random integers in a specified range. If I want the distribution to be as uniform as possible, it is best to use rejection sampling, and an infinite-length hash is very useful. The difference from using random directly is that I can use bytes as a seed, and the algorithm is standardized, so it can be easily reproduced in different languages.

@dipu-bd
Copy link
Member

dipu-bd commented Jul 6, 2024

Thank you for the effort to send a PR. I am particularly fond of this project and contributing whenever I can in my free time.

I recently made a release that improves support for the random generation. Keccak generator is included there too. Please check out the latest changes and let me know your thoughts.

@st1020
Copy link
Contributor Author

st1020 commented Jul 8, 2024

I checked the latest commit. But I still think this interface is necessary.

As I said before, in the field of random number generation, the difference between using an infinite-length hash and using random directly is that it can use bytes instead of numbers as seeds, and the SHAKE algorithm is standardized, so it can be easily reproduced in different languages.

In addition, an infinite-length hash is also very useful in the design of other cryptographic algorithms.

SHAKE in other languages ​​also often comes with an interface for generating infinite-length hashes, such as Rust sha3 crate and Python PyCryptodome library.

Adding this interface does not require much work and maintenance cost, so I think such an interface should be added. Please tell me what you think.

@dipu-bd
Copy link
Member

dipu-bd commented Jul 11, 2024

In addition, an infinite-length hash is also very useful in the design of other cryptographic algorithms.

Since a infinte loop can be easily generated from the user side, I had removed the implementation of this special case. But it is good to have in the library itself.

I have modified your PR a little bit. Instead of adding generate method in the KeccakRandom itself, I moved it to the public generator methods.

@dipu-bd dipu-bd merged commit e963acf into bitanon:master Jul 11, 2024
1 check passed
@st1020
Copy link
Contributor Author

st1020 commented Jul 11, 2024

Thanks for merging the PR. :)

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