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

little-endian constructor ignoring important zeroes #208

Closed
igormcoelho opened this issue Dec 4, 2018 · 8 comments · Fixed by #265
Closed

little-endian constructor ignoring important zeroes #208

igormcoelho opened this issue Dec 4, 2018 · 8 comments · Fixed by #265
Labels

Comments

@igormcoelho
Copy link

igormcoelho commented Dec 4, 2018

I noticed that constructor is ignoring important zeroes on little-endian constructor.
Example:

x = new BN('0000ff', 16, 'le')
<BN: ff>   // should be  <BN: ff0000>
x = new BN('010000ff', 16, 'le')
<BN: ff000001>
@amaury1093
Copy link

Same here:

new BN('0001000000000000', 'hex', 'le').toNumber()

Expected: 256
Got: 1

chjj added a commit to bcoin-org/bcrypto that referenced this issue Mar 28, 2019
@mahnunchik
Copy link

Hi, @indutny current version of bn.js completely ignores leading zeroes in le notation.

elliptic is effected to because it uses bn.js under hood: https://github.com/indutny/elliptic/blob/e71b2d9359c5fe9437fbf46f1f05096de447de57/lib/elliptic/utils.js#L115-L117

Example of incorrect multiplication:

const ec = new EdDSA('ed25519');
const k = ec.decodeInt('0000000000000000000000000000000000000000000000000000000000000001');
const K = elliptic.utils.encode(ec.encodePoint(ec.g.mul(k), 'hex'));

@fanatid
Copy link
Collaborator

fanatid commented Feb 19, 2021

I'll look into this shortly.

@mahnunchik
Copy link

I'm looking forward to have elliptic lib updated to use fixed bn.js 👀

@fanatid
Copy link
Collaborator

fanatid commented Feb 23, 2021

Released in 5.2.0

@mahnunchik
Copy link

I think https://github.com/indutny/elliptic should be updated to latest bn.js.

@fanatid
Copy link
Collaborator

fanatid commented Feb 23, 2021

Ah, I'll release 4.12.0 tomorrow for elliptic. Thanks that pointed on this!

@fanatid
Copy link
Collaborator

fanatid commented Feb 24, 2021

4.12.0 is published.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants