Skip to content

Commit

Permalink
Add Argon2 hash compare operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Xenonym committed Oct 11, 2019
1 parent ef0bbef commit c92e09e
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/core/config/Categories.json
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
"Bcrypt parse",
"Scrypt",
"Argon2",
"Argon2 compare",
"Fletcher-8 Checksum",
"Fletcher-16 Checksum",
"Fletcher-32 Checksum",
Expand Down
58 changes: 58 additions & 0 deletions src/core/operations/Argon2Compare.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @author Tan Zhen Yong [tzy@beyondthesprawl.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/

import Operation from "../Operation.mjs";
import argon2 from "argon2-browser";

/**
* Argon2 compare operation
*/
class Argon2Compare extends Operation {

/**
* Argon2Compare constructor
*/
constructor() {
super();

this.name = "Argon2 compare";
this.module = "Crypto";
this.description = "Tests whether the input matches the given Argon2 hash. To test multiple possible passwords, use the 'Fork' operation.";
this.infoURL = "https://wikipedia.org/wiki/Argon2";
this.inputType = "string";
this.outputType = "string";
this.args = [
{
"name": "Hash",
"type": "string",
"value": ""
}
];
}

/**
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
async run(input, args) {
const encoded = args[0];

try {
await argon2.verify({
pass: input,
encoded
});

return `Match: ${input}`;
} catch (err) {
return "No match";
}
}

}

export default Argon2Compare;
7 changes: 7 additions & 0 deletions tests/node/tests/operations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ Tiger-128`;
assert.strictEqual(result.toString(), "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw");
}),

it("argon2 compare", async () => {
const result = await chef.argon2Compare("argon2password", {
hash: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"
});
assert.strictEqual(result.toString(), "Match: argon2password");
}),

it("Bcrypt", async () => {
const result = await chef.bcrypt("Put a Sock In It");
const strResult = result.toString();
Expand Down

0 comments on commit c92e09e

Please sign in to comment.