feat: implement constant time equality checks#12
Conversation
Bug Report
Comments? Email us. |
| return result === 0; | ||
| } | ||
|
|
||
| export async function safeEqual(a: string, b: string): Promise<boolean> { |
There was a problem hiding this comment.
The goal of this library is to be runtime-agnostic and just web APIs. Importing crypto here would break that, and using Buffer.from would break it as well
There was a problem hiding this comment.
i can remove the code that tries to use crypto.timingSafeEqual and we can just use the JS only implementation.
Bug Report
Comments? Email us. |
Bug Report
Comments? Email us. |
Bug Report
Comments? Email us. |
| const bBytes = new TextEncoder().encode(b); | ||
|
|
||
| let len = Math.max(aBytes.length, bBytes.length); | ||
| let result = BigInt(aBytes.length ^ bBytes.length); |
There was a problem hiding this comment.
Why do we need bigint here? I think the number is enough?
There was a problem hiding this comment.
i did that to fix this warning by the ai #12 (comment)
There was a problem hiding this comment.
Yeah, I feel like the API is unnecessary. Like #12 (comment) said.
Since this is a library for the web... but you know, there's no need for security on the web
|
Oh, I didn't know we had |
This PR implements support for constant time equality checks that don't leak information, via early exits. It defaults to
crypto.timingSafeEqualif it is available, if not it will default to a JS implementation of constant time equality check.