paulmillr / noble-curves

Audited & minimal JS implementation of elliptic curve cryptography.
https://paulmillr.com/noble
MIT License
691 stars 63 forks source link

Documenting the expected behavior when one of the inputs is zero for batchInvert #17

Closed kevaundray closed 1 year ago

kevaundray commented 1 year ago

The current behavior when a value is 0 in batchInvert is to return undefined for that element. It would be good to document this behavior on top of the batchInvert method.

kevaundray commented 1 year ago

It also seems that the non batched version of invert will panic on zero, if I'm understanding correctly:

  if (number === _0n || modulo <= _0n) {
    throw new Error(`invert: expected positive integers, got n=${number} mod=${modulo}`);
  }
paulmillr commented 1 year ago

Document where?

paulmillr commented 1 year ago

It's reasonable. It should be undefined or error since inverse doesn't exist.

kevaundray commented 1 year ago

Right, I'm not commenting on whether it's reasonable, just that it would be good to have it documented, preferably on top of the function?

Though as commented above, batchInvert and Invert seem to have different behaviour on zero, what was the rationale behind this?

paulmillr commented 1 year ago

Though as commented above, batchInvert and Invert seem to have different behaviour on zero, what was the rationale behind this?

Performance reasons and easier testing

paulmillr commented 1 year ago

done