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

Add Sha3 SHAKE* #311

Closed
DougAnderson444 opened this issue May 26, 2023 · 12 comments
Closed

Add Sha3 SHAKE* #311

DougAnderson444 opened this issue May 26, 2023 · 12 comments

Comments

@DougAnderson444
Copy link

References

Rust-multihash almost got it here: #6
JS-multiformats has it here: https://github.com/multiformats/js-sha3/tree/ab7efd0fb1da9458c80977c5252cf941e7fe62eb#usage
Crates.io has it available here: https://docs.rs/sha3/0.10.8/sha3/

Drivers

Needed for BLS12-381 hash-to-curve and interop with JS implementers.

@vmx
Copy link
Member

vmx commented May 30, 2023

The currently released rust-multihash version, is kind of "catch all" for all sorts of hash function. Current master has already split things into smaller pieces. In theory it should be possible to implement other hash functions outside of this crate an integrate it in your own custom code table.

If anyone wants to give it a try, that would be great. If there are then issues, I'm happy to help.

@DougAnderson444
Copy link
Author

I can give that a try, but would that mean I need to also assign a code for Sha3 SHAKE128 and Sha3 SHAKE256? What would that do for interoperability if there are multiple implementations... with potentially different codes?

Also, if I do need to pick a code, should I just keep going with the Sha3 sequence (0x18, 0x19...)

@thomaseizinger
Copy link
Contributor

I can give that a try, but would that mean I need to also assign a code for Sha3 SHAKE128 and Sha3 SHAKE256? What would that do for interoperability if there are multiple implementations... with potentially different codes?

Also, if I do need to pick a code, should I just keep going with the Sha3 sequence (0x18, 0x19...)

Code assignment should happen in the multicodec repository: https://github.com/multiformats/multicodec

@DougAnderson444
Copy link
Author

@thomaseizinger
Copy link
Contributor

@thomaseizinger absolutely of course. Plus, they already exist!

multiformats/multicodec@df81972/table.csv#L15-L16

Then all that is needed is an implementation :)

In the simplest case, you can construct a Multihash with the correct code and the hashed digest. See https://github.com/multiformats/rust-multihash/pull/289/files#diff-b3696301e6450e80cb6418ed8cf625a5db0a2cd4acf9e4d2e446b00fef092b72R20 for example.

Note that we have heavily restructured this repository to make the base data structure nearly dependency free. This is not released yet but hopefully soon.

@DougAnderson444
Copy link
Author

Sounds amazing! The goods news is for Shake, no additional dependencies are required we already have sha3. Just need a slightly modified macro, which I've already built 🚀. Happy to request a pull if you want to take on another one of my PRs...

@thomaseizinger
Copy link
Contributor

Sounds amazing! The goods news is for Shake, no additional dependencies are required we already have sha3. Just need a slightly modified macro, which I've already built 🚀. Happy to request a pull if you want to take on another one of my PRs...

Would you like to see it in multihash-codetable? I am ambivalent :)

@DougAnderson444
Copy link
Author

That is what I was originally thinking, yes. But perhaps it's unnecessary. Here's what I've been able to do outside the library without any changes:

https://github.com/DougAnderson444/shake-multihash

The Shake derive macro I wrote is pretty close to derive_rustcrypto_hasher, but the thing about SHAKE is the user is supposed to be able to pick their digest length, so the library needs to export the macro to be able to support that.

Maybe just leave it for now, if the crowds want it integrated badly it's straightforward to upgrade.

@vmx
Copy link
Member

vmx commented Jun 1, 2023

@DougAnderson444 oh wow, this is nice! I actually would prefer keeping it outside of multihsah-codetable as it nicely shows, how people can add their own hash functions to the ecosystem. I'll probably keep people pointing to that repo, if anyone requests adding a new hash function.

It's so great to see the library being used as imagined. Thanks!

@thomaseizinger
Copy link
Contributor

@DougAnderson444 Relating to https://github.com/DougAnderson444/shake-multihash/blob/9cbd3b09272f5053d241afa9ea775692048f5bfe/src/lib.rs#L19-L20, in case you didn't know, this also works:

pub const SHAKE_128_HASH_CODE: u64 = 0x18;

@thomaseizinger
Copy link
Contributor

I think we can close this then? :)

@DougAnderson444
Copy link
Author

Yep! Thanks for the feedback gents, this helped a lot.

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

No branches or pull requests

3 participants