summaryrefslogtreecommitdiffstats
path: root/cryptopp562/factory.h
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2024-10-24 06:44:24 -0400
committerMalfurious <m@lfurio.us>2024-10-24 06:44:24 -0400
commit512aa4c77b3dc0d72db713a9215ff65a98a99ec3 (patch)
tree6db82e0109dc987b5b021f81d4e8a0926eb75ff7 /cryptopp562/factory.h
parent428471d39fb8c205a9fad899c88c30a2cb7df685 (diff)
parent10affea371406c0ae4c080e5a19390a8e9bd154b (diff)
downloadcompass-512aa4c77b3dc0d72db713a9215ff65a98a99ec3.tar.gz
compass-512aa4c77b3dc0d72db713a9215ff65a98a99ec3.zip
Merge branch 'mbedtls'
Replace Crypto++ 5.6.2 with Mbed TLS 3.6.0 Newer compilers are starting to show the age of the crypto library we've been using, as it is sometimes a pain to recompile compass lately. So, the tracked version of Crypto++ was at least due for an upgrade. However, I plan to soon begin reimplementing compass in C. So, I'm taking this opportunity to first just migrate the cryptography library to a newer C alternative. This branch does so, and integrates its use into the current C++ version of compass. * mbedtls: Remove unnecessary exception handler catch block Refactor random password generation to use mbedtls entropy source Refactor SHA256 function to use mbedtls Refactor AES functions to use mbedtls Add Mbedtls library Remove Crypto++ library
Diffstat (limited to '')
-rw-r--r--cryptopp562/factory.h136
1 files changed, 0 insertions, 136 deletions
diff --git a/cryptopp562/factory.h b/cryptopp562/factory.h
deleted file mode 100644
index 5b65db3..0000000
--- a/cryptopp562/factory.h
+++ /dev/null
@@ -1,136 +0,0 @@
-#ifndef CRYPTOPP_OBJFACT_H
-#define CRYPTOPP_OBJFACT_H
-
-#include "cryptlib.h"
-#include <map>
-#include <vector>
-
-NAMESPACE_BEGIN(CryptoPP)
-
-//! _
-template <class AbstractClass>
-class ObjectFactory
-{
-public:
- virtual ~ObjectFactory () {}
- virtual AbstractClass * CreateObject() const =0;
-};
-
-//! _
-template <class AbstractClass, class ConcreteClass>
-class DefaultObjectFactory : public ObjectFactory<AbstractClass>
-{
-public:
- AbstractClass * CreateObject() const
- {
- return new ConcreteClass;
- }
-
-};
-
-//! _
-template <class AbstractClass, int instance=0>
-class ObjectFactoryRegistry
-{
-public:
- class FactoryNotFound : public Exception
- {
- public:
- FactoryNotFound(const char *name) : Exception(OTHER_ERROR, std::string("ObjectFactoryRegistry: could not find factory for algorithm ") + name) {}
- };
-
- ~ObjectFactoryRegistry()
- {
- for (CPP_TYPENAME Map::iterator i = m_map.begin(); i != m_map.end(); ++i)
- {
- delete (ObjectFactory<AbstractClass> *)i->second;
- i->second = NULL;
- }
- }
-
- void RegisterFactory(const std::string &name, ObjectFactory<AbstractClass> *factory)
- {
- m_map[name] = factory;
- }
-
- const ObjectFactory<AbstractClass> * GetFactory(const char *name) const
- {
- CPP_TYPENAME Map::const_iterator i = m_map.find(name);
- return i == m_map.end() ? NULL : (ObjectFactory<AbstractClass> *)i->second;
- }
-
- AbstractClass *CreateObject(const char *name) const
- {
- const ObjectFactory<AbstractClass> *factory = GetFactory(name);
- if (!factory)
- throw FactoryNotFound(name);
- return factory->CreateObject();
- }
-
- // Return a vector containing the factory names. This is easier than returning an iterator.
- // from Andrew Pitonyak
- std::vector<std::string> GetFactoryNames() const
- {
- std::vector<std::string> names;
- CPP_TYPENAME Map::const_iterator iter;
- for (iter = m_map.begin(); iter != m_map.end(); ++iter)
- names.push_back(iter->first);
- return names;
- }
-
- CRYPTOPP_NOINLINE static ObjectFactoryRegistry<AbstractClass, instance> & Registry(CRYPTOPP_NOINLINE_DOTDOTDOT);
-
-private:
- // use void * instead of ObjectFactory<AbstractClass> * to save code size
- typedef std::map<std::string, void *> Map;
- Map m_map;
-};
-
-template <class AbstractClass, int instance>
-ObjectFactoryRegistry<AbstractClass, instance> & ObjectFactoryRegistry<AbstractClass, instance>::Registry(CRYPTOPP_NOINLINE_DOTDOTDOT)
-{
- static ObjectFactoryRegistry<AbstractClass, instance> s_registry;
- return s_registry;
-}
-
-template <class AbstractClass, class ConcreteClass, int instance = 0>
-struct RegisterDefaultFactoryFor {
-RegisterDefaultFactoryFor(const char *name=NULL)
-{
- // BCB2006 workaround
- std::string n = name ? std::string(name) : std::string(ConcreteClass::StaticAlgorithmName());
- ObjectFactoryRegistry<AbstractClass, instance>::Registry().
- RegisterFactory(n, new DefaultObjectFactory<AbstractClass, ConcreteClass>);
-}};
-
-template <class SchemeClass>
-void RegisterAsymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL)
-{
- RegisterDefaultFactoryFor<PK_Encryptor, CPP_TYPENAME SchemeClass::Encryptor>((const char *)name);
- RegisterDefaultFactoryFor<PK_Decryptor, CPP_TYPENAME SchemeClass::Decryptor>((const char *)name);
-}
-
-template <class SchemeClass>
-void RegisterSignatureSchemeDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL)
-{
- RegisterDefaultFactoryFor<PK_Signer, CPP_TYPENAME SchemeClass::Signer>((const char *)name);
- RegisterDefaultFactoryFor<PK_Verifier, CPP_TYPENAME SchemeClass::Verifier>((const char *)name);
-}
-
-template <class SchemeClass>
-void RegisterSymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL)
-{
- RegisterDefaultFactoryFor<SymmetricCipher, CPP_TYPENAME SchemeClass::Encryption, ENCRYPTION>((const char *)name);
- RegisterDefaultFactoryFor<SymmetricCipher, CPP_TYPENAME SchemeClass::Decryption, DECRYPTION>((const char *)name);
-}
-
-template <class SchemeClass>
-void RegisterAuthenticatedSymmetricCipherDefaultFactories(const char *name=NULL, SchemeClass *dummy=NULL)
-{
- RegisterDefaultFactoryFor<AuthenticatedSymmetricCipher, CPP_TYPENAME SchemeClass::Encryption, ENCRYPTION>((const char *)name);
- RegisterDefaultFactoryFor<AuthenticatedSymmetricCipher, CPP_TYPENAME SchemeClass::Decryption, DECRYPTION>((const char *)name);
-}
-
-NAMESPACE_END
-
-#endif