LibCrypto: Ensure RSA decryption with CRT works for all inputs

Ensure becomes `m1` greater than `m2` even when smaller by more than
one `p`. Since the next operations on `m1` are modulus `p` we can add it
as many times as it's needed.
This commit is contained in:
devgianlu 2024-12-18 18:51:48 +01:00 committed by Jelle Raaijmakers
parent 1c9f0601e9
commit 8620a2af47
Notes: github-actions[bot] 2024-12-19 17:44:17 +00:00

View file

@ -141,11 +141,9 @@ void RSA::decrypt(ReadonlyBytes in, Bytes& out)
} else {
auto m1 = NumberTheory::ModularPower(in_integer, m_private_key.exponent1(), m_private_key.prime1());
auto m2 = NumberTheory::ModularPower(in_integer, m_private_key.exponent2(), m_private_key.prime2());
if (m1 < m2)
while (m1 < m2)
m1 = m1.plus(m_private_key.prime1());
VERIFY(m1 >= m2);
auto h = NumberTheory::Mod(m1.minus(m2).multiplied_by(m_private_key.coefficient()), m_private_key.prime1());
m = m2.plus(h.multiplied_by(m_private_key.prime2()));
}