MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / constructor

Method constructor

modules/crypt/etc/rsa.js:42–63  ·  view source on GitHub ↗
(e, m, p, q, dp, dq, C2)

Source from the content-addressed store, hash-verified

40
41export default class RSA {
42 constructor(e, m, p, q, dp, dq, C2) {
43 if (BigInt.bitLength(e) > 17 && p && q) {
44 // use CRT
45 this.dp = dp ? dp : e % (p - 1);
46 this.dq = dq ? dq : e % (q - 1);
47 this.mp = new Mont({m: p, method: Mont.SW});
48 this.mq = new Mont({m: q, method: Mont.SW});
49 this.C2 = C2 ? C2 : this.mp.mulinv(q); // (C2 = q^-1 mod p) according to PKCS8
50 this.p = p;
51 this.q = q;
52 if (!m)
53 m = z.mul(p, q);
54 }
55 else {
56 if (!m && p && q)
57 m = z.mul(p, q);
58 this.mn = new Modular(m);
59 this.e = e;
60 }
61 let n = BigInt.bitLength(m);
62 this.orderSize = (n + 7) >>> 3;
63 };
64 process(c) {
65 if (this.mn)
66 return this.mn.exp(c, this.e);

Callers

nothing calls this directly

Calls 3

bitLengthMethod · 0.80
mulinvMethod · 0.80
mulMethod · 0.45

Tested by

no test coverage detected