crypto.generatePrimeSync(size[, options])
-
size<number> 要生成的素数的大小(以位为单位)。¥
size<number> The size (in bits) of the prime to generate. -
options<Object>-
add<ArrayBuffer> | <SharedArrayBuffer> | <TypedArray> | <Buffer> | <DataView> | <bigint> -
rem<ArrayBuffer> | <SharedArrayBuffer> | <TypedArray> | <Buffer> | <DataView> | <bigint> -
safe<boolean> 默认值:false。¥
safe<boolean> Default:false. -
bigint<boolean> 当true时,生成的素数作为bigint返回。¥
bigint<boolean> Whentrue, the generated prime is returned as abigint.
-
-
返回:<ArrayBuffer> | <bigint>
¥Returns: <ArrayBuffer> | <bigint>
生成 size 位的伪随机素数。
¥Generates a pseudorandom prime of size bits.
如果 options.safe 是 true,素数将是一个安全素数 - 也就是说,(prime - 1) / 2 也将是素数。
¥If options.safe is true, the prime will be a safe prime -- that is,
(prime - 1) / 2 will also be a prime.
options.add 和 options.rem 参数可用于强制执行其他要求,例如,对于 Diffie-Hellman:
¥The options.add and options.rem parameters can be used to enforce additional
requirements, e.g., for Diffie-Hellman:
-
如果
options.add和options.rem都设置,素数将满足条件prime % add = rem。¥If
options.addandoptions.remare both set, the prime will satisfy the condition thatprime % add = rem. -
如果只设置了
options.add而options.safe不是true,素数将满足条件prime % add = 1。¥If only
options.addis set andoptions.safeis nottrue, the prime will satisfy the condition thatprime % add = 1. -
如果只设置了
options.add,而将options.safe设置为true,则素数将满足条件prime % add = 3。这是必要的,因为options.add > 2的prime % add = 1会与options.safe强制执行的条件相矛盾。¥If only
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.add,则忽略options.rem。¥
options.remis ignored ifoptions.addis not given.
如果以 ArrayBuffer、SharedArrayBuffer、TypedArray、Buffer 或 DataView 形式给出,则 options.add 和 options.rem 都必须编码为大端序列。
¥Both options.add and options.rem must be encoded as big-endian sequences
if given as an ArrayBuffer, SharedArrayBuffer, TypedArray, Buffer, or
DataView.
默认情况下,素数被编码为 <ArrayBuffer> 中八位字节的大端序列。如果 bigint 选项为 true,则提供 <bigint>。
¥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.