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

ExpandMsg improvements #874

Merged
merged 7 commits into from
Jan 7, 2022

Conversation

daxpedda
Copy link
Contributor

@daxpedda daxpedda commented Jan 7, 2022

Follow-up for #400.

  • Prevent overflows and add zero check.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

So should we make hash_from_bytes and encode_from_bytes infallible?
#871 (comment)

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

Some outstanding issues:

  • Updating to digest 0.10.
  • Make hash_to_field publicly accessible.

We can merge this and make separate PR's for each or handle it here. Are there any other unresolved questions @tarcieri @mikelodder7?

@tarcieri
Copy link
Member

tarcieri commented Jan 7, 2022

Updating to digest 0.10.

This is going to be a pretty big effort and needs to happen in a coordinated way across not only elliptic-curve but also ecdsa and k256/p256. It will require a major version bump of all of these crates and I'm still working on getting all of the downstream dependencies of these crates I maintain updated to the latest releases.

I did the first step of cutting a new signature release which bumps to digest v0.10 but updating everything else is going to be a lot of work.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

That's alright, we will do this later then. The remaining issue is hash_to_field then. Any suggestions on what to do? I was actually thinking of adding it to GroupDigest and letting it return a Scalar, which should solve the problem.

@tarcieri
Copy link
Member

tarcieri commented Jan 7, 2022

Isn't hash_to_field primarily intended to hash an input message to elements of the base field?

Are there valid use cases (interop?) for hash-to-scalar that make it a better choice than the existing Reduce trait?

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

Implementing VOPRF requires calling hash_to_field:
https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-08.html#section-4.3-1.1.2.2

@tarcieri
Copy link
Member

tarcieri commented Jan 7, 2022

Okay, well if it's needed for interop I'd be fine with a public hash_to_scalar function, but I think it should be called that and not hash_to_field, to avoid confusion with the base field

@tarcieri
Copy link
Member

tarcieri commented Jan 7, 2022

Also VOPRF seems like the sort of thing that probably belongs in the respective RustCrypto/elliptic-curves crates?

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

... but I think it should be called that and not hash_to_field, to avoid confusion with the base field

Sounds good to me.

Also VOPRF seems like the sort of thing that probably belongs in the respective RustCrypto/elliptic-curves crates?

Yes, we just need a trait we can be generic over.

@mikelodder7
Copy link
Contributor

hash_to_scalar would be just a convenience wrapper for Digest output to 64 bytes then calling Reduce. I wouldn't usehash_to_field for this purpose since it does a more complex mixing of bytes than is necessary for that purpose.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

Well I have to name it something 😄. Preferable I would like to stick with hash_to_field as this is what it's called in the spec, but I understand @tarcieri concern. I will just name it hash_to_scalar for now and let you guys hash it out 😉.

@mikelodder7
Copy link
Contributor

Well I have to name it something 😄. Preferable I would like to stick with hash_to_field as this is what it's called in the spec, but I understand @tarcieri concern. I will just name it hash_to_scalar for now and let you guys hash it out 😉.

Dalek uses the name hash_from_bytes. That could work.

@tarcieri
Copy link
Member

tarcieri commented Jan 7, 2022

hash_to_scalar would be just a convenience wrapper for Digest output to 64 bytes then calling Reduce. I wouldn't usehash_to_field for this purpose since it does a more complex mixing of bytes than is necessary for that purpose.

And that's what's already provided by these methods on Reduce (added in #869):

Screen Shot 2022-01-07 at 7 53 16 AM

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

Maybe it would be better to actually codify that comment?

I left the comment to explain why this can't fail nonetheless.

Dalek uses the name hash_from_bytes. That could work.

I agree with @tarcieri, it's not the same, and already provided.

@mikelodder7
Copy link
Contributor

Yep that's just fine the way it is

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Looks good now!

@mikelodder7 WDYT?

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

I'm a bit busy with something else right now, still adding the other test vectors. But feel free to merge if you like to.

@tarcieri
Copy link
Member

tarcieri commented Jan 7, 2022

Not in a hurry. Feel free to push some more changes.

@mikelodder7
Copy link
Contributor

Looks good now!

@mikelodder7 WDYT?

I think it works for now once all the checks are cleared. Some minor nits that I can make after this merge.

@daxpedda
Copy link
Contributor Author

daxpedda commented Jan 7, 2022

This is good to go.

It seems I am out of my depth when it comes to how to implement hash_to_scalar, any guidance is welcome, in the meantime I will do more research.

Copy link
Member

@tarcieri tarcieri left a comment

Choose a reason for hiding this comment

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

Looks good!

@tarcieri tarcieri merged commit 67960c2 into RustCrypto:master Jan 7, 2022
@tarcieri tarcieri mentioned this pull request Jan 14, 2022
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.

3 participants