diff --git a/README.hbs b/README.hbs index 190f751..5f96dd1 100644 --- a/README.hbs +++ b/README.hbs @@ -1,6 +1,6 @@ # bigint-crypto-utils -Utils for working with cryptography using native JS (stage 3) implementation of BigInt. It includes some extra functions to work with modular arithmetics along with secure random numbers and a fast strong probable prime generator/tester (parallelised multi-threaded Miller-Rabin primality test). 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 11 or enable at runtime with `node --experimental-worker` with Node.js >=10.5.0. +Utils for working with cryptography using native JS (stage 3) implementation of BigInt. It includes some extra functions to work with modular arithmetics along with secure random numbers and a fast strong probable prime generator/tester (parallelised multi-threaded Miller-Rabin primality test). 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)._ diff --git a/README.md b/README.md index 0554bd9..02f8577 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # bigint-crypto-utils -Utils for working with cryptography using native JS (stage 3) implementation of BigInt. It includes some extra functions to work with modular arithmetics along with secure random numbers and a fast strong probable prime generator/tester (parallelised multi-threaded Miller-Rabin primality test). 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 11 or enable at runtime with `node --experimental-worker` with Node.js >=10.5.0. +Utils for working with cryptography using native JS (stage 3) implementation of BigInt. It includes some extra functions to work with modular arithmetics along with secure random numbers and a fast strong probable prime generator/tester (parallelised multi-threaded Miller-Rabin primality test). 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)._ @@ -97,7 +97,7 @@ Take positive integers a, b as input, and return a triple (g, x, y), such that a
bigint
Greatest-common divisor of two integers based on the iterative binary algorithm.
Promise
Promise
The test first tries if any of the first 250 small primes are a factor of the input number and then passes several iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
Promise
+## isProbablyPrime(w, [iterations]) ⇒ Promise
The test first tries if any of the first 250 small primes are a factor of the input number and then passes several
iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
**Kind**: global function
**Returns**: Promise
- A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
-| Param | Type | Description |
-| --- | --- | --- |
-| w | number
\| bigint
| An integer to be tested for primality |
-| iterations | number
| The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3 |
+| Param | Type | Default | Description |
+| --- | --- | --- | --- |
+| w | number
\| bigint
| | An integer to be tested for primality |
+| [iterations] | number
| 16
| The number of iterations for the primality test. The value shall be consistent with Table C.1, C.2 or C.3 |
diff --git a/dist/bigint-crypto-utils-latest.browser.js b/dist/bigint-crypto-utils-latest.browser.js
index dede38f..1d1cadf 100644
--- a/dist/bigint-crypto-utils-latest.browser.js
+++ b/dist/bigint-crypto-utils-latest.browser.js
@@ -121,7 +121,7 @@ var bigintCryptoUtils = (function (exports) {
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
*
* @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
*
* @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
*/
diff --git a/dist/bigint-crypto-utils-latest.browser.mod.js b/dist/bigint-crypto-utils-latest.browser.mod.js
index 5e7502e..48ab08d 100644
--- a/dist/bigint-crypto-utils-latest.browser.mod.js
+++ b/dist/bigint-crypto-utils-latest.browser.mod.js
@@ -118,7 +118,7 @@ function gcd(a, b) {
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
*
* @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
*
* @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
*/
diff --git a/dist/bigint-crypto-utils-latest.node.js b/dist/bigint-crypto-utils-latest.node.js
index 71c57d2..5c0690a 100644
--- a/dist/bigint-crypto-utils-latest.node.js
+++ b/dist/bigint-crypto-utils-latest.node.js
@@ -122,7 +122,7 @@ function gcd(a, b) {
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
*
* @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
*
* @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
*/
diff --git a/package-lock.json b/package-lock.json
index 9936caa..4333d0b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -2400,9 +2400,9 @@
}
},
"rollup": {
- "version": "1.27.9",
- "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.27.9.tgz",
- "integrity": "sha512-8AfW4cJTPZfG6EXWwT/ujL4owUsDI1Xl8J1t+hvK4wDX81F5I4IbwP9gvGbHzxnV19fnU4rRABZQwZSX9J402Q==",
+ "version": "1.27.13",
+ "resolved": "https://registry.npmjs.org/rollup/-/rollup-1.27.13.tgz",
+ "integrity": "sha512-hDi7M07MpmNSDE8YVwGVFA8L7n8jTLJ4lG65nMAijAyqBe//rtu4JdxjUBE7JqXfdpqxqDTbCDys9WcqdpsQvw==",
"dev": true,
"requires": {
"@types/estree": "*",
diff --git a/package.json b/package.json
index 8e71903..8651255 100644
--- a/package.json
+++ b/package.json
@@ -36,15 +36,15 @@
"prepublishOnly": "npm run build && npm run build:docs"
},
"devDependencies": {
+ "@rollup/plugin-replace": "^2.2.1",
"chai": ">=4.2.0",
"eslint": "^6.5.1",
"jsdoc-to-markdown": "^5.0.3",
"mocha": "^6.2.1",
- "rollup": "^1.23.1",
+ "rollup": "^1.27.13",
"rollup-plugin-babel-minify": "^9.1.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-multi-entry": ">=2.1.0",
- "rollup-plugin-node-resolve": ">=5.2.0",
- "@rollup/plugin-replace": "^2.2.1"
+ "rollup-plugin-node-resolve": ">=5.2.0"
}
}
diff --git a/src/main.js b/src/main.js
index d5c0382..27a5c71 100644
--- a/src/main.js
+++ b/src/main.js
@@ -120,7 +120,7 @@ export function gcd(a, b) {
* iterations of Miller-Rabin Probabilistic Primality Test (FIPS 186-4 C.3.1)
*
* @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
*
* @return {Promise} A promise that resolves to a boolean that is either true (a probably prime number) or false (definitely composite)
*/