https://github.com/commenthol/compare-timing-safe
String comparison in length constant time
https://github.com/commenthol/compare-timing-safe
Last synced: 4 months ago
JSON representation
String comparison in length constant time
- Host: GitHub
- URL: https://github.com/commenthol/compare-timing-safe
- Owner: commenthol
- License: unlicense
- Created: 2017-07-16T06:31:57.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-10-23T19:52:07.000Z (over 1 year ago)
- Last Synced: 2025-09-27T02:21:45.597Z (9 months ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/compare-timing-safe/)
[](https://github.com/commenthol/compare-timing-safe/actions/workflows/ci.yml?query=branch%3Amaster)
# compare-timing-safe
> String comparison in length constant time
Works in node and in the browser.
Node version uses `crypto` module.
### `timingSafeEqual(a, b)`
String, buffer comparison in length-constant time
**Example**
```js
import timingSafeEqual from 'compare-timing-safe'
const input = 'a'
const compareWith = 'bbbbbbbb'
timingSafeEqual(input, compareWith)
//> false
```
**Parameters**
| parameter | type | description |
| --------- | -------------- | ------------------------------------ |
| `a` | String, Buffer | String or buffer from input |
| `b` | String, Buffer | String or buffer to compare with `a` |
**Returns** `Boolean`, true if strings match
## Installation
Requires [nodejs](http://nodejs.org/).
```sh
$ npm install compare-timing-safe
```
## Tests
```sh
$ npm test
```
## License
Unlicense
## References
- [A lesson in timing attacks](https://codahale.com/a-lesson-in-timing-attacks/)