> I've posted an answer on SE, but will give a short summary of what I think 
> solves the problem here.
> Please contact the author to make sure my proposed fix solves the problem.
>

We benchmarked this, and we found there's about a non-trivial speedup using 
the square of a random value. Below is the updated code.

We need to retain the Jacobi tests because of possible testing using small 
moduli. That is, landing on p and q may not be that remote in some 
scenarios.

*****

Here are the representative benchmarks. They ratios are consistent with and 
without OpenMP, on a host or in a VM, etc.

Purely Random:
    $ ./rw-test.exe
   5000 signings performed in 22530 milliseconds

Random squaring:
    $ ./rw-test.exe
    5000 signings performed in 13580 milliseconds

*****

+void InvertibleRWFunction::GenerateBlindingValue(RandomNumberGenerator& 
rng, Integer& r, Integer& rInv) const
+{
+    ModularArithmetic modn(m_n);
+    bool stop = false;
+
+    while(!stop)
+    {
+        // Jacobi is O(m*log(n)); ModInv is O(n^2). Perform the Jacobi's 
first
+        r.Randomize(rng, Integer::One(), m_n - Integer::One());
+        r = modn.Square(r);
+
+        int jp, jq;
+        #pragma omp parallel sections
+        {
+            #pragma omp section
+                jp = Jacobi(r % m_p, m_p);
+            #pragma omp section
+                jq = Jacobi(r % m_q, m_q);
+        }
+
+        if ((jp != -1) && (jq != -1))
+        {
+            rInv = modn.MultiplicativeInverse(r);
+            if(rInv.NotZero())
+                stop = true;
+        }
+    }
+ }

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to