-
Notifications
You must be signed in to change notification settings - Fork 477
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
Poor Scalar performance #507
Comments
I'm curious if there are actually good use cases for Also curious what overhead using bytes as the internal "packed" representation of a scalar might be adding (if any) or if it impacts LLVM inlining ( |
Beyond x25519, which I can't comment on, I think the remaining concern may be how the Group API requires the modulus as a Scalar (not just via char_le_bits), which requires unreduced Scalars as a possibility. |
It doesn't though? For
(note: there's that on the But beyond that there's nothing that requires an unreduced |
... you are right. I've even implemented 0.13 into my own libs. I have no idea why I thought it did that. Sorry. |
BASEPOINT_ORDER also currently exists as a way to access an unreduced Scalar. |
Indeed. Wonder if that could be made private at least. |
Clamping makes the given scalar a multiple of 8, so we'd definitely still need to expose |
Considering the order of the points actually generatable from G is If x25519 does have breaking behavior, I'd note that anything expecting those bits to not be cleared (or reduced out) could be shimmed by a function which clears the bits, performs the scalarmul, and then for the set bits, adds the relevant point from https://docs.rs/curve25519-dalek/latest/curve25519_dalek/constants/constant.EIGHT_TORSION.html. Accordingly, while an API breaking change, it'd still be possible to provide a safe, always % l, Scalar API that still acknowledges/supports all use cases. |
Was this addressed by #519? |
I'd assume so. @rozbb noted the performance benefits of their PR. |
Ok I'll close for now. @kayabaNerve if you end up running some benchmarks against other scalar impls and find that ours is noticeably worse, feel free to re-open. Thanks! |
dalek scalars are about 10x as inperformant as k256 Scalars, for both addition and multiplication, according to some recent benchmarking I had performed. While that isn't a fair comparison, one being curve25519 and one being secp256k1, it is a striking difference that shows something is likely going on with dalek's impl. The following block of code was pointed out to me as the likely culprit:
curve25519-dalek/src/scalar.rs
Lines 367 to 375 in b2d0f0e
Would it be possible to expose an addition which does not hedge against the potential use of an API in existence for x25519, greatly accelerating Ed25519 operations? Potentially a distinct ReducedScalar type entirely?
The text was updated successfully, but these errors were encountered: