OSDN Git Service

- add crypto-js library(for new hash access method).
[feedblog/feedblog.git] / js / crypto-js / components / x64-core.js
diff --git a/js/crypto-js/components/x64-core.js b/js/crypto-js/components/x64-core.js
new file mode 100644 (file)
index 0000000..7a5be33
--- /dev/null
@@ -0,0 +1,290 @@
+/*
+CryptoJS v3.1.2
+code.google.com/p/crypto-js
+(c) 2009-2013 by Jeff Mott. All rights reserved.
+code.google.com/p/crypto-js/wiki/License
+*/
+(function (undefined) {\r
+    // Shortcuts\r
+    var C = CryptoJS;\r
+    var C_lib = C.lib;\r
+    var Base = C_lib.Base;\r
+    var X32WordArray = C_lib.WordArray;\r
+\r
+    /**\r
+     * x64 namespace.\r
+     */\r
+    var C_x64 = C.x64 = {};\r
+\r
+    /**\r
+     * A 64-bit word.\r
+     */\r
+    var X64Word = C_x64.Word = Base.extend({\r
+        /**\r
+         * Initializes a newly created 64-bit word.\r
+         *\r
+         * @param {number} high The high 32 bits.\r
+         * @param {number} low The low 32 bits.\r
+         *\r
+         * @example\r
+         *\r
+         *     var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);\r
+         */\r
+        init: function (high, low) {\r
+            this.high = high;\r
+            this.low = low;\r
+        }\r
+\r
+        /**\r
+         * Bitwise NOTs this word.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after negating.\r
+         *\r
+         * @example\r
+         *\r
+         *     var negated = x64Word.not();\r
+         */\r
+        // not: function () {\r
+            // var high = ~this.high;\r
+            // var low = ~this.low;\r
+\r
+            // return X64Word.create(high, low);\r
+        // },\r
+\r
+        /**\r
+         * Bitwise ANDs this word with the passed word.\r
+         *\r
+         * @param {X64Word} word The x64-Word to AND with this word.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after ANDing.\r
+         *\r
+         * @example\r
+         *\r
+         *     var anded = x64Word.and(anotherX64Word);\r
+         */\r
+        // and: function (word) {\r
+            // var high = this.high & word.high;\r
+            // var low = this.low & word.low;\r
+\r
+            // return X64Word.create(high, low);\r
+        // },\r
+\r
+        /**\r
+         * Bitwise ORs this word with the passed word.\r
+         *\r
+         * @param {X64Word} word The x64-Word to OR with this word.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after ORing.\r
+         *\r
+         * @example\r
+         *\r
+         *     var ored = x64Word.or(anotherX64Word);\r
+         */\r
+        // or: function (word) {\r
+            // var high = this.high | word.high;\r
+            // var low = this.low | word.low;\r
+\r
+            // return X64Word.create(high, low);\r
+        // },\r
+\r
+        /**\r
+         * Bitwise XORs this word with the passed word.\r
+         *\r
+         * @param {X64Word} word The x64-Word to XOR with this word.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after XORing.\r
+         *\r
+         * @example\r
+         *\r
+         *     var xored = x64Word.xor(anotherX64Word);\r
+         */\r
+        // xor: function (word) {\r
+            // var high = this.high ^ word.high;\r
+            // var low = this.low ^ word.low;\r
+\r
+            // return X64Word.create(high, low);\r
+        // },\r
+\r
+        /**\r
+         * Shifts this word n bits to the left.\r
+         *\r
+         * @param {number} n The number of bits to shift.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after shifting.\r
+         *\r
+         * @example\r
+         *\r
+         *     var shifted = x64Word.shiftL(25);\r
+         */\r
+        // shiftL: function (n) {\r
+            // if (n < 32) {\r
+                // var high = (this.high << n) | (this.low >>> (32 - n));\r
+                // var low = this.low << n;\r
+            // } else {\r
+                // var high = this.low << (n - 32);\r
+                // var low = 0;\r
+            // }\r
+\r
+            // return X64Word.create(high, low);\r
+        // },\r
+\r
+        /**\r
+         * Shifts this word n bits to the right.\r
+         *\r
+         * @param {number} n The number of bits to shift.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after shifting.\r
+         *\r
+         * @example\r
+         *\r
+         *     var shifted = x64Word.shiftR(7);\r
+         */\r
+        // shiftR: function (n) {\r
+            // if (n < 32) {\r
+                // var low = (this.low >>> n) | (this.high << (32 - n));\r
+                // var high = this.high >>> n;\r
+            // } else {\r
+                // var low = this.high >>> (n - 32);\r
+                // var high = 0;\r
+            // }\r
+\r
+            // return X64Word.create(high, low);\r
+        // },\r
+\r
+        /**\r
+         * Rotates this word n bits to the left.\r
+         *\r
+         * @param {number} n The number of bits to rotate.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after rotating.\r
+         *\r
+         * @example\r
+         *\r
+         *     var rotated = x64Word.rotL(25);\r
+         */\r
+        // rotL: function (n) {\r
+            // return this.shiftL(n).or(this.shiftR(64 - n));\r
+        // },\r
+\r
+        /**\r
+         * Rotates this word n bits to the right.\r
+         *\r
+         * @param {number} n The number of bits to rotate.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after rotating.\r
+         *\r
+         * @example\r
+         *\r
+         *     var rotated = x64Word.rotR(7);\r
+         */\r
+        // rotR: function (n) {\r
+            // return this.shiftR(n).or(this.shiftL(64 - n));\r
+        // },\r
+\r
+        /**\r
+         * Adds this word with the passed word.\r
+         *\r
+         * @param {X64Word} word The x64-Word to add with this word.\r
+         *\r
+         * @return {X64Word} A new x64-Word object after adding.\r
+         *\r
+         * @example\r
+         *\r
+         *     var added = x64Word.add(anotherX64Word);\r
+         */\r
+        // add: function (word) {\r
+            // var low = (this.low + word.low) | 0;\r
+            // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;\r
+            // var high = (this.high + word.high + carry) | 0;\r
+\r
+            // return X64Word.create(high, low);\r
+        // }\r
+    });\r
+\r
+    /**\r
+     * An array of 64-bit words.\r
+     *\r
+     * @property {Array} words The array of CryptoJS.x64.Word objects.\r
+     * @property {number} sigBytes The number of significant bytes in this word array.\r
+     */\r
+    var X64WordArray = C_x64.WordArray = Base.extend({\r
+        /**\r
+         * Initializes a newly created word array.\r
+         *\r
+         * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.\r
+         * @param {number} sigBytes (Optional) The number of significant bytes in the words.\r
+         *\r
+         * @example\r
+         *\r
+         *     var wordArray = CryptoJS.x64.WordArray.create();\r
+         *\r
+         *     var wordArray = CryptoJS.x64.WordArray.create([\r
+         *         CryptoJS.x64.Word.create(0x00010203, 0x04050607),\r
+         *         CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)\r
+         *     ]);\r
+         *\r
+         *     var wordArray = CryptoJS.x64.WordArray.create([\r
+         *         CryptoJS.x64.Word.create(0x00010203, 0x04050607),\r
+         *         CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)\r
+         *     ], 10);\r
+         */\r
+        init: function (words, sigBytes) {\r
+            words = this.words = words || [];\r
+\r
+            if (sigBytes != undefined) {\r
+                this.sigBytes = sigBytes;\r
+            } else {\r
+                this.sigBytes = words.length * 8;\r
+            }\r
+        },\r
+\r
+        /**\r
+         * Converts this 64-bit word array to a 32-bit word array.\r
+         *\r
+         * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.\r
+         *\r
+         * @example\r
+         *\r
+         *     var x32WordArray = x64WordArray.toX32();\r
+         */\r
+        toX32: function () {\r
+            // Shortcuts\r
+            var x64Words = this.words;\r
+            var x64WordsLength = x64Words.length;\r
+\r
+            // Convert\r
+            var x32Words = [];\r
+            for (var i = 0; i < x64WordsLength; i++) {\r
+                var x64Word = x64Words[i];\r
+                x32Words.push(x64Word.high);\r
+                x32Words.push(x64Word.low);\r
+            }\r
+\r
+            return X32WordArray.create(x32Words, this.sigBytes);\r
+        },\r
+\r
+        /**\r
+         * Creates a copy of this word array.\r
+         *\r
+         * @return {X64WordArray} The clone.\r
+         *\r
+         * @example\r
+         *\r
+         *     var clone = x64WordArray.clone();\r
+         */\r
+        clone: function () {\r
+            var clone = Base.clone.call(this);\r
+\r
+            // Clone "words" array\r
+            var words = clone.words = this.words.slice(0);\r
+\r
+            // Clone each X64Word object\r
+            var wordsLength = words.length;\r
+            for (var i = 0; i < wordsLength; i++) {\r
+                words[i] = words[i].clone();\r
+            }\r
+\r
+            return clone;\r
+        }\r
+    });\r
+}());\r