Crypto++

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

eprecomp.h

    00001 #ifndef CRYPTOPP_EPRECOMP_H
    00002 #define CRYPTOPP_EPRECOMP_H
    00003
    00004 #include "integer.h"
    00005 #include "algebra.h"
    00006 #include <vector>
    00007
    00008 NAMESPACE_BEGIN(CryptoPP)
    00009
    00010 template <class T>
    00011 class DL_GroupPrecomputation
    00012 {
    00013 public:
    00014     typedef T Element;
    00015
    00016     virtual bool NeedConversions() const {return false;}
    00017     virtual Element ConvertIn(const Element &v) const {return v;}
    00018     virtual Element ConvertOut(const Element &v) const {return v;}
    00019     virtual const AbstractGroup<Element> & GetGroup() const =0;
    00020     virtual Element BERDecodeElement(BufferedTransformation &bt) const =0;
    00021     virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0;
    00022 };
    00023
    00024 template <class T>
    00025 class DL_FixedBasePrecomputation
    00026 {
    00027 public:
    00028     typedef T Element;
    00029
    00030     virtual bool IsInitialized() const =0;
    00031     virtual void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base) =0;
    00032     virtual const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const =0;
    00033     virtual void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage) =0;
    00034     virtual void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) =0;
    00035     virtual void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const =0;
    00036     virtual Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const =0;
    00037     virtual Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const =0;
    00038 };
    00039
    00040 template <class T>
    00041 class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation<T>
    00042 {
    00043 public:
    00044     typedef T Element;
    00045
    00046     DL_FixedBasePrecomputationImpl() : m_windowSize(0) {}
    00047
    00048     // DL_FixedBasePrecomputation
    00049     bool IsInitialized() const
    00050         {return !m_bases.empty();}
    00051     void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base);
    00052     const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const
    00053         {return group.NeedConversions() ? m_base : m_bases[0];}
    00054     void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage);
    00055     void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation);
    00056     void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const;
    00057     Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
    00058     Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const;
    00059
    00060 private:
    00061     void PrepareCascade(const DL_GroupPrecomputation<Element> &group, std::vector<BaseAndExponent<Element> > &eb, const Integer &exponent) const;
    00062
    00063     Element m_base;
    00064     unsigned int m_windowSize;
    00065     Integer m_exponentBase;         // what base to represent the exponent in
    00066     std::vector<Element> m_bases;   // precalculated bases
    00067 };
    00068
    00069 NAMESPACE_END
    00070
    00071 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
    00072 #include "eprecomp.cpp"
    00073 #endif
    00074
    00075 #endif