Tidied up Argon2 operations

This commit is contained in:
n1474335 2023-03-24 22:15:21 +00:00
parent ca340cdd7b
commit 25fe7bba67
No known key found for this signature in database
GPG key ID: D15457B7B4AF3F37
8 changed files with 88 additions and 32 deletions

21
package-lock.json generated
View file

@ -13,6 +13,7 @@
"@astronautlabs/amf": "^0.0.6",
"@babel/polyfill": "^7.12.1",
"@blu3r4y/lzma": "^2.3.3",
"argon2-browser": "^1.18.0",
"arrive": "^2.4.1",
"avsc": "^5.7.7",
"bcryptjs": "^2.4.3",
@ -109,6 +110,7 @@
"babel-loader": "^9.1.2",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0",
"chromedriver": "^110.0.0",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
@ -3200,6 +3202,11 @@
"dev": true,
"license": "MIT"
},
"node_modules/argon2-browser": {
"version": "1.18.0",
"resolved": "https://registry.npmjs.org/argon2-browser/-/argon2-browser-1.18.0.tgz",
"integrity": "sha512-ImVAGIItnFnvET1exhsQB7apRztcoC5TnlSqernMJDUjbc/DLq3UEYeXFrLPrlaIl8cVfwnXb6wX2KpFf2zxHw=="
},
"node_modules/argparse": {
"version": "2.0.1",
"license": "Python-2.0"
@ -3633,6 +3640,12 @@
],
"license": "MIT"
},
"node_modules/base64-loader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base64-loader/-/base64-loader-1.0.0.tgz",
"integrity": "sha512-p32+F8dg+ANGx7s8QsZS74ZPHfIycmC2yZcoerzFgbersIYWitPbbF39G6SBx3gyvzyLH5nt1ooocxr0IHuWKA==",
"dev": true
},
"node_modules/basic-auth": {
"version": "2.0.1",
"dev": true,
@ -16041,9 +16054,9 @@
"dev": true
},
"argon2-browser": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/argon2-browser/-/argon2-browser-1.11.1.tgz",
"integrity": "sha512-C+WsBLSkwQExkDYB7vriugrBTXq2z+fTRDlGWqr2zm89TaKo7zYtSGARMgoBxpDnmNNzduNlZJmpY2j0Dp7ZOQ=="
"version": "1.18.0",
"resolved": "https://registry.npmjs.org/argon2-browser/-/argon2-browser-1.18.0.tgz",
"integrity": "sha512-ImVAGIItnFnvET1exhsQB7apRztcoC5TnlSqernMJDUjbc/DLq3UEYeXFrLPrlaIl8cVfwnXb6wX2KpFf2zxHw=="
},
"argparse": {
"version": "2.0.1"
@ -16355,7 +16368,7 @@
"base64-loader": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/base64-loader/-/base64-loader-1.0.0.tgz",
"integrity": "sha1-5TC62I6QbdKh+tCvLZ5oP6i9kqg=",
"integrity": "sha512-p32+F8dg+ANGx7s8QsZS74ZPHfIycmC2yZcoerzFgbersIYWitPbbF39G6SBx3gyvzyLH5nt1ooocxr0IHuWKA==",
"dev": true
},
"basic-auth": {

View file

@ -54,6 +54,7 @@
"babel-loader": "^9.1.2",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-transform-builtin-extend": "1.1.2",
"base64-loader": "^1.0.0",
"chromedriver": "^110.0.0",
"cli-progress": "^3.12.0",
"colors": "^1.4.0",
@ -94,7 +95,7 @@
"@astronautlabs/amf": "^0.0.6",
"@babel/polyfill": "^7.12.1",
"@blu3r4y/lzma": "^2.3.3",
"argon2-browser": "^1.11.1",
"argon2-browser": "^1.18.0",
"arrive": "^2.4.1",
"avsc": "^5.7.7",
"bcryptjs": "^2.4.3",
@ -179,8 +180,8 @@
"start": "npx grunt dev",
"build": "npx grunt prod",
"node": "npx grunt node",
"repl": "node --experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings src/node/repl.mjs",
"test": "npx grunt configTests && node --experimental-modules --experimental-json-modules --no-warnings --no-deprecation --openssl-legacy-provider tests/node/index.mjs && node --experimental-modules --experimental-json-modules --no-warnings --no-deprecation --openssl-legacy-provider tests/operations/index.mjs",
"repl": "node --experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-experimental-fetch --no-warnings src/node/repl.mjs",
"test": "npx grunt configTests && node --experimental-modules --experimental-json-modules --no-warnings --no-deprecation --openssl-legacy-provider --no-experimental-fetch tests/node/index.mjs && node --experimental-modules --experimental-json-modules --no-warnings --no-deprecation --openssl-legacy-provider --no-experimental-fetch tests/operations/index.mjs",
"testnodeconsumer": "npx grunt testnodeconsumer",
"testui": "npx grunt testui",
"testuidev": "npx nightwatch --env=dev",

View file

@ -381,9 +381,9 @@
"Bcrypt",
"Bcrypt compare",
"Bcrypt parse",
"Scrypt",
"Argon2",
"Argon2 compare",
"Scrypt",
"NT Hash",
"LM Hash",
"Fletcher-8 Checksum",

View file

@ -6,6 +6,7 @@
import Operation from "../Operation.mjs";
import OperationError from "../errors/OperationError.mjs";
import Utils from "../Utils.mjs";
import argon2 from "argon2-browser";
/**
@ -28,8 +29,9 @@ class Argon2 extends Operation {
this.args = [
{
"name": "Salt",
"type": "string",
"value": "somesalt"
"type": "toggleString",
"value": "somesalt",
"toggleValues": ["UTF8", "Hex", "Base64", "Latin1"]
},
{
"name": "Iterations",
@ -56,6 +58,11 @@ class Argon2 extends Operation {
"type": "option",
"value": ["Argon2i", "Argon2d", "Argon2id"],
"defaultIndex": 0
},
{
"name": "Output format",
"type": "option",
"value": ["Encoded hash", "Hex hash", "Raw hash"]
}
];
}
@ -72,12 +79,13 @@ class Argon2 extends Operation {
"Argon2id": argon2.ArgonType.Argon2id
};
const salt = args[0],
const salt = Utils.convertToByteString(args[0].string || "", args[0].option),
time = args[1],
mem = args[2],
parallelism = args[3],
hashLen = args[4],
type = argon2Types[args[5]];
type = argon2Types[args[5]],
outFormat = args[6];
try {
const result = await argon2.hash({
@ -90,7 +98,15 @@ class Argon2 extends Operation {
type,
});
return result.encoded;
switch (outFormat) {
case "Hex hash":
return result.hashHex;
case "Raw hash":
return Utils.arrayBufferToStr(result.hash);
case "Encoded hash":
default:
return result.encoded;
}
} catch (err) {
throw new OperationError(`Error: ${err.message}`);
}

View file

@ -26,7 +26,7 @@ class Argon2Compare extends Operation {
this.outputType = "string";
this.args = [
{
"name": "Hash",
"name": "Encoded hash",
"type": "string",
"value": ""
}

View file

@ -133,18 +133,6 @@ Tiger-128`;
}),
it("argon2", async () => {
const result = await chef.argon2("argon2password");
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();

View file

@ -1109,7 +1109,7 @@ TestRegister.addTests([
args: ["D-A"]
}
]
}
},
/* { // This takes a LONG time to run (over a minute usually).
name: "Scrypt: RFC test vector 4",
input: "pleaseletmein",
@ -1127,4 +1127,36 @@ TestRegister.addTests([
}
]
}, */
{
name: "Argon2",
input: "argon2password",
expectedOutput: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw",
recipeConfig: [
{
op: "Argon2",
args: [
{"option": "UTF8", "string": "somesalt"},
3,
4096,
1,
32,
"Argon2i",
"Encoded hash"
]
}
]
},
{
name: "Argon2 compare",
input: "argon2password",
expectedOutput: "Match: argon2password",
recipeConfig: [
{
op: "Argon2 compare",
args: [
"$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"
]
}
]
}
]);

View file

@ -115,7 +115,7 @@ module.exports = {
},
module: {
// argon2-browser loads argon2.wasm by itself, so Webpack should not load it
noParse: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/,
noParse: /argon2\.wasm$/,
rules: [
{
test: /\.m?js$/,
@ -129,10 +129,16 @@ module.exports = {
loader: "babel-loader"
},
{
test: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/,
// Load argon2.wasm as base64-encoded binary file
// expected by argon2-browser
loaders: "base64-loader",
test: /node-forge/,
loader: "imports-loader",
options: {
additionalCode: "var jQuery = false;"
}
},
{
// Load argon2.wasm as base64-encoded binary file expected by argon2-browser
test: /argon2\.wasm$/,
loader: "base64-loader",
type: "javascript/auto"
},
{