Skip to content

Commit 25fe7bb

Browse files
committed
Tidied up Argon2 operations
1 parent ca340cd commit 25fe7bb

File tree

8 files changed

+88
-32
lines changed

8 files changed

+88
-32
lines changed

package-lock.json

+17-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"babel-loader": "^9.1.2",
5555
"babel-plugin-dynamic-import-node": "^2.3.3",
5656
"babel-plugin-transform-builtin-extend": "1.1.2",
57+
"base64-loader": "^1.0.0",
5758
"chromedriver": "^110.0.0",
5859
"cli-progress": "^3.12.0",
5960
"colors": "^1.4.0",
@@ -94,7 +95,7 @@
9495
"@astronautlabs/amf": "^0.0.6",
9596
"@babel/polyfill": "^7.12.1",
9697
"@blu3r4y/lzma": "^2.3.3",
97-
"argon2-browser": "^1.11.1",
98+
"argon2-browser": "^1.18.0",
9899
"arrive": "^2.4.1",
99100
"avsc": "^5.7.7",
100101
"bcryptjs": "^2.4.3",
@@ -179,8 +180,8 @@
179180
"start": "npx grunt dev",
180181
"build": "npx grunt prod",
181182
"node": "npx grunt node",
182-
"repl": "node --experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings src/node/repl.mjs",
183-
"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",
183+
"repl": "node --experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-experimental-fetch --no-warnings src/node/repl.mjs",
184+
"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",
184185
"testnodeconsumer": "npx grunt testnodeconsumer",
185186
"testui": "npx grunt testui",
186187
"testuidev": "npx nightwatch --env=dev",

src/core/config/Categories.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,9 @@
381381
"Bcrypt",
382382
"Bcrypt compare",
383383
"Bcrypt parse",
384-
"Scrypt",
385384
"Argon2",
386385
"Argon2 compare",
386+
"Scrypt",
387387
"NT Hash",
388388
"LM Hash",
389389
"Fletcher-8 Checksum",

src/core/operations/Argon2.mjs

+21-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import Operation from "../Operation.mjs";
88
import OperationError from "../errors/OperationError.mjs";
9+
import Utils from "../Utils.mjs";
910
import argon2 from "argon2-browser";
1011

1112
/**
@@ -28,8 +29,9 @@ class Argon2 extends Operation {
2829
this.args = [
2930
{
3031
"name": "Salt",
31-
"type": "string",
32-
"value": "somesalt"
32+
"type": "toggleString",
33+
"value": "somesalt",
34+
"toggleValues": ["UTF8", "Hex", "Base64", "Latin1"]
3335
},
3436
{
3537
"name": "Iterations",
@@ -56,6 +58,11 @@ class Argon2 extends Operation {
5658
"type": "option",
5759
"value": ["Argon2i", "Argon2d", "Argon2id"],
5860
"defaultIndex": 0
61+
},
62+
{
63+
"name": "Output format",
64+
"type": "option",
65+
"value": ["Encoded hash", "Hex hash", "Raw hash"]
5966
}
6067
];
6168
}
@@ -72,12 +79,13 @@ class Argon2 extends Operation {
7279
"Argon2id": argon2.ArgonType.Argon2id
7380
};
7481

75-
const salt = args[0],
82+
const salt = Utils.convertToByteString(args[0].string || "", args[0].option),
7683
time = args[1],
7784
mem = args[2],
7885
parallelism = args[3],
7986
hashLen = args[4],
80-
type = argon2Types[args[5]];
87+
type = argon2Types[args[5]],
88+
outFormat = args[6];
8189

8290
try {
8391
const result = await argon2.hash({
@@ -90,7 +98,15 @@ class Argon2 extends Operation {
9098
type,
9199
});
92100

93-
return result.encoded;
101+
switch (outFormat) {
102+
case "Hex hash":
103+
return result.hashHex;
104+
case "Raw hash":
105+
return Utils.arrayBufferToStr(result.hash);
106+
case "Encoded hash":
107+
default:
108+
return result.encoded;
109+
}
94110
} catch (err) {
95111
throw new OperationError(`Error: ${err.message}`);
96112
}

src/core/operations/Argon2Compare.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Argon2Compare extends Operation {
2626
this.outputType = "string";
2727
this.args = [
2828
{
29-
"name": "Hash",
29+
"name": "Encoded hash",
3030
"type": "string",
3131
"value": ""
3232
}

tests/node/tests/operations.mjs

-12
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,6 @@ Tiger-128`;
133133

134134
}),
135135

136-
it("argon2", async () => {
137-
const result = await chef.argon2("argon2password");
138-
assert.strictEqual(result.toString(), "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw");
139-
}),
140-
141-
it("argon2 compare", async () => {
142-
const result = await chef.argon2Compare("argon2password", {
143-
hash: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"
144-
});
145-
assert.strictEqual(result.toString(), "Match: argon2password");
146-
}),
147-
148136
it("Bcrypt", async () => {
149137
const result = await chef.bcrypt("Put a Sock In It");
150138
const strResult = result.toString();

tests/operations/tests/Hash.mjs

+33-1
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ TestRegister.addTests([
11091109
args: ["D-A"]
11101110
}
11111111
]
1112-
}
1112+
},
11131113
/* { // This takes a LONG time to run (over a minute usually).
11141114
name: "Scrypt: RFC test vector 4",
11151115
input: "pleaseletmein",
@@ -1127,4 +1127,36 @@ TestRegister.addTests([
11271127
}
11281128
]
11291129
}, */
1130+
{
1131+
name: "Argon2",
1132+
input: "argon2password",
1133+
expectedOutput: "$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw",
1134+
recipeConfig: [
1135+
{
1136+
op: "Argon2",
1137+
args: [
1138+
{"option": "UTF8", "string": "somesalt"},
1139+
3,
1140+
4096,
1141+
1,
1142+
32,
1143+
"Argon2i",
1144+
"Encoded hash"
1145+
]
1146+
}
1147+
]
1148+
},
1149+
{
1150+
name: "Argon2 compare",
1151+
input: "argon2password",
1152+
expectedOutput: "Match: argon2password",
1153+
recipeConfig: [
1154+
{
1155+
op: "Argon2 compare",
1156+
args: [
1157+
"$argon2i$v=19$m=4096,t=3,p=1$c29tZXNhbHQ$s43my9eBljQADuF/LWCG8vGqwAJzOorKQ0Yog8jFvbw"
1158+
]
1159+
}
1160+
]
1161+
}
11301162
]);

webpack.config.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ module.exports = {
115115
},
116116
module: {
117117
// argon2-browser loads argon2.wasm by itself, so Webpack should not load it
118-
noParse: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/,
118+
noParse: /argon2\.wasm$/,
119119
rules: [
120120
{
121121
test: /\.m?js$/,
@@ -129,10 +129,16 @@ module.exports = {
129129
loader: "babel-loader"
130130
},
131131
{
132-
test: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/,
133-
// Load argon2.wasm as base64-encoded binary file
134-
// expected by argon2-browser
135-
loaders: "base64-loader",
132+
test: /node-forge/,
133+
loader: "imports-loader",
134+
options: {
135+
additionalCode: "var jQuery = false;"
136+
}
137+
},
138+
{
139+
// Load argon2.wasm as base64-encoded binary file expected by argon2-browser
140+
test: /argon2\.wasm$/,
141+
loader: "base64-loader",
136142
type: "javascript/auto"
137143
},
138144
{

0 commit comments

Comments
 (0)