mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-10-27 06:43:19 +08:00
Keys, primes and generators drop their leading zero bytes before import, as BN_bin2bn does, and a value still past mbedTLS's 80000-byte limit throws Node's error or a coded SC2020 error instead of aborting the process: computeSecret rejects a key longer than the prime as too large, a long generator is a bad generator, and setPublicKey/setPrivateKey refuse with SC2020. Under the RFC 5114 groups, computeSecret rejects a peer key with key^q mod p != 1 with ERR_CRYPTO_INVALID_KEYTYPE, as OpenSSL's public key check does, closing small-subgroup confinement of the private key. The safe-prime groups keep the range check only, as in Node. Exponents past 8192 bits are split into digits bit by bit, so generateKeys with a long private key takes linear time.