If options.safe is true, the prime will be a safe prime -- that is, (prime - 1) / 2 will also be a prime.
The options.add and options.rem parameters can be used to enforce additional
requirements, e.g., for Diffie-Hellman:
If options.add and options.rem are both set, the prime will satisfy the
condition that prime % add = rem.
If only options.add is set and options.safe is not true, the prime will
satisfy the condition that prime % add = 1.
If only options.add is set and options.safe is set to true, the prime
will instead satisfy the condition that prime % add = 3. This is necessary
because prime % add = 1 for options.add > 2 would contradict the condition
enforced by options.safe.
options.rem is ignored if options.add is not given.
Both options.add and options.rem must be encoded as big-endian sequences
if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or DataView.
By default, the prime is encoded as a big-endian sequence of octets
in an ArrayBuffer. If the bigint option is true, then a
bigint is provided.
Generates a pseudorandom prime of
sizebits.If
options.safeistrue, the prime will be a safe prime -- that is,(prime - 1) / 2will also be a prime.The
options.addandoptions.remparameters can be used to enforce additional requirements, e.g., for Diffie-Hellman:options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem.options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1.options.addis set andoptions.safeis set totrue, the prime will instead satisfy the condition thatprime % add = 3. This is necessary becauseprime % add = 1foroptions.add > 2would contradict the condition enforced byoptions.safe.options.remis ignored ifoptions.addis not given.Both
options.addandoptions.remmust be encoded as big-endian sequences if given as anArrayBuffer,SharedArrayBuffer,TypedArray,Buffer, orDataView.By default, the prime is encoded as a big-endian sequence of octets in an ArrayBuffer. If the
bigintoption istrue, then a bigint is provided.