浏览代码

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.
devgianlu 7 月之前
父节点
当前提交
8620a2af47
共有 1 个文件被更改,包括 1 次插入3 次删除
  1. 1 3
      Libraries/LibCrypto/PK/RSA.cpp

+ 1 - 3
Libraries/LibCrypto/PK/RSA.cpp

@@ -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()));
     }