Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ build: off
version: '{build}'
environment:
matrix:
- nodejs_version: '10'
- nodejs_version: '8'
- nodejs_version: '6'
- nodejs_version: Stable
- nodejs_version: 12.0.0
platform:
- x86
- x64
Expand All @@ -21,5 +20,3 @@ test_script:
- node -e "console.log('RAM:', require('os').totalmem().toLocaleString(), 'bytes')"
- node -e "console.log('CPU:', require('os').cpus().length, 'x', require('os').cpus()[0].model)"
- npm test
after_test:
- npx codecov
40 changes: 40 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: 2
jobs:
build_12.0.0:
docker:
- image: 'circleci/node:12.0.0'
working_directory: ~/app
steps:
- checkout
- restore_cache:
keys:
- 'v2-dependencies-{{ checksum "package.json" }}'
- v2-dependencies-
- run: npm install
- save_cache:
paths:
- node_modules
key: 'v2-dependencies-{{ checksum "package.json" }}'
- run: npm test
build_latest:
docker:
- image: 'circleci/node:latest'
working_directory: ~/app
steps:
- checkout
- restore_cache:
keys:
- 'v1-dependencies-{{ checksum "package.json" }}'
- v1-dependencies-
- run: npm install
- save_cache:
paths:
- node_modules
key: 'v1-dependencies-{{ checksum "package.json" }}'
- run: npm test
workflows:
version: 2
workflow:
jobs:
- build_12.0.0
- build_latest
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

24 changes: 0 additions & 24 deletions .travis.yml

This file was deleted.

23 changes: 11 additions & 12 deletions bench.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,55 +18,54 @@ async function bench(hpass, vpass, options) {
Promise.resolve()
// Default configs
.then(() => bench('r9(yaV@L', 'r9(yaV@L'))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})

// Custom Iterations
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {iterations: 5}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {iterations: 10}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {iterations: 25}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {iterations: 50}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {iterations: 100}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})

// Custom Memory
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {memory: 2 ** 14}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {memory: 2 ** 16}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})
.then(() => bench('r9(yaV@L', 'r9(yaV@L', {memory: 2 ** 18}))
.then(results => {
.then((results) => {
console.log('► CMD:', results.cmd);
console.log(results.stdout);
})

.catch(err => {
console.error(err);
.catch((error) => {
console.error(error);
});
32 changes: 24 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable capitalized-comments,complexity,prefer-destructuring */
/* eslint-disable capitalized-comments,complexity,prefer-destructuring,promise/prefer-await-to-then,unicorn/prevent-abbreviations */
'use strict';

const argon2 = require('argon2');
Expand Down Expand Up @@ -93,6 +93,7 @@ function hash(password, options) {
new TypeError("The 'iterations' option must be an integer")
);
}

if (iterations < 1 || iterations > MAX_UINT32) {
return Promise.reject(
new TypeError(
Expand All @@ -107,6 +108,7 @@ function hash(password, options) {
new TypeError("The 'parallelism' option must be an integer")
);
}

if (parallelism < 1 || parallelism > MAX_UINT24) {
return Promise.reject(
new TypeError(
Expand All @@ -121,6 +123,7 @@ function hash(password, options) {
new TypeError("The 'memory' option must be an integer")
);
}

const minmem = 8 * parallelism;
if (memory < minmem || memory > MAX_UINT32) {
return Promise.reject(
Expand All @@ -136,6 +139,7 @@ function hash(password, options) {
new TypeError("The 'variant' option must be a string")
);
}

variant = variant.toLowerCase();
if (!Object.prototype.hasOwnProperty.call(variants, variant)) {
return Promise.reject(
Expand All @@ -154,7 +158,7 @@ function hash(password, options) {
);
}

return gensalt(saltSize).then(salt => {
return gensalt(saltSize).then((salt) => {
const params = {
version,
type: variants[variant],
Expand All @@ -164,7 +168,7 @@ function hash(password, options) {
salt,
raw: true
};
return argon2.hash(password, params).then(hash => {
return argon2.hash(password, params).then((hash) => {
const phcstr = phc.serialize({
id: `argon2${variant}`,
version,
Expand Down Expand Up @@ -194,8 +198,8 @@ function verify(phcstr, password) {
let phcobj;
try {
phcobj = phc.deserialize(phcstr);
} catch (err) {
return Promise.reject(err);
} catch (error) {
return Promise.reject(error);
}

// Identifier Validation
Expand All @@ -210,22 +214,26 @@ function verify(phcstr, password) {
new TypeError(`Incompatible ${phcobj.id} identifier found in the hash`)
);
}

if (!Object.prototype.hasOwnProperty.call(variants, idparts[1])) {
return Promise.reject(
new TypeError(`Unsupported ${idparts[1]} variant function`)
);
}

const variant = idparts[1];

// Version Validation
if (typeof phcobj.version === 'undefined') {
phcobj.version = versions[0]; // Old Argon2 strings without the version.
}
if (versions.indexOf(phcobj.version) === -1) {

if (!versions.includes(phcobj.version)) {
return Promise.reject(
new TypeError(`Unsupported ${phcobj.version} version`)
);
}

const version = phcobj.version;

// Parameters Existence Validation
Expand All @@ -240,13 +248,15 @@ function verify(phcstr, password) {
) {
return Promise.reject(new TypeError("The 't' param must be an integer"));
}

if (phcobj.params.t < 1 || phcobj.params.t > MAX_UINT32) {
return Promise.reject(
new TypeError(
`The 't' param must be in the range (1 <= t <= ${MAX_UINT32})`
)
);
}

const iterations = phcobj.params.t;

// Parallelism Validation
Expand All @@ -256,13 +266,15 @@ function verify(phcstr, password) {
) {
return Promise.reject(new TypeError("The 'p' param must be an integer"));
}

if (phcobj.params.p < 1 || phcobj.params.p > MAX_UINT24) {
return Promise.reject(
new TypeError(
`The 'p' param must be in the range (1 <= p <= ${MAX_UINT24})`
)
);
}

const parallelism = phcobj.params.p;

// Memory Validation
Expand All @@ -272,6 +284,7 @@ function verify(phcstr, password) {
) {
return Promise.reject(new TypeError("The 'm' param must be an integer"));
}

const minmem = 8 * phcobj.params.p;
if (phcobj.params.m < minmem || phcobj.params.m > MAX_UINT32) {
return Promise.reject(
Expand All @@ -280,18 +293,21 @@ function verify(phcstr, password) {
)
);
}

const memory = phcobj.params.m;

// Salt Validation
if (typeof phcobj.salt === 'undefined') {
return Promise.reject(new TypeError('No salt found in the given string'));
}

const salt = phcobj.salt;

// Hash Validation
if (typeof phcobj.hash === 'undefined') {
return Promise.reject(new TypeError('No hash found in the given string'));
}

const hash = phcobj.hash;
const keylen = phcobj.hash.byteLength;

Expand All @@ -306,7 +322,7 @@ function verify(phcstr, password) {
raw: true
};

return argon2.hash(password, params).then(newhash => {
return argon2.hash(password, params).then((newhash) => {
const match = tsse(hash, newhash);
return match;
});
Expand All @@ -318,7 +334,7 @@ function verify(phcstr, password) {
* @returns {string[]} A list of identifiers supported by this hashing function.
*/
function identifiers() {
return Object.keys(variants).map(variant => `argon2${variant}`);
return Object.keys(variants).map((variant) => `argon2${variant}`);
}

module.exports = {
Expand Down
Loading