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

fix Point.prototype.toJSON for short curves #188

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mvayngrib
Copy link

thanks @fanatid for helping me look into this

@fanatid
Copy link
Contributor

fanatid commented Aug 13, 2019

Short explanation:

p192, p224, curve25519, ed25519, secp256k1 use Base reduction engine
p256, p384, p521 use Montgomery method engine

BN-Red for curve created at https://github.com/indutny/elliptic/blob/v6.5.0/lib/elliptic/curve/base.js#L14

On serialization BN#toJSON called without checking red existence: https://github.com/indutny/bn.js/blob/v5.0.0/lib/bn.js#L529-L531

While Base reduction engine call just remove red property: https://github.com/indutny/bn.js/blob/v5.0.0/lib/bn.js#L3386-L3390

Montgomery method engine makes manipulations: https://github.com/indutny/bn.js/blob/v5.0.0/lib/bn.js#L3422-L3426

As result if point with Montgomery method will be serialized result will not be same on deserialization.

@jprichardson
Copy link

@indutny @fanatid can we get this merged? Anything more we can help with to move this forward?

@fanatid
Copy link
Contributor

fanatid commented Sep 10, 2019

LGTM

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