spice-html5-rails 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. data/COPYING +674 -0
  2. data/COPYING.LESSER +165 -0
  3. data/LICENSE.txt +15 -0
  4. data/README.md +35 -0
  5. data/lib/spice-html5-rails/version.rb +7 -0
  6. data/lib/spice-html5-rails.rb +10 -0
  7. data/vendor/assets/javascripts/spice-html5.js +25 -0
  8. data/vendor/assets/javascripts/spiceHTML5/atKeynames.js +183 -0
  9. data/vendor/assets/javascripts/spiceHTML5/bitmap.js +51 -0
  10. data/vendor/assets/javascripts/spiceHTML5/cursor.js +92 -0
  11. data/vendor/assets/javascripts/spiceHTML5/display.js +806 -0
  12. data/vendor/assets/javascripts/spiceHTML5/enums.js +282 -0
  13. data/vendor/assets/javascripts/spiceHTML5/inputs.js +271 -0
  14. data/vendor/assets/javascripts/spiceHTML5/lz.js +166 -0
  15. data/vendor/assets/javascripts/spiceHTML5/main.js +177 -0
  16. data/vendor/assets/javascripts/spiceHTML5/png.js +256 -0
  17. data/vendor/assets/javascripts/spiceHTML5/quic.js +1335 -0
  18. data/vendor/assets/javascripts/spiceHTML5/spiceconn.js +455 -0
  19. data/vendor/assets/javascripts/spiceHTML5/spicedataview.js +96 -0
  20. data/vendor/assets/javascripts/spiceHTML5/spicemsg.js +883 -0
  21. data/vendor/assets/javascripts/spiceHTML5/spicetype.js +480 -0
  22. data/vendor/assets/javascripts/spiceHTML5/thirdparty/jsbn.js +589 -0
  23. data/vendor/assets/javascripts/spiceHTML5/thirdparty/prng4.js +79 -0
  24. data/vendor/assets/javascripts/spiceHTML5/thirdparty/rng.js +102 -0
  25. data/vendor/assets/javascripts/spiceHTML5/thirdparty/rsa.js +146 -0
  26. data/vendor/assets/javascripts/spiceHTML5/thirdparty/sha1.js +346 -0
  27. data/vendor/assets/javascripts/spiceHTML5/ticket.js +250 -0
  28. data/vendor/assets/javascripts/spiceHTML5/utils.js +261 -0
  29. data/vendor/assets/javascripts/spiceHTML5/wire.js +123 -0
  30. metadata +108 -0
