From 7557e1e9e5a22017439781678e78484aba2fcd4d Mon Sep 17 00:00:00 2001 From: n1474335 Date: Wed, 27 Sep 2017 15:33:14 +0000 Subject: [PATCH] Added Snefru hashing operation --- package-lock.json | 6 +-- package.json | 2 +- src/core/config/Categories.js | 1 + src/core/config/OperationConfig.js | 18 ++++++++ src/core/config/modules/Hashing.js | 1 + src/core/operations/Hash.js | 25 +++++++++++ test/tests/operations/Hash.js | 66 ++++++++++++++++++++++++++++++ 7 files changed, 115 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 02c0ff33..e231bb6e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1755,9 +1755,9 @@ } }, "crypto-api": { - "version": "0.7.4", - "resolved": "https://registry.npmjs.org/crypto-api/-/crypto-api-0.7.4.tgz", - "integrity": "sha1-wuiM1WOWxJ0A75uA40lGUKdIKoE=" + "version": "0.7.5", + "resolved": "https://registry.npmjs.org/crypto-api/-/crypto-api-0.7.5.tgz", + "integrity": "sha1-TCc3K8s85mnSKNV7NZG8YRjFKdU=" }, "crypto-browserify": { "version": "3.11.1", diff --git a/package.json b/package.json index a58cc3a6..0a3aeb4e 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "bootstrap": "^3.3.7", "bootstrap-colorpicker": "^2.5.1", "bootstrap-switch": "^3.3.4", - "crypto-api": "^0.7.4", + "crypto-api": "^0.7.5", "crypto-js": "^3.1.9-1", "diff": "^3.3.1", "escodegen": "^1.9.0", diff --git a/src/core/config/Categories.js b/src/core/config/Categories.js index 4a551d37..d1ed8132 100755 --- a/src/core/config/Categories.js +++ b/src/core/config/Categories.js @@ -257,6 +257,7 @@ const Categories = [ "RIPEMD", "HAS-160", "Whirlpool", + "Snefru", "HMAC", "Fletcher-8 Checksum", "Fletcher-16 Checksum", diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 5e1aae87..d302abee 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3011,6 +3011,24 @@ const OperationConfig = { } ] }, + "Snefru": { + module: "Hashing", + description: "Snefru is a cryptographic hash function invented by Ralph Merkle in 1990 while working at Xerox PARC. The function supports 128-bit and 256-bit output. It was named after the Egyptian Pharaoh Sneferu, continuing the tradition of the Khufu and Khafre block ciphers.

The original design of Snefru was shown to be insecure by Eli Biham and Adi Shamir who were able to use differential cryptanalysis to find hash collisions. The design was then modified by increasing the number of iterations of the main pass of the algorithm from two to eight.", + inputType: "string", + outputType: "string", + args: [ + { + name: "Rounds", + type: "option", + value: Hash.SNEFRU_ROUNDS + }, + { + name: "Size", + type: "option", + value: Hash.SNEFRU_SIZE + } + ] + }, "HMAC": { module: "Hashing", description: "Keyed-Hash Message Authentication Codes (HMAC) are a mechanism for message authentication using cryptographic hash functions.", diff --git a/src/core/config/modules/Hashing.js b/src/core/config/modules/Hashing.js index 235a9cfe..c19fc3ed 100644 --- a/src/core/config/modules/Hashing.js +++ b/src/core/config/modules/Hashing.js @@ -33,6 +33,7 @@ OpModules.Hashing = { "RIPEMD": Hash.runRIPEMD, "HAS-160": Hash.runHAS, "Whirlpool": Hash.runWhirlpool, + "Snefru": Hash.runSnefru, "HMAC": Hash.runHMAC, "Fletcher-8 Checksum": Checksum.runFletcher8, "Fletcher-16 Checksum": Checksum.runFletcher16, diff --git a/src/core/operations/Hash.js b/src/core/operations/Hash.js index b165f51e..6d1d3a16 100755 --- a/src/core/operations/Hash.js +++ b/src/core/operations/Hash.js @@ -294,6 +294,31 @@ const Hash = { }, + /** + * @constant + * @default + */ + SNEFRU_ROUNDS: ["8", "4", "2"], + /** + * @constant + * @default + */ + SNEFRU_SIZE: ["256", "128"], + + /** + * Snefru operation. + * + * @param {string} input + * @param {Object[]} args + * @returns {string} + */ + runSnefru: function (input, args) { + const rounds = args[0], + size = args[1]; + return CryptoApi.hash(`snefru-${rounds}-${size}`, input, {}).stringify("hex"); + }, + + /** * @constant * @default diff --git a/test/tests/operations/Hash.js b/test/tests/operations/Hash.js index a0cd5da2..19a9a09e 100644 --- a/test/tests/operations/Hash.js +++ b/test/tests/operations/Hash.js @@ -338,6 +338,72 @@ TestRegister.addTests([ } ] }, + { + name: "Snefru 2 128", + input: "Hello, World!", + expectedOutput: "a4ad2b8848580511d0884fb4233a7e7a", + recipeConfig: [ + { + "op": "Snefru", + "args": ["2", "128"] + } + ] + }, + { + name: "Snefru 4 128", + input: "Hello, World!", + expectedOutput: "d154eae2c9ffbcd2e1bdaf0b84736126", + recipeConfig: [ + { + "op": "Snefru", + "args": ["4", "128"] + } + ] + }, + { + name: "Snefru 8 128", + input: "Hello, World!", + expectedOutput: "6f3d55b69557abb0a3c4e9de9d29ba5d", + recipeConfig: [ + { + "op": "Snefru", + "args": ["8", "128"] + } + ] + }, + { + name: "Snefru 2 256", + input: "Hello, World!", + expectedOutput: "65736daba648de28ef4c4a316b4684584ecf9f22ddb5c457729e6bf0f40113c4", + recipeConfig: [ + { + "op": "Snefru", + "args": ["2", "256"] + } + ] + }, + { + name: "Snefru 4 256", + input: "Hello, World!", + expectedOutput: "71b0ea4b3e33f2e58bcc67c8a8de060b99ec0107355bbfdc18d8f65f0194ffcc", + recipeConfig: [ + { + "op": "Snefru", + "args": ["4", "256"] + } + ] + }, + { + name: "Snefru 8 256", + input: "Hello, World!", + expectedOutput: "255cd401414c79588cf689e8d5ff0536a2cfab83fcae36e654f202b09bc4b8a7", + recipeConfig: [ + { + "op": "Snefru", + "args": ["8", "256"] + } + ] + }, { name: "HMAC SHA256", input: "Hello, World!",