diff --git a/package-lock.json b/package-lock.json
index 02c0ff33f..e231bb6eb 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 a58cc3a64..0a3aeb4e5 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 4a551d377..d1ed81327 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 5e1aae87f..d302abee2 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 235a9cfe1..c19fc3ed1 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 b165f51e2..6d1d3a166 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 a0cd5da27..19a9a09ef 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!",