From 1f09c03d4897206e7ed4a3d90cac6c577c486aed Mon Sep 17 00:00:00 2001 From: GCHQ 77703 Date: Fri, 15 Feb 2019 14:23:16 +0000 Subject: [PATCH 01/13] Add De Bruijn Operation --- src/core/config/Categories.json | 1 + .../operations/GenerateDeBruijnSequence.mjs | 87 +++++++++++++++++++ tests/operations/index.mjs | 1 + .../tests/GenerateDeBruijnSequence.mjs | 33 +++++++ 4 files changed, 122 insertions(+) create mode 100644 src/core/operations/GenerateDeBruijnSequence.mjs create mode 100644 tests/operations/tests/GenerateDeBruijnSequence.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 8235ab10..238c7282 100755 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -370,6 +370,7 @@ "Chi Square", "Disassemble x86", "Pseudo-Random Number Generator", + "Generate De Bruijn Sequence", "Generate UUID", "Generate TOTP", "Generate HOTP", diff --git a/src/core/operations/GenerateDeBruijnSequence.mjs b/src/core/operations/GenerateDeBruijnSequence.mjs new file mode 100644 index 00000000..647d3c7f --- /dev/null +++ b/src/core/operations/GenerateDeBruijnSequence.mjs @@ -0,0 +1,87 @@ +/** + * @author gchq77703 [gchq77703@gchq.gov.uk] + * @copyright Crown Copyright 2019 + * @license Apache-2.0 + */ + +import Operation from "../Operation"; +import OperationError from "../errors/OperationError"; + +/** + * Generate De Bruijn Sequence operation + */ +class GenerateDeBruijnSequence extends Operation { + + /** + * GenerateDeBruijnSequence constructor + */ + constructor() { + super(); + + this.name = "Generate De Bruijn Sequence"; + this.module = "Default"; + this.description = "Generates rolling keycode combinations given a certain alphabet size and key length."; + this.infoURL = "https://wikipedia.org/wiki/De_Bruijn_sequence"; + this.inputType = "string"; + this.outputType = "string"; + this.args = [ + { + name: "Alphabet size (k)", + type: "number", + value: 2 + }, + { + name: "Key length (n)", + type: "number", + value: 3 + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + run(input, args) { + const [k, n] = args; + + if (k < 2 || k > 9) { + throw new OperationError("Invalid alphabet size, required to be between 2 and 9 (inclusive)."); + } + + if (n < 2) { + throw new OperationError("Invalid key length, required to be at least 2."); + } + + if (Math.pow(k, n) > 50000) { + throw new OperationError("Too many permutations, please reduce k^n to under 50,000."); + } + + const a = []; + for (let i = 0; i < k * n; i++) a.push(0); + + const sequence = []; + + (function db(t = 1, p = 1) { + if (t > n) { + if (n % p !== 0) return; + for (let j = 1; j <= p; j++) { + sequence.push(a[j]); + } + return; + } + + a[t] = a[t - p]; + db(t + 1, p); + for (let j = a[t - p] + 1; j < k; j++) { + a[t] = j; + db(t + 1, t); + } + })(); + + return sequence.join(""); + } +} + +export default GenerateDeBruijnSequence; diff --git a/tests/operations/index.mjs b/tests/operations/index.mjs index fb68ed9c..316e934c 100644 --- a/tests/operations/index.mjs +++ b/tests/operations/index.mjs @@ -45,6 +45,7 @@ import "./tests/DateTime"; import "./tests/ExtractEmailAddresses"; import "./tests/Fork"; import "./tests/FromDecimal"; +import "./tests/GenerateDeBruijnSequence"; import "./tests/Hash"; import "./tests/HaversineDistance"; import "./tests/Hexdump"; diff --git a/tests/operations/tests/GenerateDeBruijnSequence.mjs b/tests/operations/tests/GenerateDeBruijnSequence.mjs new file mode 100644 index 00000000..b68a843f --- /dev/null +++ b/tests/operations/tests/GenerateDeBruijnSequence.mjs @@ -0,0 +1,33 @@ +/** + * De Brujin Sequence tests. + * + * @author gchq77703 [gchq77703@gchq.gov.uk] + * @copyright Crown Copyright 2017 + * @license Apache-2.0 + */ +import TestRegister from "../TestRegister"; + +TestRegister.addTests([ + { + name: "Small Sequence", + input: "", + expectedOutput: "00010111", + recipeConfig: [ + { + "op": "Generate De Bruijn Sequence", + "args": [2, 3] + } + ] + }, + { + name: "Long Sequence", + input: "", + expectedOutput: "0000010000200003000110001200013000210002200023000310003200033001010010200103001110011200113001210012200123001310013200133002010020200203002110021200213002210022200223002310023200233003010030200303003110031200313003210032200323003310033200333010110101201013010210102201023010310103201033011020110301111011120111301121011220112301131011320113301202012030121101212012130122101222012230123101232012330130201303013110131201313013210132201323013310133201333020210202202023020310203202033021030211102112021130212102122021230213102132021330220302211022120221302221022220222302231022320223302303023110231202313023210232202323023310233202333030310303203033031110311203113031210312203123031310313203133032110321203213032210322203223032310323203233033110331203313033210332203323033310333203333111112111131112211123111321113311212112131122211223112321123311312113131132211323113321133312122121231213212133122131222212223122321223312313123221232312332123331313213133132221322313232132331332213323133321333322222322233223232233323233233333", + recipeConfig: [ + { + "op": "Generate De Bruijn Sequence", + "args": [4, 5] + } + ] + } +]) \ No newline at end of file From 44a164ed2825ddd799b656459b89b1a4ee5a9f0a Mon Sep 17 00:00:00 2001 From: GCHQ 77703 Date: Tue, 19 Feb 2019 09:56:38 +0000 Subject: [PATCH 02/13] Fix test script linter --- tests/operations/tests/GenerateDeBruijnSequence.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/operations/tests/GenerateDeBruijnSequence.mjs b/tests/operations/tests/GenerateDeBruijnSequence.mjs index b68a843f..48e8c4ff 100644 --- a/tests/operations/tests/GenerateDeBruijnSequence.mjs +++ b/tests/operations/tests/GenerateDeBruijnSequence.mjs @@ -30,4 +30,4 @@ TestRegister.addTests([ } ] } -]) \ No newline at end of file +]); From 822a4fab86572817fcd2e6218d8c736d1e22bbf4 Mon Sep 17 00:00:00 2001 From: GCHQ 77703 Date: Tue, 19 Feb 2019 10:16:51 +0000 Subject: [PATCH 03/13] Fix operation linting --- src/core/operations/GenerateDeBruijnSequence.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/operations/GenerateDeBruijnSequence.mjs b/src/core/operations/GenerateDeBruijnSequence.mjs index 647d3c7f..af788585 100644 --- a/src/core/operations/GenerateDeBruijnSequence.mjs +++ b/src/core/operations/GenerateDeBruijnSequence.mjs @@ -71,7 +71,7 @@ class GenerateDeBruijnSequence extends Operation { } return; } - + a[t] = a[t - p]; db(t + 1, p); for (let j = a[t - p] + 1; j < k; j++) { From 2fab1028c51c6245480d03f4d9f2e8b7249996ec Mon Sep 17 00:00:00 2001 From: Tan Zhen Yong Date: Mon, 7 Oct 2019 02:24:09 +0800 Subject: [PATCH 04/13] Add Argon2 hash operation --- package-lock.json | 11 ++++ package.json | 1 + src/core/config/Categories.json | 1 + src/core/operations/Argon2.mjs | 101 ++++++++++++++++++++++++++++++++ tests/node/tests/operations.mjs | 5 ++ webpack.config.js | 12 ++-- 6 files changed, 126 insertions(+), 5 deletions(-) create mode 100644 src/core/operations/Argon2.mjs diff --git a/package-lock.json b/package-lock.json index 8b5641c9..6e4f9230 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16587,6 +16587,11 @@ "integrity": "sha512-e0hDa9H2Z9AwFkk2qDlwhoMYE4eToKarchkQHovNdLTCYMHZHeRjI71crOh+dio4K6u1IcwubQqo79Ga4CyAQA==", "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==" + }, "argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -16976,6 +16981,12 @@ "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==" }, + "base64-loader": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/base64-loader/-/base64-loader-1.0.0.tgz", + "integrity": "sha1-5TC62I6QbdKh+tCvLZ5oP6i9kqg=", + "dev": true + }, "basic-auth": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-2.0.1.tgz", diff --git a/package.json b/package.json index fe93fe52..46a0f232 100644 --- a/package.json +++ b/package.json @@ -89,6 +89,7 @@ "@astronautlabs/amf": "^0.0.6", "@babel/polyfill": "^7.12.1", "@blu3r4y/lzma": "^2.3.3", + "argon2-browser": "^1.11.1", "arrive": "^2.4.1", "avsc": "^5.7.4", "bcryptjs": "^2.4.3", diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 075e8d66..da9e0d0d 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -379,6 +379,7 @@ "Bcrypt compare", "Bcrypt parse", "Scrypt", + "Argon2", "NT Hash", "LM Hash", "Fletcher-8 Checksum", diff --git a/src/core/operations/Argon2.mjs b/src/core/operations/Argon2.mjs new file mode 100644 index 00000000..f36e5d0a --- /dev/null +++ b/src/core/operations/Argon2.mjs @@ -0,0 +1,101 @@ +/** + * @author Tan Zhen Yong [tzy@beyondthesprawl.com] + * @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.

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; diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index 8611ecb4..45b38c7e 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -133,6 +133,11 @@ 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("Bcrypt", async () => { const result = await chef.bcrypt("Put a Sock In It"); const strResult = result.toString(); diff --git a/webpack.config.js b/webpack.config.js index 50c4c731..6011b1dd 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -114,6 +114,8 @@ module.exports = { } }, module: { + // argon2-browser loads argon2.wasm by itself, so Webpack should not load it + noParse: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/, rules: [ { test: /\.m?js$/, @@ -127,11 +129,11 @@ module.exports = { loader: "babel-loader" }, { - test: /node-forge/, - loader: "imports-loader", - options: { - additionalCode: "var jQuery = false;" - } + test: /node_modules\/argon2-browser\/dist\/argon2\.wasm$/, + // Load argon2.wasm as base64-encoded binary file + // expected by argon2-browser + loaders: "base64-loader", + type: "javascript/auto" }, { test: /prime.worker.min.js$/, From bca4c34b3abe2e6cfea72d8589f2501e775e8aab Mon Sep 17 00:00:00 2001 From: Tan Zhen Yong Date: Mon, 7 Oct 2019 17:44:00 +0800 Subject: [PATCH 05/13] Add Argon2 hash compare operation --- src/core/config/Categories.json | 1 + src/core/operations/Argon2Compare.mjs | 58 +++++++++++++++++++++++++++ tests/node/tests/operations.mjs | 7 ++++ 3 files changed, 66 insertions(+) create mode 100644 src/core/operations/Argon2Compare.mjs diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index da9e0d0d..fec21d50 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -380,6 +380,7 @@ "Bcrypt parse", "Scrypt", "Argon2", + "Argon2 compare", "NT Hash", "LM Hash", "Fletcher-8 Checksum", diff --git a/src/core/operations/Argon2Compare.mjs b/src/core/operations/Argon2Compare.mjs new file mode 100644 index 00000000..01ad9234 --- /dev/null +++ b/src/core/operations/Argon2Compare.mjs @@ -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; diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index 45b38c7e..eaf92804 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -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(); From 266fbab8fd2e886dde24fe16036d9438255f2d9c Mon Sep 17 00:00:00 2001 From: Matt Coomber Date: Fri, 24 Mar 2023 09:57:06 +0000 Subject: [PATCH 06/13] Fix loading messages Missing comma in array --- src/web/html/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/web/html/index.html b/src/web/html/index.html index 92d52771..c602c275 100755 --- a/src/web/html/index.html +++ b/src/web/html/index.html @@ -61,7 +61,7 @@ "Symlinking emacs and vim to ed...", "Training branch predictor...", "Timing cache hits...", - "Speculatively executing recipes..." + "Speculatively executing recipes...", "Adding LLM hallucinations..." ]; From 25fe7bba67b59791a10bdfc0d218a7944b1cab60 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:15:21 +0000 Subject: [PATCH 07/13] Tidied up Argon2 operations --- package-lock.json | 21 +++++++++++++---- package.json | 7 +++--- src/core/config/Categories.json | 2 +- src/core/operations/Argon2.mjs | 26 ++++++++++++++++---- src/core/operations/Argon2Compare.mjs | 2 +- tests/node/tests/operations.mjs | 12 ---------- tests/operations/tests/Hash.mjs | 34 ++++++++++++++++++++++++++- webpack.config.js | 16 +++++++++---- 8 files changed, 88 insertions(+), 32 deletions(-) diff --git a/package-lock.json b/package-lock.json index 03c8c028..ec8805b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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": { diff --git a/package.json b/package.json index ba68d18e..e3ebb6a0 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 8a8e25f1..92754d0e 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -381,9 +381,9 @@ "Bcrypt", "Bcrypt compare", "Bcrypt parse", - "Scrypt", "Argon2", "Argon2 compare", + "Scrypt", "NT Hash", "LM Hash", "Fletcher-8 Checksum", diff --git a/src/core/operations/Argon2.mjs b/src/core/operations/Argon2.mjs index f36e5d0a..4feb881c 100644 --- a/src/core/operations/Argon2.mjs +++ b/src/core/operations/Argon2.mjs @@ -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}`); } diff --git a/src/core/operations/Argon2Compare.mjs b/src/core/operations/Argon2Compare.mjs index 01ad9234..68e48ed0 100644 --- a/src/core/operations/Argon2Compare.mjs +++ b/src/core/operations/Argon2Compare.mjs @@ -26,7 +26,7 @@ class Argon2Compare extends Operation { this.outputType = "string"; this.args = [ { - "name": "Hash", + "name": "Encoded hash", "type": "string", "value": "" } diff --git a/tests/node/tests/operations.mjs b/tests/node/tests/operations.mjs index eaf92804..8611ecb4 100644 --- a/tests/node/tests/operations.mjs +++ b/tests/node/tests/operations.mjs @@ -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(); diff --git a/tests/operations/tests/Hash.mjs b/tests/operations/tests/Hash.mjs index 95a18ffd..4480f65a 100644 --- a/tests/operations/tests/Hash.mjs +++ b/tests/operations/tests/Hash.mjs @@ -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" + ] + } + ] + } ]); diff --git a/webpack.config.js b/webpack.config.js index 6011b1dd..d318d7c2 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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" }, { From d902c7e30c586807a0b5b8a566c700b66ba7076c Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:17:11 +0000 Subject: [PATCH 08/13] Updated CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f205fe9..6932d3d7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ All major and minor version changes will be documented in this file. Details of ## Details +### [10.3.0] - 2023-03-24 +- Added 'Argon2' and 'Argon2 compare' operations [@Xenonym] | [#661] + ### [10.2.0] - 2023-03-23 - Added 'Derive HKDF key' operation [@mikecat] | [#1528] @@ -365,6 +368,7 @@ All major and minor version changes will be documented in this file. Details of +[10.3.0]: https://github.com/gchq/CyberChef/releases/tag/v10.3.0 [10.2.0]: https://github.com/gchq/CyberChef/releases/tag/v10.2.0 [10.1.0]: https://github.com/gchq/CyberChef/releases/tag/v10.1.0 [10.0.0]: https://github.com/gchq/CyberChef/releases/tag/v10.0.0 @@ -514,6 +518,7 @@ All major and minor version changes will be documented in this file. Details of [@valdelaseras]: https://github.com/valdelaseras [@brun0ne]: https://github.com/brun0ne [@joostrijneveld]: https://github.com/joostrijneveld +[@Xenonym]: https://github.com/Xenonym [8ad18b]: https://github.com/gchq/CyberChef/commit/8ad18bc7db6d9ff184ba3518686293a7685bf7b7 [9a33498]: https://github.com/gchq/CyberChef/commit/9a33498fed26a8df9c9f35f39a78a174bf50a513 @@ -629,4 +634,5 @@ All major and minor version changes will be documented in this file. Details of [#1498]: https://github.com/gchq/CyberChef/pull/1498 [#1499]: https://github.com/gchq/CyberChef/pull/1499 [#1528]: https://github.com/gchq/CyberChef/pull/1528 +[#661]: https://github.com/gchq/CyberChef/pull/661 From 3faa9d3a1ee49b18e0af381f7e02679088a65e2e Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:17:19 +0000 Subject: [PATCH 09/13] 10.3.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index ec8805b5..8a01242d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cyberchef", - "version": "10.2.0", + "version": "10.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cyberchef", - "version": "10.2.0", + "version": "10.3.0", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index e3ebb6a0..878eccda 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "10.2.0", + "version": "10.3.0", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef", From d102e1b15cf62e307927c7b762841c74892b77eb Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:39:08 +0000 Subject: [PATCH 10/13] Tidied 'Generate De Bruijn Sequence' operation --- src/core/operations/GenerateDeBruijnSequence.mjs | 8 +++----- tests/operations/tests/GenerateDeBruijnSequence.mjs | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/operations/GenerateDeBruijnSequence.mjs b/src/core/operations/GenerateDeBruijnSequence.mjs index af788585..f28d421f 100644 --- a/src/core/operations/GenerateDeBruijnSequence.mjs +++ b/src/core/operations/GenerateDeBruijnSequence.mjs @@ -4,8 +4,8 @@ * @license Apache-2.0 */ -import Operation from "../Operation"; -import OperationError from "../errors/OperationError"; +import Operation from "../Operation.mjs"; +import OperationError from "../errors/OperationError.mjs"; /** * Generate De Bruijn Sequence operation @@ -58,9 +58,7 @@ class GenerateDeBruijnSequence extends Operation { throw new OperationError("Too many permutations, please reduce k^n to under 50,000."); } - const a = []; - for (let i = 0; i < k * n; i++) a.push(0); - + const a = new Array(k * n).fill(0); const sequence = []; (function db(t = 1, p = 1) { diff --git a/tests/operations/tests/GenerateDeBruijnSequence.mjs b/tests/operations/tests/GenerateDeBruijnSequence.mjs index 48e8c4ff..d1f8352a 100644 --- a/tests/operations/tests/GenerateDeBruijnSequence.mjs +++ b/tests/operations/tests/GenerateDeBruijnSequence.mjs @@ -5,11 +5,11 @@ * @copyright Crown Copyright 2017 * @license Apache-2.0 */ -import TestRegister from "../TestRegister"; +import TestRegister from "../TestRegister.mjs"; TestRegister.addTests([ { - name: "Small Sequence", + name: "Generate De Bruijn Sequence: Small Sequence", input: "", expectedOutput: "00010111", recipeConfig: [ @@ -20,7 +20,7 @@ TestRegister.addTests([ ] }, { - name: "Long Sequence", + name: "Generate De Bruijn Sequence: Long Sequence", input: "", expectedOutput: "0000010000200003000110001200013000210002200023000310003200033001010010200103001110011200113001210012200123001310013200133002010020200203002110021200213002210022200223002310023200233003010030200303003110031200313003210032200323003310033200333010110101201013010210102201023010310103201033011020110301111011120111301121011220112301131011320113301202012030121101212012130122101222012230123101232012330130201303013110131201313013210132201323013310133201333020210202202023020310203202033021030211102112021130212102122021230213102132021330220302211022120221302221022220222302231022320223302303023110231202313023210232202323023310233202333030310303203033031110311203113031210312203123031310313203133032110321203213032210322203223032310323203233033110331203313033210332203323033310333203333111112111131112211123111321113311212112131122211223112321123311312113131132211323113321133312122121231213212133122131222212223122321223312313123221232312332123331313213133132221322313232132331332213323133321333322222322233223232233323233233333", recipeConfig: [ From e46a7448d9e3d61b02ca71b07ac95e604c1169f1 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:40:07 +0000 Subject: [PATCH 11/13] Fixed De Bruijn test import --- tests/operations/tests/GenerateDeBruijnSequence.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/operations/tests/GenerateDeBruijnSequence.mjs b/tests/operations/tests/GenerateDeBruijnSequence.mjs index d1f8352a..24490d1c 100644 --- a/tests/operations/tests/GenerateDeBruijnSequence.mjs +++ b/tests/operations/tests/GenerateDeBruijnSequence.mjs @@ -5,7 +5,7 @@ * @copyright Crown Copyright 2017 * @license Apache-2.0 */ -import TestRegister from "../TestRegister.mjs"; +import TestRegister from "../../lib/TestRegister.mjs"; TestRegister.addTests([ { From 7bb0649b27bbfe5c9668e885127ca7c10ba944cb Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:41:24 +0000 Subject: [PATCH 12/13] Updated CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6932d3d7..1d13e56d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ All major and minor version changes will be documented in this file. Details of ## Details +### [10.4.0] - 2023-03-24 +- Added 'Generate De Bruijn Sequence' operation [@gchq77703] | [#493] + ### [10.3.0] - 2023-03-24 - Added 'Argon2' and 'Argon2 compare' operations [@Xenonym] | [#661] @@ -368,6 +371,7 @@ All major and minor version changes will be documented in this file. Details of +[10.4.0]: https://github.com/gchq/CyberChef/releases/tag/v10.4.0 [10.3.0]: https://github.com/gchq/CyberChef/releases/tag/v10.3.0 [10.2.0]: https://github.com/gchq/CyberChef/releases/tag/v10.2.0 [10.1.0]: https://github.com/gchq/CyberChef/releases/tag/v10.1.0 @@ -519,6 +523,7 @@ All major and minor version changes will be documented in this file. Details of [@brun0ne]: https://github.com/brun0ne [@joostrijneveld]: https://github.com/joostrijneveld [@Xenonym]: https://github.com/Xenonym +[@gchq77703]: https://github.com/gchq77703 [8ad18b]: https://github.com/gchq/CyberChef/commit/8ad18bc7db6d9ff184ba3518686293a7685bf7b7 [9a33498]: https://github.com/gchq/CyberChef/commit/9a33498fed26a8df9c9f35f39a78a174bf50a513 @@ -635,4 +640,5 @@ All major and minor version changes will be documented in this file. Details of [#1499]: https://github.com/gchq/CyberChef/pull/1499 [#1528]: https://github.com/gchq/CyberChef/pull/1528 [#661]: https://github.com/gchq/CyberChef/pull/661 +[#493]: https://github.com/gchq/CyberChef/pull/493 From 1bc88728f04135aa99f4126e839d62cc8291056b Mon Sep 17 00:00:00 2001 From: n1474335 Date: Fri, 24 Mar 2023 22:41:40 +0000 Subject: [PATCH 13/13] 10.4.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8a01242d..9b939b88 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cyberchef", - "version": "10.3.0", + "version": "10.4.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cyberchef", - "version": "10.3.0", + "version": "10.4.0", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { diff --git a/package.json b/package.json index 878eccda..f5d9a7f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cyberchef", - "version": "10.3.0", + "version": "10.4.0", "description": "The Cyber Swiss Army Knife for encryption, encoding, compression and data analysis.", "author": "n1474335 ", "homepage": "https://gchq.github.io/CyberChef",