UNPKG

123 kBJavaScriptView Raw
1/*! OpenPGP.js v5.0.0-1 - 2021-03-03 - this is LGPL licensed code, see LICENSE/our website https://openpgpjs.org/ for more information. */
2const globalThis = typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
3
4import { c as createCommonjsModule, m as minimalisticAssert, i as inherits_browser, u as utils, b as common, d as common$1, _ as _224, e as _256, f as _384, g as _512, r as ripemd } from './openpgp.mjs';
5import bn from './bn.mjs';
6
7var utils_1 = createCommonjsModule(function (module, exports) {
8
9var utils = exports;
10
11function toArray(msg, enc) {
12 if (Array.isArray(msg))
13 return msg.slice();
14 if (!msg)
15 return [];
16 var res = [];
17 if (typeof msg !== 'string') {
18 for (var i = 0; i < msg.length; i++)
19 res[i] = msg[i] | 0;
20 return res;
21 }
22 if (enc === 'hex') {
23 msg = msg.replace(/[^a-z0-9]+/ig, '');
24 if (msg.length % 2 !== 0)
25 msg = '0' + msg;
26 for (var i = 0; i < msg.length; i += 2)
27 res.push(parseInt(msg[i] + msg[i + 1], 16));
28 } else {
29 for (var i = 0; i < msg.length; i++) {
30 var c = msg.charCodeAt(i);
31 var hi = c >> 8;
32 var lo = c & 0xff;
33 if (hi)
34 res.push(hi, lo);
35 else
36 res.push(lo);
37 }
38 }
39 return res;
40}
41utils.toArray = toArray;
42
43function zero2(word) {
44 if (word.length === 1)
45 return '0' + word;
46 else
47 return word;
48}
49utils.zero2 = zero2;
50
51function toHex(msg) {
52 var res = '';
53 for (var i = 0; i < msg.length; i++)
54 res += zero2(msg[i].toString(16));
55 return res;
56}
57utils.toHex = toHex;
58
59utils.encode = function encode(arr, enc) {
60 if (enc === 'hex')
61 return toHex(arr);
62 else
63 return arr;
64};
65});
66
67var utils_1$1 = createCommonjsModule(function (module, exports) {
68
69var utils = exports;
70
71
72
73
74utils.assert = minimalisticAssert;
75utils.toArray = utils_1.toArray;
76utils.zero2 = utils_1.zero2;
77utils.toHex = utils_1.toHex;
78utils.encode = utils_1.encode;
79
80// Represent num in a w-NAF form
81function getNAF(num, w) {
82 var naf = [];
83 var ws = 1 << (w + 1);
84 var k = num.clone();
85 while (k.cmpn(1) >= 0) {
86 var z;
87 if (k.isOdd()) {
88 var mod = k.andln(ws - 1);
89 if (mod > (ws >> 1) - 1)
90 z = (ws >> 1) - mod;
91 else
92 z = mod;
93 k.isubn(z);
94 } else {
95 z = 0;
96 }
97 naf.push(z);
98
99 // Optimization, shift by word if possible
100 var shift = (k.cmpn(0) !== 0 && k.andln(ws - 1) === 0) ? (w + 1) : 1;
101 for (var i = 1; i < shift; i++)
102 naf.push(0);
103 k.iushrn(shift);
104 }
105
106 return naf;
107}
108utils.getNAF = getNAF;
109
110// Represent k1, k2 in a Joint Sparse Form
111function getJSF(k1, k2) {
112 var jsf = [
113 [],
114 []
115 ];
116
117 k1 = k1.clone();
118 k2 = k2.clone();
119 var d1 = 0;
120 var d2 = 0;
121 while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) {
122
123 // First phase
124 var m14 = (k1.andln(3) + d1) & 3;
125 var m24 = (k2.andln(3) + d2) & 3;
126 if (m14 === 3)
127 m14 = -1;
128 if (m24 === 3)
129 m24 = -1;
130 var u1;
131 if ((m14 & 1) === 0) {
132 u1 = 0;
133 } else {
134 var m8 = (k1.andln(7) + d1) & 7;
135 if ((m8 === 3 || m8 === 5) && m24 === 2)
136 u1 = -m14;
137 else
138 u1 = m14;
139 }
140 jsf[0].push(u1);
141
142 var u2;
143 if ((m24 & 1) === 0) {
144 u2 = 0;
145 } else {
146 var m8 = (k2.andln(7) + d2) & 7;
147 if ((m8 === 3 || m8 === 5) && m14 === 2)
148 u2 = -m24;
149 else
150 u2 = m24;
151 }
152 jsf[1].push(u2);
153
154 // Second phase
155 if (2 * d1 === u1 + 1)
156 d1 = 1 - d1;
157 if (2 * d2 === u2 + 1)
158 d2 = 1 - d2;
159 k1.iushrn(1);
160 k2.iushrn(1);
161 }
162
163 return jsf;
164}
165utils.getJSF = getJSF;
166
167function cachedProperty(obj, name, computer) {
168 var key = '_' + name;
169 obj.prototype[name] = function cachedProperty() {
170 return this[key] !== undefined ? this[key] :
171 this[key] = computer.call(this);
172 };
173}
174utils.cachedProperty = cachedProperty;
175
176function parseBytes(bytes) {
177 return typeof bytes === 'string' ? utils.toArray(bytes, 'hex') :
178 bytes;
179}
180utils.parseBytes = parseBytes;
181
182function intFromLE(bytes) {
183 return new bn(bytes, 'hex', 'le');
184}
185utils.intFromLE = intFromLE;
186});
187
188var r;
189
190var brorand = function rand(len) {
191 if (!r)
192 r = new Rand(null);
193
194 return r.generate(len);
195};
196
197function Rand(rand) {
198 this.rand = rand;
199}
200var Rand_1 = Rand;
201
202Rand.prototype.generate = function generate(len) {
203 return this._rand(len);
204};
205
206// Emulate crypto API using randy
207Rand.prototype._rand = function _rand(n) {
208 if (this.rand.getBytes)
209 return this.rand.getBytes(n);
210
211 var res = new Uint8Array(n);
212 for (var i = 0; i < res.length; i++)
213 res[i] = this.rand.getByte();
214 return res;
215};
216
217if (typeof self === 'object') {
218 if (self.crypto && self.crypto.getRandomValues) {
219 // Modern browsers
220 Rand.prototype._rand = function _rand(n) {
221 var arr = new Uint8Array(n);
222 self.crypto.getRandomValues(arr);
223 return arr;
224 };
225 } else if (self.msCrypto && self.msCrypto.getRandomValues) {
226 // IE
227 Rand.prototype._rand = function _rand(n) {
228 var arr = new Uint8Array(n);
229 self.msCrypto.getRandomValues(arr);
230 return arr;
231 };
232
233 // Safari's WebWorkers do not have `crypto`
234 } else if (typeof window === 'object') {
235 // Old junk
236 Rand.prototype._rand = function() {
237 throw new Error('Not implemented yet');
238 };
239 }
240} else {
241 // Node.js or Web worker with no crypto support
242 try {
243 var crypto = void('crypto');
244 if (typeof crypto.randomBytes !== 'function')
245 throw new Error('Not supported');
246
247 Rand.prototype._rand = function _rand(n) {
248 return crypto.randomBytes(n);
249 };
250 } catch (e) {
251 }
252}
253brorand.Rand = Rand_1;
254
255var getNAF = utils_1$1.getNAF;
256var getJSF = utils_1$1.getJSF;
257var assert = utils_1$1.assert;
258
259function BaseCurve(type, conf) {
260 this.type = type;
261 this.p = new bn(conf.p, 16);
262
263 // Use Montgomery, when there is no fast reduction for the prime
264 this.red = conf.prime ? bn.red(conf.prime) : bn.mont(this.p);
265
266 // Useful for many curves
267 this.zero = new bn(0).toRed(this.red);
268 this.one = new bn(1).toRed(this.red);
269 this.two = new bn(2).toRed(this.red);
270
271 // Curve configuration, optional
272 this.n = conf.n && new bn(conf.n, 16);
273 this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed);
274
275 // Temporary arrays
276 this._wnafT1 = new Array(4);
277 this._wnafT2 = new Array(4);
278 this._wnafT3 = new Array(4);
279 this._wnafT4 = new Array(4);
280
281 // Generalized Greg Maxwell's trick
282 var adjustCount = this.n && this.p.div(this.n);
283 if (!adjustCount || adjustCount.cmpn(100) > 0) {
284 this.redN = null;
285 } else {
286 this._maxwellTrick = true;
287 this.redN = this.n.toRed(this.red);
288 }
289}
290var base = BaseCurve;
291
292BaseCurve.prototype.point = function point() {
293 throw new Error('Not implemented');
294};
295
296BaseCurve.prototype.validate = function validate() {
297 throw new Error('Not implemented');
298};
299
300BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) {
301 assert(p.precomputed);
302 var doubles = p._getDoubles();
303
304 var naf = getNAF(k, 1);
305 var I = (1 << (doubles.step + 1)) - (doubles.step % 2 === 0 ? 2 : 1);
306 I /= 3;
307
308 // Translate into more windowed form
309 var repr = [];
310 for (var j = 0; j < naf.length; j += doubles.step) {
311 var nafW = 0;
312 for (var k = j + doubles.step - 1; k >= j; k--)
313 nafW = (nafW << 1) + naf[k];
314 repr.push(nafW);
315 }
316
317 var a = this.jpoint(null, null, null);
318 var b = this.jpoint(null, null, null);
319 for (var i = I; i > 0; i--) {
320 for (var j = 0; j < repr.length; j++) {
321 var nafW = repr[j];
322 if (nafW === i)
323 b = b.mixedAdd(doubles.points[j]);
324 else if (nafW === -i)
325 b = b.mixedAdd(doubles.points[j].neg());
326 }
327 a = a.add(b);
328 }
329 return a.toP();
330};
331
332BaseCurve.prototype._wnafMul = function _wnafMul(p, k) {
333 var w = 4;
334
335 // Precompute window
336 var nafPoints = p._getNAFPoints(w);
337 w = nafPoints.wnd;
338 var wnd = nafPoints.points;
339
340 // Get NAF form
341 var naf = getNAF(k, w);
342
343 // Add `this`*(N+1) for every w-NAF index
344 var acc = this.jpoint(null, null, null);
345 for (var i = naf.length - 1; i >= 0; i--) {
346 // Count zeroes
347 for (var k = 0; i >= 0 && naf[i] === 0; i--)
348 k++;
349 if (i >= 0)
350 k++;
351 acc = acc.dblp(k);
352
353 if (i < 0)
354 break;
355 var z = naf[i];
356 assert(z !== 0);
357 if (p.type === 'affine') {
358 // J +- P
359 if (z > 0)
360 acc = acc.mixedAdd(wnd[(z - 1) >> 1]);
361 else
362 acc = acc.mixedAdd(wnd[(-z - 1) >> 1].neg());
363 } else {
364 // J +- J
365 if (z > 0)
366 acc = acc.add(wnd[(z - 1) >> 1]);
367 else
368 acc = acc.add(wnd[(-z - 1) >> 1].neg());
369 }
370 }
371 return p.type === 'affine' ? acc.toP() : acc;
372};
373
374BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW,
375 points,
376 coeffs,
377 len,
378 jacobianResult) {
379 var wndWidth = this._wnafT1;
380 var wnd = this._wnafT2;
381 var naf = this._wnafT3;
382
383 // Fill all arrays
384 var max = 0;
385 for (var i = 0; i < len; i++) {
386 var p = points[i];
387 var nafPoints = p._getNAFPoints(defW);
388 wndWidth[i] = nafPoints.wnd;
389 wnd[i] = nafPoints.points;
390 }
391
392 // Comb small window NAFs
393 for (var i = len - 1; i >= 1; i -= 2) {
394 var a = i - 1;
395 var b = i;
396 if (wndWidth[a] !== 1 || wndWidth[b] !== 1) {
397 naf[a] = getNAF(coeffs[a], wndWidth[a]);
398 naf[b] = getNAF(coeffs[b], wndWidth[b]);
399 max = Math.max(naf[a].length, max);
400 max = Math.max(naf[b].length, max);
401 continue;
402 }
403
404 var comb = [
405 points[a], /* 1 */
406 null, /* 3 */
407 null, /* 5 */
408 points[b] /* 7 */
409 ];
410
411 // Try to avoid Projective points, if possible
412 if (points[a].y.cmp(points[b].y) === 0) {
413 comb[1] = points[a].add(points[b]);
414 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
415 } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) {
416 comb[1] = points[a].toJ().mixedAdd(points[b]);
417 comb[2] = points[a].add(points[b].neg());
418 } else {
419 comb[1] = points[a].toJ().mixedAdd(points[b]);
420 comb[2] = points[a].toJ().mixedAdd(points[b].neg());
421 }
422
423 var index = [
424 -3, /* -1 -1 */
425 -1, /* -1 0 */
426 -5, /* -1 1 */
427 -7, /* 0 -1 */
428 0, /* 0 0 */
429 7, /* 0 1 */
430 5, /* 1 -1 */
431 1, /* 1 0 */
432 3 /* 1 1 */
433 ];
434
435 var jsf = getJSF(coeffs[a], coeffs[b]);
436 max = Math.max(jsf[0].length, max);
437 naf[a] = new Array(max);
438 naf[b] = new Array(max);
439 for (var j = 0; j < max; j++) {
440 var ja = jsf[0][j] | 0;
441 var jb = jsf[1][j] | 0;
442
443 naf[a][j] = index[(ja + 1) * 3 + (jb + 1)];
444 naf[b][j] = 0;
445 wnd[a] = comb;
446 }
447 }
448
449 var acc = this.jpoint(null, null, null);
450 var tmp = this._wnafT4;
451 for (var i = max; i >= 0; i--) {
452 var k = 0;
453
454 while (i >= 0) {
455 var zero = true;
456 for (var j = 0; j < len; j++) {
457 tmp[j] = naf[j][i] | 0;
458 if (tmp[j] !== 0)
459 zero = false;
460 }
461 if (!zero)
462 break;
463 k++;
464 i--;
465 }
466 if (i >= 0)
467 k++;
468 acc = acc.dblp(k);
469 if (i < 0)
470 break;
471
472 for (var j = 0; j < len; j++) {
473 var z = tmp[j];
474 var p;
475 if (z === 0)
476 continue;
477 else if (z > 0)
478 p = wnd[j][(z - 1) >> 1];
479 else if (z < 0)
480 p = wnd[j][(-z - 1) >> 1].neg();
481
482 if (p.type === 'affine')
483 acc = acc.mixedAdd(p);
484 else
485 acc = acc.add(p);
486 }
487 }
488 // Zeroify references
489 for (var i = 0; i < len; i++)
490 wnd[i] = null;
491
492 if (jacobianResult)
493 return acc;
494 else
495 return acc.toP();
496};
497
498function BasePoint(curve, type) {
499 this.curve = curve;
500 this.type = type;
501 this.precomputed = null;
502}
503BaseCurve.BasePoint = BasePoint;
504
505BasePoint.prototype.eq = function eq(/*other*/) {
506 throw new Error('Not implemented');
507};
508
509BasePoint.prototype.validate = function validate() {
510 return this.curve.validate(this);
511};
512
513BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
514 bytes = utils_1$1.toArray(bytes, enc);
515
516 var len = this.p.byteLength();
517
518 // uncompressed, hybrid-odd, hybrid-even
519 if ((bytes[0] === 0x04 || bytes[0] === 0x06 || bytes[0] === 0x07) &&
520 bytes.length - 1 === 2 * len) {
521 if (bytes[0] === 0x06)
522 assert(bytes[bytes.length - 1] % 2 === 0);
523 else if (bytes[0] === 0x07)
524 assert(bytes[bytes.length - 1] % 2 === 1);
525
526 var res = this.point(bytes.slice(1, 1 + len),
527 bytes.slice(1 + len, 1 + 2 * len));
528
529 return res;
530 } else if ((bytes[0] === 0x02 || bytes[0] === 0x03) &&
531 bytes.length - 1 === len) {
532 return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 0x03);
533 }
534 throw new Error('Unknown point format');
535};
536
537BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) {
538 return this.encode(enc, true);
539};
540
541BasePoint.prototype._encode = function _encode(compact) {
542 var len = this.curve.p.byteLength();
543 var x = this.getX().toArray('be', len);
544
545 if (compact)
546 return [ this.getY().isEven() ? 0x02 : 0x03 ].concat(x);
547
548 return [ 0x04 ].concat(x, this.getY().toArray('be', len)) ;
549};
550
551BasePoint.prototype.encode = function encode(enc, compact) {
552 return utils_1$1.encode(this._encode(compact), enc);
553};
554
555BasePoint.prototype.precompute = function precompute(power) {
556 if (this.precomputed)
557 return this;
558
559 var precomputed = {
560 doubles: null,
561 naf: null,
562 beta: null
563 };
564 precomputed.naf = this._getNAFPoints(8);
565 precomputed.doubles = this._getDoubles(4, power);
566 precomputed.beta = this._getBeta();
567 this.precomputed = precomputed;
568
569 return this;
570};
571
572BasePoint.prototype._hasDoubles = function _hasDoubles(k) {
573 if (!this.precomputed)
574 return false;
575
576 var doubles = this.precomputed.doubles;
577 if (!doubles)
578 return false;
579
580 return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step);
581};
582
583BasePoint.prototype._getDoubles = function _getDoubles(step, power) {
584 if (this.precomputed && this.precomputed.doubles)
585 return this.precomputed.doubles;
586
587 var doubles = [ this ];
588 var acc = this;
589 for (var i = 0; i < power; i += step) {
590 for (var j = 0; j < step; j++)
591 acc = acc.dbl();
592 doubles.push(acc);
593 }
594 return {
595 step: step,
596 points: doubles
597 };
598};
599
600BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) {
601 if (this.precomputed && this.precomputed.naf)
602 return this.precomputed.naf;
603
604 var res = [ this ];
605 var max = (1 << wnd) - 1;
606 var dbl = max === 1 ? null : this.dbl();
607 for (var i = 1; i < max; i++)
608 res[i] = res[i - 1].add(dbl);
609 return {
610 wnd: wnd,
611 points: res
612 };
613};
614
615BasePoint.prototype._getBeta = function _getBeta() {
616 return null;
617};
618
619BasePoint.prototype.dblp = function dblp(k) {
620 var r = this;
621 for (var i = 0; i < k; i++)
622 r = r.dbl();
623 return r;
624};
625
626var assert$1 = utils_1$1.assert;
627
628function ShortCurve(conf) {
629 base.call(this, 'short', conf);
630
631 this.a = new bn(conf.a, 16).toRed(this.red);
632 this.b = new bn(conf.b, 16).toRed(this.red);
633 this.tinv = this.two.redInvm();
634
635 this.zeroA = this.a.fromRed().cmpn(0) === 0;
636 this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0;
637
638 // If the curve is endomorphic, precalculate beta and lambda
639 this.endo = this._getEndomorphism(conf);
640 this._endoWnafT1 = new Array(4);
641 this._endoWnafT2 = new Array(4);
642}
643inherits_browser(ShortCurve, base);
644var short_1 = ShortCurve;
645
646ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) {
647 // No efficient endomorphism
648 if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1)
649 return;
650
651 // Compute beta and lambda, that lambda * P = (beta * Px; Py)
652 var beta;
653 var lambda;
654 if (conf.beta) {
655 beta = new bn(conf.beta, 16).toRed(this.red);
656 } else {
657 var betas = this._getEndoRoots(this.p);
658 // Choose the smallest beta
659 beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1];
660 beta = beta.toRed(this.red);
661 }
662 if (conf.lambda) {
663 lambda = new bn(conf.lambda, 16);
664 } else {
665 // Choose the lambda that is matching selected beta
666 var lambdas = this._getEndoRoots(this.n);
667 if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) {
668 lambda = lambdas[0];
669 } else {
670 lambda = lambdas[1];
671 assert$1(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0);
672 }
673 }
674
675 // Get basis vectors, used for balanced length-two representation
676 var basis;
677 if (conf.basis) {
678 basis = conf.basis.map(function(vec) {
679 return {
680 a: new bn(vec.a, 16),
681 b: new bn(vec.b, 16)
682 };
683 });
684 } else {
685 basis = this._getEndoBasis(lambda);
686 }
687
688 return {
689 beta: beta,
690 lambda: lambda,
691 basis: basis
692 };
693};
694
695ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) {
696 // Find roots of for x^2 + x + 1 in F
697 // Root = (-1 +- Sqrt(-3)) / 2
698 //
699 var red = num === this.p ? this.red : bn.mont(num);
700 var tinv = new bn(2).toRed(red).redInvm();
701 var ntinv = tinv.redNeg();
702
703 var s = new bn(3).toRed(red).redNeg().redSqrt().redMul(tinv);
704
705 var l1 = ntinv.redAdd(s).fromRed();
706 var l2 = ntinv.redSub(s).fromRed();
707 return [ l1, l2 ];
708};
709
710ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) {
711 // aprxSqrt >= sqrt(this.n)
712 var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2));
713
714 // 3.74
715 // Run EGCD, until r(L + 1) < aprxSqrt
716 var u = lambda;
717 var v = this.n.clone();
718 var x1 = new bn(1);
719 var y1 = new bn(0);
720 var x2 = new bn(0);
721 var y2 = new bn(1);
722
723 // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n)
724 var a0;
725 var b0;
726 // First vector
727 var a1;
728 var b1;
729 // Second vector
730 var a2;
731 var b2;
732
733 var prevR;
734 var i = 0;
735 var r;
736 var x;
737 while (u.cmpn(0) !== 0) {
738 var q = v.div(u);
739 r = v.sub(q.mul(u));
740 x = x2.sub(q.mul(x1));
741 var y = y2.sub(q.mul(y1));
742
743 if (!a1 && r.cmp(aprxSqrt) < 0) {
744 a0 = prevR.neg();
745 b0 = x1;
746 a1 = r.neg();
747 b1 = x;
748 } else if (a1 && ++i === 2) {
749 break;
750 }
751 prevR = r;
752
753 v = u;
754 u = r;
755 x2 = x1;
756 x1 = x;
757 y2 = y1;
758 y1 = y;
759 }
760 a2 = r.neg();
761 b2 = x;
762
763 var len1 = a1.sqr().add(b1.sqr());
764 var len2 = a2.sqr().add(b2.sqr());
765 if (len2.cmp(len1) >= 0) {
766 a2 = a0;
767 b2 = b0;
768 }
769
770 // Normalize signs
771 if (a1.negative) {
772 a1 = a1.neg();
773 b1 = b1.neg();
774 }
775 if (a2.negative) {
776 a2 = a2.neg();
777 b2 = b2.neg();
778 }
779
780 return [
781 { a: a1, b: b1 },
782 { a: a2, b: b2 }
783 ];
784};
785
786ShortCurve.prototype._endoSplit = function _endoSplit(k) {
787 var basis = this.endo.basis;
788 var v1 = basis[0];
789 var v2 = basis[1];
790
791 var c1 = v2.b.mul(k).divRound(this.n);
792 var c2 = v1.b.neg().mul(k).divRound(this.n);
793
794 var p1 = c1.mul(v1.a);
795 var p2 = c2.mul(v2.a);
796 var q1 = c1.mul(v1.b);
797 var q2 = c2.mul(v2.b);
798
799 // Calculate answer
800 var k1 = k.sub(p1).sub(p2);
801 var k2 = q1.add(q2).neg();
802 return { k1: k1, k2: k2 };
803};
804
805ShortCurve.prototype.pointFromX = function pointFromX(x, odd) {
806 x = new bn(x, 16);
807 if (!x.red)
808 x = x.toRed(this.red);
809
810 var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);
811 var y = y2.redSqrt();
812 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
813 throw new Error('invalid point');
814
815 // XXX Is there any way to tell if the number is odd without converting it
816 // to non-red form?
817 var isOdd = y.fromRed().isOdd();
818 if (odd && !isOdd || !odd && isOdd)
819 y = y.redNeg();
820
821 return this.point(x, y);
822};
823
824ShortCurve.prototype.validate = function validate(point) {
825 if (point.inf)
826 return true;
827
828 var x = point.x;
829 var y = point.y;
830
831 var ax = this.a.redMul(x);
832 var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);
833 return y.redSqr().redISub(rhs).cmpn(0) === 0;
834};
835
836ShortCurve.prototype._endoWnafMulAdd =
837 function _endoWnafMulAdd(points, coeffs, jacobianResult) {
838 var npoints = this._endoWnafT1;
839 var ncoeffs = this._endoWnafT2;
840 for (var i = 0; i < points.length; i++) {
841 var split = this._endoSplit(coeffs[i]);
842 var p = points[i];
843 var beta = p._getBeta();
844
845 if (split.k1.negative) {
846 split.k1.ineg();
847 p = p.neg(true);
848 }
849 if (split.k2.negative) {
850 split.k2.ineg();
851 beta = beta.neg(true);
852 }
853
854 npoints[i * 2] = p;
855 npoints[i * 2 + 1] = beta;
856 ncoeffs[i * 2] = split.k1;
857 ncoeffs[i * 2 + 1] = split.k2;
858 }
859 var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult);
860
861 // Clean-up references to points and coefficients
862 for (var j = 0; j < i * 2; j++) {
863 npoints[j] = null;
864 ncoeffs[j] = null;
865 }
866 return res;
867};
868
869function Point(curve, x, y, isRed) {
870 base.BasePoint.call(this, curve, 'affine');
871 if (x === null && y === null) {
872 this.x = null;
873 this.y = null;
874 this.inf = true;
875 } else {
876 this.x = new bn(x, 16);
877 this.y = new bn(y, 16);
878 // Force redgomery representation when loading from JSON
879 if (isRed) {
880 this.x.forceRed(this.curve.red);
881 this.y.forceRed(this.curve.red);
882 }
883 if (!this.x.red)
884 this.x = this.x.toRed(this.curve.red);
885 if (!this.y.red)
886 this.y = this.y.toRed(this.curve.red);
887 this.inf = false;
888 }
889}
890inherits_browser(Point, base.BasePoint);
891
892ShortCurve.prototype.point = function point(x, y, isRed) {
893 return new Point(this, x, y, isRed);
894};
895
896ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) {
897 return Point.fromJSON(this, obj, red);
898};
899
900Point.prototype._getBeta = function _getBeta() {
901 if (!this.curve.endo)
902 return;
903
904 var pre = this.precomputed;
905 if (pre && pre.beta)
906 return pre.beta;
907
908 var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y);
909 if (pre) {
910 var curve = this.curve;
911 var endoMul = function(p) {
912 return curve.point(p.x.redMul(curve.endo.beta), p.y);
913 };
914 pre.beta = beta;
915 beta.precomputed = {
916 beta: null,
917 naf: pre.naf && {
918 wnd: pre.naf.wnd,
919 points: pre.naf.points.map(endoMul)
920 },
921 doubles: pre.doubles && {
922 step: pre.doubles.step,
923 points: pre.doubles.points.map(endoMul)
924 }
925 };
926 }
927 return beta;
928};
929
930Point.prototype.toJSON = function toJSON() {
931 if (!this.precomputed)
932 return [ this.x, this.y ];
933
934 return [ this.x, this.y, this.precomputed && {
935 doubles: this.precomputed.doubles && {
936 step: this.precomputed.doubles.step,
937 points: this.precomputed.doubles.points.slice(1)
938 },
939 naf: this.precomputed.naf && {
940 wnd: this.precomputed.naf.wnd,
941 points: this.precomputed.naf.points.slice(1)
942 }
943 } ];
944};
945
946Point.fromJSON = function fromJSON(curve, obj, red) {
947 if (typeof obj === 'string')
948 obj = JSON.parse(obj);
949 var res = curve.point(obj[0], obj[1], red);
950 if (!obj[2])
951 return res;
952
953 function obj2point(obj) {
954 return curve.point(obj[0], obj[1], red);
955 }
956
957 var pre = obj[2];
958 res.precomputed = {
959 beta: null,
960 doubles: pre.doubles && {
961 step: pre.doubles.step,
962 points: [ res ].concat(pre.doubles.points.map(obj2point))
963 },
964 naf: pre.naf && {
965 wnd: pre.naf.wnd,
966 points: [ res ].concat(pre.naf.points.map(obj2point))
967 }
968 };
969 return res;
970};
971
972Point.prototype.inspect = function inspect() {
973 if (this.isInfinity())
974 return '<EC Point Infinity>';
975 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
976 ' y: ' + this.y.fromRed().toString(16, 2) + '>';
977};
978
979Point.prototype.isInfinity = function isInfinity() {
980 return this.inf;
981};
982
983Point.prototype.add = function add(p) {
984 // O + P = P
985 if (this.inf)
986 return p;
987
988 // P + O = P
989 if (p.inf)
990 return this;
991
992 // P + P = 2P
993 if (this.eq(p))
994 return this.dbl();
995
996 // P + (-P) = O
997 if (this.neg().eq(p))
998 return this.curve.point(null, null);
999
1000 // P + Q = O
1001 if (this.x.cmp(p.x) === 0)
1002 return this.curve.point(null, null);
1003
1004 var c = this.y.redSub(p.y);
1005 if (c.cmpn(0) !== 0)
1006 c = c.redMul(this.x.redSub(p.x).redInvm());
1007 var nx = c.redSqr().redISub(this.x).redISub(p.x);
1008 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
1009 return this.curve.point(nx, ny);
1010};
1011
1012Point.prototype.dbl = function dbl() {
1013 if (this.inf)
1014 return this;
1015
1016 // 2P = O
1017 var ys1 = this.y.redAdd(this.y);
1018 if (ys1.cmpn(0) === 0)
1019 return this.curve.point(null, null);
1020
1021 var a = this.curve.a;
1022
1023 var x2 = this.x.redSqr();
1024 var dyinv = ys1.redInvm();
1025 var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);
1026
1027 var nx = c.redSqr().redISub(this.x.redAdd(this.x));
1028 var ny = c.redMul(this.x.redSub(nx)).redISub(this.y);
1029 return this.curve.point(nx, ny);
1030};
1031
1032Point.prototype.getX = function getX() {
1033 return this.x.fromRed();
1034};
1035
1036Point.prototype.getY = function getY() {
1037 return this.y.fromRed();
1038};
1039
1040Point.prototype.mul = function mul(k) {
1041 k = new bn(k, 16);
1042 if (this.isInfinity())
1043 return this;
1044 else if (this._hasDoubles(k))
1045 return this.curve._fixedNafMul(this, k);
1046 else if (this.curve.endo)
1047 return this.curve._endoWnafMulAdd([ this ], [ k ]);
1048 else
1049 return this.curve._wnafMul(this, k);
1050};
1051
1052Point.prototype.mulAdd = function mulAdd(k1, p2, k2) {
1053 var points = [ this, p2 ];
1054 var coeffs = [ k1, k2 ];
1055 if (this.curve.endo)
1056 return this.curve._endoWnafMulAdd(points, coeffs);
1057 else
1058 return this.curve._wnafMulAdd(1, points, coeffs, 2);
1059};
1060
1061Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) {
1062 var points = [ this, p2 ];
1063 var coeffs = [ k1, k2 ];
1064 if (this.curve.endo)
1065 return this.curve._endoWnafMulAdd(points, coeffs, true);
1066 else
1067 return this.curve._wnafMulAdd(1, points, coeffs, 2, true);
1068};
1069
1070Point.prototype.eq = function eq(p) {
1071 return this === p ||
1072 this.inf === p.inf &&
1073 (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0);
1074};
1075
1076Point.prototype.neg = function neg(_precompute) {
1077 if (this.inf)
1078 return this;
1079
1080 var res = this.curve.point(this.x, this.y.redNeg());
1081 if (_precompute && this.precomputed) {
1082 var pre = this.precomputed;
1083 var negate = function(p) {
1084 return p.neg();
1085 };
1086 res.precomputed = {
1087 naf: pre.naf && {
1088 wnd: pre.naf.wnd,
1089 points: pre.naf.points.map(negate)
1090 },
1091 doubles: pre.doubles && {
1092 step: pre.doubles.step,
1093 points: pre.doubles.points.map(negate)
1094 }
1095 };
1096 }
1097 return res;
1098};
1099
1100Point.prototype.toJ = function toJ() {
1101 if (this.inf)
1102 return this.curve.jpoint(null, null, null);
1103
1104 var res = this.curve.jpoint(this.x, this.y, this.curve.one);
1105 return res;
1106};
1107
1108function JPoint(curve, x, y, z) {
1109 base.BasePoint.call(this, curve, 'jacobian');
1110 if (x === null && y === null && z === null) {
1111 this.x = this.curve.one;
1112 this.y = this.curve.one;
1113 this.z = new bn(0);
1114 } else {
1115 this.x = new bn(x, 16);
1116 this.y = new bn(y, 16);
1117 this.z = new bn(z, 16);
1118 }
1119 if (!this.x.red)
1120 this.x = this.x.toRed(this.curve.red);
1121 if (!this.y.red)
1122 this.y = this.y.toRed(this.curve.red);
1123 if (!this.z.red)
1124 this.z = this.z.toRed(this.curve.red);
1125
1126 this.zOne = this.z === this.curve.one;
1127}
1128inherits_browser(JPoint, base.BasePoint);
1129
1130ShortCurve.prototype.jpoint = function jpoint(x, y, z) {
1131 return new JPoint(this, x, y, z);
1132};
1133
1134JPoint.prototype.toP = function toP() {
1135 if (this.isInfinity())
1136 return this.curve.point(null, null);
1137
1138 var zinv = this.z.redInvm();
1139 var zinv2 = zinv.redSqr();
1140 var ax = this.x.redMul(zinv2);
1141 var ay = this.y.redMul(zinv2).redMul(zinv);
1142
1143 return this.curve.point(ax, ay);
1144};
1145
1146JPoint.prototype.neg = function neg() {
1147 return this.curve.jpoint(this.x, this.y.redNeg(), this.z);
1148};
1149
1150JPoint.prototype.add = function add(p) {
1151 // O + P = P
1152 if (this.isInfinity())
1153 return p;
1154
1155 // P + O = P
1156 if (p.isInfinity())
1157 return this;
1158
1159 // 12M + 4S + 7A
1160 var pz2 = p.z.redSqr();
1161 var z2 = this.z.redSqr();
1162 var u1 = this.x.redMul(pz2);
1163 var u2 = p.x.redMul(z2);
1164 var s1 = this.y.redMul(pz2.redMul(p.z));
1165 var s2 = p.y.redMul(z2.redMul(this.z));
1166
1167 var h = u1.redSub(u2);
1168 var r = s1.redSub(s2);
1169 if (h.cmpn(0) === 0) {
1170 if (r.cmpn(0) !== 0)
1171 return this.curve.jpoint(null, null, null);
1172 else
1173 return this.dbl();
1174 }
1175
1176 var h2 = h.redSqr();
1177 var h3 = h2.redMul(h);
1178 var v = u1.redMul(h2);
1179
1180 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
1181 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
1182 var nz = this.z.redMul(p.z).redMul(h);
1183
1184 return this.curve.jpoint(nx, ny, nz);
1185};
1186
1187JPoint.prototype.mixedAdd = function mixedAdd(p) {
1188 // O + P = P
1189 if (this.isInfinity())
1190 return p.toJ();
1191
1192 // P + O = P
1193 if (p.isInfinity())
1194 return this;
1195
1196 // 8M + 3S + 7A
1197 var z2 = this.z.redSqr();
1198 var u1 = this.x;
1199 var u2 = p.x.redMul(z2);
1200 var s1 = this.y;
1201 var s2 = p.y.redMul(z2).redMul(this.z);
1202
1203 var h = u1.redSub(u2);
1204 var r = s1.redSub(s2);
1205 if (h.cmpn(0) === 0) {
1206 if (r.cmpn(0) !== 0)
1207 return this.curve.jpoint(null, null, null);
1208 else
1209 return this.dbl();
1210 }
1211
1212 var h2 = h.redSqr();
1213 var h3 = h2.redMul(h);
1214 var v = u1.redMul(h2);
1215
1216 var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v);
1217 var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));
1218 var nz = this.z.redMul(h);
1219
1220 return this.curve.jpoint(nx, ny, nz);
1221};
1222
1223JPoint.prototype.dblp = function dblp(pow) {
1224 if (pow === 0)
1225 return this;
1226 if (this.isInfinity())
1227 return this;
1228 if (!pow)
1229 return this.dbl();
1230
1231 if (this.curve.zeroA || this.curve.threeA) {
1232 var r = this;
1233 for (var i = 0; i < pow; i++)
1234 r = r.dbl();
1235 return r;
1236 }
1237
1238 // 1M + 2S + 1A + N * (4S + 5M + 8A)
1239 // N = 1 => 6M + 6S + 9A
1240 var a = this.curve.a;
1241 var tinv = this.curve.tinv;
1242
1243 var jx = this.x;
1244 var jy = this.y;
1245 var jz = this.z;
1246 var jz4 = jz.redSqr().redSqr();
1247
1248 // Reuse results
1249 var jyd = jy.redAdd(jy);
1250 for (var i = 0; i < pow; i++) {
1251 var jx2 = jx.redSqr();
1252 var jyd2 = jyd.redSqr();
1253 var jyd4 = jyd2.redSqr();
1254 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
1255
1256 var t1 = jx.redMul(jyd2);
1257 var nx = c.redSqr().redISub(t1.redAdd(t1));
1258 var t2 = t1.redISub(nx);
1259 var dny = c.redMul(t2);
1260 dny = dny.redIAdd(dny).redISub(jyd4);
1261 var nz = jyd.redMul(jz);
1262 if (i + 1 < pow)
1263 jz4 = jz4.redMul(jyd4);
1264
1265 jx = nx;
1266 jz = nz;
1267 jyd = dny;
1268 }
1269
1270 return this.curve.jpoint(jx, jyd.redMul(tinv), jz);
1271};
1272
1273JPoint.prototype.dbl = function dbl() {
1274 if (this.isInfinity())
1275 return this;
1276
1277 if (this.curve.zeroA)
1278 return this._zeroDbl();
1279 else if (this.curve.threeA)
1280 return this._threeDbl();
1281 else
1282 return this._dbl();
1283};
1284
1285JPoint.prototype._zeroDbl = function _zeroDbl() {
1286 var nx;
1287 var ny;
1288 var nz;
1289 // Z = 1
1290 if (this.zOne) {
1291 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
1292 // #doubling-mdbl-2007-bl
1293 // 1M + 5S + 14A
1294
1295 // XX = X1^2
1296 var xx = this.x.redSqr();
1297 // YY = Y1^2
1298 var yy = this.y.redSqr();
1299 // YYYY = YY^2
1300 var yyyy = yy.redSqr();
1301 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
1302 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
1303 s = s.redIAdd(s);
1304 // M = 3 * XX + a; a = 0
1305 var m = xx.redAdd(xx).redIAdd(xx);
1306 // T = M ^ 2 - 2*S
1307 var t = m.redSqr().redISub(s).redISub(s);
1308
1309 // 8 * YYYY
1310 var yyyy8 = yyyy.redIAdd(yyyy);
1311 yyyy8 = yyyy8.redIAdd(yyyy8);
1312 yyyy8 = yyyy8.redIAdd(yyyy8);
1313
1314 // X3 = T
1315 nx = t;
1316 // Y3 = M * (S - T) - 8 * YYYY
1317 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
1318 // Z3 = 2*Y1
1319 nz = this.y.redAdd(this.y);
1320 } else {
1321 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html
1322 // #doubling-dbl-2009-l
1323 // 2M + 5S + 13A
1324
1325 // A = X1^2
1326 var a = this.x.redSqr();
1327 // B = Y1^2
1328 var b = this.y.redSqr();
1329 // C = B^2
1330 var c = b.redSqr();
1331 // D = 2 * ((X1 + B)^2 - A - C)
1332 var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c);
1333 d = d.redIAdd(d);
1334 // E = 3 * A
1335 var e = a.redAdd(a).redIAdd(a);
1336 // F = E^2
1337 var f = e.redSqr();
1338
1339 // 8 * C
1340 var c8 = c.redIAdd(c);
1341 c8 = c8.redIAdd(c8);
1342 c8 = c8.redIAdd(c8);
1343
1344 // X3 = F - 2 * D
1345 nx = f.redISub(d).redISub(d);
1346 // Y3 = E * (D - X3) - 8 * C
1347 ny = e.redMul(d.redISub(nx)).redISub(c8);
1348 // Z3 = 2 * Y1 * Z1
1349 nz = this.y.redMul(this.z);
1350 nz = nz.redIAdd(nz);
1351 }
1352
1353 return this.curve.jpoint(nx, ny, nz);
1354};
1355
1356JPoint.prototype._threeDbl = function _threeDbl() {
1357 var nx;
1358 var ny;
1359 var nz;
1360 // Z = 1
1361 if (this.zOne) {
1362 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html
1363 // #doubling-mdbl-2007-bl
1364 // 1M + 5S + 15A
1365
1366 // XX = X1^2
1367 var xx = this.x.redSqr();
1368 // YY = Y1^2
1369 var yy = this.y.redSqr();
1370 // YYYY = YY^2
1371 var yyyy = yy.redSqr();
1372 // S = 2 * ((X1 + YY)^2 - XX - YYYY)
1373 var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
1374 s = s.redIAdd(s);
1375 // M = 3 * XX + a
1376 var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a);
1377 // T = M^2 - 2 * S
1378 var t = m.redSqr().redISub(s).redISub(s);
1379 // X3 = T
1380 nx = t;
1381 // Y3 = M * (S - T) - 8 * YYYY
1382 var yyyy8 = yyyy.redIAdd(yyyy);
1383 yyyy8 = yyyy8.redIAdd(yyyy8);
1384 yyyy8 = yyyy8.redIAdd(yyyy8);
1385 ny = m.redMul(s.redISub(t)).redISub(yyyy8);
1386 // Z3 = 2 * Y1
1387 nz = this.y.redAdd(this.y);
1388 } else {
1389 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b
1390 // 3M + 5S
1391
1392 // delta = Z1^2
1393 var delta = this.z.redSqr();
1394 // gamma = Y1^2
1395 var gamma = this.y.redSqr();
1396 // beta = X1 * gamma
1397 var beta = this.x.redMul(gamma);
1398 // alpha = 3 * (X1 - delta) * (X1 + delta)
1399 var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta));
1400 alpha = alpha.redAdd(alpha).redIAdd(alpha);
1401 // X3 = alpha^2 - 8 * beta
1402 var beta4 = beta.redIAdd(beta);
1403 beta4 = beta4.redIAdd(beta4);
1404 var beta8 = beta4.redAdd(beta4);
1405 nx = alpha.redSqr().redISub(beta8);
1406 // Z3 = (Y1 + Z1)^2 - gamma - delta
1407 nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta);
1408 // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2
1409 var ggamma8 = gamma.redSqr();
1410 ggamma8 = ggamma8.redIAdd(ggamma8);
1411 ggamma8 = ggamma8.redIAdd(ggamma8);
1412 ggamma8 = ggamma8.redIAdd(ggamma8);
1413 ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8);
1414 }
1415
1416 return this.curve.jpoint(nx, ny, nz);
1417};
1418
1419JPoint.prototype._dbl = function _dbl() {
1420 var a = this.curve.a;
1421
1422 // 4M + 6S + 10A
1423 var jx = this.x;
1424 var jy = this.y;
1425 var jz = this.z;
1426 var jz4 = jz.redSqr().redSqr();
1427
1428 var jx2 = jx.redSqr();
1429 var jy2 = jy.redSqr();
1430
1431 var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4));
1432
1433 var jxd4 = jx.redAdd(jx);
1434 jxd4 = jxd4.redIAdd(jxd4);
1435 var t1 = jxd4.redMul(jy2);
1436 var nx = c.redSqr().redISub(t1.redAdd(t1));
1437 var t2 = t1.redISub(nx);
1438
1439 var jyd8 = jy2.redSqr();
1440 jyd8 = jyd8.redIAdd(jyd8);
1441 jyd8 = jyd8.redIAdd(jyd8);
1442 jyd8 = jyd8.redIAdd(jyd8);
1443 var ny = c.redMul(t2).redISub(jyd8);
1444 var nz = jy.redAdd(jy).redMul(jz);
1445
1446 return this.curve.jpoint(nx, ny, nz);
1447};
1448
1449JPoint.prototype.trpl = function trpl() {
1450 if (!this.curve.zeroA)
1451 return this.dbl().add(this);
1452
1453 // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl
1454 // 5M + 10S + ...
1455
1456 // XX = X1^2
1457 var xx = this.x.redSqr();
1458 // YY = Y1^2
1459 var yy = this.y.redSqr();
1460 // ZZ = Z1^2
1461 var zz = this.z.redSqr();
1462 // YYYY = YY^2
1463 var yyyy = yy.redSqr();
1464 // M = 3 * XX + a * ZZ2; a = 0
1465 var m = xx.redAdd(xx).redIAdd(xx);
1466 // MM = M^2
1467 var mm = m.redSqr();
1468 // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM
1469 var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy);
1470 e = e.redIAdd(e);
1471 e = e.redAdd(e).redIAdd(e);
1472 e = e.redISub(mm);
1473 // EE = E^2
1474 var ee = e.redSqr();
1475 // T = 16*YYYY
1476 var t = yyyy.redIAdd(yyyy);
1477 t = t.redIAdd(t);
1478 t = t.redIAdd(t);
1479 t = t.redIAdd(t);
1480 // U = (M + E)^2 - MM - EE - T
1481 var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t);
1482 // X3 = 4 * (X1 * EE - 4 * YY * U)
1483 var yyu4 = yy.redMul(u);
1484 yyu4 = yyu4.redIAdd(yyu4);
1485 yyu4 = yyu4.redIAdd(yyu4);
1486 var nx = this.x.redMul(ee).redISub(yyu4);
1487 nx = nx.redIAdd(nx);
1488 nx = nx.redIAdd(nx);
1489 // Y3 = 8 * Y1 * (U * (T - U) - E * EE)
1490 var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee)));
1491 ny = ny.redIAdd(ny);
1492 ny = ny.redIAdd(ny);
1493 ny = ny.redIAdd(ny);
1494 // Z3 = (Z1 + E)^2 - ZZ - EE
1495 var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee);
1496
1497 return this.curve.jpoint(nx, ny, nz);
1498};
1499
1500JPoint.prototype.mul = function mul(k, kbase) {
1501 k = new bn(k, kbase);
1502
1503 return this.curve._wnafMul(this, k);
1504};
1505
1506JPoint.prototype.eq = function eq(p) {
1507 if (p.type === 'affine')
1508 return this.eq(p.toJ());
1509
1510 if (this === p)
1511 return true;
1512
1513 // x1 * z2^2 == x2 * z1^2
1514 var z2 = this.z.redSqr();
1515 var pz2 = p.z.redSqr();
1516 if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0)
1517 return false;
1518
1519 // y1 * z2^3 == y2 * z1^3
1520 var z3 = z2.redMul(this.z);
1521 var pz3 = pz2.redMul(p.z);
1522 return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0;
1523};
1524
1525JPoint.prototype.eqXToP = function eqXToP(x) {
1526 var zs = this.z.redSqr();
1527 var rx = x.toRed(this.curve.red).redMul(zs);
1528 if (this.x.cmp(rx) === 0)
1529 return true;
1530
1531 var xc = x.clone();
1532 var t = this.curve.redN.redMul(zs);
1533 for (;;) {
1534 xc.iadd(this.curve.n);
1535 if (xc.cmp(this.curve.p) >= 0)
1536 return false;
1537
1538 rx.redIAdd(t);
1539 if (this.x.cmp(rx) === 0)
1540 return true;
1541 }
1542};
1543
1544JPoint.prototype.inspect = function inspect() {
1545 if (this.isInfinity())
1546 return '<EC JPoint Infinity>';
1547 return '<EC JPoint x: ' + this.x.toString(16, 2) +
1548 ' y: ' + this.y.toString(16, 2) +
1549 ' z: ' + this.z.toString(16, 2) + '>';
1550};
1551
1552JPoint.prototype.isInfinity = function isInfinity() {
1553 // XXX This code assumes that zero is always zero in red
1554 return this.z.cmpn(0) === 0;
1555};
1556
1557function MontCurve(conf) {
1558 base.call(this, 'mont', conf);
1559
1560 this.a = new bn(conf.a, 16).toRed(this.red);
1561 this.b = new bn(conf.b, 16).toRed(this.red);
1562 this.i4 = new bn(4).toRed(this.red).redInvm();
1563 this.two = new bn(2).toRed(this.red);
1564 // Note: this implementation is according to the original paper
1565 // by P. Montgomery, NOT the one by D. J. Bernstein.
1566 this.a24 = this.i4.redMul(this.a.redAdd(this.two));
1567}
1568inherits_browser(MontCurve, base);
1569var mont = MontCurve;
1570
1571MontCurve.prototype.validate = function validate(point) {
1572 var x = point.normalize().x;
1573 var x2 = x.redSqr();
1574 var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);
1575 var y = rhs.redSqrt();
1576
1577 return y.redSqr().cmp(rhs) === 0;
1578};
1579
1580function Point$1(curve, x, z) {
1581 base.BasePoint.call(this, curve, 'projective');
1582 if (x === null && z === null) {
1583 this.x = this.curve.one;
1584 this.z = this.curve.zero;
1585 } else {
1586 this.x = new bn(x, 16);
1587 this.z = new bn(z, 16);
1588 if (!this.x.red)
1589 this.x = this.x.toRed(this.curve.red);
1590 if (!this.z.red)
1591 this.z = this.z.toRed(this.curve.red);
1592 }
1593}
1594inherits_browser(Point$1, base.BasePoint);
1595
1596MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) {
1597 var bytes = utils_1$1.toArray(bytes, enc);
1598
1599 // TODO Curve448
1600 // Montgomery curve points must be represented in the compressed format
1601 // https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-02#appendix-B
1602 if (bytes.length === 33 && bytes[0] === 0x40)
1603 bytes = bytes.slice(1, 33).reverse(); // point must be little-endian
1604 if (bytes.length !== 32)
1605 throw new Error('Unknown point compression format');
1606 return this.point(bytes, 1);
1607};
1608
1609MontCurve.prototype.point = function point(x, z) {
1610 return new Point$1(this, x, z);
1611};
1612
1613MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
1614 return Point$1.fromJSON(this, obj);
1615};
1616
1617Point$1.prototype.precompute = function precompute() {
1618 // No-op
1619};
1620
1621Point$1.prototype._encode = function _encode(compact) {
1622 var len = this.curve.p.byteLength();
1623
1624 // Note: the output should always be little-endian
1625 // https://tools.ietf.org/html/draft-ietf-openpgp-rfc4880bis-02#appendix-B
1626 if (compact) {
1627 return [ 0x40 ].concat(this.getX().toArray('le', len));
1628 } else {
1629 return this.getX().toArray('be', len);
1630 }
1631};
1632
1633Point$1.fromJSON = function fromJSON(curve, obj) {
1634 return new Point$1(curve, obj[0], obj[1] || curve.one);
1635};
1636
1637Point$1.prototype.inspect = function inspect() {
1638 if (this.isInfinity())
1639 return '<EC Point Infinity>';
1640 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
1641 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
1642};
1643
1644Point$1.prototype.isInfinity = function isInfinity() {
1645 // XXX This code assumes that zero is always zero in red
1646 return this.z.cmpn(0) === 0;
1647};
1648
1649Point$1.prototype.dbl = function dbl() {
1650 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3
1651 // 2M + 2S + 4A
1652
1653 // A = X1 + Z1
1654 var a = this.x.redAdd(this.z);
1655 // AA = A^2
1656 var aa = a.redSqr();
1657 // B = X1 - Z1
1658 var b = this.x.redSub(this.z);
1659 // BB = B^2
1660 var bb = b.redSqr();
1661 // C = AA - BB
1662 var c = aa.redSub(bb);
1663 // X3 = AA * BB
1664 var nx = aa.redMul(bb);
1665 // Z3 = C * (BB + A24 * C)
1666 var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c)));
1667 return this.curve.point(nx, nz);
1668};
1669
1670Point$1.prototype.add = function add() {
1671 throw new Error('Not supported on Montgomery curve');
1672};
1673
1674Point$1.prototype.diffAdd = function diffAdd(p, diff) {
1675 // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3
1676 // 4M + 2S + 6A
1677
1678 // A = X2 + Z2
1679 var a = this.x.redAdd(this.z);
1680 // B = X2 - Z2
1681 var b = this.x.redSub(this.z);
1682 // C = X3 + Z3
1683 var c = p.x.redAdd(p.z);
1684 // D = X3 - Z3
1685 var d = p.x.redSub(p.z);
1686 // DA = D * A
1687 var da = d.redMul(a);
1688 // CB = C * B
1689 var cb = c.redMul(b);
1690 // X5 = Z1 * (DA + CB)^2
1691 var nx = diff.z.redMul(da.redAdd(cb).redSqr());
1692 // Z5 = X1 * (DA - CB)^2
1693 var nz = diff.x.redMul(da.redISub(cb).redSqr());
1694 return this.curve.point(nx, nz);
1695};
1696
1697Point$1.prototype.mul = function mul(k) {
1698 k = new bn(k, 16);
1699
1700 var t = k.clone();
1701 var a = this; // (N / 2) * Q + Q
1702 var b = this.curve.point(null, null); // (N / 2) * Q
1703 var c = this; // Q
1704
1705 for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1))
1706 bits.push(t.andln(1));
1707
1708 for (var i = bits.length - 1; i >= 0; i--) {
1709 if (bits[i] === 0) {
1710 // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q
1711 a = a.diffAdd(b, c);
1712 // N * Q = 2 * ((N / 2) * Q + Q))
1713 b = b.dbl();
1714 } else {
1715 // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q)
1716 b = a.diffAdd(b, c);
1717 // N * Q + Q = 2 * ((N / 2) * Q + Q)
1718 a = a.dbl();
1719 }
1720 }
1721 return b;
1722};
1723
1724Point$1.prototype.mulAdd = function mulAdd() {
1725 throw new Error('Not supported on Montgomery curve');
1726};
1727
1728Point$1.prototype.jumlAdd = function jumlAdd() {
1729 throw new Error('Not supported on Montgomery curve');
1730};
1731
1732Point$1.prototype.eq = function eq(other) {
1733 return this.getX().cmp(other.getX()) === 0;
1734};
1735
1736Point$1.prototype.normalize = function normalize() {
1737 this.x = this.x.redMul(this.z.redInvm());
1738 this.z = this.curve.one;
1739 return this;
1740};
1741
1742Point$1.prototype.getX = function getX() {
1743 // Normalize coordinates
1744 this.normalize();
1745
1746 return this.x.fromRed();
1747};
1748
1749var assert$2 = utils_1$1.assert;
1750
1751function EdwardsCurve(conf) {
1752 // NOTE: Important as we are creating point in Base.call()
1753 this.twisted = (conf.a | 0) !== 1;
1754 this.mOneA = this.twisted && (conf.a | 0) === -1;
1755 this.extended = this.mOneA;
1756
1757 base.call(this, 'edwards', conf);
1758
1759 this.a = new bn(conf.a, 16).umod(this.red.m);
1760 this.a = this.a.toRed(this.red);
1761 this.c = new bn(conf.c, 16).toRed(this.red);
1762 this.c2 = this.c.redSqr();
1763 this.d = new bn(conf.d, 16).toRed(this.red);
1764 this.dd = this.d.redAdd(this.d);
1765
1766 assert$2(!this.twisted || this.c.fromRed().cmpn(1) === 0);
1767 this.oneC = (conf.c | 0) === 1;
1768}
1769inherits_browser(EdwardsCurve, base);
1770var edwards = EdwardsCurve;
1771
1772EdwardsCurve.prototype._mulA = function _mulA(num) {
1773 if (this.mOneA)
1774 return num.redNeg();
1775 else
1776 return this.a.redMul(num);
1777};
1778
1779EdwardsCurve.prototype._mulC = function _mulC(num) {
1780 if (this.oneC)
1781 return num;
1782 else
1783 return this.c.redMul(num);
1784};
1785
1786// Just for compatibility with Short curve
1787EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) {
1788 return this.point(x, y, z, t);
1789};
1790
1791EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) {
1792 x = new bn(x, 16);
1793 if (!x.red)
1794 x = x.toRed(this.red);
1795
1796 var x2 = x.redSqr();
1797 var rhs = this.c2.redSub(this.a.redMul(x2));
1798 var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2));
1799
1800 var y2 = rhs.redMul(lhs.redInvm());
1801 var y = y2.redSqrt();
1802 if (y.redSqr().redSub(y2).cmp(this.zero) !== 0)
1803 throw new Error('invalid point');
1804
1805 var isOdd = y.fromRed().isOdd();
1806 if (odd && !isOdd || !odd && isOdd)
1807 y = y.redNeg();
1808
1809 return this.point(x, y);
1810};
1811
1812EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) {
1813 y = new bn(y, 16);
1814 if (!y.red)
1815 y = y.toRed(this.red);
1816
1817 // x^2 = (y^2 - c^2) / (c^2 d y^2 - a)
1818 var y2 = y.redSqr();
1819 var lhs = y2.redSub(this.c2);
1820 var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a);
1821 var x2 = lhs.redMul(rhs.redInvm());
1822
1823 if (x2.cmp(this.zero) === 0) {
1824 if (odd)
1825 throw new Error('invalid point');
1826 else
1827 return this.point(this.zero, y);
1828 }
1829
1830 var x = x2.redSqrt();
1831 if (x.redSqr().redSub(x2).cmp(this.zero) !== 0)
1832 throw new Error('invalid point');
1833
1834 if (x.fromRed().isOdd() !== odd)
1835 x = x.redNeg();
1836
1837 return this.point(x, y);
1838};
1839
1840EdwardsCurve.prototype.validate = function validate(point) {
1841 if (point.isInfinity())
1842 return true;
1843
1844 // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2)
1845 point.normalize();
1846
1847 var x2 = point.x.redSqr();
1848 var y2 = point.y.redSqr();
1849 var lhs = x2.redMul(this.a).redAdd(y2);
1850 var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2)));
1851
1852 return lhs.cmp(rhs) === 0;
1853};
1854
1855function Point$2(curve, x, y, z, t) {
1856 base.BasePoint.call(this, curve, 'projective');
1857 if (x === null && y === null && z === null) {
1858 this.x = this.curve.zero;
1859 this.y = this.curve.one;
1860 this.z = this.curve.one;
1861 this.t = this.curve.zero;
1862 this.zOne = true;
1863 } else {
1864 this.x = new bn(x, 16);
1865 this.y = new bn(y, 16);
1866 this.z = z ? new bn(z, 16) : this.curve.one;
1867 this.t = t && new bn(t, 16);
1868 if (!this.x.red)
1869 this.x = this.x.toRed(this.curve.red);
1870 if (!this.y.red)
1871 this.y = this.y.toRed(this.curve.red);
1872 if (!this.z.red)
1873 this.z = this.z.toRed(this.curve.red);
1874 if (this.t && !this.t.red)
1875 this.t = this.t.toRed(this.curve.red);
1876 this.zOne = this.z === this.curve.one;
1877
1878 // Use extended coordinates
1879 if (this.curve.extended && !this.t) {
1880 this.t = this.x.redMul(this.y);
1881 if (!this.zOne)
1882 this.t = this.t.redMul(this.z.redInvm());
1883 }
1884 }
1885}
1886inherits_browser(Point$2, base.BasePoint);
1887
1888EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) {
1889 return Point$2.fromJSON(this, obj);
1890};
1891
1892EdwardsCurve.prototype.point = function point(x, y, z, t) {
1893 return new Point$2(this, x, y, z, t);
1894};
1895
1896Point$2.fromJSON = function fromJSON(curve, obj) {
1897 return new Point$2(curve, obj[0], obj[1], obj[2]);
1898};
1899
1900Point$2.prototype.inspect = function inspect() {
1901 if (this.isInfinity())
1902 return '<EC Point Infinity>';
1903 return '<EC Point x: ' + this.x.fromRed().toString(16, 2) +
1904 ' y: ' + this.y.fromRed().toString(16, 2) +
1905 ' z: ' + this.z.fromRed().toString(16, 2) + '>';
1906};
1907
1908Point$2.prototype.isInfinity = function isInfinity() {
1909 // XXX This code assumes that zero is always zero in red
1910 return this.x.cmpn(0) === 0 &&
1911 (this.y.cmp(this.z) === 0 ||
1912 (this.zOne && this.y.cmp(this.curve.c) === 0));
1913};
1914
1915Point$2.prototype._extDbl = function _extDbl() {
1916 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
1917 // #doubling-dbl-2008-hwcd
1918 // 4M + 4S
1919
1920 // A = X1^2
1921 var a = this.x.redSqr();
1922 // B = Y1^2
1923 var b = this.y.redSqr();
1924 // C = 2 * Z1^2
1925 var c = this.z.redSqr();
1926 c = c.redIAdd(c);
1927 // D = a * A
1928 var d = this.curve._mulA(a);
1929 // E = (X1 + Y1)^2 - A - B
1930 var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);
1931 // G = D + B
1932 var g = d.redAdd(b);
1933 // F = G - C
1934 var f = g.redSub(c);
1935 // H = D - B
1936 var h = d.redSub(b);
1937 // X3 = E * F
1938 var nx = e.redMul(f);
1939 // Y3 = G * H
1940 var ny = g.redMul(h);
1941 // T3 = E * H
1942 var nt = e.redMul(h);
1943 // Z3 = F * G
1944 var nz = f.redMul(g);
1945 return this.curve.point(nx, ny, nz, nt);
1946};
1947
1948Point$2.prototype._projDbl = function _projDbl() {
1949 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
1950 // #doubling-dbl-2008-bbjlp
1951 // #doubling-dbl-2007-bl
1952 // and others
1953 // Generally 3M + 4S or 2M + 4S
1954
1955 // B = (X1 + Y1)^2
1956 var b = this.x.redAdd(this.y).redSqr();
1957 // C = X1^2
1958 var c = this.x.redSqr();
1959 // D = Y1^2
1960 var d = this.y.redSqr();
1961
1962 var nx;
1963 var ny;
1964 var nz;
1965 if (this.curve.twisted) {
1966 // E = a * C
1967 var e = this.curve._mulA(c);
1968 // F = E + D
1969 var f = e.redAdd(d);
1970 if (this.zOne) {
1971 // X3 = (B - C - D) * (F - 2)
1972 nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));
1973 // Y3 = F * (E - D)
1974 ny = f.redMul(e.redSub(d));
1975 // Z3 = F^2 - 2 * F
1976 nz = f.redSqr().redSub(f).redSub(f);
1977 } else {
1978 // H = Z1^2
1979 var h = this.z.redSqr();
1980 // J = F - 2 * H
1981 var j = f.redSub(h).redISub(h);
1982 // X3 = (B-C-D)*J
1983 nx = b.redSub(c).redISub(d).redMul(j);
1984 // Y3 = F * (E - D)
1985 ny = f.redMul(e.redSub(d));
1986 // Z3 = F * J
1987 nz = f.redMul(j);
1988 }
1989 } else {
1990 // E = C + D
1991 var e = c.redAdd(d);
1992 // H = (c * Z1)^2
1993 var h = this.curve._mulC(this.z).redSqr();
1994 // J = E - 2 * H
1995 var j = e.redSub(h).redSub(h);
1996 // X3 = c * (B - E) * J
1997 nx = this.curve._mulC(b.redISub(e)).redMul(j);
1998 // Y3 = c * E * (C - D)
1999 ny = this.curve._mulC(e).redMul(c.redISub(d));
2000 // Z3 = E * J
2001 nz = e.redMul(j);
2002 }
2003 return this.curve.point(nx, ny, nz);
2004};
2005
2006Point$2.prototype.dbl = function dbl() {
2007 if (this.isInfinity())
2008 return this;
2009
2010 // Double in extended coordinates
2011 if (this.curve.extended)
2012 return this._extDbl();
2013 else
2014 return this._projDbl();
2015};
2016
2017Point$2.prototype._extAdd = function _extAdd(p) {
2018 // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html
2019 // #addition-add-2008-hwcd-3
2020 // 8M
2021
2022 // A = (Y1 - X1) * (Y2 - X2)
2023 var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x));
2024 // B = (Y1 + X1) * (Y2 + X2)
2025 var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));
2026 // C = T1 * k * T2
2027 var c = this.t.redMul(this.curve.dd).redMul(p.t);
2028 // D = Z1 * 2 * Z2
2029 var d = this.z.redMul(p.z.redAdd(p.z));
2030 // E = B - A
2031 var e = b.redSub(a);
2032 // F = D - C
2033 var f = d.redSub(c);
2034 // G = D + C
2035 var g = d.redAdd(c);
2036 // H = B + A
2037 var h = b.redAdd(a);
2038 // X3 = E * F
2039 var nx = e.redMul(f);
2040 // Y3 = G * H
2041 var ny = g.redMul(h);
2042 // T3 = E * H
2043 var nt = e.redMul(h);
2044 // Z3 = F * G
2045 var nz = f.redMul(g);
2046 return this.curve.point(nx, ny, nz, nt);
2047};
2048
2049Point$2.prototype._projAdd = function _projAdd(p) {
2050 // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html
2051 // #addition-add-2008-bbjlp
2052 // #addition-add-2007-bl
2053 // 10M + 1S
2054
2055 // A = Z1 * Z2
2056 var a = this.z.redMul(p.z);
2057 // B = A^2
2058 var b = a.redSqr();
2059 // C = X1 * X2
2060 var c = this.x.redMul(p.x);
2061 // D = Y1 * Y2
2062 var d = this.y.redMul(p.y);
2063 // E = d * C * D
2064 var e = this.curve.d.redMul(c).redMul(d);
2065 // F = B - E
2066 var f = b.redSub(e);
2067 // G = B + E
2068 var g = b.redAdd(e);
2069 // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D)
2070 var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);
2071 var nx = a.redMul(f).redMul(tmp);
2072 var ny;
2073 var nz;
2074 if (this.curve.twisted) {
2075 // Y3 = A * G * (D - a * C)
2076 ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));
2077 // Z3 = F * G
2078 nz = f.redMul(g);
2079 } else {
2080 // Y3 = A * G * (D - C)
2081 ny = a.redMul(g).redMul(d.redSub(c));
2082 // Z3 = c * F * G
2083 nz = this.curve._mulC(f).redMul(g);
2084 }
2085 return this.curve.point(nx, ny, nz);
2086};
2087
2088Point$2.prototype.add = function add(p) {
2089 if (this.isInfinity())
2090 return p;
2091 if (p.isInfinity())
2092 return this;
2093
2094 if (this.curve.extended)
2095 return this._extAdd(p);
2096 else
2097 return this._projAdd(p);
2098};
2099
2100Point$2.prototype.mul = function mul(k) {
2101 if (this._hasDoubles(k))
2102 return this.curve._fixedNafMul(this, k);
2103 else
2104 return this.curve._wnafMul(this, k);
2105};
2106
2107Point$2.prototype.mulAdd = function mulAdd(k1, p, k2) {
2108 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, false);
2109};
2110
2111Point$2.prototype.jmulAdd = function jmulAdd(k1, p, k2) {
2112 return this.curve._wnafMulAdd(1, [ this, p ], [ k1, k2 ], 2, true);
2113};
2114
2115Point$2.prototype.normalize = function normalize() {
2116 if (this.zOne)
2117 return this;
2118
2119 // Normalize coordinates
2120 var zi = this.z.redInvm();
2121 this.x = this.x.redMul(zi);
2122 this.y = this.y.redMul(zi);
2123 if (this.t)
2124 this.t = this.t.redMul(zi);
2125 this.z = this.curve.one;
2126 this.zOne = true;
2127 return this;
2128};
2129
2130Point$2.prototype.neg = function neg() {
2131 return this.curve.point(this.x.redNeg(),
2132 this.y,
2133 this.z,
2134 this.t && this.t.redNeg());
2135};
2136
2137Point$2.prototype.getX = function getX() {
2138 this.normalize();
2139 return this.x.fromRed();
2140};
2141
2142Point$2.prototype.getY = function getY() {
2143 this.normalize();
2144 return this.y.fromRed();
2145};
2146
2147Point$2.prototype.eq = function eq(other) {
2148 return this === other ||
2149 this.getX().cmp(other.getX()) === 0 &&
2150 this.getY().cmp(other.getY()) === 0;
2151};
2152
2153Point$2.prototype.eqXToP = function eqXToP(x) {
2154 var rx = x.toRed(this.curve.red).redMul(this.z);
2155 if (this.x.cmp(rx) === 0)
2156 return true;
2157
2158 var xc = x.clone();
2159 var t = this.curve.redN.redMul(this.z);
2160 for (;;) {
2161 xc.iadd(this.curve.n);
2162 if (xc.cmp(this.curve.p) >= 0)
2163 return false;
2164
2165 rx.redIAdd(t);
2166 if (this.x.cmp(rx) === 0)
2167 return true;
2168 }
2169};
2170
2171// Compatibility with BaseCurve
2172Point$2.prototype.toP = Point$2.prototype.normalize;
2173Point$2.prototype.mixedAdd = Point$2.prototype.add;
2174
2175var curve_1 = createCommonjsModule(function (module, exports) {
2176
2177var curve = exports;
2178
2179curve.base = base;
2180curve.short = short_1;
2181curve.mont = mont;
2182curve.edwards = edwards;
2183});
2184
2185var rotl32 = utils.rotl32;
2186var sum32 = utils.sum32;
2187var sum32_5 = utils.sum32_5;
2188var ft_1 = common.ft_1;
2189var BlockHash = common$1.BlockHash;
2190
2191var sha1_K = [
2192 0x5A827999, 0x6ED9EBA1,
2193 0x8F1BBCDC, 0xCA62C1D6
2194];
2195
2196function SHA1() {
2197 if (!(this instanceof SHA1))
2198 return new SHA1();
2199
2200 BlockHash.call(this);
2201 this.h = [
2202 0x67452301, 0xefcdab89, 0x98badcfe,
2203 0x10325476, 0xc3d2e1f0 ];
2204 this.W = new Array(80);
2205}
2206
2207utils.inherits(SHA1, BlockHash);
2208var _1 = SHA1;
2209
2210SHA1.blockSize = 512;
2211SHA1.outSize = 160;
2212SHA1.hmacStrength = 80;
2213SHA1.padLength = 64;
2214
2215SHA1.prototype._update = function _update(msg, start) {
2216 var W = this.W;
2217
2218 for (var i = 0; i < 16; i++)
2219 W[i] = msg[start + i];
2220
2221 for(; i < W.length; i++)
2222 W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
2223
2224 var a = this.h[0];
2225 var b = this.h[1];
2226 var c = this.h[2];
2227 var d = this.h[3];
2228 var e = this.h[4];
2229
2230 for (i = 0; i < W.length; i++) {
2231 var s = ~~(i / 20);
2232 var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
2233 e = d;
2234 d = c;
2235 c = rotl32(b, 30);
2236 b = a;
2237 a = t;
2238 }
2239
2240 this.h[0] = sum32(this.h[0], a);
2241 this.h[1] = sum32(this.h[1], b);
2242 this.h[2] = sum32(this.h[2], c);
2243 this.h[3] = sum32(this.h[3], d);
2244 this.h[4] = sum32(this.h[4], e);
2245};
2246
2247SHA1.prototype._digest = function digest(enc) {
2248 if (enc === 'hex')
2249 return utils.toHex32(this.h, 'big');
2250 else
2251 return utils.split32(this.h, 'big');
2252};
2253
2254var sha1 = _1;
2255var sha224 = _224;
2256var sha256 = _256;
2257var sha384 = _384;
2258var sha512 = _512;
2259
2260var sha = {
2261 sha1: sha1,
2262 sha224: sha224,
2263 sha256: sha256,
2264 sha384: sha384,
2265 sha512: sha512
2266};
2267
2268function Hmac(hash, key, enc) {
2269 if (!(this instanceof Hmac))
2270 return new Hmac(hash, key, enc);
2271 this.Hash = hash;
2272 this.blockSize = hash.blockSize / 8;
2273 this.outSize = hash.outSize / 8;
2274 this.inner = null;
2275 this.outer = null;
2276
2277 this._init(utils.toArray(key, enc));
2278}
2279var hmac = Hmac;
2280
2281Hmac.prototype._init = function init(key) {
2282 // Shorten key, if needed
2283 if (key.length > this.blockSize)
2284 key = new this.Hash().update(key).digest();
2285 minimalisticAssert(key.length <= this.blockSize);
2286
2287 // Add padding to key
2288 for (var i = key.length; i < this.blockSize; i++)
2289 key.push(0);
2290
2291 for (i = 0; i < key.length; i++)
2292 key[i] ^= 0x36;
2293 this.inner = new this.Hash().update(key);
2294
2295 // 0x36 ^ 0x5c = 0x6a
2296 for (i = 0; i < key.length; i++)
2297 key[i] ^= 0x6a;
2298 this.outer = new this.Hash().update(key);
2299};
2300
2301Hmac.prototype.update = function update(msg, enc) {
2302 this.inner.update(msg, enc);
2303 return this;
2304};
2305
2306Hmac.prototype.digest = function digest(enc) {
2307 this.outer.update(this.inner.digest());
2308 return this.outer.digest(enc);
2309};
2310
2311var hash_1 = createCommonjsModule(function (module, exports) {
2312var hash = exports;
2313
2314hash.utils = utils;
2315hash.common = common$1;
2316hash.sha = sha;
2317hash.ripemd = ripemd;
2318hash.hmac = hmac;
2319
2320// Proxy hash functions to the main object
2321hash.sha1 = hash.sha.sha1;
2322hash.sha256 = hash.sha.sha256;
2323hash.sha224 = hash.sha.sha224;
2324hash.sha384 = hash.sha.sha384;
2325hash.sha512 = hash.sha.sha512;
2326hash.ripemd160 = hash.ripemd.ripemd160;
2327});
2328
2329var secp256k1 = {
2330 doubles: {
2331 step: 4,
2332 points: [
2333 [
2334 'e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a',
2335 'f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821'
2336 ],
2337 [
2338 '8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508',
2339 '11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf'
2340 ],
2341 [
2342 '175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739',
2343 'd3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695'
2344 ],
2345 [
2346 '363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640',
2347 '4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9'
2348 ],
2349 [
2350 '8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c',
2351 '4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36'
2352 ],
2353 [
2354 '723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda',
2355 '96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f'
2356 ],
2357 [
2358 'eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa',
2359 '5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999'
2360 ],
2361 [
2362 '100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0',
2363 'cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09'
2364 ],
2365 [
2366 'e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d',
2367 '9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d'
2368 ],
2369 [
2370 'feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d',
2371 'e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088'
2372 ],
2373 [
2374 'da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1',
2375 '9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d'
2376 ],
2377 [
2378 '53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0',
2379 '5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8'
2380 ],
2381 [
2382 '8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047',
2383 '10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a'
2384 ],
2385 [
2386 '385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862',
2387 '283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453'
2388 ],
2389 [
2390 '6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7',
2391 '7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160'
2392 ],
2393 [
2394 '3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd',
2395 '56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0'
2396 ],
2397 [
2398 '85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83',
2399 '7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6'
2400 ],
2401 [
2402 '948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a',
2403 '53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589'
2404 ],
2405 [
2406 '6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8',
2407 'bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17'
2408 ],
2409 [
2410 'e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d',
2411 '4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda'
2412 ],
2413 [
2414 'e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725',
2415 '7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd'
2416 ],
2417 [
2418 '213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754',
2419 '4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2'
2420 ],
2421 [
2422 '4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c',
2423 '17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6'
2424 ],
2425 [
2426 'fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6',
2427 '6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f'
2428 ],
2429 [
2430 '76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39',
2431 'c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01'
2432 ],
2433 [
2434 'c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891',
2435 '893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3'
2436 ],
2437 [
2438 'd895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b',
2439 'febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f'
2440 ],
2441 [
2442 'b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03',
2443 '2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7'
2444 ],
2445 [
2446 'e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d',
2447 'eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78'
2448 ],
2449 [
2450 'a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070',
2451 '7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1'
2452 ],
2453 [
2454 '90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4',
2455 'e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150'
2456 ],
2457 [
2458 '8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da',
2459 '662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82'
2460 ],
2461 [
2462 'e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11',
2463 '1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc'
2464 ],
2465 [
2466 '8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e',
2467 'efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b'
2468 ],
2469 [
2470 'e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41',
2471 '2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51'
2472 ],
2473 [
2474 'b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef',
2475 '67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45'
2476 ],
2477 [
2478 'd68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8',
2479 'db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120'
2480 ],
2481 [
2482 '324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d',
2483 '648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84'
2484 ],
2485 [
2486 '4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96',
2487 '35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d'
2488 ],
2489 [
2490 '9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd',
2491 'ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d'
2492 ],
2493 [
2494 '6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5',
2495 '9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8'
2496 ],
2497 [
2498 'a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266',
2499 '40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8'
2500 ],
2501 [
2502 '7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71',
2503 '34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac'
2504 ],
2505 [
2506 '928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac',
2507 'c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f'
2508 ],
2509 [
2510 '85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751',
2511 '1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962'
2512 ],
2513 [
2514 'ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e',
2515 '493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907'
2516 ],
2517 [
2518 '827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241',
2519 'c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec'
2520 ],
2521 [
2522 'eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3',
2523 'be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d'
2524 ],
2525 [
2526 'e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f',
2527 '4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414'
2528 ],
2529 [
2530 '1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19',
2531 'aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd'
2532 ],
2533 [
2534 '146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be',
2535 'b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0'
2536 ],
2537 [
2538 'fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9',
2539 '6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811'
2540 ],
2541 [
2542 'da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2',
2543 '8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1'
2544 ],
2545 [
2546 'a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13',
2547 '7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c'
2548 ],
2549 [
2550 '174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c',
2551 'ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73'
2552 ],
2553 [
2554 '959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba',
2555 '2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd'
2556 ],
2557 [
2558 'd2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151',
2559 'e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405'
2560 ],
2561 [
2562 '64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073',
2563 'd99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589'
2564 ],
2565 [
2566 '8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458',
2567 '38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e'
2568 ],
2569 [
2570 '13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b',
2571 '69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27'
2572 ],
2573 [
2574 'bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366',
2575 'd3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1'
2576 ],
2577 [
2578 '8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa',
2579 '40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482'
2580 ],
2581 [
2582 '8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0',
2583 '620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945'
2584 ],
2585 [
2586 'dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787',
2587 '7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573'
2588 ],
2589 [
2590 'f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e',
2591 'ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82'
2592 ]
2593 ]
2594 },
2595 naf: {
2596 wnd: 7,
2597 points: [
2598 [
2599 'f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9',
2600 '388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672'
2601 ],
2602 [
2603 '2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4',
2604 'd8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6'
2605 ],
2606 [
2607 '5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc',
2608 '6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da'
2609 ],
2610 [
2611 'acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe',
2612 'cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37'
2613 ],
2614 [
2615 '774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb',
2616 'd984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b'
2617 ],
2618 [
2619 'f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8',
2620 'ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81'
2621 ],
2622 [
2623 'd7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e',
2624 '581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58'
2625 ],
2626 [
2627 'defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34',
2628 '4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77'
2629 ],
2630 [
2631 '2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c',
2632 '85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a'
2633 ],
2634 [
2635 '352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5',
2636 '321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c'
2637 ],
2638 [
2639 '2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f',
2640 '2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67'
2641 ],
2642 [
2643 '9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714',
2644 '73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402'
2645 ],
2646 [
2647 'daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729',
2648 'a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55'
2649 ],
2650 [
2651 'c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db',
2652 '2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482'
2653 ],
2654 [
2655 '6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4',
2656 'e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82'
2657 ],
2658 [
2659 '1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5',
2660 'b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396'
2661 ],
2662 [
2663 '605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479',
2664 '2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49'
2665 ],
2666 [
2667 '62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d',
2668 '80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf'
2669 ],
2670 [
2671 '80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f',
2672 '1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a'
2673 ],
2674 [
2675 '7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb',
2676 'd0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7'
2677 ],
2678 [
2679 'd528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9',
2680 'eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933'
2681 ],
2682 [
2683 '49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963',
2684 '758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a'
2685 ],
2686 [
2687 '77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74',
2688 '958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6'
2689 ],
2690 [
2691 'f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530',
2692 'e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37'
2693 ],
2694 [
2695 '463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b',
2696 '5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e'
2697 ],
2698 [
2699 'f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247',
2700 'cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6'
2701 ],
2702 [
2703 'caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1',
2704 'cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476'
2705 ],
2706 [
2707 '2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120',
2708 '4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40'
2709 ],
2710 [
2711 '7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435',
2712 '91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61'
2713 ],
2714 [
2715 '754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18',
2716 '673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683'
2717 ],
2718 [
2719 'e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8',
2720 '59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5'
2721 ],
2722 [
2723 '186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb',
2724 '3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b'
2725 ],
2726 [
2727 'df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f',
2728 '55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417'
2729 ],
2730 [
2731 '5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143',
2732 'efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868'
2733 ],
2734 [
2735 '290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba',
2736 'e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a'
2737 ],
2738 [
2739 'af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45',
2740 'f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6'
2741 ],
2742 [
2743 '766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a',
2744 '744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996'
2745 ],
2746 [
2747 '59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e',
2748 'c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e'
2749 ],
2750 [
2751 'f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8',
2752 'e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d'
2753 ],
2754 [
2755 '7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c',
2756 '30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2'
2757 ],
2758 [
2759 '948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519',
2760 'e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e'
2761 ],
2762 [
2763 '7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab',
2764 '100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437'
2765 ],
2766 [
2767 '3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca',
2768 'ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311'
2769 ],
2770 [
2771 'd3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf',
2772 '8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4'
2773 ],
2774 [
2775 '1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610',
2776 '68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575'
2777 ],
2778 [
2779 '733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4',
2780 'f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d'
2781 ],
2782 [
2783 '15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c',
2784 'd56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d'
2785 ],
2786 [
2787 'a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940',
2788 'edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629'
2789 ],
2790 [
2791 'e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980',
2792 'a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06'
2793 ],
2794 [
2795 '311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3',
2796 '66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374'
2797 ],
2798 [
2799 '34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf',
2800 '9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee'
2801 ],
2802 [
2803 'f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63',
2804 '4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1'
2805 ],
2806 [
2807 'd7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448',
2808 'fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b'
2809 ],
2810 [
2811 '32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf',
2812 '5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661'
2813 ],
2814 [
2815 '7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5',
2816 '8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6'
2817 ],
2818 [
2819 'ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6',
2820 '8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e'
2821 ],
2822 [
2823 '16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5',
2824 '5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d'
2825 ],
2826 [
2827 'eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99',
2828 'f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc'
2829 ],
2830 [
2831 '78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51',
2832 'f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4'
2833 ],
2834 [
2835 '494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5',
2836 '42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c'
2837 ],
2838 [
2839 'a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5',
2840 '204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b'
2841 ],
2842 [
2843 'c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997',
2844 '4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913'
2845 ],
2846 [
2847 '841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881',
2848 '73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154'
2849 ],
2850 [
2851 '5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5',
2852 '39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865'
2853 ],
2854 [
2855 '36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66',
2856 'd2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc'
2857 ],
2858 [
2859 '336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726',
2860 'ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224'
2861 ],
2862 [
2863 '8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede',
2864 '6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e'
2865 ],
2866 [
2867 '1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94',
2868 '60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6'
2869 ],
2870 [
2871 '85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31',
2872 '3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511'
2873 ],
2874 [
2875 '29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51',
2876 'b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b'
2877 ],
2878 [
2879 'a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252',
2880 'ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2'
2881 ],
2882 [
2883 '4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5',
2884 'cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c'
2885 ],
2886 [
2887 'd24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b',
2888 '6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3'
2889 ],
2890 [
2891 'ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4',
2892 '322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d'
2893 ],
2894 [
2895 'af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f',
2896 '6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700'
2897 ],
2898 [
2899 'e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889',
2900 '2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4'
2901 ],
2902 [
2903 '591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246',
2904 'b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196'
2905 ],
2906 [
2907 '11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984',
2908 '998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4'
2909 ],
2910 [
2911 '3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a',
2912 'b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257'
2913 ],
2914 [
2915 'cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030',
2916 'bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13'
2917 ],
2918 [
2919 'c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197',
2920 '6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096'
2921 ],
2922 [
2923 'c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593',
2924 'c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38'
2925 ],
2926 [
2927 'a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef',
2928 '21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f'
2929 ],
2930 [
2931 '347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38',
2932 '60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448'
2933 ],
2934 [
2935 'da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a',
2936 '49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a'
2937 ],
2938 [
2939 'c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111',
2940 '5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4'
2941 ],
2942 [
2943 '4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502',
2944 '7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437'
2945 ],
2946 [
2947 '3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea',
2948 'be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7'
2949 ],
2950 [
2951 'cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26',
2952 '8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d'
2953 ],
2954 [
2955 'b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986',
2956 '39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a'
2957 ],
2958 [
2959 'd4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e',
2960 '62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54'
2961 ],
2962 [
2963 '48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4',
2964 '25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77'
2965 ],
2966 [
2967 'dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda',
2968 'ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517'
2969 ],
2970 [
2971 '6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859',
2972 'cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10'
2973 ],
2974 [
2975 'e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f',
2976 'f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125'
2977 ],
2978 [
2979 'eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c',
2980 '6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e'
2981 ],
2982 [
2983 '13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942',
2984 'fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1'
2985 ],
2986 [
2987 'ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a',
2988 '1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2'
2989 ],
2990 [
2991 'b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80',
2992 '5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423'
2993 ],
2994 [
2995 'ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d',
2996 '438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8'
2997 ],
2998 [
2999 '8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1',
3000 'cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758'
3001 ],
3002 [
3003 '52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63',
3004 'c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375'
3005 ],
3006 [
3007 'e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352',
3008 '6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d'
3009 ],
3010 [
3011 '7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193',
3012 'ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec'
3013 ],
3014 [
3015 '5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00',
3016 '9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0'
3017 ],
3018 [
3019 '32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58',
3020 'ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c'
3021 ],
3022 [
3023 'e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7',
3024 'd3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4'
3025 ],
3026 [
3027 '8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8',
3028 'c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f'
3029 ],
3030 [
3031 '4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e',
3032 '67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649'
3033 ],
3034 [
3035 '3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d',
3036 'cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826'
3037 ],
3038 [
3039 '674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b',
3040 '299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5'
3041 ],
3042 [
3043 'd32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f',
3044 'f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87'
3045 ],
3046 [
3047 '30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6',
3048 '462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b'
3049 ],
3050 [
3051 'be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297',
3052 '62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc'
3053 ],
3054 [
3055 '93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a',
3056 '7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c'
3057 ],
3058 [
3059 'b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c',
3060 'ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f'
3061 ],
3062 [
3063 'd5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52',
3064 '4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a'
3065 ],
3066 [
3067 'd3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb',
3068 'bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46'
3069 ],
3070 [
3071 '463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065',
3072 'bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f'
3073 ],
3074 [
3075 '7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917',
3076 '603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03'
3077 ],
3078 [
3079 '74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9',
3080 'cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08'
3081 ],
3082 [
3083 '30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3',
3084 '553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8'
3085 ],
3086 [
3087 '9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57',
3088 '712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373'
3089 ],
3090 [
3091 '176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66',
3092 'ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3'
3093 ],
3094 [
3095 '75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8',
3096 '9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8'
3097 ],
3098 [
3099 '809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721',
3100 '9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1'
3101 ],
3102 [
3103 '1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180',
3104 '4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9'
3105 ]
3106 ]
3107 }
3108};
3109
3110var curves_1 = createCommonjsModule(function (module, exports) {
3111
3112var curves = exports;
3113
3114
3115
3116
3117
3118var assert = utils_1$1.assert;
3119
3120function PresetCurve(options) {
3121 if (options.type === 'short')
3122 this.curve = new curve_1.short(options);
3123 else if (options.type === 'edwards')
3124 this.curve = new curve_1.edwards(options);
3125 else if (options.type === 'mont')
3126 this.curve = new curve_1.mont(options);
3127 else throw new Error('Unknown curve type.');
3128 this.g = this.curve.g;
3129 this.n = this.curve.n;
3130 this.hash = options.hash;
3131
3132 assert(this.g.validate(), 'Invalid curve');
3133 assert(this.g.mul(this.n).isInfinity(), 'Invalid curve, n*G != O');
3134}
3135curves.PresetCurve = PresetCurve;
3136
3137function defineCurve(name, options) {
3138 Object.defineProperty(curves, name, {
3139 configurable: true,
3140 enumerable: true,
3141 get: function() {
3142 var curve = new PresetCurve(options);
3143 Object.defineProperty(curves, name, {
3144 configurable: true,
3145 enumerable: true,
3146 value: curve
3147 });
3148 return curve;
3149 }
3150 });
3151}
3152
3153defineCurve('p192', {
3154 type: 'short',
3155 prime: 'p192',
3156 p: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff',
3157 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc',
3158 b: '64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1',
3159 n: 'ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831',
3160 hash: hash_1.sha256,
3161 gRed: false,
3162 g: [
3163 '188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012',
3164 '07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811'
3165 ]
3166});
3167
3168defineCurve('p224', {
3169 type: 'short',
3170 prime: 'p224',
3171 p: 'ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001',
3172 a: 'ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe',
3173 b: 'b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4',
3174 n: 'ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d',
3175 hash: hash_1.sha256,
3176 gRed: false,
3177 g: [
3178 'b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21',
3179 'bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34'
3180 ]
3181});
3182
3183defineCurve('p256', {
3184 type: 'short',
3185 prime: null,
3186 p: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff',
3187 a: 'ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc',
3188 b: '5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b',
3189 n: 'ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551',
3190 hash: hash_1.sha256,
3191 gRed: false,
3192 g: [
3193 '6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296',
3194 '4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5'
3195 ]
3196});
3197
3198defineCurve('p384', {
3199 type: 'short',
3200 prime: null,
3201 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3202 'fffffffe ffffffff 00000000 00000000 ffffffff',
3203 a: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3204 'fffffffe ffffffff 00000000 00000000 fffffffc',
3205 b: 'b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f ' +
3206 '5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef',
3207 n: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 ' +
3208 'f4372ddf 581a0db2 48b0a77a ecec196a ccc52973',
3209 hash: hash_1.sha384,
3210 gRed: false,
3211 g: [
3212 'aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 ' +
3213 '5502f25d bf55296c 3a545e38 72760ab7',
3214 '3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 ' +
3215 '0a60b1ce 1d7e819d 7a431d7c 90ea0e5f'
3216 ]
3217});
3218
3219defineCurve('p521', {
3220 type: 'short',
3221 prime: null,
3222 p: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3223 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3224 'ffffffff ffffffff ffffffff ffffffff ffffffff',
3225 a: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3226 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3227 'ffffffff ffffffff ffffffff ffffffff fffffffc',
3228 b: '00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b ' +
3229 '99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd ' +
3230 '3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00',
3231 n: '000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ' +
3232 'ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 ' +
3233 'f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409',
3234 hash: hash_1.sha512,
3235 gRed: false,
3236 g: [
3237 '000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 ' +
3238 '053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 ' +
3239 'a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66',
3240 '00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 ' +
3241 '579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 ' +
3242 '3fad0761 353c7086 a272c240 88be9476 9fd16650'
3243 ]
3244});
3245
3246// https://tools.ietf.org/html/rfc7748#section-4.1
3247defineCurve('curve25519', {
3248 type: 'mont',
3249 prime: 'p25519',
3250 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
3251 a: '76d06',
3252 b: '1',
3253 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
3254 cofactor: '8',
3255 hash: hash_1.sha256,
3256 gRed: false,
3257 g: [
3258 '9'
3259 ]
3260});
3261
3262defineCurve('ed25519', {
3263 type: 'edwards',
3264 prime: 'p25519',
3265 p: '7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed',
3266 a: '-1',
3267 c: '1',
3268 // -121665 * (121666^(-1)) (mod P)
3269 d: '52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3',
3270 n: '1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed',
3271 cofactor: '8',
3272 hash: hash_1.sha256,
3273 gRed: false,
3274 g: [
3275 '216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a',
3276 // 4/5
3277 '6666666666666666666666666666666666666666666666666666666666666658'
3278 ]
3279});
3280
3281// https://tools.ietf.org/html/rfc5639#section-3.4
3282defineCurve('brainpoolP256r1', {
3283 type: 'short',
3284 prime: null,
3285 p: 'A9FB57DB A1EEA9BC 3E660A90 9D838D72 6E3BF623 D5262028 2013481D 1F6E5377',
3286 a: '7D5A0975 FC2C3057 EEF67530 417AFFE7 FB8055C1 26DC5C6C E94A4B44 F330B5D9',
3287 b: '26DC5C6C E94A4B44 F330B5D9 BBD77CBF 95841629 5CF7E1CE 6BCCDC18 FF8C07B6',
3288 n: 'A9FB57DB A1EEA9BC 3E660A90 9D838D71 8C397AA3 B561A6F7 901E0E82 974856A7',
3289 hash: hash_1.sha256, // or 384, or 512
3290 gRed: false,
3291 g: [
3292 '8BD2AEB9CB7E57CB2C4B482FFC81B7AFB9DE27E1E3BD23C23A4453BD9ACE3262',
3293 '547EF835C3DAC4FD97F8461A14611DC9C27745132DED8E545C1D54C72F046997'
3294 ]
3295});
3296
3297// https://tools.ietf.org/html/rfc5639#section-3.6
3298defineCurve('brainpoolP384r1', {
3299 type: 'short',
3300 prime: null,
3301 p: '8CB91E82 A3386D28 0F5D6F7E 50E641DF 152F7109 ED5456B4 12B1DA19 7FB71123' +
3302 'ACD3A729 901D1A71 87470013 3107EC53',
3303 a: '7BC382C6 3D8C150C 3C72080A CE05AFA0 C2BEA28E 4FB22787 139165EF BA91F90F' +
3304 '8AA5814A 503AD4EB 04A8C7DD 22CE2826',
3305 b: '04A8C7DD 22CE2826 8B39B554 16F0447C 2FB77DE1 07DCD2A6 2E880EA5 3EEB62D5' +
3306 '7CB43902 95DBC994 3AB78696 FA504C11',
3307 n: '8CB91E82 A3386D28 0F5D6F7E 50E641DF 152F7109 ED5456B3 1F166E6C AC0425A7' +
3308 'CF3AB6AF 6B7FC310 3B883202 E9046565',
3309 hash: hash_1.sha384, // or 512
3310 gRed: false,
3311 g: [
3312 '1D1C64F068CF45FFA2A63A81B7C13F6B8847A3E77EF14FE3DB7FCAFE0CBD10' +
3313 'E8E826E03436D646AAEF87B2E247D4AF1E',
3314 '8ABE1D7520F9C2A45CB1EB8E95CFD55262B70B29FEEC5864E19C054FF99129' +
3315 '280E4646217791811142820341263C5315'
3316 ]
3317});
3318
3319// https://tools.ietf.org/html/rfc5639#section-3.7
3320defineCurve('brainpoolP512r1', {
3321 type: 'short',
3322 prime: null,
3323 p: 'AADD9DB8 DBE9C48B 3FD4E6AE 33C9FC07 CB308DB3 B3C9D20E D6639CCA 70330871' +
3324 '7D4D9B00 9BC66842 AECDA12A E6A380E6 2881FF2F 2D82C685 28AA6056 583A48F3',
3325 a: '7830A331 8B603B89 E2327145 AC234CC5 94CBDD8D 3DF91610 A83441CA EA9863BC' +
3326 '2DED5D5A A8253AA1 0A2EF1C9 8B9AC8B5 7F1117A7 2BF2C7B9 E7C1AC4D 77FC94CA',
3327 b: '3DF91610 A83441CA EA9863BC 2DED5D5A A8253AA1 0A2EF1C9 8B9AC8B5 7F1117A7' +
3328 '2BF2C7B9 E7C1AC4D 77FC94CA DC083E67 984050B7 5EBAE5DD 2809BD63 8016F723',
3329 n: 'AADD9DB8 DBE9C48B 3FD4E6AE 33C9FC07 CB308DB3 B3C9D20E D6639CCA 70330870' +
3330 '553E5C41 4CA92619 41866119 7FAC1047 1DB1D381 085DDADD B5879682 9CA90069',
3331 hash: hash_1.sha512,
3332 gRed: false,
3333 g: [
3334 '81AEE4BDD82ED9645A21322E9C4C6A9385ED9F70B5D916C1B43B62EEF4D009' +
3335 '8EFF3B1F78E2D0D48D50D1687B93B97D5F7C6D5047406A5E688B352209BCB9F822',
3336 '7DDE385D566332ECC0EABFA9CF7822FDF209F70024A57B1AA000C55B881F81' +
3337 '11B2DCDE494A5F485E5BCA4BD88A2763AED1CA2B2FA8F0540678CD1E0F3AD80892'
3338 ]
3339});
3340
3341// https://en.bitcoin.it/wiki/Secp256k1
3342var pre;
3343try {
3344 pre = secp256k1;
3345} catch (e) {
3346 pre = undefined;
3347}
3348
3349defineCurve('secp256k1', {
3350 type: 'short',
3351 prime: 'k256',
3352 p: 'ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f',
3353 a: '0',
3354 b: '7',
3355 n: 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141',
3356 h: '1',
3357 hash: hash_1.sha256,
3358
3359 // Precomputed endomorphism
3360 beta: '7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee',
3361 lambda: '5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72',
3362 basis: [
3363 {
3364 a: '3086d221a7d46bcde86c90e49284eb15',
3365 b: '-e4437ed6010e88286f547fa90abfe4c3'
3366 },
3367 {
3368 a: '114ca50f7a8e2f3f657c1108d9d44cfd8',
3369 b: '3086d221a7d46bcde86c90e49284eb15'
3370 }
3371 ],
3372
3373 gRed: false,
3374 g: [
3375 '79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
3376 '483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8',
3377 pre
3378 ]
3379});
3380});
3381
3382function HmacDRBG(options) {
3383 if (!(this instanceof HmacDRBG))
3384 return new HmacDRBG(options);
3385 this.hash = options.hash;
3386 this.predResist = !!options.predResist;
3387
3388 this.outLen = this.hash.outSize;
3389 this.minEntropy = options.minEntropy || this.hash.hmacStrength;
3390
3391 this._reseed = null;
3392 this.reseedInterval = null;
3393 this.K = null;
3394 this.V = null;
3395
3396 var entropy = utils_1.toArray(options.entropy, options.entropyEnc || 'hex');
3397 var nonce = utils_1.toArray(options.nonce, options.nonceEnc || 'hex');
3398 var pers = utils_1.toArray(options.pers, options.persEnc || 'hex');
3399 minimalisticAssert(entropy.length >= (this.minEntropy / 8),
3400 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
3401 this._init(entropy, nonce, pers);
3402}
3403var hmacDrbg = HmacDRBG;
3404
3405HmacDRBG.prototype._init = function init(entropy, nonce, pers) {
3406 var seed = entropy.concat(nonce).concat(pers);
3407
3408 this.K = new Array(this.outLen / 8);
3409 this.V = new Array(this.outLen / 8);
3410 for (var i = 0; i < this.V.length; i++) {
3411 this.K[i] = 0x00;
3412 this.V[i] = 0x01;
3413 }
3414
3415 this._update(seed);
3416 this._reseed = 1;
3417 this.reseedInterval = 0x1000000000000; // 2^48
3418};
3419
3420HmacDRBG.prototype._hmac = function hmac() {
3421 return new hash_1.hmac(this.hash, this.K);
3422};
3423
3424HmacDRBG.prototype._update = function update(seed) {
3425 var kmac = this._hmac()
3426 .update(this.V)
3427 .update([ 0x00 ]);
3428 if (seed)
3429 kmac = kmac.update(seed);
3430 this.K = kmac.digest();
3431 this.V = this._hmac().update(this.V).digest();
3432 if (!seed)
3433 return;
3434
3435 this.K = this._hmac()
3436 .update(this.V)
3437 .update([ 0x01 ])
3438 .update(seed)
3439 .digest();
3440 this.V = this._hmac().update(this.V).digest();
3441};
3442
3443HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) {
3444 // Optional entropy enc
3445 if (typeof entropyEnc !== 'string') {
3446 addEnc = add;
3447 add = entropyEnc;
3448 entropyEnc = null;
3449 }
3450
3451 entropy = utils_1.toArray(entropy, entropyEnc);
3452 add = utils_1.toArray(add, addEnc);
3453
3454 minimalisticAssert(entropy.length >= (this.minEntropy / 8),
3455 'Not enough entropy. Minimum is: ' + this.minEntropy + ' bits');
3456
3457 this._update(entropy.concat(add || []));
3458 this._reseed = 1;
3459};
3460
3461HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) {
3462 if (this._reseed > this.reseedInterval)
3463 throw new Error('Reseed is required');
3464
3465 // Optional encoding
3466 if (typeof enc !== 'string') {
3467 addEnc = add;
3468 add = enc;
3469 enc = null;
3470 }
3471
3472 // Optional additional data
3473 if (add) {
3474 add = utils_1.toArray(add, addEnc || 'hex');
3475 this._update(add);
3476 }
3477
3478 var temp = [];
3479 while (temp.length < len) {
3480 this.V = this._hmac().update(this.V).digest();
3481 temp = temp.concat(this.V);
3482 }
3483
3484 var res = temp.slice(0, len);
3485 this._update(add);
3486 this._reseed++;
3487 return utils_1.encode(res, enc);
3488};
3489
3490var assert$3 = utils_1$1.assert;
3491
3492function KeyPair(ec, options) {
3493 this.ec = ec;
3494 this.priv = null;
3495 this.pub = null;
3496
3497 // KeyPair(ec, { priv: ..., pub: ... })
3498 if (options.priv)
3499 this._importPrivate(options.priv, options.privEnc);
3500 if (options.pub)
3501 this._importPublic(options.pub, options.pubEnc);
3502}
3503var key = KeyPair;
3504
3505KeyPair.fromPublic = function fromPublic(ec, pub, enc) {
3506 if (pub instanceof KeyPair)
3507 return pub;
3508
3509 return new KeyPair(ec, {
3510 pub: pub,
3511 pubEnc: enc
3512 });
3513};
3514
3515KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) {
3516 if (priv instanceof KeyPair)
3517 return priv;
3518
3519 return new KeyPair(ec, {
3520 priv: priv,
3521 privEnc: enc
3522 });
3523};
3524
3525// TODO: should not validate for X25519
3526KeyPair.prototype.validate = function validate() {
3527 var pub = this.getPublic();
3528
3529 if (pub.isInfinity())
3530 return { result: false, reason: 'Invalid public key' };
3531 if (!pub.validate())
3532 return { result: false, reason: 'Public key is not a point' };
3533 if (!pub.mul(this.ec.curve.n).isInfinity())
3534 return { result: false, reason: 'Public key * N != O' };
3535
3536 return { result: true, reason: null };
3537};
3538
3539KeyPair.prototype.getPublic = function getPublic(enc, compact) {
3540 if (!this.pub)
3541 this.pub = this.ec.g.mul(this.priv);
3542
3543 if (!enc)
3544 return this.pub;
3545
3546 return this.pub.encode(enc, compact);
3547};
3548
3549KeyPair.prototype.getPrivate = function getPrivate(enc) {
3550 if (enc === 'hex')
3551 return this.priv.toString(16, 2);
3552 else
3553 return this.priv;
3554};
3555
3556KeyPair.prototype._importPrivate = function _importPrivate(key, enc) {
3557 this.priv = new bn(key, enc || 16);
3558
3559 // For Curve25519/Curve448 we have a specific procedure.
3560 // TODO Curve448
3561 if (this.ec.curve.type === 'mont') {
3562 var one = this.ec.curve.one;
3563 var mask = one.ushln(255 - 3).sub(one).ushln(3);
3564 this.priv = this.priv.or(one.ushln(255 - 1));
3565 this.priv = this.priv.and(mask);
3566 } else
3567 // Ensure that the priv won't be bigger than n, otherwise we may fail
3568 // in fixed multiplication method
3569 this.priv = this.priv.umod(this.ec.curve.n);
3570};
3571
3572KeyPair.prototype._importPublic = function _importPublic(key, enc) {
3573 if (key.x || key.y) {
3574 // Montgomery points only have an `x` coordinate.
3575 // Weierstrass/Edwards points on the other hand have both `x` and
3576 // `y` coordinates.
3577 if (this.ec.curve.type === 'mont') {
3578 assert$3(key.x, 'Need x coordinate');
3579 } else if (this.ec.curve.type === 'short' ||
3580 this.ec.curve.type === 'edwards') {
3581 assert$3(key.x && key.y, 'Need both x and y coordinate');
3582 }
3583 this.pub = this.ec.curve.point(key.x, key.y);
3584 return;
3585 }
3586 this.pub = this.ec.curve.decodePoint(key, enc);
3587};
3588
3589// ECDH
3590KeyPair.prototype.derive = function derive(pub) {
3591 return pub.mul(this.priv).getX();
3592};
3593
3594// ECDSA
3595KeyPair.prototype.sign = function sign(msg, enc, options) {
3596 return this.ec.sign(msg, this, enc, options);
3597};
3598
3599KeyPair.prototype.verify = function verify(msg, signature) {
3600 return this.ec.verify(msg, signature, this);
3601};
3602
3603KeyPair.prototype.inspect = function inspect() {
3604 return '<Key priv: ' + (this.priv && this.priv.toString(16, 2)) +
3605 ' pub: ' + (this.pub && this.pub.inspect()) + ' >';
3606};
3607
3608var assert$4 = utils_1$1.assert;
3609
3610function Signature(options, enc) {
3611 if (options instanceof Signature)
3612 return options;
3613
3614 if (this._importDER(options, enc))
3615 return;
3616
3617 assert$4(options.r && options.s, 'Signature without r or s');
3618 this.r = new bn(options.r, 16);
3619 this.s = new bn(options.s, 16);
3620 if (options.recoveryParam === undefined)
3621 this.recoveryParam = null;
3622 else
3623 this.recoveryParam = options.recoveryParam;
3624}
3625var signature = Signature;
3626
3627function Position() {
3628 this.place = 0;
3629}
3630
3631function getLength(buf, p) {
3632 var initial = buf[p.place++];
3633 if (!(initial & 0x80)) {
3634 return initial;
3635 }
3636 var octetLen = initial & 0xf;
3637 var val = 0;
3638 for (var i = 0, off = p.place; i < octetLen; i++, off++) {
3639 val <<= 8;
3640 val |= buf[off];
3641 }
3642 p.place = off;
3643 return val;
3644}
3645
3646function rmPadding(buf) {
3647 var i = 0;
3648 var len = buf.length - 1;
3649 while (!buf[i] && !(buf[i + 1] & 0x80) && i < len) {
3650 i++;
3651 }
3652 if (i === 0) {
3653 return buf;
3654 }
3655 return buf.slice(i);
3656}
3657
3658Signature.prototype._importDER = function _importDER(data, enc) {
3659 data = utils_1$1.toArray(data, enc);
3660 var p = new Position();
3661 if (data[p.place++] !== 0x30) {
3662 return false;
3663 }
3664 var len = getLength(data, p);
3665 if ((len + p.place) !== data.length) {
3666 return false;
3667 }
3668 if (data[p.place++] !== 0x02) {
3669 return false;
3670 }
3671 var rlen = getLength(data, p);
3672 var r = data.slice(p.place, rlen + p.place);
3673 p.place += rlen;
3674 if (data[p.place++] !== 0x02) {
3675 return false;
3676 }
3677 var slen = getLength(data, p);
3678 if (data.length !== slen + p.place) {
3679 return false;
3680 }
3681 var s = data.slice(p.place, slen + p.place);
3682 if (r[0] === 0 && (r[1] & 0x80)) {
3683 r = r.slice(1);
3684 }
3685 if (s[0] === 0 && (s[1] & 0x80)) {
3686 s = s.slice(1);
3687 }
3688
3689 this.r = new bn(r);
3690 this.s = new bn(s);
3691 this.recoveryParam = null;
3692
3693 return true;
3694};
3695
3696function constructLength(arr, len) {
3697 if (len < 0x80) {
3698 arr.push(len);
3699 return;
3700 }
3701 var octets = 1 + (Math.log(len) / Math.LN2 >>> 3);
3702 arr.push(octets | 0x80);
3703 while (--octets) {
3704 arr.push((len >>> (octets << 3)) & 0xff);
3705 }
3706 arr.push(len);
3707}
3708
3709Signature.prototype.toDER = function toDER(enc) {
3710 var r = this.r.toArray();
3711 var s = this.s.toArray();
3712
3713 // Pad values
3714 if (r[0] & 0x80)
3715 r = [ 0 ].concat(r);
3716 // Pad values
3717 if (s[0] & 0x80)
3718 s = [ 0 ].concat(s);
3719
3720 r = rmPadding(r);
3721 s = rmPadding(s);
3722
3723 while (!s[0] && !(s[1] & 0x80)) {
3724 s = s.slice(1);
3725 }
3726 var arr = [ 0x02 ];
3727 constructLength(arr, r.length);
3728 arr = arr.concat(r);
3729 arr.push(0x02);
3730 constructLength(arr, s.length);
3731 var backHalf = arr.concat(s);
3732 var res = [ 0x30 ];
3733 constructLength(res, backHalf.length);
3734 res = res.concat(backHalf);
3735 return utils_1$1.encode(res, enc);
3736};
3737
3738var assert$5 = utils_1$1.assert;
3739
3740
3741
3742
3743function EC(options) {
3744 if (!(this instanceof EC))
3745 return new EC(options);
3746
3747 // Shortcut `elliptic.ec(curve-name)`
3748 if (typeof options === 'string') {
3749 assert$5(curves_1.hasOwnProperty(options), 'Unknown curve ' + options);
3750
3751 options = curves_1[options];
3752 }
3753
3754 // Shortcut for `elliptic.ec(elliptic.curves.curveName)`
3755 if (options instanceof curves_1.PresetCurve)
3756 options = { curve: options };
3757
3758 this.curve = options.curve.curve;
3759 this.n = this.curve.n;
3760 this.nh = this.n.ushrn(1);
3761 this.g = this.curve.g;
3762
3763 // Point on curve
3764 this.g = options.curve.g;
3765 this.g.precompute(options.curve.n.bitLength() + 1);
3766
3767 // Hash function for DRBG
3768 this.hash = options.hash || options.curve.hash;
3769}
3770var ec = EC;
3771
3772EC.prototype.keyPair = function keyPair(options) {
3773 return new key(this, options);
3774};
3775
3776EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) {
3777 return key.fromPrivate(this, priv, enc);
3778};
3779
3780EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) {
3781 return key.fromPublic(this, pub, enc);
3782};
3783
3784EC.prototype.genKeyPair = function genKeyPair(options) {
3785 if (!options)
3786 options = {};
3787
3788 // Instantiate Hmac_DRBG
3789 var drbg =