summaryrefslogtreecommitdiffstats
path: root/lib/cryptopp/eprecomp.h
diff options
context:
space:
mode:
authorworktycho <work.tycho@gmail.com>2013-12-09 18:51:12 +0100
committerworktycho <work.tycho@gmail.com>2013-12-09 18:51:12 +0100
commit843605d59ebc128be0a578dc6f45ef8c05da6e79 (patch)
tree3ffebc6ba27baf7a9e1d4bc51501ffeea9b14226 /lib/cryptopp/eprecomp.h
parentmerged makefile changes (diff)
parentFix Undefined behavior at Bindings/LuaWindow line 32 (diff)
downloadcuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.gz
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.bz2
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.lz
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.xz
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.tar.zst
cuberite-843605d59ebc128be0a578dc6f45ef8c05da6e79.zip
Diffstat (limited to 'lib/cryptopp/eprecomp.h')
-rw-r--r--lib/cryptopp/eprecomp.h75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/cryptopp/eprecomp.h b/lib/cryptopp/eprecomp.h
new file mode 100644
index 000000000..1f3256766
--- /dev/null
+++ b/lib/cryptopp/eprecomp.h
@@ -0,0 +1,75 @@
+#ifndef CRYPTOPP_EPRECOMP_H
+#define CRYPTOPP_EPRECOMP_H
+
+#include "integer.h"
+#include "algebra.h"
+#include <vector>
+
+NAMESPACE_BEGIN(CryptoPP)
+
+template <class T>
+class DL_GroupPrecomputation
+{
+public:
+ typedef T Element;
+
+ virtual bool NeedConversions() const {return false;}
+ virtual Element ConvertIn(const Element &v) const {return v;}
+ virtual Element ConvertOut(const Element &v) const {return v;}
+ virtual const AbstractGroup<Element> & GetGroup() const =0;
+ virtual Element BERDecodeElement(BufferedTransformation &bt) const =0;
+ virtual void DEREncodeElement(BufferedTransformation &bt, const Element &P) const =0;
+};
+
+template <class T>
+class DL_FixedBasePrecomputation
+{
+public:
+ typedef T Element;
+
+ virtual bool IsInitialized() const =0;
+ virtual void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base) =0;
+ virtual const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const =0;
+ virtual void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage) =0;
+ virtual void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) =0;
+ virtual void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const =0;
+ virtual Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const =0;
+ virtual Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const =0;
+};
+
+template <class T>
+class DL_FixedBasePrecomputationImpl : public DL_FixedBasePrecomputation<T>
+{
+public:
+ typedef T Element;
+
+ DL_FixedBasePrecomputationImpl() : m_windowSize(0) {}
+
+ // DL_FixedBasePrecomputation
+ bool IsInitialized() const
+ {return !m_bases.empty();}
+ void SetBase(const DL_GroupPrecomputation<Element> &group, const Element &base);
+ const Element & GetBase(const DL_GroupPrecomputation<Element> &group) const
+ {return group.NeedConversions() ? m_base : m_bases[0];}
+ void Precompute(const DL_GroupPrecomputation<Element> &group, unsigned int maxExpBits, unsigned int storage);
+ void Load(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation);
+ void Save(const DL_GroupPrecomputation<Element> &group, BufferedTransformation &storedPrecomputation) const;
+ Element Exponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent) const;
+ Element CascadeExponentiate(const DL_GroupPrecomputation<Element> &group, const Integer &exponent, const DL_FixedBasePrecomputation<Element> &pc2, const Integer &exponent2) const;
+
+private:
+ void PrepareCascade(const DL_GroupPrecomputation<Element> &group, std::vector<BaseAndExponent<Element> > &eb, const Integer &exponent) const;
+
+ Element m_base;
+ unsigned int m_windowSize;
+ Integer m_exponentBase; // what base to represent the exponent in
+ std::vector<Element> m_bases; // precalculated bases
+};
+
+NAMESPACE_END
+
+#ifdef CRYPTOPP_MANUALLY_INSTANTIATE_TEMPLATES
+#include "eprecomp.cpp"
+#endif
+
+#endif