monotone

monotone Mtn Source Tree

Root/cryptopp/eprecomp.h

1#ifndef CRYPTOPP_EPRECOMP_H
2#define CRYPTOPP_EPRECOMP_H
3
4#include "integer.h"
5#include "algebra.h"
6#include <vector>
7
8NAMESPACE_BEGIN(CryptoPP)
9
10template <class T>
11class DL_GroupPrecomputation
12{
13public:
14typedef T Element;
15
16virtual bool NeedConversions() const {return false;}
17virtual Element ConvertIn(const Element &v) const {return v;}
18virtual Element ConvertOut(const Element &v) const {return v;}
19virtual const AbstractGroup<Element> & GetGroup() const =0;
20virtual Element BERDecodeElement(BufferedTransformation &bt) const =0;
21virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0;
22};
23
24template <class T>
25class DL_FixedBasePrecomputation
26{
27public:
28typedef T Element;
29
30virtual bool IsInitialized() const =0;
31virtual void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base) =0;
32virtual const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const =0;
33virtual void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage) =0;
34virtual void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) =0;
35virtual void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const =0;
36virtual Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const =0;
37virtual Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const =0;
38};
39
40template <class T>
41class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation<T>
42{
43public:
44typedef T Element;
45
46// DL_FixedBasePrecomputation
47bool IsInitialized() const
48{return !m_bases.empty();}
49void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base);
50const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const
51{return group.NeedConversions() ? m_base : m_bases[0];}
52void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage);
53void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation);
54void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const;
55Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
56Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const;
57
58private:
59void PrepareCascade(const DL_GroupPrecomputation<Element> &group, std::vector<BaseAndExponent<Element> > &eb, const Integer &exponent) const;
60
61Element m_base;
62unsigned int m_windowSize;
63Integer m_exponentBase;// what base to represent the exponent in
64std::vector<Element> m_bases;// precalculated bases
65};
66
67NAMESPACE_END
68
69#endif

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status