1 (function(e
){if("object"==typeof exports
&&"undefined"!=typeof module
)module
.exports
=e();else if("function"==typeof define
&&define
.amd
)define([],e
);else{var f
;"undefined"!=typeof window
?f
=window:"undefined"!=typeof global
?f
=global:"undefined"!=typeof self
&&(f
=self
),f
.Bitcoin
=e()}})(function(){var define
,module
,exports
;return (function e(t
,n
,r
){function s(o
,u
){if(!n
[o
]){if(!t
[o
]){var a
=typeof require
=="function"&&require
;if(!u
&&a
)return a(o
,!0);if(i
)return i(o
,!0);throw new Error("Cannot find module '"+o
+"'")}var f
=n
[o
]={exports:{}};t
[o
][0].call(f
.exports
,function(e
){var n
=t
[o
][1][e
];return s(n
?n:e
)},f
,f
.exports
,e
,t
,n
,r
)}return n
[o
].exports
}var i
=typeof require
=="function"&&require
;for(var o
=0;o
<r
.length
;o
++)s(r
[o
]);return s
})({1:[function(_dereq_
,module
,exports
){
2 var assert
= _dereq_('assert')
4 module
.exports
= BigInteger
6 // JavaScript engine analysis
7 var canary
= 0xdeadbeefcafe;
8 var j_lm
= ((canary
&0xffffff)==0xefcafe);
10 // (public) Constructor
11 function BigInteger(a
,b
,c
) {
12 if (!(this instanceof BigInteger
)) {
13 return new BigInteger(a
, b
, c
);
17 if("number" == typeof a
) this.fromNumber(a
,b
,c
);
18 else if(b
== null && "string" != typeof a
) this.fromString(a
,256);
19 else this.fromString(a
,b
);
23 var proto
= BigInteger
.prototype;
25 // return new, unset BigInteger
26 function nbi() { return new BigInteger(null); }
31 // am: Compute w_j += (x*this_i), propagate carries,
32 // c is initial carry, returns final carry.
33 // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
34 // We need to select the fastest one that works in this environment.
36 // am1: use a single mult and divide to get the high bits,
37 // max digit bits should be 26 because
38 // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
39 function am1(i
,x
,w
,j
,c
,n
) {
41 var v
= x
*this[i
++]+w
[j
]+c
;
42 c
= Math
.floor(v
/0x4000000);
47 // am2 avoids a big mult-and-extract completely.
48 // Max digit bits should be <= 30 because we do bitwise ops
49 // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
50 function am2(i
,x
,w
,j
,c
,n
) {
51 var xl
= x
&0x7fff, xh
= x
>>15;
53 var l
= this[i
]&0x7fff;
54 var h
= this[i
++]>>15;
56 l
= xl
*l
+((m
&0x7fff)<<15)+w
[j
]+(c
&0x3fffffff);
57 c
= (l
>>>30)+(m
>>>15)+xh
*h
+(c
>>>30);
58 w
[j
++] = l
&0x3fffffff;
62 // Alternately, set max digit bits to 28 since some
63 // browsers slow down when dealing with 32-bit numbers.
64 function am3(i
,x
,w
,j
,c
,n
) {
65 var xl
= x
&0x3fff, xh
= x
>>14;
67 var l
= this[i
]&0x3fff;
68 var h
= this[i
++]>>14;
70 l
= xl
*l
+((m
&0x3fff)<<14)+w
[j
]+c
;
71 c
= (l
>>28)+(m
>>14)+xh
*h
;
78 BigInteger
.prototype.am
= am1
;
82 if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
83 BigInteger.prototype.am = am2;
86 else if(j_lm && (navigator.appName != "Netscape")) {
87 BigInteger.prototype.am = am1;
90 else { // Mozilla/Netscape seems to prefer am3
91 BigInteger.prototype.am = am3;
96 BigInteger
.prototype.DB
= dbits
;
97 BigInteger
.prototype.DM
= ((1<<dbits
)-1);
98 var DV
= BigInteger
.prototype.DV
= (1<<dbits
);
101 BigInteger
.prototype.FV
= Math
.pow(2,BI_FP
);
102 BigInteger
.prototype.F1
= BI_FP
-dbits
;
103 BigInteger
.prototype.F2
= 2*dbits
-BI_FP
;
106 var BI_RM
= "0123456789abcdefghijklmnopqrstuvwxyz";
107 var BI_RC
= new Array();
109 rr
= "0".charCodeAt(0);
110 for(vv
= 0; vv
<= 9; ++vv
) BI_RC
[rr
++] = vv
;
111 rr
= "a".charCodeAt(0);
112 for(vv
= 10; vv
< 36; ++vv
) BI_RC
[rr
++] = vv
;
113 rr
= "A".charCodeAt(0);
114 for(vv
= 10; vv
< 36; ++vv
) BI_RC
[rr
++] = vv
;
116 function int2char(n
) { return BI_RM
.charAt(n
); }
117 function intAt(s
,i
) {
118 var c
= BI_RC
[s
.charCodeAt(i
)];
119 return (c
==null)?-1:c
;
122 // (protected) copy this to r
123 function bnpCopyTo(r
) {
124 for(var i
= this.t
-1; i
>= 0; --i
) r
[i
] = this[i
];
129 // (protected) set from integer value x, -DV <= x < DV
130 function bnpFromInt(x
) {
133 if(x
> 0) this[0] = x
;
134 else if(x
< -1) this[0] = x
+DV
;
138 // return bigint initialized to value
139 function nbv(i
) { var r
= nbi(); r
.fromInt(i
); return r
; }
141 // (protected) set from string and radix
142 function bnpFromString(s
,b
) {
147 else if(b
== 8) k
= 3;
148 else if(b
== 256) k
= 8; // byte array
149 else if(b
== 2) k
= 1;
150 else if(b
== 32) k
= 5;
151 else if(b
== 4) k
= 2;
152 else { self
.fromRadix(s
,b
); return; }
155 var i
= s
.length
, mi
= false, sh
= 0;
157 var x
= (k
==8)?s
[i
]&0xff:intAt(s
,i
);
159 if(s
.charAt(i
) == "-") mi
= true;
165 else if(sh
+k
> self
.DB
) {
166 self
[self
.t
-1] |= (x
&((1<<(self
.DB
-sh
))-1))<<sh
;
167 self
[self
.t
++] = (x
>>(self
.DB
-sh
));
170 self
[self
.t
-1] |= x
<<sh
;
172 if(sh
>= self
.DB
) sh
-= self
.DB
;
174 if(k
== 8 && (s
[0]&0x80) != 0) {
176 if(sh
> 0) self
[self
.t
-1] |= ((1<<(self
.DB
-sh
))-1)<<sh
;
179 if(mi
) BigInteger
.ZERO
.subTo(self
,self
);
182 // (protected) clamp off excess high words
183 function bnpClamp() {
184 var c
= this.s
&this.DM
;
185 while(this.t
> 0 && this[this.t
-1] == c
) --this.t
;
188 // (public) return string representation in given radix
189 function bnToString(b
) {
191 if(self
.s
< 0) return "-"+self
.negate().toString(b
);
194 else if(b
== 8) k
= 3;
195 else if(b
== 2) k
= 1;
196 else if(b
== 32) k
= 5;
197 else if(b
== 4) k
= 2;
198 else return self
.toRadix(b
);
199 var km
= (1<<k
)-1, d
, m
= false, r
= "", i
= self
.t
;
200 var p
= self
.DB
-(i
*self
.DB
)%k
;
202 if(p
< self
.DB
&& (d
= self
[i
]>>p
) > 0) { m
= true; r
= int2char(d
); }
205 d
= (self
[i
]&((1<<p
)-1))<<(k
-p
);
206 d
|= self
[--i
]>>(p
+=self
.DB
-k
);
209 d
= (self
[i
]>>(p
-=k
))&km
;
210 if(p
<= 0) { p
+= self
.DB
; --i
; }
213 if(m
) r
+= int2char(d
);
220 function bnNegate() { var r
= nbi(); BigInteger
.ZERO
.subTo(this,r
); return r
; }
223 function bnAbs() { return (this.s
<0)?this.negate():this; }
225 // (public) return + if this > a, - if this < a, 0 if equal
226 function bnCompareTo(a
) {
231 if(r
!= 0) return (this.s
<0)?-r:r
;
232 while(--i
>= 0) if((r
=this[i
]-a
[i
]) != 0) return r
;
236 // returns bit length of the integer x
239 if((t
=x
>>>16) != 0) { x
= t
; r
+= 16; }
240 if((t
=x
>>8) != 0) { x
= t
; r
+= 8; }
241 if((t
=x
>>4) != 0) { x
= t
; r
+= 4; }
242 if((t
=x
>>2) != 0) { x
= t
; r
+= 2; }
243 if((t
=x
>>1) != 0) { x
= t
; r
+= 1; }
247 // (public) return the number of bits in "this"
248 function bnBitLength() {
249 if(this.t
<= 0) return 0;
250 return this.DB
*(this.t
-1)+nbits(this[this.t
-1]^(this.s
&this.DM
));
253 // (protected) r = this << n*DB
254 function bnpDLShiftTo(n
,r
) {
256 for(i
= this.t
-1; i
>= 0; --i
) r
[i
+n
] = this[i
];
257 for(i
= n
-1; i
>= 0; --i
) r
[i
] = 0;
262 // (protected) r = this >> n*DB
263 function bnpDRShiftTo(n
,r
) {
264 for(var i
= n
; i
< this.t
; ++i
) r
[i
-n
] = this[i
];
265 r
.t
= Math
.max(this.t
-n
,0);
269 // (protected) r = this << n
270 function bnpLShiftTo(n
,r
) {
273 var cbs
= self
.DB
-bs
;
275 var ds
= Math
.floor(n
/self
.DB
), c
= (self
.s
<<bs
)&self
.DM
, i
;
276 for(i
= self
.t
-1; i
>= 0; --i
) {
277 r
[i
+ds
+1] = (self
[i
]>>cbs
)|c
;
278 c
= (self
[i
]&bm
)<<bs
;
280 for(i
= ds
-1; i
>= 0; --i
) r
[i
] = 0;
287 // (protected) r = this >> n
288 function bnpRShiftTo(n
,r
) {
291 var ds
= Math
.floor(n
/self
.DB
);
292 if(ds
>= self
.t
) { r
.t
= 0; return; }
294 var cbs
= self
.DB
-bs
;
297 for(var i
= ds
+1; i
< self
.t
; ++i
) {
298 r
[i
-ds
-1] |= (self
[i
]&bm
)<<cbs
;
299 r
[i
-ds
] = self
[i
]>>bs
;
301 if(bs
> 0) r
[self
.t
-ds
-1] |= (self
.s
&bm
)<<cbs
;
306 // (protected) r = this - a
307 function bnpSubTo(a
,r
) {
309 var i
= 0, c
= 0, m
= Math
.min(a
.t
,self
.t
);
334 if(c
< -1) r
[i
++] = self
.DV
+c
;
335 else if(c
> 0) r
[i
++] = c
;
340 // (protected) r = this * a, r != this,a (HAC 14.12)
341 // "this" should be the larger one if appropriate.
342 function bnpMultiplyTo(a
,r
) {
343 var x
= this.abs(), y
= a
.abs();
346 while(--i
>= 0) r
[i
] = 0;
347 for(i
= 0; i
< y
.t
; ++i
) r
[i
+x
.t
] = x
.am(0,y
[i
],r
,i
,0,x
.t
);
350 if(this.s
!= a
.s
) BigInteger
.ZERO
.subTo(r
,r
);
353 // (protected) r = this^2, r != this (HAC 14.16)
354 function bnpSquareTo(r
) {
357 while(--i
>= 0) r
[i
] = 0;
358 for(i
= 0; i
< x
.t
-1; ++i
) {
359 var c
= x
.am(i
,x
[i
],r
,2*i
,0,1);
360 if((r
[i
+x
.t
]+=x
.am(i
+1,2*x
[i
],r
,2*i
+1,c
,x
.t
-i
-1)) >= x
.DV
) {
365 if(r
.t
> 0) r
[r
.t
-1] += x
.am(i
,x
[i
],r
,2*i
,0,1);
370 // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
371 // r != q, this != m. q or r may be null.
372 function bnpDivRemTo(m
,q
,r
) {
375 if(pm
.t
<= 0) return;
378 if(q
!= null) q
.fromInt(0);
379 if(r
!= null) self
.copyTo(r
);
382 if(r
== null) r
= nbi();
383 var y
= nbi(), ts
= self
.s
, ms
= m
.s
;
384 var nsh
= self
.DB
-nbits(pm
[pm
.t
-1]); // normalize modulus
385 if(nsh
> 0) { pm
.lShiftTo(nsh
,y
); pt
.lShiftTo(nsh
,r
); }
386 else { pm
.copyTo(y
); pt
.copyTo(r
); }
390 var yt
= y0
*(1<<self
.F1
)+((ys
>1)?y
[ys
-2]>>self
.F2:0);
391 var d1
= self
.FV
/yt
, d2
= (1<<self
.F1
)/yt
, e
= 1<<self
.F2
;
392 var i
= r
.t
, j
= i
-ys
, t
= (q
==null)?nbi():q
;
394 if(r
.compareTo(t
) >= 0) {
398 BigInteger
.ONE
.dlShiftTo(ys
,t
);
399 t
.subTo(y
,y
); // "negative" y so we can replace sub with am later
400 while(y
.t
< ys
) y
[y
.t
++] = 0;
402 // Estimate quotient digit
403 var qd
= (r
[--i
]==y0
)?self
.DM:Math
.floor(r
[i
]*d1
+(r
[i
-1]+e
)*d2
);
404 if((r
[i
]+=y
.am(0,qd
,r
,j
,0,ys
)) < qd
) { // Try it out
407 while(r
[i
] < --qd
) r
.subTo(t
,r
);
412 if(ts
!= ms
) BigInteger
.ZERO
.subTo(q
,q
);
416 if(nsh
> 0) r
.rShiftTo(nsh
,r
); // Denormalize remainder
417 if(ts
< 0) BigInteger
.ZERO
.subTo(r
,r
);
420 // (public) this mod a
423 this.abs().divRemTo(a
,null,r
);
424 if(this.s
< 0 && r
.compareTo(BigInteger
.ZERO
) > 0) a
.subTo(r
,r
);
428 // Modular reduction using "classic" algorithm
429 function Classic(m
) { this.m
= m
; }
430 function cConvert(x
) {
431 if(x
.s
< 0 || x
.compareTo(this.m
) >= 0) return x
.mod(this.m
);
434 function cRevert(x
) { return x
; }
435 function cReduce(x
) { x
.divRemTo(this.m
,null,x
); }
436 function cMulTo(x
,y
,r
) { x
.multiplyTo(y
,r
); this.reduce(r
); }
437 function cSqrTo(x
,r
) { x
.squareTo(r
); this.reduce(r
); }
439 Classic
.prototype.convert
= cConvert
;
440 Classic
.prototype.revert
= cRevert
;
441 Classic
.prototype.reduce
= cReduce
;
442 Classic
.prototype.mulTo
= cMulTo
;
443 Classic
.prototype.sqrTo
= cSqrTo
;
445 // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
449 // xy(2-xy) = (1+km)(1-km)
450 // x[y(2-xy)] = 1-k^2m^2
451 // x[y(2-xy)] == 1 (mod m^2)
452 // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
453 // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
454 // JS multiply "overflows" differently from C/C++, so care is needed here.
455 function bnpInvDigit() {
456 if(this.t
< 1) return 0;
458 if((x
&1) == 0) return 0;
459 var y
= x
&3; // y == 1/x mod 2^2
460 y
= (y
*(2-(x
&0xf)*y
))&0xf; // y == 1/x mod 2^4
461 y
= (y
*(2-(x
&0xff)*y
))&0xff; // y == 1/x mod 2^8
462 y
= (y
*(2-(((x
&0xffff)*y
)&0xffff)))&0xffff; // y == 1/x mod 2^16
463 // last step - calculate inverse mod DV directly;
464 // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
465 y
= (y
*(2-x
*y
%this.DV
))%this.DV
; // y == 1/x mod 2^dbits
466 // we really want the negative inverse, and -DV < y < DV
467 return (y
>0)?this.DV
-y:-y
;
470 // Montgomery reduction
471 function Montgomery(m
) {
473 this.mp
= m
.invDigit();
474 this.mpl
= this.mp
&0x7fff;
475 this.mph
= this.mp
>>15;
476 this.um
= (1<<(m
.DB
-15))-1;
481 function montConvert(x
) {
483 x
.abs().dlShiftTo(this.m
.t
,r
);
484 r
.divRemTo(this.m
,null,r
);
485 if(x
.s
< 0 && r
.compareTo(BigInteger
.ZERO
) > 0) this.m
.subTo(r
,r
);
490 function montRevert(x
) {
497 // x = x/R mod m (HAC 14.32)
498 function montReduce(x
) {
499 while(x
.t
<= this.mt2
) // pad x so am has enough room later
501 for(var i
= 0; i
< this.m
.t
; ++i
) {
502 // faster way of calculating u0 = x[i]*mp mod DV
504 var u0
= (j
*this.mpl
+(((j
*this.mph
+(x
[i
]>>15)*this.mpl
)&this.um
)<<15))&x
.DM
;
505 // use am to combine the multiply-shift-add into one call
507 x
[j
] += this.m
.am(0,u0
,x
,i
,0,this.m
.t
);
509 while(x
[j
] >= x
.DV
) { x
[j
] -= x
.DV
; x
[++j
]++; }
512 x
.drShiftTo(this.m
.t
,x
);
513 if(x
.compareTo(this.m
) >= 0) x
.subTo(this.m
,x
);
516 // r = "x^2/R mod m"; x != r
517 function montSqrTo(x
,r
) { x
.squareTo(r
); this.reduce(r
); }
519 // r = "xy/R mod m"; x,y != r
520 function montMulTo(x
,y
,r
) { x
.multiplyTo(y
,r
); this.reduce(r
); }
522 Montgomery
.prototype.convert
= montConvert
;
523 Montgomery
.prototype.revert
= montRevert
;
524 Montgomery
.prototype.reduce
= montReduce
;
525 Montgomery
.prototype.mulTo
= montMulTo
;
526 Montgomery
.prototype.sqrTo
= montSqrTo
;
528 // (protected) true iff this is even
529 function bnpIsEven() { return ((this.t
>0)?(this[0]&1):this.s
) == 0; }
531 // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
532 function bnpExp(e
,z
) {
533 if(e
> 0xffffffff || e
< 1) return BigInteger
.ONE
;
534 var r
= nbi(), r2
= nbi(), g
= z
.convert(this), i
= nbits(e
)-1;
538 if((e
&(1<<i
)) > 0) z
.mulTo(r2
,g
,r
);
539 else { var t
= r
; r
= r2
; r2
= t
; }
544 // (public) this^e % m, 0 <= e < 2^32
545 function bnModPowInt(e
,m
) {
547 if(e
< 256 || m
.isEven()) z
= new Classic(m
); else z
= new Montgomery(m
);
548 return this.exp(e
,z
);
552 proto
.copyTo
= bnpCopyTo
;
553 proto
.fromInt
= bnpFromInt
;
554 proto
.fromString
= bnpFromString
;
555 proto
.clamp
= bnpClamp
;
556 proto
.dlShiftTo
= bnpDLShiftTo
;
557 proto
.drShiftTo
= bnpDRShiftTo
;
558 proto
.lShiftTo
= bnpLShiftTo
;
559 proto
.rShiftTo
= bnpRShiftTo
;
560 proto
.subTo
= bnpSubTo
;
561 proto
.multiplyTo
= bnpMultiplyTo
;
562 proto
.squareTo
= bnpSquareTo
;
563 proto
.divRemTo
= bnpDivRemTo
;
564 proto
.invDigit
= bnpInvDigit
;
565 proto
.isEven
= bnpIsEven
;
569 proto
.toString
= bnToString
;
570 proto
.negate
= bnNegate
;
572 proto
.compareTo
= bnCompareTo
;
573 proto
.bitLength
= bnBitLength
;
575 proto
.modPowInt
= bnModPowInt
;
579 function nbi() { return new BigInteger(null); }
582 function bnClone() { var r
= nbi(); this.copyTo(r
); return r
; }
584 // (public) return value as integer
585 function bnIntValue() {
587 if(this.t
== 1) return this[0]-this.DV
;
588 else if(this.t
== 0) return -1;
590 else if(this.t
== 1) return this[0];
591 else if(this.t
== 0) return 0;
592 // assumes 16 < DB < 32
593 return ((this[1]&((1<<(32-this.DB
))-1))<<this.DB
)|this[0];
596 // (public) return value as byte
597 function bnByteValue() { return (this.t
==0)?this.s:(this[0]<<24)>>24; }
599 // (public) return value as short (assumes DB>=16)
600 function bnShortValue() { return (this.t
==0)?this.s:(this[0]<<16)>>16; }
602 // (protected) return x s.t. r^x < DV
603 function bnpChunkSize(r
) { return Math
.floor(Math
.LN2
*this.DB
/Math
.log(r
)); }
605 // (public) 0 if this == 0, 1 if this > 0
606 function bnSigNum() {
607 if(this.s
< 0) return -1;
608 else if(this.t
<= 0 || (this.t
== 1 && this[0] <= 0)) return 0;
612 // (protected) convert to radix string
613 function bnpToRadix(b
) {
614 if(b
== null) b
= 10;
615 if(this.signum() == 0 || b
< 2 || b
> 36) return "0";
616 var cs
= this.chunkSize(b
);
617 var a
= Math
.pow(b
,cs
);
618 var d
= nbv(a
), y
= nbi(), z
= nbi(), r
= "";
619 this.divRemTo(d
,y
,z
);
620 while(y
.signum() > 0) {
621 r
= (a
+z
.intValue()).toString(b
).substr(1) + r
;
624 return z
.intValue().toString(b
) + r
;
627 // (protected) convert from radix string
628 function bnpFromRadix(s
,b
) {
631 if(b
== null) b
= 10;
632 var cs
= self
.chunkSize(b
);
633 var d
= Math
.pow(b
,cs
), mi
= false, j
= 0, w
= 0;
634 for(var i
= 0; i
< s
.length
; ++i
) {
637 if(s
.charAt(i
) == "-" && self
.signum() == 0) mi
= true;
643 self
.dAddOffset(w
,0);
649 self
.dMultiply(Math
.pow(b
,j
));
650 self
.dAddOffset(w
,0);
652 if(mi
) BigInteger
.ZERO
.subTo(self
,self
);
655 // (protected) alternate constructor
656 function bnpFromNumber(a
,b
,c
) {
658 if("number" == typeof b
) {
659 // new BigInteger(int,int,RNG)
660 if(a
< 2) self
.fromInt(1);
662 self
.fromNumber(a
,c
);
663 if(!self
.testBit(a
-1)) // force MSB set
664 self
.bitwiseTo(BigInteger
.ONE
.shiftLeft(a
-1),op_or
,self
);
665 if(self
.isEven()) self
.dAddOffset(1,0); // force odd
666 while(!self
.isProbablePrime(b
)) {
667 self
.dAddOffset(2,0);
668 if(self
.bitLength() > a
) self
.subTo(BigInteger
.ONE
.shiftLeft(a
-1),self
);
673 // new BigInteger(int,RNG)
674 var x
= new Array(), t
= a
&7;
677 if(t
> 0) x
[0] &= ((1<<t
)-1); else x
[0] = 0;
678 self
.fromString(x
,256);
682 // (public) convert to bigendian byte array
683 function bnToByteArray() {
685 var i
= self
.t
, r
= new Array();
687 var p
= self
.DB
-(i
*self
.DB
)%8, d
, k
= 0;
689 if(p
< self
.DB
&& (d
= self
[i
]>>p
) != (self
.s
&self
.DM
)>>p
)
690 r
[k
++] = d
|(self
.s
<<(self
.DB
-p
));
693 d
= (self
[i
]&((1<<p
)-1))<<(8-p
);
694 d
|= self
[--i
]>>(p
+=self
.DB
-8);
697 d
= (self
[i
]>>(p
-=8))&0xff;
698 if(p
<= 0) { p
+= self
.DB
; --i
; }
700 if((d
&0x80) != 0) d
|= -256;
701 if(k
=== 0 && (self
.s
&0x80) != (d
&0x80)) ++k
;
702 if(k
> 0 || d
!= self
.s
) r
[k
++] = d
;
708 function bnEquals(a
) { return(this.compareTo(a
)==0); }
709 function bnMin(a
) { return(this.compareTo(a
)<0)?this:a
; }
710 function bnMax(a
) { return(this.compareTo(a
)>0)?this:a
; }
712 // (protected) r = this op a (bitwise)
713 function bnpBitwiseTo(a
,op
,r
) {
715 var i
, f
, m
= Math
.min(a
.t
,self
.t
);
716 for(i
= 0; i
< m
; ++i
) r
[i
] = op(self
[i
],a
[i
]);
719 for(i
= m
; i
< self
.t
; ++i
) r
[i
] = op(self
[i
],f
);
724 for(i
= m
; i
< a
.t
; ++i
) r
[i
] = op(f
,a
[i
]);
727 r
.s
= op(self
.s
,a
.s
);
732 function op_and(x
,y
) { return x
&y
; }
733 function bnAnd(a
) { var r
= nbi(); this.bitwiseTo(a
,op_and
,r
); return r
; }
736 function op_or(x
,y
) { return x
|y
; }
737 function bnOr(a
) { var r
= nbi(); this.bitwiseTo(a
,op_or
,r
); return r
; }
740 function op_xor(x
,y
) { return x
^y
; }
741 function bnXor(a
) { var r
= nbi(); this.bitwiseTo(a
,op_xor
,r
); return r
; }
743 // (public) this & ~a
744 function op_andnot(x
,y
) { return x
&~y
; }
745 function bnAndNot(a
) { var r
= nbi(); this.bitwiseTo(a
,op_andnot
,r
); return r
; }
750 for(var i
= 0; i
< this.t
; ++i
) r
[i
] = this.DM
&~this[i
];
756 // (public) this << n
757 function bnShiftLeft(n
) {
759 if(n
< 0) this.rShiftTo(-n
,r
); else this.lShiftTo(n
,r
);
763 // (public) this >> n
764 function bnShiftRight(n
) {
766 if(n
< 0) this.lShiftTo(-n
,r
); else this.rShiftTo(n
,r
);
770 // return index of lowest 1-bit in x, x < 2^31
772 if(x
== 0) return -1;
774 if((x
&0xffff) == 0) { x
>>= 16; r
+= 16; }
775 if((x
&0xff) == 0) { x
>>= 8; r
+= 8; }
776 if((x
&0xf) == 0) { x
>>= 4; r
+= 4; }
777 if((x
&3) == 0) { x
>>= 2; r
+= 2; }
782 // (public) returns index of lowest 1-bit (or -1 if none)
783 function bnGetLowestSetBit() {
784 for(var i
= 0; i
< this.t
; ++i
)
785 if(this[i
] != 0) return i
*this.DB
+lbit(this[i
]);
786 if(this.s
< 0) return this.t
*this.DB
;
790 // return number of 1 bits in x
793 while(x
!= 0) { x
&= x
-1; ++r
; }
797 // (public) return number of set bits
798 function bnBitCount() {
799 var r
= 0, x
= this.s
&this.DM
;
800 for(var i
= 0; i
< this.t
; ++i
) r
+= cbit(this[i
]^x
);
804 // (public) true iff nth bit is set
805 function bnTestBit(n
) {
806 var j
= Math
.floor(n
/this.DB
);
807 if(j
>= this.t
) return(this.s
!=0);
808 return((this[j
]&(1<<(n
%this.DB
)))!=0);
811 // (protected) this op (1<<n)
812 function bnpChangeBit(n
,op
) {
813 var r
= BigInteger
.ONE
.shiftLeft(n
);
814 this.bitwiseTo(r
,op
,r
);
818 // (public) this | (1<<n)
819 function bnSetBit(n
) { return this.changeBit(n
,op_or
); }
821 // (public) this & ~(1<<n)
822 function bnClearBit(n
) { return this.changeBit(n
,op_andnot
); }
824 // (public) this ^ (1<<n)
825 function bnFlipBit(n
) { return this.changeBit(n
,op_xor
); }
827 // (protected) r = this + a
828 function bnpAddTo(a
,r
) {
831 var i
= 0, c
= 0, m
= Math
.min(a
.t
,self
.t
);
856 if(c
> 0) r
[i
++] = c
;
857 else if(c
< -1) r
[i
++] = self
.DV
+c
;
863 function bnAdd(a
) { var r
= nbi(); this.addTo(a
,r
); return r
; }
866 function bnSubtract(a
) { var r
= nbi(); this.subTo(a
,r
); return r
; }
869 function bnMultiply(a
) { var r
= nbi(); this.multiplyTo(a
,r
); return r
; }
872 function bnSquare() { var r
= nbi(); this.squareTo(r
); return r
; }
875 function bnDivide(a
) { var r
= nbi(); this.divRemTo(a
,r
,null); return r
; }
878 function bnRemainder(a
) { var r
= nbi(); this.divRemTo(a
,null,r
); return r
; }
880 // (public) [this/a,this%a]
881 function bnDivideAndRemainder(a
) {
882 var q
= nbi(), r
= nbi();
883 this.divRemTo(a
,q
,r
);
884 return new Array(q
,r
);
887 // (protected) this *= n, this >= 0, 1 < n < DV
888 function bnpDMultiply(n
) {
889 this[this.t
] = this.am(0,n
-1,this,0,0,this.t
);
894 // (protected) this += n << w words, this >= 0
895 function bnpDAddOffset(n
,w
) {
897 while(this.t
<= w
) this[this.t
++] = 0;
899 while(this[w
] >= this.DV
) {
901 if(++w
>= this.t
) this[this.t
++] = 0;
907 function NullExp() {}
908 function nNop(x
) { return x
; }
909 function nMulTo(x
,y
,r
) { x
.multiplyTo(y
,r
); }
910 function nSqrTo(x
,r
) { x
.squareTo(r
); }
912 NullExp
.prototype.convert
= nNop
;
913 NullExp
.prototype.revert
= nNop
;
914 NullExp
.prototype.mulTo
= nMulTo
;
915 NullExp
.prototype.sqrTo
= nSqrTo
;
918 function bnPow(e
) { return this.exp(e
,new NullExp()); }
920 // (protected) r = lower n words of "this * a", a.t <= n
921 // "this" should be the larger one if appropriate.
922 function bnpMultiplyLowerTo(a
,n
,r
) {
923 var i
= Math
.min(this.t
+a
.t
,n
);
924 r
.s
= 0; // assumes a,this >= 0
926 while(i
> 0) r
[--i
] = 0;
928 for(j
= r
.t
-this.t
; i
< j
; ++i
) r
[i
+this.t
] = this.am(0,a
[i
],r
,i
,0,this.t
);
929 for(j
= Math
.min(a
.t
,n
); i
< j
; ++i
) this.am(0,a
[i
],r
,i
,0,n
-i
);
933 // (protected) r = "this * a" without lower n words, n > 0
934 // "this" should be the larger one if appropriate.
935 function bnpMultiplyUpperTo(a
,n
,r
) {
937 var i
= r
.t
= this.t
+a
.t
-n
;
938 r
.s
= 0; // assumes a,this >= 0
939 while(--i
>= 0) r
[i
] = 0;
940 for(i
= Math
.max(n
-this.t
,0); i
< a
.t
; ++i
)
941 r
[this.t
+i
-n
] = this.am(n
-i
,a
[i
],r
,0,0,this.t
+i
-n
);
946 // Barrett modular reduction
947 function Barrett(m
) {
951 BigInteger
.ONE
.dlShiftTo(2*m
.t
,this.r2
);
952 this.mu
= this.r2
.divide(m
);
956 function barrettConvert(x
) {
957 if(x
.s
< 0 || x
.t
> 2*this.m
.t
) return x
.mod(this.m
);
958 else if(x
.compareTo(this.m
) < 0) return x
;
959 else { var r
= nbi(); x
.copyTo(r
); this.reduce(r
); return r
; }
962 function barrettRevert(x
) { return x
; }
964 // x = x mod m (HAC 14.42)
965 function barrettReduce(x
) {
967 x
.drShiftTo(self
.m
.t
-1,self
.r2
);
968 if(x
.t
> self
.m
.t
+1) { x
.t
= self
.m
.t
+1; x
.clamp(); }
969 self
.mu
.multiplyUpperTo(self
.r2
,self
.m
.t
+1,self
.q3
);
970 self
.m
.multiplyLowerTo(self
.q3
,self
.m
.t
+1,self
.r2
);
971 while(x
.compareTo(self
.r2
) < 0) x
.dAddOffset(1,self
.m
.t
+1);
973 while(x
.compareTo(self
.m
) >= 0) x
.subTo(self
.m
,x
);
976 // r = x^2 mod m; x != r
977 function barrettSqrTo(x
,r
) { x
.squareTo(r
); this.reduce(r
); }
979 // r = x*y mod m; x,y != r
980 function barrettMulTo(x
,y
,r
) { x
.multiplyTo(y
,r
); this.reduce(r
); }
982 Barrett
.prototype.convert
= barrettConvert
;
983 Barrett
.prototype.revert
= barrettRevert
;
984 Barrett
.prototype.reduce
= barrettReduce
;
985 Barrett
.prototype.mulTo
= barrettMulTo
;
986 Barrett
.prototype.sqrTo
= barrettSqrTo
;
988 // (public) this^e % m (HAC 14.85)
989 function bnModPow(e
,m
) {
990 var i
= e
.bitLength(), k
, r
= nbv(1), z
;
992 else if(i
< 18) k
= 1;
993 else if(i
< 48) k
= 3;
994 else if(i
< 144) k
= 4;
995 else if(i
< 768) k
= 5;
1002 z
= new Montgomery(m
);
1005 var g
= new Array(), n
= 3, k1
= k
-1, km
= (1<<k
)-1;
1006 g
[1] = z
.convert(this);
1012 z
.mulTo(g2
,g
[n
-2],g
[n
]);
1017 var j
= e
.t
-1, w
, is1
= true, r2
= nbi(), t
;
1020 if(i
>= k1
) w
= (e
[j
]>>(i
-k1
))&km
;
1022 w
= (e
[j
]&((1<<(i
+1))-1))<<(k1
-i
);
1023 if(j
> 0) w
|= e
[j
-1]>>(this.DB
+i
-k1
);
1027 while((w
&1) == 0) { w
>>= 1; --n
; }
1028 if((i
-= n
) < 0) { i
+= this.DB
; --j
; }
1029 if(is1
) { // ret == 1, don't bother squaring or multiplying it
1034 while(n
> 1) { z
.sqrTo(r
,r2
); z
.sqrTo(r2
,r
); n
-= 2; }
1035 if(n
> 0) z
.sqrTo(r
,r2
); else { t
= r
; r
= r2
; r2
= t
; }
1039 while(j
>= 0 && (e
[j
]&(1<<i
)) == 0) {
1040 z
.sqrTo(r
,r2
); t
= r
; r
= r2
; r2
= t
;
1041 if(--i
< 0) { i
= this.DB
-1; --j
; }
1047 // (public) gcd(this,a) (HAC 14.54)
1049 var x
= (this.s
<0)?this.negate():this.clone();
1050 var y
= (a
.s
<0)?a
.negate():a
.clone();
1051 if(x
.compareTo(y
) < 0) { var t
= x
; x
= y
; y
= t
; }
1052 var i
= x
.getLowestSetBit(), g
= y
.getLowestSetBit();
1059 while(x
.signum() > 0) {
1060 if((i
= x
.getLowestSetBit()) > 0) x
.rShiftTo(i
,x
);
1061 if((i
= y
.getLowestSetBit()) > 0) y
.rShiftTo(i
,y
);
1062 if(x
.compareTo(y
) >= 0) {
1071 if(g
> 0) y
.lShiftTo(g
,y
);
1075 // (protected) this % n, n < 2^26
1076 function bnpModInt(n
) {
1077 if(n
<= 0) return 0;
1078 var d
= this.DV
%n
, r
= (this.s
<0)?n
-1:0;
1080 if(d
== 0) r
= this[0]%n
;
1081 else for(var i
= this.t
-1; i
>= 0; --i
) r
= (d
*r
+this[i
])%n
;
1085 // (public) 1/this % m (HAC 14.61)
1086 function bnModInverse(m
) {
1087 var ac
= m
.isEven();
1088 if((this.isEven() && ac
) || m
.signum() == 0) return BigInteger
.ZERO
;
1089 var u
= m
.clone(), v
= this.clone();
1090 var a
= nbv(1), b
= nbv(0), c
= nbv(0), d
= nbv(1);
1091 while(u
.signum() != 0) {
1095 if(!a
.isEven() || !b
.isEven()) { a
.addTo(this,a
); b
.subTo(m
,b
); }
1098 else if(!b
.isEven()) b
.subTo(m
,b
);
1104 if(!c
.isEven() || !d
.isEven()) { c
.addTo(this,c
); d
.subTo(m
,d
); }
1107 else if(!d
.isEven()) d
.subTo(m
,d
);
1110 if(u
.compareTo(v
) >= 0) {
1112 if(ac
) a
.subTo(c
,a
);
1117 if(ac
) c
.subTo(a
,c
);
1121 if(v
.compareTo(BigInteger
.ONE
) != 0) return BigInteger
.ZERO
;
1122 if(d
.compareTo(m
) >= 0) return d
.subtract(m
);
1123 if(d
.signum() < 0) d
.addTo(m
,d
); else return d
;
1124 if(d
.signum() < 0) return d
.add(m
); else return d
;
1128 proto
.chunkSize
= bnpChunkSize
;
1129 proto
.toRadix
= bnpToRadix
;
1130 proto
.fromRadix
= bnpFromRadix
;
1131 proto
.fromNumber
= bnpFromNumber
;
1132 proto
.bitwiseTo
= bnpBitwiseTo
;
1133 proto
.changeBit
= bnpChangeBit
;
1134 proto
.addTo
= bnpAddTo
;
1135 proto
.dMultiply
= bnpDMultiply
;
1136 proto
.dAddOffset
= bnpDAddOffset
;
1137 proto
.multiplyLowerTo
= bnpMultiplyLowerTo
;
1138 proto
.multiplyUpperTo
= bnpMultiplyUpperTo
;
1139 proto
.modInt
= bnpModInt
;
1142 proto
.clone
= bnClone
;
1143 proto
.intValue
= bnIntValue
;
1144 proto
.byteValue
= bnByteValue
;
1145 proto
.shortValue
= bnShortValue
;
1146 proto
.signum
= bnSigNum
;
1147 proto
.toByteArray
= bnToByteArray
;
1148 proto
.equals
= bnEquals
;
1154 proto
.andNot
= bnAndNot
;
1156 proto
.shiftLeft
= bnShiftLeft
;
1157 proto
.shiftRight
= bnShiftRight
;
1158 proto
.getLowestSetBit
= bnGetLowestSetBit
;
1159 proto
.bitCount
= bnBitCount
;
1160 proto
.testBit
= bnTestBit
;
1161 proto
.setBit
= bnSetBit
;
1162 proto
.clearBit
= bnClearBit
;
1163 proto
.flipBit
= bnFlipBit
;
1165 proto
.subtract
= bnSubtract
;
1166 proto
.multiply
= bnMultiply
;
1167 proto
.divide
= bnDivide
;
1168 proto
.remainder
= bnRemainder
;
1169 proto
.divideAndRemainder
= bnDivideAndRemainder
;
1170 proto
.modPow
= bnModPow
;
1171 proto
.modInverse
= bnModInverse
;
1175 // JSBN-specific extension
1176 proto
.square
= bnSquare
;
1178 // BigInteger interfaces not implemented in jsbn:
1180 // BigInteger(int signum, byte[] magnitude)
1181 // double doubleValue()
1182 // float floatValue()
1185 // static BigInteger valueOf(long val)
1188 BigInteger
.ZERO
= nbv(0);
1189 BigInteger
.ONE
= nbv(1);
1190 BigInteger
.valueOf
= nbv
;
1192 },{"assert":4}],2:[function(_dereq_
,module
,exports
){
1194 // FIXME: Kind of a weird way to throw exceptions, consider removing
1195 var assert
= _dereq_('assert')
1196 var BigInteger
= _dereq_('./bigi')
1199 * Turns a byte array into a big integer.
1201 * This function will interpret a byte array as a big integer in big
1204 BigInteger
.fromByteArrayUnsigned = function(byteArray
) {
1205 // BigInteger expects a DER integer conformant byte array
1206 if (byteArray
[0] & 0x80) {
1207 return new BigInteger([0].concat(byteArray
))
1210 return new BigInteger(byteArray
)
1214 * Returns a byte array representation of the big integer.
1216 * This returns the absolute of the contained value in big endian
1217 * form. A value of zero results in an empty array.
1219 BigInteger
.prototype.toByteArrayUnsigned = function() {
1220 var byteArray
= this.toByteArray()
1221 return byteArray
[0] === 0 ? byteArray
.slice(1) : byteArray
1224 BigInteger
.fromDERInteger = function(byteArray
) {
1225 return new BigInteger(byteArray
)
1229 * Converts BigInteger to a DER integer representation.
1231 * The format for this value uses the most significant bit as a sign
1232 * bit. If the most significant bit is already set and the integer is
1233 * positive, a 0x00 is prepended.
1251 BigInteger
.prototype.toDERInteger
= BigInteger
.prototype.toByteArray
1253 BigInteger
.fromBuffer = function(buffer
) {
1254 // BigInteger expects a DER integer conformant byte array
1255 if (buffer
[0] & 0x80) {
1256 var byteArray
= Array
.prototype.slice
.call(buffer
)
1258 return new BigInteger([0].concat(byteArray
))
1261 return new BigInteger(buffer
)
1264 BigInteger
.fromHex = function(hex
) {
1265 if (hex
=== '') return BigInteger
.ZERO
1267 assert
.equal(hex
, hex
.match(/^[A-Fa-f0-9]+/), 'Invalid hex string')
1268 assert
.equal(hex
.length
% 2, 0, 'Incomplete hex')
1269 return new BigInteger(hex
, 16)
1272 BigInteger
.prototype.toBuffer = function(size
) {
1273 var byteArray
= this.toByteArrayUnsigned()
1276 var padding
= size
- byteArray
.length
1277 while (zeros
.length
< padding
) zeros
.push(0)
1279 return new Buffer(zeros
.concat(byteArray
))
1282 BigInteger
.prototype.toHex = function(size
) {
1283 return this.toBuffer(size
).toString('hex')
1286 }).call(this,_dereq_("buffer").Buffer
)
1287 },{"./bigi":1,"assert":4,"buffer":8}],3:[function(_dereq_
,module
,exports
){
1288 var BigInteger
= _dereq_('./bigi')
1291 _dereq_('./convert')
1293 module
.exports
= BigInteger
1294 },{"./bigi":1,"./convert":2}],4:[function(_dereq_
,module
,exports
){
1295 // http://wiki.commonjs.org/wiki/Unit_Testing/1.0
1297 // THIS IS NOT TESTED NOR LIKELY TO WORK OUTSIDE V8!
1299 // Originally from narwhal.js (http://narwhaljs.org)
1300 // Copyright (c) 2009 Thomas Robinson <280north.com>
1302 // Permission is hereby granted, free of charge, to any person obtaining a copy
1303 // of this software and associated documentation files (the 'Software'), to
1304 // deal in the Software without restriction, including without limitation the
1305 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
1306 // sell copies of the Software, and to permit persons to whom the Software is
1307 // furnished to do so, subject to the following conditions:
1309 // The above copyright notice and this permission notice shall be included in
1310 // all copies or substantial portions of the Software.
1312 // THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1313 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1314 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1315 // AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
1316 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
1317 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1319 // when used in node, this will actually load the util module we depend on
1320 // versus loading the builtin util module as happens otherwise
1321 // this is a bug in node module loading as far as I am concerned
1322 var util
= _dereq_('util/');
1324 var pSlice
= Array
.prototype.slice
;
1325 var hasOwn
= Object
.prototype.hasOwnProperty
;
1327 // 1. The assert module provides functions that throw
1328 // AssertionError's when particular conditions are not met. The
1329 // assert module must conform to the following interface.
1331 var assert
= module
.exports
= ok
;
1333 // 2. The AssertionError is defined in assert.
1334 // new assert.AssertionError({ message: message,
1336 // expected: expected })
1338 assert
.AssertionError
= function AssertionError(options
) {
1339 this.name
= 'AssertionError';
1340 this.actual
= options
.actual
;
1341 this.expected
= options
.expected
;
1342 this.operator
= options
.operator
;
1343 if (options
.message
) {
1344 this.message
= options
.message
;
1345 this.generatedMessage
= false;
1347 this.message
= getMessage(this);
1348 this.generatedMessage
= true;
1350 var stackStartFunction
= options
.stackStartFunction
|| fail
;
1352 if (Error
.captureStackTrace
) {
1353 Error
.captureStackTrace(this, stackStartFunction
);
1356 // non v8 browsers so we can have a stacktrace
1357 var err
= new Error();
1359 var out
= err
.stack
;
1361 // try to strip useless frames
1362 var fn_name
= stackStartFunction
.name
;
1363 var idx
= out
.indexOf('\n' + fn_name
);
1365 // once we have located the function frame
1366 // we need to strip out everything before it (and its line)
1367 var next_line
= out
.indexOf('\n', idx
+ 1);
1368 out
= out
.substring(next_line
+ 1);
1376 // assert.AssertionError instanceof Error
1377 util
.inherits(assert
.AssertionError
, Error
);
1379 function replacer(key
, value
) {
1380 if (util
.isUndefined(value
)) {
1383 if (util
.isNumber(value
) && (isNaN(value
) || !isFinite(value
))) {
1384 return value
.toString();
1386 if (util
.isFunction(value
) || util
.isRegExp(value
)) {
1387 return value
.toString();
1392 function truncate(s
, n
) {
1393 if (util
.isString(s
)) {
1394 return s
.length
< n
? s : s
.slice(0, n
);
1400 function getMessage(self
) {
1401 return truncate(JSON
.stringify(self
.actual
, replacer
), 128) + ' ' +
1402 self
.operator
+ ' ' +
1403 truncate(JSON
.stringify(self
.expected
, replacer
), 128);
1406 // At present only the three keys mentioned above are used and
1407 // understood by the spec. Implementations or sub modules can pass
1408 // other keys to the AssertionError's constructor - they will be
1411 // 3. All of the following functions must throw an AssertionError
1412 // when a corresponding condition is not met, with a message that
1413 // may be undefined if not provided. All assertion methods provide
1414 // both the actual and expected values to the assertion error for
1415 // display purposes.
1417 function fail(actual
, expected
, message
, operator
, stackStartFunction
) {
1418 throw new assert
.AssertionError({
1423 stackStartFunction: stackStartFunction
1427 // EXTENSION! allows for well behaved errors defined elsewhere.
1430 // 4. Pure assertion tests whether a value is truthy, as determined
1432 // assert.ok(guard, message_opt);
1433 // This statement is equivalent to assert.equal(true, !!guard,
1434 // message_opt);. To test strictly for the value true, use
1435 // assert.strictEqual(true, guard, message_opt);.
1437 function ok(value
, message
) {
1438 if (!value
) fail(value
, true, message
, '==', assert
.ok
);
1442 // 5. The equality assertion tests shallow, coercive equality with
1444 // assert.equal(actual, expected, message_opt);
1446 assert
.equal
= function equal(actual
, expected
, message
) {
1447 if (actual
!= expected
) fail(actual
, expected
, message
, '==', assert
.equal
);
1450 // 6. The non-equality assertion tests for whether two objects are not equal
1451 // with != assert.notEqual(actual, expected, message_opt);
1453 assert
.notEqual
= function notEqual(actual
, expected
, message
) {
1454 if (actual
== expected
) {
1455 fail(actual
, expected
, message
, '!=', assert
.notEqual
);
1459 // 7. The equivalence assertion tests a deep equality relation.
1460 // assert.deepEqual(actual, expected, message_opt);
1462 assert
.deepEqual
= function deepEqual(actual
, expected
, message
) {
1463 if (!_deepEqual(actual
, expected
)) {
1464 fail(actual
, expected
, message
, 'deepEqual', assert
.deepEqual
);
1468 function _deepEqual(actual
, expected
) {
1469 // 7.1. All identical values are equivalent, as determined by ===.
1470 if (actual
=== expected
) {
1473 } else if (util
.isBuffer(actual
) && util
.isBuffer(expected
)) {
1474 if (actual
.length
!= expected
.length
) return false;
1476 for (var i
= 0; i
< actual
.length
; i
++) {
1477 if (actual
[i
] !== expected
[i
]) return false;
1482 // 7.2. If the expected value is a Date object, the actual value is
1483 // equivalent if it is also a Date object that refers to the same time.
1484 } else if (util
.isDate(actual
) && util
.isDate(expected
)) {
1485 return actual
.getTime() === expected
.getTime();
1487 // 7.3 If the expected value is a RegExp object, the actual value is
1488 // equivalent if it is also a RegExp object with the same source and
1489 // properties (`global`, `multiline`, `lastIndex`, `ignoreCase`).
1490 } else if (util
.isRegExp(actual
) && util
.isRegExp(expected
)) {
1491 return actual
.source
=== expected
.source
&&
1492 actual
.global
=== expected
.global
&&
1493 actual
.multiline
=== expected
.multiline
&&
1494 actual
.lastIndex
=== expected
.lastIndex
&&
1495 actual
.ignoreCase
=== expected
.ignoreCase
;
1497 // 7.4. Other pairs that do not both pass typeof value == 'object',
1498 // equivalence is determined by ==.
1499 } else if (!util
.isObject(actual
) && !util
.isObject(expected
)) {
1500 return actual
== expected
;
1502 // 7.5 For all other Object pairs, including Array objects, equivalence is
1503 // determined by having the same number of owned properties (as verified
1504 // with Object.prototype.hasOwnProperty.call), the same set of keys
1505 // (although not necessarily the same order), equivalent values for every
1506 // corresponding key, and an identical 'prototype' property. Note: this
1507 // accounts for both named and indexed properties on Arrays.
1509 return objEquiv(actual
, expected
);
1513 function isArguments(object
) {
1514 return Object
.prototype.toString
.call(object
) == '[object Arguments]';
1517 function objEquiv(a
, b
) {
1518 if (util
.isNullOrUndefined(a
) || util
.isNullOrUndefined(b
))
1520 // an identical 'prototype' property.
1521 if (a
.prototype !== b
.prototype) return false;
1522 //~~~I've managed to break Object.keys through screwy arguments passing.
1523 // Converting to array solves the problem.
1524 if (isArguments(a
)) {
1525 if (!isArguments(b
)) {
1530 return _deepEqual(a
, b
);
1533 var ka
= objectKeys(a
),
1536 } catch (e
) {//happens when one is a string literal and the other isn't
1539 // having the same number of owned properties (keys incorporates
1541 if (ka
.length
!= kb
.length
)
1543 //the same set of keys (although not necessarily the same order),
1547 for (i
= ka
.length
- 1; i
>= 0; i
--) {
1551 //equivalent values for every corresponding key, and
1552 //~~~possibly expensive deep test
1553 for (i
= ka
.length
- 1; i
>= 0; i
--) {
1555 if (!_deepEqual(a
[key
], b
[key
])) return false;
1560 // 8. The non-equivalence assertion tests for any deep inequality.
1561 // assert.notDeepEqual(actual, expected, message_opt);
1563 assert
.notDeepEqual
= function notDeepEqual(actual
, expected
, message
) {
1564 if (_deepEqual(actual
, expected
)) {
1565 fail(actual
, expected
, message
, 'notDeepEqual', assert
.notDeepEqual
);
1569 // 9. The strict equality assertion tests strict equality, as determined by ===.
1570 // assert.strictEqual(actual, expected, message_opt);
1572 assert
.strictEqual
= function strictEqual(actual
, expected
, message
) {
1573 if (actual
!== expected
) {
1574 fail(actual
, expected
, message
, '===', assert
.strictEqual
);
1578 // 10. The strict non-equality assertion tests for strict inequality, as
1579 // determined by !==. assert.notStrictEqual(actual, expected, message_opt);
1581 assert
.notStrictEqual
= function notStrictEqual(actual
, expected
, message
) {
1582 if (actual
=== expected
) {
1583 fail(actual
, expected
, message
, '!==', assert
.notStrictEqual
);
1587 function expectedException(actual
, expected
) {
1588 if (!actual
|| !expected
) {
1592 if (Object
.prototype.toString
.call(expected
) == '[object RegExp]') {
1593 return expected
.test(actual
);
1594 } else if (actual
instanceof expected
) {
1596 } else if (expected
.call({}, actual
) === true) {
1603 function _throws(shouldThrow
, block
, expected
, message
) {
1606 if (util
.isString(expected
)) {
1617 message
= (expected
&& expected
.name
? ' (' + expected
.name
+ ').' : '.') +
1618 (message
? ' ' + message : '.');
1620 if (shouldThrow
&& !actual
) {
1621 fail(actual
, expected
, 'Missing expected exception' + message
);
1624 if (!shouldThrow
&& expectedException(actual
, expected
)) {
1625 fail(actual
, expected
, 'Got unwanted exception' + message
);
1628 if ((shouldThrow
&& actual
&& expected
&&
1629 !expectedException(actual
, expected
)) || (!shouldThrow
&& actual
)) {
1634 // 11. Expected to throw an error:
1635 // assert.throws(block, Error_opt, message_opt);
1637 assert
.throws = function(block
, /*optional*/error
, /*optional*/message
) {
1638 _throws
.apply(this, [true].concat(pSlice
.call(arguments
)));
1641 // EXTENSION! This is annoying to write outside this module.
1642 assert
.doesNotThrow = function(block
, /*optional*/message
) {
1643 _throws
.apply(this, [false].concat(pSlice
.call(arguments
)));
1646 assert
.ifError = function(err
) { if (err
) {throw err
;}};
1648 var objectKeys
= Object
.keys
|| function (obj
) {
1650 for (var key
in obj
) {
1651 if (hasOwn
.call(obj
, key
)) keys
.push(key
);
1656 },{"util/":6}],5:[function(_dereq_
,module
,exports
){
1657 module
.exports
= function isBuffer(arg
) {
1658 return arg
&& typeof arg
=== 'object'
1659 && typeof arg
.copy
=== 'function'
1660 && typeof arg
.fill
=== 'function'
1661 && typeof arg
.readUInt8
=== 'function';
1663 },{}],6:[function(_dereq_
,module
,exports
){
1664 (function (process
,global
){
1665 // Copyright Joyent, Inc. and other Node contributors.
1667 // Permission is hereby granted, free of charge, to any person obtaining a
1668 // copy of this software and associated documentation files (the
1669 // "Software"), to deal in the Software without restriction, including
1670 // without limitation the rights to use, copy, modify, merge, publish,
1671 // distribute, sublicense, and/or sell copies of the Software, and to permit
1672 // persons to whom the Software is furnished to do so, subject to the
1673 // following conditions:
1675 // The above copyright notice and this permission notice shall be included
1676 // in all copies or substantial portions of the Software.
1678 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1679 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
1680 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
1681 // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
1682 // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
1683 // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
1684 // USE OR OTHER DEALINGS IN THE SOFTWARE.
1686 var formatRegExp
= /%[sdj%]/g;
1687 exports
.format = function(f
) {
1690 for (var i
= 0; i
< arguments
.length
; i
++) {
1691 objects
.push(inspect(arguments
[i
]));
1693 return objects
.join(' ');
1697 var args
= arguments
;
1698 var len
= args
.length
;
1699 var str
= String(f
).replace(formatRegExp
, function(x
) {
1700 if (x
=== '%%') return '%';
1701 if (i
>= len
) return x
;
1703 case '%s': return String(args
[i
++]);
1704 case '%d': return Number(args
[i
++]);
1707 return JSON
.stringify(args
[i
++]);
1709 return '[Circular]';
1715 for (var x
= args
[i
]; i
< len
; x
= args
[++i
]) {
1716 if (isNull(x
) || !isObject(x
)) {
1719 str
+= ' ' + inspect(x
);
1726 // Mark that a method should not be used.
1727 // Returns a modified function which warns once by default.
1728 // If --no-deprecation is set, then it is a no-op.
1729 exports
.deprecate = function(fn
, msg
) {
1730 // Allow for deprecating things in the process of starting up.
1731 if (isUndefined(global
.process
)) {
1733 return exports
.deprecate(fn
, msg
).apply(this, arguments
);
1737 if (process
.noDeprecation
=== true) {
1742 function deprecated() {
1744 if (process
.throwDeprecation
) {
1745 throw new Error(msg
);
1746 } else if (process
.traceDeprecation
) {
1753 return fn
.apply(this, arguments
);
1762 exports
.debuglog = function(set) {
1763 if (isUndefined(debugEnviron
))
1764 debugEnviron
= process
.env
.NODE_DEBUG
|| '';
1765 set = set.toUpperCase();
1767 if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron
)) {
1768 var pid
= process
.pid
;
1769 debugs
[set] = function() {
1770 var msg
= exports
.format
.apply(exports
, arguments
);
1771 console
.error('%s %d: %s', set, pid
, msg
);
1774 debugs
[set] = function() {};
1782 * Echos the value of a value. Trys to print the value out
1783 * in the best way possible given the different types.
1785 * @param {Object} obj The object to print out.
1786 * @param {Object} opts Optional options object that alters the output.
1788 /* legacy: obj, showHidden, depth, colors*/
1789 function inspect(obj
, opts
) {
1793 stylize: stylizeNoColor
1796 if (arguments
.length
>= 3) ctx
.depth
= arguments
[2];
1797 if (arguments
.length
>= 4) ctx
.colors
= arguments
[3];
1798 if (isBoolean(opts
)) {
1800 ctx
.showHidden
= opts
;
1802 // got an "options" object
1803 exports
._extend(ctx
, opts
);
1805 // set default options
1806 if (isUndefined(ctx
.showHidden
)) ctx
.showHidden
= false;
1807 if (isUndefined(ctx
.depth
)) ctx
.depth
= 2;
1808 if (isUndefined(ctx
.colors
)) ctx
.colors
= false;
1809 if (isUndefined(ctx
.customInspect
)) ctx
.customInspect
= true;
1810 if (ctx
.colors
) ctx
.stylize
= stylizeWithColor
;
1811 return formatValue(ctx
, obj
, ctx
.depth
);
1813 exports
.inspect
= inspect
;
1816 // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
1820 'underline' : [4, 24],
1821 'inverse' : [7, 27],
1828 'magenta' : [35, 39],
1833 // Don't use 'blue' not visible on cmd.exe
1837 'boolean': 'yellow',
1838 'undefined': 'grey',
1842 // "name": intentionally not styling
1847 function stylizeWithColor(str
, styleType
) {
1848 var style
= inspect
.styles
[styleType
];
1851 return '\u001b[' + inspect
.colors
[style
][0] + 'm' + str
+
1852 '\u001b[' + inspect
.colors
[style
][1] + 'm';
1859 function stylizeNoColor(str
, styleType
) {
1864 function arrayToHash(array
) {
1867 array
.forEach(function(val
, idx
) {
1875 function formatValue(ctx
, value
, recurseTimes
) {
1876 // Provide a hook for user-specified inspect functions.
1877 // Check that value is an object with an inspect function on it
1878 if (ctx
.customInspect
&&
1880 isFunction(value
.inspect
) &&
1881 // Filter out the util module, it's inspect function is special
1882 value
.inspect
!== exports
.inspect
&&
1883 // Also filter out any prototype objects using the circular check.
1884 !(value
.constructor && value
.constructor.prototype === value
)) {
1885 var ret
= value
.inspect(recurseTimes
, ctx
);
1886 if (!isString(ret
)) {
1887 ret
= formatValue(ctx
, ret
, recurseTimes
);
1892 // Primitive types cannot have properties
1893 var primitive
= formatPrimitive(ctx
, value
);
1898 // Look up the keys of the object.
1899 var keys
= Object
.keys(value
);
1900 var visibleKeys
= arrayToHash(keys
);
1902 if (ctx
.showHidden
) {
1903 keys
= Object
.getOwnPropertyNames(value
);
1906 // IE doesn't make error fields non-enumerable
1907 // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
1909 && (keys
.indexOf('message') >= 0 || keys
.indexOf('description') >= 0)) {
1910 return formatError(value
);
1913 // Some type of object without properties can be shortcutted.
1914 if (keys
.length
=== 0) {
1915 if (isFunction(value
)) {
1916 var name
= value
.name
? ': ' + value
.name : '';
1917 return ctx
.stylize('[Function' + name
+ ']', 'special');
1919 if (isRegExp(value
)) {
1920 return ctx
.stylize(RegExp
.prototype.toString
.call(value
), 'regexp');
1922 if (isDate(value
)) {
1923 return ctx
.stylize(Date
.prototype.toString
.call(value
), 'date');
1925 if (isError(value
)) {
1926 return formatError(value
);
1930 var base
= '', array
= false, braces
= ['{', '}'];
1932 // Make Array say that they are Array
1933 if (isArray(value
)) {
1935 braces
= ['[', ']'];
1938 // Make functions say that they are functions
1939 if (isFunction(value
)) {
1940 var n
= value
.name
? ': ' + value
.name : '';
1941 base
= ' [Function' + n
+ ']';
1944 // Make RegExps say that they are RegExps
1945 if (isRegExp(value
)) {
1946 base
= ' ' + RegExp
.prototype.toString
.call(value
);
1949 // Make dates with properties first say the date
1950 if (isDate(value
)) {
1951 base
= ' ' + Date
.prototype.toUTCString
.call(value
);
1954 // Make error with message first say the error
1955 if (isError(value
)) {
1956 base
= ' ' + formatError(value
);
1959 if (keys
.length
=== 0 && (!array
|| value
.length
== 0)) {
1960 return braces
[0] + base
+ braces
[1];
1963 if (recurseTimes
< 0) {
1964 if (isRegExp(value
)) {
1965 return ctx
.stylize(RegExp
.prototype.toString
.call(value
), 'regexp');
1967 return ctx
.stylize('[Object]', 'special');
1971 ctx
.seen
.push(value
);
1975 output
= formatArray(ctx
, value
, recurseTimes
, visibleKeys
, keys
);
1977 output
= keys
.map(function(key
) {
1978 return formatProperty(ctx
, value
, recurseTimes
, visibleKeys
, key
, array
);
1984 return reduceToSingleString(output
, base
, braces
);
1988 function formatPrimitive(ctx
, value
) {
1989 if (isUndefined(value
))
1990 return ctx
.stylize('undefined', 'undefined');
1991 if (isString(value
)) {
1992 var simple
= '\'' + JSON
.stringify(value
).replace(/^"|"$/g, '')
1993 .replace(/'/g, "\\'")
1994 .replace(/\\"/g
, '"') + '\'';
1995 return ctx
.stylize(simple
, 'string');
1997 if (isNumber(value
))
1998 return ctx
.stylize('' + value
, 'number');
1999 if (isBoolean(value
))
2000 return ctx
.stylize('' + value
, 'boolean');
2001 // For some reason typeof null is "object", so special case here.
2003 return ctx
.stylize('null', 'null');
2007 function formatError(value
) {
2008 return '[' + Error
.prototype.toString
.call(value
) + ']';
2012 function formatArray(ctx
, value
, recurseTimes
, visibleKeys
, keys
) {
2014 for (var i
= 0, l
= value
.length
; i
< l
; ++i
) {
2015 if (hasOwnProperty(value
, String(i
))) {
2016 output
.push(formatProperty(ctx
, value
, recurseTimes
, visibleKeys
,
2022 keys
.forEach(function(key
) {
2023 if (!key
.match(/^\d+$/)) {
2024 output
.push(formatProperty(ctx
, value
, recurseTimes
, visibleKeys
,
2032 function formatProperty(ctx
, value
, recurseTimes
, visibleKeys
, key
, array
) {
2033 var name
, str
, desc
;
2034 desc
= Object
.getOwnPropertyDescriptor(value
, key
) || { value: value
[key
] };
2037 str
= ctx
.stylize('[Getter/Setter]', 'special');
2039 str
= ctx
.stylize('[Getter]', 'special');
2043 str
= ctx
.stylize('[Setter]', 'special');
2046 if (!hasOwnProperty(visibleKeys
, key
)) {
2047 name
= '[' + key
+ ']';
2050 if (ctx
.seen
.indexOf(desc
.value
) < 0) {
2051 if (isNull(recurseTimes
)) {
2052 str
= formatValue(ctx
, desc
.value
, null);
2054 str
= formatValue(ctx
, desc
.value
, recurseTimes
- 1);
2056 if (str
.indexOf('\n') > -1) {
2058 str
= str
.split('\n').map(function(line
) {
2060 }).join('\n').substr(2);
2062 str
= '\n' + str
.split('\n').map(function(line
) {
2068 str
= ctx
.stylize('[Circular]', 'special');
2071 if (isUndefined(name
)) {
2072 if (array
&& key
.match(/^\d+$/)) {
2075 name
= JSON
.stringify('' + key
);
2076 if (name
.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
2077 name
= name
.substr(1, name
.length
- 2);
2078 name
= ctx
.stylize(name
, 'name');
2080 name
= name
.replace(/'/g, "\\'")
2081 .replace(/\\"/g
, '"')
2082 .replace(/(^"|"$)/g, "'");
2083 name
= ctx
.stylize(name
, 'string');
2087 return name
+ ': ' + str
;
2091 function reduceToSingleString(output
, base
, braces
) {
2092 var numLinesEst
= 0;
2093 var length
= output
.reduce(function(prev
, cur
) {
2095 if (cur
.indexOf('\n') >= 0) numLinesEst
++;
2096 return prev
+ cur
.replace(/\u001b\[\d\d?m/g, '').length
+ 1;
2101 (base
=== '' ? '' : base
+ '\n ') +
2103 output
.join(',\n ') +
2108 return braces
[0] + base
+ ' ' + output
.join(', ') + ' ' + braces
[1];
2112 // NOTE: These type checking functions intentionally don't use `instanceof`
2113 // because it is fragile and can be easily faked with `Object.create()`.
2114 function isArray(ar
) {
2115 return Array
.isArray(ar
);
2117 exports
.isArray
= isArray
;
2119 function isBoolean(arg
) {
2120 return typeof arg
=== 'boolean';
2122 exports
.isBoolean
= isBoolean
;
2124 function isNull(arg
) {
2125 return arg
=== null;
2127 exports
.isNull
= isNull
;
2129 function isNullOrUndefined(arg
) {
2132 exports
.isNullOrUndefined
= isNullOrUndefined
;
2134 function isNumber(arg
) {
2135 return typeof arg
=== 'number';
2137 exports
.isNumber
= isNumber
;
2139 function isString(arg
) {
2140 return typeof arg
=== 'string';
2142 exports
.isString
= isString
;
2144 function isSymbol(arg
) {
2145 return typeof arg
=== 'symbol';
2147 exports
.isSymbol
= isSymbol
;
2149 function isUndefined(arg
) {
2150 return arg
=== void 0;
2152 exports
.isUndefined
= isUndefined
;
2154 function isRegExp(re
) {
2155 return isObject(re
) && objectToString(re
) === '[object RegExp]';
2157 exports
.isRegExp
= isRegExp
;
2159 function isObject(arg
) {
2160 return typeof arg
=== 'object' && arg
!== null;
2162 exports
.isObject
= isObject
;
2164 function isDate(d
) {
2165 return isObject(d
) && objectToString(d
) === '[object Date]';
2167 exports
.isDate
= isDate
;
2169 function isError(e
) {
2170 return isObject(e
) &&
2171 (objectToString(e
) === '[object Error]' || e
instanceof Error
);
2173 exports
.isError
= isError
;
2175 function isFunction(arg
) {
2176 return typeof arg
=== 'function';
2178 exports
.isFunction
= isFunction
;
2180 function isPrimitive(arg
) {
2181 return arg
=== null ||
2182 typeof arg
=== 'boolean' ||
2183 typeof arg
=== 'number' ||
2184 typeof arg
=== 'string' ||
2185 typeof arg
=== 'symbol' || // ES6 symbol
2186 typeof arg
=== 'undefined';
2188 exports
.isPrimitive
= isPrimitive
;
2190 exports
.isBuffer
= _dereq_('./support/isBuffer');
2192 function objectToString(o
) {
2193 return Object
.prototype.toString
.call(o
);
2198 return n
< 10 ? '0' + n
.toString(10) : n
.toString(10);
2202 var months
= ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
2203 'Oct', 'Nov', 'Dec'];
2206 function timestamp() {
2208 var time
= [pad(d
.getHours()),
2209 pad(d
.getMinutes()),
2210 pad(d
.getSeconds())].join(':');
2211 return [d
.getDate(), months
[d
.getMonth()], time
].join(' ');
2215 // log is just a thin wrapper to console.log that prepends a timestamp
2216 exports
.log = function() {
2217 console
.log('%s - %s', timestamp(), exports
.format
.apply(exports
, arguments
));
2222 * Inherit the prototype methods from one constructor into another.
2224 * The Function.prototype.inherits from lang.js rewritten as a standalone
2225 * function (not on Function.prototype). NOTE: If this file is to be loaded
2226 * during bootstrapping this function needs to be rewritten using some native
2227 * functions as prototype setup using normal JavaScript does not work as
2228 * expected during bootstrapping (see mirror.js in r114903).
2230 * @param {function} ctor Constructor function which needs to inherit the
2232 * @param {function} superCtor Constructor function to inherit prototype from.
2234 exports
.inherits
= _dereq_('inherits');
2236 exports
._extend = function(origin
, add
) {
2237 // Don't do anything if add isn't an object
2238 if (!add
|| !isObject(add
)) return origin
;
2240 var keys
= Object
.keys(add
);
2241 var i
= keys
.length
;
2243 origin
[keys
[i
]] = add
[keys
[i
]];
2248 function hasOwnProperty(obj
, prop
) {
2249 return Object
.prototype.hasOwnProperty
.call(obj
, prop
);
2252 }).call(this,_dereq_("FWaASH"),typeof self
!== "undefined" ? self : typeof window
!== "undefined" ? window : {})
2253 },{"./support/isBuffer":5,"FWaASH":12,"inherits":11}],7:[function(_dereq_
,module
,exports
){
2255 },{}],8:[function(_dereq_
,module
,exports
){
2257 * The buffer module from node.js, for the browser.
2259 * at author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
2263 var base64
= _dereq_('base64-js')
2264 var ieee754
= _dereq_('ieee754')
2266 exports
.Buffer
= Buffer
2267 exports
.SlowBuffer
= Buffer
2268 exports
.INSPECT_MAX_BYTES
= 50
2269 Buffer
.poolSize
= 8192
2272 * If `Buffer._useTypedArrays`:
2273 * === true Use Uint8Array implementation (fastest)
2274 * === false Use Object implementation (compatible down to IE6)
2276 Buffer
._useTypedArrays
= (function () {
2277 // Detect if browser supports Typed Arrays. Supported browsers are IE 10+, Firefox 4+,
2278 // Chrome 7+, Safari 5.1+, Opera 11.6+, iOS 4.2+. If the browser does not support adding
2279 // properties to `Uint8Array` instances, then that's the same as no `Uint8Array` support
2280 // because we need to be able to add all the node Buffer API methods. This is an issue
2281 // in Firefox 4-29. Now fixed: https://bugzilla.mozilla.org/show_bug.cgi?id=695438
2283 var buf
= new ArrayBuffer(0)
2284 var arr
= new Uint8Array(buf
)
2285 arr
.foo = function () { return 42 }
2286 return 42 === arr
.foo() &&
2287 typeof arr
.subarray
=== 'function' // Chrome 9-10 lack `subarray`
2297 * The Buffer constructor returns instances of `Uint8Array` that are augmented
2298 * with function properties for all the node `Buffer` API functions. We use
2299 * `Uint8Array` so that square bracket notation works as expected -- it returns
2302 * By augmenting the instances, we can avoid modifying the `Uint8Array`
2305 function Buffer (subject
, encoding
, noZero
) {
2306 if (!(this instanceof Buffer
))
2307 return new Buffer(subject
, encoding
, noZero
)
2309 var type
= typeof subject
2311 if (encoding
=== 'base64' && type
=== 'string') {
2312 subject
= base64clean(subject
)
2317 if (type
=== 'number')
2318 length
= coerce(subject
)
2319 else if (type
=== 'string')
2320 length
= Buffer
.byteLength(subject
, encoding
)
2321 else if (type
=== 'object')
2322 length
= coerce(subject
.length
) // assume that object is array-like
2324 throw new Error('First argument needs to be a number, array or string.')
2327 if (Buffer
._useTypedArrays
) {
2328 // Preferred: Return an augmented `Uint8Array` instance for best performance
2329 buf
= Buffer
._augment(new Uint8Array(length
))
2331 // Fallback: Return THIS instance of Buffer (created by `new`)
2334 buf
._isBuffer
= true
2338 if (Buffer
._useTypedArrays
&& typeof subject
.byteLength
=== 'number') {
2339 // Speed optimization -- use set if we're copying from a typed array
2341 } else if (isArrayish(subject
)) {
2342 // Treat array-ish objects as a byte array
2343 if (Buffer
.isBuffer(subject
)) {
2344 for (i
= 0; i
< length
; i
++)
2345 buf
[i
] = subject
.readUInt8(i
)
2347 for (i
= 0; i
< length
; i
++)
2348 buf
[i
] = ((subject
[i
] % 256) + 256) % 256
2350 } else if (type
=== 'string') {
2351 buf
.write(subject
, 0, encoding
)
2352 } else if (type
=== 'number' && !Buffer
._useTypedArrays
&& !noZero
) {
2353 for (i
= 0; i
< length
; i
++) {
2364 Buffer
.isEncoding = function (encoding
) {
2365 switch (String(encoding
).toLowerCase()) {
2383 Buffer
.isBuffer = function (b
) {
2384 return !!(b
!== null && b
!== undefined && b
._isBuffer
)
2387 Buffer
.byteLength = function (str
, encoding
) {
2389 str
= str
.toString()
2390 switch (encoding
|| 'utf8') {
2392 ret
= str
.length
/ 2
2396 ret
= utf8ToBytes(str
).length
2404 ret
= base64ToBytes(str
).length
2410 ret
= str
.length
* 2
2413 throw new Error('Unknown encoding')
2418 Buffer
.concat = function (list
, totalLength
) {
2419 assert(isArray(list
), 'Usage: Buffer.concat(list[, length])')
2421 if (list
.length
=== 0) {
2422 return new Buffer(0)
2423 } else if (list
.length
=== 1) {
2428 if (totalLength
=== undefined) {
2430 for (i
= 0; i
< list
.length
; i
++) {
2431 totalLength
+= list
[i
].length
2435 var buf
= new Buffer(totalLength
)
2437 for (i
= 0; i
< list
.length
; i
++) {
2445 Buffer
.compare = function (a
, b
) {
2446 assert(Buffer
.isBuffer(a
) && Buffer
.isBuffer(b
), 'Arguments must be Buffers')
2449 for (var i
= 0, len
= Math
.min(x
, y
); i
< len
&& a
[i
] === b
[i
]; i
++) {}
2463 // BUFFER INSTANCE METHODS
2464 // =======================
2466 function hexWrite (buf
, string
, offset
, length
) {
2467 offset
= Number(offset
) || 0
2468 var remaining
= buf
.length
- offset
2472 length
= Number(length
)
2473 if (length
> remaining
) {
2478 // must be an even number of digits
2479 var strLen
= string
.length
2480 assert(strLen
% 2 === 0, 'Invalid hex string')
2482 if (length
> strLen
/ 2) {
2485 for (var i
= 0; i
< length
; i
++) {
2486 var byte = parseInt(string
.substr(i
* 2, 2), 16)
2487 assert(!isNaN(byte), 'Invalid hex string')
2488 buf
[offset
+ i
] = byte
2493 function utf8Write (buf
, string
, offset
, length
) {
2494 var charsWritten
= blitBuffer(utf8ToBytes(string
), buf
, offset
, length
)
2498 function asciiWrite (buf
, string
, offset
, length
) {
2499 var charsWritten
= blitBuffer(asciiToBytes(string
), buf
, offset
, length
)
2503 function binaryWrite (buf
, string
, offset
, length
) {
2504 return asciiWrite(buf
, string
, offset
, length
)
2507 function base64Write (buf
, string
, offset
, length
) {
2508 var charsWritten
= blitBuffer(base64ToBytes(string
), buf
, offset
, length
)
2512 function utf16leWrite (buf
, string
, offset
, length
) {
2513 var charsWritten
= blitBuffer(utf16leToBytes(string
), buf
, offset
, length
)
2517 Buffer
.prototype.write = function (string
, offset
, length
, encoding
) {
2518 // Support both (string, offset, length, encoding)
2519 // and the legacy (string, encoding, offset, length)
2520 if (isFinite(offset
)) {
2521 if (!isFinite(length
)) {
2532 offset
= Number(offset
) || 0
2533 var remaining
= this.length
- offset
2537 length
= Number(length
)
2538 if (length
> remaining
) {
2542 encoding
= String(encoding
|| 'utf8').toLowerCase()
2547 ret
= hexWrite(this, string
, offset
, length
)
2551 ret
= utf8Write(this, string
, offset
, length
)
2554 ret
= asciiWrite(this, string
, offset
, length
)
2557 ret
= binaryWrite(this, string
, offset
, length
)
2560 ret
= base64Write(this, string
, offset
, length
)
2566 ret
= utf16leWrite(this, string
, offset
, length
)
2569 throw new Error('Unknown encoding')
2574 Buffer
.prototype.toString = function (encoding
, start
, end
) {
2577 encoding
= String(encoding
|| 'utf8').toLowerCase()
2578 start
= Number(start
) || 0
2579 end
= (end
=== undefined) ? self
.length : Number(end
)
2581 // Fastpath empty strings
2588 ret
= hexSlice(self
, start
, end
)
2592 ret
= utf8Slice(self
, start
, end
)
2595 ret
= asciiSlice(self
, start
, end
)
2598 ret
= binarySlice(self
, start
, end
)
2601 ret
= base64Slice(self
, start
, end
)
2607 ret
= utf16leSlice(self
, start
, end
)
2610 throw new Error('Unknown encoding')
2615 Buffer
.prototype.toJSON = function () {
2618 data: Array
.prototype.slice
.call(this._arr
|| this, 0)
2622 Buffer
.prototype.equals = function (b
) {
2623 assert(Buffer
.isBuffer(b
), 'Argument must be a Buffer')
2624 return Buffer
.compare(this, b
) === 0
2627 Buffer
.prototype.compare = function (b
) {
2628 assert(Buffer
.isBuffer(b
), 'Argument must be a Buffer')
2629 return Buffer
.compare(this, b
)
2632 // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
2633 Buffer
.prototype.copy = function (target
, target_start
, start
, end
) {
2636 if (!start
) start
= 0
2637 if (!end
&& end
!== 0) end
= this.length
2638 if (!target_start
) target_start
= 0
2640 // Copy 0 bytes; we're done
2641 if (end
=== start
) return
2642 if (target
.length
=== 0 || source
.length
=== 0) return
2644 // Fatal error conditions
2645 assert(end
>= start
, 'sourceEnd < sourceStart')
2646 assert(target_start
>= 0 && target_start
< target
.length
,
2647 'targetStart out of bounds')
2648 assert(start
>= 0 && start
< source
.length
, 'sourceStart out of bounds')
2649 assert(end
>= 0 && end
<= source
.length
, 'sourceEnd out of bounds')
2652 if (end
> this.length
)
2654 if (target
.length
- target_start
< end
- start
)
2655 end
= target
.length
- target_start
+ start
2657 var len
= end
- start
2659 if (len
< 100 || !Buffer
._useTypedArrays
) {
2660 for (var i
= 0; i
< len
; i
++) {
2661 target
[i
+ target_start
] = this[i
+ start
]
2664 target
._set(this.subarray(start
, start
+ len
), target_start
)
2668 function base64Slice (buf
, start
, end
) {
2669 if (start
=== 0 && end
=== buf
.length
) {
2670 return base64
.fromByteArray(buf
)
2672 return base64
.fromByteArray(buf
.slice(start
, end
))
2676 function utf8Slice (buf
, start
, end
) {
2679 end
= Math
.min(buf
.length
, end
)
2681 for (var i
= start
; i
< end
; i
++) {
2682 if (buf
[i
] <= 0x7F) {
2683 res
+= decodeUtf8Char(tmp
) + String
.fromCharCode(buf
[i
])
2686 tmp
+= '%' + buf
[i
].toString(16)
2690 return res
+ decodeUtf8Char(tmp
)
2693 function asciiSlice (buf
, start
, end
) {
2695 end
= Math
.min(buf
.length
, end
)
2697 for (var i
= start
; i
< end
; i
++) {
2698 ret
+= String
.fromCharCode(buf
[i
])
2703 function binarySlice (buf
, start
, end
) {
2704 return asciiSlice(buf
, start
, end
)
2707 function hexSlice (buf
, start
, end
) {
2708 var len
= buf
.length
2710 if (!start
|| start
< 0) start
= 0
2711 if (!end
|| end
< 0 || end
> len
) end
= len
2714 for (var i
= start
; i
< end
; i
++) {
2715 out
+= toHex(buf
[i
])
2720 function utf16leSlice (buf
, start
, end
) {
2721 var bytes
= buf
.slice(start
, end
)
2723 for (var i
= 0; i
< bytes
.length
; i
+= 2) {
2724 res
+= String
.fromCharCode(bytes
[i
] + bytes
[i
+ 1] * 256)
2729 Buffer
.prototype.slice = function (start
, end
) {
2730 var len
= this.length
2731 start
= clamp(start
, len
, 0)
2732 end
= clamp(end
, len
, len
)
2734 if (Buffer
._useTypedArrays
) {
2735 return Buffer
._augment(this.subarray(start
, end
))
2737 var sliceLen
= end
- start
2738 var newBuf
= new Buffer(sliceLen
, undefined, true)
2739 for (var i
= 0; i
< sliceLen
; i
++) {
2740 newBuf
[i
] = this[i
+ start
]
2746 // `get` will be removed in Node 0.13+
2747 Buffer
.prototype.get = function (offset
) {
2748 console
.log('.get() is deprecated. Access using array indexes instead.')
2749 return this.readUInt8(offset
)
2752 // `set` will be removed in Node 0.13+
2753 Buffer
.prototype.set = function (v
, offset
) {
2754 console
.log('.set() is deprecated. Access using array indexes instead.')
2755 return this.writeUInt8(v
, offset
)
2758 Buffer
.prototype.readUInt8 = function (offset
, noAssert
) {
2760 assert(offset
!== undefined && offset
!== null, 'missing offset')
2761 assert(offset
< this.length
, 'Trying to read beyond buffer length')
2764 if (offset
>= this.length
)
2770 function readUInt16 (buf
, offset
, littleEndian
, noAssert
) {
2772 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2773 assert(offset
!== undefined && offset
!== null, 'missing offset')
2774 assert(offset
+ 1 < buf
.length
, 'Trying to read beyond buffer length')
2777 var len
= buf
.length
2784 if (offset
+ 1 < len
)
2785 val
|= buf
[offset
+ 1] << 8
2787 val
= buf
[offset
] << 8
2788 if (offset
+ 1 < len
)
2789 val
|= buf
[offset
+ 1]
2794 Buffer
.prototype.readUInt16LE = function (offset
, noAssert
) {
2795 return readUInt16(this, offset
, true, noAssert
)
2798 Buffer
.prototype.readUInt16BE = function (offset
, noAssert
) {
2799 return readUInt16(this, offset
, false, noAssert
)
2802 function readUInt32 (buf
, offset
, littleEndian
, noAssert
) {
2804 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2805 assert(offset
!== undefined && offset
!== null, 'missing offset')
2806 assert(offset
+ 3 < buf
.length
, 'Trying to read beyond buffer length')
2809 var len
= buf
.length
2815 if (offset
+ 2 < len
)
2816 val
= buf
[offset
+ 2] << 16
2817 if (offset
+ 1 < len
)
2818 val
|= buf
[offset
+ 1] << 8
2820 if (offset
+ 3 < len
)
2821 val
= val
+ (buf
[offset
+ 3] << 24 >>> 0)
2823 if (offset
+ 1 < len
)
2824 val
= buf
[offset
+ 1] << 16
2825 if (offset
+ 2 < len
)
2826 val
|= buf
[offset
+ 2] << 8
2827 if (offset
+ 3 < len
)
2828 val
|= buf
[offset
+ 3]
2829 val
= val
+ (buf
[offset
] << 24 >>> 0)
2834 Buffer
.prototype.readUInt32LE = function (offset
, noAssert
) {
2835 return readUInt32(this, offset
, true, noAssert
)
2838 Buffer
.prototype.readUInt32BE = function (offset
, noAssert
) {
2839 return readUInt32(this, offset
, false, noAssert
)
2842 Buffer
.prototype.readInt8 = function (offset
, noAssert
) {
2844 assert(offset
!== undefined && offset
!== null,
2846 assert(offset
< this.length
, 'Trying to read beyond buffer length')
2849 if (offset
>= this.length
)
2852 var neg
= this[offset
] & 0x80
2854 return (0xff - this[offset
] + 1) * -1
2859 function readInt16 (buf
, offset
, littleEndian
, noAssert
) {
2861 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2862 assert(offset
!== undefined && offset
!== null, 'missing offset')
2863 assert(offset
+ 1 < buf
.length
, 'Trying to read beyond buffer length')
2866 var len
= buf
.length
2870 var val
= readUInt16(buf
, offset
, littleEndian
, true)
2871 var neg
= val
& 0x8000
2873 return (0xffff - val
+ 1) * -1
2878 Buffer
.prototype.readInt16LE = function (offset
, noAssert
) {
2879 return readInt16(this, offset
, true, noAssert
)
2882 Buffer
.prototype.readInt16BE = function (offset
, noAssert
) {
2883 return readInt16(this, offset
, false, noAssert
)
2886 function readInt32 (buf
, offset
, littleEndian
, noAssert
) {
2888 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2889 assert(offset
!== undefined && offset
!== null, 'missing offset')
2890 assert(offset
+ 3 < buf
.length
, 'Trying to read beyond buffer length')
2893 var len
= buf
.length
2897 var val
= readUInt32(buf
, offset
, littleEndian
, true)
2898 var neg
= val
& 0x80000000
2900 return (0xffffffff - val
+ 1) * -1
2905 Buffer
.prototype.readInt32LE = function (offset
, noAssert
) {
2906 return readInt32(this, offset
, true, noAssert
)
2909 Buffer
.prototype.readInt32BE = function (offset
, noAssert
) {
2910 return readInt32(this, offset
, false, noAssert
)
2913 function readFloat (buf
, offset
, littleEndian
, noAssert
) {
2915 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2916 assert(offset
+ 3 < buf
.length
, 'Trying to read beyond buffer length')
2919 return ieee754
.read(buf
, offset
, littleEndian
, 23, 4)
2922 Buffer
.prototype.readFloatLE = function (offset
, noAssert
) {
2923 return readFloat(this, offset
, true, noAssert
)
2926 Buffer
.prototype.readFloatBE = function (offset
, noAssert
) {
2927 return readFloat(this, offset
, false, noAssert
)
2930 function readDouble (buf
, offset
, littleEndian
, noAssert
) {
2932 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2933 assert(offset
+ 7 < buf
.length
, 'Trying to read beyond buffer length')
2936 return ieee754
.read(buf
, offset
, littleEndian
, 52, 8)
2939 Buffer
.prototype.readDoubleLE = function (offset
, noAssert
) {
2940 return readDouble(this, offset
, true, noAssert
)
2943 Buffer
.prototype.readDoubleBE = function (offset
, noAssert
) {
2944 return readDouble(this, offset
, false, noAssert
)
2947 Buffer
.prototype.writeUInt8 = function (value
, offset
, noAssert
) {
2949 assert(value
!== undefined && value
!== null, 'missing value')
2950 assert(offset
!== undefined && offset
!== null, 'missing offset')
2951 assert(offset
< this.length
, 'trying to write beyond buffer length')
2952 verifuint(value
, 0xff)
2955 if (offset
>= this.length
) return
2957 this[offset
] = value
2961 function writeUInt16 (buf
, value
, offset
, littleEndian
, noAssert
) {
2963 assert(value
!== undefined && value
!== null, 'missing value')
2964 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2965 assert(offset
!== undefined && offset
!== null, 'missing offset')
2966 assert(offset
+ 1 < buf
.length
, 'trying to write beyond buffer length')
2967 verifuint(value
, 0xffff)
2970 var len
= buf
.length
2974 for (var i
= 0, j
= Math
.min(len
- offset
, 2); i
< j
; i
++) {
2976 (value
& (0xff << (8 * (littleEndian
? i : 1 - i
)))) >>>
2977 (littleEndian
? i : 1 - i
) * 8
2982 Buffer
.prototype.writeUInt16LE = function (value
, offset
, noAssert
) {
2983 return writeUInt16(this, value
, offset
, true, noAssert
)
2986 Buffer
.prototype.writeUInt16BE = function (value
, offset
, noAssert
) {
2987 return writeUInt16(this, value
, offset
, false, noAssert
)
2990 function writeUInt32 (buf
, value
, offset
, littleEndian
, noAssert
) {
2992 assert(value
!== undefined && value
!== null, 'missing value')
2993 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
2994 assert(offset
!== undefined && offset
!== null, 'missing offset')
2995 assert(offset
+ 3 < buf
.length
, 'trying to write beyond buffer length')
2996 verifuint(value
, 0xffffffff)
2999 var len
= buf
.length
3003 for (var i
= 0, j
= Math
.min(len
- offset
, 4); i
< j
; i
++) {
3005 (value
>>> (littleEndian
? i : 3 - i
) * 8) & 0xff
3010 Buffer
.prototype.writeUInt32LE = function (value
, offset
, noAssert
) {
3011 return writeUInt32(this, value
, offset
, true, noAssert
)
3014 Buffer
.prototype.writeUInt32BE = function (value
, offset
, noAssert
) {
3015 return writeUInt32(this, value
, offset
, false, noAssert
)
3018 Buffer
.prototype.writeInt8 = function (value
, offset
, noAssert
) {
3020 assert(value
!== undefined && value
!== null, 'missing value')
3021 assert(offset
!== undefined && offset
!== null, 'missing offset')
3022 assert(offset
< this.length
, 'Trying to write beyond buffer length')
3023 verifsint(value
, 0x7f, -0x80)
3026 if (offset
>= this.length
)
3030 this.writeUInt8(value
, offset
, noAssert
)
3032 this.writeUInt8(0xff + value
+ 1, offset
, noAssert
)
3036 function writeInt16 (buf
, value
, offset
, littleEndian
, noAssert
) {
3038 assert(value
!== undefined && value
!== null, 'missing value')
3039 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
3040 assert(offset
!== undefined && offset
!== null, 'missing offset')
3041 assert(offset
+ 1 < buf
.length
, 'Trying to write beyond buffer length')
3042 verifsint(value
, 0x7fff, -0x8000)
3045 var len
= buf
.length
3050 writeUInt16(buf
, value
, offset
, littleEndian
, noAssert
)
3052 writeUInt16(buf
, 0xffff + value
+ 1, offset
, littleEndian
, noAssert
)
3056 Buffer
.prototype.writeInt16LE = function (value
, offset
, noAssert
) {
3057 return writeInt16(this, value
, offset
, true, noAssert
)
3060 Buffer
.prototype.writeInt16BE = function (value
, offset
, noAssert
) {
3061 return writeInt16(this, value
, offset
, false, noAssert
)
3064 function writeInt32 (buf
, value
, offset
, littleEndian
, noAssert
) {
3066 assert(value
!== undefined && value
!== null, 'missing value')
3067 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
3068 assert(offset
!== undefined && offset
!== null, 'missing offset')
3069 assert(offset
+ 3 < buf
.length
, 'Trying to write beyond buffer length')
3070 verifsint(value
, 0x7fffffff, -0x80000000)
3073 var len
= buf
.length
3078 writeUInt32(buf
, value
, offset
, littleEndian
, noAssert
)
3080 writeUInt32(buf
, 0xffffffff + value
+ 1, offset
, littleEndian
, noAssert
)
3084 Buffer
.prototype.writeInt32LE = function (value
, offset
, noAssert
) {
3085 return writeInt32(this, value
, offset
, true, noAssert
)
3088 Buffer
.prototype.writeInt32BE = function (value
, offset
, noAssert
) {
3089 return writeInt32(this, value
, offset
, false, noAssert
)
3092 function writeFloat (buf
, value
, offset
, littleEndian
, noAssert
) {
3094 assert(value
!== undefined && value
!== null, 'missing value')
3095 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
3096 assert(offset
!== undefined && offset
!== null, 'missing offset')
3097 assert(offset
+ 3 < buf
.length
, 'Trying to write beyond buffer length')
3098 verifIEEE754(value
, 3.4028234663852886e+38, -3.4028234663852886e+38)
3101 var len
= buf
.length
3105 ieee754
.write(buf
, value
, offset
, littleEndian
, 23, 4)
3109 Buffer
.prototype.writeFloatLE = function (value
, offset
, noAssert
) {
3110 return writeFloat(this, value
, offset
, true, noAssert
)
3113 Buffer
.prototype.writeFloatBE = function (value
, offset
, noAssert
) {
3114 return writeFloat(this, value
, offset
, false, noAssert
)
3117 function writeDouble (buf
, value
, offset
, littleEndian
, noAssert
) {
3119 assert(value
!== undefined && value
!== null, 'missing value')
3120 assert(typeof littleEndian
=== 'boolean', 'missing or invalid endian')
3121 assert(offset
!== undefined && offset
!== null, 'missing offset')
3122 assert(offset
+ 7 < buf
.length
,
3123 'Trying to write beyond buffer length')
3124 verifIEEE754(value
, 1.7976931348623157E+308, -1.7976931348623157E+308)
3127 var len
= buf
.length
3131 ieee754
.write(buf
, value
, offset
, littleEndian
, 52, 8)
3135 Buffer
.prototype.writeDoubleLE = function (value
, offset
, noAssert
) {
3136 return writeDouble(this, value
, offset
, true, noAssert
)
3139 Buffer
.prototype.writeDoubleBE = function (value
, offset
, noAssert
) {
3140 return writeDouble(this, value
, offset
, false, noAssert
)
3143 // fill(value, start=0, end=buffer.length)
3144 Buffer
.prototype.fill = function (value
, start
, end
) {
3145 if (!value
) value
= 0
3146 if (!start
) start
= 0
3147 if (!end
) end
= this.length
3149 assert(end
>= start
, 'end < start')
3151 // Fill 0 bytes; we're done
3152 if (end
=== start
) return
3153 if (this.length
=== 0) return
3155 assert(start
>= 0 && start
< this.length
, 'start out of bounds')
3156 assert(end
>= 0 && end
<= this.length
, 'end out of bounds')
3159 if (typeof value
=== 'number') {
3160 for (i
= start
; i
< end
; i
++) {
3164 var bytes
= utf8ToBytes(value
.toString())
3165 var len
= bytes
.length
3166 for (i
= start
; i
< end
; i
++) {
3167 this[i
] = bytes
[i
% len
]
3174 Buffer
.prototype.inspect = function () {
3176 var len
= this.length
3177 for (var i
= 0; i
< len
; i
++) {
3178 out
[i
] = toHex(this[i
])
3179 if (i
=== exports
.INSPECT_MAX_BYTES
) {
3184 return '<Buffer ' + out
.join(' ') + '>'
3188 * Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
3189 * Added in Node 0.12. Only available in browsers that support ArrayBuffer.
3191 Buffer
.prototype.toArrayBuffer = function () {
3192 if (typeof Uint8Array
!== 'undefined') {
3193 if (Buffer
._useTypedArrays
) {
3194 return (new Buffer(this)).buffer
3196 var buf
= new Uint8Array(this.length
)
3197 for (var i
= 0, len
= buf
.length
; i
< len
; i
+= 1) {
3203 throw new Error('Buffer.toArrayBuffer not supported in this browser')
3210 var BP
= Buffer
.prototype
3213 * Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
3215 Buffer
._augment = function (arr
) {
3216 arr
._isBuffer
= true
3218 // save reference to original Uint8Array get/set methods before overwriting
3222 // deprecated, will be removed in node 0.13+
3226 arr
.write
= BP
.write
3227 arr
.toString
= BP
.toString
3228 arr
.toLocaleString
= BP
.toString
3229 arr
.toJSON
= BP
.toJSON
3230 arr
.equals
= BP
.equals
3231 arr
.compare
= BP
.compare
3233 arr
.slice
= BP
.slice
3234 arr
.readUInt8
= BP
.readUInt8
3235 arr
.readUInt16LE
= BP
.readUInt16LE
3236 arr
.readUInt16BE
= BP
.readUInt16BE
3237 arr
.readUInt32LE
= BP
.readUInt32LE
3238 arr
.readUInt32BE
= BP
.readUInt32BE
3239 arr
.readInt8
= BP
.readInt8
3240 arr
.readInt16LE
= BP
.readInt16LE
3241 arr
.readInt16BE
= BP
.readInt16BE
3242 arr
.readInt32LE
= BP
.readInt32LE
3243 arr
.readInt32BE
= BP
.readInt32BE
3244 arr
.readFloatLE
= BP
.readFloatLE
3245 arr
.readFloatBE
= BP
.readFloatBE
3246 arr
.readDoubleLE
= BP
.readDoubleLE
3247 arr
.readDoubleBE
= BP
.readDoubleBE
3248 arr
.writeUInt8
= BP
.writeUInt8
3249 arr
.writeUInt16LE
= BP
.writeUInt16LE
3250 arr
.writeUInt16BE
= BP
.writeUInt16BE
3251 arr
.writeUInt32LE
= BP
.writeUInt32LE
3252 arr
.writeUInt32BE
= BP
.writeUInt32BE
3253 arr
.writeInt8
= BP
.writeInt8
3254 arr
.writeInt16LE
= BP
.writeInt16LE
3255 arr
.writeInt16BE
= BP
.writeInt16BE
3256 arr
.writeInt32LE
= BP
.writeInt32LE
3257 arr
.writeInt32BE
= BP
.writeInt32BE
3258 arr
.writeFloatLE
= BP
.writeFloatLE
3259 arr
.writeFloatBE
= BP
.writeFloatBE
3260 arr
.writeDoubleLE
= BP
.writeDoubleLE
3261 arr
.writeDoubleBE
= BP
.writeDoubleBE
3263 arr
.inspect
= BP
.inspect
3264 arr
.toArrayBuffer
= BP
.toArrayBuffer
3269 var INVALID_BASE64_RE
= /[^+\/0-9A-z]/g
3271 function base64clean (str
) {
3272 // Node strips out invalid characters like \n and \t from the string, base64-js does not
3273 str
= stringtrim(str
).replace(INVALID_BASE64_RE
, '')
3274 // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
3275 while (str
.length
% 4 !== 0) {
3281 function stringtrim (str
) {
3282 if (str
.trim
) return str
.trim()
3283 return str
.replace(/^\s+|\s+$/g, '')
3286 // slice(start, end)
3287 function clamp (index
, len
, defaultValue
) {
3288 if (typeof index
!== 'number') return defaultValue
3289 index
= ~~index
; // Coerce to integer.
3290 if (index
>= len
) return len
3291 if (index
>= 0) return index
3293 if (index
>= 0) return index
3297 function coerce (length
) {
3298 // Coerce length to a number (possibly NaN), round up
3299 // in case it's fractional (e.g. 123.456) then do a
3300 // double negate to coerce a NaN to 0. Easy, right?
3301 length
= ~~Math
.ceil(+length
)
3302 return length
< 0 ? 0 : length
3305 function isArray (subject
) {
3306 return (Array
.isArray
|| function (subject
) {
3307 return Object
.prototype.toString
.call(subject
) === '[object Array]'
3311 function isArrayish (subject
) {
3312 return isArray(subject
) || Buffer
.isBuffer(subject
) ||
3313 subject
&& typeof subject
=== 'object' &&
3314 typeof subject
.length
=== 'number'
3317 function toHex (n
) {
3318 if (n
< 16) return '0' + n
.toString(16)
3319 return n
.toString(16)
3322 function utf8ToBytes (str
) {
3324 for (var i
= 0; i
< str
.length
; i
++) {
3325 var b
= str
.charCodeAt(i
)
3330 if (b
>= 0xD800 && b
<= 0xDFFF) i
++
3331 var h
= encodeURIComponent(str
.slice(start
, i
+1)).substr(1).split('%')
3332 for (var j
= 0; j
< h
.length
; j
++) {
3333 byteArray
.push(parseInt(h
[j
], 16))
3340 function asciiToBytes (str
) {
3342 for (var i
= 0; i
< str
.length
; i
++) {
3343 // Node's code seems to be doing this and not & 0x7F..
3344 byteArray
.push(str
.charCodeAt(i
) & 0xFF)
3349 function utf16leToBytes (str
) {
3352 for (var i
= 0; i
< str
.length
; i
++) {
3353 c
= str
.charCodeAt(i
)
3363 function base64ToBytes (str
) {
3364 return base64
.toByteArray(str
)
3367 function blitBuffer (src
, dst
, offset
, length
) {
3368 for (var i
= 0; i
< length
; i
++) {
3369 if ((i
+ offset
>= dst
.length
) || (i
>= src
.length
))
3371 dst
[i
+ offset
] = src
[i
]
3376 function decodeUtf8Char (str
) {
3378 return decodeURIComponent(str
)
3380 return String
.fromCharCode(0xFFFD) // UTF 8 invalid char
3385 * We have to make sure that the value is a valid integer. This means that it
3386 * is non-negative. It has no fractional component and that it does not
3387 * exceed the maximum allowed value.
3389 function verifuint (value
, max
) {
3390 assert(typeof value
=== 'number', 'cannot write a non-number as a number')
3391 assert(value
>= 0, 'specified a negative value for writing an unsigned value')
3392 assert(value
<= max
, 'value is larger than maximum value for type')
3393 assert(Math
.floor(value
) === value
, 'value has a fractional component')
3396 function verifsint (value
, max
, min
) {
3397 assert(typeof value
=== 'number', 'cannot write a non-number as a number')
3398 assert(value
<= max
, 'value larger than maximum allowed value')
3399 assert(value
>= min
, 'value smaller than minimum allowed value')
3400 assert(Math
.floor(value
) === value
, 'value has a fractional component')
3403 function verifIEEE754 (value
, max
, min
) {
3404 assert(typeof value
=== 'number', 'cannot write a non-number as a number')
3405 assert(value
<= max
, 'value larger than maximum allowed value')
3406 assert(value
>= min
, 'value smaller than minimum allowed value')
3409 function assert (test
, message
) {
3410 if (!test
) throw new Error(message
|| 'Failed assertion')
3413 },{"base64-js":9,"ieee754":10}],9:[function(_dereq_
,module
,exports
){
3414 var lookup
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
3416 ;(function (exports
) {
3419 var Arr
= (typeof Uint8Array
!== 'undefined')
3423 var PLUS
= '+'.charCodeAt(0)
3424 var SLASH
= '/'.charCodeAt(0)
3425 var NUMBER
= '0'.charCodeAt(0)
3426 var LOWER
= 'a'.charCodeAt(0)
3427 var UPPER
= 'A'.charCodeAt(0)
3429 function decode (elt
) {
3430 var code
= elt
.charCodeAt(0)
3436 return -1 //no match
3437 if (code
< NUMBER
+ 10)
3438 return code
- NUMBER
+ 26 + 26
3439 if (code
< UPPER
+ 26)
3441 if (code
< LOWER
+ 26)
3442 return code
- LOWER
+ 26
3445 function b64ToByteArray (b64
) {
3446 var i
, j
, l
, tmp
, placeHolders
, arr
3448 if (b64
.length
% 4 > 0) {
3449 throw new Error('Invalid string. Length must be a multiple of 4')
3452 // the number of equal signs (place holders)
3453 // if there are two placeholders, than the two characters before it
3454 // represent one byte
3455 // if there is only one, then the three characters before it represent 2 bytes
3456 // this is just a cheap hack to not do indexOf twice
3457 var len
= b64
.length
3458 placeHolders
= '=' === b64
.charAt(len
- 2) ? 2 : '=' === b64
.charAt(len
- 1) ? 1 : 0
3460 // base64 is 4/3 + up to two characters of the original data
3461 arr
= new Arr(b64
.length
* 3 / 4 - placeHolders
)
3463 // if there are placeholders, only get up to the last complete 4 chars
3464 l
= placeHolders
> 0 ? b64
.length
- 4 : b64
.length
3472 for (i
= 0, j
= 0; i
< l
; i
+= 4, j
+= 3) {
3473 tmp
= (decode(b64
.charAt(i
)) << 18) | (decode(b64
.charAt(i
+ 1)) << 12) | (decode(b64
.charAt(i
+ 2)) << 6) | decode(b64
.charAt(i
+ 3))
3474 push((tmp
& 0xFF0000) >> 16)
3475 push((tmp
& 0xFF00) >> 8)
3479 if (placeHolders
=== 2) {
3480 tmp
= (decode(b64
.charAt(i
)) << 2) | (decode(b64
.charAt(i
+ 1)) >> 4)
3482 } else if (placeHolders
=== 1) {
3483 tmp
= (decode(b64
.charAt(i
)) << 10) | (decode(b64
.charAt(i
+ 1)) << 4) | (decode(b64
.charAt(i
+ 2)) >> 2)
3484 push((tmp
>> 8) & 0xFF)
3491 function uint8ToBase64 (uint8
) {
3493 extraBytes
= uint8
.length
% 3, // if we have 1 byte left, pad 2 bytes
3497 function encode (num
) {
3498 return lookup
.charAt(num
)
3501 function tripletToBase64 (num
) {
3502 return encode(num
>> 18 & 0x3F) + encode(num
>> 12 & 0x3F) + encode(num
>> 6 & 0x3F) + encode(num
& 0x3F)
3505 // go through the array every three bytes, we'll deal with trailing stuff later
3506 for (i
= 0, length
= uint8
.length
- extraBytes
; i
< length
; i
+= 3) {
3507 temp
= (uint8
[i
] << 16) + (uint8
[i
+ 1] << 8) + (uint8
[i
+ 2])
3508 output
+= tripletToBase64(temp
)
3511 // pad the end with zeros, but make sure to not forget the extra bytes
3512 switch (extraBytes
) {
3514 temp
= uint8
[uint8
.length
- 1]
3515 output
+= encode(temp
>> 2)
3516 output
+= encode((temp
<< 4) & 0x3F)
3520 temp
= (uint8
[uint8
.length
- 2] << 8) + (uint8
[uint8
.length
- 1])
3521 output
+= encode(temp
>> 10)
3522 output
+= encode((temp
>> 4) & 0x3F)
3523 output
+= encode((temp
<< 2) & 0x3F)
3531 exports
.toByteArray
= b64ToByteArray
3532 exports
.fromByteArray
= uint8ToBase64
3533 }(typeof exports
=== 'undefined' ? (this.base64js
= {}) : exports
))
3535 },{}],10:[function(_dereq_
,module
,exports
){
3536 exports
.read = function(buffer
, offset
, isLE
, mLen
, nBytes
) {
3538 eLen
= nBytes
* 8 - mLen
- 1,
3539 eMax
= (1 << eLen
) - 1,
3542 i
= isLE
? (nBytes
- 1) : 0,
3544 s
= buffer
[offset
+ i
];
3548 e
= s
& ((1 << (-nBits
)) - 1);
3551 for (; nBits
> 0; e
= e
* 256 + buffer
[offset
+ i
], i
+= d
, nBits
-= 8){};
3553 m
= e
& ((1 << (-nBits
)) - 1);
3556 for (; nBits
> 0; m
= m
* 256 + buffer
[offset
+ i
], i
+= d
, nBits
-= 8){};
3560 } else if (e
=== eMax
) {
3561 return m
? NaN : ((s
? -1 : 1) * Infinity
);
3563 m
= m
+ Math
.pow(2, mLen
);
3566 return (s
? -1 : 1) * m
* Math
.pow(2, e
- mLen
);
3569 exports
.write = function(buffer
, value
, offset
, isLE
, mLen
, nBytes
) {
3571 eLen
= nBytes
* 8 - mLen
- 1,
3572 eMax
= (1 << eLen
) - 1,
3574 rt
= (mLen
=== 23 ? Math
.pow(2, -24) - Math
.pow(2, -77) : 0),
3575 i
= isLE
? 0 : (nBytes
- 1),
3577 s
= value
< 0 || (value
=== 0 && 1 / value
< 0) ? 1 : 0;
3579 value
= Math
.abs(value
);
3581 if (isNaN(value
) || value
=== Infinity
) {
3582 m
= isNaN(value
) ? 1 : 0;
3585 e
= Math
.floor(Math
.log(value
) / Math
.LN2
);
3586 if (value
* (c
= Math
.pow(2, -e
)) < 1) {
3590 if (e
+ eBias
>= 1) {
3593 value
+= rt
* Math
.pow(2, 1 - eBias
);
3595 if (value
* c
>= 2) {
3600 if (e
+ eBias
>= eMax
) {
3603 } else if (e
+ eBias
>= 1) {
3604 m
= (value
* c
- 1) * Math
.pow(2, mLen
);
3607 m
= value
* Math
.pow(2, eBias
- 1) * Math
.pow(2, mLen
);
3612 for (; mLen
>= 8; buffer
[offset
+ i
] = m
& 0xff, i
+= d
, m
/= 256, mLen
-= 8){};
3614 e
= (e
<< mLen
) | m
;
3616 for (; eLen
> 0; buffer
[offset
+ i
] = e
& 0xff, i
+= d
, e
/= 256, eLen
-= 8){};
3618 buffer
[offset
+ i
- d
] |= s
* 128;
3621 },{}],11:[function(_dereq_
,module
,exports
){
3622 if (typeof Object
.create
=== 'function') {
3623 // implementation from standard node.js 'util' module
3624 module
.exports
= function inherits(ctor
, superCtor
) {
3625 ctor
.super_
= superCtor
3626 ctor
.prototype = Object
.create(superCtor
.prototype, {
3636 // old school shim for old browsers
3637 module
.exports
= function inherits(ctor
, superCtor
) {
3638 ctor
.super_
= superCtor
3639 var TempCtor = function () {}
3640 TempCtor
.prototype = superCtor
.prototype
3641 ctor
.prototype = new TempCtor()
3642 ctor
.prototype.constructor = ctor
3646 },{}],12:[function(_dereq_
,module
,exports
){
3647 // shim for using process in browser
3649 var process
= module
.exports
= {};
3651 process
.nextTick
= (function () {
3652 var canSetImmediate
= typeof window
!== 'undefined'
3653 && window
.setImmediate
;
3654 var canPost
= typeof window
!== 'undefined'
3655 && window
.postMessage
&& window
.addEventListener
3658 if (canSetImmediate
) {
3659 return function (f
) { return window
.setImmediate(f
) };
3664 window
.addEventListener('message', function (ev
) {
3665 var source
= ev
.source
;
3666 if ((source
=== window
|| source
=== null) && ev
.data
=== 'process-tick') {
3667 ev
.stopPropagation();
3668 if (queue
.length
> 0) {
3669 var fn
= queue
.shift();
3675 return function nextTick(fn
) {
3677 window
.postMessage('process-tick', '*');
3681 return function nextTick(fn
) {
3686 process
.title
= 'browser';
3687 process
.browser
= true;
3694 process
.addListener
= noop
;
3695 process
.once
= noop
;
3697 process
.removeListener
= noop
;
3698 process
.removeAllListeners
= noop
;
3699 process
.emit
= noop
;
3701 process
.binding = function (name
) {
3702 throw new Error('process.binding is not supported');
3706 process
.cwd = function () { return '/' };
3707 process
.chdir = function (dir
) {
3708 throw new Error('process.chdir is not supported');
3711 },{}],13:[function(_dereq_
,module
,exports
){
3712 module
.exports
=_dereq_(5)
3713 },{}],14:[function(_dereq_
,module
,exports
){
3714 module
.exports
=_dereq_(6)
3715 },{"./support/isBuffer":13,"FWaASH":12,"inherits":11}],15:[function(_dereq_
,module
,exports
){
3717 // Base58 encoding/decoding
3718 // Originally written by Mike Hearn for BitcoinJ
3719 // Copyright (c) 2011 Google Inc
3720 // Ported to JavaScript by Stefan Thomas
3721 // Merged Buffer refactorings from base58-native by Stephen Pair
3722 // Copyright (c) 2013 BitPay Inc
3724 var assert
= _dereq_('assert')
3725 var BigInteger
= _dereq_('bigi')
3727 var ALPHABET
= '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'
3728 var ALPHABET_BUF
= new Buffer(ALPHABET
, 'ascii')
3729 var ALPHABET_MAP
= {}
3730 for(var i
= 0; i
< ALPHABET
.length
; i
++) {
3731 ALPHABET_MAP
[ALPHABET
.charAt(i
)] = BigInteger
.valueOf(i
)
3733 var BASE
= new BigInteger('58')
3735 function encode(buffer
) {
3736 var bi
= BigInteger
.fromBuffer(buffer
)
3737 var result
= new Buffer(buffer
.length
<< 1)
3739 var i
= result
.length
- 1
3740 while (bi
.signum() > 0) {
3741 var remainder
= bi
.mod(BASE
)
3742 bi
= bi
.divide(BASE
)
3744 result
[i
] = ALPHABET_BUF
[remainder
.intValue()]
3748 // deal with leading zeros
3750 while (buffer
[j
] === 0) {
3751 result
[i
] = ALPHABET_BUF
[0]
3756 return result
.slice(i
+ 1, result
.length
).toString('ascii')
3759 function decode(string
) {
3760 if (string
.length
=== 0) return new Buffer(0)
3762 var num
= BigInteger
.ZERO
3764 for (var i
= 0; i
< string
.length
; i
++) {
3765 num
= num
.multiply(BASE
)
3767 var figure
= ALPHABET_MAP
[string
.charAt(i
)]
3768 assert
.notEqual(figure
, undefined, 'Non-base58 character')
3770 num
= num
.add(figure
)
3773 // deal with leading zeros
3775 while ((j
< string
.length
) && (string
[j
] === ALPHABET
[0])) {
3779 var buffer
= num
.toBuffer()
3780 var leadingZeros
= new Buffer(j
)
3781 leadingZeros
.fill(0)
3783 return Buffer
.concat([leadingZeros
, buffer
])
3791 }).call(this,_dereq_("buffer").Buffer
)
3792 },{"assert":4,"bigi":3,"buffer":8}],16:[function(_dereq_
,module
,exports
){
3794 var createHash
= _dereq_('sha.js')
3796 var md5
= toConstructor(_dereq_('./md5'))
3797 var rmd160
= toConstructor(_dereq_('ripemd160'))
3799 function toConstructor (fn
) {
3800 return function () {
3803 update: function (data
, enc
) {
3804 if(!Buffer
.isBuffer(data
)) data
= new Buffer(data
, enc
)
3808 digest: function (enc
) {
3809 var buf
= Buffer
.concat(buffers
)
3812 return enc
? r
.toString(enc
) : r
3819 module
.exports = function (alg
) {
3820 if('md5' === alg
) return new md5()
3821 if('rmd160' === alg
) return new rmd160()
3822 return createHash(alg
)
3825 }).call(this,_dereq_("buffer").Buffer
)
3826 },{"./md5":20,"buffer":8,"ripemd160":21,"sha.js":23}],17:[function(_dereq_
,module
,exports
){
3828 var createHash
= _dereq_('./create-hash')
3831 var zeroBuffer
= new Buffer(blocksize
); zeroBuffer
.fill(0)
3833 module
.exports
= Hmac
3835 function Hmac (alg
, key
) {
3836 if(!(this instanceof Hmac
)) return new Hmac(alg
, key
)
3840 key
= this._key
= !Buffer
.isBuffer(key
) ? new Buffer(key
) : key
3842 if(key
.length
> blocksize
) {
3843 key
= createHash(alg
).update(key
).digest()
3844 } else if(key
.length
< blocksize
) {
3845 key
= Buffer
.concat([key
, zeroBuffer
], blocksize
)
3848 var ipad
= this._ipad
= new Buffer(blocksize
)
3849 var opad
= this._opad
= new Buffer(blocksize
)
3851 for(var i
= 0; i
< blocksize
; i
++) {
3852 ipad
[i
] = key
[i
] ^ 0x36
3853 opad
[i
] = key
[i
] ^ 0x5C
3856 this._hash
= createHash(alg
).update(ipad
)
3859 Hmac
.prototype.update = function (data
, enc
) {
3860 this._hash
.update(data
, enc
)
3864 Hmac
.prototype.digest = function (enc
) {
3865 var h
= this._hash
.digest()
3866 return createHash(this._alg
).update(this._opad
).update(h
).digest(enc
)
3870 }).call(this,_dereq_("buffer").Buffer
)
3871 },{"./create-hash":16,"buffer":8}],18:[function(_dereq_
,module
,exports
){
3874 var zeroBuffer
= new Buffer(intSize
); zeroBuffer
.fill(0);
3877 function toArray(buf
, bigEndian
) {
3878 if ((buf
.length
% intSize
) !== 0) {
3879 var len
= buf
.length
+ (intSize
- (buf
.length
% intSize
));
3880 buf
= Buffer
.concat([buf
, zeroBuffer
], len
);
3884 var fn
= bigEndian
? buf
.readInt32BE : buf
.readInt32LE
;
3885 for (var i
= 0; i
< buf
.length
; i
+= intSize
) {
3886 arr
.push(fn
.call(buf
, i
));
3891 function toBuffer(arr
, size
, bigEndian
) {
3892 var buf
= new Buffer(size
);
3893 var fn
= bigEndian
? buf
.writeInt32BE : buf
.writeInt32LE
;
3894 for (var i
= 0; i
< arr
.length
; i
++) {
3895 fn
.call(buf
, arr
[i
], i
* 4, true);
3900 function hash(buf
, fn
, hashSize
, bigEndian
) {
3901 if (!Buffer
.isBuffer(buf
)) buf
= new Buffer(buf
);
3902 var arr
= fn(toArray(buf
, bigEndian
), buf
.length
* chrsz
);
3903 return toBuffer(arr
, hashSize
, bigEndian
);
3906 module
.exports
= { hash: hash
};
3908 }).call(this,_dereq_("buffer").Buffer
)
3909 },{"buffer":8}],19:[function(_dereq_
,module
,exports
){
3911 var rng
= _dereq_('./rng')
3914 var m
= [].slice
.call(arguments
).join(' ')
3917 'we accept pull requests',
3918 'http://github.com/dominictarr/crypto-browserify'
3922 exports
.createHash
= _dereq_('./create-hash')
3924 exports
.createHmac
= _dereq_('./create-hmac')
3926 exports
.randomBytes = function(size
, callback
) {
3927 if (callback
&& callback
.call
) {
3929 callback
.call(this, undefined, new Buffer(rng(size
)))
3930 } catch (err
) { callback(err
) }
3932 return new Buffer(rng(size
))
3936 function each(a
, f
) {
3941 exports
.getHashes = function () {
3942 return ['sha1', 'sha256', 'md5', 'rmd160']
3946 var p
= _dereq_('./pbkdf2')(exports
.createHmac
)
3947 exports
.pbkdf2
= p
.pbkdf2
3948 exports
.pbkdf2Sync
= p
.pbkdf2Sync
3951 // the least I can do is make error messages for the rest of the node.js/crypto api.
3952 each(['createCredentials'
3956 , 'createDecipheriv'
3959 , 'createDiffieHellman'
3960 ], function (name
) {
3961 exports
[name
] = function () {
3962 error('sorry,', name
, 'is not implemented yet')
3966 }).call(this,_dereq_("buffer").Buffer
)
3967 },{"./create-hash":16,"./create-hmac":17,"./pbkdf2":27,"./rng":28,"buffer":8}],20:[function(_dereq_
,module
,exports
){
3969 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
3970 * Digest Algorithm, as defined in RFC 1321.
3971 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
3972 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
3973 * Distributed under the BSD License
3974 * See http://pajhome.org.uk/crypt/md5 for more info.
3977 var helpers
= _dereq_('./helpers');
3980 * Calculate the MD5 of an array of little-endian words, and a bit length
3982 function core_md5(x
, len
)
3984 /* append padding */
3985 x
[len
>> 5] |= 0x80 << ((len
) % 32);
3986 x
[(((len
+ 64) >>> 9) << 4) + 14] = len
;
3990 var c
= -1732584194;
3993 for(var i
= 0; i
< x
.length
; i
+= 16)
4000 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 0], 7 , -680876936);
4001 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 1], 12, -389564586);
4002 c
= md5_ff(c
, d
, a
, b
, x
[i
+ 2], 17, 606105819);
4003 b
= md5_ff(b
, c
, d
, a
, x
[i
+ 3], 22, -1044525330);
4004 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 4], 7 , -176418897);
4005 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 5], 12, 1200080426);
4006 c
= md5_ff(c
, d
, a
, b
, x
[i
+ 6], 17, -1473231341);
4007 b
= md5_ff(b
, c
, d
, a
, x
[i
+ 7], 22, -45705983);
4008 a
= md5_ff(a
, b
, c
, d
, x
[i
+ 8], 7 , 1770035416);
4009 d
= md5_ff(d
, a
, b
, c
, x
[i
+ 9], 12, -1958414417);
4010 c
= md5_ff(c
, d
, a
, b
, x
[i
+10], 17, -42063);
4011 b
= md5_ff(b
, c
, d
, a
, x
[i
+11], 22, -1990404162);
4012 a
= md5_ff(a
, b
, c
, d
, x
[i
+12], 7 , 1804603682);
4013 d
= md5_ff(d
, a
, b
, c
, x
[i
+13], 12, -40341101);
4014 c
= md5_ff(c
, d
, a
, b
, x
[i
+14], 17, -1502002290);
4015 b
= md5_ff(b
, c
, d
, a
, x
[i
+15], 22, 1236535329);
4017 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 1], 5 , -165796510);
4018 d
= md5_gg(d
, a
, b
, c
, x
[i
+ 6], 9 , -1069501632);
4019 c
= md5_gg(c
, d
, a
, b
, x
[i
+11], 14, 643717713);
4020 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 0], 20, -373897302);
4021 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 5], 5 , -701558691);
4022 d
= md5_gg(d
, a
, b
, c
, x
[i
+10], 9 , 38016083);
4023 c
= md5_gg(c
, d
, a
, b
, x
[i
+15], 14, -660478335);
4024 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 4], 20, -405537848);
4025 a
= md5_gg(a
, b
, c
, d
, x
[i
+ 9], 5 , 568446438);
4026 d
= md5_gg(d
, a
, b
, c
, x
[i
+14], 9 , -1019803690);
4027 c
= md5_gg(c
, d
, a
, b
, x
[i
+ 3], 14, -187363961);
4028 b
= md5_gg(b
, c
, d
, a
, x
[i
+ 8], 20, 1163531501);
4029 a
= md5_gg(a
, b
, c
, d
, x
[i
+13], 5 , -1444681467);
4030 d
= md5_gg(d
, a
, b
, c
, x
[i
+ 2], 9 , -51403784);
4031 c
= md5_gg(c
, d
, a
, b
, x
[i
+ 7], 14, 1735328473);
4032 b
= md5_gg(b
, c
, d
, a
, x
[i
+12], 20, -1926607734);
4034 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 5], 4 , -378558);
4035 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 8], 11, -2022574463);
4036 c
= md5_hh(c
, d
, a
, b
, x
[i
+11], 16, 1839030562);
4037 b
= md5_hh(b
, c
, d
, a
, x
[i
+14], 23, -35309556);
4038 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 1], 4 , -1530992060);
4039 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 4], 11, 1272893353);
4040 c
= md5_hh(c
, d
, a
, b
, x
[i
+ 7], 16, -155497632);
4041 b
= md5_hh(b
, c
, d
, a
, x
[i
+10], 23, -1094730640);
4042 a
= md5_hh(a
, b
, c
, d
, x
[i
+13], 4 , 681279174);
4043 d
= md5_hh(d
, a
, b
, c
, x
[i
+ 0], 11, -358537222);
4044 c
= md5_hh(c
, d
, a
, b
, x
[i
+ 3], 16, -722521979);
4045 b
= md5_hh(b
, c
, d
, a
, x
[i
+ 6], 23, 76029189);
4046 a
= md5_hh(a
, b
, c
, d
, x
[i
+ 9], 4 , -640364487);
4047 d
= md5_hh(d
, a
, b
, c
, x
[i
+12], 11, -421815835);
4048 c
= md5_hh(c
, d
, a
, b
, x
[i
+15], 16, 530742520);
4049 b
= md5_hh(b
, c
, d
, a
, x
[i
+ 2], 23, -995338651);
4051 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 0], 6 , -198630844);
4052 d
= md5_ii(d
, a
, b
, c
, x
[i
+ 7], 10, 1126891415);
4053 c
= md5_ii(c
, d
, a
, b
, x
[i
+14], 15, -1416354905);
4054 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 5], 21, -57434055);
4055 a
= md5_ii(a
, b
, c
, d
, x
[i
+12], 6 , 1700485571);
4056 d
= md5_ii(d
, a
, b
, c
, x
[i
+ 3], 10, -1894986606);
4057 c
= md5_ii(c
, d
, a
, b
, x
[i
+10], 15, -1051523);
4058 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 1], 21, -2054922799);
4059 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 8], 6 , 1873313359);
4060 d
= md5_ii(d
, a
, b
, c
, x
[i
+15], 10, -30611744);
4061 c
= md5_ii(c
, d
, a
, b
, x
[i
+ 6], 15, -1560198380);
4062 b
= md5_ii(b
, c
, d
, a
, x
[i
+13], 21, 1309151649);
4063 a
= md5_ii(a
, b
, c
, d
, x
[i
+ 4], 6 , -145523070);
4064 d
= md5_ii(d
, a
, b
, c
, x
[i
+11], 10, -1120210379);
4065 c
= md5_ii(c
, d
, a
, b
, x
[i
+ 2], 15, 718787259);
4066 b
= md5_ii(b
, c
, d
, a
, x
[i
+ 9], 21, -343485551);
4068 a
= safe_add(a
, olda
);
4069 b
= safe_add(b
, oldb
);
4070 c
= safe_add(c
, oldc
);
4071 d
= safe_add(d
, oldd
);
4073 return Array(a
, b
, c
, d
);
4078 * These functions implement the four basic operations the algorithm uses.
4080 function md5_cmn(q
, a
, b
, x
, s
, t
)
4082 return safe_add(bit_rol(safe_add(safe_add(a
, q
), safe_add(x
, t
)), s
),b
);
4084 function md5_ff(a
, b
, c
, d
, x
, s
, t
)
4086 return md5_cmn((b
& c
) | ((~b
) & d
), a
, b
, x
, s
, t
);
4088 function md5_gg(a
, b
, c
, d
, x
, s
, t
)
4090 return md5_cmn((b
& d
) | (c
& (~d
)), a
, b
, x
, s
, t
);
4092 function md5_hh(a
, b
, c
, d
, x
, s
, t
)
4094 return md5_cmn(b
^ c
^ d
, a
, b
, x
, s
, t
);
4096 function md5_ii(a
, b
, c
, d
, x
, s
, t
)
4098 return md5_cmn(c
^ (b
| (~d
)), a
, b
, x
, s
, t
);
4102 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
4103 * to work around bugs in some JS interpreters.
4105 function safe_add(x
, y
)
4107 var lsw
= (x
& 0xFFFF) + (y
& 0xFFFF);
4108 var msw
= (x
>> 16) + (y
>> 16) + (lsw
>> 16);
4109 return (msw
<< 16) | (lsw
& 0xFFFF);
4113 * Bitwise rotate a 32-bit number to the left.
4115 function bit_rol(num
, cnt
)
4117 return (num
<< cnt
) | (num
>>> (32 - cnt
));
4120 module
.exports
= function md5(buf
) {
4121 return helpers
.hash(buf
, core_md5
, 16);
4124 },{"./helpers":18}],21:[function(_dereq_
,module
,exports
){
4127 module
.exports
= ripemd160
4133 code.google.com/p/crypto-js
4134 (c) 2009-2013 by Jeff Mott. All rights reserved.
4135 code.google.com/p/crypto-js/wiki/License
4138 (c) 2012 by Cédric Mesnil. All rights reserved.
4140 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4142 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
4143 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
4145 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
4150 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
4151 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
4152 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
4153 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
4154 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13];
4156 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
4157 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
4158 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
4159 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
4160 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11];
4162 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
4163 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
4164 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
4165 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
4166 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ];
4168 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
4169 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
4170 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
4171 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
4172 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ];
4174 var hl
= [ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E];
4175 var hr
= [ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000];
4177 var bytesToWords = function (bytes
) {
4179 for (var i
= 0, b
= 0; i
< bytes
.length
; i
++, b
+= 8) {
4180 words
[b
>>> 5] |= bytes
[i
] << (24 - b
% 32);
4185 var wordsToBytes = function (words
) {
4187 for (var b
= 0; b
< words
.length
* 32; b
+= 8) {
4188 bytes
.push((words
[b
>>> 5] >>> (24 - b
% 32)) & 0xFF);
4193 var processBlock = function (H
, M
, offset
) {
4196 for (var i
= 0; i
< 16; i
++) {
4197 var offset_i
= offset
+ i
;
4198 var M_offset_i
= M
[offset_i
];
4202 (((M_offset_i
<< 8) | (M_offset_i
>>> 24)) & 0x00ff00ff) |
4203 (((M_offset_i
<< 24) | (M_offset_i
>>> 8)) & 0xff00ff00)
4207 // Working variables
4208 var al
, bl
, cl
, dl
, el
;
4209 var ar
, br
, cr
, dr
, er
;
4218 for (var i
= 0; i
< 80; i
+= 1) {
4219 t
= (al
+ M
[offset
+zl
[i
]])|0;
4221 t
+= f1(bl
,cl
,dl
) + hl
[0];
4223 t
+= f2(bl
,cl
,dl
) + hl
[1];
4225 t
+= f3(bl
,cl
,dl
) + hl
[2];
4227 t
+= f4(bl
,cl
,dl
) + hl
[3];
4228 } else {// if (i<80) {
4229 t
+= f5(bl
,cl
,dl
) + hl
[4];
4240 t
= (ar
+ M
[offset
+zr
[i
]])|0;
4242 t
+= f5(br
,cr
,dr
) + hr
[0];
4244 t
+= f4(br
,cr
,dr
) + hr
[1];
4246 t
+= f3(br
,cr
,dr
) + hr
[2];
4248 t
+= f2(br
,cr
,dr
) + hr
[3];
4249 } else {// if (i<80) {
4250 t
+= f1(br
,cr
,dr
) + hr
[4];
4261 // Intermediate hash value
4262 t
= (H
[1] + cl
+ dr
)|0;
4263 H
[1] = (H
[2] + dl
+ er
)|0;
4264 H
[2] = (H
[3] + el
+ ar
)|0;
4265 H
[3] = (H
[4] + al
+ br
)|0;
4266 H
[4] = (H
[0] + bl
+ cr
)|0;
4270 function f1(x
, y
, z
) {
4271 return ((x
) ^ (y
) ^ (z
));
4274 function f2(x
, y
, z
) {
4275 return (((x
)&(y
)) | ((~x
)&(z
)));
4278 function f3(x
, y
, z
) {
4279 return (((x
) | (~(y
))) ^ (z
));
4282 function f4(x
, y
, z
) {
4283 return (((x
) & (z
)) | ((y
)&(~(z
))));
4286 function f5(x
, y
, z
) {
4287 return ((x
) ^ ((y
) |(~(z
))));
4290 function rotl(x
,n
) {
4291 return (x
<<n
) | (x
>>>(32-n
));
4294 function ripemd160(message
) {
4295 var H
= [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0];
4297 if (typeof message
== 'string')
4298 message
= new Buffer(message
, 'utf8');
4300 var m
= bytesToWords(message
);
4302 var nBitsLeft
= message
.length
* 8;
4303 var nBitsTotal
= message
.length
* 8;
4306 m
[nBitsLeft
>>> 5] |= 0x80 << (24 - nBitsLeft
% 32);
4307 m
[(((nBitsLeft
+ 64) >>> 9) << 4) + 14] = (
4308 (((nBitsTotal
<< 8) | (nBitsTotal
>>> 24)) & 0x00ff00ff) |
4309 (((nBitsTotal
<< 24) | (nBitsTotal
>>> 8)) & 0xff00ff00)
4312 for (var i
=0 ; i
<m
.length
; i
+= 16) {
4313 processBlock(H
, m
, i
);
4317 for (var i
= 0; i
< 5; i
++) {
4322 H
[i
] = (((H_i
<< 8) | (H_i
>>> 24)) & 0x00ff00ff) |
4323 (((H_i
<< 24) | (H_i
>>> 8)) & 0xff00ff00);
4326 var digestbytes
= wordsToBytes(H
);
4327 return new Buffer(digestbytes
);
4332 }).call(this,_dereq_("buffer").Buffer
)
4333 },{"buffer":8}],22:[function(_dereq_
,module
,exports
){
4334 var u
= _dereq_('./util')
4336 var fill
= u
.zeroFill
4338 module
.exports = function (Buffer
) {
4340 //prototype class for hash functions
4341 function Hash (blockSize
, finalSize
) {
4342 this._block
= new Buffer(blockSize
) //new Uint32Array(blockSize/4)
4343 this._finalSize
= finalSize
4344 this._blockSize
= blockSize
4349 Hash
.prototype.init = function () {
4354 function lengthOf(data
, enc
) {
4355 if(enc
== null) return data
.byteLength
|| data
.length
4356 if(enc
== 'ascii' || enc
== 'binary') return data
.length
4357 if(enc
== 'hex') return data
.length
/2
4358 if(enc
== 'base64') return data
.length
/3
4361 Hash
.prototype.update = function (data
, enc
) {
4362 var bl
= this._blockSize
4364 //I'd rather do this with a streaming encoder, like the opposite of
4365 //http://nodejs.org/api/string_decoder.html
4367 if(!enc
&& 'string' === typeof data
)
4374 if(enc
=== 'base64' || enc
=== 'utf8')
4375 data
= new Buffer(data
, enc
), enc
= null
4377 length
= lengthOf(data
, enc
)
4379 length
= data
.byteLength
|| data
.length
4381 var l
= this._len
+= length
4382 var s
= this._s
= (this._s
|| 0)
4384 var buffer
= this._block
4386 var t
= Math
.min(length
, f
+ bl
)
4387 write(buffer
, data
, enc
, s
%bl
, f
, t
)
4392 this._update(buffer
)
4400 Hash
.prototype.digest = function (enc
) {
4401 var bl
= this._blockSize
4402 var fl
= this._finalSize
4403 var len
= this._len
*8
4407 var bits
= len
% (bl
*8)
4409 //add end marker, so that appending 0's creats a different hash.
4410 x
[this._len
% bl
] = 0x80
4411 fill(this._block
, this._len
% bl
+ 1)
4414 this._update(this._block
)
4415 u
.zeroFill(this._block
, 0)
4418 //TODO: handle case where the bit length is > Math.pow(2, 29)
4419 x
.writeInt32BE(len
, fl
+ 4) //big endian
4421 var hash
= this._update(this._block
) || this._hash()
4422 if(enc
== null) return hash
4423 return hash
.toString(enc
)
4426 Hash
.prototype._update = function () {
4427 throw new Error('_update must be implemented by subclass')
4433 },{"./util":26}],23:[function(_dereq_
,module
,exports
){
4434 var exports
= module
.exports = function (alg
) {
4435 var Alg
= exports
[alg
]
4436 if(!Alg
) throw new Error(alg
+ ' is not supported (we accept pull requests)')
4440 var Buffer
= _dereq_('buffer').Buffer
4441 var Hash
= _dereq_('./hash')(Buffer
)
4444 exports
.sha1
= _dereq_('./sha1')(Buffer
, Hash
)
4445 exports
.sha256
= _dereq_('./sha256')(Buffer
, Hash
)
4447 },{"./hash":22,"./sha1":24,"./sha256":25,"buffer":8}],24:[function(_dereq_
,module
,exports
){
4449 * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined
4451 * Version 2.1a Copyright Paul Johnston 2000 - 2002.
4452 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
4453 * Distributed under the BSD License
4454 * See http://pajhome.org.uk/crypt/md5 for details.
4456 module
.exports = function (Buffer
, Hash
) {
4458 var inherits
= _dereq_('util').inherits
4460 inherits(Sha1
, Hash
)
4471 var W
= new Int32Array(80)
4477 return POOL
.pop().init()
4479 if(!(this instanceof Sha1
)) return new Sha1()
4481 Hash
.call(this, 16*4, 14*4)
4487 Sha1
.prototype.init = function () {
4488 this._a
= 0x67452301
4489 this._b
= 0xefcdab89
4490 this._c
= 0x98badcfe
4491 this._d
= 0x10325476
4492 this._e
= 0xc3d2e1f0
4494 Hash
.prototype.init
.call(this)
4498 Sha1
.prototype._POOL
= POOL
4500 // assume that array is a Uint32Array with length=16,
4501 // and that if it is the last block, it already has the length and the 1 bit appended.
4504 var isDV
= new Buffer(1) instanceof DataView
4505 function readInt32BE (X
, i
) {
4507 ? X
.getInt32(i
, false)
4511 Sha1
.prototype._update = function (array
) {
4515 var a
, b
, c
, d
, e
, _a
, _b
, _c
, _d
, _e
4525 for(var j
= 0; j
< 80; j
++) {
4528 //? X.getInt32(j*4, false)
4529 //? readInt32BE(X, j*4) //*/ X.readInt32BE(j*4) //*/
4530 ? X
.readInt32BE(j
*4)
4531 : rol(w
[j
- 3] ^ w
[j
- 8] ^ w
[j
- 14] ^ w
[j
- 16], 1)
4535 add(rol(a
, 5), sha1_ft(j
, b
, c
, d
)),
4536 add(add(e
, W
), sha1_kt(j
))
4546 this._a
= add(a
, _a
)
4547 this._b
= add(b
, _b
)
4548 this._c
= add(c
, _c
)
4549 this._d
= add(d
, _d
)
4550 this._e
= add(e
, _e
)
4553 Sha1
.prototype._hash = function () {
4554 if(POOL
.length
< 100) POOL
.push(this)
4555 var H
= new Buffer(20)
4556 //console.log(this._a|0, this._b|0, this._c|0, this._d|0, this._e|0)
4557 H
.writeInt32BE(this._a
|0, A
)
4558 H
.writeInt32BE(this._b
|0, B
)
4559 H
.writeInt32BE(this._c
|0, C
)
4560 H
.writeInt32BE(this._d
|0, D
)
4561 H
.writeInt32BE(this._e
|0, E
)
4566 * Perform the appropriate triplet combination function for the current
4569 function sha1_ft(t
, b
, c
, d
) {
4570 if(t
< 20) return (b
& c
) | ((~b
) & d
);
4571 if(t
< 40) return b
^ c
^ d
;
4572 if(t
< 60) return (b
& c
) | (b
& d
) | (c
& d
);
4577 * Determine the appropriate additive constant for the current iteration
4579 function sha1_kt(t
) {
4580 return (t
< 20) ? 1518500249 : (t
< 40) ? 1859775393 :
4581 (t
< 60) ? -1894007588 : -899497514;
4585 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
4586 * to work around bugs in some JS interpreters.
4587 * //dominictarr: this is 10 years old, so maybe this can be dropped?)
4590 function add(x
, y
) {
4592 //lets see how this goes on testling.
4593 // var lsw = (x & 0xFFFF) + (y & 0xFFFF);
4594 // var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
4595 // return (msw << 16) | (lsw & 0xFFFF);
4599 * Bitwise rotate a 32-bit number to the left.
4601 function rol(num
, cnt
) {
4602 return (num
<< cnt
) | (num
>>> (32 - cnt
));
4608 },{"util":14}],25:[function(_dereq_
,module
,exports
){
4611 * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined
4613 * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009.
4614 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
4618 var inherits
= _dereq_('util').inherits
4621 var u
= _dereq_('./util')
4623 module
.exports = function (Buffer
, Hash
) {
4626 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
4627 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
4628 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
4629 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
4630 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
4631 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
4632 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
4633 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
4634 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
4635 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
4636 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
4637 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
4638 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
4639 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
4640 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
4641 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
4644 inherits(Sha256
, Hash
)
4645 var W
= new Array(64)
4648 // Closure compiler warning - this code lacks side effects - thus commented out
4649 // if(POOL.length) {
4650 // return POOL.shift().init()
4652 //this._data = new Buffer(32)
4656 this._w
= W
//new Array(64)
4658 Hash
.call(this, 16*4, 14*4)
4661 Sha256
.prototype.init = function () {
4663 this._a
= 0x6a09e667|0
4664 this._b
= 0xbb67ae85|0
4665 this._c
= 0x3c6ef372|0
4666 this._d
= 0xa54ff53a|0
4667 this._e
= 0x510e527f|0
4668 this._f
= 0x9b05688c|0
4669 this._g
= 0x1f83d9ab|0
4670 this._h
= 0x5be0cd19|0
4672 this._len
= this._s
= 0
4677 var safe_add = function(x
, y
) {
4678 var lsw
= (x
& 0xFFFF) + (y
& 0xFFFF);
4679 var msw
= (x
>> 16) + (y
>> 16) + (lsw
>> 16);
4680 return (msw
<< 16) | (lsw
& 0xFFFF);
4684 return (X
>>> n
) | (X
<< (32 - n
));
4691 function Ch (x
, y
, z
) {
4692 return ((x
& y
) ^ ((~x
) & z
));
4695 function Maj (x
, y
, z
) {
4696 return ((x
& y
) ^ (x
& z
) ^ (y
& z
));
4699 function Sigma0256 (x
) {
4700 return (S(x
, 2) ^ S(x
, 13) ^ S(x
, 22));
4703 function Sigma1256 (x
) {
4704 return (S(x
, 6) ^ S(x
, 11) ^ S(x
, 25));
4707 function Gamma0256 (x
) {
4708 return (S(x
, 7) ^ S(x
, 18) ^ R(x
, 3));
4711 function Gamma1256 (x
) {
4712 return (S(x
, 17) ^ S(x
, 19) ^ R(x
, 10));
4715 Sha256
.prototype._update = function(m
) {
4718 var a
, b
, c
, d
, e
, f
, g
, h
4730 for (var j
= 0; j
< 64; j
++) {
4731 var w
= W
[j
] = j
< 16
4732 ? M
.readInt32BE(j
* 4)
4733 : Gamma1256(W
[j
- 2]) + W
[j
- 7] + Gamma0256(W
[j
- 15]) + W
[j
- 16]
4735 T1
= h
+ Sigma1256(e
) + Ch(e
, f
, g
) + K
[j
] + w
4737 T2
= Sigma0256(a
) + Maj(a
, b
, c
);
4738 h
= g
; g
= f
; f
= e
; e
= d
+ T1
; d
= c
; c
= b
; b
= a
; a
= T1
+ T2
;
4741 this._a
= (a
+ this._a
) | 0
4742 this._b
= (b
+ this._b
) | 0
4743 this._c
= (c
+ this._c
) | 0
4744 this._d
= (d
+ this._d
) | 0
4745 this._e
= (e
+ this._e
) | 0
4746 this._f
= (f
+ this._f
) | 0
4747 this._g
= (g
+ this._g
) | 0
4748 this._h
= (h
+ this._h
) | 0
4752 Sha256
.prototype._hash = function () {
4753 if(POOL
.length
< 10)
4756 var H
= new Buffer(32)
4758 H
.writeInt32BE(this._a
, 0)
4759 H
.writeInt32BE(this._b
, 4)
4760 H
.writeInt32BE(this._c
, 8)
4761 H
.writeInt32BE(this._d
, 12)
4762 H
.writeInt32BE(this._e
, 16)
4763 H
.writeInt32BE(this._f
, 20)
4764 H
.writeInt32BE(this._g
, 24)
4765 H
.writeInt32BE(this._h
, 28)
4774 },{"./util":26,"util":14}],26:[function(_dereq_
,module
,exports
){
4775 exports
.write
= write
4776 exports
.zeroFill
= zeroFill
4778 exports
.toString
= toString
4780 function write (buffer
, string
, enc
, start
, from, to
, LE
) {
4782 if(enc
=== 'ascii' || enc
=== 'binary') {
4783 for( var i
= 0; i
< l
; i
++) {
4784 buffer
[start
+ i
] = string
.charCodeAt(i
+ from)
4787 else if(enc
== null) {
4788 for( var i
= 0; i
< l
; i
++) {
4789 buffer
[start
+ i
] = string
[i
+ from]
4792 else if(enc
=== 'hex') {
4793 for(var i
= 0; i
< l
; i
++) {
4795 buffer
[start
+ i
] = parseInt(string
[j
*2] + string
[(j
*2)+1], 16)
4798 else if(enc
=== 'base64') {
4799 throw new Error('base64 encoding not yet supported')
4802 throw new Error(enc
+' encoding not yet supported')
4805 //always fill to the end!
4806 function zeroFill(buf
, from) {
4807 for(var i
= from; i
< buf
.length
; i
++)
4812 },{}],27:[function(_dereq_
,module
,exports
){
4814 // JavaScript PBKDF2 Implementation
4815 // Based on http://git.io/qsv2zw
4816 // Licensed under LGPL v3
4817 // Copyright (c) 2013 jduncanator
4820 var zeroBuffer
= new Buffer(blocksize
); zeroBuffer
.fill(0)
4822 module
.exports = function (createHmac
, exports
) {
4823 exports
= exports
|| {}
4825 exports
.pbkdf2 = function(password
, salt
, iterations
, keylen
, cb
) {
4826 if('function' !== typeof cb
)
4827 throw new Error('No callback provided to pbkdf2');
4828 setTimeout(function () {
4829 cb(null, exports
.pbkdf2Sync(password
, salt
, iterations
, keylen
))
4833 exports
.pbkdf2Sync = function(key
, salt
, iterations
, keylen
) {
4834 if('number' !== typeof iterations
)
4835 throw new TypeError('Iterations not a number')
4837 throw new TypeError('Bad iterations')
4838 if('number' !== typeof keylen
)
4839 throw new TypeError('Key length not a number')
4841 throw new TypeError('Bad key length')
4843 //stretch key to the correct length that hmac wants it,
4844 //otherwise this will happen every time hmac is called
4845 //twice per iteration.
4846 var key
= !Buffer
.isBuffer(key
) ? new Buffer(key
) : key
4848 if(key
.length
> blocksize
) {
4849 key
= createHash(alg
).update(key
).digest()
4850 } else if(key
.length
< blocksize
) {
4851 key
= Buffer
.concat([key
, zeroBuffer
], blocksize
)
4855 var cplen
, p
= 0, i
= 1, itmp
= new Buffer(4), digtmp
;
4856 var out
= new Buffer(keylen
);
4864 /* We are unlikely to ever use more than 256 blocks (5120 bits!)
4865 * but just in case...
4867 itmp
[0] = (i
>> 24) & 0xff;
4868 itmp
[1] = (i
>> 16) & 0xff;
4869 itmp
[2] = (i
>> 8) & 0xff;
4872 HMAC
= createHmac('sha1', key
);
4875 digtmp
= HMAC
.digest();
4876 digtmp
.copy(out
, p
, 0, cplen
);
4878 for(var j
= 1; j
< iterations
; j
++) {
4879 HMAC
= createHmac('sha1', key
);
4880 HMAC
.update(digtmp
);
4881 digtmp
= HMAC
.digest();
4882 for(var k
= 0; k
< cplen
; k
++) {
4883 out
[k
] ^= digtmp
[k
];
4897 }).call(this,_dereq_("buffer").Buffer
)
4898 },{"buffer":8}],28:[function(_dereq_
,module
,exports
){
4900 // Original code adapted from Robert Kieffer.
4901 // details at https://github.com/broofa/node-uuid
4907 var mathRNG
, whatwgRNG
;
4909 // NOTE: Math.random() does not guarantee "cryptographic quality"
4910 mathRNG = function(size
) {
4911 var bytes
= new Buffer(size
);
4914 for (var i
= 0, r
; i
< size
; i
++) {
4915 if ((i
& 0x03) == 0) r
= Math
.random() * 0x100000000;
4916 bytes
[i
] = r
>>> ((i
& 0x03) << 3) & 0xff;
4922 if (_global
.crypto
&& crypto
.getRandomValues
) {
4923 whatwgRNG = function(size
) {
4924 var bytes
= new Buffer(size
); //in browserify, this is an extended Uint8Array
4925 crypto
.getRandomValues(bytes
);
4930 module
.exports
= whatwgRNG
|| mathRNG
;
4934 }).call(this,_dereq_("buffer").Buffer
)
4935 },{"buffer":8}],29:[function(_dereq_
,module
,exports
){
4936 ;(function (root
, factory
, undef
) {
4937 if (typeof exports
=== "object") {
4939 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./enc-base64"), _dereq_("./md5"), _dereq_("./evpkdf"), _dereq_("./cipher-core"));
4941 else if (typeof define
=== "function" && define
.amd
) {
4943 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory
);
4947 factory(root
.CryptoJS
);
4949 }(this, function (CryptoJS
) {
4955 var BlockCipher
= C_lib
.BlockCipher
;
4956 var C_algo
= C
.algo
;
4965 var INV_SUB_MIX_0
= [];
4966 var INV_SUB_MIX_1
= [];
4967 var INV_SUB_MIX_2
= [];
4968 var INV_SUB_MIX_3
= [];
4970 // Compute lookup tables
4972 // Compute double table
4974 for (var i
= 0; i
< 256; i
++) {
4978 d
[i
] = (i
<< 1) ^ 0x11b;
4985 for (var i
= 0; i
< 256; i
++) {
4987 var sx
= xi
^ (xi
<< 1) ^ (xi
<< 2) ^ (xi
<< 3) ^ (xi
<< 4);
4988 sx
= (sx
>>> 8) ^ (sx
& 0xff) ^ 0x63;
4992 // Compute multiplication
4997 // Compute sub bytes, mix columns tables
4998 var t
= (d
[sx
] * 0x101) ^ (sx
* 0x1010100);
4999 SUB_MIX_0
[x
] = (t
<< 24) | (t
>>> 8);
5000 SUB_MIX_1
[x
] = (t
<< 16) | (t
>>> 16);
5001 SUB_MIX_2
[x
] = (t
<< 8) | (t
>>> 24);
5004 // Compute inv sub bytes, inv mix columns tables
5005 var t
= (x8
* 0x1010101) ^ (x4
* 0x10001) ^ (x2
* 0x101) ^ (x
* 0x1010100);
5006 INV_SUB_MIX_0
[sx
] = (t
<< 24) | (t
>>> 8);
5007 INV_SUB_MIX_1
[sx
] = (t
<< 16) | (t
>>> 16);
5008 INV_SUB_MIX_2
[sx
] = (t
<< 8) | (t
>>> 24);
5009 INV_SUB_MIX_3
[sx
] = t
;
5011 // Compute next counter
5015 x
= x2
^ d
[d
[d
[x8
^ x2
]]];
5021 // Precomputed Rcon lookup
5022 var RCON
= [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36];
5025 * AES block cipher algorithm.
5027 var AES
= C_algo
.AES
= BlockCipher
.extend({
5028 _doReset: function () {
5030 var key
= this._key
;
5031 var keyWords
= key
.words
;
5032 var keySize
= key
.sigBytes
/ 4;
5034 // Compute number of rounds
5035 var nRounds
= this._nRounds
= keySize
+ 6
5037 // Compute number of key schedule rows
5038 var ksRows
= (nRounds
+ 1) * 4;
5040 // Compute key schedule
5041 var keySchedule
= this._keySchedule
= [];
5042 for (var ksRow
= 0; ksRow
< ksRows
; ksRow
++) {
5043 if (ksRow
< keySize
) {
5044 keySchedule
[ksRow
] = keyWords
[ksRow
];
5046 var t
= keySchedule
[ksRow
- 1];
5048 if (!(ksRow
% keySize
)) {
5050 t
= (t
<< 8) | (t
>>> 24);
5053 t
= (SBOX
[t
>>> 24] << 24) | (SBOX
[(t
>>> 16) & 0xff] << 16) | (SBOX
[(t
>>> 8) & 0xff] << 8) | SBOX
[t
& 0xff];
5056 t
^= RCON
[(ksRow
/ keySize
) | 0] << 24;
5057 } else if (keySize
> 6 && ksRow
% keySize
== 4) {
5059 t
= (SBOX
[t
>>> 24] << 24) | (SBOX
[(t
>>> 16) & 0xff] << 16) | (SBOX
[(t
>>> 8) & 0xff] << 8) | SBOX
[t
& 0xff];
5062 keySchedule
[ksRow
] = keySchedule
[ksRow
- keySize
] ^ t
;
5066 // Compute inv key schedule
5067 var invKeySchedule
= this._invKeySchedule
= [];
5068 for (var invKsRow
= 0; invKsRow
< ksRows
; invKsRow
++) {
5069 var ksRow
= ksRows
- invKsRow
;
5072 var t
= keySchedule
[ksRow
];
5074 var t
= keySchedule
[ksRow
- 4];
5077 if (invKsRow
< 4 || ksRow
<= 4) {
5078 invKeySchedule
[invKsRow
] = t
;
5080 invKeySchedule
[invKsRow
] = INV_SUB_MIX_0
[SBOX
[t
>>> 24]] ^ INV_SUB_MIX_1
[SBOX
[(t
>>> 16) & 0xff]] ^
5081 INV_SUB_MIX_2
[SBOX
[(t
>>> 8) & 0xff]] ^ INV_SUB_MIX_3
[SBOX
[t
& 0xff]];
5086 encryptBlock: function (M
, offset
) {
5087 this._doCryptBlock(M
, offset
, this._keySchedule
, SUB_MIX_0
, SUB_MIX_1
, SUB_MIX_2
, SUB_MIX_3
, SBOX
);
5090 decryptBlock: function (M
, offset
) {
5091 // Swap 2nd and 4th rows
5092 var t
= M
[offset
+ 1];
5093 M
[offset
+ 1] = M
[offset
+ 3];
5096 this._doCryptBlock(M
, offset
, this._invKeySchedule
, INV_SUB_MIX_0
, INV_SUB_MIX_1
, INV_SUB_MIX_2
, INV_SUB_MIX_3
, INV_SBOX
);
5098 // Inv swap 2nd and 4th rows
5099 var t
= M
[offset
+ 1];
5100 M
[offset
+ 1] = M
[offset
+ 3];
5104 _doCryptBlock: function (M
, offset
, keySchedule
, SUB_MIX_0
, SUB_MIX_1
, SUB_MIX_2
, SUB_MIX_3
, SBOX
) {
5106 var nRounds
= this._nRounds
;
5108 // Get input, add round key
5109 var s0
= M
[offset
] ^ keySchedule
[0];
5110 var s1
= M
[offset
+ 1] ^ keySchedule
[1];
5111 var s2
= M
[offset
+ 2] ^ keySchedule
[2];
5112 var s3
= M
[offset
+ 3] ^ keySchedule
[3];
5114 // Key schedule row counter
5118 for (var round
= 1; round
< nRounds
; round
++) {
5119 // Shift rows, sub bytes, mix columns, add round key
5120 var t0
= SUB_MIX_0
[s0
>>> 24] ^ SUB_MIX_1
[(s1
>>> 16) & 0xff] ^ SUB_MIX_2
[(s2
>>> 8) & 0xff] ^ SUB_MIX_3
[s3
& 0xff] ^ keySchedule
[ksRow
++];
5121 var t1
= SUB_MIX_0
[s1
>>> 24] ^ SUB_MIX_1
[(s2
>>> 16) & 0xff] ^ SUB_MIX_2
[(s3
>>> 8) & 0xff] ^ SUB_MIX_3
[s0
& 0xff] ^ keySchedule
[ksRow
++];
5122 var t2
= SUB_MIX_0
[s2
>>> 24] ^ SUB_MIX_1
[(s3
>>> 16) & 0xff] ^ SUB_MIX_2
[(s0
>>> 8) & 0xff] ^ SUB_MIX_3
[s1
& 0xff] ^ keySchedule
[ksRow
++];
5123 var t3
= SUB_MIX_0
[s3
>>> 24] ^ SUB_MIX_1
[(s0
>>> 16) & 0xff] ^ SUB_MIX_2
[(s1
>>> 8) & 0xff] ^ SUB_MIX_3
[s2
& 0xff] ^ keySchedule
[ksRow
++];
5132 // Shift rows, sub bytes, add round key
5133 var t0
= ((SBOX
[s0
>>> 24] << 24) | (SBOX
[(s1
>>> 16) & 0xff] << 16) | (SBOX
[(s2
>>> 8) & 0xff] << 8) | SBOX
[s3
& 0xff]) ^ keySchedule
[ksRow
++];
5134 var t1
= ((SBOX
[s1
>>> 24] << 24) | (SBOX
[(s2
>>> 16) & 0xff] << 16) | (SBOX
[(s3
>>> 8) & 0xff] << 8) | SBOX
[s0
& 0xff]) ^ keySchedule
[ksRow
++];
5135 var t2
= ((SBOX
[s2
>>> 24] << 24) | (SBOX
[(s3
>>> 16) & 0xff] << 16) | (SBOX
[(s0
>>> 8) & 0xff] << 8) | SBOX
[s1
& 0xff]) ^ keySchedule
[ksRow
++];
5136 var t3
= ((SBOX
[s3
>>> 24] << 24) | (SBOX
[(s0
>>> 16) & 0xff] << 16) | (SBOX
[(s1
>>> 8) & 0xff] << 8) | SBOX
[s2
& 0xff]) ^ keySchedule
[ksRow
++];
5149 * Shortcut functions to the cipher's object interface.
5153 * var ciphertext = CryptoJS.AES.encrypt(message, key, cfg);
5154 * var plaintext = CryptoJS.AES.decrypt(ciphertext, key, cfg);
5156 C
.AES
= BlockCipher
._createHelper(AES
);
5160 return CryptoJS
.AES
;
5163 },{"./cipher-core":30,"./core":31,"./enc-base64":32,"./evpkdf":34,"./md5":39}],30:[function(_dereq_
,module
,exports
){
5164 ;(function (root
, factory
) {
5165 if (typeof exports
=== "object") {
5167 module
.exports
= exports
= factory(_dereq_("./core"));
5169 else if (typeof define
=== "function" && define
.amd
) {
5171 define(["./core"], factory
);
5175 factory(root
.CryptoJS
);
5177 }(this, function (CryptoJS
) {
5180 * Cipher core components.
5182 CryptoJS
.lib
.Cipher
|| (function (undefined) {
5186 var Base
= C_lib
.Base
;
5187 var WordArray
= C_lib
.WordArray
;
5188 var BufferedBlockAlgorithm
= C_lib
.BufferedBlockAlgorithm
;
5190 var Utf8
= C_enc
.Utf8
;
5191 var Base64
= C_enc
.Base64
;
5192 var C_algo
= C
.algo
;
5193 var EvpKDF
= C_algo
.EvpKDF
;
5196 * Abstract base cipher template.
5198 * @property {number} keySize This cipher's key size. Default: 4 (128 bits)
5199 * @property {number} ivSize This cipher's IV size. Default: 4 (128 bits)
5200 * @property {number} _ENC_XFORM_MODE A constant representing encryption mode.
5201 * @property {number} _DEC_XFORM_MODE A constant representing decryption mode.
5203 var Cipher
= C_lib
.Cipher
= BufferedBlockAlgorithm
.extend({
5205 * Configuration options.
5207 * @property {WordArray} iv The IV to use for this operation.
5212 * Creates this cipher in encryption mode.
5214 * @param {WordArray} key The key.
5215 * @param {Object} cfg (Optional) The configuration options to use for this operation.
5217 * @return {Cipher} A cipher instance.
5223 * var cipher = CryptoJS.algo.AES.createEncryptor(keyWordArray, { iv: ivWordArray });
5225 createEncryptor: function (key
, cfg
) {
5226 return this.create(this._ENC_XFORM_MODE
, key
, cfg
);
5230 * Creates this cipher in decryption mode.
5232 * @param {WordArray} key The key.
5233 * @param {Object} cfg (Optional) The configuration options to use for this operation.
5235 * @return {Cipher} A cipher instance.
5241 * var cipher = CryptoJS.algo.AES.createDecryptor(keyWordArray, { iv: ivWordArray });
5243 createDecryptor: function (key
, cfg
) {
5244 return this.create(this._DEC_XFORM_MODE
, key
, cfg
);
5248 * Initializes a newly created cipher.
5250 * @param {number} xformMode Either the encryption or decryption transormation mode constant.
5251 * @param {WordArray} key The key.
5252 * @param {Object} cfg (Optional) The configuration options to use for this operation.
5256 * var cipher = CryptoJS.algo.AES.create(CryptoJS.algo.AES._ENC_XFORM_MODE, keyWordArray, { iv: ivWordArray });
5258 init: function (xformMode
, key
, cfg
) {
5259 // Apply config defaults
5260 this.cfg
= this.cfg
.extend(cfg
);
5262 // Store transform mode and key
5263 this._xformMode
= xformMode
;
5266 // Set initial values
5271 * Resets this cipher to its initial state.
5277 reset: function () {
5278 // Reset data buffer
5279 BufferedBlockAlgorithm
.reset
.call(this);
5281 // Perform concrete-cipher logic
5286 * Adds data to be encrypted or decrypted.
5288 * @param {WordArray|string} dataUpdate The data to encrypt or decrypt.
5290 * @return {WordArray} The data after processing.
5294 * var encrypted = cipher.process('data');
5295 * var encrypted = cipher.process(wordArray);
5297 process: function (dataUpdate
) {
5299 this._append(dataUpdate
);
5301 // Process available blocks
5302 return this._process();
5306 * Finalizes the encryption or decryption process.
5307 * Note that the finalize operation is effectively a destructive, read-once operation.
5309 * @param {WordArray|string} dataUpdate The final data to encrypt or decrypt.
5311 * @return {WordArray} The data after final processing.
5315 * var encrypted = cipher.finalize();
5316 * var encrypted = cipher.finalize('data');
5317 * var encrypted = cipher.finalize(wordArray);
5319 finalize: function (dataUpdate
) {
5320 // Final data update
5322 this._append(dataUpdate
);
5325 // Perform concrete-cipher logic
5326 var finalProcessedData
= this._doFinalize();
5328 return finalProcessedData
;
5340 * Creates shortcut functions to a cipher's object interface.
5342 * @param {Cipher} cipher The cipher to create a helper for.
5344 * @return {Object} An object with encrypt and decrypt shortcut functions.
5350 * var AES = CryptoJS.lib.Cipher._createHelper(CryptoJS.algo.AES);
5352 _createHelper: (function () {
5353 function selectCipherStrategy(key
) {
5354 if (typeof key
== 'string') {
5355 return PasswordBasedCipher
;
5357 return SerializableCipher
;
5361 return function (cipher
) {
5363 encrypt: function (message
, key
, cfg
) {
5364 return selectCipherStrategy(key
).encrypt(cipher
, message
, key
, cfg
);
5367 decrypt: function (ciphertext
, key
, cfg
) {
5368 return selectCipherStrategy(key
).decrypt(cipher
, ciphertext
, key
, cfg
);
5376 * Abstract base stream cipher template.
5378 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 1 (32 bits)
5380 var StreamCipher
= C_lib
.StreamCipher
= Cipher
.extend({
5381 _doFinalize: function () {
5382 // Process partial blocks
5383 var finalProcessedBlocks
= this._process(!!'flush');
5385 return finalProcessedBlocks
;
5394 var C_mode
= C
.mode
= {};
5397 * Abstract base block cipher mode template.
5399 var BlockCipherMode
= C_lib
.BlockCipherMode
= Base
.extend({
5401 * Creates this mode for encryption.
5403 * @param {Cipher} cipher A block cipher instance.
5404 * @param {Array} iv The IV words.
5410 * var mode = CryptoJS.mode.CBC.createEncryptor(cipher, iv.words);
5412 createEncryptor: function (cipher
, iv
) {
5413 return this.Encryptor
.create(cipher
, iv
);
5417 * Creates this mode for decryption.
5419 * @param {Cipher} cipher A block cipher instance.
5420 * @param {Array} iv The IV words.
5426 * var mode = CryptoJS.mode.CBC.createDecryptor(cipher, iv.words);
5428 createDecryptor: function (cipher
, iv
) {
5429 return this.Decryptor
.create(cipher
, iv
);
5433 * Initializes a newly created mode.
5435 * @param {Cipher} cipher A block cipher instance.
5436 * @param {Array} iv The IV words.
5440 * var mode = CryptoJS.mode.CBC.Encryptor.create(cipher, iv.words);
5442 init: function (cipher
, iv
) {
5443 this._cipher
= cipher
;
5449 * Cipher Block Chaining mode.
5451 var CBC
= C_mode
.CBC
= (function () {
5453 * Abstract base CBC mode.
5455 var CBC
= BlockCipherMode
.extend();
5460 CBC
.Encryptor
= CBC
.extend({
5462 * Processes the data block at offset.
5464 * @param {Array} words The data words to operate on.
5465 * @param {number} offset The offset where the block starts.
5469 * mode.processBlock(data.words, offset);
5471 processBlock: function (words
, offset
) {
5473 var cipher
= this._cipher
;
5474 var blockSize
= cipher
.blockSize
;
5477 xorBlock
.call(this, words
, offset
, blockSize
);
5478 cipher
.encryptBlock(words
, offset
);
5480 // Remember this block to use with next block
5481 this._prevBlock
= words
.slice(offset
, offset
+ blockSize
);
5488 CBC
.Decryptor
= CBC
.extend({
5490 * Processes the data block at offset.
5492 * @param {Array} words The data words to operate on.
5493 * @param {number} offset The offset where the block starts.
5497 * mode.processBlock(data.words, offset);
5499 processBlock: function (words
, offset
) {
5501 var cipher
= this._cipher
;
5502 var blockSize
= cipher
.blockSize
;
5504 // Remember this block to use with next block
5505 var thisBlock
= words
.slice(offset
, offset
+ blockSize
);
5508 cipher
.decryptBlock(words
, offset
);
5509 xorBlock
.call(this, words
, offset
, blockSize
);
5511 // This block becomes the previous block
5512 this._prevBlock
= thisBlock
;
5516 function xorBlock(words
, offset
, blockSize
) {
5520 // Choose mixing block
5524 // Remove IV for subsequent blocks
5525 this._iv
= undefined;
5527 var block
= this._prevBlock
;
5531 for (var i
= 0; i
< blockSize
; i
++) {
5532 words
[offset
+ i
] ^= block
[i
];
5540 * Padding namespace.
5542 var C_pad
= C
.pad
= {};
5545 * PKCS #5/7 padding strategy.
5547 var Pkcs7
= C_pad
.Pkcs7
= {
5549 * Pads data using the algorithm defined in PKCS #5/7.
5551 * @param {WordArray} data The data to pad.
5552 * @param {number} blockSize The multiple that the data should be padded to.
5558 * CryptoJS.pad.Pkcs7.pad(wordArray, 4);
5560 pad: function (data
, blockSize
) {
5562 var blockSizeBytes
= blockSize
* 4;
5564 // Count padding bytes
5565 var nPaddingBytes
= blockSizeBytes
- data
.sigBytes
% blockSizeBytes
;
5567 // Create padding word
5568 var paddingWord
= (nPaddingBytes
<< 24) | (nPaddingBytes
<< 16) | (nPaddingBytes
<< 8) | nPaddingBytes
;
5571 var paddingWords
= [];
5572 for (var i
= 0; i
< nPaddingBytes
; i
+= 4) {
5573 paddingWords
.push(paddingWord
);
5575 var padding
= WordArray
.create(paddingWords
, nPaddingBytes
);
5578 data
.concat(padding
);
5582 * Unpads data that had been padded using the algorithm defined in PKCS #5/7.
5584 * @param {WordArray} data The data to unpad.
5590 * CryptoJS.pad.Pkcs7.unpad(wordArray);
5592 unpad: function (data
) {
5593 // Get number of padding bytes from last byte
5594 var nPaddingBytes
= data
.words
[(data
.sigBytes
- 1) >>> 2] & 0xff;
5597 data
.sigBytes
-= nPaddingBytes
;
5602 * Abstract base block cipher template.
5604 * @property {number} blockSize The number of 32-bit words this cipher operates on. Default: 4 (128 bits)
5606 var BlockCipher
= C_lib
.BlockCipher
= Cipher
.extend({
5608 * Configuration options.
5610 * @property {Mode} mode The block mode to use. Default: CBC
5611 * @property {Padding} padding The padding strategy to use. Default: Pkcs7
5613 cfg: Cipher
.cfg
.extend({
5618 reset: function () {
5620 Cipher
.reset
.call(this);
5625 var mode
= cfg
.mode
;
5628 if (this._xformMode
== this._ENC_XFORM_MODE
) {
5629 var modeCreator
= mode
.createEncryptor
;
5630 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
5631 var modeCreator
= mode
.createDecryptor
;
5633 // Keep at least one block in the buffer for unpadding
5634 this._minBufferSize
= 1;
5636 this._mode
= modeCreator
.call(mode
, this, iv
&& iv
.words
);
5639 _doProcessBlock: function (words
, offset
) {
5640 this._mode
.processBlock(words
, offset
);
5643 _doFinalize: function () {
5645 var padding
= this.cfg
.padding
;
5648 if (this._xformMode
== this._ENC_XFORM_MODE
) {
5650 padding
.pad(this._data
, this.blockSize
);
5652 // Process final blocks
5653 var finalProcessedBlocks
= this._process(!!'flush');
5654 } else /* if (this._xformMode == this._DEC_XFORM_MODE) */ {
5655 // Process final blocks
5656 var finalProcessedBlocks
= this._process(!!'flush');
5659 padding
.unpad(finalProcessedBlocks
);
5662 return finalProcessedBlocks
;
5669 * A collection of cipher parameters.
5671 * @property {WordArray} ciphertext The raw ciphertext.
5672 * @property {WordArray} key The key to this ciphertext.
5673 * @property {WordArray} iv The IV used in the ciphering operation.
5674 * @property {WordArray} salt The salt used with a key derivation function.
5675 * @property {Cipher} algorithm The cipher algorithm.
5676 * @property {Mode} mode The block mode used in the ciphering operation.
5677 * @property {Padding} padding The padding scheme used in the ciphering operation.
5678 * @property {number} blockSize The block size of the cipher.
5679 * @property {Format} formatter The default formatting strategy to convert this cipher params object to a string.
5681 var CipherParams
= C_lib
.CipherParams
= Base
.extend({
5683 * Initializes a newly created cipher params object.
5685 * @param {Object} cipherParams An object with any of the possible cipher parameters.
5689 * var cipherParams = CryptoJS.lib.CipherParams.create({
5690 * ciphertext: ciphertextWordArray,
5691 * key: keyWordArray,
5693 * salt: saltWordArray,
5694 * algorithm: CryptoJS.algo.AES,
5695 * mode: CryptoJS.mode.CBC,
5696 * padding: CryptoJS.pad.PKCS7,
5698 * formatter: CryptoJS.format.OpenSSL
5701 init: function (cipherParams
) {
5702 this.mixIn(cipherParams
);
5706 * Converts this cipher params object to a string.
5708 * @param {Format} formatter (Optional) The formatting strategy to use.
5710 * @return {string} The stringified cipher params.
5712 * @throws Error If neither the formatter nor the default formatter is set.
5716 * var string = cipherParams + '';
5717 * var string = cipherParams.toString();
5718 * var string = cipherParams.toString(CryptoJS.format.OpenSSL);
5720 toString: function (formatter
) {
5721 return (formatter
|| this.formatter
).stringify(this);
5728 var C_format
= C
.format
= {};
5731 * OpenSSL formatting strategy.
5733 var OpenSSLFormatter
= C_format
.OpenSSL
= {
5735 * Converts a cipher params object to an OpenSSL-compatible string.
5737 * @param {CipherParams} cipherParams The cipher params object.
5739 * @return {string} The OpenSSL-compatible string.
5745 * var openSSLString = CryptoJS.format.OpenSSL.stringify(cipherParams);
5747 stringify: function (cipherParams
) {
5749 var ciphertext
= cipherParams
.ciphertext
;
5750 var salt
= cipherParams
.salt
;
5754 var wordArray
= WordArray
.create([0x53616c74, 0x65645f5f]).concat(salt
).concat(ciphertext
);
5756 var wordArray
= ciphertext
;
5759 return wordArray
.toString(Base64
);
5763 * Converts an OpenSSL-compatible string to a cipher params object.
5765 * @param {string} openSSLStr The OpenSSL-compatible string.
5767 * @return {CipherParams} The cipher params object.
5773 * var cipherParams = CryptoJS.format.OpenSSL.parse(openSSLString);
5775 parse: function (openSSLStr
) {
5777 var ciphertext
= Base64
.parse(openSSLStr
);
5780 var ciphertextWords
= ciphertext
.words
;
5783 if (ciphertextWords
[0] == 0x53616c74 && ciphertextWords
[1] == 0x65645f5f) {
5785 var salt
= WordArray
.create(ciphertextWords
.slice(2, 4));
5787 // Remove salt from ciphertext
5788 ciphertextWords
.splice(0, 4);
5789 ciphertext
.sigBytes
-= 16;
5792 return CipherParams
.create({ ciphertext: ciphertext
, salt: salt
});
5797 * A cipher wrapper that returns ciphertext as a serializable cipher params object.
5799 var SerializableCipher
= C_lib
.SerializableCipher
= Base
.extend({
5801 * Configuration options.
5803 * @property {Formatter} format The formatting strategy to convert cipher param objects to and from a string. Default: OpenSSL
5806 format: OpenSSLFormatter
5810 * Encrypts a message.
5812 * @param {Cipher} cipher The cipher algorithm to use.
5813 * @param {WordArray|string} message The message to encrypt.
5814 * @param {WordArray} key The key.
5815 * @param {Object} cfg (Optional) The configuration options to use for this operation.
5817 * @return {CipherParams} A cipher params object.
5823 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key);
5824 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv });
5825 * var ciphertextParams = CryptoJS.lib.SerializableCipher.encrypt(CryptoJS.algo.AES, message, key, { iv: iv, format: CryptoJS.format.OpenSSL });
5827 encrypt: function (cipher
, message
, key
, cfg
) {
5828 // Apply config defaults
5829 cfg
= this.cfg
.extend(cfg
);
5832 var encryptor
= cipher
.createEncryptor(key
, cfg
);
5833 var ciphertext
= encryptor
.finalize(message
);
5836 var cipherCfg
= encryptor
.cfg
;
5838 // Create and return serializable cipher params
5839 return CipherParams
.create({
5840 ciphertext: ciphertext
,
5844 mode: cipherCfg
.mode
,
5845 padding: cipherCfg
.padding
,
5846 blockSize: cipher
.blockSize
,
5847 formatter: cfg
.format
5852 * Decrypts serialized ciphertext.
5854 * @param {Cipher} cipher The cipher algorithm to use.
5855 * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
5856 * @param {WordArray} key The key.
5857 * @param {Object} cfg (Optional) The configuration options to use for this operation.
5859 * @return {WordArray} The plaintext.
5865 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, key, { iv: iv, format: CryptoJS.format.OpenSSL });
5866 * var plaintext = CryptoJS.lib.SerializableCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, key, { iv: iv, format: CryptoJS.format.OpenSSL });
5868 decrypt: function (cipher
, ciphertext
, key
, cfg
) {
5869 // Apply config defaults
5870 cfg
= this.cfg
.extend(cfg
);
5872 // Convert string to CipherParams
5873 ciphertext
= this._parse(ciphertext
, cfg
.format
);
5876 var plaintext
= cipher
.createDecryptor(key
, cfg
).finalize(ciphertext
.ciphertext
);
5882 * Converts serialized ciphertext to CipherParams,
5883 * else assumed CipherParams already and returns ciphertext unchanged.
5885 * @param {CipherParams|string} ciphertext The ciphertext.
5886 * @param {Formatter} format The formatting strategy to use to parse serialized ciphertext.
5888 * @return {CipherParams} The unserialized ciphertext.
5894 * var ciphertextParams = CryptoJS.lib.SerializableCipher._parse(ciphertextStringOrParams, format);
5896 _parse: function (ciphertext
, format
) {
5897 if (typeof ciphertext
== 'string') {
5898 return format
.parse(ciphertext
, this);
5906 * Key derivation function namespace.
5908 var C_kdf
= C
.kdf
= {};
5911 * OpenSSL key derivation function.
5913 var OpenSSLKdf
= C_kdf
.OpenSSL
= {
5915 * Derives a key and IV from a password.
5917 * @param {string} password The password to derive from.
5918 * @param {number} keySize The size in words of the key to generate.
5919 * @param {number} ivSize The size in words of the IV to generate.
5920 * @param {WordArray|string} salt (Optional) A 64-bit salt to use. If omitted, a salt will be generated randomly.
5922 * @return {CipherParams} A cipher params object with the key, IV, and salt.
5928 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32);
5929 * var derivedParams = CryptoJS.kdf.OpenSSL.execute('Password', 256/32, 128/32, 'saltsalt');
5931 execute: function (password
, keySize
, ivSize
, salt
) {
5932 // Generate random salt
5934 salt
= WordArray
.random(64/8);
5937 // Derive key and IV
5938 var key
= EvpKDF
.create({ keySize: keySize
+ ivSize
}).compute(password
, salt
);
5940 // Separate key and IV
5941 var iv
= WordArray
.create(key
.words
.slice(keySize
), ivSize
* 4);
5942 key
.sigBytes
= keySize
* 4;
5945 return CipherParams
.create({ key: key
, iv: iv
, salt: salt
});
5950 * A serializable cipher wrapper that derives the key from a password,
5951 * and returns ciphertext as a serializable cipher params object.
5953 var PasswordBasedCipher
= C_lib
.PasswordBasedCipher
= SerializableCipher
.extend({
5955 * Configuration options.
5957 * @property {KDF} kdf The key derivation function to use to generate a key and IV from a password. Default: OpenSSL
5959 cfg: SerializableCipher
.cfg
.extend({
5964 * Encrypts a message using a password.
5966 * @param {Cipher} cipher The cipher algorithm to use.
5967 * @param {WordArray|string} message The message to encrypt.
5968 * @param {string} password The password.
5969 * @param {Object} cfg (Optional) The configuration options to use for this operation.
5971 * @return {CipherParams} A cipher params object.
5977 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password');
5978 * var ciphertextParams = CryptoJS.lib.PasswordBasedCipher.encrypt(CryptoJS.algo.AES, message, 'password', { format: CryptoJS.format.OpenSSL });
5980 encrypt: function (cipher
, message
, password
, cfg
) {
5981 // Apply config defaults
5982 cfg
= this.cfg
.extend(cfg
);
5984 // Derive key and other params
5985 var derivedParams
= cfg
.kdf
.execute(password
, cipher
.keySize
, cipher
.ivSize
);
5988 cfg
.iv
= derivedParams
.iv
;
5991 var ciphertext
= SerializableCipher
.encrypt
.call(this, cipher
, message
, derivedParams
.key
, cfg
);
5993 // Mix in derived params
5994 ciphertext
.mixIn(derivedParams
);
6000 * Decrypts serialized ciphertext using a password.
6002 * @param {Cipher} cipher The cipher algorithm to use.
6003 * @param {CipherParams|string} ciphertext The ciphertext to decrypt.
6004 * @param {string} password The password.
6005 * @param {Object} cfg (Optional) The configuration options to use for this operation.
6007 * @return {WordArray} The plaintext.
6013 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, formattedCiphertext, 'password', { format: CryptoJS.format.OpenSSL });
6014 * var plaintext = CryptoJS.lib.PasswordBasedCipher.decrypt(CryptoJS.algo.AES, ciphertextParams, 'password', { format: CryptoJS.format.OpenSSL });
6016 decrypt: function (cipher
, ciphertext
, password
, cfg
) {
6017 // Apply config defaults
6018 cfg
= this.cfg
.extend(cfg
);
6020 // Convert string to CipherParams
6021 ciphertext
= this._parse(ciphertext
, cfg
.format
);
6023 // Derive key and other params
6024 var derivedParams
= cfg
.kdf
.execute(password
, cipher
.keySize
, cipher
.ivSize
, ciphertext
.salt
);
6027 cfg
.iv
= derivedParams
.iv
;
6030 var plaintext
= SerializableCipher
.decrypt
.call(this, cipher
, ciphertext
, derivedParams
.key
, cfg
);
6039 },{"./core":31}],31:[function(_dereq_
,module
,exports
){
6040 ;(function (root
, factory
) {
6041 if (typeof exports
=== "object") {
6043 module
.exports
= exports
= factory();
6045 else if (typeof define
=== "function" && define
.amd
) {
6047 define([], factory
);
6051 root
.CryptoJS
= factory();
6053 }(this, function () {
6056 * CryptoJS core components.
6058 var CryptoJS
= CryptoJS
|| (function (Math
, undefined) {
6060 * CryptoJS namespace.
6065 * Library namespace.
6067 var C_lib
= C
.lib
= {};
6070 * Base object for prototypal inheritance.
6072 var Base
= C_lib
.Base
= (function () {
6077 * Creates a new object that inherits from this object.
6079 * @param {Object} overrides Properties to copy into the new object.
6081 * @return {Object} The new object.
6087 * var MyType = CryptoJS.lib.Base.extend({
6090 * method: function () {
6094 extend: function (overrides
) {
6097 var subtype
= new F();
6101 subtype
.mixIn(overrides
);
6104 // Create default initializer
6105 if (!subtype
.hasOwnProperty('init')) {
6106 subtype
.init = function () {
6107 subtype
.$super.init
.apply(this, arguments
);
6111 // Initializer's prototype is the subtype object
6112 subtype
.init
.prototype = subtype
;
6114 // Reference supertype
6115 subtype
.$super = this;
6121 * Extends this object and runs the init method.
6122 * Arguments to create() will be passed to init().
6124 * @return {Object} The new object.
6130 * var instance = MyType.create();
6132 create: function () {
6133 var instance
= this.extend();
6134 instance
.init
.apply(instance
, arguments
);
6140 * Initializes a newly created object.
6141 * Override this method to add some logic when your objects are created.
6145 * var MyType = CryptoJS.lib.Base.extend({
6146 * init: function () {
6155 * Copies properties into this object.
6157 * @param {Object} properties The properties to mix in.
6165 mixIn: function (properties
) {
6166 for (var propertyName
in properties
) {
6167 if (properties
.hasOwnProperty(propertyName
)) {
6168 this[propertyName
] = properties
[propertyName
];
6172 // IE won't copy toString using the loop above
6173 if (properties
.hasOwnProperty('toString')) {
6174 this.toString
= properties
.toString
;
6179 * Creates a copy of this object.
6181 * @return {Object} The clone.
6185 * var clone = instance.clone();
6187 clone: function () {
6188 return this.init
.prototype.extend(this);
6194 * An array of 32-bit words.
6196 * @property {Array} words The array of 32-bit words.
6197 * @property {number} sigBytes The number of significant bytes in this word array.
6199 var WordArray
= C_lib
.WordArray
= Base
.extend({
6201 * Initializes a newly created word array.
6203 * @param {Array} words (Optional) An array of 32-bit words.
6204 * @param {number} sigBytes (Optional) The number of significant bytes in the words.
6208 * var wordArray = CryptoJS.lib.WordArray.create();
6209 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607]);
6210 * var wordArray = CryptoJS.lib.WordArray.create([0x00010203, 0x04050607], 6);
6212 init: function (words
, sigBytes
) {
6213 words
= this.words
= words
|| [];
6215 if (sigBytes
!= undefined) {
6216 this.sigBytes
= sigBytes
;
6218 this.sigBytes
= words
.length
* 4;
6223 * Converts this word array to a string.
6225 * @param {Encoder} encoder (Optional) The encoding strategy to use. Default: CryptoJS.enc.Hex
6227 * @return {string} The stringified word array.
6231 * var string = wordArray + '';
6232 * var string = wordArray.toString();
6233 * var string = wordArray.toString(CryptoJS.enc.Utf8);
6235 toString: function (encoder
) {
6236 return (encoder
|| Hex
).stringify(this);
6240 * Concatenates a word array to this word array.
6242 * @param {WordArray} wordArray The word array to append.
6244 * @return {WordArray} This word array.
6248 * wordArray1.concat(wordArray2);
6250 concat: function (wordArray
) {
6252 var thisWords
= this.words
;
6253 var thatWords
= wordArray
.words
;
6254 var thisSigBytes
= this.sigBytes
;
6255 var thatSigBytes
= wordArray
.sigBytes
;
6257 // Clamp excess bits
6261 if (thisSigBytes
% 4) {
6262 // Copy one byte at a time
6263 for (var i
= 0; i
< thatSigBytes
; i
++) {
6264 var thatByte
= (thatWords
[i
>>> 2] >>> (24 - (i
% 4) * 8)) & 0xff;
6265 thisWords
[(thisSigBytes
+ i
) >>> 2] |= thatByte
<< (24 - ((thisSigBytes
+ i
) % 4) * 8);
6267 } else if (thatWords
.length
> 0xffff) {
6268 // Copy one word at a time
6269 for (var i
= 0; i
< thatSigBytes
; i
+= 4) {
6270 thisWords
[(thisSigBytes
+ i
) >>> 2] = thatWords
[i
>>> 2];
6273 // Copy all words at once
6274 thisWords
.push
.apply(thisWords
, thatWords
);
6276 this.sigBytes
+= thatSigBytes
;
6283 * Removes insignificant bits.
6287 * wordArray.clamp();
6289 clamp: function () {
6291 var words
= this.words
;
6292 var sigBytes
= this.sigBytes
;
6295 words
[sigBytes
>>> 2] &= 0xffffffff << (32 - (sigBytes
% 4) * 8);
6296 words
.length
= Math
.ceil(sigBytes
/ 4);
6300 * Creates a copy of this word array.
6302 * @return {WordArray} The clone.
6306 * var clone = wordArray.clone();
6308 clone: function () {
6309 var clone
= Base
.clone
.call(this);
6310 clone
.words
= this.words
.slice(0);
6316 * Creates a word array filled with random bytes.
6318 * @param {number} nBytes The number of random bytes to generate.
6320 * @return {WordArray} The random word array.
6326 * var wordArray = CryptoJS.lib.WordArray.random(16);
6328 random: function (nBytes
) {
6330 for (var i
= 0; i
< nBytes
; i
+= 4) {
6331 words
.push((Math
.random() * 0x100000000) | 0);
6334 return new WordArray
.init(words
, nBytes
);
6339 * Encoder namespace.
6341 var C_enc
= C
.enc
= {};
6344 * Hex encoding strategy.
6346 var Hex
= C_enc
.Hex
= {
6348 * Converts a word array to a hex string.
6350 * @param {WordArray} wordArray The word array.
6352 * @return {string} The hex string.
6358 * var hexString = CryptoJS.enc.Hex.stringify(wordArray);
6360 stringify: function (wordArray
) {
6362 var words
= wordArray
.words
;
6363 var sigBytes
= wordArray
.sigBytes
;
6367 for (var i
= 0; i
< sigBytes
; i
++) {
6368 var bite
= (words
[i
>>> 2] >>> (24 - (i
% 4) * 8)) & 0xff;
6369 hexChars
.push((bite
>>> 4).toString(16));
6370 hexChars
.push((bite
& 0x0f).toString(16));
6373 return hexChars
.join('');
6377 * Converts a hex string to a word array.
6379 * @param {string} hexStr The hex string.
6381 * @return {WordArray} The word array.
6387 * var wordArray = CryptoJS.enc.Hex.parse(hexString);
6389 parse: function (hexStr
) {
6391 var hexStrLength
= hexStr
.length
;
6395 for (var i
= 0; i
< hexStrLength
; i
+= 2) {
6396 words
[i
>>> 3] |= parseInt(hexStr
.substr(i
, 2), 16) << (24 - (i
% 8) * 4);
6399 return new WordArray
.init(words
, hexStrLength
/ 2);
6404 * Latin1 encoding strategy.
6406 var Latin1
= C_enc
.Latin1
= {
6408 * Converts a word array to a Latin1 string.
6410 * @param {WordArray} wordArray The word array.
6412 * @return {string} The Latin1 string.
6418 * var latin1String = CryptoJS.enc.Latin1.stringify(wordArray);
6420 stringify: function (wordArray
) {
6422 var words
= wordArray
.words
;
6423 var sigBytes
= wordArray
.sigBytes
;
6426 var latin1Chars
= [];
6427 for (var i
= 0; i
< sigBytes
; i
++) {
6428 var bite
= (words
[i
>>> 2] >>> (24 - (i
% 4) * 8)) & 0xff;
6429 latin1Chars
.push(String
.fromCharCode(bite
));
6432 return latin1Chars
.join('');
6436 * Converts a Latin1 string to a word array.
6438 * @param {string} latin1Str The Latin1 string.
6440 * @return {WordArray} The word array.
6446 * var wordArray = CryptoJS.enc.Latin1.parse(latin1String);
6448 parse: function (latin1Str
) {
6450 var latin1StrLength
= latin1Str
.length
;
6454 for (var i
= 0; i
< latin1StrLength
; i
++) {
6455 words
[i
>>> 2] |= (latin1Str
.charCodeAt(i
) & 0xff) << (24 - (i
% 4) * 8);
6458 return new WordArray
.init(words
, latin1StrLength
);
6463 * UTF-8 encoding strategy.
6465 var Utf8
= C_enc
.Utf8
= {
6467 * Converts a word array to a UTF-8 string.
6469 * @param {WordArray} wordArray The word array.
6471 * @return {string} The UTF-8 string.
6477 * var utf8String = CryptoJS.enc.Utf8.stringify(wordArray);
6479 stringify: function (wordArray
) {
6481 return decodeURIComponent(escape(Latin1
.stringify(wordArray
)));
6483 throw new Error('Malformed UTF-8 data');
6488 * Converts a UTF-8 string to a word array.
6490 * @param {string} utf8Str The UTF-8 string.
6492 * @return {WordArray} The word array.
6498 * var wordArray = CryptoJS.enc.Utf8.parse(utf8String);
6500 parse: function (utf8Str
) {
6501 return Latin1
.parse(unescape(encodeURIComponent(utf8Str
)));
6506 * Abstract buffered block algorithm template.
6508 * The property blockSize must be implemented in a concrete subtype.
6510 * @property {number} _minBufferSize The number of blocks that should be kept unprocessed in the buffer. Default: 0
6512 var BufferedBlockAlgorithm
= C_lib
.BufferedBlockAlgorithm
= Base
.extend({
6514 * Resets this block algorithm's data buffer to its initial state.
6518 * bufferedBlockAlgorithm.reset();
6520 reset: function () {
6522 this._data
= new WordArray
.init();
6523 this._nDataBytes
= 0;
6527 * Adds new data to this block algorithm's buffer.
6529 * @param {WordArray|string} data The data to append. Strings are converted to a WordArray using UTF-8.
6533 * bufferedBlockAlgorithm._append('data');
6534 * bufferedBlockAlgorithm._append(wordArray);
6536 _append: function (data
) {
6537 // Convert string to WordArray, else assume WordArray already
6538 if (typeof data
== 'string') {
6539 data
= Utf8
.parse(data
);
6543 this._data
.concat(data
);
6544 this._nDataBytes
+= data
.sigBytes
;
6548 * Processes available data blocks.
6550 * This method invokes _doProcessBlock(offset), which must be implemented by a concrete subtype.
6552 * @param {boolean} doFlush Whether all blocks and partial blocks should be processed.
6554 * @return {WordArray} The processed data.
6558 * var processedData = bufferedBlockAlgorithm._process();
6559 * var processedData = bufferedBlockAlgorithm._process(!!'flush');
6561 _process: function (doFlush
) {
6563 var data
= this._data
;
6564 var dataWords
= data
.words
;
6565 var dataSigBytes
= data
.sigBytes
;
6566 var blockSize
= this.blockSize
;
6567 var blockSizeBytes
= blockSize
* 4;
6569 // Count blocks ready
6570 var nBlocksReady
= dataSigBytes
/ blockSizeBytes
;
6572 // Round up to include partial blocks
6573 nBlocksReady
= Math
.ceil(nBlocksReady
);
6575 // Round down to include only full blocks,
6576 // less the number of blocks that must remain in the buffer
6577 nBlocksReady
= Math
.max((nBlocksReady
| 0) - this._minBufferSize
, 0);
6580 // Count words ready
6581 var nWordsReady
= nBlocksReady
* blockSize
;
6583 // Count bytes ready
6584 var nBytesReady
= Math
.min(nWordsReady
* 4, dataSigBytes
);
6588 for (var offset
= 0; offset
< nWordsReady
; offset
+= blockSize
) {
6589 // Perform concrete-algorithm logic
6590 this._doProcessBlock(dataWords
, offset
);
6593 // Remove processed words
6594 var processedWords
= dataWords
.splice(0, nWordsReady
);
6595 data
.sigBytes
-= nBytesReady
;
6598 // Return processed words
6599 return new WordArray
.init(processedWords
, nBytesReady
);
6603 * Creates a copy of this object.
6605 * @return {Object} The clone.
6609 * var clone = bufferedBlockAlgorithm.clone();
6611 clone: function () {
6612 var clone
= Base
.clone
.call(this);
6613 clone
._data
= this._data
.clone();
6622 * Abstract hasher template.
6624 * @property {number} blockSize The number of 32-bit words this hasher operates on. Default: 16 (512 bits)
6626 var Hasher
= C_lib
.Hasher
= BufferedBlockAlgorithm
.extend({
6628 * Configuration options.
6633 * Initializes a newly created hasher.
6635 * @param {Object} cfg (Optional) The configuration options to use for this hash computation.
6639 * var hasher = CryptoJS.algo.SHA256.create();
6641 init: function (cfg
) {
6642 // Apply config defaults
6643 this.cfg
= this.cfg
.extend(cfg
);
6645 // Set initial values
6650 * Resets this hasher to its initial state.
6656 reset: function () {
6657 // Reset data buffer
6658 BufferedBlockAlgorithm
.reset
.call(this);
6660 // Perform concrete-hasher logic
6665 * Updates this hasher with a message.
6667 * @param {WordArray|string} messageUpdate The message to append.
6669 * @return {Hasher} This hasher.
6673 * hasher.update('message');
6674 * hasher.update(wordArray);
6676 update: function (messageUpdate
) {
6678 this._append(messageUpdate
);
6688 * Finalizes the hash computation.
6689 * Note that the finalize operation is effectively a destructive, read-once operation.
6691 * @param {WordArray|string} messageUpdate (Optional) A final message update.
6693 * @return {WordArray} The hash.
6697 * var hash = hasher.finalize();
6698 * var hash = hasher.finalize('message');
6699 * var hash = hasher.finalize(wordArray);
6701 finalize: function (messageUpdate
) {
6702 // Final message update
6703 if (messageUpdate
) {
6704 this._append(messageUpdate
);
6707 // Perform concrete-hasher logic
6708 var hash
= this._doFinalize();
6716 * Creates a shortcut function to a hasher's object interface.
6718 * @param {Hasher} hasher The hasher to create a helper for.
6720 * @return {Function} The shortcut function.
6726 * var SHA256 = CryptoJS.lib.Hasher._createHelper(CryptoJS.algo.SHA256);
6728 _createHelper: function (hasher
) {
6729 return function (message
, cfg
) {
6730 return new hasher
.init(cfg
).finalize(message
);
6735 * Creates a shortcut function to the HMAC's object interface.
6737 * @param {Hasher} hasher The hasher to use in this HMAC helper.
6739 * @return {Function} The shortcut function.
6745 * var HmacSHA256 = CryptoJS.lib.Hasher._createHmacHelper(CryptoJS.algo.SHA256);
6747 _createHmacHelper: function (hasher
) {
6748 return function (message
, key
) {
6749 return new C_algo
.HMAC
.init(hasher
, key
).finalize(message
);
6755 * Algorithm namespace.
6757 var C_algo
= C
.algo
= {};
6766 },{}],32:[function(_dereq_
,module
,exports
){
6767 ;(function (root
, factory
) {
6768 if (typeof exports
=== "object") {
6770 module
.exports
= exports
= factory(_dereq_("./core"));
6772 else if (typeof define
=== "function" && define
.amd
) {
6774 define(["./core"], factory
);
6778 factory(root
.CryptoJS
);
6780 }(this, function (CryptoJS
) {
6786 var WordArray
= C_lib
.WordArray
;
6790 * Base64 encoding strategy.
6792 var Base64
= C_enc
.Base64
= {
6794 * Converts a word array to a Base64 string.
6796 * @param {WordArray} wordArray The word array.
6798 * @return {string} The Base64 string.
6804 * var base64String = CryptoJS.enc.Base64.stringify(wordArray);
6806 stringify: function (wordArray
) {
6808 var words
= wordArray
.words
;
6809 var sigBytes
= wordArray
.sigBytes
;
6810 var map
= this._map
;
6812 // Clamp excess bits
6816 var base64Chars
= [];
6817 for (var i
= 0; i
< sigBytes
; i
+= 3) {
6818 var byte1
= (words
[i
>>> 2] >>> (24 - (i
% 4) * 8)) & 0xff;
6819 var byte2
= (words
[(i
+ 1) >>> 2] >>> (24 - ((i
+ 1) % 4) * 8)) & 0xff;
6820 var byte3
= (words
[(i
+ 2) >>> 2] >>> (24 - ((i
+ 2) % 4) * 8)) & 0xff;
6822 var triplet
= (byte1
<< 16) | (byte2
<< 8) | byte3
;
6824 for (var j
= 0; (j
< 4) && (i
+ j
* 0.75 < sigBytes
); j
++) {
6825 base64Chars
.push(map
.charAt((triplet
>>> (6 * (3 - j
))) & 0x3f));
6830 var paddingChar
= map
.charAt(64);
6832 while (base64Chars
.length
% 4) {
6833 base64Chars
.push(paddingChar
);
6837 return base64Chars
.join('');
6841 * Converts a Base64 string to a word array.
6843 * @param {string} base64Str The Base64 string.
6845 * @return {WordArray} The word array.
6851 * var wordArray = CryptoJS.enc.Base64.parse(base64String);
6853 parse: function (base64Str
) {
6855 var base64StrLength
= base64Str
.length
;
6856 var map
= this._map
;
6859 var paddingChar
= map
.charAt(64);
6861 var paddingIndex
= base64Str
.indexOf(paddingChar
);
6862 if (paddingIndex
!= -1) {
6863 base64StrLength
= paddingIndex
;
6870 for (var i
= 0; i
< base64StrLength
; i
++) {
6872 var bits1
= map
.indexOf(base64Str
.charAt(i
- 1)) << ((i
% 4) * 2);
6873 var bits2
= map
.indexOf(base64Str
.charAt(i
)) >>> (6 - (i
% 4) * 2);
6874 words
[nBytes
>>> 2] |= (bits1
| bits2
) << (24 - (nBytes
% 4) * 8);
6879 return WordArray
.create(words
, nBytes
);
6882 _map: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
6887 return CryptoJS
.enc
.Base64
;
6890 },{"./core":31}],33:[function(_dereq_
,module
,exports
){
6891 ;(function (root
, factory
) {
6892 if (typeof exports
=== "object") {
6894 module
.exports
= exports
= factory(_dereq_("./core"));
6896 else if (typeof define
=== "function" && define
.amd
) {
6898 define(["./core"], factory
);
6902 factory(root
.CryptoJS
);
6904 }(this, function (CryptoJS
) {
6910 var WordArray
= C_lib
.WordArray
;
6914 * UTF-16 BE encoding strategy.
6916 var Utf16BE
= C_enc
.Utf16
= C_enc
.Utf16BE
= {
6918 * Converts a word array to a UTF-16 BE string.
6920 * @param {WordArray} wordArray The word array.
6922 * @return {string} The UTF-16 BE string.
6928 * var utf16String = CryptoJS.enc.Utf16.stringify(wordArray);
6930 stringify: function (wordArray
) {
6932 var words
= wordArray
.words
;
6933 var sigBytes
= wordArray
.sigBytes
;
6936 var utf16Chars
= [];
6937 for (var i
= 0; i
< sigBytes
; i
+= 2) {
6938 var codePoint
= (words
[i
>>> 2] >>> (16 - (i
% 4) * 8)) & 0xffff;
6939 utf16Chars
.push(String
.fromCharCode(codePoint
));
6942 return utf16Chars
.join('');
6946 * Converts a UTF-16 BE string to a word array.
6948 * @param {string} utf16Str The UTF-16 BE string.
6950 * @return {WordArray} The word array.
6956 * var wordArray = CryptoJS.enc.Utf16.parse(utf16String);
6958 parse: function (utf16Str
) {
6960 var utf16StrLength
= utf16Str
.length
;
6964 for (var i
= 0; i
< utf16StrLength
; i
++) {
6965 words
[i
>>> 1] |= utf16Str
.charCodeAt(i
) << (16 - (i
% 2) * 16);
6968 return WordArray
.create(words
, utf16StrLength
* 2);
6973 * UTF-16 LE encoding strategy.
6977 * Converts a word array to a UTF-16 LE string.
6979 * @param {WordArray} wordArray The word array.
6981 * @return {string} The UTF-16 LE string.
6987 * var utf16Str = CryptoJS.enc.Utf16LE.stringify(wordArray);
6989 stringify: function (wordArray
) {
6991 var words
= wordArray
.words
;
6992 var sigBytes
= wordArray
.sigBytes
;
6995 var utf16Chars
= [];
6996 for (var i
= 0; i
< sigBytes
; i
+= 2) {
6997 var codePoint
= swapEndian((words
[i
>>> 2] >>> (16 - (i
% 4) * 8)) & 0xffff);
6998 utf16Chars
.push(String
.fromCharCode(codePoint
));
7001 return utf16Chars
.join('');
7005 * Converts a UTF-16 LE string to a word array.
7007 * @param {string} utf16Str The UTF-16 LE string.
7009 * @return {WordArray} The word array.
7015 * var wordArray = CryptoJS.enc.Utf16LE.parse(utf16Str);
7017 parse: function (utf16Str
) {
7019 var utf16StrLength
= utf16Str
.length
;
7023 for (var i
= 0; i
< utf16StrLength
; i
++) {
7024 words
[i
>>> 1] |= swapEndian(utf16Str
.charCodeAt(i
) << (16 - (i
% 2) * 16));
7027 return WordArray
.create(words
, utf16StrLength
* 2);
7031 function swapEndian(word
) {
7032 return ((word
<< 8) & 0xff00ff00) | ((word
>>> 8) & 0x00ff00ff);
7037 return CryptoJS
.enc
.Utf16
;
7040 },{"./core":31}],34:[function(_dereq_
,module
,exports
){
7041 ;(function (root
, factory
, undef
) {
7042 if (typeof exports
=== "object") {
7044 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./sha1"), _dereq_("./hmac"));
7046 else if (typeof define
=== "function" && define
.amd
) {
7048 define(["./core", "./sha1", "./hmac"], factory
);
7052 factory(root
.CryptoJS
);
7054 }(this, function (CryptoJS
) {
7060 var Base
= C_lib
.Base
;
7061 var WordArray
= C_lib
.WordArray
;
7062 var C_algo
= C
.algo
;
7063 var MD5
= C_algo
.MD5
;
7066 * This key derivation function is meant to conform with EVP_BytesToKey.
7067 * www.openssl.org/docs/crypto/EVP_BytesToKey.html
7069 var EvpKDF
= C_algo
.EvpKDF
= Base
.extend({
7071 * Configuration options.
7073 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
7074 * @property {Hasher} hasher The hash algorithm to use. Default: MD5
7075 * @property {number} iterations The number of iterations to perform. Default: 1
7084 * Initializes a newly created key derivation function.
7086 * @param {Object} cfg (Optional) The configuration options to use for the derivation.
7090 * var kdf = CryptoJS.algo.EvpKDF.create();
7091 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8 });
7092 * var kdf = CryptoJS.algo.EvpKDF.create({ keySize: 8, iterations: 1000 });
7094 init: function (cfg
) {
7095 this.cfg
= this.cfg
.extend(cfg
);
7099 * Derives a key from a password.
7101 * @param {WordArray|string} password The password.
7102 * @param {WordArray|string} salt A salt.
7104 * @return {WordArray} The derived key.
7108 * var key = kdf.compute(password, salt);
7110 compute: function (password
, salt
) {
7115 var hasher
= cfg
.hasher
.create();
7118 var derivedKey
= WordArray
.create();
7121 var derivedKeyWords
= derivedKey
.words
;
7122 var keySize
= cfg
.keySize
;
7123 var iterations
= cfg
.iterations
;
7126 while (derivedKeyWords
.length
< keySize
) {
7128 hasher
.update(block
);
7130 var block
= hasher
.update(password
).finalize(salt
);
7134 for (var i
= 1; i
< iterations
; i
++) {
7135 block
= hasher
.finalize(block
);
7139 derivedKey
.concat(block
);
7141 derivedKey
.sigBytes
= keySize
* 4;
7148 * Derives a key from a password.
7150 * @param {WordArray|string} password The password.
7151 * @param {WordArray|string} salt A salt.
7152 * @param {Object} cfg (Optional) The configuration options to use for this computation.
7154 * @return {WordArray} The derived key.
7160 * var key = CryptoJS.EvpKDF(password, salt);
7161 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8 });
7162 * var key = CryptoJS.EvpKDF(password, salt, { keySize: 8, iterations: 1000 });
7164 C
.EvpKDF = function (password
, salt
, cfg
) {
7165 return EvpKDF
.create(cfg
).compute(password
, salt
);
7170 return CryptoJS
.EvpKDF
;
7173 },{"./core":31,"./hmac":36,"./sha1":55}],35:[function(_dereq_
,module
,exports
){
7174 ;(function (root
, factory
, undef
) {
7175 if (typeof exports
=== "object") {
7177 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
7179 else if (typeof define
=== "function" && define
.amd
) {
7181 define(["./core", "./cipher-core"], factory
);
7185 factory(root
.CryptoJS
);
7187 }(this, function (CryptoJS
) {
7189 (function (undefined) {
7193 var CipherParams
= C_lib
.CipherParams
;
7195 var Hex
= C_enc
.Hex
;
7196 var C_format
= C
.format
;
7198 var HexFormatter
= C_format
.Hex
= {
7200 * Converts the ciphertext of a cipher params object to a hexadecimally encoded string.
7202 * @param {CipherParams} cipherParams The cipher params object.
7204 * @return {string} The hexadecimally encoded string.
7210 * var hexString = CryptoJS.format.Hex.stringify(cipherParams);
7212 stringify: function (cipherParams
) {
7213 return cipherParams
.ciphertext
.toString(Hex
);
7217 * Converts a hexadecimally encoded ciphertext string to a cipher params object.
7219 * @param {string} input The hexadecimally encoded string.
7221 * @return {CipherParams} The cipher params object.
7227 * var cipherParams = CryptoJS.format.Hex.parse(hexString);
7229 parse: function (input
) {
7230 var ciphertext
= Hex
.parse(input
);
7231 return CipherParams
.create({ ciphertext: ciphertext
});
7237 return CryptoJS
.format
.Hex
;
7240 },{"./cipher-core":30,"./core":31}],36:[function(_dereq_
,module
,exports
){
7241 ;(function (root
, factory
) {
7242 if (typeof exports
=== "object") {
7244 module
.exports
= exports
= factory(_dereq_("./core"));
7246 else if (typeof define
=== "function" && define
.amd
) {
7248 define(["./core"], factory
);
7252 factory(root
.CryptoJS
);
7254 }(this, function (CryptoJS
) {
7260 var Base
= C_lib
.Base
;
7262 var Utf8
= C_enc
.Utf8
;
7263 var C_algo
= C
.algo
;
7268 var HMAC
= C_algo
.HMAC
= Base
.extend({
7270 * Initializes a newly created HMAC.
7272 * @param {Hasher} hasher The hash algorithm to use.
7273 * @param {WordArray|string} key The secret key.
7277 * var hmacHasher = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, key);
7279 init: function (hasher
, key
) {
7281 hasher
= this._hasher
= new hasher
.init();
7283 // Convert string to WordArray, else assume WordArray already
7284 if (typeof key
== 'string') {
7285 key
= Utf8
.parse(key
);
7289 var hasherBlockSize
= hasher
.blockSize
;
7290 var hasherBlockSizeBytes
= hasherBlockSize
* 4;
7292 // Allow arbitrary length keys
7293 if (key
.sigBytes
> hasherBlockSizeBytes
) {
7294 key
= hasher
.finalize(key
);
7297 // Clamp excess bits
7300 // Clone key for inner and outer pads
7301 var oKey
= this._oKey
= key
.clone();
7302 var iKey
= this._iKey
= key
.clone();
7305 var oKeyWords
= oKey
.words
;
7306 var iKeyWords
= iKey
.words
;
7308 // XOR keys with pad constants
7309 for (var i
= 0; i
< hasherBlockSize
; i
++) {
7310 oKeyWords
[i
] ^= 0x5c5c5c5c;
7311 iKeyWords
[i
] ^= 0x36363636;
7313 oKey
.sigBytes
= iKey
.sigBytes
= hasherBlockSizeBytes
;
7315 // Set initial values
7320 * Resets this HMAC to its initial state.
7324 * hmacHasher.reset();
7326 reset: function () {
7328 var hasher
= this._hasher
;
7332 hasher
.update(this._iKey
);
7336 * Updates this HMAC with a message.
7338 * @param {WordArray|string} messageUpdate The message to append.
7340 * @return {HMAC} This HMAC instance.
7344 * hmacHasher.update('message');
7345 * hmacHasher.update(wordArray);
7347 update: function (messageUpdate
) {
7348 this._hasher
.update(messageUpdate
);
7355 * Finalizes the HMAC computation.
7356 * Note that the finalize operation is effectively a destructive, read-once operation.
7358 * @param {WordArray|string} messageUpdate (Optional) A final message update.
7360 * @return {WordArray} The HMAC.
7364 * var hmac = hmacHasher.finalize();
7365 * var hmac = hmacHasher.finalize('message');
7366 * var hmac = hmacHasher.finalize(wordArray);
7368 finalize: function (messageUpdate
) {
7370 var hasher
= this._hasher
;
7373 var innerHash
= hasher
.finalize(messageUpdate
);
7375 var hmac
= hasher
.finalize(this._oKey
.clone().concat(innerHash
));
7384 },{"./core":31}],37:[function(_dereq_
,module
,exports
){
7385 ;(function (root
, factory
, undef
) {
7386 if (typeof exports
=== "object") {
7388 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./x64-core"), _dereq_("./lib-typedarrays"), _dereq_("./enc-utf16"), _dereq_("./enc-base64"), _dereq_("./md5"), _dereq_("./sha1"), _dereq_("./sha256"), _dereq_("./sha224"), _dereq_("./sha512"), _dereq_("./sha384"), _dereq_("./sha3"), _dereq_("./ripemd160"), _dereq_("./hmac"), _dereq_("./pbkdf2"), _dereq_("./evpkdf"), _dereq_("./cipher-core"), _dereq_("./mode-cfb"), _dereq_("./mode-ctr"), _dereq_("./mode-ctr-gladman"), _dereq_("./mode-ofb"), _dereq_("./mode-ecb"), _dereq_("./pad-ansix923"), _dereq_("./pad-iso10126"), _dereq_("./pad-iso97971"), _dereq_("./pad-zeropadding"), _dereq_("./pad-nopadding"), _dereq_("./format-hex"), _dereq_("./aes"), _dereq_("./tripledes"), _dereq_("./rc4"), _dereq_("./rabbit"), _dereq_("./rabbit-legacy"));
7390 else if (typeof define
=== "function" && define
.amd
) {
7392 define(["./core", "./x64-core", "./lib-typedarrays", "./enc-utf16", "./enc-base64", "./md5", "./sha1", "./sha256", "./sha224", "./sha512", "./sha384", "./sha3", "./ripemd160", "./hmac", "./pbkdf2", "./evpkdf", "./cipher-core", "./mode-cfb", "./mode-ctr", "./mode-ctr-gladman", "./mode-ofb", "./mode-ecb", "./pad-ansix923", "./pad-iso10126", "./pad-iso97971", "./pad-zeropadding", "./pad-nopadding", "./format-hex", "./aes", "./tripledes", "./rc4", "./rabbit", "./rabbit-legacy"], factory
);
7396 factory(root
.CryptoJS
);
7398 }(this, function (CryptoJS
) {
7403 },{"./aes":29,"./cipher-core":30,"./core":31,"./enc-base64":32,"./enc-utf16":33,"./evpkdf":34,"./format-hex":35,"./hmac":36,"./lib-typedarrays":38,"./md5":39,"./mode-cfb":40,"./mode-ctr":42,"./mode-ctr-gladman":41,"./mode-ecb":43,"./mode-ofb":44,"./pad-ansix923":45,"./pad-iso10126":46,"./pad-iso97971":47,"./pad-nopadding":48,"./pad-zeropadding":49,"./pbkdf2":50,"./rabbit":52,"./rabbit-legacy":51,"./rc4":53,"./ripemd160":54,"./sha1":55,"./sha224":56,"./sha256":57,"./sha3":58,"./sha384":59,"./sha512":60,"./tripledes":61,"./x64-core":62}],38:[function(_dereq_
,module
,exports
){
7404 ;(function (root
, factory
) {
7405 if (typeof exports
=== "object") {
7407 module
.exports
= exports
= factory(_dereq_("./core"));
7409 else if (typeof define
=== "function" && define
.amd
) {
7411 define(["./core"], factory
);
7415 factory(root
.CryptoJS
);
7417 }(this, function (CryptoJS
) {
7420 // Check if typed arrays are supported
7421 if (typeof ArrayBuffer
!= 'function') {
7428 var WordArray
= C_lib
.WordArray
;
7430 // Reference original init
7431 var superInit
= WordArray
.init
;
7433 // Augment WordArray.init to handle typed arrays
7434 var subInit
= WordArray
.init = function (typedArray
) {
7435 // Convert buffers to uint8
7436 if (typedArray
instanceof ArrayBuffer
) {
7437 typedArray
= new Uint8Array(typedArray
);
7440 // Convert other array views to uint8
7442 typedArray
instanceof Int8Array
||
7443 typedArray
instanceof Uint8ClampedArray
||
7444 typedArray
instanceof Int16Array
||
7445 typedArray
instanceof Uint16Array
||
7446 typedArray
instanceof Int32Array
||
7447 typedArray
instanceof Uint32Array
||
7448 typedArray
instanceof Float32Array
||
7449 typedArray
instanceof Float64Array
7451 typedArray
= new Uint8Array(typedArray
.buffer
, typedArray
.byteOffset
, typedArray
.byteLength
);
7454 // Handle Uint8Array
7455 if (typedArray
instanceof Uint8Array
) {
7457 var typedArrayByteLength
= typedArray
.byteLength
;
7461 for (var i
= 0; i
< typedArrayByteLength
; i
++) {
7462 words
[i
>>> 2] |= typedArray
[i
] << (24 - (i
% 4) * 8);
7465 // Initialize this word array
7466 superInit
.call(this, words
, typedArrayByteLength
);
7468 // Else call normal init
7469 superInit
.apply(this, arguments
);
7473 subInit
.prototype = WordArray
;
7477 return CryptoJS
.lib
.WordArray
;
7480 },{"./core":31}],39:[function(_dereq_
,module
,exports
){
7481 ;(function (root
, factory
) {
7482 if (typeof exports
=== "object") {
7484 module
.exports
= exports
= factory(_dereq_("./core"));
7486 else if (typeof define
=== "function" && define
.amd
) {
7488 define(["./core"], factory
);
7492 factory(root
.CryptoJS
);
7494 }(this, function (CryptoJS
) {
7500 var WordArray
= C_lib
.WordArray
;
7501 var Hasher
= C_lib
.Hasher
;
7502 var C_algo
= C
.algo
;
7507 // Compute constants
7509 for (var i
= 0; i
< 64; i
++) {
7510 T
[i
] = (Math
.abs(Math
.sin(i
+ 1)) * 0x100000000) | 0;
7515 * MD5 hash algorithm.
7517 var MD5
= C_algo
.MD5
= Hasher
.extend({
7518 _doReset: function () {
7519 this._hash
= new WordArray
.init([
7520 0x67452301, 0xefcdab89,
7521 0x98badcfe, 0x10325476
7525 _doProcessBlock: function (M
, offset
) {
7527 for (var i
= 0; i
< 16; i
++) {
7529 var offset_i
= offset
+ i
;
7530 var M_offset_i
= M
[offset_i
];
7533 (((M_offset_i
<< 8) | (M_offset_i
>>> 24)) & 0x00ff00ff) |
7534 (((M_offset_i
<< 24) | (M_offset_i
>>> 8)) & 0xff00ff00)
7539 var H
= this._hash
.words
;
7541 var M_offset_0
= M
[offset
+ 0];
7542 var M_offset_1
= M
[offset
+ 1];
7543 var M_offset_2
= M
[offset
+ 2];
7544 var M_offset_3
= M
[offset
+ 3];
7545 var M_offset_4
= M
[offset
+ 4];
7546 var M_offset_5
= M
[offset
+ 5];
7547 var M_offset_6
= M
[offset
+ 6];
7548 var M_offset_7
= M
[offset
+ 7];
7549 var M_offset_8
= M
[offset
+ 8];
7550 var M_offset_9
= M
[offset
+ 9];
7551 var M_offset_10
= M
[offset
+ 10];
7552 var M_offset_11
= M
[offset
+ 11];
7553 var M_offset_12
= M
[offset
+ 12];
7554 var M_offset_13
= M
[offset
+ 13];
7555 var M_offset_14
= M
[offset
+ 14];
7556 var M_offset_15
= M
[offset
+ 15];
7558 // Working varialbes
7565 a
= FF(a
, b
, c
, d
, M_offset_0
, 7, T
[0]);
7566 d
= FF(d
, a
, b
, c
, M_offset_1
, 12, T
[1]);
7567 c
= FF(c
, d
, a
, b
, M_offset_2
, 17, T
[2]);
7568 b
= FF(b
, c
, d
, a
, M_offset_3
, 22, T
[3]);
7569 a
= FF(a
, b
, c
, d
, M_offset_4
, 7, T
[4]);
7570 d
= FF(d
, a
, b
, c
, M_offset_5
, 12, T
[5]);
7571 c
= FF(c
, d
, a
, b
, M_offset_6
, 17, T
[6]);
7572 b
= FF(b
, c
, d
, a
, M_offset_7
, 22, T
[7]);
7573 a
= FF(a
, b
, c
, d
, M_offset_8
, 7, T
[8]);
7574 d
= FF(d
, a
, b
, c
, M_offset_9
, 12, T
[9]);
7575 c
= FF(c
, d
, a
, b
, M_offset_10
, 17, T
[10]);
7576 b
= FF(b
, c
, d
, a
, M_offset_11
, 22, T
[11]);
7577 a
= FF(a
, b
, c
, d
, M_offset_12
, 7, T
[12]);
7578 d
= FF(d
, a
, b
, c
, M_offset_13
, 12, T
[13]);
7579 c
= FF(c
, d
, a
, b
, M_offset_14
, 17, T
[14]);
7580 b
= FF(b
, c
, d
, a
, M_offset_15
, 22, T
[15]);
7582 a
= GG(a
, b
, c
, d
, M_offset_1
, 5, T
[16]);
7583 d
= GG(d
, a
, b
, c
, M_offset_6
, 9, T
[17]);
7584 c
= GG(c
, d
, a
, b
, M_offset_11
, 14, T
[18]);
7585 b
= GG(b
, c
, d
, a
, M_offset_0
, 20, T
[19]);
7586 a
= GG(a
, b
, c
, d
, M_offset_5
, 5, T
[20]);
7587 d
= GG(d
, a
, b
, c
, M_offset_10
, 9, T
[21]);
7588 c
= GG(c
, d
, a
, b
, M_offset_15
, 14, T
[22]);
7589 b
= GG(b
, c
, d
, a
, M_offset_4
, 20, T
[23]);
7590 a
= GG(a
, b
, c
, d
, M_offset_9
, 5, T
[24]);
7591 d
= GG(d
, a
, b
, c
, M_offset_14
, 9, T
[25]);
7592 c
= GG(c
, d
, a
, b
, M_offset_3
, 14, T
[26]);
7593 b
= GG(b
, c
, d
, a
, M_offset_8
, 20, T
[27]);
7594 a
= GG(a
, b
, c
, d
, M_offset_13
, 5, T
[28]);
7595 d
= GG(d
, a
, b
, c
, M_offset_2
, 9, T
[29]);
7596 c
= GG(c
, d
, a
, b
, M_offset_7
, 14, T
[30]);
7597 b
= GG(b
, c
, d
, a
, M_offset_12
, 20, T
[31]);
7599 a
= HH(a
, b
, c
, d
, M_offset_5
, 4, T
[32]);
7600 d
= HH(d
, a
, b
, c
, M_offset_8
, 11, T
[33]);
7601 c
= HH(c
, d
, a
, b
, M_offset_11
, 16, T
[34]);
7602 b
= HH(b
, c
, d
, a
, M_offset_14
, 23, T
[35]);
7603 a
= HH(a
, b
, c
, d
, M_offset_1
, 4, T
[36]);
7604 d
= HH(d
, a
, b
, c
, M_offset_4
, 11, T
[37]);
7605 c
= HH(c
, d
, a
, b
, M_offset_7
, 16, T
[38]);
7606 b
= HH(b
, c
, d
, a
, M_offset_10
, 23, T
[39]);
7607 a
= HH(a
, b
, c
, d
, M_offset_13
, 4, T
[40]);
7608 d
= HH(d
, a
, b
, c
, M_offset_0
, 11, T
[41]);
7609 c
= HH(c
, d
, a
, b
, M_offset_3
, 16, T
[42]);
7610 b
= HH(b
, c
, d
, a
, M_offset_6
, 23, T
[43]);
7611 a
= HH(a
, b
, c
, d
, M_offset_9
, 4, T
[44]);
7612 d
= HH(d
, a
, b
, c
, M_offset_12
, 11, T
[45]);
7613 c
= HH(c
, d
, a
, b
, M_offset_15
, 16, T
[46]);
7614 b
= HH(b
, c
, d
, a
, M_offset_2
, 23, T
[47]);
7616 a
= II(a
, b
, c
, d
, M_offset_0
, 6, T
[48]);
7617 d
= II(d
, a
, b
, c
, M_offset_7
, 10, T
[49]);
7618 c
= II(c
, d
, a
, b
, M_offset_14
, 15, T
[50]);
7619 b
= II(b
, c
, d
, a
, M_offset_5
, 21, T
[51]);
7620 a
= II(a
, b
, c
, d
, M_offset_12
, 6, T
[52]);
7621 d
= II(d
, a
, b
, c
, M_offset_3
, 10, T
[53]);
7622 c
= II(c
, d
, a
, b
, M_offset_10
, 15, T
[54]);
7623 b
= II(b
, c
, d
, a
, M_offset_1
, 21, T
[55]);
7624 a
= II(a
, b
, c
, d
, M_offset_8
, 6, T
[56]);
7625 d
= II(d
, a
, b
, c
, M_offset_15
, 10, T
[57]);
7626 c
= II(c
, d
, a
, b
, M_offset_6
, 15, T
[58]);
7627 b
= II(b
, c
, d
, a
, M_offset_13
, 21, T
[59]);
7628 a
= II(a
, b
, c
, d
, M_offset_4
, 6, T
[60]);
7629 d
= II(d
, a
, b
, c
, M_offset_11
, 10, T
[61]);
7630 c
= II(c
, d
, a
, b
, M_offset_2
, 15, T
[62]);
7631 b
= II(b
, c
, d
, a
, M_offset_9
, 21, T
[63]);
7633 // Intermediate hash value
7634 H
[0] = (H
[0] + a
) | 0;
7635 H
[1] = (H
[1] + b
) | 0;
7636 H
[2] = (H
[2] + c
) | 0;
7637 H
[3] = (H
[3] + d
) | 0;
7640 _doFinalize: function () {
7642 var data
= this._data
;
7643 var dataWords
= data
.words
;
7645 var nBitsTotal
= this._nDataBytes
* 8;
7646 var nBitsLeft
= data
.sigBytes
* 8;
7649 dataWords
[nBitsLeft
>>> 5] |= 0x80 << (24 - nBitsLeft
% 32);
7651 var nBitsTotalH
= Math
.floor(nBitsTotal
/ 0x100000000);
7652 var nBitsTotalL
= nBitsTotal
;
7653 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 15] = (
7654 (((nBitsTotalH
<< 8) | (nBitsTotalH
>>> 24)) & 0x00ff00ff) |
7655 (((nBitsTotalH
<< 24) | (nBitsTotalH
>>> 8)) & 0xff00ff00)
7657 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 14] = (
7658 (((nBitsTotalL
<< 8) | (nBitsTotalL
>>> 24)) & 0x00ff00ff) |
7659 (((nBitsTotalL
<< 24) | (nBitsTotalL
>>> 8)) & 0xff00ff00)
7662 data
.sigBytes
= (dataWords
.length
+ 1) * 4;
7664 // Hash final blocks
7668 var hash
= this._hash
;
7672 for (var i
= 0; i
< 4; i
++) {
7676 H
[i
] = (((H_i
<< 8) | (H_i
>>> 24)) & 0x00ff00ff) |
7677 (((H_i
<< 24) | (H_i
>>> 8)) & 0xff00ff00);
7680 // Return final computed hash
7684 clone: function () {
7685 var clone
= Hasher
.clone
.call(this);
7686 clone
._hash
= this._hash
.clone();
7692 function FF(a
, b
, c
, d
, x
, s
, t
) {
7693 var n
= a
+ ((b
& c
) | (~b
& d
)) + x
+ t
;
7694 return ((n
<< s
) | (n
>>> (32 - s
))) + b
;
7697 function GG(a
, b
, c
, d
, x
, s
, t
) {
7698 var n
= a
+ ((b
& d
) | (c
& ~d
)) + x
+ t
;
7699 return ((n
<< s
) | (n
>>> (32 - s
))) + b
;
7702 function HH(a
, b
, c
, d
, x
, s
, t
) {
7703 var n
= a
+ (b
^ c
^ d
) + x
+ t
;
7704 return ((n
<< s
) | (n
>>> (32 - s
))) + b
;
7707 function II(a
, b
, c
, d
, x
, s
, t
) {
7708 var n
= a
+ (c
^ (b
| ~d
)) + x
+ t
;
7709 return ((n
<< s
) | (n
>>> (32 - s
))) + b
;
7713 * Shortcut function to the hasher's object interface.
7715 * @param {WordArray|string} message The message to hash.
7717 * @return {WordArray} The hash.
7723 * var hash = CryptoJS.MD5('message');
7724 * var hash = CryptoJS.MD5(wordArray);
7726 C
.MD5
= Hasher
._createHelper(MD5
);
7729 * Shortcut function to the HMAC's object interface.
7731 * @param {WordArray|string} message The message to hash.
7732 * @param {WordArray|string} key The secret key.
7734 * @return {WordArray} The HMAC.
7740 * var hmac = CryptoJS.HmacMD5(message, key);
7742 C
.HmacMD5
= Hasher
._createHmacHelper(MD5
);
7746 return CryptoJS
.MD5
;
7749 },{"./core":31}],40:[function(_dereq_
,module
,exports
){
7750 ;(function (root
, factory
, undef
) {
7751 if (typeof exports
=== "object") {
7753 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
7755 else if (typeof define
=== "function" && define
.amd
) {
7757 define(["./core", "./cipher-core"], factory
);
7761 factory(root
.CryptoJS
);
7763 }(this, function (CryptoJS
) {
7766 * Cipher Feedback block mode.
7768 CryptoJS
.mode
.CFB
= (function () {
7769 var CFB
= CryptoJS
.lib
.BlockCipherMode
.extend();
7771 CFB
.Encryptor
= CFB
.extend({
7772 processBlock: function (words
, offset
) {
7774 var cipher
= this._cipher
;
7775 var blockSize
= cipher
.blockSize
;
7777 generateKeystreamAndEncrypt
.call(this, words
, offset
, blockSize
, cipher
);
7779 // Remember this block to use with next block
7780 this._prevBlock
= words
.slice(offset
, offset
+ blockSize
);
7784 CFB
.Decryptor
= CFB
.extend({
7785 processBlock: function (words
, offset
) {
7787 var cipher
= this._cipher
;
7788 var blockSize
= cipher
.blockSize
;
7790 // Remember this block to use with next block
7791 var thisBlock
= words
.slice(offset
, offset
+ blockSize
);
7793 generateKeystreamAndEncrypt
.call(this, words
, offset
, blockSize
, cipher
);
7795 // This block becomes the previous block
7796 this._prevBlock
= thisBlock
;
7800 function generateKeystreamAndEncrypt(words
, offset
, blockSize
, cipher
) {
7804 // Generate keystream
7806 var keystream
= iv
.slice(0);
7808 // Remove IV for subsequent blocks
7809 this._iv
= undefined;
7811 var keystream
= this._prevBlock
;
7813 cipher
.encryptBlock(keystream
, 0);
7816 for (var i
= 0; i
< blockSize
; i
++) {
7817 words
[offset
+ i
] ^= keystream
[i
];
7825 return CryptoJS
.mode
.CFB
;
7828 },{"./cipher-core":30,"./core":31}],41:[function(_dereq_
,module
,exports
){
7829 ;(function (root
, factory
, undef
) {
7830 if (typeof exports
=== "object") {
7832 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
7834 else if (typeof define
=== "function" && define
.amd
) {
7836 define(["./core", "./cipher-core"], factory
);
7840 factory(root
.CryptoJS
);
7842 }(this, function (CryptoJS
) {
7845 * Counter block mode compatible with Dr Brian Gladman fileenc.c
7846 * derived from CryptoJS.mode.CTR
7847 * Jan Hruby jhruby.web@gmail.com
7849 CryptoJS
.mode
.CTRGladman
= (function () {
7850 var CTRGladman
= CryptoJS
.lib
.BlockCipherMode
.extend();
7852 function incWord(word
)
7854 if (((word
>> 24) & 0xff) === 0xff) { //overflow
7855 var b1
= (word
>> 16)&0xff;
7856 var b2
= (word
>> 8)&0xff;
7857 var b3
= word
& 0xff;
7859 if (b1
=== 0xff) // overflow b1
7891 word
+= (0x01 << 24);
7896 function incCounter(counter
)
7898 if ((counter
[0] = incWord(counter
[0])) === 0)
7900 // encr_data in fileenc.c from Dr Brian Gladman's counts only with DWORD j < 8
7901 counter
[1] = incWord(counter
[1]);
7906 var Encryptor
= CTRGladman
.Encryptor
= CTRGladman
.extend({
7907 processBlock: function (words
, offset
) {
7909 var cipher
= this._cipher
7910 var blockSize
= cipher
.blockSize
;
7912 var counter
= this._counter
;
7914 // Generate keystream
7916 counter
= this._counter
= iv
.slice(0);
7918 // Remove IV for subsequent blocks
7919 this._iv
= undefined;
7922 incCounter(counter
);
7924 var keystream
= counter
.slice(0);
7925 cipher
.encryptBlock(keystream
, 0);
7928 for (var i
= 0; i
< blockSize
; i
++) {
7929 words
[offset
+ i
] ^= keystream
[i
];
7934 CTRGladman
.Decryptor
= Encryptor
;
7942 return CryptoJS
.mode
.CTRGladman
;
7945 },{"./cipher-core":30,"./core":31}],42:[function(_dereq_
,module
,exports
){
7946 ;(function (root
, factory
, undef
) {
7947 if (typeof exports
=== "object") {
7949 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
7951 else if (typeof define
=== "function" && define
.amd
) {
7953 define(["./core", "./cipher-core"], factory
);
7957 factory(root
.CryptoJS
);
7959 }(this, function (CryptoJS
) {
7962 * Counter block mode.
7964 CryptoJS
.mode
.CTR
= (function () {
7965 var CTR
= CryptoJS
.lib
.BlockCipherMode
.extend();
7967 var Encryptor
= CTR
.Encryptor
= CTR
.extend({
7968 processBlock: function (words
, offset
) {
7970 var cipher
= this._cipher
7971 var blockSize
= cipher
.blockSize
;
7973 var counter
= this._counter
;
7975 // Generate keystream
7977 counter
= this._counter
= iv
.slice(0);
7979 // Remove IV for subsequent blocks
7980 this._iv
= undefined;
7982 var keystream
= counter
.slice(0);
7983 cipher
.encryptBlock(keystream
, 0);
7985 // Increment counter
7986 counter
[blockSize
- 1] = (counter
[blockSize
- 1] + 1) | 0
7989 for (var i
= 0; i
< blockSize
; i
++) {
7990 words
[offset
+ i
] ^= keystream
[i
];
7995 CTR
.Decryptor
= Encryptor
;
8001 return CryptoJS
.mode
.CTR
;
8004 },{"./cipher-core":30,"./core":31}],43:[function(_dereq_
,module
,exports
){
8005 ;(function (root
, factory
, undef
) {
8006 if (typeof exports
=== "object") {
8008 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8010 else if (typeof define
=== "function" && define
.amd
) {
8012 define(["./core", "./cipher-core"], factory
);
8016 factory(root
.CryptoJS
);
8018 }(this, function (CryptoJS
) {
8021 * Electronic Codebook block mode.
8023 CryptoJS
.mode
.ECB
= (function () {
8024 var ECB
= CryptoJS
.lib
.BlockCipherMode
.extend();
8026 ECB
.Encryptor
= ECB
.extend({
8027 processBlock: function (words
, offset
) {
8028 this._cipher
.encryptBlock(words
, offset
);
8032 ECB
.Decryptor
= ECB
.extend({
8033 processBlock: function (words
, offset
) {
8034 this._cipher
.decryptBlock(words
, offset
);
8042 return CryptoJS
.mode
.ECB
;
8045 },{"./cipher-core":30,"./core":31}],44:[function(_dereq_
,module
,exports
){
8046 ;(function (root
, factory
, undef
) {
8047 if (typeof exports
=== "object") {
8049 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8051 else if (typeof define
=== "function" && define
.amd
) {
8053 define(["./core", "./cipher-core"], factory
);
8057 factory(root
.CryptoJS
);
8059 }(this, function (CryptoJS
) {
8062 * Output Feedback block mode.
8064 CryptoJS
.mode
.OFB
= (function () {
8065 var OFB
= CryptoJS
.lib
.BlockCipherMode
.extend();
8067 var Encryptor
= OFB
.Encryptor
= OFB
.extend({
8068 processBlock: function (words
, offset
) {
8070 var cipher
= this._cipher
8071 var blockSize
= cipher
.blockSize
;
8073 var keystream
= this._keystream
;
8075 // Generate keystream
8077 keystream
= this._keystream
= iv
.slice(0);
8079 // Remove IV for subsequent blocks
8080 this._iv
= undefined;
8082 cipher
.encryptBlock(keystream
, 0);
8085 for (var i
= 0; i
< blockSize
; i
++) {
8086 words
[offset
+ i
] ^= keystream
[i
];
8091 OFB
.Decryptor
= Encryptor
;
8097 return CryptoJS
.mode
.OFB
;
8100 },{"./cipher-core":30,"./core":31}],45:[function(_dereq_
,module
,exports
){
8101 ;(function (root
, factory
, undef
) {
8102 if (typeof exports
=== "object") {
8104 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8106 else if (typeof define
=== "function" && define
.amd
) {
8108 define(["./core", "./cipher-core"], factory
);
8112 factory(root
.CryptoJS
);
8114 }(this, function (CryptoJS
) {
8117 * ANSI X.923 padding strategy.
8119 CryptoJS
.pad
.AnsiX923
= {
8120 pad: function (data
, blockSize
) {
8122 var dataSigBytes
= data
.sigBytes
;
8123 var blockSizeBytes
= blockSize
* 4;
8125 // Count padding bytes
8126 var nPaddingBytes
= blockSizeBytes
- dataSigBytes
% blockSizeBytes
;
8128 // Compute last byte position
8129 var lastBytePos
= dataSigBytes
+ nPaddingBytes
- 1;
8133 data
.words
[lastBytePos
>>> 2] |= nPaddingBytes
<< (24 - (lastBytePos
% 4) * 8);
8134 data
.sigBytes
+= nPaddingBytes
;
8137 unpad: function (data
) {
8138 // Get number of padding bytes from last byte
8139 var nPaddingBytes
= data
.words
[(data
.sigBytes
- 1) >>> 2] & 0xff;
8142 data
.sigBytes
-= nPaddingBytes
;
8147 return CryptoJS
.pad
.Ansix923
;
8150 },{"./cipher-core":30,"./core":31}],46:[function(_dereq_
,module
,exports
){
8151 ;(function (root
, factory
, undef
) {
8152 if (typeof exports
=== "object") {
8154 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8156 else if (typeof define
=== "function" && define
.amd
) {
8158 define(["./core", "./cipher-core"], factory
);
8162 factory(root
.CryptoJS
);
8164 }(this, function (CryptoJS
) {
8167 * ISO 10126 padding strategy.
8169 CryptoJS
.pad
.Iso10126
= {
8170 pad: function (data
, blockSize
) {
8172 var blockSizeBytes
= blockSize
* 4;
8174 // Count padding bytes
8175 var nPaddingBytes
= blockSizeBytes
- data
.sigBytes
% blockSizeBytes
;
8178 data
.concat(CryptoJS
.lib
.WordArray
.random(nPaddingBytes
- 1)).
8179 concat(CryptoJS
.lib
.WordArray
.create([nPaddingBytes
<< 24], 1));
8182 unpad: function (data
) {
8183 // Get number of padding bytes from last byte
8184 var nPaddingBytes
= data
.words
[(data
.sigBytes
- 1) >>> 2] & 0xff;
8187 data
.sigBytes
-= nPaddingBytes
;
8192 return CryptoJS
.pad
.Iso10126
;
8195 },{"./cipher-core":30,"./core":31}],47:[function(_dereq_
,module
,exports
){
8196 ;(function (root
, factory
, undef
) {
8197 if (typeof exports
=== "object") {
8199 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8201 else if (typeof define
=== "function" && define
.amd
) {
8203 define(["./core", "./cipher-core"], factory
);
8207 factory(root
.CryptoJS
);
8209 }(this, function (CryptoJS
) {
8212 * ISO/IEC 9797-1 Padding Method 2.
8214 CryptoJS
.pad
.Iso97971
= {
8215 pad: function (data
, blockSize
) {
8217 data
.concat(CryptoJS
.lib
.WordArray
.create([0x80000000], 1));
8219 // Zero pad the rest
8220 CryptoJS
.pad
.ZeroPadding
.pad(data
, blockSize
);
8223 unpad: function (data
) {
8224 // Remove zero padding
8225 CryptoJS
.pad
.ZeroPadding
.unpad(data
);
8227 // Remove one more byte -- the 0x80 byte
8233 return CryptoJS
.pad
.Iso97971
;
8236 },{"./cipher-core":30,"./core":31}],48:[function(_dereq_
,module
,exports
){
8237 ;(function (root
, factory
, undef
) {
8238 if (typeof exports
=== "object") {
8240 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8242 else if (typeof define
=== "function" && define
.amd
) {
8244 define(["./core", "./cipher-core"], factory
);
8248 factory(root
.CryptoJS
);
8250 }(this, function (CryptoJS
) {
8253 * A noop padding strategy.
8255 CryptoJS
.pad
.NoPadding
= {
8259 unpad: function () {
8264 return CryptoJS
.pad
.NoPadding
;
8267 },{"./cipher-core":30,"./core":31}],49:[function(_dereq_
,module
,exports
){
8268 ;(function (root
, factory
, undef
) {
8269 if (typeof exports
=== "object") {
8271 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./cipher-core"));
8273 else if (typeof define
=== "function" && define
.amd
) {
8275 define(["./core", "./cipher-core"], factory
);
8279 factory(root
.CryptoJS
);
8281 }(this, function (CryptoJS
) {
8284 * Zero padding strategy.
8286 CryptoJS
.pad
.ZeroPadding
= {
8287 pad: function (data
, blockSize
) {
8289 var blockSizeBytes
= blockSize
* 4;
8293 data
.sigBytes
+= blockSizeBytes
- ((data
.sigBytes
% blockSizeBytes
) || blockSizeBytes
);
8296 unpad: function (data
) {
8298 var dataWords
= data
.words
;
8301 var i
= data
.sigBytes
- 1;
8302 while (!((dataWords
[i
>>> 2] >>> (24 - (i
% 4) * 8)) & 0xff)) {
8305 data
.sigBytes
= i
+ 1;
8310 return CryptoJS
.pad
.ZeroPadding
;
8313 },{"./cipher-core":30,"./core":31}],50:[function(_dereq_
,module
,exports
){
8314 ;(function (root
, factory
, undef
) {
8315 if (typeof exports
=== "object") {
8317 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./sha1"), _dereq_("./hmac"));
8319 else if (typeof define
=== "function" && define
.amd
) {
8321 define(["./core", "./sha1", "./hmac"], factory
);
8325 factory(root
.CryptoJS
);
8327 }(this, function (CryptoJS
) {
8333 var Base
= C_lib
.Base
;
8334 var WordArray
= C_lib
.WordArray
;
8335 var C_algo
= C
.algo
;
8336 var SHA1
= C_algo
.SHA1
;
8337 var HMAC
= C_algo
.HMAC
;
8340 * Password-Based Key Derivation Function 2 algorithm.
8342 var PBKDF2
= C_algo
.PBKDF2
= Base
.extend({
8344 * Configuration options.
8346 * @property {number} keySize The key size in words to generate. Default: 4 (128 bits)
8347 * @property {Hasher} hasher The hasher to use. Default: SHA1
8348 * @property {number} iterations The number of iterations to perform. Default: 1
8357 * Initializes a newly created key derivation function.
8359 * @param {Object} cfg (Optional) The configuration options to use for the derivation.
8363 * var kdf = CryptoJS.algo.PBKDF2.create();
8364 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8 });
8365 * var kdf = CryptoJS.algo.PBKDF2.create({ keySize: 8, iterations: 1000 });
8367 init: function (cfg
) {
8368 this.cfg
= this.cfg
.extend(cfg
);
8372 * Computes the Password-Based Key Derivation Function 2.
8374 * @param {WordArray|string} password The password.
8375 * @param {WordArray|string} salt A salt.
8377 * @return {WordArray} The derived key.
8381 * var key = kdf.compute(password, salt);
8383 compute: function (password
, salt
) {
8388 var hmac
= HMAC
.create(cfg
.hasher
, password
);
8391 var derivedKey
= WordArray
.create();
8392 var blockIndex
= WordArray
.create([0x00000001]);
8395 var derivedKeyWords
= derivedKey
.words
;
8396 var blockIndexWords
= blockIndex
.words
;
8397 var keySize
= cfg
.keySize
;
8398 var iterations
= cfg
.iterations
;
8401 while (derivedKeyWords
.length
< keySize
) {
8402 var block
= hmac
.update(salt
).finalize(blockIndex
);
8406 var blockWords
= block
.words
;
8407 var blockWordsLength
= blockWords
.length
;
8410 var intermediate
= block
;
8411 for (var i
= 1; i
< iterations
; i
++) {
8412 intermediate
= hmac
.finalize(intermediate
);
8416 var intermediateWords
= intermediate
.words
;
8418 // XOR intermediate with block
8419 for (var j
= 0; j
< blockWordsLength
; j
++) {
8420 blockWords
[j
] ^= intermediateWords
[j
];
8424 derivedKey
.concat(block
);
8425 blockIndexWords
[0]++;
8427 derivedKey
.sigBytes
= keySize
* 4;
8434 * Computes the Password-Based Key Derivation Function 2.
8436 * @param {WordArray|string} password The password.
8437 * @param {WordArray|string} salt A salt.
8438 * @param {Object} cfg (Optional) The configuration options to use for this computation.
8440 * @return {WordArray} The derived key.
8446 * var key = CryptoJS.PBKDF2(password, salt);
8447 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8 });
8448 * var key = CryptoJS.PBKDF2(password, salt, { keySize: 8, iterations: 1000 });
8450 C
.PBKDF2 = function (password
, salt
, cfg
) {
8451 return PBKDF2
.create(cfg
).compute(password
, salt
);
8456 return CryptoJS
.PBKDF2
;
8459 },{"./core":31,"./hmac":36,"./sha1":55}],51:[function(_dereq_
,module
,exports
){
8460 ;(function (root
, factory
, undef
) {
8461 if (typeof exports
=== "object") {
8463 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./enc-base64"), _dereq_("./md5"), _dereq_("./evpkdf"), _dereq_("./cipher-core"));
8465 else if (typeof define
=== "function" && define
.amd
) {
8467 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory
);
8471 factory(root
.CryptoJS
);
8473 }(this, function (CryptoJS
) {
8479 var StreamCipher
= C_lib
.StreamCipher
;
8480 var C_algo
= C
.algo
;
8488 * Rabbit stream cipher algorithm.
8490 * This is a legacy version that neglected to convert the key to little-endian.
8491 * This error doesn't affect the cipher's security,
8492 * but it does affect its compatibility with other implementations.
8494 var RabbitLegacy
= C_algo
.RabbitLegacy
= StreamCipher
.extend({
8495 _doReset: function () {
8497 var K
= this._key
.words
;
8498 var iv
= this.cfg
.iv
;
8500 // Generate initial state values
8502 K
[0], (K
[3] << 16) | (K
[2] >>> 16),
8503 K
[1], (K
[0] << 16) | (K
[3] >>> 16),
8504 K
[2], (K
[1] << 16) | (K
[0] >>> 16),
8505 K
[3], (K
[2] << 16) | (K
[1] >>> 16)
8508 // Generate initial counter values
8510 (K
[2] << 16) | (K
[2] >>> 16), (K
[0] & 0xffff0000) | (K
[1] & 0x0000ffff),
8511 (K
[3] << 16) | (K
[3] >>> 16), (K
[1] & 0xffff0000) | (K
[2] & 0x0000ffff),
8512 (K
[0] << 16) | (K
[0] >>> 16), (K
[2] & 0xffff0000) | (K
[3] & 0x0000ffff),
8513 (K
[1] << 16) | (K
[1] >>> 16), (K
[3] & 0xffff0000) | (K
[0] & 0x0000ffff)
8519 // Iterate the system four times
8520 for (var i
= 0; i
< 4; i
++) {
8521 nextState
.call(this);
8524 // Modify the counters
8525 for (var i
= 0; i
< 8; i
++) {
8526 C
[i
] ^= X
[(i
+ 4) & 7];
8536 // Generate four subvectors
8537 var i0
= (((IV_0
<< 8) | (IV_0
>>> 24)) & 0x00ff00ff) | (((IV_0
<< 24) | (IV_0
>>> 8)) & 0xff00ff00);
8538 var i2
= (((IV_1
<< 8) | (IV_1
>>> 24)) & 0x00ff00ff) | (((IV_1
<< 24) | (IV_1
>>> 8)) & 0xff00ff00);
8539 var i1
= (i0
>>> 16) | (i2
& 0xffff0000);
8540 var i3
= (i2
<< 16) | (i0
& 0x0000ffff);
8542 // Modify counter values
8552 // Iterate the system four times
8553 for (var i
= 0; i
< 4; i
++) {
8554 nextState
.call(this);
8559 _doProcessBlock: function (M
, offset
) {
8563 // Iterate the system
8564 nextState
.call(this);
8566 // Generate four keystream words
8567 S
[0] = X
[0] ^ (X
[5] >>> 16) ^ (X
[3] << 16);
8568 S
[1] = X
[2] ^ (X
[7] >>> 16) ^ (X
[5] << 16);
8569 S
[2] = X
[4] ^ (X
[1] >>> 16) ^ (X
[7] << 16);
8570 S
[3] = X
[6] ^ (X
[3] >>> 16) ^ (X
[1] << 16);
8572 for (var i
= 0; i
< 4; i
++) {
8574 S
[i
] = (((S
[i
] << 8) | (S
[i
] >>> 24)) & 0x00ff00ff) |
8575 (((S
[i
] << 24) | (S
[i
] >>> 8)) & 0xff00ff00);
8578 M
[offset
+ i
] ^= S
[i
];
8587 function nextState() {
8592 // Save old counter values
8593 for (var i
= 0; i
< 8; i
++) {
8597 // Calculate new counter values
8598 C
[0] = (C
[0] + 0x4d34d34d + this._b
) | 0;
8599 C
[1] = (C
[1] + 0xd34d34d3 + ((C
[0] >>> 0) < (C_
[0] >>> 0) ? 1 : 0)) | 0;
8600 C
[2] = (C
[2] + 0x34d34d34 + ((C
[1] >>> 0) < (C_
[1] >>> 0) ? 1 : 0)) | 0;
8601 C
[3] = (C
[3] + 0x4d34d34d + ((C
[2] >>> 0) < (C_
[2] >>> 0) ? 1 : 0)) | 0;
8602 C
[4] = (C
[4] + 0xd34d34d3 + ((C
[3] >>> 0) < (C_
[3] >>> 0) ? 1 : 0)) | 0;
8603 C
[5] = (C
[5] + 0x34d34d34 + ((C
[4] >>> 0) < (C_
[4] >>> 0) ? 1 : 0)) | 0;
8604 C
[6] = (C
[6] + 0x4d34d34d + ((C
[5] >>> 0) < (C_
[5] >>> 0) ? 1 : 0)) | 0;
8605 C
[7] = (C
[7] + 0xd34d34d3 + ((C
[6] >>> 0) < (C_
[6] >>> 0) ? 1 : 0)) | 0;
8606 this._b
= (C
[7] >>> 0) < (C_
[7] >>> 0) ? 1 : 0;
8608 // Calculate the g-values
8609 for (var i
= 0; i
< 8; i
++) {
8610 var gx
= X
[i
] + C
[i
];
8612 // Construct high and low argument for squaring
8613 var ga
= gx
& 0xffff;
8616 // Calculate high and low result of squaring
8617 var gh
= ((((ga
* ga
) >>> 17) + ga
* gb
) >>> 15) + gb
* gb
;
8618 var gl
= (((gx
& 0xffff0000) * gx
) | 0) + (((gx
& 0x0000ffff) * gx
) | 0);
8624 // Calculate new state values
8625 X
[0] = (G
[0] + ((G
[7] << 16) | (G
[7] >>> 16)) + ((G
[6] << 16) | (G
[6] >>> 16))) | 0;
8626 X
[1] = (G
[1] + ((G
[0] << 8) | (G
[0] >>> 24)) + G
[7]) | 0;
8627 X
[2] = (G
[2] + ((G
[1] << 16) | (G
[1] >>> 16)) + ((G
[0] << 16) | (G
[0] >>> 16))) | 0;
8628 X
[3] = (G
[3] + ((G
[2] << 8) | (G
[2] >>> 24)) + G
[1]) | 0;
8629 X
[4] = (G
[4] + ((G
[3] << 16) | (G
[3] >>> 16)) + ((G
[2] << 16) | (G
[2] >>> 16))) | 0;
8630 X
[5] = (G
[5] + ((G
[4] << 8) | (G
[4] >>> 24)) + G
[3]) | 0;
8631 X
[6] = (G
[6] + ((G
[5] << 16) | (G
[5] >>> 16)) + ((G
[4] << 16) | (G
[4] >>> 16))) | 0;
8632 X
[7] = (G
[7] + ((G
[6] << 8) | (G
[6] >>> 24)) + G
[5]) | 0;
8636 * Shortcut functions to the cipher's object interface.
8640 * var ciphertext = CryptoJS.RabbitLegacy.encrypt(message, key, cfg);
8641 * var plaintext = CryptoJS.RabbitLegacy.decrypt(ciphertext, key, cfg);
8643 C
.RabbitLegacy
= StreamCipher
._createHelper(RabbitLegacy
);
8647 return CryptoJS
.RabbitLegacy
;
8650 },{"./cipher-core":30,"./core":31,"./enc-base64":32,"./evpkdf":34,"./md5":39}],52:[function(_dereq_
,module
,exports
){
8651 ;(function (root
, factory
, undef
) {
8652 if (typeof exports
=== "object") {
8654 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./enc-base64"), _dereq_("./md5"), _dereq_("./evpkdf"), _dereq_("./cipher-core"));
8656 else if (typeof define
=== "function" && define
.amd
) {
8658 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory
);
8662 factory(root
.CryptoJS
);
8664 }(this, function (CryptoJS
) {
8670 var StreamCipher
= C_lib
.StreamCipher
;
8671 var C_algo
= C
.algo
;
8679 * Rabbit stream cipher algorithm
8681 var Rabbit
= C_algo
.Rabbit
= StreamCipher
.extend({
8682 _doReset: function () {
8684 var K
= this._key
.words
;
8685 var iv
= this.cfg
.iv
;
8688 for (var i
= 0; i
< 4; i
++) {
8689 K
[i
] = (((K
[i
] << 8) | (K
[i
] >>> 24)) & 0x00ff00ff) |
8690 (((K
[i
] << 24) | (K
[i
] >>> 8)) & 0xff00ff00);
8693 // Generate initial state values
8695 K
[0], (K
[3] << 16) | (K
[2] >>> 16),
8696 K
[1], (K
[0] << 16) | (K
[3] >>> 16),
8697 K
[2], (K
[1] << 16) | (K
[0] >>> 16),
8698 K
[3], (K
[2] << 16) | (K
[1] >>> 16)
8701 // Generate initial counter values
8703 (K
[2] << 16) | (K
[2] >>> 16), (K
[0] & 0xffff0000) | (K
[1] & 0x0000ffff),
8704 (K
[3] << 16) | (K
[3] >>> 16), (K
[1] & 0xffff0000) | (K
[2] & 0x0000ffff),
8705 (K
[0] << 16) | (K
[0] >>> 16), (K
[2] & 0xffff0000) | (K
[3] & 0x0000ffff),
8706 (K
[1] << 16) | (K
[1] >>> 16), (K
[3] & 0xffff0000) | (K
[0] & 0x0000ffff)
8712 // Iterate the system four times
8713 for (var i
= 0; i
< 4; i
++) {
8714 nextState
.call(this);
8717 // Modify the counters
8718 for (var i
= 0; i
< 8; i
++) {
8719 C
[i
] ^= X
[(i
+ 4) & 7];
8729 // Generate four subvectors
8730 var i0
= (((IV_0
<< 8) | (IV_0
>>> 24)) & 0x00ff00ff) | (((IV_0
<< 24) | (IV_0
>>> 8)) & 0xff00ff00);
8731 var i2
= (((IV_1
<< 8) | (IV_1
>>> 24)) & 0x00ff00ff) | (((IV_1
<< 24) | (IV_1
>>> 8)) & 0xff00ff00);
8732 var i1
= (i0
>>> 16) | (i2
& 0xffff0000);
8733 var i3
= (i2
<< 16) | (i0
& 0x0000ffff);
8735 // Modify counter values
8745 // Iterate the system four times
8746 for (var i
= 0; i
< 4; i
++) {
8747 nextState
.call(this);
8752 _doProcessBlock: function (M
, offset
) {
8756 // Iterate the system
8757 nextState
.call(this);
8759 // Generate four keystream words
8760 S
[0] = X
[0] ^ (X
[5] >>> 16) ^ (X
[3] << 16);
8761 S
[1] = X
[2] ^ (X
[7] >>> 16) ^ (X
[5] << 16);
8762 S
[2] = X
[4] ^ (X
[1] >>> 16) ^ (X
[7] << 16);
8763 S
[3] = X
[6] ^ (X
[3] >>> 16) ^ (X
[1] << 16);
8765 for (var i
= 0; i
< 4; i
++) {
8767 S
[i
] = (((S
[i
] << 8) | (S
[i
] >>> 24)) & 0x00ff00ff) |
8768 (((S
[i
] << 24) | (S
[i
] >>> 8)) & 0xff00ff00);
8771 M
[offset
+ i
] ^= S
[i
];
8780 function nextState() {
8785 // Save old counter values
8786 for (var i
= 0; i
< 8; i
++) {
8790 // Calculate new counter values
8791 C
[0] = (C
[0] + 0x4d34d34d + this._b
) | 0;
8792 C
[1] = (C
[1] + 0xd34d34d3 + ((C
[0] >>> 0) < (C_
[0] >>> 0) ? 1 : 0)) | 0;
8793 C
[2] = (C
[2] + 0x34d34d34 + ((C
[1] >>> 0) < (C_
[1] >>> 0) ? 1 : 0)) | 0;
8794 C
[3] = (C
[3] + 0x4d34d34d + ((C
[2] >>> 0) < (C_
[2] >>> 0) ? 1 : 0)) | 0;
8795 C
[4] = (C
[4] + 0xd34d34d3 + ((C
[3] >>> 0) < (C_
[3] >>> 0) ? 1 : 0)) | 0;
8796 C
[5] = (C
[5] + 0x34d34d34 + ((C
[4] >>> 0) < (C_
[4] >>> 0) ? 1 : 0)) | 0;
8797 C
[6] = (C
[6] + 0x4d34d34d + ((C
[5] >>> 0) < (C_
[5] >>> 0) ? 1 : 0)) | 0;
8798 C
[7] = (C
[7] + 0xd34d34d3 + ((C
[6] >>> 0) < (C_
[6] >>> 0) ? 1 : 0)) | 0;
8799 this._b
= (C
[7] >>> 0) < (C_
[7] >>> 0) ? 1 : 0;
8801 // Calculate the g-values
8802 for (var i
= 0; i
< 8; i
++) {
8803 var gx
= X
[i
] + C
[i
];
8805 // Construct high and low argument for squaring
8806 var ga
= gx
& 0xffff;
8809 // Calculate high and low result of squaring
8810 var gh
= ((((ga
* ga
) >>> 17) + ga
* gb
) >>> 15) + gb
* gb
;
8811 var gl
= (((gx
& 0xffff0000) * gx
) | 0) + (((gx
& 0x0000ffff) * gx
) | 0);
8817 // Calculate new state values
8818 X
[0] = (G
[0] + ((G
[7] << 16) | (G
[7] >>> 16)) + ((G
[6] << 16) | (G
[6] >>> 16))) | 0;
8819 X
[1] = (G
[1] + ((G
[0] << 8) | (G
[0] >>> 24)) + G
[7]) | 0;
8820 X
[2] = (G
[2] + ((G
[1] << 16) | (G
[1] >>> 16)) + ((G
[0] << 16) | (G
[0] >>> 16))) | 0;
8821 X
[3] = (G
[3] + ((G
[2] << 8) | (G
[2] >>> 24)) + G
[1]) | 0;
8822 X
[4] = (G
[4] + ((G
[3] << 16) | (G
[3] >>> 16)) + ((G
[2] << 16) | (G
[2] >>> 16))) | 0;
8823 X
[5] = (G
[5] + ((G
[4] << 8) | (G
[4] >>> 24)) + G
[3]) | 0;
8824 X
[6] = (G
[6] + ((G
[5] << 16) | (G
[5] >>> 16)) + ((G
[4] << 16) | (G
[4] >>> 16))) | 0;
8825 X
[7] = (G
[7] + ((G
[6] << 8) | (G
[6] >>> 24)) + G
[5]) | 0;
8829 * Shortcut functions to the cipher's object interface.
8833 * var ciphertext = CryptoJS.Rabbit.encrypt(message, key, cfg);
8834 * var plaintext = CryptoJS.Rabbit.decrypt(ciphertext, key, cfg);
8836 C
.Rabbit
= StreamCipher
._createHelper(Rabbit
);
8840 return CryptoJS
.Rabbit
;
8843 },{"./cipher-core":30,"./core":31,"./enc-base64":32,"./evpkdf":34,"./md5":39}],53:[function(_dereq_
,module
,exports
){
8844 ;(function (root
, factory
, undef
) {
8845 if (typeof exports
=== "object") {
8847 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./enc-base64"), _dereq_("./md5"), _dereq_("./evpkdf"), _dereq_("./cipher-core"));
8849 else if (typeof define
=== "function" && define
.amd
) {
8851 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory
);
8855 factory(root
.CryptoJS
);
8857 }(this, function (CryptoJS
) {
8863 var StreamCipher
= C_lib
.StreamCipher
;
8864 var C_algo
= C
.algo
;
8867 * RC4 stream cipher algorithm.
8869 var RC4
= C_algo
.RC4
= StreamCipher
.extend({
8870 _doReset: function () {
8872 var key
= this._key
;
8873 var keyWords
= key
.words
;
8874 var keySigBytes
= key
.sigBytes
;
8877 var S
= this._S
= [];
8878 for (var i
= 0; i
< 256; i
++) {
8883 for (var i
= 0, j
= 0; i
< 256; i
++) {
8884 var keyByteIndex
= i
% keySigBytes
;
8885 var keyByte
= (keyWords
[keyByteIndex
>>> 2] >>> (24 - (keyByteIndex
% 4) * 8)) & 0xff;
8887 j
= (j
+ S
[i
] + keyByte
) % 256;
8896 this._i
= this._j
= 0;
8899 _doProcessBlock: function (M
, offset
) {
8900 M
[offset
] ^= generateKeystreamWord
.call(this);
8908 function generateKeystreamWord() {
8914 // Generate keystream word
8915 var keystreamWord
= 0;
8916 for (var n
= 0; n
< 4; n
++) {
8918 j
= (j
+ S
[i
]) % 256;
8925 keystreamWord
|= S
[(S
[i
] + S
[j
]) % 256] << (24 - n
* 8);
8932 return keystreamWord
;
8936 * Shortcut functions to the cipher's object interface.
8940 * var ciphertext = CryptoJS.RC4.encrypt(message, key, cfg);
8941 * var plaintext = CryptoJS.RC4.decrypt(ciphertext, key, cfg);
8943 C
.RC4
= StreamCipher
._createHelper(RC4
);
8946 * Modified RC4 stream cipher algorithm.
8948 var RC4Drop
= C_algo
.RC4Drop
= RC4
.extend({
8950 * Configuration options.
8952 * @property {number} drop The number of keystream words to drop. Default 192
8954 cfg: RC4
.cfg
.extend({
8958 _doReset: function () {
8959 RC4
._doReset
.call(this);
8962 for (var i
= this.cfg
.drop
; i
> 0; i
--) {
8963 generateKeystreamWord
.call(this);
8969 * Shortcut functions to the cipher's object interface.
8973 * var ciphertext = CryptoJS.RC4Drop.encrypt(message, key, cfg);
8974 * var plaintext = CryptoJS.RC4Drop.decrypt(ciphertext, key, cfg);
8976 C
.RC4Drop
= StreamCipher
._createHelper(RC4Drop
);
8980 return CryptoJS
.RC4
;
8983 },{"./cipher-core":30,"./core":31,"./enc-base64":32,"./evpkdf":34,"./md5":39}],54:[function(_dereq_
,module
,exports
){
8984 ;(function (root
, factory
) {
8985 if (typeof exports
=== "object") {
8987 module
.exports
= exports
= factory(_dereq_("./core"));
8989 else if (typeof define
=== "function" && define
.amd
) {
8991 define(["./core"], factory
);
8995 factory(root
.CryptoJS
);
8997 }(this, function (CryptoJS
) {
9000 (c) 2012 by Cédric Mesnil. All rights reserved.
9002 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
9004 - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9005 - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9007 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
9014 var WordArray
= C_lib
.WordArray
;
9015 var Hasher
= C_lib
.Hasher
;
9016 var C_algo
= C
.algo
;
9019 var _zl
= WordArray
.create([
9020 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
9021 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8,
9022 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12,
9023 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2,
9024 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]);
9025 var _zr
= WordArray
.create([
9026 5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12,
9027 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2,
9028 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13,
9029 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14,
9030 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]);
9031 var _sl
= WordArray
.create([
9032 11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8,
9033 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12,
9034 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5,
9035 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12,
9036 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6 ]);
9037 var _sr
= WordArray
.create([
9038 8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6,
9039 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11,
9040 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5,
9041 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8,
9042 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11 ]);
9044 var _hl
= WordArray
.create([ 0x00000000, 0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xA953FD4E]);
9045 var _hr
= WordArray
.create([ 0x50A28BE6, 0x5C4DD124, 0x6D703EF3, 0x7A6D76E9, 0x00000000]);
9048 * RIPEMD160 hash algorithm.
9050 var RIPEMD160
= C_algo
.RIPEMD160
= Hasher
.extend({
9051 _doReset: function () {
9052 this._hash
= WordArray
.create([0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0]);
9055 _doProcessBlock: function (M
, offset
) {
9058 for (var i
= 0; i
< 16; i
++) {
9060 var offset_i
= offset
+ i
;
9061 var M_offset_i
= M
[offset_i
];
9065 (((M_offset_i
<< 8) | (M_offset_i
>>> 24)) & 0x00ff00ff) |
9066 (((M_offset_i
<< 24) | (M_offset_i
>>> 8)) & 0xff00ff00)
9070 var H
= this._hash
.words
;
9078 // Working variables
9079 var al
, bl
, cl
, dl
, el
;
9080 var ar
, br
, cr
, dr
, er
;
9089 for (var i
= 0; i
< 80; i
+= 1) {
9090 t
= (al
+ M
[offset
+zl
[i
]])|0;
9092 t
+= f1(bl
,cl
,dl
) + hl
[0];
9094 t
+= f2(bl
,cl
,dl
) + hl
[1];
9096 t
+= f3(bl
,cl
,dl
) + hl
[2];
9098 t
+= f4(bl
,cl
,dl
) + hl
[3];
9099 } else {// if (i<80) {
9100 t
+= f5(bl
,cl
,dl
) + hl
[4];
9111 t
= (ar
+ M
[offset
+zr
[i
]])|0;
9113 t
+= f5(br
,cr
,dr
) + hr
[0];
9115 t
+= f4(br
,cr
,dr
) + hr
[1];
9117 t
+= f3(br
,cr
,dr
) + hr
[2];
9119 t
+= f2(br
,cr
,dr
) + hr
[3];
9120 } else {// if (i<80) {
9121 t
+= f1(br
,cr
,dr
) + hr
[4];
9132 // Intermediate hash value
9133 t
= (H
[1] + cl
+ dr
)|0;
9134 H
[1] = (H
[2] + dl
+ er
)|0;
9135 H
[2] = (H
[3] + el
+ ar
)|0;
9136 H
[3] = (H
[4] + al
+ br
)|0;
9137 H
[4] = (H
[0] + bl
+ cr
)|0;
9141 _doFinalize: function () {
9143 var data
= this._data
;
9144 var dataWords
= data
.words
;
9146 var nBitsTotal
= this._nDataBytes
* 8;
9147 var nBitsLeft
= data
.sigBytes
* 8;
9150 dataWords
[nBitsLeft
>>> 5] |= 0x80 << (24 - nBitsLeft
% 32);
9151 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 14] = (
9152 (((nBitsTotal
<< 8) | (nBitsTotal
>>> 24)) & 0x00ff00ff) |
9153 (((nBitsTotal
<< 24) | (nBitsTotal
>>> 8)) & 0xff00ff00)
9155 data
.sigBytes
= (dataWords
.length
+ 1) * 4;
9157 // Hash final blocks
9161 var hash
= this._hash
;
9165 for (var i
= 0; i
< 5; i
++) {
9170 H
[i
] = (((H_i
<< 8) | (H_i
>>> 24)) & 0x00ff00ff) |
9171 (((H_i
<< 24) | (H_i
>>> 8)) & 0xff00ff00);
9174 // Return final computed hash
9178 clone: function () {
9179 var clone
= Hasher
.clone
.call(this);
9180 clone
._hash
= this._hash
.clone();
9187 function f1(x
, y
, z
) {
9188 return ((x
) ^ (y
) ^ (z
));
9192 function f2(x
, y
, z
) {
9193 return (((x
)&(y
)) | ((~x
)&(z
)));
9196 function f3(x
, y
, z
) {
9197 return (((x
) | (~(y
))) ^ (z
));
9200 function f4(x
, y
, z
) {
9201 return (((x
) & (z
)) | ((y
)&(~(z
))));
9204 function f5(x
, y
, z
) {
9205 return ((x
) ^ ((y
) |(~(z
))));
9209 function rotl(x
,n
) {
9210 return (x
<<n
) | (x
>>>(32-n
));
9215 * Shortcut function to the hasher's object interface.
9217 * @param {WordArray|string} message The message to hash.
9219 * @return {WordArray} The hash.
9225 * var hash = CryptoJS.RIPEMD160('message');
9226 * var hash = CryptoJS.RIPEMD160(wordArray);
9228 C
.RIPEMD160
= Hasher
._createHelper(RIPEMD160
);
9231 * Shortcut function to the HMAC's object interface.
9233 * @param {WordArray|string} message The message to hash.
9234 * @param {WordArray|string} key The secret key.
9236 * @return {WordArray} The HMAC.
9242 * var hmac = CryptoJS.HmacRIPEMD160(message, key);
9244 C
.HmacRIPEMD160
= Hasher
._createHmacHelper(RIPEMD160
);
9248 return CryptoJS
.RIPEMD160
;
9251 },{"./core":31}],55:[function(_dereq_
,module
,exports
){
9252 ;(function (root
, factory
) {
9253 if (typeof exports
=== "object") {
9255 module
.exports
= exports
= factory(_dereq_("./core"));
9257 else if (typeof define
=== "function" && define
.amd
) {
9259 define(["./core"], factory
);
9263 factory(root
.CryptoJS
);
9265 }(this, function (CryptoJS
) {
9271 var WordArray
= C_lib
.WordArray
;
9272 var Hasher
= C_lib
.Hasher
;
9273 var C_algo
= C
.algo
;
9279 * SHA-1 hash algorithm.
9281 var SHA1
= C_algo
.SHA1
= Hasher
.extend({
9282 _doReset: function () {
9283 this._hash
= new WordArray
.init([
9284 0x67452301, 0xefcdab89,
9285 0x98badcfe, 0x10325476,
9290 _doProcessBlock: function (M
, offset
) {
9292 var H
= this._hash
.words
;
9294 // Working variables
9302 for (var i
= 0; i
< 80; i
++) {
9304 W
[i
] = M
[offset
+ i
] | 0;
9306 var n
= W
[i
- 3] ^ W
[i
- 8] ^ W
[i
- 14] ^ W
[i
- 16];
9307 W
[i
] = (n
<< 1) | (n
>>> 31);
9310 var t
= ((a
<< 5) | (a
>>> 27)) + e
+ W
[i
];
9312 t
+= ((b
& c
) | (~b
& d
)) + 0x5a827999;
9313 } else if (i
< 40) {
9314 t
+= (b
^ c
^ d
) + 0x6ed9eba1;
9315 } else if (i
< 60) {
9316 t
+= ((b
& c
) | (b
& d
) | (c
& d
)) - 0x70e44324;
9317 } else /* if (i < 80) */ {
9318 t
+= (b
^ c
^ d
) - 0x359d3e2a;
9323 c
= (b
<< 30) | (b
>>> 2);
9328 // Intermediate hash value
9329 H
[0] = (H
[0] + a
) | 0;
9330 H
[1] = (H
[1] + b
) | 0;
9331 H
[2] = (H
[2] + c
) | 0;
9332 H
[3] = (H
[3] + d
) | 0;
9333 H
[4] = (H
[4] + e
) | 0;
9336 _doFinalize: function () {
9338 var data
= this._data
;
9339 var dataWords
= data
.words
;
9341 var nBitsTotal
= this._nDataBytes
* 8;
9342 var nBitsLeft
= data
.sigBytes
* 8;
9345 dataWords
[nBitsLeft
>>> 5] |= 0x80 << (24 - nBitsLeft
% 32);
9346 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 14] = Math
.floor(nBitsTotal
/ 0x100000000);
9347 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 15] = nBitsTotal
;
9348 data
.sigBytes
= dataWords
.length
* 4;
9350 // Hash final blocks
9353 // Return final computed hash
9357 clone: function () {
9358 var clone
= Hasher
.clone
.call(this);
9359 clone
._hash
= this._hash
.clone();
9366 * Shortcut function to the hasher's object interface.
9368 * @param {WordArray|string} message The message to hash.
9370 * @return {WordArray} The hash.
9376 * var hash = CryptoJS.SHA1('message');
9377 * var hash = CryptoJS.SHA1(wordArray);
9379 C
.SHA1
= Hasher
._createHelper(SHA1
);
9382 * Shortcut function to the HMAC's object interface.
9384 * @param {WordArray|string} message The message to hash.
9385 * @param {WordArray|string} key The secret key.
9387 * @return {WordArray} The HMAC.
9393 * var hmac = CryptoJS.HmacSHA1(message, key);
9395 C
.HmacSHA1
= Hasher
._createHmacHelper(SHA1
);
9399 return CryptoJS
.SHA1
;
9402 },{"./core":31}],56:[function(_dereq_
,module
,exports
){
9403 ;(function (root
, factory
, undef
) {
9404 if (typeof exports
=== "object") {
9406 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./sha256"));
9408 else if (typeof define
=== "function" && define
.amd
) {
9410 define(["./core", "./sha256"], factory
);
9414 factory(root
.CryptoJS
);
9416 }(this, function (CryptoJS
) {
9422 var WordArray
= C_lib
.WordArray
;
9423 var C_algo
= C
.algo
;
9424 var SHA256
= C_algo
.SHA256
;
9427 * SHA-224 hash algorithm.
9429 var SHA224
= C_algo
.SHA224
= SHA256
.extend({
9430 _doReset: function () {
9431 this._hash
= new WordArray
.init([
9432 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
9433 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
9437 _doFinalize: function () {
9438 var hash
= SHA256
._doFinalize
.call(this);
9447 * Shortcut function to the hasher's object interface.
9449 * @param {WordArray|string} message The message to hash.
9451 * @return {WordArray} The hash.
9457 * var hash = CryptoJS.SHA224('message');
9458 * var hash = CryptoJS.SHA224(wordArray);
9460 C
.SHA224
= SHA256
._createHelper(SHA224
);
9463 * Shortcut function to the HMAC's object interface.
9465 * @param {WordArray|string} message The message to hash.
9466 * @param {WordArray|string} key The secret key.
9468 * @return {WordArray} The HMAC.
9474 * var hmac = CryptoJS.HmacSHA224(message, key);
9476 C
.HmacSHA224
= SHA256
._createHmacHelper(SHA224
);
9480 return CryptoJS
.SHA224
;
9483 },{"./core":31,"./sha256":57}],57:[function(_dereq_
,module
,exports
){
9484 ;(function (root
, factory
) {
9485 if (typeof exports
=== "object") {
9487 module
.exports
= exports
= factory(_dereq_("./core"));
9489 else if (typeof define
=== "function" && define
.amd
) {
9491 define(["./core"], factory
);
9495 factory(root
.CryptoJS
);
9497 }(this, function (CryptoJS
) {
9503 var WordArray
= C_lib
.WordArray
;
9504 var Hasher
= C_lib
.Hasher
;
9505 var C_algo
= C
.algo
;
9507 // Initialization and round constants tables
9511 // Compute constants
9513 function isPrime(n
) {
9514 var sqrtN
= Math
.sqrt(n
);
9515 for (var factor
= 2; factor
<= sqrtN
; factor
++) {
9516 if (!(n
% factor
)) {
9524 function getFractionalBits(n
) {
9525 return ((n
- (n
| 0)) * 0x100000000) | 0;
9530 while (nPrime
< 64) {
9533 H
[nPrime
] = getFractionalBits(Math
.pow(n
, 1 / 2));
9535 K
[nPrime
] = getFractionalBits(Math
.pow(n
, 1 / 3));
9548 * SHA-256 hash algorithm.
9550 var SHA256
= C_algo
.SHA256
= Hasher
.extend({
9551 _doReset: function () {
9552 this._hash
= new WordArray
.init(H
.slice(0));
9555 _doProcessBlock: function (M
, offset
) {
9557 var H
= this._hash
.words
;
9559 // Working variables
9570 for (var i
= 0; i
< 64; i
++) {
9572 W
[i
] = M
[offset
+ i
] | 0;
9574 var gamma0x
= W
[i
- 15];
9575 var gamma0
= ((gamma0x
<< 25) | (gamma0x
>>> 7)) ^
9576 ((gamma0x
<< 14) | (gamma0x
>>> 18)) ^
9579 var gamma1x
= W
[i
- 2];
9580 var gamma1
= ((gamma1x
<< 15) | (gamma1x
>>> 17)) ^
9581 ((gamma1x
<< 13) | (gamma1x
>>> 19)) ^
9584 W
[i
] = gamma0
+ W
[i
- 7] + gamma1
+ W
[i
- 16];
9587 var ch
= (e
& f
) ^ (~e
& g
);
9588 var maj
= (a
& b
) ^ (a
& c
) ^ (b
& c
);
9590 var sigma0
= ((a
<< 30) | (a
>>> 2)) ^ ((a
<< 19) | (a
>>> 13)) ^ ((a
<< 10) | (a
>>> 22));
9591 var sigma1
= ((e
<< 26) | (e
>>> 6)) ^ ((e
<< 21) | (e
>>> 11)) ^ ((e
<< 7) | (e
>>> 25));
9593 var t1
= h
+ sigma1
+ ch
+ K
[i
] + W
[i
];
9594 var t2
= sigma0
+ maj
;
9606 // Intermediate hash value
9607 H
[0] = (H
[0] + a
) | 0;
9608 H
[1] = (H
[1] + b
) | 0;
9609 H
[2] = (H
[2] + c
) | 0;
9610 H
[3] = (H
[3] + d
) | 0;
9611 H
[4] = (H
[4] + e
) | 0;
9612 H
[5] = (H
[5] + f
) | 0;
9613 H
[6] = (H
[6] + g
) | 0;
9614 H
[7] = (H
[7] + h
) | 0;
9617 _doFinalize: function () {
9619 var data
= this._data
;
9620 var dataWords
= data
.words
;
9622 var nBitsTotal
= this._nDataBytes
* 8;
9623 var nBitsLeft
= data
.sigBytes
* 8;
9626 dataWords
[nBitsLeft
>>> 5] |= 0x80 << (24 - nBitsLeft
% 32);
9627 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 14] = Math
.floor(nBitsTotal
/ 0x100000000);
9628 dataWords
[(((nBitsLeft
+ 64) >>> 9) << 4) + 15] = nBitsTotal
;
9629 data
.sigBytes
= dataWords
.length
* 4;
9631 // Hash final blocks
9634 // Return final computed hash
9638 clone: function () {
9639 var clone
= Hasher
.clone
.call(this);
9640 clone
._hash
= this._hash
.clone();
9647 * Shortcut function to the hasher's object interface.
9649 * @param {WordArray|string} message The message to hash.
9651 * @return {WordArray} The hash.
9657 * var hash = CryptoJS.SHA256('message');
9658 * var hash = CryptoJS.SHA256(wordArray);
9660 C
.SHA256
= Hasher
._createHelper(SHA256
);
9663 * Shortcut function to the HMAC's object interface.
9665 * @param {WordArray|string} message The message to hash.
9666 * @param {WordArray|string} key The secret key.
9668 * @return {WordArray} The HMAC.
9674 * var hmac = CryptoJS.HmacSHA256(message, key);
9676 C
.HmacSHA256
= Hasher
._createHmacHelper(SHA256
);
9680 return CryptoJS
.SHA256
;
9683 },{"./core":31}],58:[function(_dereq_
,module
,exports
){
9684 ;(function (root
, factory
, undef
) {
9685 if (typeof exports
=== "object") {
9687 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./x64-core"));
9689 else if (typeof define
=== "function" && define
.amd
) {
9691 define(["./core", "./x64-core"], factory
);
9695 factory(root
.CryptoJS
);
9697 }(this, function (CryptoJS
) {
9703 var WordArray
= C_lib
.WordArray
;
9704 var Hasher
= C_lib
.Hasher
;
9706 var X64Word
= C_x64
.Word
;
9707 var C_algo
= C
.algo
;
9710 var RHO_OFFSETS
= [];
9711 var PI_INDEXES
= [];
9712 var ROUND_CONSTANTS
= [];
9714 // Compute Constants
9716 // Compute rho offset constants
9718 for (var t
= 0; t
< 24; t
++) {
9719 RHO_OFFSETS
[x
+ 5 * y
] = ((t
+ 1) * (t
+ 2) / 2) % 64;
9722 var newY
= (2 * x
+ 3 * y
) % 5;
9727 // Compute pi index constants
9728 for (var x
= 0; x
< 5; x
++) {
9729 for (var y
= 0; y
< 5; y
++) {
9730 PI_INDEXES
[x
+ 5 * y
] = y
+ ((2 * x
+ 3 * y
) % 5) * 5;
9734 // Compute round constants
9736 for (var i
= 0; i
< 24; i
++) {
9737 var roundConstantMsw
= 0;
9738 var roundConstantLsw
= 0;
9740 for (var j
= 0; j
< 7; j
++) {
9742 var bitPosition
= (1 << j
) - 1;
9743 if (bitPosition
< 32) {
9744 roundConstantLsw
^= 1 << bitPosition
;
9745 } else /* if (bitPosition >= 32) */ {
9746 roundConstantMsw
^= 1 << (bitPosition
- 32);
9750 // Compute next LFSR
9752 // Primitive polynomial over GF(2): x^8 + x^6 + x^5 + x^4 + 1
9753 LFSR
= (LFSR
<< 1) ^ 0x71;
9759 ROUND_CONSTANTS
[i
] = X64Word
.create(roundConstantMsw
, roundConstantLsw
);
9763 // Reusable objects for temporary values
9766 for (var i
= 0; i
< 25; i
++) {
9767 T
[i
] = X64Word
.create();
9772 * SHA-3 hash algorithm.
9774 var SHA3
= C_algo
.SHA3
= Hasher
.extend({
9776 * Configuration options.
9778 * @property {number} outputLength
9779 * The desired number of bits in the output hash.
9780 * Only values permitted are: 224, 256, 384, 512.
9783 cfg: Hasher
.cfg
.extend({
9787 _doReset: function () {
9788 var state
= this._state
= []
9789 for (var i
= 0; i
< 25; i
++) {
9790 state
[i
] = new X64Word
.init();
9793 this.blockSize
= (1600 - 2 * this.cfg
.outputLength
) / 32;
9796 _doProcessBlock: function (M
, offset
) {
9798 var state
= this._state
;
9799 var nBlockSizeLanes
= this.blockSize
/ 2;
9802 for (var i
= 0; i
< nBlockSizeLanes
; i
++) {
9804 var M2i
= M
[offset
+ 2 * i
];
9805 var M2i1
= M
[offset
+ 2 * i
+ 1];
9809 (((M2i
<< 8) | (M2i
>>> 24)) & 0x00ff00ff) |
9810 (((M2i
<< 24) | (M2i
>>> 8)) & 0xff00ff00)
9813 (((M2i1
<< 8) | (M2i1
>>> 24)) & 0x00ff00ff) |
9814 (((M2i1
<< 24) | (M2i1
>>> 8)) & 0xff00ff00)
9817 // Absorb message into state
9818 var lane
= state
[i
];
9824 for (var round
= 0; round
< 24; round
++) {
9826 for (var x
= 0; x
< 5; x
++) {
9828 var tMsw
= 0, tLsw
= 0;
9829 for (var y
= 0; y
< 5; y
++) {
9830 var lane
= state
[x
+ 5 * y
];
9840 for (var x
= 0; x
< 5; x
++) {
9842 var Tx4
= T
[(x
+ 4) % 5];
9843 var Tx1
= T
[(x
+ 1) % 5];
9844 var Tx1Msw
= Tx1
.high
;
9845 var Tx1Lsw
= Tx1
.low
;
9847 // Mix surrounding columns
9848 var tMsw
= Tx4
.high
^ ((Tx1Msw
<< 1) | (Tx1Lsw
>>> 31));
9849 var tLsw
= Tx4
.low
^ ((Tx1Lsw
<< 1) | (Tx1Msw
>>> 31));
9850 for (var y
= 0; y
< 5; y
++) {
9851 var lane
= state
[x
+ 5 * y
];
9858 for (var laneIndex
= 1; laneIndex
< 25; laneIndex
++) {
9860 var lane
= state
[laneIndex
];
9861 var laneMsw
= lane
.high
;
9862 var laneLsw
= lane
.low
;
9863 var rhoOffset
= RHO_OFFSETS
[laneIndex
];
9866 if (rhoOffset
< 32) {
9867 var tMsw
= (laneMsw
<< rhoOffset
) | (laneLsw
>>> (32 - rhoOffset
));
9868 var tLsw
= (laneLsw
<< rhoOffset
) | (laneMsw
>>> (32 - rhoOffset
));
9869 } else /* if (rhoOffset >= 32) */ {
9870 var tMsw
= (laneLsw
<< (rhoOffset
- 32)) | (laneMsw
>>> (64 - rhoOffset
));
9871 var tLsw
= (laneMsw
<< (rhoOffset
- 32)) | (laneLsw
>>> (64 - rhoOffset
));
9875 var TPiLane
= T
[PI_INDEXES
[laneIndex
]];
9876 TPiLane
.high
= tMsw
;
9880 // Rho pi at x = y = 0
9882 var state0
= state
[0];
9883 T0
.high
= state0
.high
;
9884 T0
.low
= state0
.low
;
9887 for (var x
= 0; x
< 5; x
++) {
9888 for (var y
= 0; y
< 5; y
++) {
9890 var laneIndex
= x
+ 5 * y
;
9891 var lane
= state
[laneIndex
];
9892 var TLane
= T
[laneIndex
];
9893 var Tx1Lane
= T
[((x
+ 1) % 5) + 5 * y
];
9894 var Tx2Lane
= T
[((x
+ 2) % 5) + 5 * y
];
9897 lane
.high
= TLane
.high
^ (~Tx1Lane
.high
& Tx2Lane
.high
);
9898 lane
.low
= TLane
.low
^ (~Tx1Lane
.low
& Tx2Lane
.low
);
9903 var lane
= state
[0];
9904 var roundConstant
= ROUND_CONSTANTS
[round
];
9905 lane
.high
^= roundConstant
.high
;
9906 lane
.low
^= roundConstant
.low
;;
9910 _doFinalize: function () {
9912 var data
= this._data
;
9913 var dataWords
= data
.words
;
9914 var nBitsTotal
= this._nDataBytes
* 8;
9915 var nBitsLeft
= data
.sigBytes
* 8;
9916 var blockSizeBits
= this.blockSize
* 32;
9919 dataWords
[nBitsLeft
>>> 5] |= 0x1 << (24 - nBitsLeft
% 32);
9920 dataWords
[((Math
.ceil((nBitsLeft
+ 1) / blockSizeBits
) * blockSizeBits
) >>> 5) - 1] |= 0x80;
9921 data
.sigBytes
= dataWords
.length
* 4;
9923 // Hash final blocks
9927 var state
= this._state
;
9928 var outputLengthBytes
= this.cfg
.outputLength
/ 8;
9929 var outputLengthLanes
= outputLengthBytes
/ 8;
9933 for (var i
= 0; i
< outputLengthLanes
; i
++) {
9935 var lane
= state
[i
];
9936 var laneMsw
= lane
.high
;
9937 var laneLsw
= lane
.low
;
9941 (((laneMsw
<< 8) | (laneMsw
>>> 24)) & 0x00ff00ff) |
9942 (((laneMsw
<< 24) | (laneMsw
>>> 8)) & 0xff00ff00)
9945 (((laneLsw
<< 8) | (laneLsw
>>> 24)) & 0x00ff00ff) |
9946 (((laneLsw
<< 24) | (laneLsw
>>> 8)) & 0xff00ff00)
9949 // Squeeze state to retrieve hash
9950 hashWords
.push(laneLsw
);
9951 hashWords
.push(laneMsw
);
9954 // Return final computed hash
9955 return new WordArray
.init(hashWords
, outputLengthBytes
);
9958 clone: function () {
9959 var clone
= Hasher
.clone
.call(this);
9961 var state
= clone
._state
= this._state
.slice(0);
9962 for (var i
= 0; i
< 25; i
++) {
9963 state
[i
] = state
[i
].clone();
9971 * Shortcut function to the hasher's object interface.
9973 * @param {WordArray|string} message The message to hash.
9975 * @return {WordArray} The hash.
9981 * var hash = CryptoJS.SHA3('message');
9982 * var hash = CryptoJS.SHA3(wordArray);
9984 C
.SHA3
= Hasher
._createHelper(SHA3
);
9987 * Shortcut function to the HMAC's object interface.
9989 * @param {WordArray|string} message The message to hash.
9990 * @param {WordArray|string} key The secret key.
9992 * @return {WordArray} The HMAC.
9998 * var hmac = CryptoJS.HmacSHA3(message, key);
10000 C
.HmacSHA3
= Hasher
._createHmacHelper(SHA3
);
10004 return CryptoJS
.SHA3
;
10007 },{"./core":31,"./x64-core":62}],59:[function(_dereq_
,module
,exports
){
10008 ;(function (root
, factory
, undef
) {
10009 if (typeof exports
=== "object") {
10011 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./x64-core"), _dereq_("./sha512"));
10013 else if (typeof define
=== "function" && define
.amd
) {
10015 define(["./core", "./x64-core", "./sha512"], factory
);
10018 // Global (browser)
10019 factory(root
.CryptoJS
);
10021 }(this, function (CryptoJS
) {
10027 var X64Word
= C_x64
.Word
;
10028 var X64WordArray
= C_x64
.WordArray
;
10029 var C_algo
= C
.algo
;
10030 var SHA512
= C_algo
.SHA512
;
10033 * SHA-384 hash algorithm.
10035 var SHA384
= C_algo
.SHA384
= SHA512
.extend({
10036 _doReset: function () {
10037 this._hash
= new X64WordArray
.init([
10038 new X64Word
.init(0xcbbb9d5d, 0xc1059ed8), new X64Word
.init(0x629a292a, 0x367cd507),
10039 new X64Word
.init(0x9159015a, 0x3070dd17), new X64Word
.init(0x152fecd8, 0xf70e5939),
10040 new X64Word
.init(0x67332667, 0xffc00b31), new X64Word
.init(0x8eb44a87, 0x68581511),
10041 new X64Word
.init(0xdb0c2e0d, 0x64f98fa7), new X64Word
.init(0x47b5481d, 0xbefa4fa4)
10045 _doFinalize: function () {
10046 var hash
= SHA512
._doFinalize
.call(this);
10048 hash
.sigBytes
-= 16;
10055 * Shortcut function to the hasher's object interface.
10057 * @param {WordArray|string} message The message to hash.
10059 * @return {WordArray} The hash.
10065 * var hash = CryptoJS.SHA384('message');
10066 * var hash = CryptoJS.SHA384(wordArray);
10068 C
.SHA384
= SHA512
._createHelper(SHA384
);
10071 * Shortcut function to the HMAC's object interface.
10073 * @param {WordArray|string} message The message to hash.
10074 * @param {WordArray|string} key The secret key.
10076 * @return {WordArray} The HMAC.
10082 * var hmac = CryptoJS.HmacSHA384(message, key);
10084 C
.HmacSHA384
= SHA512
._createHmacHelper(SHA384
);
10088 return CryptoJS
.SHA384
;
10091 },{"./core":31,"./sha512":60,"./x64-core":62}],60:[function(_dereq_
,module
,exports
){
10092 ;(function (root
, factory
, undef
) {
10093 if (typeof exports
=== "object") {
10095 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./x64-core"));
10097 else if (typeof define
=== "function" && define
.amd
) {
10099 define(["./core", "./x64-core"], factory
);
10102 // Global (browser)
10103 factory(root
.CryptoJS
);
10105 }(this, function (CryptoJS
) {
10111 var Hasher
= C_lib
.Hasher
;
10113 var X64Word
= C_x64
.Word
;
10114 var X64WordArray
= C_x64
.WordArray
;
10115 var C_algo
= C
.algo
;
10117 function X64Word_create() {
10118 return X64Word
.create
.apply(X64Word
, arguments
);
10123 X64Word_create(0x428a2f98, 0xd728ae22), X64Word_create(0x71374491, 0x23ef65cd),
10124 X64Word_create(0xb5c0fbcf, 0xec4d3b2f), X64Word_create(0xe9b5dba5, 0x8189dbbc),
10125 X64Word_create(0x3956c25b, 0xf348b538), X64Word_create(0x59f111f1, 0xb605d019),
10126 X64Word_create(0x923f82a4, 0xaf194f9b), X64Word_create(0xab1c5ed5, 0xda6d8118),
10127 X64Word_create(0xd807aa98, 0xa3030242), X64Word_create(0x12835b01, 0x45706fbe),
10128 X64Word_create(0x243185be, 0x4ee4b28c), X64Word_create(0x550c7dc3, 0xd5ffb4e2),
10129 X64Word_create(0x72be5d74, 0xf27b896f), X64Word_create(0x80deb1fe, 0x3b1696b1),
10130 X64Word_create(0x9bdc06a7, 0x25c71235), X64Word_create(0xc19bf174, 0xcf692694),
10131 X64Word_create(0xe49b69c1, 0x9ef14ad2), X64Word_create(0xefbe4786, 0x384f25e3),
10132 X64Word_create(0x0fc19dc6, 0x8b8cd5b5), X64Word_create(0x240ca1cc, 0x77ac9c65),
10133 X64Word_create(0x2de92c6f, 0x592b0275), X64Word_create(0x4a7484aa, 0x6ea6e483),
10134 X64Word_create(0x5cb0a9dc, 0xbd41fbd4), X64Word_create(0x76f988da, 0x831153b5),
10135 X64Word_create(0x983e5152, 0xee66dfab), X64Word_create(0xa831c66d, 0x2db43210),
10136 X64Word_create(0xb00327c8, 0x98fb213f), X64Word_create(0xbf597fc7, 0xbeef0ee4),
10137 X64Word_create(0xc6e00bf3, 0x3da88fc2), X64Word_create(0xd5a79147, 0x930aa725),
10138 X64Word_create(0x06ca6351, 0xe003826f), X64Word_create(0x14292967, 0x0a0e6e70),
10139 X64Word_create(0x27b70a85, 0x46d22ffc), X64Word_create(0x2e1b2138, 0x5c26c926),
10140 X64Word_create(0x4d2c6dfc, 0x5ac42aed), X64Word_create(0x53380d13, 0x9d95b3df),
10141 X64Word_create(0x650a7354, 0x8baf63de), X64Word_create(0x766a0abb, 0x3c77b2a8),
10142 X64Word_create(0x81c2c92e, 0x47edaee6), X64Word_create(0x92722c85, 0x1482353b),
10143 X64Word_create(0xa2bfe8a1, 0x4cf10364), X64Word_create(0xa81a664b, 0xbc423001),
10144 X64Word_create(0xc24b8b70, 0xd0f89791), X64Word_create(0xc76c51a3, 0x0654be30),
10145 X64Word_create(0xd192e819, 0xd6ef5218), X64Word_create(0xd6990624, 0x5565a910),
10146 X64Word_create(0xf40e3585, 0x5771202a), X64Word_create(0x106aa070, 0x32bbd1b8),
10147 X64Word_create(0x19a4c116, 0xb8d2d0c8), X64Word_create(0x1e376c08, 0x5141ab53),
10148 X64Word_create(0x2748774c, 0xdf8eeb99), X64Word_create(0x34b0bcb5, 0xe19b48a8),
10149 X64Word_create(0x391c0cb3, 0xc5c95a63), X64Word_create(0x4ed8aa4a, 0xe3418acb),
10150 X64Word_create(0x5b9cca4f, 0x7763e373), X64Word_create(0x682e6ff3, 0xd6b2b8a3),
10151 X64Word_create(0x748f82ee, 0x5defb2fc), X64Word_create(0x78a5636f, 0x43172f60),
10152 X64Word_create(0x84c87814, 0xa1f0ab72), X64Word_create(0x8cc70208, 0x1a6439ec),
10153 X64Word_create(0x90befffa, 0x23631e28), X64Word_create(0xa4506ceb, 0xde82bde9),
10154 X64Word_create(0xbef9a3f7, 0xb2c67915), X64Word_create(0xc67178f2, 0xe372532b),
10155 X64Word_create(0xca273ece, 0xea26619c), X64Word_create(0xd186b8c7, 0x21c0c207),
10156 X64Word_create(0xeada7dd6, 0xcde0eb1e), X64Word_create(0xf57d4f7f, 0xee6ed178),
10157 X64Word_create(0x06f067aa, 0x72176fba), X64Word_create(0x0a637dc5, 0xa2c898a6),
10158 X64Word_create(0x113f9804, 0xbef90dae), X64Word_create(0x1b710b35, 0x131c471b),
10159 X64Word_create(0x28db77f5, 0x23047d84), X64Word_create(0x32caab7b, 0x40c72493),
10160 X64Word_create(0x3c9ebe0a, 0x15c9bebc), X64Word_create(0x431d67c4, 0x9c100d4c),
10161 X64Word_create(0x4cc5d4be, 0xcb3e42b6), X64Word_create(0x597f299c, 0xfc657e2a),
10162 X64Word_create(0x5fcb6fab, 0x3ad6faec), X64Word_create(0x6c44198c, 0x4a475817)
10165 // Reusable objects
10168 for (var i
= 0; i
< 80; i
++) {
10169 W
[i
] = X64Word_create();
10174 * SHA-512 hash algorithm.
10176 var SHA512
= C_algo
.SHA512
= Hasher
.extend({
10177 _doReset: function () {
10178 this._hash
= new X64WordArray
.init([
10179 new X64Word
.init(0x6a09e667, 0xf3bcc908), new X64Word
.init(0xbb67ae85, 0x84caa73b),
10180 new X64Word
.init(0x3c6ef372, 0xfe94f82b), new X64Word
.init(0xa54ff53a, 0x5f1d36f1),
10181 new X64Word
.init(0x510e527f, 0xade682d1), new X64Word
.init(0x9b05688c, 0x2b3e6c1f),
10182 new X64Word
.init(0x1f83d9ab, 0xfb41bd6b), new X64Word
.init(0x5be0cd19, 0x137e2179)
10186 _doProcessBlock: function (M
, offset
) {
10188 var H
= this._hash
.words
;
10216 // Working variables
10235 for (var i
= 0; i
< 80; i
++) {
10241 var Wih
= Wi
.high
= M
[offset
+ i
* 2] | 0;
10242 var Wil
= Wi
.low
= M
[offset
+ i
* 2 + 1] | 0;
10245 var gamma0x
= W
[i
- 15];
10246 var gamma0xh
= gamma0x
.high
;
10247 var gamma0xl
= gamma0x
.low
;
10248 var gamma0h
= ((gamma0xh
>>> 1) | (gamma0xl
<< 31)) ^ ((gamma0xh
>>> 8) | (gamma0xl
<< 24)) ^ (gamma0xh
>>> 7);
10249 var gamma0l
= ((gamma0xl
>>> 1) | (gamma0xh
<< 31)) ^ ((gamma0xl
>>> 8) | (gamma0xh
<< 24)) ^ ((gamma0xl
>>> 7) | (gamma0xh
<< 25));
10252 var gamma1x
= W
[i
- 2];
10253 var gamma1xh
= gamma1x
.high
;
10254 var gamma1xl
= gamma1x
.low
;
10255 var gamma1h
= ((gamma1xh
>>> 19) | (gamma1xl
<< 13)) ^ ((gamma1xh
<< 3) | (gamma1xl
>>> 29)) ^ (gamma1xh
>>> 6);
10256 var gamma1l
= ((gamma1xl
>>> 19) | (gamma1xh
<< 13)) ^ ((gamma1xl
<< 3) | (gamma1xh
>>> 29)) ^ ((gamma1xl
>>> 6) | (gamma1xh
<< 26));
10258 // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16]
10259 var Wi7
= W
[i
- 7];
10260 var Wi7h
= Wi7
.high
;
10261 var Wi7l
= Wi7
.low
;
10263 var Wi16
= W
[i
- 16];
10264 var Wi16h
= Wi16
.high
;
10265 var Wi16l
= Wi16
.low
;
10267 var Wil
= gamma0l
+ Wi7l
;
10268 var Wih
= gamma0h
+ Wi7h
+ ((Wil
>>> 0) < (gamma0l
>>> 0) ? 1 : 0);
10269 var Wil
= Wil
+ gamma1l
;
10270 var Wih
= Wih
+ gamma1h
+ ((Wil
>>> 0) < (gamma1l
>>> 0) ? 1 : 0);
10271 var Wil
= Wil
+ Wi16l
;
10272 var Wih
= Wih
+ Wi16h
+ ((Wil
>>> 0) < (Wi16l
>>> 0) ? 1 : 0);
10278 var chh
= (eh
& fh
) ^ (~eh
& gh
);
10279 var chl
= (el
& fl
) ^ (~el
& gl
);
10280 var majh
= (ah
& bh
) ^ (ah
& ch
) ^ (bh
& ch
);
10281 var majl
= (al
& bl
) ^ (al
& cl
) ^ (bl
& cl
);
10283 var sigma0h
= ((ah
>>> 28) | (al
<< 4)) ^ ((ah
<< 30) | (al
>>> 2)) ^ ((ah
<< 25) | (al
>>> 7));
10284 var sigma0l
= ((al
>>> 28) | (ah
<< 4)) ^ ((al
<< 30) | (ah
>>> 2)) ^ ((al
<< 25) | (ah
>>> 7));
10285 var sigma1h
= ((eh
>>> 14) | (el
<< 18)) ^ ((eh
>>> 18) | (el
<< 14)) ^ ((eh
<< 23) | (el
>>> 9));
10286 var sigma1l
= ((el
>>> 14) | (eh
<< 18)) ^ ((el
>>> 18) | (eh
<< 14)) ^ ((el
<< 23) | (eh
>>> 9));
10288 // t1 = h + sigma1 + ch + K[i] + W[i]
10293 var t1l
= hl
+ sigma1l
;
10294 var t1h
= hh
+ sigma1h
+ ((t1l
>>> 0) < (hl
>>> 0) ? 1 : 0);
10295 var t1l
= t1l
+ chl
;
10296 var t1h
= t1h
+ chh
+ ((t1l
>>> 0) < (chl
>>> 0) ? 1 : 0);
10297 var t1l
= t1l
+ Kil
;
10298 var t1h
= t1h
+ Kih
+ ((t1l
>>> 0) < (Kil
>>> 0) ? 1 : 0);
10299 var t1l
= t1l
+ Wil
;
10300 var t1h
= t1h
+ Wih
+ ((t1l
>>> 0) < (Wil
>>> 0) ? 1 : 0);
10302 // t2 = sigma0 + maj
10303 var t2l
= sigma0l
+ majl
;
10304 var t2h
= sigma0h
+ majh
+ ((t2l
>>> 0) < (sigma0l
>>> 0) ? 1 : 0);
10306 // Update working variables
10313 el
= (dl
+ t1l
) | 0;
10314 eh
= (dh
+ t1h
+ ((el
>>> 0) < (dl
>>> 0) ? 1 : 0)) | 0;
10321 al
= (t1l
+ t2l
) | 0;
10322 ah
= (t1h
+ t2h
+ ((al
>>> 0) < (t1l
>>> 0) ? 1 : 0)) | 0;
10325 // Intermediate hash value
10326 H0l
= H0
.low
= (H0l
+ al
);
10327 H0
.high
= (H0h
+ ah
+ ((H0l
>>> 0) < (al
>>> 0) ? 1 : 0));
10328 H1l
= H1
.low
= (H1l
+ bl
);
10329 H1
.high
= (H1h
+ bh
+ ((H1l
>>> 0) < (bl
>>> 0) ? 1 : 0));
10330 H2l
= H2
.low
= (H2l
+ cl
);
10331 H2
.high
= (H2h
+ ch
+ ((H2l
>>> 0) < (cl
>>> 0) ? 1 : 0));
10332 H3l
= H3
.low
= (H3l
+ dl
);
10333 H3
.high
= (H3h
+ dh
+ ((H3l
>>> 0) < (dl
>>> 0) ? 1 : 0));
10334 H4l
= H4
.low
= (H4l
+ el
);
10335 H4
.high
= (H4h
+ eh
+ ((H4l
>>> 0) < (el
>>> 0) ? 1 : 0));
10336 H5l
= H5
.low
= (H5l
+ fl
);
10337 H5
.high
= (H5h
+ fh
+ ((H5l
>>> 0) < (fl
>>> 0) ? 1 : 0));
10338 H6l
= H6
.low
= (H6l
+ gl
);
10339 H6
.high
= (H6h
+ gh
+ ((H6l
>>> 0) < (gl
>>> 0) ? 1 : 0));
10340 H7l
= H7
.low
= (H7l
+ hl
);
10341 H7
.high
= (H7h
+ hh
+ ((H7l
>>> 0) < (hl
>>> 0) ? 1 : 0));
10344 _doFinalize: function () {
10346 var data
= this._data
;
10347 var dataWords
= data
.words
;
10349 var nBitsTotal
= this._nDataBytes
* 8;
10350 var nBitsLeft
= data
.sigBytes
* 8;
10353 dataWords
[nBitsLeft
>>> 5] |= 0x80 << (24 - nBitsLeft
% 32);
10354 dataWords
[(((nBitsLeft
+ 128) >>> 10) << 5) + 30] = Math
.floor(nBitsTotal
/ 0x100000000);
10355 dataWords
[(((nBitsLeft
+ 128) >>> 10) << 5) + 31] = nBitsTotal
;
10356 data
.sigBytes
= dataWords
.length
* 4;
10358 // Hash final blocks
10361 // Convert hash to 32-bit word array before returning
10362 var hash
= this._hash
.toX32();
10364 // Return final computed hash
10368 clone: function () {
10369 var clone
= Hasher
.clone
.call(this);
10370 clone
._hash
= this._hash
.clone();
10379 * Shortcut function to the hasher's object interface.
10381 * @param {WordArray|string} message The message to hash.
10383 * @return {WordArray} The hash.
10389 * var hash = CryptoJS.SHA512('message');
10390 * var hash = CryptoJS.SHA512(wordArray);
10392 C
.SHA512
= Hasher
._createHelper(SHA512
);
10395 * Shortcut function to the HMAC's object interface.
10397 * @param {WordArray|string} message The message to hash.
10398 * @param {WordArray|string} key The secret key.
10400 * @return {WordArray} The HMAC.
10406 * var hmac = CryptoJS.HmacSHA512(message, key);
10408 C
.HmacSHA512
= Hasher
._createHmacHelper(SHA512
);
10412 return CryptoJS
.SHA512
;
10415 },{"./core":31,"./x64-core":62}],61:[function(_dereq_
,module
,exports
){
10416 ;(function (root
, factory
, undef
) {
10417 if (typeof exports
=== "object") {
10419 module
.exports
= exports
= factory(_dereq_("./core"), _dereq_("./enc-base64"), _dereq_("./md5"), _dereq_("./evpkdf"), _dereq_("./cipher-core"));
10421 else if (typeof define
=== "function" && define
.amd
) {
10423 define(["./core", "./enc-base64", "./md5", "./evpkdf", "./cipher-core"], factory
);
10426 // Global (browser)
10427 factory(root
.CryptoJS
);
10429 }(this, function (CryptoJS
) {
10435 var WordArray
= C_lib
.WordArray
;
10436 var BlockCipher
= C_lib
.BlockCipher
;
10437 var C_algo
= C
.algo
;
10439 // Permuted Choice 1 constants
10441 57, 49, 41, 33, 25, 17, 9, 1,
10442 58, 50, 42, 34, 26, 18, 10, 2,
10443 59, 51, 43, 35, 27, 19, 11, 3,
10444 60, 52, 44, 36, 63, 55, 47, 39,
10445 31, 23, 15, 7, 62, 54, 46, 38,
10446 30, 22, 14, 6, 61, 53, 45, 37,
10447 29, 21, 13, 5, 28, 20, 12, 4
10450 // Permuted Choice 2 constants
10452 14, 17, 11, 24, 1, 5,
10453 3, 28, 15, 6, 21, 10,
10454 23, 19, 12, 4, 26, 8,
10455 16, 7, 27, 20, 13, 2,
10456 41, 52, 31, 37, 47, 55,
10457 30, 40, 51, 45, 33, 48,
10458 44, 49, 39, 56, 34, 53,
10459 46, 42, 50, 36, 29, 32
10462 // Cumulative bit shift constants
10463 var BIT_SHIFTS
= [1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28];
10465 // SBOXes and round permutation constants
10469 0x10000000: 0x8000,
10470 0x20000000: 0x808002,
10473 0x50000000: 0x808202,
10474 0x60000000: 0x800202,
10475 0x70000000: 0x800000,
10477 0x90000000: 0x800200,
10478 0xa0000000: 0x8200,
10479 0xb0000000: 0x808000,
10480 0xc0000000: 0x8002,
10481 0xd0000000: 0x800002,
10483 0xf0000000: 0x8202,
10485 0x18000000: 0x808202,
10486 0x28000000: 0x8202,
10487 0x38000000: 0x8000,
10488 0x48000000: 0x808200,
10490 0x68000000: 0x808002,
10492 0x88000000: 0x800200,
10493 0x98000000: 0x8200,
10494 0xa8000000: 0x808000,
10495 0xb8000000: 0x800202,
10496 0xc8000000: 0x800002,
10497 0xd8000000: 0x8002,
10499 0xf8000000: 0x800000,
10502 0x20000001: 0x808200,
10503 0x30000001: 0x800000,
10504 0x40000001: 0x808002,
10505 0x50000001: 0x8200,
10507 0x70000001: 0x800202,
10508 0x80000001: 0x808202,
10509 0x90000001: 0x808000,
10510 0xa0000001: 0x800002,
10511 0xb0000001: 0x8202,
10513 0xd0000001: 0x800200,
10514 0xe0000001: 0x8002,
10516 0x8000001: 0x808202,
10517 0x18000001: 0x808000,
10518 0x28000001: 0x800000,
10520 0x48000001: 0x8000,
10521 0x58000001: 0x800002,
10523 0x78000001: 0x8202,
10524 0x88000001: 0x8002,
10525 0x98000001: 0x800202,
10527 0xb8000001: 0x808200,
10528 0xc8000001: 0x800200,
10530 0xe8000001: 0x8200,
10531 0xf8000001: 0x808002
10536 0x2000000: 0x80000,
10537 0x3000000: 0x40080010,
10538 0x4000000: 0x40000010,
10539 0x5000000: 0x40084000,
10540 0x6000000: 0x40004000,
10542 0x8000000: 0x84000,
10543 0x9000000: 0x40004010,
10544 0xa000000: 0x40000000,
10545 0xb000000: 0x84010,
10546 0xc000000: 0x80010,
10549 0xf000000: 0x40080000,
10550 0x800000: 0x40004000,
10551 0x1800000: 0x84010,
10553 0x3800000: 0x40004010,
10554 0x4800000: 0x40084010,
10555 0x5800000: 0x40000000,
10556 0x6800000: 0x80000,
10557 0x7800000: 0x40080010,
10558 0x8800000: 0x80010,
10561 0xb800000: 0x40080000,
10562 0xc800000: 0x40000010,
10563 0xd800000: 0x84000,
10564 0xe800000: 0x40084000,
10567 0x11000000: 0x40080010,
10568 0x12000000: 0x40004010,
10569 0x13000000: 0x40084000,
10570 0x14000000: 0x40080000,
10572 0x16000000: 0x84010,
10573 0x17000000: 0x4000,
10574 0x18000000: 0x4010,
10575 0x19000000: 0x80000,
10576 0x1a000000: 0x80010,
10577 0x1b000000: 0x40000010,
10578 0x1c000000: 0x84000,
10579 0x1d000000: 0x40004000,
10580 0x1e000000: 0x40000000,
10581 0x1f000000: 0x40084010,
10582 0x10800000: 0x84010,
10583 0x11800000: 0x80000,
10584 0x12800000: 0x40080000,
10585 0x13800000: 0x4000,
10586 0x14800000: 0x40004000,
10587 0x15800000: 0x40084010,
10589 0x17800000: 0x40000000,
10590 0x18800000: 0x40084000,
10591 0x19800000: 0x40000010,
10592 0x1a800000: 0x40004010,
10593 0x1b800000: 0x80010,
10595 0x1d800000: 0x4010,
10596 0x1e800000: 0x40080010,
10597 0x1f800000: 0x84000
10602 0x200000: 0x4000100,
10605 0x500000: 0x4000004,
10606 0x600000: 0x4010104,
10607 0x700000: 0x4010000,
10608 0x800000: 0x4000000,
10609 0x900000: 0x4010100,
10611 0xb00000: 0x4010004,
10612 0xc00000: 0x4000104,
10616 0x80000: 0x4010100,
10617 0x180000: 0x4010004,
10619 0x380000: 0x4000100,
10620 0x480000: 0x4000004,
10626 0xa80000: 0x4010000,
10629 0xd80000: 0x4000104,
10630 0xe80000: 0x4010104,
10631 0xf80000: 0x4000000,
10632 0x1000000: 0x4010100,
10633 0x1100000: 0x10004,
10634 0x1200000: 0x10000,
10635 0x1300000: 0x4000100,
10637 0x1500000: 0x4010104,
10638 0x1600000: 0x4000004,
10640 0x1800000: 0x4000104,
10641 0x1900000: 0x4000000,
10643 0x1b00000: 0x10100,
10644 0x1c00000: 0x4010000,
10646 0x1e00000: 0x10104,
10647 0x1f00000: 0x4010004,
10648 0x1080000: 0x4000000,
10650 0x1280000: 0x4010100,
10652 0x1480000: 0x10004,
10653 0x1580000: 0x4000100,
10655 0x1780000: 0x4010004,
10656 0x1880000: 0x10000,
10657 0x1980000: 0x4010104,
10658 0x1a80000: 0x10104,
10659 0x1b80000: 0x4000004,
10660 0x1c80000: 0x4000104,
10661 0x1d80000: 0x4010000,
10667 0x10000: 0x80001040,
10669 0x30000: 0x80400000,
10672 0x60000: 0x80000040,
10674 0x80000: 0x80000000,
10677 0xb0000: 0x80001000,
10678 0xc0000: 0x80400040,
10681 0xf0000: 0x80401040,
10682 0x8000: 0x80001040,
10684 0x28000: 0x80400040,
10685 0x38000: 0x80001000,
10687 0x58000: 0x80401040,
10689 0x78000: 0x80400000,
10691 0x98000: 0x80401000,
10694 0xc8000: 0x80000000,
10697 0xf8000: 0x80000040,
10698 0x100000: 0x400040,
10699 0x110000: 0x401000,
10700 0x120000: 0x80000040,
10703 0x150000: 0x80400040,
10704 0x160000: 0x80401000,
10705 0x170000: 0x80001040,
10706 0x180000: 0x80401040,
10707 0x190000: 0x80000000,
10708 0x1a0000: 0x80400000,
10709 0x1b0000: 0x401040,
10710 0x1c0000: 0x80001000,
10711 0x1d0000: 0x400000,
10714 0x108000: 0x80400000,
10715 0x118000: 0x80401040,
10717 0x138000: 0x401000,
10718 0x148000: 0x400040,
10719 0x158000: 0x80000000,
10720 0x168000: 0x80001040,
10722 0x188000: 0x80000040,
10724 0x1a8000: 0x80001000,
10725 0x1b8000: 0x80400040,
10727 0x1d8000: 0x80401000,
10728 0x1e8000: 0x400000,
10735 0x3000: 0x20000000,
10736 0x4000: 0x20040080,
10738 0x6000: 0x21000080,
10741 0x9000: 0x20040000,
10742 0xa000: 0x20000080,
10743 0xb000: 0x21040080,
10744 0xc000: 0x21040000,
10747 0xf000: 0x21000000,
10749 0x1800: 0x21000080,
10753 0x5800: 0x20040080,
10754 0x6800: 0x21040000,
10755 0x7800: 0x20000000,
10756 0x8800: 0x20040000,
10758 0xa800: 0x21040080,
10760 0xc800: 0x20000080,
10761 0xd800: 0x21000000,
10766 0x12000: 0x20000000,
10767 0x13000: 0x21000080,
10768 0x14000: 0x1000080,
10769 0x15000: 0x21040000,
10770 0x16000: 0x20040080,
10771 0x17000: 0x1000000,
10772 0x18000: 0x21040080,
10773 0x19000: 0x21000000,
10774 0x1a000: 0x1040000,
10775 0x1b000: 0x20040000,
10777 0x1d000: 0x20000080,
10779 0x1f000: 0x1040080,
10780 0x10800: 0x21000080,
10781 0x11800: 0x1000000,
10782 0x12800: 0x1040000,
10783 0x13800: 0x20040080,
10784 0x14800: 0x20000000,
10785 0x15800: 0x1040080,
10787 0x17800: 0x21040000,
10789 0x19800: 0x21040080,
10791 0x1b800: 0x21000000,
10792 0x1c800: 0x1000080,
10794 0x1e800: 0x20040000,
10795 0x1f800: 0x20000080
10830 0x1000: 0x10002000,
10831 0x1100: 0x10200008,
10832 0x1200: 0x10202008,
10835 0x1500: 0x10000000,
10836 0x1600: 0x10000008,
10841 0x1b00: 0x10200000,
10843 0x1d00: 0x10002008,
10844 0x1e00: 0x10202000,
10849 0x1380: 0x10000008,
10850 0x1480: 0x10002000,
10852 0x1680: 0x10202008,
10853 0x1780: 0x10200000,
10854 0x1880: 0x10202000,
10855 0x1980: 0x10200008,
10860 0x1e80: 0x10000000,
10947 0x80000001: 0x8020820,
10948 0x80000002: 0x8000820,
10949 0x80000003: 0x8000000,
10950 0x80000004: 0x8020000,
10951 0x80000005: 0x20800,
10952 0x80000006: 0x20820,
10954 0x80000008: 0x8000020,
10956 0x8000000a: 0x20020,
10957 0x8000000b: 0x8020800,
10959 0x8000000d: 0x8020020,
10960 0x8000000e: 0x8000800,
10961 0x8000000f: 0x20000,
10978 0x80000010: 0x20000,
10980 0x80000012: 0x8020020,
10981 0x80000013: 0x20820,
10983 0x80000015: 0x8020000,
10984 0x80000016: 0x8000000,
10985 0x80000017: 0x8000820,
10986 0x80000018: 0x8020820,
10987 0x80000019: 0x8000020,
10988 0x8000001a: 0x8000800,
10990 0x8000001c: 0x20800,
10992 0x8000001e: 0x20020,
10993 0x8000001f: 0x8020800
10997 // Masks that select the SBOX input
10999 0xf8000001, 0x1f800000, 0x01f80000, 0x001f8000,
11000 0x0001f800, 0x00001f80, 0x000001f8, 0x8000001f
11004 * DES block cipher algorithm.
11006 var DES
= C_algo
.DES
= BlockCipher
.extend({
11007 _doReset: function () {
11009 var key
= this._key
;
11010 var keyWords
= key
.words
;
11012 // Select 56 bits according to PC1
11014 for (var i
= 0; i
< 56; i
++) {
11015 var keyBitPos
= PC1
[i
] - 1;
11016 keyBits
[i
] = (keyWords
[keyBitPos
>>> 5] >>> (31 - keyBitPos
% 32)) & 1;
11019 // Assemble 16 subkeys
11020 var subKeys
= this._subKeys
= [];
11021 for (var nSubKey
= 0; nSubKey
< 16; nSubKey
++) {
11023 var subKey
= subKeys
[nSubKey
] = [];
11026 var bitShift
= BIT_SHIFTS
[nSubKey
];
11028 // Select 48 bits according to PC2
11029 for (var i
= 0; i
< 24; i
++) {
11030 // Select from the left 28 key bits
11031 subKey
[(i
/ 6) | 0] |= keyBits
[((PC2
[i
] - 1) + bitShift
) % 28] << (31 - i
% 6);
11033 // Select from the right 28 key bits
11034 subKey
[4 + ((i
/ 6) | 0)] |= keyBits
[28 + (((PC2
[i
+ 24] - 1) + bitShift
) % 28)] << (31 - i
% 6);
11037 // Since each subkey is applied to an expanded 32-bit input,
11038 // the subkey can be broken into 8 values scaled to 32-bits,
11039 // which allows the key to be used without expansion
11040 subKey
[0] = (subKey
[0] << 1) | (subKey
[0] >>> 31);
11041 for (var i
= 1; i
< 7; i
++) {
11042 subKey
[i
] = subKey
[i
] >>> ((i
- 1) * 4 + 3);
11044 subKey
[7] = (subKey
[7] << 5) | (subKey
[7] >>> 27);
11047 // Compute inverse subkeys
11048 var invSubKeys
= this._invSubKeys
= [];
11049 for (var i
= 0; i
< 16; i
++) {
11050 invSubKeys
[i
] = subKeys
[15 - i
];
11054 encryptBlock: function (M
, offset
) {
11055 this._doCryptBlock(M
, offset
, this._subKeys
);
11058 decryptBlock: function (M
, offset
) {
11059 this._doCryptBlock(M
, offset
, this._invSubKeys
);
11062 _doCryptBlock: function (M
, offset
, subKeys
) {
11064 this._lBlock
= M
[offset
];
11065 this._rBlock
= M
[offset
+ 1];
11067 // Initial permutation
11068 exchangeLR
.call(this, 4, 0x0f0f0f0f);
11069 exchangeLR
.call(this, 16, 0x0000ffff);
11070 exchangeRL
.call(this, 2, 0x33333333);
11071 exchangeRL
.call(this, 8, 0x00ff00ff);
11072 exchangeLR
.call(this, 1, 0x55555555);
11075 for (var round
= 0; round
< 16; round
++) {
11077 var subKey
= subKeys
[round
];
11078 var lBlock
= this._lBlock
;
11079 var rBlock
= this._rBlock
;
11081 // Feistel function
11083 for (var i
= 0; i
< 8; i
++) {
11084 f
|= SBOX_P
[i
][((rBlock
^ subKey
[i
]) & SBOX_MASK
[i
]) >>> 0];
11086 this._lBlock
= rBlock
;
11087 this._rBlock
= lBlock
^ f
;
11090 // Undo swap from last round
11091 var t
= this._lBlock
;
11092 this._lBlock
= this._rBlock
;
11095 // Final permutation
11096 exchangeLR
.call(this, 1, 0x55555555);
11097 exchangeRL
.call(this, 8, 0x00ff00ff);
11098 exchangeRL
.call(this, 2, 0x33333333);
11099 exchangeLR
.call(this, 16, 0x0000ffff);
11100 exchangeLR
.call(this, 4, 0x0f0f0f0f);
11103 M
[offset
] = this._lBlock
;
11104 M
[offset
+ 1] = this._rBlock
;
11114 // Swap bits across the left and right words
11115 function exchangeLR(offset
, mask
) {
11116 var t
= ((this._lBlock
>>> offset
) ^ this._rBlock
) & mask
;
11118 this._lBlock
^= t
<< offset
;
11121 function exchangeRL(offset
, mask
) {
11122 var t
= ((this._rBlock
>>> offset
) ^ this._lBlock
) & mask
;
11124 this._rBlock
^= t
<< offset
;
11128 * Shortcut functions to the cipher's object interface.
11132 * var ciphertext = CryptoJS.DES.encrypt(message, key, cfg);
11133 * var plaintext = CryptoJS.DES.decrypt(ciphertext, key, cfg);
11135 C
.DES
= BlockCipher
._createHelper(DES
);
11138 * Triple-DES block cipher algorithm.
11140 var TripleDES
= C_algo
.TripleDES
= BlockCipher
.extend({
11141 _doReset: function () {
11143 var key
= this._key
;
11144 var keyWords
= key
.words
;
11146 // Create DES instances
11147 this._des1
= DES
.createEncryptor(WordArray
.create(keyWords
.slice(0, 2)));
11148 this._des2
= DES
.createEncryptor(WordArray
.create(keyWords
.slice(2, 4)));
11149 this._des3
= DES
.createEncryptor(WordArray
.create(keyWords
.slice(4, 6)));
11152 encryptBlock: function (M
, offset
) {
11153 this._des1
.encryptBlock(M
, offset
);
11154 this._des2
.decryptBlock(M
, offset
);
11155 this._des3
.encryptBlock(M
, offset
);
11158 decryptBlock: function (M
, offset
) {
11159 this._des3
.decryptBlock(M
, offset
);
11160 this._des2
.encryptBlock(M
, offset
);
11161 this._des1
.decryptBlock(M
, offset
);
11172 * Shortcut functions to the cipher's object interface.
11176 * var ciphertext = CryptoJS.TripleDES.encrypt(message, key, cfg);
11177 * var plaintext = CryptoJS.TripleDES.decrypt(ciphertext, key, cfg);
11179 C
.TripleDES
= BlockCipher
._createHelper(TripleDES
);
11183 return CryptoJS
.TripleDES
;
11186 },{"./cipher-core":30,"./core":31,"./enc-base64":32,"./evpkdf":34,"./md5":39}],62:[function(_dereq_
,module
,exports
){
11187 ;(function (root
, factory
) {
11188 if (typeof exports
=== "object") {
11190 module
.exports
= exports
= factory(_dereq_("./core"));
11192 else if (typeof define
=== "function" && define
.amd
) {
11194 define(["./core"], factory
);
11197 // Global (browser)
11198 factory(root
.CryptoJS
);
11200 }(this, function (CryptoJS
) {
11202 (function (undefined) {
11206 var Base
= C_lib
.Base
;
11207 var X32WordArray
= C_lib
.WordArray
;
11212 var C_x64
= C
.x64
= {};
11217 var X64Word
= C_x64
.Word
= Base
.extend({
11219 * Initializes a newly created 64-bit word.
11221 * @param {number} high The high 32 bits.
11222 * @param {number} low The low 32 bits.
11226 * var x64Word = CryptoJS.x64.Word.create(0x00010203, 0x04050607);
11228 init: function (high
, low
) {
11234 * Bitwise NOTs this word.
11236 * @return {X64Word} A new x64-Word object after negating.
11240 * var negated = x64Word.not();
11242 // not: function () {
11243 // var high = ~this.high;
11244 // var low = ~this.low;
11246 // return X64Word.create(high, low);
11250 * Bitwise ANDs this word with the passed word.
11252 * @param {X64Word} word The x64-Word to AND with this word.
11254 * @return {X64Word} A new x64-Word object after ANDing.
11258 * var anded = x64Word.and(anotherX64Word);
11260 // and: function (word) {
11261 // var high = this.high & word.high;
11262 // var low = this.low & word.low;
11264 // return X64Word.create(high, low);
11268 * Bitwise ORs this word with the passed word.
11270 * @param {X64Word} word The x64-Word to OR with this word.
11272 * @return {X64Word} A new x64-Word object after ORing.
11276 * var ored = x64Word.or(anotherX64Word);
11278 // or: function (word) {
11279 // var high = this.high | word.high;
11280 // var low = this.low | word.low;
11282 // return X64Word.create(high, low);
11286 * Bitwise XORs this word with the passed word.
11288 * @param {X64Word} word The x64-Word to XOR with this word.
11290 * @return {X64Word} A new x64-Word object after XORing.
11294 * var xored = x64Word.xor(anotherX64Word);
11296 // xor: function (word) {
11297 // var high = this.high ^ word.high;
11298 // var low = this.low ^ word.low;
11300 // return X64Word.create(high, low);
11304 * Shifts this word n bits to the left.
11306 * @param {number} n The number of bits to shift.
11308 * @return {X64Word} A new x64-Word object after shifting.
11312 * var shifted = x64Word.shiftL(25);
11314 // shiftL: function (n) {
11316 // var high = (this.high << n) | (this.low >>> (32 - n));
11317 // var low = this.low << n;
11319 // var high = this.low << (n - 32);
11323 // return X64Word.create(high, low);
11327 * Shifts this word n bits to the right.
11329 * @param {number} n The number of bits to shift.
11331 * @return {X64Word} A new x64-Word object after shifting.
11335 * var shifted = x64Word.shiftR(7);
11337 // shiftR: function (n) {
11339 // var low = (this.low >>> n) | (this.high << (32 - n));
11340 // var high = this.high >>> n;
11342 // var low = this.high >>> (n - 32);
11346 // return X64Word.create(high, low);
11350 * Rotates this word n bits to the left.
11352 * @param {number} n The number of bits to rotate.
11354 * @return {X64Word} A new x64-Word object after rotating.
11358 * var rotated = x64Word.rotL(25);
11360 // rotL: function (n) {
11361 // return this.shiftL(n).or(this.shiftR(64 - n));
11365 * Rotates this word n bits to the right.
11367 * @param {number} n The number of bits to rotate.
11369 * @return {X64Word} A new x64-Word object after rotating.
11373 * var rotated = x64Word.rotR(7);
11375 // rotR: function (n) {
11376 // return this.shiftR(n).or(this.shiftL(64 - n));
11380 * Adds this word with the passed word.
11382 * @param {X64Word} word The x64-Word to add with this word.
11384 * @return {X64Word} A new x64-Word object after adding.
11388 * var added = x64Word.add(anotherX64Word);
11390 // add: function (word) {
11391 // var low = (this.low + word.low) | 0;
11392 // var carry = (low >>> 0) < (this.low >>> 0) ? 1 : 0;
11393 // var high = (this.high + word.high + carry) | 0;
11395 // return X64Word.create(high, low);
11400 * An array of 64-bit words.
11402 * @property {Array} words The array of CryptoJS.x64.Word objects.
11403 * @property {number} sigBytes The number of significant bytes in this word array.
11405 var X64WordArray
= C_x64
.WordArray
= Base
.extend({
11407 * Initializes a newly created word array.
11409 * @param {Array} words (Optional) An array of CryptoJS.x64.Word objects.
11410 * @param {number} sigBytes (Optional) The number of significant bytes in the words.
11414 * var wordArray = CryptoJS.x64.WordArray.create();
11416 * var wordArray = CryptoJS.x64.WordArray.create([
11417 * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
11418 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
11421 * var wordArray = CryptoJS.x64.WordArray.create([
11422 * CryptoJS.x64.Word.create(0x00010203, 0x04050607),
11423 * CryptoJS.x64.Word.create(0x18191a1b, 0x1c1d1e1f)
11426 init: function (words
, sigBytes
) {
11427 words
= this.words
= words
|| [];
11429 if (sigBytes
!= undefined) {
11430 this.sigBytes
= sigBytes
;
11432 this.sigBytes
= words
.length
* 8;
11437 * Converts this 64-bit word array to a 32-bit word array.
11439 * @return {CryptoJS.lib.WordArray} This word array's data as a 32-bit word array.
11443 * var x32WordArray = x64WordArray.toX32();
11445 toX32: function () {
11447 var x64Words
= this.words
;
11448 var x64WordsLength
= x64Words
.length
;
11452 for (var i
= 0; i
< x64WordsLength
; i
++) {
11453 var x64Word
= x64Words
[i
];
11454 x32Words
.push(x64Word
.high
);
11455 x32Words
.push(x64Word
.low
);
11458 return X32WordArray
.create(x32Words
, this.sigBytes
);
11462 * Creates a copy of this word array.
11464 * @return {X64WordArray} The clone.
11468 * var clone = x64WordArray.clone();
11470 clone: function () {
11471 var clone
= Base
.clone
.call(this);
11473 // Clone "words" array
11474 var words
= clone
.words
= this.words
.slice(0);
11476 // Clone each X64Word object
11477 var wordsLength
= words
.length
;
11478 for (var i
= 0; i
< wordsLength
; i
++) {
11479 words
[i
] = words
[i
].clone();
11491 },{"./core":31}],63:[function(_dereq_
,module
,exports
){
11492 var assert
= _dereq_('assert')
11493 var BigInteger
= _dereq_('bigi')
11495 var Point
= _dereq_('./point')
11497 function Curve(p
, a
, b
, Gx
, Gy
, n
, h
) {
11501 this.G
= Point
.fromAffine(this, Gx
, Gy
)
11505 this.infinity
= new Point(this, null, null, BigInteger
.ZERO
)
11508 this.pOverFour
= p
.add(BigInteger
.ONE
).shiftRight(2)
11511 Curve
.prototype.pointFromX = function(isOdd
, x
) {
11512 var alpha
= x
.pow(3).add(this.a
.multiply(x
)).add(this.b
).mod(this.p
)
11513 var beta
= alpha
.modPow(this.pOverFour
, this.p
)
11516 if (beta
.isEven() ^ !isOdd
) {
11517 y
= this.p
.subtract(y
) // -y % p
11520 return Point
.fromAffine(this, x
, y
)
11523 Curve
.prototype.isInfinity = function(Q
) {
11524 if (Q
=== this.infinity
) return true
11526 return Q
.z
.signum() === 0 && Q
.y
.signum() !== 0
11529 Curve
.prototype.isOnCurve = function(Q
) {
11530 if (this.isInfinity(Q
)) return true
11538 // Check that xQ and yQ are integers in the interval [0, p - 1]
11539 if (x
.signum() < 0 || x
.compareTo(p
) >= 0) return false
11540 if (y
.signum() < 0 || y
.compareTo(p
) >= 0) return false
11542 // and check that y^2 = x^3 + ax + b (mod p)
11543 var lhs
= y
.square().mod(p
)
11544 var rhs
= x
.pow(3).add(a
.multiply(x
)).add(b
).mod(p
)
11545 return lhs
.equals(rhs
)
11549 * Validate an elliptic curve point.
11551 * See SEC 1, section 3.2.2.1: Elliptic Curve Public Key Validation Primitive
11553 Curve
.prototype.validate = function(Q
) {
11555 assert(!this.isInfinity(Q
), 'Point is at infinity')
11556 assert(this.isOnCurve(Q
), 'Point is not on the curve')
11558 // Check nQ = O (where Q is a scalar multiple of G)
11559 var nQ
= Q
.multiply(this.n
)
11560 assert(this.isInfinity(nQ
), 'Point is not a scalar multiple of G')
11565 module
.exports
= Curve
11567 },{"./point":67,"assert":4,"bigi":3}],64:[function(_dereq_
,module
,exports
){
11570 "p": "fffffffdffffffffffffffffffffffff",
11571 "a": "fffffffdfffffffffffffffffffffffc",
11572 "b": "e87579c11079f43dd824993c2cee5ed3",
11573 "n": "fffffffe0000000075a30d1b9038a115",
11575 "Gx": "161ff7528b899b2d0c28607ca52c5b86",
11576 "Gy": "cf5ac8395bafeb13c02da292dded7a83"
11579 "p": "fffffffffffffffffffffffffffffffeffffac73",
11582 "n": "0100000000000000000001b8fa16dfab9aca16b6b3",
11584 "Gx": "3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",
11585 "Gy": "938cf935318fdced6bc28286531733c3f03c4fee"
11588 "p": "ffffffffffffffffffffffffffffffff7fffffff",
11589 "a": "ffffffffffffffffffffffffffffffff7ffffffc",
11590 "b": "1c97befc54bd7a8b65acf89f81d4d4adc565fa45",
11591 "n": "0100000000000000000001f4c8f927aed3ca752257",
11593 "Gx": "4a96b5688ef573284664698968c38bb913cbfc82",
11594 "Gy": "23a628553168947d59dcc912042351377ac5fb32"
11597 "p": "fffffffffffffffffffffffffffffffffffffffeffffee37",
11600 "n": "fffffffffffffffffffffffe26f2fc170f69466a74defd8d",
11602 "Gx": "db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",
11603 "Gy": "9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"
11606 "p": "fffffffffffffffffffffffffffffffeffffffffffffffff",
11607 "a": "fffffffffffffffffffffffffffffffefffffffffffffffc",
11608 "b": "64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",
11609 "n": "ffffffffffffffffffffffff99def836146bc9b1b4d22831",
11611 "Gx": "188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",
11612 "Gy": "07192b95ffc8da78631011ed6b24cdd573f977a11e794811"
11615 "p": "ffffffffffffffffffffffffffffffff000000000000000000000001",
11616 "a": "fffffffffffffffffffffffffffffffefffffffffffffffffffffffe",
11617 "b": "b4050a850c04b3abf54132565044b0b7d7bfd8ba270b39432355ffb4",
11618 "n": "ffffffffffffffffffffffffffff16a2e0b8f03e13dd29455c5c2a3d",
11620 "Gx": "b70e0cbd6bb4bf7f321390b94a03c1d356c21122343280d6115c1d21",
11621 "Gy": "bd376388b5f723fb4c22dfe6cd4375a05a07476444d5819985007e34"
11624 "p": "fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",
11627 "n": "fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",
11629 "Gx": "79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",
11630 "Gy": "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"
11633 "p": "ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",
11634 "a": "ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",
11635 "b": "5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",
11636 "n": "ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",
11638 "Gx": "6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",
11639 "Gy": "4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"
11643 },{}],65:[function(_dereq_
,module
,exports
){
11644 var Point
= _dereq_('./point')
11645 var Curve
= _dereq_('./curve')
11647 var getCurveByName
= _dereq_('./names')
11652 getCurveByName: getCurveByName
11655 },{"./curve":63,"./names":66,"./point":67}],66:[function(_dereq_
,module
,exports
){
11656 var BigInteger
= _dereq_('bigi')
11658 var curves
= _dereq_('./curves')
11659 var Curve
= _dereq_('./curve')
11661 function getCurveByName(name
) {
11662 var curve
= curves
[name
]
11663 if (!curve
) return null
11665 var p
= new BigInteger(curve
.p
, 16)
11666 var a
= new BigInteger(curve
.a
, 16)
11667 var b
= new BigInteger(curve
.b
, 16)
11668 var n
= new BigInteger(curve
.n
, 16)
11669 var h
= new BigInteger(curve
.h
, 16)
11670 var Gx
= new BigInteger(curve
.Gx
, 16)
11671 var Gy
= new BigInteger(curve
.Gy
, 16)
11673 return new Curve(p
, a
, b
, Gx
, Gy
, n
, h
)
11676 module
.exports
= getCurveByName
11678 },{"./curve":63,"./curves":64,"bigi":3}],67:[function(_dereq_
,module
,exports
){
11679 (function (Buffer
){
11680 var assert
= _dereq_('assert')
11681 var BigInteger
= _dereq_('bigi')
11683 var THREE
= BigInteger
.valueOf(3)
11685 function Point(curve
, x
, y
, z
) {
11686 assert
.notStrictEqual(z
, undefined, 'Missing Z coordinate')
11694 this.compressed
= true
11697 Object
.defineProperty(Point
.prototype, 'zInv', {
11699 if (this._zInv
=== null) {
11700 this._zInv
= this.z
.modInverse(this.curve
.p
)
11707 Object
.defineProperty(Point
.prototype, 'affineX', {
11709 return this.x
.multiply(this.zInv
).mod(this.curve
.p
)
11713 Object
.defineProperty(Point
.prototype, 'affineY', {
11715 return this.y
.multiply(this.zInv
).mod(this.curve
.p
)
11719 Point
.fromAffine = function(curve
, x
, y
) {
11720 return new Point(curve
, x
, y
, BigInteger
.ONE
)
11723 Point
.prototype.equals = function(other
) {
11724 if (other
=== this) return true
11725 if (this.curve
.isInfinity(this)) return this.curve
.isInfinity(other
)
11726 if (this.curve
.isInfinity(other
)) return this.curve
.isInfinity(this)
11728 // u = Y2 * Z1 - Y1 * Z2
11729 var u
= other
.y
.multiply(this.z
).subtract(this.y
.multiply(other
.z
)).mod(this.curve
.p
)
11731 if (u
.signum() !== 0) return false
11733 // v = X2 * Z1 - X1 * Z2
11734 var v
= other
.x
.multiply(this.z
).subtract(this.x
.multiply(other
.z
)).mod(this.curve
.p
)
11736 return v
.signum() === 0
11739 Point
.prototype.negate = function() {
11740 var y
= this.curve
.p
.subtract(this.y
)
11742 return new Point(this.curve
, this.x
, y
, this.z
)
11745 Point
.prototype.add = function(b
) {
11746 if (this.curve
.isInfinity(this)) return b
11747 if (this.curve
.isInfinity(b
)) return this
11754 // u = Y2 * Z1 - Y1 * Z2
11755 var u
= y2
.multiply(this.z
).subtract(y1
.multiply(b
.z
)).mod(this.curve
.p
)
11756 // v = X2 * Z1 - X1 * Z2
11757 var v
= x2
.multiply(this.z
).subtract(x1
.multiply(b
.z
)).mod(this.curve
.p
)
11759 if (v
.signum() === 0) {
11760 if (u
.signum() === 0) {
11761 return this.twice() // this == b, so double
11764 return this.curve
.infinity
// this = -b, so infinity
11767 var v2
= v
.square()
11768 var v3
= v2
.multiply(v
)
11769 var x1v2
= x1
.multiply(v2
)
11770 var zu2
= u
.square().multiply(this.z
)
11772 // x3 = v * (z2 * (z1 * u^2 - 2 * x1 * v^2) - v^3)
11773 var x3
= zu2
.subtract(x1v2
.shiftLeft(1)).multiply(b
.z
).subtract(v3
).multiply(v
).mod(this.curve
.p
)
11774 // y3 = z2 * (3 * x1 * u * v^2 - y1 * v^3 - z1 * u^3) + u * v^3
11775 var y3
= x1v2
.multiply(THREE
).multiply(u
).subtract(y1
.multiply(v3
)).subtract(zu2
.multiply(u
)).multiply(b
.z
).add(u
.multiply(v3
)).mod(this.curve
.p
)
11776 // z3 = v^3 * z1 * z2
11777 var z3
= v3
.multiply(this.z
).multiply(b
.z
).mod(this.curve
.p
)
11779 return new Point(this.curve
, x3
, y3
, z3
)
11782 Point
.prototype.twice = function() {
11783 if (this.curve
.isInfinity(this)) return this
11784 if (this.y
.signum() === 0) return this.curve
.infinity
11789 var y1z1
= y1
.multiply(this.z
)
11790 var y1sqz1
= y1z1
.multiply(y1
).mod(this.curve
.p
)
11791 var a
= this.curve
.a
11793 // w = 3 * x1^2 + a * z1^2
11794 var w
= x1
.square().multiply(THREE
)
11796 if (a
.signum() !== 0) {
11797 w
= w
.add(this.z
.square().multiply(a
))
11800 w
= w
.mod(this.curve
.p
)
11801 // x3 = 2 * y1 * z1 * (w^2 - 8 * x1 * y1^2 * z1)
11802 var x3
= w
.square().subtract(x1
.shiftLeft(3).multiply(y1sqz1
)).shiftLeft(1).multiply(y1z1
).mod(this.curve
.p
)
11803 // y3 = 4 * y1^2 * z1 * (3 * w * x1 - 2 * y1^2 * z1) - w^3
11804 var y3
= w
.multiply(THREE
).multiply(x1
).subtract(y1sqz1
.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1
).subtract(w
.pow(3)).mod(this.curve
.p
)
11805 // z3 = 8 * (y1 * z1)^3
11806 var z3
= y1z1
.pow(3).shiftLeft(3).mod(this.curve
.p
)
11808 return new Point(this.curve
, x3
, y3
, z3
)
11811 // Simple NAF (Non-Adjacent Form) multiplication algorithm
11812 // TODO: modularize the multiplication algorithm
11813 Point
.prototype.multiply = function(k
) {
11814 if (this.curve
.isInfinity(this)) return this
11815 if (k
.signum() === 0) return this.curve
.infinity
11818 var h
= e
.multiply(THREE
)
11820 var neg
= this.negate()
11823 for (var i
= h
.bitLength() - 2; i
> 0; --i
) {
11826 var hBit
= h
.testBit(i
)
11827 var eBit
= e
.testBit(i
)
11829 if (hBit
!= eBit
) {
11830 R
= R
.add(hBit
? this : neg
)
11837 // Compute this*j + x*k (simultaneous multiplication)
11838 Point
.prototype.multiplyTwo = function(j
, x
, k
) {
11841 if (j
.bitLength() > k
.bitLength())
11842 i
= j
.bitLength() - 1
11844 i
= k
.bitLength() - 1
11846 var R
= this.curve
.infinity
11847 var both
= this.add(x
)
11852 var jBit
= j
.testBit(i
)
11853 var kBit
= k
.testBit(i
)
11874 Point
.prototype.getEncoded = function(compressed
) {
11875 if (compressed
== undefined) compressed
= this.compressed
11876 if (this.curve
.isInfinity(this)) return new Buffer('00', 'hex') // Infinity point encoded is simply '00'
11878 var x
= this.affineX
11879 var y
= this.affineY
11883 // Determine size of q in bytes
11884 var byteLength
= Math
.floor((this.curve
.p
.bitLength() + 7) / 8)
11888 buffer
= new Buffer(1 + byteLength
)
11889 buffer
.writeUInt8(y
.isEven() ? 0x02 : 0x03, 0)
11893 buffer
= new Buffer(1 + byteLength
+ byteLength
)
11894 buffer
.writeUInt8(0x04, 0)
11896 y
.toBuffer(byteLength
).copy(buffer
, 1 + byteLength
)
11899 x
.toBuffer(byteLength
).copy(buffer
, 1)
11904 Point
.decodeFrom = function(curve
, buffer
) {
11905 var type
= buffer
.readUInt8(0)
11906 var compressed
= (type
!== 4)
11908 var x
= BigInteger
.fromBuffer(buffer
.slice(1, 33))
11909 var byteLength
= Math
.floor((curve
.p
.bitLength() + 7) / 8)
11913 assert
.equal(buffer
.length
, byteLength
+ 1, 'Invalid sequence length')
11914 assert(type
=== 0x02 || type
=== 0x03, 'Invalid sequence tag')
11916 var isOdd
= (type
=== 0x03)
11917 Q
= curve
.pointFromX(isOdd
, x
)
11920 assert
.equal(buffer
.length
, 1 + byteLength
+ byteLength
, 'Invalid sequence length')
11922 var y
= BigInteger
.fromBuffer(buffer
.slice(1 + byteLength
))
11923 Q
= Point
.fromAffine(curve
, x
, y
)
11926 Q
.compressed
= compressed
11930 Point
.prototype.toString = function () {
11931 if (this.curve
.isInfinity(this)) return '(INFINITY)'
11933 return '(' + this.affineX
.toString() + ',' + this.affineY
.toString() + ')'
11936 module
.exports
= Point
11938 }).call(this,_dereq_("buffer").Buffer
)
11939 },{"assert":4,"bigi":3,"buffer":8}],68:[function(_dereq_
,module
,exports
){
11940 (function (process
,Buffer
){
11941 // Closure compiler error - result of 'not' operator not being used
11942 //!function(globals){
11943 (function(globals
){
11947 if (typeof define
!== 'undefined' && define
.amd
) { //require.js / AMD
11948 define([], function() {
11949 return secureRandom
11951 } else if (typeof module
!== 'undefined' && module
.exports
) { //CommonJS
11952 module
.exports
= secureRandom
11953 } else { //script / browser
11954 globals
.secureRandom
= secureRandom
11958 //options.type is the only valid option
11959 function secureRandom(count
, options
) {
11960 options
= options
|| {type: 'Array'}
11961 //we check for process.pid to prevent browserify from tricking us
11962 if (typeof process
!= 'undefined' && typeof process
.pid
== 'number') {
11963 return nodeRandom(count
, options
)
11965 var crypto
= window
.crypto
|| window
.msCrypto
11966 if (!crypto
) throw new Error("Your browser does not support window.crypto.")
11967 return browserRandom(count
, options
)
11971 function nodeRandom(count
, options
) {
11972 var crypto
= _dereq_('crypto')
11973 var buf
= crypto
.randomBytes(count
)
11975 switch (options
.type
) {
11977 return [].slice
.call(buf
)
11981 var arr
= new Uint8Array(count
)
11982 for (var i
= 0; i
< count
; ++i
) { arr
[i
] = buf
.readUInt8(i
) }
11985 throw new Error(options
.type
+ " is unsupported.")
11989 function browserRandom(count
, options
) {
11990 var nativeArr
= new Uint8Array(count
)
11991 var crypto
= window
.crypto
|| window
.msCrypto
11992 crypto
.getRandomValues(nativeArr
)
11994 switch (options
.type
) {
11996 return [].slice
.call(nativeArr
)
11998 try { var b
= new Buffer(1) } catch(e
) { throw new Error('Buffer not supported in this environment. Use Node.js or Browserify for browser support.')}
11999 return new Buffer(nativeArr
)
12003 throw new Error(options
.type
+ " is unsupported.")
12007 secureRandom
.randomArray = function(byteCount
) {
12008 return secureRandom(byteCount
, {type: 'Array'})
12011 secureRandom
.randomUint8Array = function(byteCount
) {
12012 return secureRandom(byteCount
, {type: 'Uint8Array'})
12015 secureRandom
.randomBuffer = function(byteCount
) {
12016 return secureRandom(byteCount
, {type: 'Buffer'})
12022 }).call(this,_dereq_("FWaASH"),_dereq_("buffer").Buffer
)
12023 },{"FWaASH":12,"buffer":8,"crypto":7}],69:[function(_dereq_
,module
,exports
){
12024 (function (Buffer
){
12025 var assert
= _dereq_('assert')
12026 var base58check
= _dereq_('./base58check')
12027 var networks
= _dereq_('./networks')
12028 var scripts
= _dereq_('./scripts')
12030 function findScriptTypeByVersion(version
) {
12031 for (var networkName
in networks
) {
12032 var network
= networks
[networkName
]
12034 if (version
=== network
.pubKeyHash
) return 'pubkeyhash'
12035 if (version
=== network
.scriptHash
) return 'scripthash'
12039 function Address(hash
, version
) {
12040 assert(Buffer
.isBuffer(hash
), 'Expected Buffer, got ' + hash
)
12041 assert
.strictEqual(hash
.length
, 20, 'Invalid hash length')
12042 assert
.strictEqual(version
& 0xff, version
, 'Invalid version byte')
12045 this.version
= version
12048 // Import functions
12049 Address
.fromBase58Check = function(string
) {
12050 var payload
= base58check
.decode(string
)
12051 var version
= payload
.readUInt8(0)
12052 var hash
= payload
.slice(1)
12054 return new Address(hash
, version
)
12057 Address
.fromOutputScript = function(script
, network
) {
12058 network
= network
|| networks
.bitcoin
12060 var type
= scripts
.classifyOutput(script
)
12062 if (type
=== 'pubkeyhash') return new Address(script
.chunks
[2], network
.pubKeyHash
)
12063 if (type
=== 'scripthash') return new Address(script
.chunks
[1], network
.scriptHash
)
12065 assert(false, type
+ ' has no matching Address')
12068 // Export functions
12069 Address
.prototype.toBase58Check = function () {
12070 var payload
= new Buffer(21)
12071 payload
.writeUInt8(this.version
, 0)
12072 this.hash
.copy(payload
, 1)
12074 return base58check
.encode(payload
)
12077 Address
.prototype.toOutputScript = function() {
12078 var scriptType
= findScriptTypeByVersion(this.version
)
12080 if (scriptType
=== 'pubkeyhash') return scripts
.pubKeyHashOutput(this.hash
)
12081 if (scriptType
=== 'scripthash') return scripts
.scriptHashOutput(this.hash
)
12083 assert(false, this.toString() + ' has no matching Script')
12086 Address
.prototype.toString
= Address
.prototype.toBase58Check
12088 module
.exports
= Address
12090 }).call(this,_dereq_("buffer").Buffer
)
12091 },{"./base58check":70,"./networks":81,"./scripts":84,"assert":4,"buffer":8}],70:[function(_dereq_
,module
,exports
){
12092 (function (Buffer
){
12093 // https://en.bitcoin.it/wiki/Base58Check_encoding
12094 var assert
= _dereq_('assert')
12095 var base58
= _dereq_('bs58')
12096 var crypto
= _dereq_('./crypto')
12098 // Encode a buffer as a base58-check-encoded string
12099 function encode(payload
) {
12100 var checksum
= crypto
.hash256(payload
).slice(0, 4)
12102 return base58
.encode(Buffer
.concat([
12108 // Decode a base58-check-encoded string to a buffer
12109 function decode(string
) {
12110 var buffer
= base58
.decode(string
)
12112 var payload
= buffer
.slice(0, -4)
12113 var checksum
= buffer
.slice(-4)
12114 var newChecksum
= crypto
.hash256(payload
).slice(0, 4)
12116 assert
.deepEqual(newChecksum
, checksum
, 'Invalid checksum')
12126 }).call(this,_dereq_("buffer").Buffer
)
12127 },{"./crypto":73,"assert":4,"bs58":15,"buffer":8}],71:[function(_dereq_
,module
,exports
){
12128 var assert
= _dereq_('assert')
12129 var opcodes
= _dereq_('./opcodes')
12131 // https://github.com/feross/buffer/blob/master/index.js#L1127
12132 function verifuint(value
, max
) {
12133 assert(typeof value
=== 'number', 'cannot write a non-number as a number')
12134 assert(value
>= 0, 'specified a negative value for writing an unsigned value')
12135 assert(value
<= max
, 'value is larger than maximum value for type')
12136 assert(Math
.floor(value
) === value
, 'value has a fractional component')
12139 function pushDataSize(i
) {
12140 return i
< opcodes
.OP_PUSHDATA1
? 1
12146 function readPushDataInt(buffer
, offset
) {
12147 var opcode
= buffer
.readUInt8(offset
)
12151 if (opcode
< opcodes
.OP_PUSHDATA1
) {
12156 } else if (opcode
=== opcodes
.OP_PUSHDATA1
) {
12157 number
= buffer
.readUInt8(offset
+ 1)
12161 } else if (opcode
=== opcodes
.OP_PUSHDATA2
) {
12162 number
= buffer
.readUInt16LE(offset
+ 1)
12167 assert
.equal(opcode
, opcodes
.OP_PUSHDATA4
, 'Unexpected opcode')
12169 number
= buffer
.readUInt32LE(offset
+ 1)
12181 function readUInt64LE(buffer
, offset
) {
12182 var a
= buffer
.readUInt32LE(offset
)
12183 var b
= buffer
.readUInt32LE(offset
+ 4)
12186 verifuint(b
+ a
, 0x001fffffffffffff)
12191 function readVarInt(buffer
, offset
) {
12192 var t
= buffer
.readUInt8(offset
)
12201 } else if (t
< 254) {
12202 number
= buffer
.readUInt16LE(offset
+ 1)
12206 } else if (t
< 255) {
12207 number
= buffer
.readUInt32LE(offset
+ 1)
12212 number
= readUInt64LE(buffer
, offset
+ 1)
12222 function writePushDataInt(buffer
, number
, offset
) {
12223 var size
= pushDataSize(number
)
12227 buffer
.writeUInt8(number
, offset
)
12230 } else if (size
=== 2) {
12231 buffer
.writeUInt8(opcodes
.OP_PUSHDATA1
, offset
)
12232 buffer
.writeUInt8(number
, offset
+ 1)
12235 } else if (size
=== 3) {
12236 buffer
.writeUInt8(opcodes
.OP_PUSHDATA2
, offset
)
12237 buffer
.writeUInt16LE(number
, offset
+ 1)
12241 buffer
.writeUInt8(opcodes
.OP_PUSHDATA4
, offset
)
12242 buffer
.writeUInt32LE(number
, offset
+ 1)
12249 function writeUInt64LE(buffer
, value
, offset
) {
12250 verifuint(value
, 0x001fffffffffffff)
12252 buffer
.writeInt32LE(value
& -1, offset
)
12253 buffer
.writeUInt32LE(Math
.floor(value
/ 0x100000000), offset
+ 4)
12256 function varIntSize(i
) {
12259 : i
< 0x100000000 ? 5
12263 function writeVarInt(buffer
, number
, offset
) {
12264 var size
= varIntSize(number
)
12268 buffer
.writeUInt8(number
, offset
)
12271 } else if (size
=== 3) {
12272 buffer
.writeUInt8(253, offset
)
12273 buffer
.writeUInt16LE(number
, offset
+ 1)
12276 } else if (size
=== 5) {
12277 buffer
.writeUInt8(254, offset
)
12278 buffer
.writeUInt32LE(number
, offset
+ 1)
12282 buffer
.writeUInt8(255, offset
)
12283 writeUInt64LE(buffer
, number
, offset
+ 1)
12290 pushDataSize: pushDataSize
,
12291 readPushDataInt: readPushDataInt
,
12292 readUInt64LE: readUInt64LE
,
12293 readVarInt: readVarInt
,
12294 varIntSize: varIntSize
,
12295 writePushDataInt: writePushDataInt
,
12296 writeUInt64LE: writeUInt64LE
,
12297 writeVarInt: writeVarInt
12300 },{"./opcodes":82,"assert":4}],72:[function(_dereq_
,module
,exports
){
12301 (function (Buffer
){
12302 var assert
= _dereq_('assert')
12303 var Crypto
= _dereq_('crypto-js')
12304 var WordArray
= Crypto
.lib
.WordArray
12306 function bufferToWordArray(buffer
) {
12307 assert(Buffer
.isBuffer(buffer
), 'Expected Buffer, got', buffer
)
12310 for (var i
= 0, b
= 0; i
< buffer
.length
; i
++, b
+= 8) {
12311 words
[b
>>> 5] |= buffer
[i
] << (24 - b
% 32)
12314 return new WordArray
.init(words
, buffer
.length
)
12317 function wordArrayToBuffer(wordArray
) {
12318 assert(Array
.isArray(wordArray
.words
), 'Expected WordArray, got' + wordArray
)
12320 var words
= wordArray
.words
12321 var buffer
= new Buffer(words
.length
* 4)
12323 words
.forEach(function(value
, i
) {
12324 buffer
.writeInt32BE(value
& -1, i
* 4)
12331 bufferToWordArray: bufferToWordArray
,
12332 wordArrayToBuffer: wordArrayToBuffer
12335 }).call(this,_dereq_("buffer").Buffer
)
12336 },{"assert":4,"buffer":8,"crypto-js":37}],73:[function(_dereq_
,module
,exports
){
12337 (function (Buffer
){
12338 // Crypto, crypto, where art thou crypto
12339 var assert
= _dereq_('assert')
12340 var CryptoJS
= _dereq_('crypto-js')
12341 var crypto
= _dereq_('crypto')
12342 var convert
= _dereq_('./convert')
12344 function hash160(buffer
) {
12345 return ripemd160(sha256(buffer
))
12348 function hash256(buffer
) {
12349 return sha256(sha256(buffer
))
12352 function ripemd160(buffer
) {
12353 return crypto
.createHash('rmd160').update(buffer
).digest()
12356 function sha1(buffer
) {
12357 return crypto
.createHash('sha1').update(buffer
).digest()
12360 function sha256(buffer
) {
12361 return crypto
.createHash('sha256').update(buffer
).digest()
12364 // FIXME: Name not consistent with others
12365 function HmacSHA256(buffer
, secret
) {
12366 return crypto
.createHmac('sha256', secret
).update(buffer
).digest()
12369 function HmacSHA512(data
, secret
) {
12370 assert(Buffer
.isBuffer(data
), 'Expected Buffer for data, got ' + data
)
12371 assert(Buffer
.isBuffer(secret
), 'Expected Buffer for secret, got ' + secret
)
12373 var dataWords
= convert
.bufferToWordArray(data
)
12374 var secretWords
= convert
.bufferToWordArray(secret
)
12376 var hash
= CryptoJS
.HmacSHA512(dataWords
, secretWords
)
12378 return convert
.wordArrayToBuffer(hash
)
12382 ripemd160: ripemd160
,
12387 HmacSHA256: HmacSHA256
,
12388 HmacSHA512: HmacSHA512
12391 }).call(this,_dereq_("buffer").Buffer
)
12392 },{"./convert":72,"assert":4,"buffer":8,"crypto":19,"crypto-js":37}],74:[function(_dereq_
,module
,exports
){
12393 (function (Buffer
){
12394 var assert
= _dereq_('assert')
12395 var crypto
= _dereq_('./crypto')
12397 var BigInteger
= _dereq_('bigi')
12398 var ECSignature
= _dereq_('./ecsignature')
12399 var Point
= _dereq_('ecurve').Point
12401 // https://tools.ietf.org/html/rfc6979#section-3.2
12402 function deterministicGenerateK(curve
, hash
, d
) {
12403 assert(Buffer
.isBuffer(hash
), 'Hash must be a Buffer, not ' + hash
)
12404 assert
.equal(hash
.length
, 32, 'Hash must be 256 bit')
12405 assert(d
instanceof BigInteger
, 'Private key must be a BigInteger')
12407 var x
= d
.toBuffer(32)
12408 var k
= new Buffer(32)
12409 var v
= new Buffer(32)
12418 k
= crypto
.HmacSHA256(Buffer
.concat([v
, new Buffer([0]), x
, hash
]), k
)
12421 v
= crypto
.HmacSHA256(v
, k
)
12424 k
= crypto
.HmacSHA256(Buffer
.concat([v
, new Buffer([1]), x
, hash
]), k
)
12427 v
= crypto
.HmacSHA256(v
, k
)
12429 // Step H1/H2a, ignored as tlen === qlen (256 bit)
12431 v
= crypto
.HmacSHA256(v
, k
)
12433 var T
= BigInteger
.fromBuffer(v
)
12435 // Step H3, repeat until T is within the interval [1, n - 1]
12436 while ((T
.signum() <= 0) || (T
.compareTo(curve
.n
) >= 0)) {
12437 k
= crypto
.HmacSHA256(Buffer
.concat([v
, new Buffer([0])]), k
)
12438 v
= crypto
.HmacSHA256(v
, k
)
12440 T
= BigInteger
.fromBuffer(v
)
12446 function sign(curve
, hash
, d
) {
12447 var k
= deterministicGenerateK(curve
, hash
, d
)
12451 var Q
= G
.multiply(k
)
12452 var e
= BigInteger
.fromBuffer(hash
)
12454 var r
= Q
.affineX
.mod(n
)
12455 assert
.notEqual(r
.signum(), 0, 'Invalid R value')
12457 var s
= k
.modInverse(n
).multiply(e
.add(d
.multiply(r
))).mod(n
)
12458 assert
.notEqual(s
.signum(), 0, 'Invalid S value')
12460 var N_OVER_TWO
= n
.shiftRight(1)
12462 // enforce low S values, see bip62: 'low s values in signatures'
12463 if (s
.compareTo(N_OVER_TWO
) > 0) {
12467 return new ECSignature(r
, s
)
12470 function verify(curve
, hash
, signature
, Q
) {
12471 var e
= BigInteger
.fromBuffer(hash
)
12473 return verifyRaw(curve
, e
, signature
, Q
)
12476 function verifyRaw(curve
, e
, signature
, Q
) {
12480 var r
= signature
.r
12481 var s
= signature
.s
12483 if (r
.signum() === 0 || r
.compareTo(n
) >= 0) return false
12484 if (s
.signum() === 0 || s
.compareTo(n
) >= 0) return false
12486 var c
= s
.modInverse(n
)
12488 var u1
= e
.multiply(c
).mod(n
)
12489 var u2
= r
.multiply(c
).mod(n
)
12491 var point
= G
.multiplyTwo(u1
, Q
, u2
)
12492 var v
= point
.affineX
.mod(n
)
12498 * Recover a public key from a signature.
12500 * See SEC 1: Elliptic Curve Cryptography, section 4.1.6, "Public
12501 * Key Recovery Operation".
12503 * http://www.secg.org/download/aid-780/sec1-v2.pdf
12505 function recoverPubKey(curve
, e
, signature
, i
) {
12506 assert
.strictEqual(i
& 3, i
, 'Recovery param is more than two bits')
12508 var r
= signature
.r
12509 var s
= signature
.s
12511 // A set LSB signifies that the y-coordinate is odd
12514 // The more significant bit specifies whether we should use the
12515 // first or second candidate key.
12516 var isSecondKey
= i
>> 1
12521 // 1.1 Let x = r + jn
12522 var x
= isSecondKey
? r
.add(n
) : r
12523 var R
= curve
.pointFromX(isYOdd
, x
)
12525 // 1.4 Check that nR is at infinity
12526 var nR
= R
.multiply(n
)
12527 assert(curve
.isInfinity(nR
), 'nR is not a valid curve point')
12529 // Compute -e from e
12530 var eNeg
= e
.negate().mod(n
)
12532 // 1.6.1 Compute Q = r^-1 (sR - eG)
12533 // Q = r^-1 (sR + -eG)
12534 var rInv
= r
.modInverse(n
)
12536 var Q
= R
.multiplyTwo(s
, G
, eNeg
).multiply(rInv
)
12543 * Calculate pubkey extraction parameter.
12545 * When extracting a pubkey from a signature, we have to
12546 * distinguish four different cases. Rather than putting this
12547 * burden on the verifier, Bitcoin includes a 2-bit value with the
12550 * This function simply tries all four cases and returns the value
12551 * that resulted in a successful pubkey recovery.
12553 function calcPubKeyRecoveryParam(curve
, e
, signature
, Q
) {
12554 for (var i
= 0; i
< 4; i
++) {
12555 var Qprime
= recoverPubKey(curve
, e
, signature
, i
)
12558 if (Qprime
.equals(Q
)) {
12563 throw new Error('Unable to find valid recovery factor')
12567 calcPubKeyRecoveryParam: calcPubKeyRecoveryParam
,
12568 deterministicGenerateK: deterministicGenerateK
,
12569 recoverPubKey: recoverPubKey
,
12572 verifyRaw: verifyRaw
12575 }).call(this,_dereq_("buffer").Buffer
)
12576 },{"./crypto":73,"./ecsignature":77,"assert":4,"bigi":3,"buffer":8,"ecurve":65}],75:[function(_dereq_
,module
,exports
){
12577 (function (Buffer
){
12578 var assert
= _dereq_('assert')
12579 var base58check
= _dereq_('./base58check')
12580 var ecdsa
= _dereq_('./ecdsa')
12581 var networks
= _dereq_('./networks')
12582 var secureRandom
= _dereq_('secure-random')
12584 var BigInteger
= _dereq_('bigi')
12585 var ECPubKey
= _dereq_('./ecpubkey')
12587 var ecurve
= _dereq_('ecurve')
12588 var curve
= ecurve
.getCurveByName('secp256k1')
12590 function ECKey(d
, compressed
) {
12591 assert(d
.signum() > 0, 'Private key must be greater than 0')
12592 assert(d
.compareTo(curve
.n
) < 0, 'Private key must be less than the curve order')
12594 var Q
= curve
.G
.multiply(d
)
12597 this.pub
= new ECPubKey(Q
, compressed
)
12600 // Static constructors
12601 ECKey
.fromWIF = function(string
) {
12602 var payload
= base58check
.decode(string
)
12603 var compressed
= false
12605 // Ignore the version byte
12606 payload
= payload
.slice(1)
12608 if (payload
.length
=== 33) {
12609 assert
.strictEqual(payload
[32], 0x01, 'Invalid compression flag')
12611 // Truncate the compression flag
12612 payload
= payload
.slice(0, -1)
12616 assert
.equal(payload
.length
, 32, 'Invalid WIF payload length')
12618 var d
= BigInteger
.fromBuffer(payload
)
12619 return new ECKey(d
, compressed
)
12622 ECKey
.makeRandom = function(compressed
, rng
) {
12623 rng
= rng
|| secureRandom
.randomBuffer
12625 var buffer
= rng(32)
12626 assert(Buffer
.isBuffer(buffer
), 'Expected Buffer, got ' + buffer
)
12628 var d
= BigInteger
.fromBuffer(buffer
)
12631 return new ECKey(d
, compressed
)
12634 // Export functions
12635 ECKey
.prototype.toWIF = function(network
) {
12636 network
= network
|| networks
.bitcoin
12638 var bufferLen
= this.pub
.compressed
? 34 : 33
12639 var buffer
= new Buffer(bufferLen
)
12641 buffer
.writeUInt8(network
.wif
, 0)
12642 this.d
.toBuffer(32).copy(buffer
, 1)
12644 if (this.pub
.compressed
) {
12645 buffer
.writeUInt8(0x01, 33)
12648 return base58check
.encode(buffer
)
12652 ECKey
.prototype.sign = function(hash
) {
12653 return ecdsa
.sign(curve
, hash
, this.d
)
12656 module
.exports
= ECKey
12658 }).call(this,_dereq_("buffer").Buffer
)
12659 },{"./base58check":70,"./ecdsa":74,"./ecpubkey":76,"./networks":81,"assert":4,"bigi":3,"buffer":8,"ecurve":65,"secure-random":68}],76:[function(_dereq_
,module
,exports
){
12660 (function (Buffer
){
12661 var assert
= _dereq_('assert')
12662 var crypto
= _dereq_('./crypto')
12663 var ecdsa
= _dereq_('./ecdsa')
12664 var networks
= _dereq_('./networks')
12666 var Address
= _dereq_('./address')
12668 var ecurve
= _dereq_('ecurve')
12669 var curve
= ecurve
.getCurveByName('secp256k1')
12671 function ECPubKey(Q
, compressed
) {
12672 assert(Q
instanceof ecurve
.Point
, 'Expected Point, got ' + Q
)
12674 if (compressed
== undefined) compressed
= true
12675 assert
.strictEqual(typeof compressed
, 'boolean', 'Expected boolean, got ' + compressed
)
12677 this.compressed
= compressed
12681 // Static constructors
12682 ECPubKey
.fromBuffer = function(buffer
) {
12683 var Q
= ecurve
.Point
.decodeFrom(curve
, buffer
)
12684 return new ECPubKey(Q
, Q
.compressed
)
12687 ECPubKey
.fromHex = function(hex
) {
12688 return ECPubKey
.fromBuffer(new Buffer(hex
, 'hex'))
12692 ECPubKey
.prototype.getAddress = function(network
) {
12693 network
= network
|| networks
.bitcoin
12695 return new Address(crypto
.hash160(this.toBuffer()), network
.pubKeyHash
)
12698 ECPubKey
.prototype.verify = function(hash
, signature
) {
12699 return ecdsa
.verify(curve
, hash
, signature
, this.Q
)
12702 // Export functions
12703 ECPubKey
.prototype.toBuffer = function() {
12704 return this.Q
.getEncoded(this.compressed
)
12707 ECPubKey
.prototype.toHex = function() {
12708 return this.toBuffer().toString('hex')
12711 module
.exports
= ECPubKey
12713 }).call(this,_dereq_("buffer").Buffer
)
12714 },{"./address":69,"./crypto":73,"./ecdsa":74,"./networks":81,"assert":4,"buffer":8,"ecurve":65}],77:[function(_dereq_
,module
,exports
){
12715 (function (Buffer
){
12716 var assert
= _dereq_('assert')
12717 var BigInteger
= _dereq_('bigi')
12719 function ECSignature(r
, s
) {
12720 assert(r
instanceof BigInteger
, 'Expected BigInteger, got ' + r
)
12721 assert(s
instanceof BigInteger
, 'Expected BigInteger, got ' + s
)
12726 // Import operations
12727 ECSignature
.parseCompact = function(buffer
) {
12728 assert
.equal(buffer
.length
, 65, 'Invalid signature length')
12729 var i
= buffer
.readUInt8(0) - 27
12732 assert
.equal(i
, i
& 7, 'Invalid signature parameter')
12733 var compressed
= !!(i
& 4)
12735 // Recovery param only
12738 var r
= BigInteger
.fromBuffer(buffer
.slice(1, 33))
12739 var s
= BigInteger
.fromBuffer(buffer
.slice(33))
12742 compressed: compressed
,
12744 signature: new ECSignature(r
, s
)
12748 ECSignature
.fromDER = function(buffer
) {
12749 assert
.equal(buffer
.readUInt8(0), 0x30, 'Not a DER sequence')
12750 assert
.equal(buffer
.readUInt8(1), buffer
.length
- 2, 'Invalid sequence length')
12751 assert
.equal(buffer
.readUInt8(2), 0x02, 'Expected a DER integer')
12753 var rLen
= buffer
.readUInt8(3)
12754 assert(rLen
> 0, 'R length is zero')
12756 var offset
= 4 + rLen
12757 assert
.equal(buffer
.readUInt8(offset
), 0x02, 'Expected a DER integer (2)')
12759 var sLen
= buffer
.readUInt8(offset
+ 1)
12760 assert(sLen
> 0, 'S length is zero')
12762 var rB
= buffer
.slice(4, offset
)
12763 var sB
= buffer
.slice(offset
+ 2)
12766 if (rLen
> 1 && rB
.readUInt8(0) === 0x00) {
12767 assert(rB
.readUInt8(1) & 0x80, 'R value excessively padded')
12770 if (sLen
> 1 && sB
.readUInt8(0) === 0x00) {
12771 assert(sB
.readUInt8(1) & 0x80, 'S value excessively padded')
12774 assert
.equal(offset
, buffer
.length
, 'Invalid DER encoding')
12775 var r
= BigInteger
.fromDERInteger(rB
)
12776 var s
= BigInteger
.fromDERInteger(sB
)
12778 assert(r
.signum() >= 0, 'R value is negative')
12779 assert(s
.signum() >= 0, 'S value is negative')
12781 return new ECSignature(r
, s
)
12784 // FIXME: 0x00, 0x04, 0x80 are SIGHASH_* boundary constants, importing Transaction causes a circular dependency
12785 ECSignature
.parseScriptSignature = function(buffer
) {
12786 var hashType
= buffer
.readUInt8(buffer
.length
- 1)
12787 var hashTypeMod
= hashType
& ~0x80
12789 assert(hashTypeMod
> 0x00 && hashTypeMod
< 0x04, 'Invalid hashType')
12792 signature: ECSignature
.fromDER(buffer
.slice(0, -1)),
12797 // Export operations
12798 ECSignature
.prototype.toCompact = function(i
, compressed
) {
12799 if (compressed
) i
+= 4
12802 var buffer
= new Buffer(65)
12803 buffer
.writeUInt8(i
, 0)
12805 this.r
.toBuffer(32).copy(buffer
, 1)
12806 this.s
.toBuffer(32).copy(buffer
, 33)
12811 ECSignature
.prototype.toDER = function() {
12812 var rBa
= this.r
.toDERInteger()
12813 var sBa
= this.s
.toDERInteger()
12816 sequence
.push(0x02) // INTEGER
12817 sequence
.push(rBa
.length
)
12818 sequence
= sequence
.concat(rBa
)
12820 sequence
.push(0x02) // INTEGER
12821 sequence
.push(sBa
.length
)
12822 sequence
= sequence
.concat(sBa
)
12824 sequence
.unshift(sequence
.length
)
12825 sequence
.unshift(0x30) // SEQUENCE
12827 return new Buffer(sequence
)
12830 ECSignature
.prototype.toScriptSignature = function(hashType
) {
12831 var hashTypeBuffer
= new Buffer(1)
12832 hashTypeBuffer
.writeUInt8(hashType
, 0)
12834 return Buffer
.concat([this.toDER(), hashTypeBuffer
])
12837 module
.exports
= ECSignature
12839 }).call(this,_dereq_("buffer").Buffer
)
12840 },{"assert":4,"bigi":3,"buffer":8}],78:[function(_dereq_
,module
,exports
){
12841 (function (Buffer
){
12842 var assert
= _dereq_('assert')
12843 var base58check
= _dereq_('./base58check')
12844 var crypto
= _dereq_('./crypto')
12845 var networks
= _dereq_('./networks')
12847 var BigInteger
= _dereq_('bigi')
12848 var ECKey
= _dereq_('./eckey')
12849 var ECPubKey
= _dereq_('./ecpubkey')
12851 var ecurve
= _dereq_('ecurve')
12852 var curve
= ecurve
.getCurveByName('secp256k1')
12854 function findBIP32ParamsByVersion(version
) {
12855 for (var name
in networks
) {
12856 var network
= networks
[name
]
12858 for (var type
in network
.bip32
) {
12859 if (version
!= network
.bip32
[type
]) continue
12862 isPrivate: (type
=== 'private'),
12868 assert(false, 'Could not find version ' + version
.toString(16))
12871 function HDNode(K
, chainCode
, network
) {
12872 network
= network
|| networks
.bitcoin
12874 assert(Buffer
.isBuffer(chainCode
), 'Expected Buffer, got ' + chainCode
)
12875 assert(network
.bip32
, 'Unknown BIP32 constants for network')
12877 this.chainCode
= chainCode
12880 this.network
= network
12882 if (K
instanceof BigInteger
) {
12883 this.privKey
= new ECKey(K
, true)
12884 this.pubKey
= this.privKey
.pub
12886 this.pubKey
= new ECPubKey(K
, true)
12890 HDNode
.MASTER_SECRET
= new Buffer('Bitcoin seed')
12891 HDNode
.HIGHEST_BIT
= 0x80000000
12894 HDNode
.fromSeedBuffer = function(seed
, network
) {
12895 var I
= crypto
.HmacSHA512(seed
, HDNode
.MASTER_SECRET
)
12896 var IL
= I
.slice(0, 32)
12897 var IR
= I
.slice(32)
12899 // In case IL is 0 or >= n, the master key is invalid
12900 // This is handled by `new ECKey` in the HDNode constructor
12901 var pIL
= BigInteger
.fromBuffer(IL
)
12903 return new HDNode(pIL
, IR
, network
)
12906 HDNode
.fromSeedHex = function(hex
, network
) {
12907 return HDNode
.fromSeedBuffer(new Buffer(hex
, 'hex'), network
)
12910 HDNode
.fromBase58 = function(string
) {
12911 return HDNode
.fromBuffer(base58check
.decode(string
))
12914 HDNode
.fromBuffer = function(buffer
) {
12915 assert
.strictEqual(buffer
.length
, HDNode
.LENGTH
, 'Invalid buffer length')
12917 // 4 byte: version bytes
12918 var version
= buffer
.readUInt32BE(0)
12919 var params
= findBIP32ParamsByVersion(version
)
12921 // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ...
12922 var depth
= buffer
.readUInt8(4)
12924 // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
12925 var parentFingerprint
= buffer
.readUInt32BE(5)
12927 assert
.strictEqual(parentFingerprint
, 0x00000000, 'Invalid parent fingerprint')
12930 // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
12931 // This is encoded in MSB order. (0x00000000 if master key)
12932 var index
= buffer
.readUInt32BE(9)
12933 assert(depth
> 0 || index
=== 0, 'Invalid index')
12935 // 32 bytes: the chain code
12936 var chainCode
= buffer
.slice(13, 45)
12939 // 33 bytes: private key data (0x00 + k)
12940 if (params
.isPrivate
) {
12941 assert
.strictEqual(buffer
.readUInt8(45), 0x00, 'Invalid private key')
12942 var data
= buffer
.slice(46, 78)
12943 var d
= BigInteger
.fromBuffer(data
)
12944 hd
= new HDNode(d
, chainCode
, params
.network
)
12946 // 33 bytes: public key data (0x02 + X or 0x03 + X)
12948 var data
= buffer
.slice(45, 78)
12949 var Q
= ecurve
.Point
.decodeFrom(curve
, data
)
12950 assert
.equal(Q
.compressed
, true, 'Invalid public key')
12952 // Verify that the X coordinate in the public point corresponds to a point on the curve.
12953 // If not, the extended public key is invalid.
12956 hd
= new HDNode(Q
, chainCode
, params
.network
)
12961 hd
.parentFingerprint
= parentFingerprint
12966 HDNode
.fromHex = function(hex
) {
12967 return HDNode
.fromBuffer(new Buffer(hex
, 'hex'))
12970 HDNode
.prototype.getIdentifier = function() {
12971 return crypto
.hash160(this.pubKey
.toBuffer())
12974 HDNode
.prototype.getFingerprint = function() {
12975 return this.getIdentifier().slice(0, 4)
12978 HDNode
.prototype.getAddress = function() {
12979 return this.pubKey
.getAddress(this.network
)
12982 HDNode
.prototype.toBase58 = function(isPrivate
) {
12983 return base58check
.encode(this.toBuffer(isPrivate
))
12986 HDNode
.prototype.toBuffer = function(isPrivate
) {
12987 if (isPrivate
== undefined) isPrivate
= !!this.privKey
12990 var version
= isPrivate
? this.network
.bip32
.private : this.network
.bip32
.public
12991 var buffer
= new Buffer(HDNode
.LENGTH
)
12993 // 4 bytes: version bytes
12994 buffer
.writeUInt32BE(version
, 0)
12997 // 1 byte: depth: 0x00 for master nodes, 0x01 for level-1 descendants, ....
12998 buffer
.writeUInt8(this.depth
, 4)
13000 // 4 bytes: the fingerprint of the parent's key (0x00000000 if master key)
13001 var fingerprint
= (this.depth
=== 0) ? 0x00000000 : this.parentFingerprint
13002 buffer
.writeUInt32BE(fingerprint
, 5)
13004 // 4 bytes: child number. This is the number i in xi = xpar/i, with xi the key being serialized.
13005 // This is encoded in Big endian. (0x00000000 if master key)
13006 buffer
.writeUInt32BE(this.index
, 9)
13008 // 32 bytes: the chain code
13009 this.chainCode
.copy(buffer
, 13)
13011 // 33 bytes: the public key or private key data
13013 assert(this.privKey
, 'Missing private key')
13015 // 0x00 + k for private keys
13016 buffer
.writeUInt8(0, 45)
13017 this.privKey
.d
.toBuffer(32).copy(buffer
, 46)
13020 // X9.62 encoding for public keys
13021 this.pubKey
.toBuffer().copy(buffer
, 45)
13027 HDNode
.prototype.toHex = function(isPrivate
) {
13028 return this.toBuffer(isPrivate
).toString('hex')
13031 // https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#child-key-derivation-ckd-functions
13032 HDNode
.prototype.derive = function(index
) {
13033 var isHardened
= index
>= HDNode
.HIGHEST_BIT
13034 var indexBuffer
= new Buffer(4)
13035 indexBuffer
.writeUInt32BE(index
, 0)
13041 assert(this.privKey
, 'Could not derive hardened child key')
13043 // data = 0x00 || ser256(kpar) || ser32(index)
13044 data
= Buffer
.concat([
13045 this.privKey
.d
.toBuffer(33),
13051 // data = serP(point(kpar)) || ser32(index)
13052 // = serP(Kpar) || ser32(index)
13053 data
= Buffer
.concat([
13054 this.pubKey
.toBuffer(),
13059 var I
= crypto
.HmacSHA512(data
, this.chainCode
)
13060 var IL
= I
.slice(0, 32)
13061 var IR
= I
.slice(32)
13063 var pIL
= BigInteger
.fromBuffer(IL
)
13065 // In case parse256(IL) >= n, proceed with the next value for i
13066 if (pIL
.compareTo(curve
.n
) >= 0) {
13067 return this.derive(index
+ 1)
13070 // Private parent key -> private child key
13072 if (this.privKey
) {
13073 // ki = parse256(IL) + kpar (mod n)
13074 var ki
= pIL
.add(this.privKey
.d
).mod(curve
.n
)
13076 // In case ki == 0, proceed with the next value for i
13077 if (ki
.signum() === 0) {
13078 return this.derive(index
+ 1)
13081 hd
= new HDNode(ki
, IR
, this.network
)
13083 // Public parent key -> public child key
13085 // Ki = point(parse256(IL)) + Kpar
13087 var Ki
= curve
.G
.multiply(pIL
).add(this.pubKey
.Q
)
13089 // In case Ki is the point at infinity, proceed with the next value for i
13090 if (curve
.isInfinity(Ki
)) {
13091 return this.derive(index
+ 1)
13094 hd
= new HDNode(Ki
, IR
, this.network
)
13097 hd
.depth
= this.depth
+ 1
13099 hd
.parentFingerprint
= this.getFingerprint().readUInt32BE(0)
13104 HDNode
.prototype.deriveHardened = function(index
) {
13105 // Only derives hardened private keys by default
13106 return this.derive(index
+ HDNode
.HIGHEST_BIT
)
13109 HDNode
.prototype.toString
= HDNode
.prototype.toBase58
13111 module
.exports
= HDNode
13113 }).call(this,_dereq_("buffer").Buffer
)
13114 },{"./base58check":70,"./crypto":73,"./eckey":75,"./ecpubkey":76,"./networks":81,"assert":4,"bigi":3,"buffer":8,"ecurve":65}],79:[function(_dereq_
,module
,exports
){
13116 Address: _dereq_('./address'),
13117 base58check: _dereq_('./base58check'),
13118 bufferutils: _dereq_('./bufferutils'),
13119 convert: _dereq_('./convert'),
13120 crypto: _dereq_('./crypto'),
13121 ecdsa: _dereq_('./ecdsa'),
13122 ECKey: _dereq_('./eckey'),
13123 ECPubKey: _dereq_('./ecpubkey'),
13124 ECSignature: _dereq_('./ecsignature'),
13125 Message: _dereq_('./message'),
13126 opcodes: _dereq_('./opcodes'),
13127 HDNode: _dereq_('./hdnode'),
13128 Script: _dereq_('./script'),
13129 scripts: _dereq_('./scripts'),
13130 Transaction: _dereq_('./transaction'),
13131 networks: _dereq_('./networks'),
13132 Wallet: _dereq_('./wallet')
13135 },{"./address":69,"./base58check":70,"./bufferutils":71,"./convert":72,"./crypto":73,"./ecdsa":74,"./eckey":75,"./ecpubkey":76,"./ecsignature":77,"./hdnode":78,"./message":80,"./networks":81,"./opcodes":82,"./script":83,"./scripts":84,"./transaction":85,"./wallet":86}],80:[function(_dereq_
,module
,exports
){
13136 (function (Buffer
){
13137 /// Implements Bitcoin's feature for signing arbitrary messages.
13138 var Address
= _dereq_('./address')
13139 var BigInteger
= _dereq_('bigi')
13140 var bufferutils
= _dereq_('./bufferutils')
13141 var crypto
= _dereq_('./crypto')
13142 var ecdsa
= _dereq_('./ecdsa')
13143 var networks
= _dereq_('./networks')
13145 var Address
= _dereq_('./address')
13146 var ECPubKey
= _dereq_('./ecpubkey')
13147 var ECSignature
= _dereq_('./ecsignature')
13149 var ecurve
= _dereq_('ecurve')
13150 var ecparams
= ecurve
.getCurveByName('secp256k1')
13152 function magicHash(message
, network
) {
13153 var magicPrefix
= new Buffer(network
.magicPrefix
)
13154 var messageBuffer
= new Buffer(message
)
13155 var lengthBuffer
= new Buffer(bufferutils
.varIntSize(messageBuffer
.length
))
13156 bufferutils
.writeVarInt(lengthBuffer
, messageBuffer
.length
, 0)
13158 var buffer
= Buffer
.concat([magicPrefix
, lengthBuffer
, messageBuffer
])
13159 return crypto
.hash256(buffer
)
13162 function sign(privKey
, message
, network
) {
13163 network
= network
|| networks
.bitcoin
13165 var hash
= magicHash(message
, network
)
13166 var signature
= privKey
.sign(hash
)
13167 var e
= BigInteger
.fromBuffer(hash
)
13168 var i
= ecdsa
.calcPubKeyRecoveryParam(ecparams
, e
, signature
, privKey
.pub
.Q
)
13170 return signature
.toCompact(i
, privKey
.pub
.compressed
)
13173 // TODO: network could be implied from address
13174 function verify(address
, signatureBuffer
, message
, network
) {
13175 if (address
instanceof Address
) {
13176 address
= address
.toString()
13178 network
= network
|| networks
.bitcoin
13180 var hash
= magicHash(message
, network
)
13181 var parsed
= ECSignature
.parseCompact(signatureBuffer
)
13182 var e
= BigInteger
.fromBuffer(hash
)
13183 var Q
= ecdsa
.recoverPubKey(ecparams
, e
, parsed
.signature
, parsed
.i
)
13185 var pubKey
= new ECPubKey(Q
, parsed
.compressed
)
13186 return pubKey
.getAddress(network
).toString() === address
13190 magicHash: magicHash
,
13195 }).call(this,_dereq_("buffer").Buffer
)
13196 },{"./address":69,"./bufferutils":71,"./crypto":73,"./ecdsa":74,"./ecpubkey":76,"./ecsignature":77,"./networks":81,"bigi":3,"buffer":8,"ecurve":65}],81:[function(_dereq_
,module
,exports
){
13197 // https://en.bitcoin.it/wiki/List_of_address_prefixes
13198 // Dogecoin BIP32 is a proposed standard: https://bitcointalk.org/index.php?topic=409731
13202 magicPrefix: '\x18Bitcoin Signed Message:\n',
13204 public: 0x0488b21e,
13205 private: 0x0488ade4
13210 dustThreshold: 546, // https://github.com/bitcoin/bitcoin/blob/v0.9.2/src/core.h#L151-L162
13211 feePerKb: 10000, // https://github.com/bitcoin/bitcoin/blob/v0.9.2/src/main.cpp#L53
13212 estimateFee: estimateFee('bitcoin')
13215 magicPrefix: '\x19Dogecoin Signed Message:\n',
13217 public: 0x02facafd,
13218 private: 0x02fac398
13223 dustThreshold: 0, // https://github.com/dogecoin/dogecoin/blob/v1.7.1/src/core.h#L155-L160
13224 dustSoftThreshold: 100000000, // https://github.com/dogecoin/dogecoin/blob/v1.7.1/src/main.h#L62
13225 feePerKb: 100000000, // https://github.com/dogecoin/dogecoin/blob/v1.7.1/src/main.cpp#L58
13226 estimateFee: estimateFee('dogecoin')
13229 magicPrefix: '\x19Litecoin Signed Message:\n',
13231 public: 0x019da462,
13232 private: 0x019d9cfe
13237 dustThreshold: 0, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.cpp#L360-L365
13238 dustSoftThreshold: 100000, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.h#L53
13239 feePerKb: 100000, // https://github.com/litecoin-project/litecoin/blob/v0.8.7.2/src/main.cpp#L56
13240 estimateFee: estimateFee('litecoin')
13243 magicPrefix: '\x18Bitcoin Signed Message:\n',
13245 public: 0x043587cf,
13246 private: 0x04358394
13251 dustThreshold: 546,
13253 estimateFee: estimateFee('testnet')
13257 function estimateFee(type
) {
13258 return function(tx
) {
13259 var network
= networks
[type
]
13260 var baseFee
= network
.feePerKb
13261 var byteSize
= tx
.toBuffer().length
13263 var fee
= baseFee
* Math
.ceil(byteSize
/ 1000)
13264 if (network
.dustSoftThreshold
== undefined) return fee
13266 tx
.outs
.forEach(function(e
){
13267 if (e
.value
< network
.dustSoftThreshold
) {
13276 module
.exports
= networks
13278 },{}],82:[function(_dereq_
,module
,exports
){
13319 OP_TOALTSTACK : 107,
13320 OP_FROMALTSTACK : 108,
13352 OP_EQUALVERIFY : 136,
13353 OP_RESERVED1 : 137,
13354 OP_RESERVED2 : 138,
13364 OP_0NOTEQUAL : 146,
13377 OP_NUMEQUALVERIFY : 157,
13378 OP_NUMNOTEQUAL : 158,
13380 OP_GREATERTHAN : 160,
13381 OP_LESSTHANOREQUAL : 161,
13382 OP_GREATERTHANOREQUAL : 162,
13389 OP_RIPEMD160 : 166,
13394 OP_CODESEPARATOR : 171,
13396 OP_CHECKSIGVERIFY : 173,
13397 OP_CHECKMULTISIG : 174,
13398 OP_CHECKMULTISIGVERIFY : 175,
13412 // template matching params
13413 OP_PUBKEYHASH : 253,
13415 OP_INVALIDOPCODE : 255
13418 },{}],83:[function(_dereq_
,module
,exports
){
13419 (function (Buffer
){
13420 var assert
= _dereq_('assert')
13421 var bufferutils
= _dereq_('./bufferutils')
13422 var crypto
= _dereq_('./crypto')
13423 var opcodes
= _dereq_('./opcodes')
13425 function Script(buffer
, chunks
) {
13426 assert(Buffer
.isBuffer(buffer
), 'Expected Buffer, got ' + buffer
)
13427 assert(Array
.isArray(chunks
), 'Expected Array, got ' + chunks
)
13429 this.buffer
= buffer
13430 this.chunks
= chunks
13433 // Import operations
13434 Script
.fromASM = function(asm
) {
13435 var strChunks
= asm
.split(' ')
13437 var chunks
= strChunks
.map(function(strChunk
) {
13438 if (strChunk
in opcodes
) {
13439 return opcodes
[strChunk
]
13442 return new Buffer(strChunk
, 'hex')
13446 return Script
.fromChunks(chunks
)
13449 Script
.fromBuffer = function(buffer
) {
13454 while (i
< buffer
.length
) {
13455 var opcode
= buffer
.readUInt8(i
)
13457 if ((opcode
> opcodes
.OP_0
) && (opcode
<= opcodes
.OP_PUSHDATA4
)) {
13458 var d
= bufferutils
.readPushDataInt(buffer
, i
)
13461 var data
= buffer
.slice(i
, i
+ d
.number
)
13467 chunks
.push(opcode
)
13473 return new Script(buffer
, chunks
)
13476 Script
.fromChunks = function(chunks
) {
13477 assert(Array
.isArray(chunks
), 'Expected Array, got ' + chunks
)
13479 var bufferSize
= chunks
.reduce(function(accum
, chunk
) {
13480 if (Buffer
.isBuffer(chunk
)) {
13481 return accum
+ bufferutils
.pushDataSize(chunk
.length
) + chunk
.length
13487 var buffer
= new Buffer(bufferSize
)
13490 chunks
.forEach(function(chunk
) {
13491 if (Buffer
.isBuffer(chunk
)) {
13492 offset
+= bufferutils
.writePushDataInt(buffer
, chunk
.length
, offset
)
13494 chunk
.copy(buffer
, offset
)
13495 offset
+= chunk
.length
13498 buffer
.writeUInt8(chunk
, offset
)
13503 assert
.equal(offset
, buffer
.length
, 'Could not decode chunks')
13504 return new Script(buffer
, chunks
)
13507 Script
.fromHex = function(hex
) {
13508 return Script
.fromBuffer(new Buffer(hex
, 'hex'))
13512 Script
.EMPTY
= Script
.fromChunks([])
13515 Script
.prototype.getHash = function() {
13516 return crypto
.hash160(this.buffer
)
13519 // FIXME: doesn't work for data chunks, maybe time to use buffertools.compare...
13520 Script
.prototype.without = function(needle
) {
13521 return Script
.fromChunks(this.chunks
.filter(function(op
) {
13522 return op
!== needle
13526 // Export operations
13527 var reverseOps
= []
13528 for (var op
in opcodes
) {
13529 var code
= opcodes
[op
]
13530 reverseOps
[code
] = op
13533 Script
.prototype.toASM = function() {
13534 return this.chunks
.map(function(chunk
) {
13535 if (Buffer
.isBuffer(chunk
)) {
13536 return chunk
.toString('hex')
13539 return reverseOps
[chunk
]
13544 Script
.prototype.toBuffer = function() {
13548 Script
.prototype.toHex = function() {
13549 return this.toBuffer().toString('hex')
13552 module
.exports
= Script
13554 }).call(this,_dereq_("buffer").Buffer
)
13555 },{"./bufferutils":71,"./crypto":73,"./opcodes":82,"assert":4,"buffer":8}],84:[function(_dereq_
,module
,exports
){
13556 (function (Buffer
){
13557 var assert
= _dereq_('assert')
13558 var opcodes
= _dereq_('./opcodes')
13560 // FIXME: use ECPubKey, currently the circular dependency breaks everything.
13563 // * Remove ECPubKey.getAddress
13564 // - Minimal change, but likely unpopular
13565 // * Move all script related functionality out of Address
13566 // - Means a lot of changes to Transaction/Wallet
13567 // * Ignore it (existing solution)
13568 // * Some form of hackery with commonjs
13570 var ecurve
= _dereq_('ecurve')
13571 var curve
= ecurve
.getCurveByName('secp256k1')
13573 var ECSignature
= _dereq_('./ecsignature')
13574 var Script
= _dereq_('./script')
13576 function classifyOutput(script
) {
13577 assert(script
instanceof Script
, 'Expected Script, got ', script
)
13579 if (isPubKeyHashOutput
.call(script
)) {
13580 return 'pubkeyhash'
13581 } else if (isScriptHashOutput
.call(script
)) {
13582 return 'scripthash'
13583 } else if (isMultisigOutput
.call(script
)) {
13585 } else if (isPubKeyOutput
.call(script
)) {
13587 } else if (isNulldataOutput
.call(script
)) {
13590 return 'nonstandard'
13594 function classifyInput(script
) {
13595 assert(script
instanceof Script
, 'Expected Script, got ', script
)
13597 if (isPubKeyHashInput
.call(script
)) {
13598 return 'pubkeyhash'
13599 } else if (isScriptHashInput
.call(script
)) {
13600 return 'scripthash'
13601 } else if (isMultisigInput
.call(script
)) {
13603 } else if (isPubKeyInput
.call(script
)) {
13606 return 'nonstandard'
13610 function isCanonicalPubKey(buffer
) {
13611 if (!Buffer
.isBuffer(buffer
)) return false
13615 ecurve
.Point
.decodeFrom(curve
, buffer
)
13617 if (!(e
.message
.match(/Invalid
sequence (length
|tag
)/))) throw e
13625 function isCanonicalSignature(buffer
) {
13626 if (!Buffer
.isBuffer(buffer
)) return false
13629 ECSignature
.parseScriptSignature(buffer
)
13631 if (!(e
.message
.match(/Not a DER sequence
|Invalid sequence length
|Expected a DER integer
|R length is zero
|S length is zero
|R value excessively padded
|S value excessively padded
|R value is negative
|S value is negative
|Invalid hashType
/))) throw e
13639 function isPubKeyHashInput() {
13640 return this.chunks
.length
=== 2 &&
13641 isCanonicalSignature(this.chunks
[0]) &&
13642 isCanonicalPubKey(this.chunks
[1])
13645 function isPubKeyHashOutput() {
13646 return this.chunks
.length
=== 5 &&
13647 this.chunks
[0] === opcodes
.OP_DUP
&&
13648 this.chunks
[1] === opcodes
.OP_HASH160
&&
13649 Buffer
.isBuffer(this.chunks
[2]) &&
13650 this.chunks
[2].length
=== 20 &&
13651 this.chunks
[3] === opcodes
.OP_EQUALVERIFY
&&
13652 this.chunks
[4] === opcodes
.OP_CHECKSIG
13655 function isPubKeyInput() {
13656 return this.chunks
.length
=== 1 &&
13657 isCanonicalSignature(this.chunks
[0])
13660 function isPubKeyOutput() {
13661 return this.chunks
.length
=== 2 &&
13662 isCanonicalPubKey(this.chunks
[0]) &&
13663 this.chunks
[1] === opcodes
.OP_CHECKSIG
13666 function isScriptHashInput() {
13667 if (this.chunks
.length
< 2) return false
13668 var lastChunk
= this.chunks
[this.chunks
.length
- 1]
13670 if (!Buffer
.isBuffer(lastChunk
)) return false
13672 var scriptSig
= Script
.fromChunks(this.chunks
.slice(0, -1))
13673 var scriptPubKey
= Script
.fromBuffer(lastChunk
)
13675 return classifyInput(scriptSig
) === classifyOutput(scriptPubKey
)
13678 function isScriptHashOutput() {
13679 return this.chunks
.length
=== 3 &&
13680 this.chunks
[0] === opcodes
.OP_HASH160
&&
13681 Buffer
.isBuffer(this.chunks
[1]) &&
13682 this.chunks
[1].length
=== 20 &&
13683 this.chunks
[2] === opcodes
.OP_EQUAL
13686 function isMultisigInput() {
13687 return this.chunks
[0] === opcodes
.OP_0
&&
13688 this.chunks
.slice(1).every(isCanonicalSignature
)
13691 function isMultisigOutput() {
13692 if (this.chunks
< 4) return false
13693 if (this.chunks
[this.chunks
.length
- 1] !== opcodes
.OP_CHECKMULTISIG
) return false
13695 var mOp
= this.chunks
[0]
13696 if (mOp
=== opcodes
.OP_0
) return false
13697 if (mOp
< opcodes
.OP_1
) return false
13698 if (mOp
> opcodes
.OP_16
) return false
13700 var nOp
= this.chunks
[this.chunks
.length
- 2]
13701 if (nOp
=== opcodes
.OP_0
) return false
13702 if (nOp
< opcodes
.OP_1
) return false
13703 if (nOp
> opcodes
.OP_16
) return false
13705 var m
= mOp
- (opcodes
.OP_1
- 1)
13706 var n
= nOp
- (opcodes
.OP_1
- 1)
13707 if (n
< m
) return false
13709 var pubKeys
= this.chunks
.slice(1, -2)
13710 if (n
< pubKeys
.length
) return false
13712 return pubKeys
.every(isCanonicalPubKey
)
13715 function isNulldataOutput() {
13716 return this.chunks
[0] === opcodes
.OP_RETURN
13719 // Standard Script Templates
13720 // {pubKey} OP_CHECKSIG
13721 function pubKeyOutput(pubKey
) {
13722 return Script
.fromChunks([
13724 opcodes
.OP_CHECKSIG
13728 // OP_DUP OP_HASH160 {pubKeyHash} OP_EQUALVERIFY OP_CHECKSIG
13729 function pubKeyHashOutput(hash
) {
13730 assert(Buffer
.isBuffer(hash
), 'Expected Buffer, got ' + hash
)
13732 return Script
.fromChunks([
13734 opcodes
.OP_HASH160
,
13736 opcodes
.OP_EQUALVERIFY
,
13737 opcodes
.OP_CHECKSIG
13741 // OP_HASH160 {scriptHash} OP_EQUAL
13742 function scriptHashOutput(hash
) {
13743 assert(Buffer
.isBuffer(hash
), 'Expected Buffer, got ' + hash
)
13745 return Script
.fromChunks([
13746 opcodes
.OP_HASH160
,
13752 // m [pubKeys ...] n OP_CHECKMULTISIG
13753 function multisigOutput(m
, pubKeys
) {
13754 assert(Array
.isArray(pubKeys
), 'Expected Array, got ' + pubKeys
)
13755 assert(pubKeys
.length
>= m
, 'Not enough pubKeys provided')
13757 var pubKeyBuffers
= pubKeys
.map(function(pubKey
) {
13758 return pubKey
.toBuffer()
13760 var n
= pubKeys
.length
13762 return Script
.fromChunks([].concat(
13763 (opcodes
.OP_1
- 1) + m
,
13765 (opcodes
.OP_1
- 1) + n
,
13766 opcodes
.OP_CHECKMULTISIG
13771 function pubKeyInput(signature
) {
13772 assert(Buffer
.isBuffer(signature
), 'Expected Buffer, got ' + signature
)
13774 return Script
.fromChunks([signature
])
13777 // {signature} {pubKey}
13778 function pubKeyHashInput(signature
, pubKey
) {
13779 assert(Buffer
.isBuffer(signature
), 'Expected Buffer, got ' + signature
)
13781 return Script
.fromChunks([signature
, pubKey
.toBuffer()])
13784 // <scriptSig> {serialized scriptPubKey script}
13785 function scriptHashInput(scriptSig
, scriptPubKey
) {
13786 return Script
.fromChunks([].concat(
13788 scriptPubKey
.toBuffer()
13792 // OP_0 [signatures ...]
13793 function multisigInput(signatures
, scriptPubKey
) {
13794 if (scriptPubKey
) {
13795 assert(isMultisigOutput
.call(scriptPubKey
))
13797 var m
= scriptPubKey
.chunks
[0]
13798 var k
= m
- (opcodes
.OP_1
- 1)
13799 assert(k
<= signatures
.length
, 'Not enough signatures provided')
13802 return Script
.fromChunks([].concat(opcodes
.OP_0
, signatures
))
13806 classifyInput: classifyInput
,
13807 classifyOutput: classifyOutput
,
13808 multisigInput: multisigInput
,
13809 multisigOutput: multisigOutput
,
13810 pubKeyHashInput: pubKeyHashInput
,
13811 pubKeyHashOutput: pubKeyHashOutput
,
13812 pubKeyInput: pubKeyInput
,
13813 pubKeyOutput: pubKeyOutput
,
13814 scriptHashInput: scriptHashInput
,
13815 scriptHashOutput: scriptHashOutput
13818 }).call(this,_dereq_("buffer").Buffer
)
13819 },{"./ecsignature":77,"./opcodes":82,"./script":83,"assert":4,"buffer":8,"ecurve":65}],85:[function(_dereq_
,module
,exports
){
13820 (function (Buffer
){
13821 var assert
= _dereq_('assert')
13822 var bufferutils
= _dereq_('./bufferutils')
13823 var crypto
= _dereq_('./crypto')
13824 var opcodes
= _dereq_('./opcodes')
13825 var scripts
= _dereq_('./scripts')
13827 var Address
= _dereq_('./address')
13828 var ECKey
= _dereq_('./eckey')
13829 var ECSignature
= _dereq_('./ecsignature')
13830 var Script
= _dereq_('./script')
13832 Transaction
.DEFAULT_SEQUENCE
= 0xffffffff
13833 Transaction
.SIGHASH_ALL
= 0x01
13834 Transaction
.SIGHASH_NONE
= 0x02
13835 Transaction
.SIGHASH_SINGLE
= 0x03
13836 Transaction
.SIGHASH_ANYONECANPAY
= 0x80
13838 function Transaction() {
13846 * Create a new txin.
13848 * Can be called with any of:
13850 * - A transaction and an index
13851 * - A transaction hash and an index
13853 * Note that this method does not sign the created input.
13855 Transaction
.prototype.addInput = function(tx
, index
, sequence
) {
13856 if (sequence
== undefined) sequence
= Transaction
.DEFAULT_SEQUENCE
13860 if (typeof tx
=== 'string') {
13861 hash
= new Buffer(tx
, 'hex')
13863 // TxId hex is big-endian, we need little-endian
13864 Array
.prototype.reverse
.call(hash
)
13866 } else if (tx
instanceof Transaction
) {
13867 hash
= tx
.getHash()
13873 assert(Buffer
.isBuffer(hash
), 'Expected Transaction, txId or txHash, got ' + tx
)
13874 assert
.equal(hash
.length
, 32, 'Expected hash length of 32, got ' + hash
.length
)
13875 assert
.equal(typeof index
, 'number', 'Expected number index, got ' + index
)
13877 return (this.ins
.push({
13880 script: Script
.EMPTY
,
13886 * Create a new txout.
13888 * Can be called with:
13890 * - A base58 address string and a value
13891 * - An Address object and a value
13892 * - A scriptPubKey Script and a value
13894 Transaction
.prototype.addOutput = function(scriptPubKey
, value
) {
13895 // Attempt to get a valid address if it's a base58 address string
13896 if (typeof scriptPubKey
=== 'string') {
13897 scriptPubKey
= Address
.fromBase58Check(scriptPubKey
)
13900 // Attempt to get a valid script if it's an Address object
13901 if (scriptPubKey
instanceof Address
) {
13902 var address
= scriptPubKey
13904 scriptPubKey
= address
.toOutputScript()
13907 return (this.outs
.push({
13908 script: scriptPubKey
,
13913 Transaction
.prototype.toBuffer = function () {
13914 var txInSize
= this.ins
.reduce(function(a
, x
) {
13915 return a
+ (40 + bufferutils
.varIntSize(x
.script
.buffer
.length
) + x
.script
.buffer
.length
)
13918 var txOutSize
= this.outs
.reduce(function(a
, x
) {
13919 return a
+ (8 + bufferutils
.varIntSize(x
.script
.buffer
.length
) + x
.script
.buffer
.length
)
13922 var buffer
= new Buffer(
13924 bufferutils
.varIntSize(this.ins
.length
) +
13925 bufferutils
.varIntSize(this.outs
.length
) +
13931 function writeSlice(slice
) {
13932 slice
.copy(buffer
, offset
)
13933 offset
+= slice
.length
13935 function writeUInt32(i
) {
13936 buffer
.writeUInt32LE(i
, offset
)
13939 function writeUInt64(i
) {
13940 bufferutils
.writeUInt64LE(buffer
, i
, offset
)
13943 function writeVarInt(i
) {
13944 var n
= bufferutils
.writeVarInt(buffer
, i
, offset
)
13948 writeUInt32(this.version
)
13949 writeVarInt(this.ins
.length
)
13951 this.ins
.forEach(function(txin
) {
13952 writeSlice(txin
.hash
)
13953 writeUInt32(txin
.index
)
13954 writeVarInt(txin
.script
.buffer
.length
)
13955 writeSlice(txin
.script
.buffer
)
13956 writeUInt32(txin
.sequence
)
13959 writeVarInt(this.outs
.length
)
13960 this.outs
.forEach(function(txout
) {
13961 writeUInt64(txout
.value
)
13962 writeVarInt(txout
.script
.buffer
.length
)
13963 writeSlice(txout
.script
.buffer
)
13966 writeUInt32(this.locktime
)
13971 Transaction
.prototype.toHex = function() {
13972 return this.toBuffer().toString('hex')
13976 * Hash transaction for signing a specific input.
13978 * Bitcoin uses a different hash for each signed transaction input. This
13979 * method copies the transaction, makes the necessary changes based on the
13980 * hashType, serializes and finally hashes the result. This hash can then be
13981 * used to sign the transaction input in question.
13983 Transaction
.prototype.hashForSignature = function(prevOutScript
, inIndex
, hashType
) {
13984 assert(inIndex
>= 0, 'Invalid vin index')
13985 assert(inIndex
< this.ins
.length
, 'Invalid vin index')
13986 assert(prevOutScript
instanceof Script
, 'Invalid Script object')
13988 var txTmp
= this.clone()
13989 var hashScript
= prevOutScript
.without(opcodes
.OP_CODESEPARATOR
)
13991 // Blank out other inputs' signatures
13992 txTmp
.ins
.forEach(function(txin
) {
13993 txin
.script
= Script
.EMPTY
13995 txTmp
.ins
[inIndex
].script
= hashScript
13997 var hashTypeModifier
= hashType
& 0x1f
13998 if (hashTypeModifier
=== Transaction
.SIGHASH_NONE
) {
13999 assert(false, 'SIGHASH_NONE not yet supported')
14001 } else if (hashTypeModifier
=== Transaction
.SIGHASH_SINGLE
) {
14002 assert(false, 'SIGHASH_SINGLE not yet supported')
14006 if (hashType
& Transaction
.SIGHASH_ANYONECANPAY
) {
14007 assert(false, 'SIGHASH_ANYONECANPAY not yet supported')
14010 var hashTypeBuffer
= new Buffer(4)
14011 hashTypeBuffer
.writeInt32LE(hashType
, 0)
14013 var buffer
= Buffer
.concat([txTmp
.toBuffer(), hashTypeBuffer
])
14014 return crypto
.hash256(buffer
)
14017 Transaction
.prototype.getHash = function () {
14018 return crypto
.hash256(this.toBuffer())
14021 Transaction
.prototype.getId = function () {
14022 var buffer
= this.getHash()
14024 // Big-endian is used for TxHash
14025 Array
.prototype.reverse
.call(buffer
)
14027 return buffer
.toString('hex')
14030 Transaction
.prototype.clone = function () {
14031 var newTx
= new Transaction()
14032 newTx
.version
= this.version
14033 newTx
.locktime
= this.locktime
14035 newTx
.ins
= this.ins
.map(function(txin
) {
14039 script: txin
.script
,
14040 sequence: txin
.sequence
14044 newTx
.outs
= this.outs
.map(function(txout
) {
14046 script: txout
.script
,
14054 Transaction
.fromBuffer = function(buffer
) {
14056 function readSlice(n
) {
14058 return buffer
.slice(offset
- n
, offset
)
14060 function readUInt32() {
14061 var i
= buffer
.readUInt32LE(offset
)
14065 function readUInt64() {
14066 var i
= bufferutils
.readUInt64LE(buffer
, offset
)
14070 function readVarInt() {
14071 var vi
= bufferutils
.readVarInt(buffer
, offset
)
14076 var tx
= new Transaction()
14077 tx
.version
= readUInt32()
14079 var vinLen
= readVarInt()
14080 for (var i
= 0; i
< vinLen
; ++i
) {
14081 var hash
= readSlice(32)
14082 var vout
= readUInt32()
14083 var scriptLen
= readVarInt()
14084 var script
= readSlice(scriptLen
)
14085 var sequence
= readUInt32()
14090 script: Script
.fromBuffer(script
),
14095 var voutLen
= readVarInt()
14096 for (i
= 0; i
< voutLen
; ++i
) {
14097 var value
= readUInt64()
14098 var scriptLen
= readVarInt()
14099 var script
= readSlice(scriptLen
)
14103 script: Script
.fromBuffer(script
)
14107 tx
.locktime
= readUInt32()
14108 assert
.equal(offset
, buffer
.length
, 'Transaction has unexpected data')
14113 Transaction
.fromHex = function(hex
) {
14114 return Transaction
.fromBuffer(new Buffer(hex
, 'hex'))
14118 * Signs a pubKeyHash output at some index with the given key
14120 Transaction
.prototype.sign = function(index
, privKey
, hashType
) {
14121 var prevOutScript
= privKey
.pub
.getAddress().toOutputScript()
14122 var signature
= this.signInput(index
, prevOutScript
, privKey
, hashType
)
14124 // FIXME: Assumed prior TX was pay-to-pubkey-hash
14125 var scriptSig
= scripts
.pubKeyHashInput(signature
, privKey
.pub
)
14126 this.setInputScript(index
, scriptSig
)
14129 Transaction
.prototype.signInput = function(index
, prevOutScript
, privKey
, hashType
) {
14130 hashType
= hashType
|| Transaction
.SIGHASH_ALL
14132 var hash
= this.hashForSignature(prevOutScript
, index
, hashType
)
14133 var signature
= privKey
.sign(hash
)
14135 return signature
.toScriptSignature(hashType
)
14138 Transaction
.prototype.setInputScript = function(index
, script
) {
14139 this.ins
[index
].script
= script
14142 // FIXME: could be validateInput(index, prevTxOut, pub)
14143 Transaction
.prototype.validateInput = function(index
, prevOutScript
, pubKey
, buffer
) {
14144 var parsed
= ECSignature
.parseScriptSignature(buffer
)
14145 var hash
= this.hashForSignature(prevOutScript
, index
, parsed
.hashType
)
14147 return pubKey
.verify(hash
, parsed
.signature
)
14150 module
.exports
= Transaction
14152 }).call(this,_dereq_("buffer").Buffer
)
14153 },{"./address":69,"./bufferutils":71,"./crypto":73,"./eckey":75,"./ecsignature":77,"./opcodes":82,"./script":83,"./scripts":84,"assert":4,"buffer":8}],86:[function(_dereq_
,module
,exports
){
14154 (function (Buffer
){
14155 var assert
= _dereq_('assert')
14156 var networks
= _dereq_('./networks')
14157 var rng
= _dereq_('secure-random')
14159 var Address
= _dereq_('./address')
14160 var HDNode
= _dereq_('./hdnode')
14161 var Transaction
= _dereq_('./transaction')
14163 function Wallet(seed
, network
) {
14164 network
= network
|| networks
.bitcoin
14166 // Stored in a closure to make accidental serialization less likely
14167 var masterkey
= null
14169 var accountZero
= null
14170 var internalAccount
= null
14171 var externalAccount
= null
14174 this.addresses
= []
14175 this.changeAddresses
= []
14177 // Transaction output data
14180 // Make a new master key
14181 this.newMasterKey = function(seed
) {
14182 seed
= seed
|| new Buffer(rng(32))
14183 masterkey
= HDNode
.fromSeedBuffer(seed
, network
)
14185 // HD first-level child derivation method should be hardened
14186 // See https://bitcointalk.org/index.php?topic=405179.msg4415254#msg4415254
14187 accountZero
= masterkey
.deriveHardened(0)
14188 externalAccount
= accountZero
.derive(0)
14189 internalAccount
= accountZero
.derive(1)
14192 me
.changeAddresses
= []
14197 this.newMasterKey(seed
)
14199 this.generateAddress = function() {
14200 var key
= externalAccount
.derive(this.addresses
.length
)
14201 this.addresses
.push(key
.getAddress().toString())
14202 return this.addresses
[this.addresses
.length
- 1]
14205 this.generateChangeAddress = function() {
14206 var key
= internalAccount
.derive(this.changeAddresses
.length
)
14207 this.changeAddresses
.push(key
.getAddress().toString())
14208 return this.changeAddresses
[this.changeAddresses
.length
- 1]
14211 this.getBalance = function() {
14212 return this.getUnspentOutputs().reduce(function(memo
, output
){
14213 return memo
+ output
.value
14217 this.getUnspentOutputs = function() {
14220 for(var key
in this.outputs
){
14221 var output
= this.outputs
[key
]
14222 if(!output
.to
) utxo
.push(outputToUnspentOutput(output
))
14228 this.setUnspentOutputs = function(utxo
) {
14231 utxo
.forEach(function(uo
){
14232 validateUnspentOutput(uo
)
14233 var o
= unspentOutputToOutput(uo
)
14234 outputs
[o
.from] = o
14237 this.outputs
= outputs
14240 function outputToUnspentOutput(output
){
14241 var hashAndIndex
= output
.from.split(":")
14244 hash: hashAndIndex
[0],
14245 outputIndex: parseInt(hashAndIndex
[1]),
14246 address: output
.address
,
14247 value: output
.value
,
14248 pending: output
.pending
14252 function unspentOutputToOutput(o
) {
14254 var key
= hash
+ ":" + o
.outputIndex
14257 address: o
.address
,
14263 function validateUnspentOutput(uo
) {
14266 if (isNullOrUndefined(uo
.hash
)) {
14267 missingField
= "hash"
14270 var requiredKeys
= ['outputIndex', 'address', 'value']
14271 requiredKeys
.forEach(function (key
) {
14272 if (isNullOrUndefined(uo
[key
])){
14277 if (missingField
) {
14279 'Invalid unspent output: key', missingField
, 'is missing.',
14280 'A valid unspent output must contain'
14282 message
.push(requiredKeys
.join(', '))
14283 message
.push("and hash")
14284 throw new Error(message
.join(' '))
14288 function isNullOrUndefined(value
) {
14289 return value
== undefined
14292 this.processPendingTx = function(tx
){
14293 processTx(tx
, true)
14296 this.processConfirmedTx = function(tx
){
14297 processTx(tx
, false)
14300 function processTx(tx
, isPending
) {
14301 var txid
= tx
.getId()
14303 tx
.outs
.forEach(function(txOut
, i
) {
14307 address
= Address
.fromOutputScript(txOut
.script
, network
).toString()
14309 if (!(e
.message
.match(/has no matching Address
/))) throw e
14312 if (isMyAddress(address
)) {
14313 var output
= txid
+ ':' + i
14315 me
.outputs
[output
] = {
14317 value: txOut
.value
,
14324 tx
.ins
.forEach(function(txIn
, i
) {
14325 // copy and convert to big-endian hex
14326 var txinId
= new Buffer(txIn
.hash
)
14327 Array
.prototype.reverse
.call(txinId
)
14328 txinId
= txinId
.toString('hex')
14330 var output
= txinId
+ ':' + txIn
.index
14332 if (!(output
in me
.outputs
)) return
14335 me
.outputs
[output
].to
= txid
+ ':' + i
14336 me
.outputs
[output
].pending
= true
14338 delete me
.outputs
[output
]
14343 this.createTx = function(to
, value
, fixedFee
, changeAddress
) {
14344 assert(value
> network
.dustThreshold
, value
+ ' must be above dust threshold (' + network
.dustThreshold
+ ' Satoshis)')
14346 var utxos
= getCandidateOutputs(value
)
14348 var subTotal
= value
14351 var tx
= new Transaction()
14352 tx
.addOutput(to
, value
)
14354 for (var i
= 0; i
< utxos
.length
; ++i
) {
14355 var utxo
= utxos
[i
]
14356 addresses
.push(utxo
.address
)
14358 var outpoint
= utxo
.from.split(':')
14359 tx
.addInput(outpoint
[0], parseInt(outpoint
[1]))
14361 var fee
= fixedFee
== undefined ? estimateFeePadChangeOutput(tx
) : fixedFee
14363 accum
+= utxo
.value
14364 subTotal
= value
+ fee
14365 if (accum
>= subTotal
) {
14366 var change
= accum
- subTotal
14368 if (change
> network
.dustThreshold
) {
14369 tx
.addOutput(changeAddress
|| getChangeAddress(), change
)
14376 assert(accum
>= subTotal
, 'Not enough funds (incl. fee): ' + accum
+ ' < ' + subTotal
)
14378 this.signWith(tx
, addresses
)
14382 function getCandidateOutputs() {
14385 for (var key
in me
.outputs
) {
14386 var output
= me
.outputs
[key
]
14387 if (!output
.pending
) unspent
.push(output
)
14390 var sortByValueDesc
= unspent
.sort(function(o1
, o2
){
14391 return o2
.value
- o1
.value
14394 return sortByValueDesc
14397 function estimateFeePadChangeOutput(tx
) {
14398 var tmpTx
= tx
.clone()
14399 tmpTx
.addOutput(getChangeAddress(), network
.dustSoftThreshold
|| 0)
14401 return network
.estimateFee(tmpTx
)
14404 function getChangeAddress() {
14405 if(me
.changeAddresses
.length
=== 0) me
.generateChangeAddress();
14406 return me
.changeAddresses
[me
.changeAddresses
.length
- 1]
14409 this.signWith = function(tx
, addresses
) {
14410 assert
.equal(tx
.ins
.length
, addresses
.length
, 'Number of addresses must match number of transaction inputs')
14412 addresses
.forEach(function(address
, i
) {
14413 var key
= me
.getPrivateKeyForAddress(address
)
14421 this.getMasterKey = function() { return masterkey
}
14422 this.getAccountZero = function() { return accountZero
}
14423 this.getInternalAccount = function() { return internalAccount
}
14424 this.getExternalAccount = function() { return externalAccount
}
14426 this.getPrivateKey = function(index
) {
14427 return externalAccount
.derive(index
).privKey
14430 this.getInternalPrivateKey = function(index
) {
14431 return internalAccount
.derive(index
).privKey
14434 this.getPrivateKeyForAddress = function(address
) {
14436 if((index
= this.addresses
.indexOf(address
)) > -1) {
14437 return this.getPrivateKey(index
)
14438 } else if((index
= this.changeAddresses
.indexOf(address
)) > -1) {
14439 return this.getInternalPrivateKey(index
)
14441 throw new Error('Unknown address. Make sure the address is from the keychain and has been generated.')
14445 function isReceiveAddress(address
){
14446 return me
.addresses
.indexOf(address
) > -1
14449 function isChangeAddress(address
){
14450 return me
.changeAddresses
.indexOf(address
) > -1
14453 function isMyAddress(address
) {
14454 return isReceiveAddress(address
) || isChangeAddress(address
)
14458 module
.exports
= Wallet
14460 }).call(this,_dereq_("buffer").Buffer
)
14461 },{"./address":69,"./hdnode":78,"./networks":81,"./transaction":85,"assert":4,"buffer":8,"secure-random":68}]},{},[79])