You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixes#490
- Bump `crypto-bigint` dependency to the current trunk.
- Use the width of a single prime instead of the full modulus where
possible. Brings `bench_rsa_2048_pkcsv1_decrypt` to pre-`crypto-bigint`
values.
- Add a check to `RsaPrivateKey::from_components()` to ensure
consistency between the primes and the modulus.
- Remove zero padding limbs from the primes and the modulus in
`RsaPrivateKey::from_components()`.
- Add a check to `rsa_decrypt()` to ensure the bit precision of the
ciphertext is the same as that of the modulus.
Notes:
- `bench_rsa_2048_pkcsv1_sign_blinded` can be restored to the original
performance by using variable-time inversion in
`algorithms::rsa::blind()` (as it was during `num-bigint` times), but it
seems to me that the blinding factor must be kept secret, so we have to
use the constant-time inversion. This leads to about 5x slowdown
compared to pre-`crypto-bigint` performance.
- The changes in test vectors are due to
RustCrypto/crypto-bigint#781
### Possible further improvements
- Keep precomputed values as `Odd`/`NonZero` as appropriate.
- If RustCrypto/crypto-bigint#811 is fixed,
resizing integers for the purposes of division can be avoided.
let lcm = p1 / NonZero::new(gcd).expect("gcd is non zero")*&q1;
359
-
let exp = exp.widen(lcm.bits_precision());
378
+
let exp = exp.resize_unchecked(lcm.bits_precision());
360
379
ifletSome(d) = exp.inv_mod(&lcm).into(){
361
380
Ok(d)
362
381
}else{
@@ -373,11 +392,55 @@ mod tests {
373
392
fnrecover_primes_works(){
374
393
let bits = 2048;
375
394
376
-
let n = BoxedUint::from_be_hex("d397b84d98a4c26138ed1b695a8106ead91d553bf06041b62d3fdc50a041e222b8f4529689c1b82c5e71554f5dd69fa2f4b6158cf0dbeb57811a0fc327e1f28e74fe74d3bc166c1eabdc1b8b57b934ca8be5b00b4f29975bcc99acaf415b59bb28a6782bb41a2c3c2976b3c18dbadef62f00c6bb226640095096c0cc60d22fe7ef987d75c6a81b10d96bf292028af110dc7cc1bbc43d22adab379a0cd5d8078cc780ff5cd6209dea34c922cf784f7717e428d75b5aec8ff30e5f0141510766e2e0ab8d473c84e8710b2b98227c3db095337ad3452f19e2b9bfbccdd8148abf6776fa552775e6e75956e45229ae5a9c46949bab1e622f0e48f56524a84ed3483b", bits).unwrap();
let d = BoxedUint::from_be_hex("c4e70c689162c94c660828191b52b4d8392115df486a9adbe831e458d73958320dc1b755456e93701e9702d76fb0b92f90e01d1fe248153281fe79aa9763a92fae69d8d7ecd144de29fa135bd14f9573e349e45031e3b76982f583003826c552e89a397c1a06bd2163488630d92e8c2bb643d7abef700da95d685c941489a46f54b5316f62b5d2c3a7f1bbd134cb37353a44683fdc9d95d36458de22f6c44057fe74a0a436c4308f73f4da42f35c47ac16a7138d483afc91e41dc3a1127382e0c0f5119b0221b4fc639d6b9c38177a6de9b526ebd88c38d7982c07f98a0efd877d508aae275b946915c02e2e1106d175d74ec6777f5e80d12c053d9c7be1e341", bits).unwrap();
379
-
let p = BoxedUint::from_be_hex("f827bbf3a41877c7cc59aebf42ed4b29c32defcb8ed96863d5b090a05a8930dd624a21c9dcf9838568fdfa0df65b8462a5f2ac913d6c56f975532bd8e78fb07bd405ca99a484bcf59f019bbddcb3933f2bce706300b4f7b110120c5df9018159067c35da3061a56c8635a52b54273b31271b4311f0795df6021e6355e1a42e61", bits / 2).unwrap();
380
-
let q = BoxedUint::from_be_hex("da4817ce0089dd36f2ade6a3ff410c73ec34bf1b4f6bda38431bfede11cef1f7f6efa70e5f8063a3b1f6e17296ffb15feefa0912a0325b8d1fd65a559e717b5b961ec345072e0ec5203d03441d29af4d64054a04507410cf1da78e7b6119d909ec66e6ad625bf995b279a4b3c5be7d895cd7c5b9c4c497fde730916fcdb4e41b", bits / 2).unwrap();
0 commit comments