Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

paillier-bigint

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paillier-bigint - npm Package Compare versions

Comparing version 1.2.0 to 2.0.0

16

dist/paillier-bigint-latest.browser.js

@@ -124,3 +124,3 @@ var paillierBigint = (function (exports) {

* @param {number|bigint} w An integer to be tested for primality
* @param {number} iterations The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
* @param {number} [iterations = 16] The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
*

@@ -785,3 +785,3 @@ * @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -826,3 +826,3 @@ };

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -902,11 +902,11 @@ };

* @param {bigint | stringBase10 | number} mu
* @param {bigint | stringBase10 | number} p - a big prime
* @param {bigint | stringBase10 | number} q - a big prime
* @param {PaillierPublicKey} publicKey
* @param {bigint | stringBase10 | number} [p = null] - a big prime
* @param {bigint | stringBase10 | number} [q = null] - a big prime
*/
constructor(lambda, mu, p, q, publicKey) {
constructor(lambda, mu, publicKey, p = null, q = null) {
this.lambda = BigInt(lambda);
this.mu = BigInt(mu);
this._p = BigInt(p);
this._q = BigInt(q);
this._p = (p) ? BigInt(p) : null;
this._q = (q) ? BigInt(q) : null;
this.publicKey = publicKey;

@@ -913,0 +913,0 @@ }

@@ -1,1 +0,1 @@

var paillierBigint=function(a){'use strict';var m=Math.floor;function c(b){return b=BigInt(b),b>=z?b:-b}function d(b){if(b=BigInt(b),b===A)return 1;let c=1;do c++;while((b>>=A)>A);return c}function e(c,d){if(c=BigInt(c),d=BigInt(d),c<=z|d<=z)return NaN;let e=z,f=A,g=A,h=z;for(;c!==z;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function f(d,e){if(d=c(d),e=c(e),d===z)return e;if(e===z)return d;let f=z;for(;!((d|e)&A);)d>>=A,e>>=A,f++;for(;!(d&A);)d>>=A;do{for(;!(e&A);)e>>=A;if(d>e){let a=d;d=e,e=a}e-=d}while(e);return d<<f}async function g(a,b=16){return"number"==typeof a&&(a=BigInt(a)),new Promise((c,d)=>{const e=new Worker(u());e.onmessage=a=>{e.terminate(),c(a.data.isPrime)},e.onmessageerror=a=>{d(a)},e.postMessage({rnd:a,iterations:b,id:0})})}function h(d,e){return d=BigInt(d),e=BigInt(e),d===z&&e===z?z:c(d*e)/f(d,e)}function i(b,a){if(b==z|a<=z)return NaN;let c=e(s(b,a),a);return c.b===A?s(c.x,a):NaN}function j(a,d,f){if(f=BigInt(f),f===z)return NaN;if(f===A)return z;if(a=s(a,f),d=BigInt(d),d<z)return i(j(a,c(d),f),f);let g=A;for(;0<d;)d%B===A&&(g=g*a%f),d/=B,a=a**B%f;return g}function k(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);return new Promise(c=>{let d=[];const e=(e,f)=>{if(e.isPrime){for(let a=0;a<d.length;a++)d[a].terminate();for(;d.length;)d.pop();c(e.value)}else{let c=p(a,!0),d=t(c);try{f.postMessage({rnd:d,iterations:b,id:e.id})}catch(a){}}};{let a=u();for(let b,c=0;c<self.navigator.hardwareConcurrency;c++)b=new Worker(a),b.onmessage=a=>e(a.data,b),d.push(b)}for(let e=0;e<d.length;e++){let c=p(a,!0),f=t(c);d[e].postMessage({rnd:f,iterations:b,id:e})}})}function l(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);let c=z;do c=t(q(a/8,!0));while(!w(c,b));return c}function o(a,b=A){if(a<=b)throw new Error("max must be > min");const c=a-b;let e,f=d(c);do{let a=p(f);e=t(a)}while(e>c);return e+b}function p(a,b=!1){var c=Math.ceil;if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);const d=c(a/8);let e=q(d,!1);if(e[0]&=2**(a%8)-1,b){let b=a%8?2**(a%8-1):128;e[0]|=b}return e}function q(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),c}function s(b,c){return(c=BigInt(c),0>=c)?NaN:(b=BigInt(b)%c,0>b?b+c:b)}function t(a){let b=z;for(let c of a.values()){let a=BigInt(c);b=(b<<BigInt(8))+a}return b}function u(){let a=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${e.toString()};const modInv = ${i.toString()};const modPow = ${j.toString()};const toZn = ${s.toString()};const randBits = ${p.toString()};const randBytesSync = ${q.toString()};const randBetween = ${o.toString()};const isProbablyPrime = ${w.toString()};${d.toString()}${t.toString()}`;return a+=`onmessage = ${async function(a){const b=await g(a.data.rnd,a.data.iterations);postMessage({isPrime:b,value:a.data.rnd,id:a.data.id})}.toString()};`,v(a)}function v(a){a=`(() => {${a}})()`;const b=new Blob([a],{type:"text/javascript"});return window.URL.createObjectURL(b)}function w(c,b=16){if(c===B)return!0;if((c&A)===z||c===A)return!1;const e=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let a=0;a<e.length&&BigInt(e[a])<=c;a++){const b=BigInt(e[a]);if(c===b)return!0;if(c%b===z)return!1}let f=z,g=c-A;for(;g%B===z;)g/=B,++f;let h=(c-A)/B**f;loop:do{let a=o(c-A,B),b=j(a,h,c);if(b===A||b===c-A)continue;for(let a=1;a<f;a++){if(b=j(b,B,c),b===c-A)continue loop;if(b===A)break}return!1}while(--b);return!0}function x(b,a){return(b-C)/a}function b(a,b=j(a,2)){const c=o(a),d=o(a);return(c*a+C)*j(d,a,b)%b}const z=BigInt(0),A=BigInt(1),B=BigInt(2),C=BigInt(1),D=class{constructor(a,b){this.n=BigInt(a),this._n2=this.n**BigInt(2),this.g=BigInt(b)}get bitLength(){return d(this.n)}encrypt(a){let b;return b=o(this.n),j(this.g,a,this._n2)*j(b,this.n,this._n2)%this._n2}addition(...a){return a.reduce((a,b)=>a*BigInt(b)%this._n2,C)}multiply(a,b){return"string"==typeof b&&(b=BigInt(b)),j(BigInt(a),b,this._n2)}},E=class{constructor(a,b,c,d,e){this.lambda=BigInt(a),this.mu=BigInt(b),this._p=BigInt(c),this._q=BigInt(d),this.publicKey=e}get bitLength(){return d(this.publicKey.n)}get n(){return this.publicKey.n}decrypt(a){return x(j(BigInt(a),this.lambda,this.publicKey._n2),this.publicKey.n)*this.mu%this.publicKey.n}};return a.PrivateKey=E,a.PublicKey=D,a.generateRandomKeys=async function(a=3072,c=!1){let e,f,l,o,r,s,t,u;do e=await k(m(a/2)+1),f=await k(m(a/2)),l=e*f;while(f===e||d(l)!=a);o=(e-C)*(f-C),r=l**BigInt(2),!0===c?(s=l+C,t=o,u=i(t,l)):(s=b(l,r),t=h(e-C,f-C),u=i(x(j(s,t,r),l),l));const v=new D(l,s),w=new E(t,u,e,f,v);return{publicKey:v,privateKey:w}},a.generateRandomKeysSync=function(a=4096,c=!1){let e,f,k,o,r,s,t,u;do e=l(m(a/2)+1),f=l(m(a/2)),k=e*f;while(f===e||d(k)!=a);o=(e-C)*(f-C),r=k**BigInt(2),!0===c?(s=k+C,t=o,u=i(t,k)):(s=b(k,r),t=h(e-C,f-C),u=i(x(j(s,t,r),k),k));const v=new D(k,s),w=new E(t,u,e,f,v);return{publicKey:v,privateKey:w}},a}({});
var paillierBigint=function(a){'use strict';var m=Math.floor;function c(b){return b=BigInt(b),b>=z?b:-b}function d(b){if(b=BigInt(b),b===A)return 1;let c=1;do c++;while((b>>=A)>A);return c}function e(c,d){if(c=BigInt(c),d=BigInt(d),c<=z|d<=z)return NaN;let e=z,f=A,g=A,h=z;for(;c!==z;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function f(d,e){if(d=c(d),e=c(e),d===z)return e;if(e===z)return d;let f=z;for(;!((d|e)&A);)d>>=A,e>>=A,f++;for(;!(d&A);)d>>=A;do{for(;!(e&A);)e>>=A;if(d>e){let a=d;d=e,e=a}e-=d}while(e);return d<<f}async function g(a,b=16){return"number"==typeof a&&(a=BigInt(a)),new Promise((c,d)=>{const e=new Worker(u());e.onmessage=a=>{e.terminate(),c(a.data.isPrime)},e.onmessageerror=a=>{d(a)},e.postMessage({rnd:a,iterations:b,id:0})})}function h(d,e){return d=BigInt(d),e=BigInt(e),d===z&&e===z?z:c(d*e)/f(d,e)}function i(b,a){if(b==z|a<=z)return NaN;let c=e(s(b,a),a);return c.b===A?s(c.x,a):NaN}function j(a,d,f){if(f=BigInt(f),f===z)return NaN;if(f===A)return z;if(a=s(a,f),d=BigInt(d),d<z)return i(j(a,c(d),f),f);let g=A;for(;0<d;)d%B===A&&(g=g*a%f),d/=B,a=a**B%f;return g}function k(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);return new Promise(c=>{let d=[];const e=(e,f)=>{if(e.isPrime){for(let a=0;a<d.length;a++)d[a].terminate();for(;d.length;)d.pop();c(e.value)}else{let c=p(a,!0),d=t(c);try{f.postMessage({rnd:d,iterations:b,id:e.id})}catch(a){}}};{let a=u();for(let b,c=0;c<self.navigator.hardwareConcurrency;c++)b=new Worker(a),b.onmessage=a=>e(a.data,b),d.push(b)}for(let e=0;e<d.length;e++){let c=p(a,!0),f=t(c);d[e].postMessage({rnd:f,iterations:b,id:e})}})}function l(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);let c=z;do c=t(q(a/8,!0));while(!w(c,b));return c}function o(a,b=A){if(a<=b)throw new Error("max must be > min");const c=a-b;let e,f=d(c);do{let a=p(f);e=t(a)}while(e>c);return e+b}function p(a,b=!1){var c=Math.ceil;if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);const d=c(a/8);let e=q(d,!1);if(e[0]&=2**(a%8)-1,b){let b=a%8?2**(a%8-1):128;e[0]|=b}return e}function q(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),c}function s(b,c){return(c=BigInt(c),0>=c)?NaN:(b=BigInt(b)%c,0>b?b+c:b)}function t(a){let b=z;for(let c of a.values()){let a=BigInt(c);b=(b<<BigInt(8))+a}return b}function u(){let a=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${e.toString()};const modInv = ${i.toString()};const modPow = ${j.toString()};const toZn = ${s.toString()};const randBits = ${p.toString()};const randBytesSync = ${q.toString()};const randBetween = ${o.toString()};const isProbablyPrime = ${w.toString()};${d.toString()}${t.toString()}`;return a+=`onmessage = ${async function(a){const b=await g(a.data.rnd,a.data.iterations);postMessage({isPrime:b,value:a.data.rnd,id:a.data.id})}.toString()};`,v(a)}function v(a){a=`(() => {${a}})()`;const b=new Blob([a],{type:"text/javascript"});return window.URL.createObjectURL(b)}function w(c,b=16){if(c===B)return!0;if((c&A)===z||c===A)return!1;const e=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let a=0;a<e.length&&BigInt(e[a])<=c;a++){const b=BigInt(e[a]);if(c===b)return!0;if(c%b===z)return!1}let f=z,g=c-A;for(;g%B===z;)g/=B,++f;let h=(c-A)/B**f;loop:do{let a=o(c-A,B),b=j(a,h,c);if(b===A||b===c-A)continue;for(let a=1;a<f;a++){if(b=j(b,B,c),b===c-A)continue loop;if(b===A)break}return!1}while(--b);return!0}function x(b,a){return(b-C)/a}function b(a,b=j(a,2)){const c=o(a),d=o(a);return(c*a+C)*j(d,a,b)%b}const z=BigInt(0),A=BigInt(1),B=BigInt(2),C=BigInt(1),D=class{constructor(a,b){this.n=BigInt(a),this._n2=this.n**BigInt(2),this.g=BigInt(b)}get bitLength(){return d(this.n)}encrypt(a){let b;return b=o(this.n),j(this.g,a,this._n2)*j(b,this.n,this._n2)%this._n2}addition(...a){return a.reduce((a,b)=>a*BigInt(b)%this._n2,C)}multiply(a,b){return"string"==typeof b&&(b=BigInt(b)),j(BigInt(a),b,this._n2)}},E=class{constructor(a,b,c,d=null,e=null){this.lambda=BigInt(a),this.mu=BigInt(b),this._p=d?BigInt(d):null,this._q=e?BigInt(e):null,this.publicKey=c}get bitLength(){return d(this.publicKey.n)}get n(){return this.publicKey.n}decrypt(a){return x(j(BigInt(a),this.lambda,this.publicKey._n2),this.publicKey.n)*this.mu%this.publicKey.n}};return a.PrivateKey=E,a.PublicKey=D,a.generateRandomKeys=async function(a=3072,c=!1){let e,f,l,o,r,s,t,u;do e=await k(m(a/2)+1),f=await k(m(a/2)),l=e*f;while(f===e||d(l)!=a);o=(e-C)*(f-C),r=l**BigInt(2),!0===c?(s=l+C,t=o,u=i(t,l)):(s=b(l,r),t=h(e-C,f-C),u=i(x(j(s,t,r),l),l));const v=new D(l,s),w=new E(t,u,v,e,f);return{publicKey:v,privateKey:w}},a.generateRandomKeysSync=function(a=4096,c=!1){let e,f,k,o,r,s,t,u;do e=l(m(a/2)+1),f=l(m(a/2)),k=e*f;while(f===e||d(k)!=a);o=(e-C)*(f-C),r=k**BigInt(2),!0===c?(s=k+C,t=o,u=i(t,k)):(s=b(k,r),t=h(e-C,f-C),u=i(x(j(s,t,r),k),k));const v=new D(k,s),w=new E(t,u,v,e,f);return{publicKey:v,privateKey:w}},a}({});

