Skip to content

Commit

Permalink
LibCrypto: Ensure RSA decryption with CRT works for all inputs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
devgianlu committed Dec 18, 2024
1 parent ce65457 commit e124a4a
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions Libraries/LibCrypto/PK/RSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down

0 comments on commit e124a4a

Please sign in to comment.