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