Repository navigation
Fixes the modulus byte length for RSA keys whose size is 8k+1 bits (1025, 2049, …) — #246. Thanks to @trackoor for the report.
The length was computed as (bits + 6) >> 3 instead of ⌈bits / 8⌉, one byte short exactly for these sizes. Key sizes that are a multiple of 8 — everything generateKeyPair can produce — and all other sizes are not affected; nothing changes for them.
What changes for an affected (imported) key
- Ciphertext blocks and signatures are now
⌈bits / 8⌉bytes (129 for a 1025-bit key, was 128);getMaxMessageSize()grows by one. - The node engine can decrypt again — it used to fail on its own and on OpenSSL's ciphertexts.
- The pure-JS engine interoperates with OpenSSL in both directions for PKCS#1 v1.5 / OAEP encryption and PKCS#1 v1.5 / PSS signatures.
- The pure-JS engine no longer fails when the RSA result needs the top byte: with jsbn
encrypt/signthrew, with nativeBigIntthey silently returned output with that byte cut off. - OAEP decryption in the pure-JS engine again checks the encoded message's leading byte in constant time. With jsbn the old code rejected such values early, so decryption time depended on whether the result was ≥ 2^(8(k−1)).
Compatibility
Ciphertexts and PKCS#1 v1.5 signatures that an older version's pure-JS engine produced with an 8k+1-bit key used a non-standard encoding and are no longer accepted. PSS signatures still verify. If you have such data, decrypt it with the old version before upgrading.
See CHANGELOG.md for details.