Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
3.0 KiB

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