This commit is contained in:
Tutur33
2023-11-24 22:35:41 +01:00
parent 3c0b507a93
commit 7644b2a0f7
45165 changed files with 4803356 additions and 3 deletions
+344
View File
@@ -0,0 +1,344 @@
/* eslint-disable capitalized-comments,complexity,prefer-destructuring,promise/prefer-await-to-then,unicorn/prevent-abbreviations */
'use strict';
const argon2 = require('argon2');
const tsse = require('tsse');
const phc = require('@phc/format');
const gensalt = require('@kdf/salt');
const MAX_UINT32 = 4294967295; // 2**32 - 1
const MAX_UINT24 = 16777215; // 2**24 - 1
/**
* Default configurations used to generate a new hash.
* @private
* @type {Object}
*/
const defaults = Object.freeze({
// Argon2 variant to use. Can be one of argon2(d), argon2(i) or argon2(id).
variant: 'id',
// time cost, in linear iterations.
iterations: 3,
// memory cost, in kibibytes.
memory: 4096,
// parallelism, in number of threads and lanes.
parallelism: 1,
// The minimum recommended size for the salt is 128 bits.
saltSize: 16
});
/**
* Supported Argon2 variants.
* Argon2 currently has three modes:
* - d: Argon2d data-dependent.
* - i: Argon2i data-independent.
* - id: Argon2id a mix of the two.
* See https://crypto.stackexchange.com/a/49969
* @private
* @type {Object}
*/
const variants = Object.freeze({
i: argon2.argon2i,
d: argon2.argon2d,
id: argon2.argon2id
});
/**
* Supported Argon2 versions.
* @private
* @type {number[]}
*/
const versions = [
0x10, // 1.0 (16)
0x13 // 1.3 (19)
];
/**
* Computes the hash string of the given password in the PHC format using argon2
* package.
* @public
* @param {string} password The password to hash.
* @param {Object} [options] Optional configurations related to the hashing
* function.
* @param {number} [options.variant=id] Optinal variant of argon2 to use.
* Can be one of [`'d'`, `'i'`, `'id'`] for argon2d, argon2i and argon2id
* respectively.
* @param {number} [options.iterations=3] Optional number of iterations to use.
* Must be an integer within the range (`1` <= `iterations` <= `2^32-1`).
* @param {number} [options.memory=4096] Optional amount of memory to use in
* kibibytes.
* Must be an integer within the range (`8` <= `memory` <= `2^32-1`).
* @param {number} [options.parallelism=1] Optional degree of parallelism to
* use.
* Must be an integer within the range (`1` <= `parallelism` <= `2^24-1`).
* @param {number} [options.saltSize=16] Optional number of bytes to use when
* autogenerating new salts.
* Must be an integer within the range (`1` <= `saltSize` <= `2^10-1`).
* @return {Promise.<string>} The generated secure hash string in the PHC
* format.
*/
function hash(password, options) {
options = options || {};
let variant = options.variant || defaults.variant;
const iterations = options.iterations || defaults.iterations;
const memory = options.memory || defaults.memory;
const parallelism = options.parallelism || defaults.parallelism;
const saltSize = options.saltSize || defaults.saltSize;
const version = versions[versions.length - 1];
// Iterations Validation
if (typeof iterations !== 'number' || !Number.isInteger(iterations)) {
return Promise.reject(
new TypeError("The 'iterations' option must be an integer")
);
}
if (iterations < 1 || iterations > MAX_UINT32) {
return Promise.reject(
new TypeError(
`The 'iterations' option must be in the range (1 <= iterations <= ${MAX_UINT32})`
)
);
}
// Parallelism Validation
if (typeof parallelism !== 'number' || !Number.isInteger(parallelism)) {
return Promise.reject(
new TypeError("The 'parallelism' option must be an integer")
);
}
if (parallelism < 1 || parallelism > MAX_UINT24) {
return Promise.reject(
new TypeError(
`The 'parallelism' option must be in the range (1 <= parallelism <= ${MAX_UINT24})`
)
);
}
// Memory Validation
if (typeof memory !== 'number' || !Number.isInteger(memory)) {
return Promise.reject(
new TypeError("The 'memory' option must be an integer")
);
}
const minmem = 8 * parallelism;
if (memory < minmem || memory > MAX_UINT32) {
return Promise.reject(
new TypeError(
`The 'memory' option must be in the range (${minmem} <= memory <= ${MAX_UINT32})`
)
);
}
// Variant Validation
if (typeof variant !== 'string') {
return Promise.reject(
new TypeError("The 'variant' option must be a string")
);
}
variant = variant.toLowerCase();
if (!Object.prototype.hasOwnProperty.call(variants, variant)) {
return Promise.reject(
new TypeError(
`The 'variant' option must be one of: ${Object.keys(variants)}`
)
);
}
// Salt Size Validation
if (saltSize < 8 || saltSize > 1024) {
return Promise.reject(
new TypeError(
"The 'saltSize' option must be in the range (8 <= parallelism <= 1023)"
)
);
}
return gensalt(saltSize).then((salt) => {
const params = {
version,
type: variants[variant],
timeCost: iterations,
memoryCost: memory,
parallelism,
salt,
raw: true
};
return argon2.hash(password, params).then((hash) => {
const phcstr = phc.serialize({
id: `argon2${variant}`,
version,
params: {
t: iterations,
m: memory,
p: parallelism
},
salt,
hash
});
return phcstr;
});
});
}
/**
* Determines whether or not the hash stored inside the PHC formatted string
* matches the hash generated for the password provided.
* @public
* @param {string} phcstr Secure hash string generated from this package.
* @param {string} password User's password input.
* @returns {Promise.<boolean>} A boolean that is true if the hash computed
* for the password matches.
*/
function verify(phcstr, password) {
let phcobj;
try {
phcobj = phc.deserialize(phcstr);
} catch (error) {
return Promise.reject(error);
}
// Identifier Validation
const idparts = phcobj.id.split('2');
if (
idparts.length !== 2 ||
idparts[0] === '' ||
idparts[1] === '' ||
idparts[0] !== 'argon'
) {
return Promise.reject(
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.includes(phcobj.version)) {
return Promise.reject(
new TypeError(`Unsupported ${phcobj.version} version`)
);
}
const version = phcobj.version;
// Parameters Existence Validation
if (typeof phcobj.params !== 'object') {
return Promise.reject(new TypeError('The param section cannot be empty'));
}
// Iterations Validation
if (
typeof phcobj.params.t !== 'number' ||
!Number.isInteger(phcobj.params.t)
) {
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
if (
typeof phcobj.params.p !== 'number' ||
!Number.isInteger(phcobj.params.p)
) {
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
if (
typeof phcobj.params.m !== 'number' ||
!Number.isInteger(phcobj.params.m)
) {
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(
new TypeError(
`The 'm' param must be in the range (${minmem} <= m <= ${MAX_UINT32})`
)
);
}
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;
const params = {
version,
type: variants[variant],
timeCost: iterations,
memoryCost: memory,
parallelism,
salt,
hashLength: keylen,
raw: true
};
return argon2.hash(password, params).then((newhash) => {
const match = tsse(hash, newhash);
return match;
});
}
/**
* Gets the list of all identifiers supported by this hashing function.
* @public
* @returns {string[]} A list of identifiers supported by this hashing function.
*/
function identifiers() {
return Object.keys(variants).map((variant) => `argon2${variant}`);
}
module.exports = {
hash,
verify,
identifiers
};
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017-2018 Simone Primarosa
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+92
View File
@@ -0,0 +1,92 @@
{
"version": "1.1.4",
"name": "phc-argon2",
"description": "Node.JS Argon2 password hashing algorithm following the PHC string format",
"license": "MIT",
"homepage": "https://github.com/thetutlage/phc-argon2#readme",
"keywords": [
"brute",
"brute force",
"credential",
"credential-plus",
"crypto",
"hash",
"function",
"hashing",
"password",
"password-argon2",
"passwords",
"pbkdf",
"argon2",
"argon2-password",
"psswrd",
"pswd",
"rainbow",
"safe",
"safe",
"salt",
"secure",
"security",
"stretching",
"strong",
"timining",
"attack",
"verification",
"verify"
],
"main": "index.js",
"files": [
"index.js"
],
"engines": {
"node": ">=12"
},
"scripts": {
"bench": "node bench.js",
"test": "xo && nyc ava",
"release": "np",
"update": "npm-check -u"
},
"publishConfig": {
"access": "public"
},
"dependencies": {
"@kdf/salt": "^2.0.1",
"@phc/format": "^1.0.0",
"argon2": "^0.30.2",
"tsse": "^2.0.0"
},
"devDependencies": {
"ava": "^4.0.1",
"execa": "^5.1.1",
"np": "^7.6.2",
"npm-check": "^5.9.2",
"nyc": "^15.1.0",
"sympact": "^0.0.7",
"xo": "^0.39.1"
},
"ava": {
"verbose": true
},
"nyc": {
"reporter": [
"lcovonly",
"text"
]
},
"xo": {
"prettier": true,
"space": true
},
"directories": {
"test": "test"
},
"author": "virk",
"repository": {
"type": "git",
"url": "git+https://github.com/thetutlage/phc-argon2.git"
},
"bugs": {
"url": "https://github.com/thetutlage/phc-argon2/issues"
}
}
+542
View File
@@ -0,0 +1,542 @@
<h1 align="center">
<b>phc-argon2</b>
</h1>
> Fork of [@phc/argon2](https://npm.im/@phc/argon2) with updated dependencies
<p align="center">
<!-- CI - TravisCI -->
<a href="https://travis-ci.com/simonepri/phc-argon2">
<img src="https://img.shields.io/travis/com/simonepri/phc-argon2/master.svg?label=MacOS%20%26%20Linux" alt="Mac/Linux Build Status" />
</a>
<!-- CI - AppVeyor -->
<a href="https://ci.appveyor.com/project/simonepri/phc-argon2">
<img src="https://img.shields.io/appveyor/ci/simonepri/phc-argon2/master.svg?label=Windows" alt="Windows Build status" />
</a>
<!-- Coverage - Codecov -->
<a href="https://codecov.io/gh/simonepri/phc-argon2">
<img src="https://img.shields.io/codecov/c/github/simonepri/phc-argon2/master.svg" alt="Codecov Coverage report" />
</a>
<!-- DM - Snyk -->
<a href="https://snyk.io/test/github/simonepri/phc-argon2?targetFile=package.json">
<img src="https://snyk.io/test/github/simonepri/phc-argon2/badge.svg?targetFile=package.json" alt="Known Vulnerabilities" />
</a>
<!-- DM - David -->
<a href="https://david-dm.org/simonepri/phc-argon2">
<img src="https://david-dm.org/simonepri/phc-argon2/status.svg" alt="Dependency Status" />
</a>
<br/>
<!-- Code Style - XO-Prettier -->
<a href="https://github.com/xojs/xo">
<img src="https://img.shields.io/badge/code_style-XO+Prettier-5ed9c7.svg" alt="XO Code Style used" />
</a>
<!-- Test Runner - AVA -->
<a href="https://github.com/avajs/ava">
<img src="https://img.shields.io/badge/test_runner-AVA-fb3170.svg" alt="AVA Test Runner used" />
</a>
<!-- Test Coverage - Istanbul -->
<a href="https://github.com/istanbuljs/nyc">
<img src="https://img.shields.io/badge/test_coverage-NYC-fec606.svg" alt="Istanbul Test Coverage used" />
</a>
<!-- Init - ni -->
<a href="https://github.com/simonepri/ni">
<img src="https://img.shields.io/badge/initialized_with-ni-e74c3c.svg" alt="NI Scaffolding System used" />
</a>
<!-- Release - np -->
<a href="https://github.com/sindresorhus/np">
<img src="https://img.shields.io/badge/released_with-np-6c8784.svg" alt="NP Release System used" />
</a>
<br/>
<!-- Version - npm -->
<a href="https://www.npmjs.com/package/@phc/argon2">
<img src="https://img.shields.io/npm/v/@phc/argon2.svg" alt="Latest version on npm" />
</a>
<!-- License - MIT -->
<a href="https://github.com/simonepri/phc-argon2/tree/master/license">
<img src="https://img.shields.io/github/license/simonepri/phc-argon2.svg" alt="Project license" />
</a>
</p>
<p align="center">
🔒 Node.JS Argon2 password hashing algorithm following the PHC string format.
<br/>
<sub>
Coded with ❤️ by <a href="#authors">Simone Primarosa</a>.
</sub>
</p>
## PHC String Format
The [PHC String Format][specs:phc] is an attempt to specify a common hash string format thats a restricted & well defined subset of the Modular Crypt Format. New hashes are strongly encouraged to adhere to the PHC specification, rather than the much looser [Modular Crypt Format][specs:mcf].
The hash strings generated by this package are in the following format:
```c
$argon2<variant>$v=<version>$m=<memory>,t=<iterations>,p=<parallelism>$<salt>$<hash>
```
Where:
| Field | Type | Description
| --- | --- | --- |
| `<variant>` | <code>string</code> | The [variant][specs:a2var] of the algorithm used to derive a key of the input password. |
| `<version>` | <code>number</code> | The version of the argon2 algorithm used. |
| `<memory>` | <code>number</code> | The amount of memory to consume in kibibytes. |
| `<iterations>` | <code>number</code> | The number of iterations desired. The higher the number of iterations, the more secure the derived key will be, but will take a longer amount of time to complete. |
| `<parallelism>` | <code>number</code> | The degree of parallelism to use while computing the hash. |
| `<salt>` | <code>string</code> | A sequence of bits, known as a [cryptographic salt][specs:salt] encoded in [B64][specs:B64]. |
| `<hash>` | <code>string</code> | The computed derived key by the [argon2][specs:Argon2] algorithm encoded in [B64][specs:B64]. |
For more details consult the Argon2 paper [here][paper].
## Install
```bash
npm install --save @phc/argon2
```
## Usage
```js
const argon2 = require('@phc/argon2');
// Hash and verify with argon2 and default configs
const hash = await argon2.hash('password');
// => $argon2id$v=19$m=4096,t=3,p=1$PcEZHj1maR/+ZQynyJHWZg$2jEN4xcww7CYp1jakZB1rxbYsZ55XH2HgjYRtdZtubI
const match = await argon2.verify(hash, 'password');
// => true
const match = await argon2.verify(hash, 'wrong');
// => false
const ids = argon2.identifiers();
// => ['argon2d', 'argon2i', 'argon2id']
```
## Benchmarks
Below you can find usage statistics of this hashing algorithm with different
options.
This should help you understand how the different options affects the running
time and memory usage of the algorithm.
Usage reports are generated thanks to [sympact][gh:sympact].
<details>
<summary><strong>System Report</strong> ↴</summary>
```
Distro Release Platform Arch
-------- ------- -------- ----
Mac OS X 10.12.6 darwin x64
CPU Brand Clock Cores
------ -------------- -------- -----
Intel® Core™ i5-6360U 2.00 GHz 4
Memory Type Size Clock
---------------------- ------ ----------- --------
Micron Technology Inc. LPDDR3 4294.967 MB 1867 MHz
Micron Technology Inc. LPDDR3 4294.967 MB 1867 MHz
```
</details>
<details>
<summary><strong>Default options</strong> - <i>{iterations:3, memory:4096, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
0.50 % ± 0.00 % 0.50 % … 0.50 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
23.927 MB ± 2.775 MB 21.152 MB … 26.702 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.020 s 0.069 s 2 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.028 s 0.50 % 21.152 MB 4934
0.069 s 0.50 % 26.702 MB 4934
```
</details>
<details>
<summary><strong>5 iterations</strong> - <i>{iterations:5, memory:4096, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
0.60 % ± 0.00 % 0.60 % … 0.60 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
24.906 MB ± 2.591 MB 21.242 MB … 26.739 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.025 s 0.077 s 3 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.025 s 0.60 % 21.242 MB 4945
0.076 s 0.60 % 26.739 MB 4945
0.077 s 0.60 % 26.739 MB 4945
```
</details>
<details>
<summary><strong>10 iterations</strong> - <i>{iterations:10, memory:4096, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
0.40 % ± 0.00 % 0.40 % … 0.40 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
24.999 MB ± 2.576 MB 21.357 MB … 26.821 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.054 s 0.112 s 3 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.033 s 0.40 % 21.357 MB 4958
0.094 s 0.40 % 26.821 MB 4958
0.112 s 0.40 % 26.821 MB 4958
```
</details>
<details>
<summary><strong>25 iterations</strong> - <i>{iterations:25, memory:4096, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
6.78 % ± 10.70 % 0.60 % … 25.30 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
25.440 MB ± 2.365 MB 21.344 MB … 26.817 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.082 s 0.129 s 4 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.026 s 0.60 % 21.344 MB 4971
0.077 s 0.60 % 26.800 MB 4971
0.109 s 0.60 % 26.800 MB 4971
0.129 s 25.30 % 26.817 MB 4971
```
</details>
<details>
<summary><strong>50 iterations</strong> - <i>{iterations:50, memory:4096, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
12.24 % ± 7.36 % 0.60 % … 16.90 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
26.076 MB ± 1.907 MB 21.406 MB … 26.866 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.158 s 0.207 s 7 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.026 s 0.60 % 21.406 MB 4986
0.077 s 0.60 % 26.849 MB 4986
0.107 s 16.90 % 26.849 MB 4986
0.145 s 16.90 % 26.849 MB 4986
0.167 s 16.90 % 26.849 MB 4986
0.196 s 16.90 % 26.866 MB 4986
0.207 s 16.90 % 26.866 MB 4986
```
</details>
<details>
<summary><strong>100 iterations</strong> - <i>{iterations:100, memory:4096, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
37.25 % ± 22.39 % 1.10 % … 59.20 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
26.418 MB ± 1.453 MB 21.385 MB … 26.849 MB
Execution time Sampling time Samples
-------------- ------------- ----------
0.408 s 0.479 s 13 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.026 s 1.10 % 21.385 MB 5007
0.076 s 1.10 % 26.833 MB 5007
0.106 s 1.10 % 26.833 MB 5007
0.153 s 30.70 % 26.833 MB 5007
0.170 s 30.70 % 26.833 MB 5007
0.201 s 30.70 % 26.833 MB 5007
0.301 s 50.70 % 26.833 MB 5007
0.330 s 50.70 % 26.833 MB 5007
0.366 s 50.70 % 26.833 MB 5007
0.403 s 59.20 % 26.833 MB 5007
0.453 s 59.20 % 26.849 MB 5007
0.478 s 59.20 % 26.849 MB 5007
0.479 s 59.20 % 26.849 MB 5007
```
</details>
<details>
<summary><strong>16˙384 KiB of memory</strong> - <i>{iterations:3, memory:16384, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
5.58 % ± 2.81 % 0.70 % … 7.20 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
34.916 MB ± 7.812 MB 21.385 MB … 39.432 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.071 s 0.13 s 4 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.033 s 0.70 % 21.385 MB 5040
0.083 s 7.20 % 39.416 MB 5040
0.116 s 7.20 % 39.432 MB 5040
0.130 s 7.20 % 39.432 MB 5040
```
</details>
<details>
<summary><strong>65˙536 KiB of memory</strong> - <i>{iterations:3, memory:65536, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
21.92 % ± 17.48 % 0.60 % … 49.30 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
75.683 MB ± 23.350 MB 20.980 MB … 89.358 MB
Execution time Sampling time Samples
-------------- ------------- ---------
0.205 s 0.258 s 8 samples
Instant CPU Usage RAM Usage PIDS
------- --------- --------- ----
0.025 s 0.60 % 20.980 MB 5055
0.075 s 0.60 % 55.775 MB 5055
0.106 s 18.90 % 81.981 MB 5055
0.143 s 18.90 % 89.342 MB 5055
0.164 s 18.90 % 89.342 MB 5055
0.194 s 18.90 % 89.342 MB 5055
0.225 s 49.30 % 89.342 MB 5055
0.258 s 49.30 % 89.358 MB 5055
```
</details>
<details>
<summary><strong>262˙144 KiB of memory</strong> - <i>{iterations:3, memory:262144, parallelism:1, variant:'id'}</i> ↴</summary>
```
CPU Usage (avarage ± σ) CPU Usage Range (min … max)
----------------------- ---------------------------
64.37 % ± 28.91 % 0.60 % … 93.90 %
RAM Usage (avarage ± σ) RAM Usage Range (min … max)
----------------------- ---------------------------
216.095 MB ± 96.874 MB 21.332 MB … 291.025 MB
Execution time Sampling time Samples
-------------- ------------- ----------
0.885 s 0.933 s 31 samples
Instant CPU Usage RAM Usage PIDS
------- --------- ---------- ----
0.026 s 0.60 % 21.332 MB 5078
0.074 s 0.60 % 51.356 MB 5078
0.106 s 19.40 % 77.545 MB 5078
0.136 s 19.40 % 99.344 MB 5078
0.167 s 19.40 % 121.168 MB 5078
0.192 s 19.40 % 140.993 MB 5078
0.225 s 47.90 % 165.065 MB 5078
0.260 s 47.90 % 188.371 MB 5078
0.286 s 47.90 % 205.804 MB 5078
0.315 s 47.90 % 229.233 MB 5078
0.343 s 66.20 % 252.084 MB 5078
0.404 s 66.20 % 288.231 MB 5078
0.422 s 66.20 % 291.025 MB 5078
0.439 s 66.20 % 291.025 MB 5078
0.468 s 77.00 % 291.025 MB 5078
0.498 s 77.00 % 291.025 MB 5078
0.528 s 77.00 % 291.025 MB 5078
0.554 s 77.00 % 291.025 MB 5078
0.586 s 77.00 % 291.025 MB 5078
0.619 s 85.10 % 291.025 MB 5078
0.649 s 85.10 % 291.025 MB 5078
0.672 s 85.10 % 291.025 MB 5078
0.703 s 85.10 % 291.025 MB 5078
0.735 s 89.80 % 291.025 MB 5078
0.765 s 89.80 % 291.025 MB 5078
0.792 s 89.80 % 291.025 MB 5078
0.823 s 89.80 % 291.025 MB 5078
0.854 s 93.90 % 291.025 MB 5078
0.896 s 93.90 % 156.807 MB 5078
0.918 s 93.90 % 22.606 MB 5078
0.933 s 93.90 % 22.606 MB 5078
```
</details>
<!--
## Test vectors
The [scrypt paper][paper:test] lists four test vectors to test implementation.
This package implements them [here][tvec].
-->
## API
#### TOC
<dl>
<dt><a href="#hash">hash(password, [options])</a> ⇒ <code>Promise.&lt;string&gt;</code></dt>
<dd><p>Computes the hash string of the given password in the PHC format using argon2
package.</p>
</dd>
<dt><a href="#verify">verify(phcstr, password)</a> ⇒ <code>Promise.&lt;boolean&gt;</code></dt>
<dd><p>Determines whether or not the hash stored inside the PHC formatted string
matches the hash generated for the password provided.</p>
</dd>
<dt><a href="#identifiers">identifiers()</a> ⇒ <code>Array.&lt;string&gt;</code></dt>
<dd><p>Gets the list of all identifiers supported by this hashing function.</p>
</dd>
</dl>
<a name="hash"></a>
### hash(password, [options]) ⇒ <code>Promise.&lt;string&gt;</code>
Computes the hash string of the given password in the PHC format using argon2
package.
**Kind**: global function
**Returns**: <code>Promise.&lt;string&gt;</code> - The generated secure hash string in the PHC
format.
**Access**: public
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| password | <code>string</code> | | The password to hash. |
| [options] | <code>Object</code> | | Optional configurations related to the hashing function. |
| [options.variant] | <code>number</code> | <code>id</code> | Optinal variant of argon2 to use. Can be one of [`'d'`, `'i'`, `'id'`] for argon2d, argon2i and argon2id respectively. |
| [options.iterations] | <code>number</code> | <code>3</code> | Optional number of iterations to use. Must be an integer within the range (`1` <= `iterations` <= `2^32-1`). |
| [options.memory] | <code>number</code> | <code>4096</code> | Optional amount of memory to use in kibibytes. Must be an integer within the range (`8` <= `memory` <= `2^32-1`). |
| [options.parallelism] | <code>number</code> | <code>1</code> | Optional degree of parallelism to use. Must be an integer within the range (`1` <= `parallelism` <= `2^24-1`). |
| [options.saltSize] | <code>number</code> | <code>16</code> | Optional number of bytes to use when autogenerating new salts. Must be an integer within the range (`1` <= `saltSize` <= `2^10-1`). |
<a name="verify"></a>
### verify(phcstr, password) ⇒ <code>Promise.&lt;boolean&gt;</code>
Determines whether or not the hash stored inside the PHC formatted string
matches the hash generated for the password provided.
**Kind**: global function
**Returns**: <code>Promise.&lt;boolean&gt;</code> - A boolean that is true if the hash computed
for the password matches.
**Access**: public
| Param | Type | Description |
| --- | --- | --- |
| phcstr | <code>string</code> | Secure hash string generated from this package. |
| password | <code>string</code> | User's password input. |
<a name="identifiers"></a>
### identifiers() ⇒ <code>Array.&lt;string&gt;</code>
Gets the list of all identifiers supported by this hashing function.
**Kind**: global function
**Returns**: <code>Array.&lt;string&gt;</code> - A list of identifiers supported by this hashing function.
**Access**: public
## Related
- [@phc/scrypt][scrypt] -
🔒 Node.JS scrypt password hashing algorithm following the PHC string format.
- [@phc/bcrypt][bcrypt] -
🔒 Node.JS bcrypt password hashing algorithm following the PHC string format.
- [@phc/pbkdf2][pbkdf2] -
🔒 Node.JS PBKDF2 password hashing algorithm following the PHC string format.
## Contributing
Contributions are REALLY welcome and if you find a security flaw in this code, PLEASE [report it][new issue].
## Authors
- **Simone Primarosa** - *Github* ([@simonepri][github:simonepri]) • *Twitter* ([@simoneprimarosa][twitter:simoneprimarosa])
See also the list of [contributors][contributors] who participated in this project.
## License
This project is licensed under the MIT License - see the [license][license] file for details.
<!-- Links -->
[start]: https://github.com/simonepri/phc-argon2#start-of-content
[new issue]: https://github.com/simonepri/phc-argon2/issues/new
[contributors]: https://github.com/simonepri/phc-argon2/contributors
[license]: https://github.com/simonepri/phc-argon2/tree/master/license
[tvec]: https://github.com/simonepri/phc-argon2/tree/master/test/vectors.js
[scrypt]: https://github.com/simonepri/phc-scrypt
[bcrypt]: https://github.com/simonepri/phc-bcrypt
[pbkdf2]: https://github.com/simonepri/phc-pbkdf2
[github:simonepri]: https://github.com/simonepri
[twitter:simoneprimarosa]: http://twitter.com/intent/user?screen_name=simoneprimarosa
[gh:sympact]: https://github.com/simonepri/sympact
[specs:mcf]: https://github.com/ademarre/binary-mcf
[specs:phc]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md
[specs:B64]: https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md#b64
[specs:salt]: https://en.wikipedia.org/wiki/Salt_(cryptography)
[specs:a2var]: https://crypto.stackexchange.com/a/49969
[specs:Argon2]: https://en.wikipedia.org/wiki/Argon2
[paper]: https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03
[paper:test]: https://tools.ietf.org/html/draft-irtf-cfrg-argon2-03#section-6