소스 검색

Added Snefru hashing operation

n1474335 7 년 전
부모
커밋
7557e1e9e5
7개의 변경된 파일115개의 추가작업 그리고 4개의 파일을 삭제
  1. 3 3
      package-lock.json
  2. 1 1
      package.json
  3. 1 0
      src/core/config/Categories.js
  4. 18 0
      src/core/config/OperationConfig.js
  5. 1 0
      src/core/config/modules/Hashing.js
  6. 25 0
      src/core/operations/Hash.js
  7. 66 0
      test/tests/operations/Hash.js

+ 3 - 3
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",

+ 1 - 1
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",

+ 1 - 0
src/core/config/Categories.js

@@ -257,6 +257,7 @@ const Categories = [
             "RIPEMD",
             "HAS-160",
             "Whirlpool",
+            "Snefru",
             "HMAC",
             "Fletcher-8 Checksum",
             "Fletcher-16 Checksum",

+ 18 - 0
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.<br><br>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.",

+ 1 - 0
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,

+ 25 - 0
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

+ 66 - 0
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!",