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

View file

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

View file

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

View file

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

View file

@ -26,7 +26,7 @@ class Argon2Compare extends Operation {
this.outputType = "string"; this.outputType = "string";
this.args = [ this.args = [
{ {
"name": "Hash", "name": "Encoded hash",
"type": "string", "type": "string",
"value": "" "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 () => { it("Bcrypt", async () => {
const result = await chef.bcrypt("Put a Sock In It"); const result = await chef.bcrypt("Put a Sock In It");
const strResult = result.toString(); const strResult = result.toString();

View file

@ -1109,7 +1109,7 @@ TestRegister.addTests([
args: ["D-A"] args: ["D-A"]
} }
] ]
} },
/* { // This takes a LONG time to run (over a minute usually). /* { // This takes a LONG time to run (over a minute usually).
name: "Scrypt: RFC test vector 4", name: "Scrypt: RFC test vector 4",
input: "pleaseletmein", 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: { module: {
// argon2-browser loads argon2.wasm by itself, so Webpack should not load it // 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: [ rules: [
{ {
test: /\.m?js$/, test: /\.m?js$/,
@ -129,10 +129,16 @@ module.exports = {
loader: "babel-loader" loader: "babel-loader"
}, },
{ {
test: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/, test: /node-forge/,
// Load argon2.wasm as base64-encoded binary file loader: "imports-loader",
// expected by argon2-browser options: {
loaders: "base64-loader", 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" type: "javascript/auto"
}, },
{ {