@@ -0,0 +1,589 @@
1
+ // Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
2
+
3
+ /*
4
+ * Copyright (c) 2003-2005 Tom Wu
5
+ * All Rights Reserved.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
20
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
21
+ *
22
+ * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
23
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
24
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
25
+ * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
26
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ *
28
+ * In addition, the following condition applies:
29
+ *
30
+ * All redistributions must retain an intact copy of this copyright notice
31
+ * and disclaimer.
32
+ */
33
+
34
+
35
+ // Basic JavaScript BN library - subset useful for RSA encryption.
36
+
37
+ // Bits per digit
38
+ var dbits;
39
+
40
+ // JavaScript engine analysis
41
+ var canary = 0xdeadbeefcafe;
42
+ var j_lm = ((canary&0xffffff)==0xefcafe);
43
+
44
+ // (public) Constructor
45
+ function BigInteger(a,b,c) {
46
+ if(a != null)
47
+ if("number" == typeof a) this.fromNumber(a,b,c);
48
+ else if(b == null && "string" != typeof a) this.fromString(a,256);
49
+ else this.fromString(a,b);
50
+ }
51
+
52
+ // return new, unset BigInteger
53
+ function nbi() { return new BigInteger(null); }
54
+
55
+ // am: Compute w_j += (x*this_i), propagate carries,
56
+ // c is initial carry, returns final carry.
57
+ // c < 3*dvalue, x < 2*dvalue, this_i < dvalue
58
+ // We need to select the fastest one that works in this environment.
59
+
60
+ // am1: use a single mult and divide to get the high bits,
61
+ // max digit bits should be 26 because
62
+ // max internal value = 2*dvalue^2-2*dvalue (< 2^53)
63
+ function am1(i,x,w,j,c,n) {
64
+ while(--n >= 0) {
65
+ var v = x*this[i++]+w[j]+c;
66
+ c = Math.floor(v/0x4000000);
67
+ w[j++] = v&0x3ffffff;
68
+ }
69
+ return c;
70
+ }
71
+ // am2 avoids a big mult-and-extract completely.
72
+ // Max digit bits should be <= 30 because we do bitwise ops
73
+ // on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
74
+ function am2(i,x,w,j,c,n) {
75
+ var xl = x&0x7fff, xh = x>>15;
76
+ while(--n >= 0) {
77
+ var l = this[i]&0x7fff;
78
+ var h = this[i++]>>15;
79
+ var m = xh*l+h*xl;
80
+ l = xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);
81
+ c = (l>>>30)+(m>>>15)+xh*h+(c>>>30);
82
+ w[j++] = l&0x3fffffff;
83
+ }
84
+ return c;
85
+ }
86
+ // Alternately, set max digit bits to 28 since some
87
+ // browsers slow down when dealing with 32-bit numbers.
88
+ function am3(i,x,w,j,c,n) {
89
+ var xl = x&0x3fff, xh = x>>14;
90
+ while(--n >= 0) {
91
+ var l = this[i]&0x3fff;
92
+ var h = this[i++]>>14;
93
+ var m = xh*l+h*xl;
94
+ l = xl*l+((m&0x3fff)<<14)+w[j]+c;
95
+ c = (l>>28)+(m>>14)+xh*h;
96
+ w[j++] = l&0xfffffff;
97
+ }
98
+ return c;
99
+ }
100
+ if(j_lm && (navigator.appName == "Microsoft Internet Explorer")) {
101
+ BigInteger.prototype.am = am2;
102
+ dbits = 30;
103
+ }
104
+ else if(j_lm && (navigator.appName != "Netscape")) {
105
+ BigInteger.prototype.am = am1;
106
+ dbits = 26;
107
+ }
108
+ else { // Mozilla/Netscape seems to prefer am3
109
+ BigInteger.prototype.am = am3;
110
+ dbits = 28;
111
+ }
112
+
113
+ BigInteger.prototype.DB = dbits;
114
+ BigInteger.prototype.DM = ((1<<dbits)-1);
115
+ BigInteger.prototype.DV = (1<<dbits);
116
+
117
+ var BI_FP = 52;
118
+ BigInteger.prototype.FV = Math.pow(2,BI_FP);
119
+ BigInteger.prototype.F1 = BI_FP-dbits;
120
+ BigInteger.prototype.F2 = 2*dbits-BI_FP;
121
+
122
+ // Digit conversions
123
+ var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
124
+ var BI_RC = new Array();
125
+ var rr,vv;
126
+ rr = "0".charCodeAt(0);
127
+ for(vv = 0; vv <= 9; ++vv) BI_RC[rr++] = vv;
128
+ rr = "a".charCodeAt(0);
129
+ for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
130
+ rr = "A".charCodeAt(0);
131
+ for(vv = 10; vv < 36; ++vv) BI_RC[rr++] = vv;
132
+
133
+ function int2char(n) { return BI_RM.charAt(n); }
134
+ function intAt(s,i) {
135
+ var c = BI_RC[s.charCodeAt(i)];
136
+ return (c==null)?-1:c;
137
+ }
138
+
139
+ // (protected) copy this to r
140
+ function bnpCopyTo(r) {
141
+ for(var i = this.t-1; i >= 0; --i) r[i] = this[i];
142
+ r.t = this.t;
143
+ r.s = this.s;
144
+ }
145
+
146
+ // (protected) set from integer value x, -DV <= x < DV
147
+ function bnpFromInt(x) {
148
+ this.t = 1;
149
+ this.s = (x<0)?-1:0;
150
+ if(x > 0) this[0] = x;
151
+ else if(x < -1) this[0] = x+DV;
152
+ else this.t = 0;
153
+ }
154
+
155
+ // return bigint initialized to value
156
+ function nbv(i) { var r = nbi(); r.fromInt(i); return r; }
157
+
158
+ // (protected) set from string and radix
159
+ function bnpFromString(s,b) {
160
+ var k;
161
+ if(b == 16) k = 4;
162
+ else if(b == 8) k = 3;
163
+ else if(b == 256) k = 8; // byte array
164
+ else if(b == 2) k = 1;
165
+ else if(b == 32) k = 5;
166
+ else if(b == 4) k = 2;
167
+ else { this.fromRadix(s,b); return; }
168
+ this.t = 0;
169
+ this.s = 0;
170
+ var i = s.length, mi = false, sh = 0;
171
+ while(--i >= 0) {
172
+ var x = (k==8)?s[i]&0xff:intAt(s,i);
173
+ if(x < 0) {
174
+ if(s.charAt(i) == "-") mi = true;
175
+ continue;
176
+ }
177
+ mi = false;
178
+ if(sh == 0)
179
+ this[this.t++] = x;
180
+ else if(sh+k > this.DB) {
181
+ this[this.t-1] |= (x&((1<<(this.DB-sh))-1))<<sh;
182
+ this[this.t++] = (x>>(this.DB-sh));
183
+ }
184
+ else
185
+ this[this.t-1] |= x<<sh;
186
+ sh += k;
187
+ if(sh >= this.DB) sh -= this.DB;
188
+ }
189
+ if(k == 8 && (s[0]&0x80) != 0) {
190
+ this.s = -1;
191
+ if(sh > 0) this[this.t-1] |= ((1<<(this.DB-sh))-1)<<sh;
192
+ }
193
+ this.clamp();
194
+ if(mi) BigInteger.ZERO.subTo(this,this);
195
+ }
196
+
197
+ // (protected) clamp off excess high words
198
+ function bnpClamp() {
199
+ var c = this.s&this.DM;
200
+ while(this.t > 0 && this[this.t-1] == c) --this.t;
201
+ }
202
+
203
+ // (public) return string representation in given radix
204
+ function bnToString(b) {
205
+ if(this.s < 0) return "-"+this.negate().toString(b);
206
+ var k;
207
+ if(b == 16) k = 4;
208
+ else if(b == 8) k = 3;
209
+ else if(b == 2) k = 1;
210
+ else if(b == 32) k = 5;
211
+ else if(b == 4) k = 2;
212
+ else return this.toRadix(b);
213
+ var km = (1<<k)-1, d, m = false, r = "", i = this.t;
214
+ var p = this.DB-(i*this.DB)%k;
215
+ if(i-- > 0) {
216
+ if(p < this.DB && (d = this[i]>>p) > 0) { m = true; r = int2char(d); }
217
+ while(i >= 0) {
218
+ if(p < k) {
219
+ d = (this[i]&((1<<p)-1))<<(k-p);
220
+ d |= this[--i]>>(p+=this.DB-k);
221
+ }
222
+ else {
223
+ d = (this[i]>>(p-=k))&km;
224
+ if(p <= 0) { p += this.DB; --i; }
225
+ }
226
+ if(d > 0) m = true;
227
+ if(m) r += int2char(d);
228
+ }
229
+ }
230
+ return m?r:"0";
231
+ }
232
+
233
+ // (public) -this
234
+ function bnNegate() { var r = nbi(); BigInteger.ZERO.subTo(this,r); return r; }
235
+
236
+ // (public) |this|
237
+ function bnAbs() { return (this.s<0)?this.negate():this; }
238
+
239
+ // (public) return + if this > a, - if this < a, 0 if equal
240
+ function bnCompareTo(a) {
241
+ var r = this.s-a.s;
242
+ if(r != 0) return r;
243
+ var i = this.t;
244
+ r = i-a.t;
245
+ if(r != 0) return r;
246
+ while(--i >= 0) if((r=this[i]-a[i]) != 0) return r;
247
+ return 0;
248
+ }
249
+
250
+ // returns bit length of the integer x
251
+ function nbits(x) {
252
+ var r = 1, t;
253
+ if((t=x>>>16) != 0) { x = t; r += 16; }
254
+ if((t=x>>8) != 0) { x = t; r += 8; }
255
+ if((t=x>>4) != 0) { x = t; r += 4; }
256
+ if((t=x>>2) != 0) { x = t; r += 2; }
257
+ if((t=x>>1) != 0) { x = t; r += 1; }
258
+ return r;
259
+ }
260
+
261
+ // (public) return the number of bits in "this"
262
+ function bnBitLength() {
263
+ if(this.t <= 0) return 0;
264
+ return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));
265
+ }
266
+
267
+ // (protected) r = this << n*DB
268
+ function bnpDLShiftTo(n,r) {
269
+ var i;
270
+ for(i = this.t-1; i >= 0; --i) r[i+n] = this[i];
271
+ for(i = n-1; i >= 0; --i) r[i] = 0;
272
+ r.t = this.t+n;
273
+ r.s = this.s;
274
+ }
275
+
276
+ // (protected) r = this >> n*DB
277
+ function bnpDRShiftTo(n,r) {
278
+ for(var i = n; i < this.t; ++i) r[i-n] = this[i];
279
+ r.t = Math.max(this.t-n,0);
280
+ r.s = this.s;
281
+ }
282
+
283
+ // (protected) r = this << n
284
+ function bnpLShiftTo(n,r) {
285
+ var bs = n%this.DB;
286
+ var cbs = this.DB-bs;
287
+ var bm = (1<<cbs)-1;
288
+ var ds = Math.floor(n/this.DB), c = (this.s<<bs)&this.DM, i;
289
+ for(i = this.t-1; i >= 0; --i) {
290
+ r[i+ds+1] = (this[i]>>cbs)|c;
291
+ c = (this[i]&bm)<<bs;
292
+ }
293
+ for(i = ds-1; i >= 0; --i) r[i] = 0;
294
+ r[ds] = c;
295
+ r.t = this.t+ds+1;
296
+ r.s = this.s;
297
+ r.clamp();
298
+ }
299
+
300
+ // (protected) r = this >> n
301
+ function bnpRShiftTo(n,r) {
302
+ r.s = this.s;
303
+ var ds = Math.floor(n/this.DB);
304
+ if(ds >= this.t) { r.t = 0; return; }
305
+ var bs = n%this.DB;
306
+ var cbs = this.DB-bs;
307
+ var bm = (1<<bs)-1;
308
+ r[0] = this[ds]>>bs;
309
+ for(var i = ds+1; i < this.t; ++i) {
310
+ r[i-ds-1] |= (this[i]&bm)<<cbs;
311
+ r[i-ds] = this[i]>>bs;
312
+ }
313
+ if(bs > 0) r[this.t-ds-1] |= (this.s&bm)<<cbs;
314
+ r.t = this.t-ds;
315
+ r.clamp();
316
+ }
317
+
318
+ // (protected) r = this - a
319
+ function bnpSubTo(a,r) {
320
+ var i = 0, c = 0, m = Math.min(a.t,this.t);
321
+ while(i < m) {
322
+ c += this[i]-a[i];
323
+ r[i++] = c&this.DM;
324
+ c >>= this.DB;
325
+ }
326
+ if(a.t < this.t) {
327
+ c -= a.s;
328
+ while(i < this.t) {
329
+ c += this[i];
330
+ r[i++] = c&this.DM;
331
+ c >>= this.DB;
332
+ }
333
+ c += this.s;
334
+ }
335
+ else {
336
+ c += this.s;
337
+ while(i < a.t) {
338
+ c -= a[i];
339
+ r[i++] = c&this.DM;
340
+ c >>= this.DB;
341
+ }
342
+ c -= a.s;
343
+ }
344
+ r.s = (c<0)?-1:0;
345
+ if(c < -1) r[i++] = this.DV+c;
346
+ else if(c > 0) r[i++] = c;
347
+ r.t = i;
348
+ r.clamp();
349
+ }
350
+
351
+ // (protected) r = this * a, r != this,a (HAC 14.12)
352
+ // "this" should be the larger one if appropriate.
353
+ function bnpMultiplyTo(a,r) {
354
+ var x = this.abs(), y = a.abs();
355
+ var i = x.t;
356
+ r.t = i+y.t;
357
+ while(--i >= 0) r[i] = 0;
358
+ for(i = 0; i < y.t; ++i) r[i+x.t] = x.am(0,y[i],r,i,0,x.t);
359
+ r.s = 0;
360
+ r.clamp();
361
+ if(this.s != a.s) BigInteger.ZERO.subTo(r,r);
362
+ }
363
+
364
+ // (protected) r = this^2, r != this (HAC 14.16)
365
+ function bnpSquareTo(r) {
366
+ var x = this.abs();
367
+ var i = r.t = 2*x.t;
368
+ while(--i >= 0) r[i] = 0;
369
+ for(i = 0; i < x.t-1; ++i) {
370
+ var c = x.am(i,x[i],r,2*i,0,1);
371
+ if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1)) >= x.DV) {
372
+ r[i+x.t] -= x.DV;
373
+ r[i+x.t+1] = 1;
374
+ }
375
+ }
376
+ if(r.t > 0) r[r.t-1] += x.am(i,x[i],r,2*i,0,1);
377
+ r.s = 0;
378
+ r.clamp();
379
+ }
380
+
381
+ // (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
382
+ // r != q, this != m. q or r may be null.
383
+ function bnpDivRemTo(m,q,r) {
384
+ var pm = m.abs();
385
+ if(pm.t <= 0) return;
386
+ var pt = this.abs();
387
+ if(pt.t < pm.t) {
388
+ if(q != null) q.fromInt(0);
389
+ if(r != null) this.copyTo(r);
390
+ return;
391
+ }
392
+ if(r == null) r = nbi();
393
+ var y = nbi(), ts = this.s, ms = m.s;
394
+ var nsh = this.DB-nbits(pm[pm.t-1]); // normalize modulus
395
+ if(nsh > 0) { pm.lShiftTo(nsh,y); pt.lShiftTo(nsh,r); }
396
+ else { pm.copyTo(y); pt.copyTo(r); }
397
+ var ys = y.t;
398
+ var y0 = y[ys-1];
399
+ if(y0 == 0) return;
400
+ var yt = y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);
401
+ var d1 = this.FV/yt, d2 = (1<<this.F1)/yt, e = 1<<this.F2;
402
+ var i = r.t, j = i-ys, t = (q==null)?nbi():q;
403
+ y.dlShiftTo(j,t);
404
+ if(r.compareTo(t) >= 0) {
405
+ r[r.t++] = 1;
406
+ r.subTo(t,r);
407
+ }
408
+ BigInteger.ONE.dlShiftTo(ys,t);
409
+ t.subTo(y,y); // "negative" y so we can replace sub with am later
410
+ while(y.t < ys) y[y.t++] = 0;
411
+ while(--j >= 0) {
412
+ // Estimate quotient digit
413
+ var qd = (r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);
414
+ if((r[i]+=y.am(0,qd,r,j,0,ys)) < qd) { // Try it out
415
+ y.dlShiftTo(j,t);
416
+ r.subTo(t,r);
417
+ while(r[i] < --qd) r.subTo(t,r);
418
+ }
419
+ }
420
+ if(q != null) {
421
+ r.drShiftTo(ys,q);
422
+ if(ts != ms) BigInteger.ZERO.subTo(q,q);
423
+ }
424
+ r.t = ys;
425
+ r.clamp();
426
+ if(nsh > 0) r.rShiftTo(nsh,r); // Denormalize remainder
427
+ if(ts < 0) BigInteger.ZERO.subTo(r,r);
428
+ }
429
+
430
+ // (public) this mod a
431
+ function bnMod(a) {
432
+ var r = nbi();
433
+ this.abs().divRemTo(a,null,r);
434
+ if(this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) a.subTo(r,r);
435
+ return r;
436
+ }
437
+
438
+ // Modular reduction using "classic" algorithm
439
+ function Classic(m) { this.m = m; }
440
+ function cConvert(x) {
441
+ if(x.s < 0 || x.compareTo(this.m) >= 0) return x.mod(this.m);
442
+ else return x;
443
+ }
444
+ function cRevert(x) { return x; }
445
+ function cReduce(x) { x.divRemTo(this.m,null,x); }
446
+ function cMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
447
+ function cSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
448
+
449
+ Classic.prototype.convert = cConvert;
450
+ Classic.prototype.revert = cRevert;
451
+ Classic.prototype.reduce = cReduce;
452
+ Classic.prototype.mulTo = cMulTo;
453
+ Classic.prototype.sqrTo = cSqrTo;
454
+
455
+ // (protected) return "-1/this % 2^DB"; useful for Mont. reduction
456
+ // justification:
457
+ // xy == 1 (mod m)
458
+ // xy = 1+km
459
+ // xy(2-xy) = (1+km)(1-km)
460
+ // x[y(2-xy)] = 1-k^2m^2
461
+ // x[y(2-xy)] == 1 (mod m^2)
462
+ // if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
463
+ // should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
464
+ // JS multiply "overflows" differently from C/C++, so care is needed here.
465
+ function bnpInvDigit() {
466
+ if(this.t < 1) return 0;
467
+ var x = this[0];
468
+ if((x&1) == 0) return 0;
469
+ var y = x&3; // y == 1/x mod 2^2
470
+ y = (y*(2-(x&0xf)*y))&0xf; // y == 1/x mod 2^4
471
+ y = (y*(2-(x&0xff)*y))&0xff; // y == 1/x mod 2^8
472
+ y = (y*(2-(((x&0xffff)*y)&0xffff)))&0xffff; // y == 1/x mod 2^16
473
+ // last step - calculate inverse mod DV directly;
474
+ // assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
475
+ y = (y*(2-x*y%this.DV))%this.DV; // y == 1/x mod 2^dbits
476
+ // we really want the negative inverse, and -DV < y < DV
477
+ return (y>0)?this.DV-y:-y;
478
+ }
479
+
480
+ // Montgomery reduction
481
+ function Montgomery(m) {
482
+ this.m = m;
483
+ this.mp = m.invDigit();
484
+ this.mpl = this.mp&0x7fff;
485
+ this.mph = this.mp>>15;
486
+ this.um = (1<<(m.DB-15))-1;
487
+ this.mt2 = 2*m.t;
488
+ }
489
+
490
+ // xR mod m
491
+ function montConvert(x) {
492
+ var r = nbi();
493
+ x.abs().dlShiftTo(this.m.t,r);
494
+ r.divRemTo(this.m,null,r);
495
+ if(x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) this.m.subTo(r,r);
496
+ return r;
497
+ }
498
+
499
+ // x/R mod m
500
+ function montRevert(x) {
501
+ var r = nbi();
502
+ x.copyTo(r);
503
+ this.reduce(r);
504
+ return r;
505
+ }
506
+
507
+ // x = x/R mod m (HAC 14.32)
508
+ function montReduce(x) {
509
+ while(x.t <= this.mt2) // pad x so am has enough room later
510
+ x[x.t++] = 0;
511
+ for(var i = 0; i < this.m.t; ++i) {
512
+ // faster way of calculating u0 = x[i]*mp mod DV
513
+ var j = x[i]&0x7fff;
514
+ var u0 = (j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;
515
+ // use am to combine the multiply-shift-add into one call
516
+ j = i+this.m.t;
517
+ x[j] += this.m.am(0,u0,x,i,0,this.m.t);
518
+ // propagate carry
519
+ while(x[j] >= x.DV) { x[j] -= x.DV; x[++j]++; }
520
+ }
521
+ x.clamp();
522
+ x.drShiftTo(this.m.t,x);
523
+ if(x.compareTo(this.m) >= 0) x.subTo(this.m,x);
524
+ }
525
+
526
+ // r = "x^2/R mod m"; x != r
527
+ function montSqrTo(x,r) { x.squareTo(r); this.reduce(r); }
528
+
529
+ // r = "xy/R mod m"; x,y != r
530
+ function montMulTo(x,y,r) { x.multiplyTo(y,r); this.reduce(r); }
531
+
532
+ Montgomery.prototype.convert = montConvert;
533
+ Montgomery.prototype.revert = montRevert;
534
+ Montgomery.prototype.reduce = montReduce;
535
+ Montgomery.prototype.mulTo = montMulTo;
536
+ Montgomery.prototype.sqrTo = montSqrTo;
537
+
538
+ // (protected) true iff this is even
539
+ function bnpIsEven() { return ((this.t>0)?(this[0]&1):this.s) == 0; }
540
+
541
+ // (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
542
+ function bnpExp(e,z) {
543
+ if(e > 0xffffffff || e < 1) return BigInteger.ONE;
544
+ var r = nbi(), r2 = nbi(), g = z.convert(this), i = nbits(e)-1;
545
+ g.copyTo(r);
546
+ while(--i >= 0) {
547
+ z.sqrTo(r,r2);
548
+ if((e&(1<<i)) > 0) z.mulTo(r2,g,r);
549
+ else { var t = r; r = r2; r2 = t; }
550
+ }
551
+ return z.revert(r);
552
+ }
553
+
554
+ // (public) this^e % m, 0 <= e < 2^32
555
+ function bnModPowInt(e,m) {
556
+ var z;
557
+ if(e < 256 || m.isEven()) z = new Classic(m); else z = new Montgomery(m);
558
+ return this.exp(e,z);
559
+ }
560
+
561
+ // protected
562
+ BigInteger.prototype.copyTo = bnpCopyTo;
563
+ BigInteger.prototype.fromInt = bnpFromInt;
564
+ BigInteger.prototype.fromString = bnpFromString;
565
+ BigInteger.prototype.clamp = bnpClamp;
566
+ BigInteger.prototype.dlShiftTo = bnpDLShiftTo;
567
+ BigInteger.prototype.drShiftTo = bnpDRShiftTo;
568
+ BigInteger.prototype.lShiftTo = bnpLShiftTo;
569
+ BigInteger.prototype.rShiftTo = bnpRShiftTo;
570
+ BigInteger.prototype.subTo = bnpSubTo;
571
+ BigInteger.prototype.multiplyTo = bnpMultiplyTo;
572
+ BigInteger.prototype.squareTo = bnpSquareTo;
573
+ BigInteger.prototype.divRemTo = bnpDivRemTo;
574
+ BigInteger.prototype.invDigit = bnpInvDigit;
575
+ BigInteger.prototype.isEven = bnpIsEven;
576
+ BigInteger.prototype.exp = bnpExp;
577
+
578
+ // public
579
+ BigInteger.prototype.toString = bnToString;
580
+ BigInteger.prototype.negate = bnNegate;
581
+ BigInteger.prototype.abs = bnAbs;
582
+ BigInteger.prototype.compareTo = bnCompareTo;
583
+ BigInteger.prototype.bitLength = bnBitLength;
584
+ BigInteger.prototype.mod = bnMod;
585
+ BigInteger.prototype.modPowInt = bnModPowInt;
586
+
587
+ // "constants"
588
+ BigInteger.ZERO = nbv(0);
589
+ BigInteger.ONE = nbv(1);
@@ -0,0 +1,79 @@
1
+ // Downloaded from http://www-cs-students.stanford.edu/~tjw/jsbn/ by Jeremy White on 6/1/2012
2
+
3
+ /*
4
+ * Copyright (c) 2003-2005 Tom Wu
5
+ * All Rights Reserved.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining
8
+ * a copy of this software and associated documentation files (the
9
+ * "Software"), to deal in the Software without restriction, including
10
+ * without limitation the rights to use, copy, modify, merge, publish,
11
+ * distribute, sublicense, and/or sell copies of the Software, and to
12
+ * permit persons to whom the Software is furnished to do so, subject to
13
+ * the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be
16
+ * included in all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
19
+ * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
20
+ * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
21
+ *
22
+ * IN NO EVENT SHALL TOM WU BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
23
+ * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER
24
+ * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT ADVISED OF
25
+ * THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT
26
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
27
+ *
28
+ * In addition, the following condition applies:
29
+ *
30
+ * All redistributions must retain an intact copy of this copyright notice
31
+ * and disclaimer.
32
+ */
33
+
34
+
35
+ // prng4.js - uses Arcfour as a PRNG
36
+
37
+ function Arcfour() {
38
+ this.i = 0;
39
+ this.j = 0;
40
+ this.S = new Array();
41
+ }
42
+
43
+ // Initialize arcfour context from key, an array of ints, each from [0..255]
44
+ function ARC4init(key) {
45
+ var i, j, t;
46
+ for(i = 0; i < 256; ++i)
47
+ this.S[i] = i;
48
+ j = 0;
49
+ for(i = 0; i < 256; ++i) {
50
+ j = (j + this.S[i] + key[i % key.length]) & 255;
51
+ t = this.S[i];
52
+ this.S[i] = this.S[j];
53
+ this.S[j] = t;
54
+ }
55
+ this.i = 0;
56
+ this.j = 0;
57
+ }
58
+
59
+ function ARC4next() {
60
+ var t;
61
+ this.i = (this.i + 1) & 255;
62
+ this.j = (this.j + this.S[this.i]) & 255;
63
+ t = this.S[this.i];
64
+ this.S[this.i] = this.S[this.j];
65
+ this.S[this.j] = t;
66
+ return this.S[(t + this.S[this.i]) & 255];
67
+ }
68
+
69
+ Arcfour.prototype.init = ARC4init;
70
+ Arcfour.prototype.next = ARC4next;
71
+
72
+ // Plug in your RNG constructor here
73
+ function prng_newstate() {
74
+ return new Arcfour();
75
+ }
76
+
77
+ // Pool size must be a multiple of 4 and greater than 32.
78
+ // An array of bytes the size of the pool will be passed to init()
79
+ var rng_psize = 256;