@@ -1961,6 +1961,48 @@ is currently in use. Setting to true requires a FIPS build of Node.js.
1961
1961
This property is deprecated. Please use ` crypto.setFips() ` and
1962
1962
` crypto.getFips() ` instead.
1963
1963
1964
+ ### ` crypto.checkPrime(candidate[, options, [callback]]) `
1965
+ <!-- YAML
1966
+ added: REPLACEME
1967
+ -->
1968
+
1969
+ * ` candidate ` {ArrayBuffer|SharedArrayBuffer|TypedArray|Buffer|DataView} A
1970
+ possible prime encoded as a sequence of big endian octets of arbitrary
1971
+ length.
1972
+ * ` options ` {Object}
1973
+ * ` checks ` {number} The number of primality checks to perform. When the
1974
+ value is ` 0 ` (zero), a number of checks is used that yields a false
1975
+ positive rate of at most 2^-64 for random input. Care must be used
1976
+ when selecting a number of checks. Refer to the OpenSSL documentation
1977
+ for the [ ` BN_is_prime_ex ` ] [ ] function ` nchecks ` options for more details.
1978
+ ** Defaults** : ` 0 `
1979
+ * ` callback ` {Function}
1980
+ * ` err ` {Error} Set to an {Error} object if an error occured during check.
1981
+ * ` result ` {boolean} ` true ` if the candidate is a prime with an error
1982
+ probability less than ` 0.25^options.checks ` .
1983
+
1984
+ Checks the primality of the ` candidate ` .
1985
+
1986
+ ### ` crypto.checkPrimeSync(candidate[, options]) `
1987
+ <!-- YAML
1988
+ added: REPLACEME
1989
+ -->
1990
+
1991
+ * ` candidate ` {ArrayBuffer|SharedArrayBuffer|TypedArray|Buffer|DataView} A
1992
+ possible prime encoded as a sequence of big endian octets of arbitrary
1993
+ length.
1994
+ * ` options ` {Object}
1995
+ * ` checks ` {number} The number of primality checks to perform. When the
1996
+ value is ` 0 ` (zero), a number of checks is used that yields a false
1997
+ positive rate of at most 2^-64 for random input. Care must be used
1998
+ when selecting a number of checks. Refer to the OpenSSL documentation
1999
+ for the [ ` BN_is_prime_ex ` ] [ ] function ` nchecks ` options for more details.
2000
+ ** Defaults** : ` 0 `
2001
+ * Returns: {boolean} ` true ` if the candidate is a prime with an error
2002
+ probability less than ` 0.25^options.checks ` .
2003
+
2004
+ Checks the primality of the ` candidate ` .
2005
+
1964
2006
### ` crypto.createCipher(algorithm, password[, options]) `
1965
2007
<!-- YAML
1966
2008
added: v0.1.94
@@ -3432,6 +3474,62 @@ const n = crypto.randomInt(1, 7);
3432
3474
console .log (` The dice rolled: ${ n} ` );
3433
3475
```
3434
3476
3477
+ ### ` crypto.randomPrime(size[, options[, callback]]) `
3478
+ <!-- YAML
3479
+ added: REPLACEME
3480
+ -->
3481
+
3482
+ * ` size ` {number} The size (in bits) of the prime to generate.
3483
+ * ` options ` {Object}
3484
+ * ` add ` {ArrayBuffer|SharedArrayBuffer|TypedArray|Buffer|DataView}
3485
+ * ` rem ` {ArrayBuffer|SharedArrayBuffer|TypedArray|Buffer|DataView}
3486
+ * ` safe ` {boolean}
3487
+ * ` callback ` {Function}
3488
+ * ` err ` {Error}
3489
+ * ` prime ` {ArrayBuffer}
3490
+
3491
+ Generates a pseudo-random prime of ` size ` bits.
3492
+
3493
+ If ` options.safe ` is true, the prime will be a safe prime -- that is,
3494
+ ` (prime - 1) / 2 ` will also be a prime.
3495
+
3496
+ If ` options.add ` and ` options.rem ` are set, the prime will satisfy the
3497
+ condition that prime % add = rem. The ` options.rem ` is ignored if
3498
+ ` options.add ` is not given. If ` options.safe ` is ` true ` , ` options.add `
3499
+ is given, and ` options.rem ` is ` undefined ` , then th prime generated
3500
+ will satisfy the condition ` prime % add = 3 ` . Otherwise if ` options.safe `
3501
+ is ` false ` and ` options.rem ` is ` undefined ` , ` options.add ` will be
3502
+ ignored.
3503
+
3504
+ The prime is encoded as a big-endian sequence of octets in an {ArrayBuffer}.
3505
+
3506
+ ### ` crypto.randomPrimeSync(size[, options]) `
3507
+ <!-- YAML
3508
+ added: REPLACEME
3509
+ -->
3510
+
3511
+ * ` size ` {number} The size (in bits) of the prime to generate.
3512
+ * ` options ` {Object}
3513
+ * ` add ` {ArrayBuffer|SharedArrayBuffer|TypedArray|Buffer|DataView}
3514
+ * ` rem ` {ArrayBuffer|SharedArrayBuffer|TypedArray|Buffer|DataView}
3515
+ * ` safe ` {boolean}
3516
+ * Returns: {ArrayBuffer}
3517
+
3518
+ Generates a pseudo-random prime of ` size ` bits.
3519
+
3520
+ If ` options.safe ` is true, the prime will be a safe prime -- that is,
3521
+ ` (prime - 1) ` / 2 will also be a prime.
3522
+
3523
+ If ` options.add ` and ` options.rem ` are set, the prime will satisfy the
3524
+ condition that prime % add = rem. The ` options.rem ` is ignored if
3525
+ ` options.add ` is not given. If ` options.safe ` is ` true ` , ` options.add `
3526
+ is given, and ` options.rem ` is ` undefined ` , then th prime generated
3527
+ will satisfy the condition ` prime % add = 3 ` . Otherwise if ` options.safe `
3528
+ is ` false ` and ` options.rem ` is ` undefined ` , ` options.add ` will be
3529
+ ignored.
3530
+
3531
+ The prime is encoded as a big-endian sequence of octets in an {ArrayBuffer}.
3532
+
3435
3533
### ` crypto.randomUUID([options]) `
3436
3534
<!-- YAML
3437
3535
added: v15.6.0
@@ -4234,6 +4332,7 @@ See the [list of SSL OP Flags][] for details.
4234
4332
[ RFC 4122 ] : https://www.rfc-editor.org/rfc/rfc4122.txt
4235
4333
[ RFC 5208 ] : https://www.rfc-editor.org/rfc/rfc5208.txt
4236
4334
[ Web Crypto API documentation ] : webcrypto.md
4335
+ [ `BN_is_prime_ex` ] : https://www.openssl.org/docs/man1.1.1/man3/BN_is_prime_ex.html
4237
4336
[ `Buffer` ] : buffer.md
4238
4337
[ `EVP_BytesToKey` ] : https://www.openssl.org/docs/man1.1.0/crypto/EVP_BytesToKey.html
4239
4338
[ `KeyObject` ] : #crypto_class_keyobject
0 commit comments