From d23a489940499bd6c634a1cb0a9875f094f8a850 Mon Sep 17 00:00:00 2001 From: weidai Date: Thu, 20 Mar 2003 01:24:12 +0000 Subject: various changes for 5.1 git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@38 57ff6487-cd31-0410-9ec3-f628ee90f5f0 --- rabin.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'rabin.cpp') diff --git a/rabin.cpp b/rabin.cpp index 80e96a6..7f85056 100644 --- a/rabin.cpp +++ b/rabin.cpp @@ -5,6 +5,7 @@ #include "nbtheory.h" #include "asn.h" #include "sha.h" +#include "modarith.h" #include "oaep.cpp" @@ -138,11 +139,17 @@ void InvertibleRabinFunction::DEREncode(BufferedTransformation &bt) const seq.MessageEnd(); } -Integer InvertibleRabinFunction::CalculateInverse(const Integer &in) const +Integer InvertibleRabinFunction::CalculateInverse(RandomNumberGenerator &rng, const Integer &in) const { DoQuickSanityCheck(); - Integer cp=in%m_p, cq=in%m_q; + ModularArithmetic modn(m_n); + Integer r(rng, Integer::One(), m_n - Integer::One()); + r = modn.Square(r); + Integer r2 = modn.Square(r); + Integer c = modn.Multiply(in, r2); // blind + + Integer cp=c%m_p, cq=c%m_q; int jp = Jacobi(cp, m_p); int jq = Jacobi(cq, m_q); @@ -167,6 +174,8 @@ Integer InvertibleRabinFunction::CalculateInverse(const Integer &in) const Integer out = CRT(cq, m_q, cp, m_p, m_u); + out = modn.Divide(out, r); // unblind + if ((jq==-1 && out.IsEven()) || (jq==1 && out.IsOdd())) out = m_n-out; -- cgit v1.2.1