@@ -121,3 +121,3 @@ const _ZERO = BigInt(0);

* @param {number|bigint} w An integer to be tested for primality
* @param {number} iterations The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
* @param {number} [iterations = 16] The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
*

@@ -782,3 +782,3 @@ * @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -823,3 +823,3 @@ };

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -899,11 +899,11 @@ };

* @param {bigint | stringBase10 | number} mu
* @param {bigint | stringBase10 | number} p - a big prime
* @param {bigint | stringBase10 | number} q - a big prime
* @param {PaillierPublicKey} publicKey
* @param {bigint | stringBase10 | number} [p = null] - a big prime
* @param {bigint | stringBase10 | number} [q = null] - a big prime
*/
constructor(lambda, mu, p, q, publicKey) {
constructor(lambda, mu, publicKey, p = null, q = null) {
this.lambda = BigInt(lambda);
this.mu = BigInt(mu);
this._p = BigInt(p);
this._q = BigInt(q);
this._p = (p) ? BigInt(p) : null;
this._q = (q) ? BigInt(q) : null;
this.publicKey = publicKey;

@@ -910,0 +910,0 @@ }

@@ -1,1 +0,1 @@

const _ZERO=BigInt(0),_ONE=BigInt(1),_TWO=BigInt(2);function abs(b){return b=BigInt(b),b>=_ZERO?b:-b}function bitLength(b){if(b=BigInt(b),b===_ONE)return 1;let c=1;do c++;while((b>>=_ONE)>_ONE);return c}function eGcd(c,d){if(c=BigInt(c),d=BigInt(d),c<=_ZERO|d<=_ZERO)return NaN;let e=_ZERO,f=_ONE,g=_ONE,h=_ZERO;for(;c!==_ZERO;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function gcd(c,d){if(c=abs(c),d=abs(d),c===_ZERO)return d;if(d===_ZERO)return c;let e=_ZERO;for(;!((c|d)&_ONE);)c>>=_ONE,d>>=_ONE,e++;for(;!(c&_ONE);)c>>=_ONE;do{for(;!(d&_ONE);)d>>=_ONE;if(c>d){let a=c;c=d,d=a}d-=c}while(d);return c<<e}async function isProbablyPrime(a,b=16){return"number"==typeof a&&(a=BigInt(a)),new Promise((c,d)=>{const e=new Worker(_isProbablyPrimeWorkerUrl());e.onmessage=a=>{e.terminate(),c(a.data.isPrime)},e.onmessageerror=a=>{d(a)},e.postMessage({rnd:a,iterations:b,id:0})})}function lcm(c,d){return c=BigInt(c),d=BigInt(d),c===_ZERO&&d===_ZERO?_ZERO:abs(c*d)/gcd(c,d)}function modInv(b,a){if(b==_ZERO|a<=_ZERO)return NaN;let c=eGcd(toZn(b,a),a);return c.b===_ONE?toZn(c.x,a):NaN}function modPow(a,c,d){if(d=BigInt(d),d===_ZERO)return NaN;if(d===_ONE)return _ZERO;if(a=toZn(a,d),c=BigInt(c),c<_ZERO)return modInv(modPow(a,abs(c),d),d);let f=_ONE;for(;0<c;)c%_TWO===_ONE&&(f=f*a%d),c/=_TWO,a=a**_TWO%d;return f}function prime(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);return new Promise(c=>{let d=[];const e=(e,f)=>{if(e.isPrime){for(let a=0;a<d.length;a++)d[a].terminate();for(;d.length;)d.pop();c(e.value)}else{let c=randBits(a,!0),d=fromBuffer(c);try{f.postMessage({rnd:d,iterations:b,id:e.id})}catch(a){}}};{let a=_isProbablyPrimeWorkerUrl();for(let b,c=0;c<self.navigator.hardwareConcurrency;c++)b=new Worker(a),b.onmessage=a=>e(a.data,b),d.push(b)}for(let e=0;e<d.length;e++){let c=randBits(a,!0),f=fromBuffer(c);d[e].postMessage({rnd:f,iterations:b,id:e})}})}function primeSync(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);let c=_ZERO;do c=fromBuffer(randBytesSync(a/8,!0));while(!_isProbablyPrime(c,b));return c}function randBetween(a,b=_ONE){if(a<=b)throw new Error("max must be > min");const c=a-b;let d,e=bitLength(c);do{let a=randBits(e);d=fromBuffer(a)}while(d>c);return d+b}function randBits(a,b=!1){var c=Math.ceil;if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);const d=c(a/8);let e=randBytesSync(d,!1);if(e[0]&=2**(a%8)-1,b){let b=a%8?2**(a%8-1):128;e[0]|=b}return e}function randBytesSync(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),c}function toZn(b,c){return(c=BigInt(c),0>=c)?NaN:(b=BigInt(b)%c,0>b?b+c:b)}function fromBuffer(a){let b=_ZERO;for(let c of a.values()){let a=BigInt(c);b=(b<<BigInt(8))+a}return b}function _isProbablyPrimeWorkerUrl(){let a=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${eGcd.toString()};const modInv = ${modInv.toString()};const modPow = ${modPow.toString()};const toZn = ${toZn.toString()};const randBits = ${randBits.toString()};const randBytesSync = ${randBytesSync.toString()};const randBetween = ${randBetween.toString()};const isProbablyPrime = ${_isProbablyPrime.toString()};${bitLength.toString()}${fromBuffer.toString()}`;return a+=`onmessage = ${async function(a){const b=await isProbablyPrime(a.data.rnd,a.data.iterations);postMessage({isPrime:b,value:a.data.rnd,id:a.data.id})}.toString()};`,_workerUrl(a)}function _workerUrl(a){a=`(() => {${a}})()`;const b=new Blob([a],{type:"text/javascript"});return window.URL.createObjectURL(b)}function _isProbablyPrime(c,b=16){if(c===_TWO)return!0;if((c&_ONE)===_ZERO||c===_ONE)return!1;const e=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let a=0;a<e.length&&BigInt(e[a])<=c;a++){const b=BigInt(e[a]);if(c===b)return!0;if(c%b===_ZERO)return!1}let f=_ZERO,g=c-_ONE;for(;g%_TWO===_ZERO;)g/=_TWO,++f;let h=(c-_ONE)/_TWO**f;loop:do{let a=randBetween(c-_ONE,_TWO),b=modPow(a,h,c);if(b===_ONE||b===c-_ONE)continue;for(let a=1;a<f;a++){if(b=modPow(b,_TWO,c),b===c-_ONE)continue loop;if(b===_ONE)break}return!1}while(--b);return!0}const _ONE$1=BigInt(1),generateRandomKeys=async function(a=3072,b=!1){var c=Math.floor;let d,e,f,h,i,j,k,l;do d=await prime(c(a/2)+1),e=await prime(c(a/2)),f=d*e;while(e===d||bitLength(f)!=a);h=(d-_ONE$1)*(e-_ONE$1),i=f**BigInt(2),!0===b?(j=f+_ONE$1,k=h,l=modInv(k,f)):(j=getGenerator(f,i),k=lcm(d-_ONE$1,e-_ONE$1),l=modInv(L(modPow(j,k,i),f),f));const m=new PublicKey(f,j),o=new PrivateKey(k,l,d,e,m);return{publicKey:m,privateKey:o}},generateRandomKeysSync=function(a=4096,b=!1){var c=Math.floor;let d,e,f,h,i,j,k,l;do d=primeSync(c(a/2)+1),e=primeSync(c(a/2)),f=d*e;while(e===d||bitLength(f)!=a);h=(d-_ONE$1)*(e-_ONE$1),i=f**BigInt(2),!0===b?(j=f+_ONE$1,k=h,l=modInv(k,f)):(j=getGenerator(f,i),k=lcm(d-_ONE$1,e-_ONE$1),l=modInv(L(modPow(j,k,i),f),f));const m=new PublicKey(f,j),o=new PrivateKey(k,l,d,e,m);return{publicKey:m,privateKey:o}},PublicKey=class{constructor(a,b){this.n=BigInt(a),this._n2=this.n**BigInt(2),this.g=BigInt(b)}get bitLength(){return bitLength(this.n)}encrypt(a){let b;return b=randBetween(this.n),modPow(this.g,a,this._n2)*modPow(b,this.n,this._n2)%this._n2}addition(...a){return a.reduce((a,b)=>a*BigInt(b)%this._n2,_ONE$1)}multiply(a,b){return"string"==typeof b&&(b=BigInt(b)),modPow(BigInt(a),b,this._n2)}},PrivateKey=class{constructor(a,b,c,d,e){this.lambda=BigInt(a),this.mu=BigInt(b),this._p=BigInt(c),this._q=BigInt(d),this.publicKey=e}get bitLength(){return bitLength(this.publicKey.n)}get n(){return this.publicKey.n}decrypt(a){return L(modPow(BigInt(a),this.lambda,this.publicKey._n2),this.publicKey.n)*this.mu%this.publicKey.n}};function L(b,a){return(b-_ONE$1)/a}function getGenerator(a,b=modPow(a,2)){const c=randBetween(a),d=randBetween(a);return(c*a+_ONE$1)*modPow(d,a,b)%b}export{PrivateKey,PublicKey,generateRandomKeys,generateRandomKeysSync};
const _ZERO=BigInt(0),_ONE=BigInt(1),_TWO=BigInt(2);function abs(b){return b=BigInt(b),b>=_ZERO?b:-b}function bitLength(b){if(b=BigInt(b),b===_ONE)return 1;let c=1;do c++;while((b>>=_ONE)>_ONE);return c}function eGcd(c,d){if(c=BigInt(c),d=BigInt(d),c<=_ZERO|d<=_ZERO)return NaN;let e=_ZERO,f=_ONE,g=_ONE,h=_ZERO;for(;c!==_ZERO;){let a=d/c,b=d%c,i=e-g*a,j=f-h*a;d=c,c=b,e=g,f=h,g=i,h=j}return{b:d,x:e,y:f}}function gcd(c,d){if(c=abs(c),d=abs(d),c===_ZERO)return d;if(d===_ZERO)return c;let e=_ZERO;for(;!((c|d)&_ONE);)c>>=_ONE,d>>=_ONE,e++;for(;!(c&_ONE);)c>>=_ONE;do{for(;!(d&_ONE);)d>>=_ONE;if(c>d){let a=c;c=d,d=a}d-=c}while(d);return c<<e}async function isProbablyPrime(a,b=16){return"number"==typeof a&&(a=BigInt(a)),new Promise((c,d)=>{const e=new Worker(_isProbablyPrimeWorkerUrl());e.onmessage=a=>{e.terminate(),c(a.data.isPrime)},e.onmessageerror=a=>{d(a)},e.postMessage({rnd:a,iterations:b,id:0})})}function lcm(c,d){return c=BigInt(c),d=BigInt(d),c===_ZERO&&d===_ZERO?_ZERO:abs(c*d)/gcd(c,d)}function modInv(b,a){if(b==_ZERO|a<=_ZERO)return NaN;let c=eGcd(toZn(b,a),a);return c.b===_ONE?toZn(c.x,a):NaN}function modPow(a,c,d){if(d=BigInt(d),d===_ZERO)return NaN;if(d===_ONE)return _ZERO;if(a=toZn(a,d),c=BigInt(c),c<_ZERO)return modInv(modPow(a,abs(c),d),d);let f=_ONE;for(;0<c;)c%_TWO===_ONE&&(f=f*a%d),c/=_TWO,a=a**_TWO%d;return f}function prime(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);return new Promise(c=>{let d=[];const e=(e,f)=>{if(e.isPrime){for(let a=0;a<d.length;a++)d[a].terminate();for(;d.length;)d.pop();c(e.value)}else{let c=randBits(a,!0),d=fromBuffer(c);try{f.postMessage({rnd:d,iterations:b,id:e.id})}catch(a){}}};{let a=_isProbablyPrimeWorkerUrl();for(let b,c=0;c<self.navigator.hardwareConcurrency;c++)b=new Worker(a),b.onmessage=a=>e(a.data,b),d.push(b)}for(let e=0;e<d.length;e++){let c=randBits(a,!0),f=fromBuffer(c);d[e].postMessage({rnd:f,iterations:b,id:e})}})}function primeSync(a,b=16){if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);let c=_ZERO;do c=fromBuffer(randBytesSync(a/8,!0));while(!_isProbablyPrime(c,b));return c}function randBetween(a,b=_ONE){if(a<=b)throw new Error("max must be > min");const c=a-b;let d,e=bitLength(c);do{let a=randBits(e);d=fromBuffer(a)}while(d>c);return d+b}function randBits(a,b=!1){var c=Math.ceil;if(1>a)throw new RangeError(`bitLength MUST be > 0 and it is ${a}`);const d=c(a/8);let e=randBytesSync(d,!1);if(e[0]&=2**(a%8)-1,b){let b=a%8?2**(a%8-1):128;e[0]|=b}return e}function randBytesSync(a,b=!1){if(1>a)throw new RangeError(`byteLength MUST be > 0 and it is ${a}`);let c;return c=new Uint8Array(a),self.crypto.getRandomValues(c),b&&(c[0]|=128),c}function toZn(b,c){return(c=BigInt(c),0>=c)?NaN:(b=BigInt(b)%c,0>b?b+c:b)}function fromBuffer(a){let b=_ZERO;for(let c of a.values()){let a=BigInt(c);b=(b<<BigInt(8))+a}return b}function _isProbablyPrimeWorkerUrl(){let a=`'use strict';const _ZERO = BigInt(0);const _ONE = BigInt(1);const _TWO = BigInt(2);const eGcd = ${eGcd.toString()};const modInv = ${modInv.toString()};const modPow = ${modPow.toString()};const toZn = ${toZn.toString()};const randBits = ${randBits.toString()};const randBytesSync = ${randBytesSync.toString()};const randBetween = ${randBetween.toString()};const isProbablyPrime = ${_isProbablyPrime.toString()};${bitLength.toString()}${fromBuffer.toString()}`;return a+=`onmessage = ${async function(a){const b=await isProbablyPrime(a.data.rnd,a.data.iterations);postMessage({isPrime:b,value:a.data.rnd,id:a.data.id})}.toString()};`,_workerUrl(a)}function _workerUrl(a){a=`(() => {${a}})()`;const b=new Blob([a],{type:"text/javascript"});return window.URL.createObjectURL(b)}function _isProbablyPrime(c,b=16){if(c===_TWO)return!0;if((c&_ONE)===_ZERO||c===_ONE)return!1;const e=[3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009,1013,1019,1021,1031,1033,1039,1049,1051,1061,1063,1069,1087,1091,1093,1097,1103,1109,1117,1123,1129,1151,1153,1163,1171,1181,1187,1193,1201,1213,1217,1223,1229,1231,1237,1249,1259,1277,1279,1283,1289,1291,1297,1301,1303,1307,1319,1321,1327,1361,1367,1373,1381,1399,1409,1423,1427,1429,1433,1439,1447,1451,1453,1459,1471,1481,1483,1487,1489,1493,1499,1511,1523,1531,1543,1549,1553,1559,1567,1571,1579,1583,1597];for(let a=0;a<e.length&&BigInt(e[a])<=c;a++){const b=BigInt(e[a]);if(c===b)return!0;if(c%b===_ZERO)return!1}let f=_ZERO,g=c-_ONE;for(;g%_TWO===_ZERO;)g/=_TWO,++f;let h=(c-_ONE)/_TWO**f;loop:do{let a=randBetween(c-_ONE,_TWO),b=modPow(a,h,c);if(b===_ONE||b===c-_ONE)continue;for(let a=1;a<f;a++){if(b=modPow(b,_TWO,c),b===c-_ONE)continue loop;if(b===_ONE)break}return!1}while(--b);return!0}const _ONE$1=BigInt(1),generateRandomKeys=async function(a=3072,b=!1){var c=Math.floor;let d,e,f,h,i,j,k,l;do d=await prime(c(a/2)+1),e=await prime(c(a/2)),f=d*e;while(e===d||bitLength(f)!=a);h=(d-_ONE$1)*(e-_ONE$1),i=f**BigInt(2),!0===b?(j=f+_ONE$1,k=h,l=modInv(k,f)):(j=getGenerator(f,i),k=lcm(d-_ONE$1,e-_ONE$1),l=modInv(L(modPow(j,k,i),f),f));const m=new PublicKey(f,j),o=new PrivateKey(k,l,m,d,e);return{publicKey:m,privateKey:o}},generateRandomKeysSync=function(a=4096,b=!1){var c=Math.floor;let d,e,f,h,i,j,k,l;do d=primeSync(c(a/2)+1),e=primeSync(c(a/2)),f=d*e;while(e===d||bitLength(f)!=a);h=(d-_ONE$1)*(e-_ONE$1),i=f**BigInt(2),!0===b?(j=f+_ONE$1,k=h,l=modInv(k,f)):(j=getGenerator(f,i),k=lcm(d-_ONE$1,e-_ONE$1),l=modInv(L(modPow(j,k,i),f),f));const m=new PublicKey(f,j),o=new PrivateKey(k,l,m,d,e);return{publicKey:m,privateKey:o}},PublicKey=class{constructor(a,b){this.n=BigInt(a),this._n2=this.n**BigInt(2),this.g=BigInt(b)}get bitLength(){return bitLength(this.n)}encrypt(a){let b;return b=randBetween(this.n),modPow(this.g,a,this._n2)*modPow(b,this.n,this._n2)%this._n2}addition(...a){return a.reduce((a,b)=>a*BigInt(b)%this._n2,_ONE$1)}multiply(a,b){return"string"==typeof b&&(b=BigInt(b)),modPow(BigInt(a),b,this._n2)}},PrivateKey=class{constructor(a,b,c,d=null,e=null){this.lambda=BigInt(a),this.mu=BigInt(b),this._p=d?BigInt(d):null,this._q=e?BigInt(e):null,this.publicKey=c}get bitLength(){return bitLength(this.publicKey.n)}get n(){return this.publicKey.n}decrypt(a){return L(modPow(BigInt(a),this.lambda,this.publicKey._n2),this.publicKey.n)*this.mu%this.publicKey.n}};function L(b,a){return(b-_ONE$1)/a}function getGenerator(a,b=modPow(a,2)){const c=randBetween(a),d=randBetween(a);return(c*a+_ONE$1)*modPow(d,a,b)%b}export{PrivateKey,PublicKey,generateRandomKeys,generateRandomKeysSync};

@@ -50,3 +50,3 @@ 'use strict';

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -91,3 +91,3 @@ };

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -167,11 +167,11 @@ };

* @param {bigint | stringBase10 | number} mu
* @param {bigint | stringBase10 | number} p - a big prime
* @param {bigint | stringBase10 | number} q - a big prime
* @param {PaillierPublicKey} publicKey
* @param {bigint | stringBase10 | number} [p = null] - a big prime
* @param {bigint | stringBase10 | number} [q = null] - a big prime
*/
constructor(lambda, mu, p, q, publicKey) {
constructor(lambda, mu, publicKey, p = null, q = null) {
this.lambda = BigInt(lambda);
this.mu = BigInt(mu);
this._p = BigInt(p);
this._q = BigInt(q);
this._p = (p) ? BigInt(p) : null;
this._q = (q) ? BigInt(q) : null;
this.publicKey = publicKey;

@@ -178,0 +178,0 @@ }

{
"name": "paillier-bigint",
"version": "1.2.0",
"version": "2.0.0",
"description": "An implementation of the Paillier cryptosystem using native JS (stage 3) implementation of BigInt",

@@ -36,7 +36,7 @@ "keywords": [

"chai": "^4.2.0",
"eslint": "^6.0.0",
"eslint": "^6.8.0",
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^6.2.2",
"rollup": "^1.27.13",
"rollup-plugin-babel-minify": "^9.0.0",
"mocha": "^7",
"rollup": "^1.29.1",
"rollup-plugin-babel-minify": "^9.1.1",
"rollup-plugin-commonjs": "^10.1.0",

@@ -48,4 +48,4 @@ "rollup-plugin-multi-entry": "^2.1.0",

"dependencies": {
"bigint-crypto-utils": "^2.3.1"
"bigint-crypto-utils": "^2.4.2"
}
}
# paillier-bigint
An implementation of the Paillier cryptosystem relying on the native JS (stage 3) implementation of BigInt. It can be
used by any [Web Browser or webview supporting
BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility)
and with Node.js (>=10.4.0). In the latter case, for multi-threaded primality tests (during key generation), you should
use Node.js 11 or enable at runtime with `node --experimental-worker` with Node.js >=10.5.0.
An implementation of the Paillier cryptosystem relying on the native JS (stage 3) implementation of BigInt. It can be used by any [Web Browser or webview supporting BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#Browser_compatibility) and with Node.js (>=10.4.0). In the latter case, for multi-threaded primality tests, you should use Node.js v11 or newer or enable at runtime with `node --experimental-worker` with Node.js version >= 10.5.0 and < 11.
_The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in
cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms
provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js
Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html)._
_The operations supported on BigInts are not constant time. BigInt can be therefore **[unsuitable for use in cryptography](https://www.chosenplaintext.ca/articles/beginners-guide-constant-time-cryptography.html).** Many platforms provide native support for cryptography, such as [Web Cryptography API](https://w3c.github.io/webcrypto/) or [Node.js Crypto](https://nodejs.org/dist/latest/docs/api/crypto.html)._

@@ -99,3 +92,3 @@ The Paillier cryptosystem, named after and invented by Pascal Paillier in 1999, is a probabilistic asymmetric algorithm

const publicKey = new paillier.PublicKey(n, g);
const privateKey = new paillier.PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new paillier.PrivateKey(lambda, mu, publicKey);

@@ -134,3 +127,3 @@ // encrypt m

const publicKey = new paillier.PublicKey(n, g);
const privateKey = new paillier.PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new paillier.PrivateKey(lambda, mu, publicKey);

@@ -263,3 +256,3 @@ // encrypt m is just

* [PrivateKey](#PrivateKey)
* [new PrivateKey(lambda, mu, p, q, publicKey)](#new_PrivateKey_new)
* [new PrivateKey(lambda, mu, publicKey, [p], [q])](#new_PrivateKey_new)
* [.bitLength](#PrivateKey+bitLength) ⇒ <code>number</code>

@@ -271,13 +264,13 @@ * [.n](#PrivateKey+n) ⇒ <code>bigint</code>

### new PrivateKey(lambda, mu, p, q, publicKey)
### new PrivateKey(lambda, mu, publicKey, [p], [q])
Creates an instance of class PaillierPrivateKey
| Param | Type | Description |
| --- | --- | --- |
| lambda | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | |
| mu | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | |
| p | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | a big prime |
| q | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | a big prime |
| publicKey | <code>PaillierPublicKey</code> | |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| lambda | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | | |
| mu | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | | |
| publicKey | <code>PaillierPublicKey</code> | | |
| [p] | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | <code></code> | a big prime |
| [q] | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | <code></code> | a big prime |

@@ -414,3 +407,3 @@ <a name="PrivateKey+bitLength"></a>

* [PrivateKey](#PrivateKey)
* [new PrivateKey(lambda, mu, p, q, publicKey)](#new_PrivateKey_new)
* [new PrivateKey(lambda, mu, publicKey, [p], [q])](#new_PrivateKey_new)
* [.bitLength](#PrivateKey+bitLength) ⇒ <code>number</code>

@@ -422,13 +415,13 @@ * [.n](#PrivateKey+n) ⇒ <code>bigint</code>

### new PrivateKey(lambda, mu, p, q, publicKey)
### new PrivateKey(lambda, mu, publicKey, [p], [q])
Creates an instance of class PaillierPrivateKey
| Param | Type | Description |
| --- | --- | --- |
| lambda | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | |
| mu | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | |
| p | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | a big prime |
| q | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | a big prime |
| publicKey | <code>PaillierPublicKey</code> | |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| lambda | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | | |
| mu | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | | |
| publicKey | <code>PaillierPublicKey</code> | | |
| [p] | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | <code></code> | a big prime |
| [q] | <code>bigint</code> \| <code>stringBase10</code> \| <code>number</code> | <code></code> | a big prime |

@@ -435,0 +428,0 @@ <a name="PrivateKey+bitLength"></a>

@@ -47,3 +47,3 @@ 'use strict';

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -88,3 +88,3 @@ };

const publicKey = new PublicKey(n, g);
const privateKey = new PrivateKey(lambda, mu, p, q, publicKey);
const privateKey = new PrivateKey(lambda, mu, publicKey, p, q);
return { publicKey: publicKey, privateKey: privateKey };

@@ -164,11 +164,11 @@ };

* @param {bigint | stringBase10 | number} mu
* @param {bigint | stringBase10 | number} p - a big prime
* @param {bigint | stringBase10 | number} q - a big prime
* @param {PaillierPublicKey} publicKey
* @param {bigint | stringBase10 | number} [p = null] - a big prime
* @param {bigint | stringBase10 | number} [q = null] - a big prime
*/
constructor(lambda, mu, p, q, publicKey) {
constructor(lambda, mu, publicKey, p = null, q = null) {
this.lambda = BigInt(lambda);
this.mu = BigInt(mu);
this._p = BigInt(p);
this._q = BigInt(q);
this._p = (p) ? BigInt(p) : null;
this._q = (q) ? BigInt(q) : null;
this.publicKey = publicKey;

@@ -175,0 +175,0 @@ }

@@ -121,3 +121,3 @@ const _ZERO = BigInt(0);

* @param {number|bigint} w An integer to be tested for primality
* @param {number} iterations The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
* @param {number} [iterations = 16] The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3
*

@@ -124,0 +124,0 @@ * @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc