<div dir="ltr">Thank you. I have confirmed that your patch resolves the issue.<div><br></div><div>However I tried again with 1.8.0 and at that version, the reproducer prints "Inverse exists".</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 10, 2022 at 9:05 AM NIIBE Yutaka <<a href="mailto:gniibe@fsij.org">gniibe@fsij.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Guido Vranken wrote:<br>
> It says that InvMod(18446744073709551615,<br>
> 340282366762482138434845932244680310781) is<br>
> 170141183381241069226646338154899963903 but that's not true, because<br>
> 170141183381241069226646338154899963903 * 18446744073709551615 %<br>
> 340282366762482138434845932244680310781 is 4294967297, not 1.<br>
<br>
Thank you for your report.  With libgcrypt 1.8, it works correctly.<br>
<br>
It is tracked by: <a href="https://dev.gnupg.org/T5970" rel="noreferrer" target="_blank">https://dev.gnupg.org/T5970</a><br>
<br>
The fix I pushed is:<br>
<br>
diff --git a/mpi/mpih-const-time.c b/mpi/mpih-const-time.c<br>
index b527ad79..9d74d190 100644<br>
--- a/mpi/mpih-const-time.c<br>
+++ b/mpi/mpih-const-time.c<br>
@@ -204,6 +204,13 @@ _gcry_mpih_cmp_ui (mpi_ptr_t up, mpi_size_t usize, unsigned long v)<br>
     is_all_zero &= (up[i] == 0);<br>
<br>
   if (is_all_zero)<br>
-    return up[0] - v;<br>
+    {<br>
+      if (up[0] < v)<br>
+        return -1;<br>
+      else if (up[0] > v)<br>
+        return 1;<br>
+      else<br>
+        return 0;<br>
+    }<br>
   return 1;<br>
 }<br>
<br>
<br>
<br>
The expression of up[0] - v is only correct on 32-bit architecture.<br>
It may return wrong result on 64-bit architecture.<br>
-- <br>
</blockquote></div>