Fabcoin Core  0.16.2
P2P Digital Currency
eprecomp.h
Go to the documentation of this file.
1 // eprecomp.h - written and placed in the public domain by Wei Dai
2 
5 
6 #ifndef CRYPTOPP_EPRECOMP_H
7 #define CRYPTOPP_EPRECOMP_H
8 
9 #include "cryptlib.h"
10 #include "integer.h"
11 #include "algebra.h"
12 #include "stdcpp.h"
13 
15 
16 template <class T>
18 {
19 public:
20  typedef T Element;
21 
23 
24  virtual bool NeedConversions() const {return false;}
25  virtual Element ConvertIn(const Element &v) const {return v;}
26  virtual Element ConvertOut(const Element &v) const {return v;}
27  virtual const AbstractGroup<Element> & GetGroup() const =0;
28  virtual Element BERDecodeElement(BufferedTransformation &bt) const =0;
29  virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0;
30 };
31 
32 template <class T>
34 {
35 public:
36  typedef T Element;
37 
39 
40  virtual bool IsInitialized() const =0;
41  virtual void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base) =0;
42  virtual const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const =0;
43  virtual void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage) =0;
44  virtual void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) =0;
45  virtual void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const =0;
46  virtual Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const =0;
47  virtual Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const =0;
48 };
49 
50 template <class T>
52 {
53 public:
54  typedef T Element;
55 
57 
58  DL_FixedBasePrecomputationImpl() : m_windowSize(0) {}
59 
60  // DL_FixedBasePrecomputation
61  bool IsInitialized() const
62  {return !m_bases.empty();}
63  void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base);
64  const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const
65  {return group.NeedConversions() ? m_base : m_bases[0];}
66  void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage);
67  void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation);
68  void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const;
69  Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
70  Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const;
71 
72 private:
73  void PrepareCascade(const DL_GroupPrecomputation<Element> &group, std::vector<BaseAndExponent<Element> > &eb, const Integer &exponent) const;
74 
75  Element m_base;
76  unsigned int m_windowSize;
77  Integer m_exponentBase; // what base to represent the exponent in
78  std::vector<Element> m_bases; // precalculated bases
79 };
80 
82 
83 #ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
84 #include "eprecomp.cpp"
85 #endif
86 
87 #endif
virtual bool NeedConversions() const
Definition: eprecomp.h:24
virtual Element Exponentiate(const DL_GroupPrecomputation< Element > &group, const Integer &exponent) const =0
virtual ~DL_FixedBasePrecomputation()
Definition: eprecomp.h:38
#define T(i, x)
#define NAMESPACE_BEGIN(x)
Definition: config.h:200
virtual ~DL_FixedBasePrecomputationImpl()
Definition: eprecomp.h:56
bool IsInitialized() const
Definition: eprecomp.h:61
Abstract base classes that provide a uniform interface to this library.
virtual void Load(const DL_GroupPrecomputation< Element > &group, BufferedTransformation &storedPrecomputation)=0
virtual Element CascadeExponentiate(const DL_GroupPrecomputation< Element > &group, const Integer &exponent, const DL_FixedBasePrecomputation< Element > &pc2, const Integer &exponent2) const =0
const Element & GetBase(const DL_GroupPrecomputation< Element > &group) const
Definition: eprecomp.h:64
Classes for performing mathematics over different fields.
Interface for buffered transformations.
Definition: cryptlib.h:1352
virtual Element ConvertIn(const Element &v) const
Definition: eprecomp.h:25
virtual void SetBase(const DL_GroupPrecomputation< Element > &group, const Element &base)=0
virtual bool IsInitialized() const =0
std::vector< Element > m_bases
Definition: eprecomp.h:78
virtual const Element & GetBase(const DL_GroupPrecomputation< Element > &group) const =0
virtual void Save(const DL_GroupPrecomputation< Element > &group, BufferedTransformation &storedPrecomputation) const =0
Multiple precision integer with arithmetic operations.
Definition: integer.h:43
virtual ~DL_GroupPrecomputation()
Definition: eprecomp.h:22
Abstract group.
Definition: algebra.h:26
#define P
Multiple precision integer with arithmetic operations.
#define NAMESPACE_END
Definition: config.h:201
Base and exponent.
Definition: algebra.h:249
virtual void Precompute(const DL_GroupPrecomputation< Element > &group, unsigned int maxExpBits, unsigned int storage)=0
virtual Element ConvertOut(const Element &v) const
Definition: eprecomp.h:26