What is tsscmp?
The tsscmp npm package is a utility for performing timing-safe string comparisons. This is particularly useful for security purposes, such as comparing cryptographic hashes or passwords, to prevent timing attacks.
What are tsscmp's main functionalities?
Timing-Safe String Comparison
This feature allows you to compare two strings in a way that is resistant to timing attacks. The comparison takes the same amount of time regardless of how similar the strings are, which helps to prevent attackers from gaining information based on the time it takes to compare the strings.
const tsscmp = require('tsscmp');
const a = 'password123';
const b = 'password123';
if (tsscmp(a, b)) {
console.log('Strings are equal');
} else {
console.log('Strings are not equal');
}
Other packages similar to tsscmp
safe-compare
The safe-compare package provides a similar functionality to tsscmp by performing timing-safe string comparisons. It ensures that the comparison takes a constant amount of time, regardless of the input strings, thereby preventing timing attacks. Compared to tsscmp, safe-compare offers a similar API and is also focused on security.
secure-compare
The secure-compare package is another alternative for timing-safe string comparisons. It is designed to be simple and efficient, ensuring that the comparison time is constant to mitigate timing attacks. Like tsscmp, secure-compare is used to securely compare sensitive strings such as passwords or tokens.
Timing safe string compare using double HMAC
Prevents timing attacks using Brad Hill's
Double HMAC pattern
to perform secure string comparison. Double HMAC avoids the timing atacks by blinding the
timing channel using random time per attempt comparison against iterative brute force attacks.
Install
npm install tsscmp
Why
To compare secret values like authentication tokens, passwords or
capability urls so that timing information is not
leaked to the attacker.
Example
var timingSafeCompare = require('tsscmp');
var sessionToken = '127e6fbfe24a750e72930c';
var givenToken = '127e6fbfe24a750e72930c';
if (timingSafeCompare(sessionToken, givenToken)) {
console.log('good token');
} else {
console.log('bad token');
}
##License:
MIT
Credits to: @jsha |
@bnoordhuis |
@suryagh |