diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2003-03-20 01:24:12 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2003-03-20 01:24:12 +0000 |
commit | d23a489940499bd6c634a1cb0a9875f094f8a850 (patch) | |
tree | f85b3bed971083e90e5f3dbb84539ea4ba0359e9 /rabin.cpp | |
parent | b3517523a738277cfe22428bd757833e69abb66e (diff) | |
download | cryptopp-d23a489940499bd6c634a1cb0a9875f094f8a850.tar.gz |
various changes for 5.1
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@38 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'rabin.cpp')
-rw-r--r-- | rabin.cpp | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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; |