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

HashToCurve and Hasher: Add new() method #203

Open
ValarDragon opened this issue Nov 26, 2020 · 3 comments
Open

HashToCurve and Hasher: Add new() method #203

ValarDragon opened this issue Nov 26, 2020 · 3 comments

Comments

@ValarDragon
Copy link

ValarDragon commented Nov 26, 2020

The current HashToCurve / Hasher API's don't let one template over the Hash type. The issue at the moment is that the hash functions require operating on a struct instantiated elsewhere.

I suggest refactoring both of these to provide a new() -> Result<Self, Self::Error> API. The digest Trait, which allows for generalizing over cryptographic hash function, does something similar with just having a new() method.

I'm currently working on such a change, and would be happy to upstream it
EDIT: Its done in this branch (https://github.com/sikkatech/celo-bls-snark-rs/tree/make_hashes_have_new_fn ), sans for fixing the same doctests that are blocking #202

@kobigurk
Copy link
Collaborator

I like the idea in general a lot, though keep in mind the following (which was the main reason it was designed like this) - when instantiating a large BH hasher, we need to generate a lot of base points, which can take noticable time.

@ValarDragon
Copy link
Author

That makes sense. In those cases, I believe that we could make them return copies of a lazily evaluated singleton instance.

Another question is should the new() method take in the domain? I imagine in the general case, you can cache the work needed for domains / personalizations. (For instance if you set a personalization string to be the first block of what you hash.

@kobigurk
Copy link
Collaborator

That makes sense. In those cases, I believe that we could make them return copies of a lazily evaluated singleton instance.

Another question is should the new() method take in the domain? I imagine in the general case, you can cache the work needed for domains / personalizations. (For instance if you set a personalization string to be the first block of what you hash.

Yep, singleton instances might work here, which is similar to what we do now, but more explicitly.

About domain, I don't have a strong preference either way. In the use-cases I'm imagining this optimization would be hard to apply anyway.

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

2 participants