AI销管
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

304 rivejä
8.7 KiB

  1. ;(function (root, factory) {
  2. if (typeof exports === "object") {
  3. // CommonJS
  4. module.exports = exports = factory(require("./core"));
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. // AMD
  8. define(["./core"], factory);
  9. }
  10. else {
  11. // Global (browser)
  12. factory(root.CryptoJS);
  13. }
  14. }(this, function (CryptoJS) {
  15. (function (undefined) {
  16. // Shortcuts
  17. var C = CryptoJS;
  18. var C_lib = C.lib;
  19. var Base = C_lib.Base;
  20. var X32WordArray = C_lib.WordArray;
  21. /**
  22. * x64 namespace.
  23. */
  24. var C_x64 = C.x64 = {};
  25. /**
  26. * A 64-bit word.
  27. */
  28. var X64Word = C_x64.Word = Base.extend({
  29. /**
  30. * Initializes a newly created 64-bit word.
  31. *
  32. * @param {number} high The high 32 bits.
  33. * @param {number} low The low 32 bits.
  34. *
  35. * @example
  36. *
  37. * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
  38. */
  39. init: function (high, low) {
  40. this.high = high;
  41. this.low = low;
  42. }
  43. /**
  44. * Bitwise NOTs this word.
  45. *
  46. * @return {X64Word} A new x64-Word object after negating.
  47. *
  48. * @example
  49. *
  50. * var negated = x64Word.not();
  51. */
  52. // not: function () {
  53. // var high = ~this.high;
  54. // var low = ~this.low;
  55. // return X64Word.create(high, low);
  56. // },
  57. /**
  58. * Bitwise ANDs this word with the passed word.
  59. *
  60. * @param {X64Word} word The x64-Word to AND with this word.
  61. *
  62. * @return {X64Word} A new x64-Word object after ANDing.
  63. *
  64. * @example
  65. *
  66. * var anded = x64Word.and(anotherX64Word);
  67. */
  68. // and: function (word) {
  69. // var high = this.high & word.high;
  70. // var low = this.low & word.low;
  71. // return X64Word.create(high, low);
  72. // },
  73. /**
  74. * Bitwise ORs this word with the passed word.
  75. *
  76. * @param {X64Word} word The x64-Word to OR with this word.
  77. *
  78. * @return {X64Word} A new x64-Word object after ORing.
  79. *
  80. * @example
  81. *
  82. * var ored = x64Word.or(anotherX64Word);
  83. */
  84. // or: function (word) {
  85. // var high = this.high | word.high;
  86. // var low = this.low | word.low;
  87. // return X64Word.create(high, low);
  88. // },
  89. /**
  90. * Bitwise XORs this word with the passed word.
  91. *
  92. * @param {X64Word} word The x64-Word to XOR with this word.
  93. *
  94. * @return {X64Word} A new x64-Word object after XORing.
  95. *
  96. * @example
  97. *
  98. * var xored = x64Word.xor(anotherX64Word);
  99. */
  100. // xor: function (word) {
  101. // var high = this.high ^ word.high;
  102. // var low = this.low ^ word.low;
  103. // return X64Word.create(high, low);
  104. // },
  105. /**
  106. * Shifts this word n bits to the left.
  107. *
  108. * @param {number} n The number of bits to shift.
  109. *
  110. * @return {X64Word} A new x64-Word object after shifting.
  111. *
  112. * @example
  113. *
  114. * var shifted = x64Word.shiftL(25);
  115. */
  116. // shiftL: function (n) {
  117. // if (n < 32) {
  118. // var high = (this.high << n) | (this.low >>> (32 - n));
  119. // var low = this.low << n;
  120. // } else {
  121. // var high = this.low << (n - 32);
  122. // var low = 0;
  123. // }
  124. // return X64Word.create(high, low);
  125. // },
  126. /**
  127. * Shifts this word n bits to the right.
  128. *
  129. * @param {number} n The number of bits to shift.
  130. *
  131. * @return {X64Word} A new x64-Word object after shifting.
  132. *
  133. * @example
  134. *
  135. * var shifted = x64Word.shiftR(7);
  136. */
  137. // shiftR: function (n) {
  138. // if (n < 32) {
  139. // var low = (this.low >>> n) | (this.high << (32 - n));
  140. // var high = this.high >>> n;
  141. // } else {
  142. // var low = this.high >>> (n - 32);
  143. // var high = 0;
  144. // }
  145. // return X64Word.create(high, low);
  146. // },
  147. /**
  148. * Rotates this word n bits to the left.
  149. *
  150. * @param {number} n The number of bits to rotate.
  151. *
  152. * @return {X64Word} A new x64-Word object after rotating.
  153. *
  154. * @example
  155. *
  156. * var rotated = x64Word.rotL(25);
  157. */
  158. // rotL: function (n) {
  159. // return this.shiftL(n).or(this.shiftR(64 - n));
  160. // },
  161. /**
  162. * Rotates this word n bits to the right.
  163. *
  164. * @param {number} n The number of bits to rotate.
  165. *
  166. * @return {X64Word} A new x64-Word object after rotating.
  167. *
  168. * @example
  169. *
  170. * var rotated = x64Word.rotR(7);
  171. */
  172. // rotR: function (n) {
  173. // return this.shiftR(n).or(this.shiftL(64 - n));
  174. // },
  175. /**
  176. * Adds this word with the passed word.
  177. *
  178. * @param {X64Word} word The x64-Word to add with this word.
  179. *
  180. * @return {X64Word} A new x64-Word object after adding.
  181. *
  182. * @example
  183. *
  184. * var added = x64Word.add(anotherX64Word);
  185. */
  186. // add: function (word) {
  187. // var low = (this.low + word.low) | 0;
  188. // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
  189. // var high = (this.high + word.high + carry) | 0;
  190. // return X64Word.create(high, low);
  191. // }
  192. });
  193. /**
  194. * An array of 64-bit words.
  195. *
  196. * @property {Array} words The array of CryptoJS.x64.Word objects.
  197. * @property {number} sigBytes The number of significant bytes in this word array.
  198. */
  199. var X64WordArray = C_x64.WordArray = Base.extend({
  200. /**
  201. * Initializes a newly created word array.
  202. *
  203. * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
  204. * @param {number} sigBytes (Optional) The number of significant bytes in the words.
  205. *
  206. * @example
  207. *
  208. * var wordArray = CryptoJS.x64.WordArray.create();
  209. *
  210. * var wordArray = CryptoJS.x64.WordArray.create([
  211. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  212. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  213. * ]);
  214. *
  215. * var wordArray = CryptoJS.x64.WordArray.create([
  216. * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
  217. * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
  218. * ], 10);
  219. */
  220. init: function (words, sigBytes) {
  221. words = this.words = words || [];
  222. if (sigBytes != undefined) {
  223. this.sigBytes = sigBytes;
  224. } else {
  225. this.sigBytes = words.length * 8;
  226. }
  227. },
  228. /**
  229. * Converts this 64-bit word array to a 32-bit word array.
  230. *
  231. * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
  232. *
  233. * @example
  234. *
  235. * var x32WordArray = x64WordArray.toX32();
  236. */
  237. toX32: function () {
  238. // Shortcuts
  239. var x64Words = this.words;
  240. var x64WordsLength = x64Words.length;
  241. // Convert
  242. var x32Words = [];
  243. for (var i = 0; i < x64WordsLength; i++) {
  244. var x64Word = x64Words[i];
  245. x32Words.push(x64Word.high);
  246. x32Words.push(x64Word.low);
  247. }
  248. return X32WordArray.create(x32Words, this.sigBytes);
  249. },
  250. /**
  251. * Creates a copy of this word array.
  252. *
  253. * @return {X64WordArray} The clone.
  254. *
  255. * @example
  256. *
  257. * var clone = x64WordArray.clone();
  258. */
  259. clone: function () {
  260. var clone = Base.clone.call(this);
  261. // Clone "words" array
  262. var words = clone.words = this.words.slice(0);
  263. // Clone each X64Word object
  264. var wordsLength = words.length;
  265. for (var i = 0; i < wordsLength; i++) {
  266. words[i] = words[i].clone();
  267. }
  268. return clone;
  269. }
  270. });
  271. }());
  272. return CryptoJS;
  273. }));