-
Notifications
You must be signed in to change notification settings - Fork 41
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
[SECURITY] Timing leaks in lib/native/bn.js #57
Comments
Addendum: Lines 471 to 472 in 4db0fee
Leaking the exponent leaks the value of Leaking the hidden number lets you recover secret keys through simple algebra. EDIT: I'm tired so I keep missing tripping up on trying to describe the problem, but the solution is to harden against timing leaks. |
The javascript backend is not designed for side-channel silence. Bcrypto used to have some attempts at this, but realistically there is no way to ensure the code generated by a JS JIT is constant-time. It's hard enough to do in C, but (in my opinion) impossible to do in JS. There are a number of reasons for this:
To make my point further: return x < 0n ? -x : x; How do you know that is a branch? Perhaps it's a branch initially, but perhaps it gets transformed into a I do not believe your code can mitigate these risks (nor can my own). Personally, I think it is irresponsible to make guarantees about javascript code being side-channel resistant. The effective only mitigation I see for JS crypto implementations is blinding factors, which bcrypto does make use of (for signing). If you want side-channel silence, you should only use the native backend, which is constant-time for any function that handles secret data. This task is accomplished by libtorsion. See the ctgrind tests. In the future, we can look into compiling libtorsion to WASM, though it still remains to be seen whether the executed code would actually be side-channel resistant. edit: Fixed some links and typos. |
It's not really relevant given my last post, but just pointing out that this is incorrect as well. It uses k.mul(b).fermat(n); That line would be computed as The blinding factor is there to hopefully mask any future operations as well. |
bcrypto/lib/native/bn.js
Line 3556 in b73dbc6
bcrypto/lib/native/bn.js
Line 3435 in b73dbc6
e
bcrypto/lib/native/bn.js
Lines 3869 to 3897 in b73dbc6
bcrypto/lib/native/bn.js
Lines 3889 to 3893 in b73dbc6
fermat()
)I wrote a library that implements constant-time algorithms in TypeScript if you want to mitigate these risks.
Further reading: [1] [2]
The text was updated successfully, but these errors were encountered: