diff --git a/src/factoryof.h b/src/factoryof.h
new file mode 100644
index 0000000..98b764a
--- /dev/null
+++ b/src/factoryof.h
@@ -0,0 +1,83 @@
+
+/*
+ * This file is part of Codecrypt.
+ *
+ * Codecrypt is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Codecrypt is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Codecrypt. If not, see .
+ */
+
+#ifndef _ccr_factoryof_h_
+#define _ccr_factoryof_h_
+
+/*
+ * This is a generic tool for safe spawning of instances of various derived
+ * ciphers on the fly.
+ */
+
+template
+class instanceof
+{
+ base_type*ptr;
+ bool deletable;
+public:
+ base_type& operator*() {
+ return *ptr;
+ }
+ const base_type& operator*() const {
+ return *ptr;
+ }
+
+ base_type* operator->() {
+ return ptr;
+ }
+ const base_type* operator->() const {
+ return ptr;
+ }
+
+ instanceof (base_type*p) : ptr (p), deletable (false) {}
+ instanceof (const instanceof&x) : ptr (x.ptr), deletable (false) {}
+ instanceof () {
+ deletable = false;
+ }
+
+ void collect() {
+ deletable = true;
+ }
+ void forget() {
+ deletable = false;
+ }
+
+ ~instanceof() {
+ if (deletable) delete ptr;
+ }
+};
+
+template class factoryof;
+
+template
+class factoryof : public factoryof
+{
+public:
+ base_type* get() {
+ return new derived_type;
+ }
+};
+
+template
+class factoryof
+{
+public:
+ virtual base_type* get() = 0;
+};
+
+#endif
diff --git a/src/hash.cpp b/src/hash.cpp
new file mode 100644
index 0000000..e62d5c6
--- /dev/null
+++ b/src/hash.cpp
@@ -0,0 +1,43 @@
+
+/*
+ * This file is part of Codecrypt.
+ *
+ * Codecrypt is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or (at
+ * your option) any later version.
+ *
+ * Codecrypt is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Codecrypt. If not, see .
+ */
+
+#include "hash.h"
+
+#include "sha_hash.h"
+#include "rmd_hash.h"
+#include "tiger_hash.h"
+#include "cube_hash.h"
+
+hash_proc::suite_t& hash_proc::suite()
+{
+ static suite_t s;
+
+#define do_hash(name,type) \
+ static factoryof type##_var; \
+ s[name]=&type##_var;
+
+ if (s.empty() ) {
+ do_hash ("CUBE512", cube512proc);
+ do_hash ("RIPEMD128", rmd128proc);
+ do_hash ("TIGER192", tiger192proc);
+ do_hash ("SHA256", sha256proc);
+ do_hash ("SHA512", sha512proc);
+ }
+
+ return s;
+}
diff --git a/src/hash.h b/src/hash.h
index ccb8298..2a49cfa 100644
--- a/src/hash.h
+++ b/src/hash.h
@@ -20,7 +20,10 @@
#define _ccr_hash_h_
#include
+#include
+#include