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.1.0 to 1.2.0

21

dist/paillier-bigint-latest.browser.js

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

* @param {number} bitLength The required bit length for the generated prime
* @param {number} iterations The number of iterations for the Miller-Rabin Probabilistic Primality Test
* @param {boolean} sync NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript.
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*

@@ -291,3 +290,3 @@ * @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits.

* @param {number} bitLength The required bit length for the generated prime
* @param {number} iterations The number of iterations for the Miller-Rabin Probabilistic Primality Test
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*

@@ -309,3 +308,3 @@ * @returns {bigint} A bigint probable prime of bitLength bits.

* @param {bigint} max Returned value will be <= max
* @param {bigint} min Returned value will be >= min
* @param {bigint} [min = BigInt(1)] Returned value will be >= min
*

@@ -330,3 +329,3 @@ * @returns {bigint} A cryptographically secure random bigint between [min,max]

* @param {number} bitLength The desired number of random bits
* @param {boolean} forceLength If we want to force the output to have a specific bit length. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a specific bit length. It basically forces the msb to be 1
*

@@ -354,3 +353,3 @@ * @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits

* @param {number} byteLength The desired number of random bytes
* @param {boolean} forceLength If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*

@@ -758,8 +757,8 @@ * @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 3072] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*
* @returns {Promise} - a promise that resolves to a {@link KeyPair} of public, private keys
*/
const generateRandomKeys = async function (bitLength$1 = 4096, simpleVariant = false) {
const generateRandomKeys = async function (bitLength$1 = 3072, simpleVariant = false) {
let p, q, n, phi, n2, g, lambda, mu;

@@ -799,4 +798,4 @@ // if p and q are bitLength/2 long -> 2**(bitLength - 2) <= n < 2**(bitLength)

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 4096] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*

@@ -803,0 +802,0 @@ * @returns {@link KeyPair} - a {@link KeyPair} of public, private keys

@@ -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=4096,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,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}({});

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

* @param {number} bitLength The required bit length for the generated prime
* @param {number} iterations The number of iterations for the Miller-Rabin Probabilistic Primality Test
* @param {boolean} sync NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript.
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*

@@ -288,3 +287,3 @@ * @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits.

* @param {number} bitLength The required bit length for the generated prime
* @param {number} iterations The number of iterations for the Miller-Rabin Probabilistic Primality Test
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*

@@ -306,3 +305,3 @@ * @returns {bigint} A bigint probable prime of bitLength bits.

* @param {bigint} max Returned value will be <= max
* @param {bigint} min Returned value will be >= min
* @param {bigint} [min = BigInt(1)] Returned value will be >= min
*

@@ -327,3 +326,3 @@ * @returns {bigint} A cryptographically secure random bigint between [min,max]

* @param {number} bitLength The desired number of random bits
* @param {boolean} forceLength If we want to force the output to have a specific bit length. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a specific bit length. It basically forces the msb to be 1
*

@@ -351,3 +350,3 @@ * @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits

* @param {number} byteLength The desired number of random bytes
* @param {boolean} forceLength If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*

@@ -755,8 +754,8 @@ * @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 3072] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*
* @returns {Promise} - a promise that resolves to a {@link KeyPair} of public, private keys
*/
const generateRandomKeys = async function (bitLength$1 = 4096, simpleVariant = false) {
const generateRandomKeys = async function (bitLength$1 = 3072, simpleVariant = false) {
let p, q, n, phi, n2, g, lambda, mu;

@@ -796,4 +795,4 @@ // if p and q are bitLength/2 long -> 2**(bitLength - 2) <= n < 2**(bitLength)

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 4096] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*

@@ -800,0 +799,0 @@ * @returns {@link KeyPair} - a {@link KeyPair} of public, private keys

@@ -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=4096,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,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};

