-
Notifications
You must be signed in to change notification settings - Fork 197
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
Improve API for hash2curve functions #876
Improve API for hash2curve functions #876
Conversation
I came up with three solutions how to remove the
I'm leaning towards the second solution, it seems to be the friendliest one for the user. |
d24d2ac
to
681f375
Compare
681f375
to
3ff40ab
Compare
This seems like an improvement to me but with the caveat I haven't carefully read the spec |
https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-08.html#section-3.3.1.1-1 |
I implemented the second solution, as explained above, for removing the |
I just realized, one solution could be to remove the whole |
613cdc2
to
898cc71
Compare
898cc71
to
ab64ed3
Compare
I decided to revert this, there is no real advantage and the current |
I'm a bit unclear what lifetime relationship the (Of course, I don't understand the impetus for the original |
The issue arises when you want to implement a spec that requires different To be more specific, VOPRF requires a different impl VoprfParameters for NistP256 {
const ID: u16 = 0x0003;
type Hash = sha2::Sha256;
}
// https://www.ietf.org/archive/id/draft-irtf-cfrg-voprf-08.html#appendix-A-6
fn derive_key_pair<G: VoprfParameters, H: Digest>(seed: &[u8]) -> ... {
// contextString = "VOPRF08-" || I2OSP(modeBase, 1) || I2OSP(suite.ID, 2)
let context_string = concat!("VOPRF-08", 0, G::ID);
// skS = GG.HashToScalar(seed, DST = "HashToScalar-" || contextString)
let sk_s = NistP256::hash_to_scalar::<ExpandMsgXmd<H>>(seed, context_string)?;
...
} This will fail, because As for the EDIT: I attempted, but it wasn't possible. I hope this clears up any questions. Please hit me up if there is anything unclear. |
If the lifetime is a big issue, I could go back to the solution of removing the |
Yeah, that's not going to work without a heap allocation. The alternative IMO would be to have an
But that should only require a lifetime on |
I thought so too, but couldn't make it work sadly. Feel free to try. |
Aah I see, you need the lifetime for the associated |
@mikelodder7 any thoughts on this? |
The lifetime is solely for the dst. I put it as static so I wouldn’t have to copy the dst to a GenericArray of a fixed size less than 255. If we can somehow manage the lifetime without static then great but it pollutes all interfaces when ExpandMsgXof doesn’t even need it. If we had a heap then you could just convert to Vec and be done. |
It seems we’re “crossing the streams” with voprf and hash2curve with multiple args but I guess it’s probably okay for now |
data
/msg
s by using&[&[u8]]
, á laHkdf::expand_multi_info()
.hash_to_scalar
, got an implementation for P-256 already working with test vectors.'static
requirement fordst
.Maybe we don't want
hash_to_scalar
onGroupDigest
, because it also pulls in arithmetic for no real reason.The goal here is to make this usable for voprf. VOPRF sometimes builds complex
msg
s that are impossible to concat without allocation, this is why the multi-message API was necessary. I would even prefer just to take anIterator<Item = &[u8]>
.The
'static
requirement doesn't work for VOPRF because it needs to build thedst
from multiple parts that are party derived from associated types from traits, this can't be used in const to build a&'static [u8]
in Rust right now.CC @tarcieri @mikelodder7