-
-
Notifications
You must be signed in to change notification settings - Fork 79
Separate get scalar function #183
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
Separate get scalar function #183
Conversation
Could you clarify your use case? |
One call of |
@kigawas what do you mean? |
How much of a performance gain are we talking about? A comparison before/after would be useful. If it's negligible then we're optimizing the wrong part. |
@paulmillr Around 2% performance improvement, and it reduces memory footprints as well (since we can save a call to I ran with Before (main branch)
After
After (another try)
|
@@ -537,6 +545,7 @@ export function twistedEdwards(curveDef: CurveType): CurveFn { | |||
G._setWindowSize(8); // Enable precomputes. Slows down first publicKey computation by 20ms. | |||
|
|||
const utils = { | |||
getPrivateScalar, |
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.
Is it necessary to expose it?
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.
That's a good question, I'd expose it for two reasons:
- In rust (ed25519-dalek) and go (standard library), user can get the exposed Scalar
- Currently we are already exposing
scalar
throughgetExtendedPublicKey
, with some extra calls
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.
I've decided to not expose it for now, because the lib needs to have feature parity with 4kb noble-ed25519. fromPrivateKey is still in though.
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.
I see. You can easily update it here when you're ready
https://github.com/paulmillr/noble-ed25519/blob/main/index.ts#L245
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.
Not really.
ed25519 does not support synchronous hashing out-of-box because it requires no deps. Curves, on the other hand, use noble-hashes.
Because of that, ed25519 provides two implementations: async (using built-in crypto.subtle) and sync (which requires connecting to hashing library first).
So utils will need TWO functions, not one. And it's already a mess with 2 getExtPubkey, 2 getPubkey, 2 sign, 2 verify, etc.
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.
I think we may need a better abstraction for the sync and async crypto just like @noble/ciphers/webcrypto
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.
yeah
Separate get scalar logic for
getExtendedPublicKey