@@ -18,8 +18,8 @@ 'use strict';

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 3072] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*
* @returns {Promise} - a promise that resolves to a {@link KeyPair} of public, private keys
*/
const generateRandomKeys = async function (bitLength = 4096, simpleVariant = false) {
const generateRandomKeys = async function (bitLength = 3072, simpleVariant = false) {
let p, q, n, phi, n2, g, lambda, mu;

@@ -59,4 +59,4 @@ // if p and q are bitLength/2 long -> 2**(bitLength - 2) <= n < 2**(bitLength)

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 4096] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*

@@ -63,0 +63,0 @@ * @returns {@link KeyPair} - a {@link KeyPair} of public, private keys

{
"name": "paillier-bigint",
"version": "1.1.0",
"version": "1.2.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": "^5.16.0",
"jsdoc-to-markdown": "^5.0.1",
"mocha": "^6.2.1",
"rollup": "^1.23.1",
"rollup-plugin-babel-minify": "^8.0.0",
"eslint": "^6.0.0",
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^6.2.2",
"rollup": "^1.27.13",
"rollup-plugin-babel-minify": "^9.0.0",
"rollup-plugin-commonjs": "^10.1.0",

@@ -43,0 +43,0 @@ "rollup-plugin-multi-entry": "^2.1.0",

@@ -314,6 +314,6 @@ # paillier-bigint

| Param | Type | Description |
| --- | --- | --- |
| bitLength | <code>number</code> | the bit length of the public modulo |
| simplevariant | <code>boolean</code> | use the simple variant to compute the generator (g=n+1) |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [bitLength] | <code>number</code> | <code>3072</code> | the bit length of the public modulo |
| [simplevariant] | <code>boolean</code> | <code>false</code> | use the simple variant to compute the generator (g=n+1) |

@@ -329,6 +329,6 @@ <a name="generateRandomKeysSync"></a>

| Param | Type | Description |
| --- | --- | --- |
| bitLength | <code>number</code> | the bit length of the public modulo |
| simplevariant | <code>boolean</code> | use the simple variant to compute the generator (g=n+1) |
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [bitLength] | <code>number</code> | <code>4096</code> | the bit length of the public modulo |
| [simplevariant] | <code>boolean</code> | <code>false</code> | use the simple variant to compute the generator (g=n+1) |

@@ -335,0 +335,0 @@ <a name="PublicKey"></a>

@@ -15,8 +15,8 @@ 'use strict';

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 3072] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*
* @returns {Promise} - a promise that resolves to a {@link KeyPair} of public, private keys
*/
export const generateRandomKeys = async function (bitLength = 4096, simpleVariant = false) {
export const generateRandomKeys = async function (bitLength = 3072, simpleVariant = false) {
let p, q, n, phi, n2, g, lambda, mu;

@@ -56,4 +56,4 @@ // if p and q are bitLength/2 long -> 2**(bitLength - 2) <= n < 2**(bitLength)

*
* @param {number} bitLength - the bit length of the public modulo
* @param {boolean} simplevariant - use the simple variant to compute the generator (g=n+1)
* @param {number} [bitLength = 4096] - the bit length of the public modulo
* @param {boolean} [simplevariant = false] - use the simple variant to compute the generator (g=n+1)
*

@@ -60,0 +60,0 @@ * @returns {@link KeyPair} - a {@link KeyPair} of public, private keys

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

* @param {number} bitLength The required bit length for the generated prime
* @param {number} iterations The number of iterations for the Miller-Rabin Probabilistic Primality Test
* @param {boolean} sync NOT RECOMMENDED. Invoke the function synchronously. It won't use workers so it'll be slower and may freeze thw window in browser's javascript.
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*

@@ -316,3 +315,3 @@ * @returns {Promise} A promise that resolves to a bigint probable prime of bitLength bits.

* @param {number} bitLength The required bit length for the generated prime
* @param {number} iterations The number of iterations for the Miller-Rabin Probabilistic Primality Test
* @param {number} [iterations = 16] The number of iterations for the Miller-Rabin Probabilistic Primality Test
*

@@ -334,3 +333,3 @@ * @returns {bigint} A bigint probable prime of bitLength bits.

* @param {bigint} max Returned value will be <= max
* @param {bigint} min Returned value will be >= min
* @param {bigint} [min = BigInt(1)] Returned value will be >= min
*

@@ -355,3 +354,3 @@ * @returns {bigint} A cryptographically secure random bigint between [min,max]

* @param {number} bitLength The desired number of random bits
* @param {boolean} forceLength If we want to force the output to have a specific bit length. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a specific bit length. It basically forces the msb to be 1
*

@@ -379,3 +378,3 @@ * @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bits

* @param {number} byteLength The desired number of random bytes
* @param {boolean} forceLength If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*

@@ -405,3 +404,3 @@ * @returns {Promise} A promise that resolves to a Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes

* @param {number} byteLength The desired number of random bytes
* @param {boolean} forceLength If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
* @param {boolean} [forceLength = false] If we want to force the output to have a bit length of 8*byteLength. It basically forces the msb to be 1
*

@@ -408,0 +407,0 @@ * @returns {Buffer|Uint8Array} A Buffer/UInt8Array (Node.js/Browser) filled with cryptographically secure random bytes

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