aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/base/buf_comp.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2015-02-04 04:03:38 +0000
committerlloyd <[email protected]>2015-02-04 04:03:38 +0000
commit0dd060fed07b0060f94e3bae62e125a85c1bb877 (patch)
treeed4bc7a961e2b30f17ed5e80769c84b0c313c8b7 /src/lib/base/buf_comp.h
parentf9a7c85b74be0f4a7273e8e0591703af83036e81 (diff)
Remove algo factory, engines, global RNG, global state, etc.
Convert all uses of Algorithm_Factory and the engines to using Algo_Registry The shared pool of entropy sources remains but is moved to EntropySource. With that and few remaining initializations (default OIDs and aliases) moved elsewhere, the global state is empty and init and shutdown are no-ops. Remove almost all of the headers and code for handling the global state, except LibraryInitializer which remains as a compatability stub. Update seeding for blinding so only one hacky almost-global RNG instance needs to be setup instead of across all pubkey uses (it uses either the system RNG or an AutoSeeded_RNG if the system RNG is not available).
Diffstat (limited to 'src/lib/base/buf_comp.h')
-rw-r--r--src/lib/base/buf_comp.h171
1 files changed, 171 insertions, 0 deletions
diff --git a/src/lib/base/buf_comp.h b/src/lib/base/buf_comp.h
new file mode 100644
index 000000000..5d11fdb73
--- /dev/null
+++ b/src/lib/base/buf_comp.h
@@ -0,0 +1,171 @@
+/*
+* Buffered Computation
+* (C) 1999-2007 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#ifndef BOTAN_BUFFERED_COMPUTATION_H__
+#define BOTAN_BUFFERED_COMPUTATION_H__
+
+#include <botan/secmem.h>
+#include <botan/get_byte.h>
+#include <string>
+
+namespace Botan {
+
+/**
+* This class represents any kind of computation which uses an internal
+* state, such as hash functions or MACs
+*/
+class BOTAN_DLL Buffered_Computation
+ {
+ public:
+ /**
+ * @return length of the output of this function in bytes
+ */
+ virtual size_t output_length() const = 0;
+
+ /**
+ * Add new input to process.
+ * @param in the input to process as a byte array
+ * @param length of param in in bytes
+ */
+ void update(const byte in[], size_t length) { add_data(in, length); }
+
+ /**
+ * Add new input to process.
+ * @param in the input to process as a secure_vector
+ */
+ void update(const secure_vector<byte>& in)
+ {
+ add_data(&in[0], in.size());
+ }
+
+ /**
+ * Add new input to process.
+ * @param in the input to process as a std::vector
+ */
+ void update(const std::vector<byte>& in)
+ {
+ add_data(&in[0], in.size());
+ }
+
+ /**
+ * Add an integer in big-endian order
+ * @param in the value
+ */
+ template<typename T> void update_be(const T in)
+ {
+ for(size_t i = 0; i != sizeof(T); ++i)
+ {
+ byte b = get_byte(i, in);
+ add_data(&b, 1);
+ }
+ }
+
+ /**
+ * Add new input to process.
+ * @param str the input to process as a std::string. Will be interpreted
+ * as a byte array based on
+ * the strings encoding.
+ */
+ void update(const std::string& str)
+ {
+ add_data(reinterpret_cast<const byte*>(str.data()), str.size());
+ }
+
+ /**
+ * Process a single byte.
+ * @param in the byte to process
+ */
+ void update(byte in) { add_data(&in, 1); }
+
+ /**
+ * Complete the computation and retrieve the
+ * final result.
+ * @param out The byte array to be filled with the result.
+ * Must be of length output_length()
+ */
+ void final(byte out[]) { final_result(out); }
+
+ /**
+ * Complete the computation and retrieve the
+ * final result.
+ * @return secure_vector holding the result
+ */
+ secure_vector<byte> final()
+ {
+ secure_vector<byte> output(output_length());
+ final_result(&output[0]);
+ return output;
+ }
+
+ /**
+ * Update and finalize computation. Does the same as calling update()
+ * and final() consecutively.
+ * @param in the input to process as a byte array
+ * @param length the length of the byte array
+ * @result the result of the call to final()
+ */
+ secure_vector<byte> process(const byte in[], size_t length)
+ {
+ add_data(in, length);
+ return final();
+ }
+
+ /**
+ * Update and finalize computation. Does the same as calling update()
+ * and final() consecutively.
+ * @param in the input to process
+ * @result the result of the call to final()
+ */
+ secure_vector<byte> process(const secure_vector<byte>& in)
+ {
+ add_data(&in[0], in.size());
+ return final();
+ }
+
+ /**
+ * Update and finalize computation. Does the same as calling update()
+ * and final() consecutively.
+ * @param in the input to process
+ * @result the result of the call to final()
+ */
+ secure_vector<byte> process(const std::vector<byte>& in)
+ {
+ add_data(&in[0], in.size());
+ return final();
+ }
+
+ /**
+ * Update and finalize computation. Does the same as calling update()
+ * and final() consecutively.
+ * @param in the input to process as a string
+ * @result the result of the call to final()
+ */
+ secure_vector<byte> process(const std::string& in)
+ {
+ update(in);
+ return final();
+ }
+
+ virtual ~Buffered_Computation() {}
+ private:
+ /**
+ * Add more data to the computation
+ * @param input is an input buffer
+ * @param length is the length of input in bytes
+ */
+ virtual void add_data(const byte input[], size_t length) = 0;
+
+ /**
+ * Write the final output to out
+ * @param out is an output buffer of output_length()
+ */
+ virtual void final_result(byte out[]) = 0;
+ };
+
+}
+
+#endif