-
Notifications
You must be signed in to change notification settings - Fork 551
curve25519-dalek: add batch montgomery conversion #722
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
curve25519-dalek: add batch montgomery conversion #722
Conversation
Seems like this could be implemented in an alloc-free manner using const generic arrays, although that would limit the input type to an array |
Agreed. It seems like it but it's a bit tricky. In the libsecp code we take an outptr for the result and during computation we abuse that as scratch space. But here our output is a bunch of I can give it a shot later today. |
Oh, I realize that in your suggestion I don't need to reuse space; I can have multiple on-stack arrays of the appropriate length. But if I do reuse space, then I could implement this by taking a |
Using const generics would allow you to return a same-sized array and avoids the runtime panic conditions |
If I use const generics I see a slight slowdown with a batch size of 128, as well as blowing up the user's stack space (and limiting the API). I don't know that this is worth making the function work in a no-alloc context. If I try to implement the outptr solution where the user passes a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The alloc
dependency is fine, I guess. Maybe it'd be nice to offer both that and an alloc
-free const generic version in the future.
Not sure how batch_to_montgomery
jives in terms of API consistency. The other public APIs put batch
at the end. Some bikeshedding/nit, but perhaps convert_batch_to_montgomery
would be better?
Would be nice if @rozbb could take a look and/or weigh in before merging
Thank you @apoelstra ! I took the liberty of simplifying the routine. We already have the Montgomery trick for batch field element inversion implemented, so I opted to just reuse that. Let me know if there's something I missed. Re naming, it's actually mixed 😞 :
That said, it's mostly I also added a reference in the function doc to point to If all is good, I'm happy to merge |
@rozbb nice, thanks for the cleanup! I didn't see the existing field batch-inversion method when I wrote this. I'm also happy with whatever names you all think are best. Happy to see this moving forward! |
This is useful for vanitygenning curve25519 keys. Unsure of other usecases.