diff options
author | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2009-03-02 02:39:17 +0000 |
---|---|---|
committer | weidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0> | 2009-03-02 02:39:17 +0000 |
commit | caf9e032e6b4ccb114a74a3936c916bcfaba262d (patch) | |
tree | 0fecaa7a6728d07549a41864ea2cedfb245f0bd3 /algparam.h | |
parent | 4e4793cc591e26c788b53c487bee7cab2d377f5e (diff) | |
download | cryptopp-caf9e032e6b4ccb114a74a3936c916bcfaba262d.tar.gz |
changes for 5.6:
- added AuthenticatedSymmetricCipher interface class and Filter wrappers
- added CCM, GCM (with SSE2 assembly), CMAC, and SEED
- improved AES speed on x86 and x64
- removed WORD64_AVAILABLE; compiler 64-bit int support is now required
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@433 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'algparam.h')
-rw-r--r-- | algparam.h | 75 |
1 files changed, 56 insertions, 19 deletions
@@ -245,7 +245,7 @@ CRYPTOPP_DLL extern PAssignIntToInteger g_pAssignIntToInteger; CRYPTOPP_DLL const std::type_info & CRYPTOPP_API IntegerTypeId(); -class CRYPTOPP_DLL AlgorithmParametersBase : public NameValuePairs +class CRYPTOPP_DLL AlgorithmParametersBase { public: class ParameterNotUsed : public Exception @@ -254,10 +254,18 @@ public: ParameterNotUsed(const char *name) : Exception(OTHER_ERROR, std::string("AlgorithmParametersBase: parameter \"") + name + "\" not used") {} }; + // this is actually a move, not a copy + AlgorithmParametersBase(const AlgorithmParametersBase &x) + : m_name(x.m_name), m_throwIfNotUsed(x.m_throwIfNotUsed), m_used(x.m_used) + { + m_next.reset(const_cast<AlgorithmParametersBase &>(x).m_next.release()); + x.m_used = true; + } + AlgorithmParametersBase(const char *name, bool throwIfNotUsed) : m_name(name), m_throwIfNotUsed(throwIfNotUsed), m_used(false) {} - ~AlgorithmParametersBase() + virtual ~AlgorithmParametersBase() { #ifdef CRYPTOPP_UNCAUGHT_EXCEPTION_AVAILABLE if (!std::uncaught_exception()) @@ -281,62 +289,91 @@ protected: friend class AlgorithmParameters; virtual void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const =0; + virtual void MoveInto(void *p) const =0; // not really const const char *m_name; bool m_throwIfNotUsed; mutable bool m_used; - member_ptr<NameValuePairs> m_next; + member_ptr<AlgorithmParametersBase> m_next; }; template <class T> class AlgorithmParametersTemplate : public AlgorithmParametersBase { public: - AlgorithmParametersTemplate(const char *name, const T &value, bool throwIfNotUsed) : AlgorithmParametersBase(name, throwIfNotUsed), m_value(value) {} + AlgorithmParametersTemplate(const char *name, const T &value, bool throwIfNotUsed) + : AlgorithmParametersBase(name, throwIfNotUsed), m_value(value) + { + } void AssignValue(const char *name, const std::type_info &valueType, void *pValue) const { // special case for retrieving an Integer parameter when an int was passed in if (!(g_pAssignIntToInteger != NULL && typeid(T) == typeid(int) && g_pAssignIntToInteger(valueType, pValue, &m_value))) { - ThrowIfTypeMismatch(name, typeid(T), valueType); + NameValuePairs::ThrowIfTypeMismatch(name, typeid(T), valueType); *reinterpret_cast<T *>(pValue) = m_value; } } + void MoveInto(void *buffer) const + { + AlgorithmParametersTemplate<T>* p = new(buffer) AlgorithmParametersTemplate<T>(*this); + } + protected: T m_value; }; -class AlgorithmParameters : public NameValuePairs +CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<bool>; +CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<int>; +CRYPTOPP_DLL_TEMPLATE_CLASS AlgorithmParametersTemplate<ConstByteArrayParameter>; + +class CRYPTOPP_DLL AlgorithmParameters : public NameValuePairs { public: - AlgorithmParameters(AlgorithmParameters &x) : m_ptr(x.m_ptr.release()) {} - - AlgorithmParameters(AlgorithmParametersBase *p) : m_ptr(p) {} - + AlgorithmParameters(); + + AlgorithmParameters(const AlgorithmParameters &x); + + ~AlgorithmParameters(); + template <class T> AlgorithmParameters & operator()(const char *name, const T &value, bool throwIfNotUsed) { - member_ptr<AlgorithmParametersBase> p(new AlgorithmParametersTemplate<T>(name, value, throwIfNotUsed)); - p->m_next.reset(m_ptr.release()); - m_ptr.reset(p.release()); + if (m_constructed || sizeof(m_first) < sizeof(AlgorithmParametersTemplate<T>)) + { + member_ptr<AlgorithmParametersBase> p(new AlgorithmParametersTemplate<T>(name, value, throwIfNotUsed)); + p->m_next.reset(Next().release()); + Next().reset(p.release()); + } + else + { + member_ptr<AlgorithmParametersBase> temp(Next().release()); + AlgorithmParametersTemplate<T>* p = new(m_first) AlgorithmParametersTemplate<T>(name, value, throwIfNotUsed); + p->m_next.reset(temp.release()); + m_constructed = true; + } + m_defaultThrowIfNotUsed = throwIfNotUsed; return *this; } template <class T> AlgorithmParameters & operator()(const char *name, const T &value) { - member_ptr<AlgorithmParametersBase> p(new AlgorithmParametersTemplate<T>(name, value, m_ptr->m_throwIfNotUsed)); - p->m_next.reset(m_ptr.release()); - m_ptr.reset(p.release()); - return *this; + return operator()(name, value, m_defaultThrowIfNotUsed); } bool GetVoidValue(const char *name, const std::type_info &valueType, void *pValue) const; protected: - member_ptr<AlgorithmParametersBase> m_ptr; + AlgorithmParametersBase & First(); + member_ptr<AlgorithmParametersBase> & Next(); + const AlgorithmParametersBase & First() const {return const_cast<AlgorithmParameters *>(this)->First();} + member_ptr<AlgorithmParametersBase> & Next() const {return const_cast<AlgorithmParameters *>(this)->Next();} + + bool m_constructed, m_defaultThrowIfNotUsed; + char m_first[sizeof(AlgorithmParametersBase) + 16]; }; //! Create an object that implements NameValuePairs for passing parameters @@ -350,7 +387,7 @@ protected: template <class T> AlgorithmParameters MakeParameters(const char *name, const T &value, bool throwIfNotUsed = true) { - return AlgorithmParameters(new AlgorithmParametersTemplate<T>(name, value, throwIfNotUsed)); + return AlgorithmParameters()(name, value, throwIfNotUsed); } #define CRYPTOPP_GET_FUNCTION_ENTRY(name) (Name::name(), &ThisClass::Get##name) |