-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/add-argon2-operation' of https://github.com/Xen…
- Loading branch information
Showing
7 changed files
with
192 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/** | ||
* @author Tan Zhen Yong [[email protected]] | ||
* @copyright Crown Copyright 2019 | ||
* @license Apache-2.0 | ||
*/ | ||
|
||
import Operation from "../Operation.mjs"; | ||
import OperationError from "../errors/OperationError.mjs"; | ||
import argon2 from "argon2-browser"; | ||
|
||
/** | ||
* Argon2 operation | ||
*/ | ||
class Argon2 extends Operation { | ||
|
||
/** | ||
* Argon2 constructor | ||
*/ | ||
constructor() { | ||
super(); | ||
|
||
this.name = "Argon2"; | ||
this.module = "Crypto"; | ||
this.description = "Argon2 is a key derivation function that was selected as the winner of the Password Hashing Competition in July 2015. It was designed by Alex Biryukov, Daniel Dinu, and Dmitry Khovratovich from the University of Luxembourg.<br><br>Enter the password in the input to generate its hash."; | ||
this.infoURL = "https://wikipedia.org/wiki/Argon2"; | ||
this.inputType = "string"; | ||
this.outputType = "string"; | ||
this.args = [ | ||
{ | ||
"name": "Salt", | ||
"type": "string", | ||
"value": "somesalt" | ||
}, | ||
{ | ||
"name": "Iterations", | ||
"type": "number", | ||
"value": 3 | ||
}, | ||
{ | ||
"name": "Memory (KiB)", | ||
"type": "number", | ||
"value": 4096 | ||
}, | ||
{ | ||
"name": "Parallelism", | ||
"type": "number", | ||
"value": 1 | ||
}, | ||
{ | ||
"name": "Hash length (bytes)", | ||
"type": "number", | ||
"value": 32 | ||
}, | ||
{ | ||
"name": "Type", | ||
"type": "option", | ||
"value": ["Argon2i", "Argon2d", "Argon2id"], | ||
"defaultIndex": 0 | ||
} | ||
]; | ||
} | ||
|
||
/** | ||
* @param {string} input | ||
* @param {Object[]} args | ||
* @returns {string} | ||
*/ | ||
async run(input, args) { | ||
const argon2Types = { | ||
"Argon2i": argon2.ArgonType.Argon2i, | ||
"Argon2d": argon2.ArgonType.Argon2d, | ||
"Argon2id": argon2.ArgonType.Argon2id | ||
}; | ||
|
||
const salt = args[0], | ||
time = args[1], | ||
mem = args[2], | ||
parallelism = args[3], | ||
hashLen = args[4], | ||
type = argon2Types[args[5]]; | ||
|
||
try { | ||
const result = await argon2.hash({ | ||
pass: input, | ||
salt, | ||
time, | ||
mem, | ||
parallelism, | ||
hashLen, | ||
type, | ||
}); | ||
|
||
return result.encoded; | ||
} catch (err) { | ||
throw new OperationError(`Error: ${err.message}`); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default Argon2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @author Tan Zhen Yong [[email protected]] | ||
* @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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters