Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

modexppc.cpp

00001 // modexppc.cpp - written and placed in the public domain by Wei Dai 00002 00003 #include "pch.h" 00004 #include "modexppc.h" 00005 #include "asn.h" 00006 00007 #include "algebra.cpp" 00008 #include "eprecomp.cpp" 00009 00010 NAMESPACE_BEGIN(CryptoPP) 00011 00012 template class DL_FixedBasePrecomputationImpl<Integer>; 00013 00014 /* 00015 ModExpPrecomputation& ModExpPrecomputation::operator=(const ModExpPrecomputation &rhs) 00016 { 00017 m_base = rhs.m_base; 00018 m_mr = rhs.m_mr; 00019 m_ep = rhs.m_ep; 00020 if (m_mr.get() != NULL) 00021 m_ep.m_group = &m_mr->MultiplicativeGroup(); 00022 return *this; 00023 } 00024 00025 void ModExpPrecomputation::SetModulusAndBase(const Integer &modulus, const Integer &base) 00026 { 00027 m_base = base; 00028 if (m_mr.get() == NULL || modulus != m_mr->GetModulus()) 00029 m_mr.reset(new MontgomeryRepresentation(modulus)); 00030 m_ep.SetGroupAndBase(m_mr->MultiplicativeGroup(), m_mr->ConvertIn(base)); 00031 } 00032 00033 void ModExpPrecomputation::SetBase(const Integer &base) 00034 { 00035 m_base = base; 00036 m_ep.SetGroupAndBase(m_mr->MultiplicativeGroup(), m_mr->ConvertIn(base)); 00037 } 00038 00039 void ModExpPrecomputation::Precompute(unsigned int maxExpBits, unsigned int storage) 00040 { 00041 m_ep.Precompute(maxExpBits, storage); 00042 } 00043 00044 void ModExpPrecomputation::Load(BufferedTransformation &bt) 00045 { 00046 BERSequenceDecoder seq(bt); 00047 word32 version; 00048 BERDecodeUnsigned<word32>(seq, version, INTEGER, 1, 1); 00049 m_ep.m_exponentBase.BERDecode(seq); 00050 m_ep.m_windowSize = m_ep.m_exponentBase.BitCount() - 1; 00051 m_ep.m_bases.clear(); 00052 while (!seq.EndReached()) 00053 m_ep.m_bases.push_back(Integer(seq)); 00054 if (!m_ep.m_bases.empty()) 00055 m_base = m_mr->ConvertOut(m_ep.m_bases[0]); 00056 seq.MessageEnd(); 00057 } 00058 00059 void ModExpPrecomputation::Save(BufferedTransformation &bt) const 00060 { 00061 DERSequenceEncoder seq(bt); 00062 DEREncodeUnsigned<word32>(seq, 1); // version 00063 m_ep.m_exponentBase.DEREncode(seq); 00064 for (unsigned i=0; i<m_ep.m_bases.size(); i++) 00065 m_ep.m_bases[i].DEREncode(seq); 00066 seq.MessageEnd(); 00067 } 00068 00069 Integer ModExpPrecomputation::Exponentiate(const Integer &exponent) const 00070 { 00071 return m_mr->ConvertOut(m_ep.Exponentiate(exponent)); 00072 } 00073 00074 Integer ModExpPrecomputation::CascadeExponentiate(const Integer &exponent, const DL_FixedBasePrecomputation<Integer> &pc2, const Integer &exponent2) const 00075 { 00076 return m_mr->ConvertOut(m_ep.CascadeExponentiate(exponent, static_cast<const ModExpPrecomputation &>(pc2).m_ep, exponent2)); 00077 } 00078 */ 00079 00080 NAMESPACE_END

Generated on Wed Jul 28 08:07:08 2004 for Crypto++ by doxygen 1.3.7