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