[SECURITY] Timing leaks in lib/native/bn.js
- Dominant language
- JavaScript
- Stars
- 102
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
* Branching timing leaks
* https://github.com/bcoin-org/bcrypto/blob/b73dbc69884ecc790864e8ac513d627cdb0318d7/lib/native/bn.js#L3556
* https://github.com/bcoin-org/bcrypto/blob/b73dbc69884ecc790864e8ac513d627cdb0318d7/lib/native/bn.js#L3435
* powm leaks the value of `e`
* https://github.com/bcoin-org/bcrypto/blob/b73dbc69884ecc790864e8ac513d627cdb0318d7/lib/native/bn.js#L3869-L3897
* https://github.com/bcoin-org/bcrypto/blob/b73dbc69884ecc790864e8ac513d627cdb0318d7/lib/native/bn.js#L3889-L3893
* (This also breaks any modular inversion that relies on [`fermat()`](https://github.com/bcoin-org/bcrypto/blob/b73dbc69884ecc790864e8ac513d627cdb0318d7/lib/native/bn.js#L3812))
I wrote a library that implements [constant-time algorithms in TypeScript](https://github.com/soatok/constant-time-js) if you want to mitigate these risks.
Further reading: [[1]](https://soatok.blog/2020/08/27/soatoks-guide-to-side-channel-attacks/) [[2]](https://github.com/veorq/cryptocoding)
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in lib/native/bn.js at the branching locations around lines 3435 and 3556, then inspect powm around lines 3869-3897 and fermat around line 3812. Compare the affected operations with the linked constant-time TypeScript library and ensure the reported timing leaks, including modular inversion through fermat(), are addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- cryptography, security
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100