aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/base.cpp76
-rw-r--r--src/core/base.h89
-rw-r--r--src/core/buf_comp.cpp86
-rw-r--r--src/core/buf_comp.h104
-rw-r--r--src/core/hash.h2
-rw-r--r--src/core/info.txt2
-rw-r--r--src/hash/mdx_hash/mdx_hash.cpp1
-rw-r--r--src/hash/tiger/tiger.cpp1
-rw-r--r--src/kdf/mgf1/mgf1.cpp1
-rw-r--r--src/kdf/ssl_prf/prf_ssl3.cpp2
-rw-r--r--src/mac/info.txt12
-rw-r--r--src/mac/mac.cpp24
-rw-r--r--src/mac/mac.h2
13 files changed, 236 insertions, 166 deletions
diff --git a/src/core/base.cpp b/src/core/base.cpp
index 4fdf9562d..ede199685 100644
--- a/src/core/base.cpp
+++ b/src/core/base.cpp
@@ -69,13 +69,6 @@ StreamCipher::StreamCipher(u32bit key_min, u32bit key_max, u32bit key_mod,
}
/*************************************************
-* BufferedComputation Constructor *
-*************************************************/
-BufferedComputation::BufferedComputation(u32bit olen) : OUTPUT_LENGTH(olen)
- {
- }
-
-/*************************************************
* Default StreamCipher Resync Operation *
*************************************************/
void StreamCipher::resync(const byte[], u32bit length)
@@ -93,73 +86,4 @@ void StreamCipher::seek(u32bit)
throw Exception("The stream cipher " + name() + " does not support seek()");
}
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-void BufferedComputation::update(const byte in[], u32bit n)
- {
- add_data(in, n);
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-void BufferedComputation::update(const MemoryRegion<byte>& in)
- {
- add_data(in, in.size());
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-void BufferedComputation::update(const std::string& str)
- {
- update(reinterpret_cast<const byte*>(str.data()), str.size());
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-void BufferedComputation::update(byte in)
- {
- update(&in, 1);
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-SecureVector<byte> BufferedComputation::final()
- {
- SecureVector<byte> output(OUTPUT_LENGTH);
- final_result(output);
- return output;
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-SecureVector<byte> BufferedComputation::process(const byte in[], u32bit len)
- {
- update(in, len);
- return final();
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-SecureVector<byte> BufferedComputation::process(const MemoryRegion<byte>& in)
- {
- update(in, in.size());
- return final();
- }
-
-/*************************************************
-* Hashing/MACing *
-*************************************************/
-SecureVector<byte> BufferedComputation::process(const std::string& in)
- {
- update(in);
- return final();
- }
-
}
diff --git a/src/core/base.h b/src/core/base.h
index 64186f903..b9be665b1 100644
--- a/src/core/base.h
+++ b/src/core/base.h
@@ -209,95 +209,6 @@ class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
virtual void cipher(const byte[], byte[], u32bit) = 0;
};
-/**
-* This class represents any kind of computation which
-* uses an internal state,
-* such as hash functions.
-*/
-class BOTAN_DLL BufferedComputation
- {
- public:
-
- /**
- * The length of the output of this function in bytes.
- */
- const u32bit OUTPUT_LENGTH;
-
- /**
- * Add new input to process.
- * @param in the input to process as a byte array
- * @param the length of the byte array
- */
- void update(const byte in[], u32bit length);
-
- /**
- * Add new input to process.
- * @param in the input to process as a MemoryRegion
- */
- void update(const MemoryRegion<byte>& in);
-
- /**
- * Add new input to process.
- * @param in 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&);
-
- /**
- * Process a single byte.
- * @param in the byte to process
- */
- void update(byte in);
-
- /**
- * 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 a SecureVector holding the result
- */
- SecureVector<byte> final();
-
- /**
- * 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()
- */
- SecureVector<byte> process(const byte in[], u32bit length);
-
- /**
- * 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()
- */
- SecureVector<byte> process(const MemoryRegion<byte>& in);
-
- /**
- * 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()
- */
- SecureVector<byte> process(const std::string& in);
-
- BufferedComputation(u32bit);
- virtual ~BufferedComputation() {}
- private:
- BufferedComputation& operator=(const BufferedComputation&);
- virtual void add_data(const byte[], u32bit) = 0;
- virtual void final_result(byte[]) = 0;
- };
-
}
#endif
diff --git a/src/core/buf_comp.cpp b/src/core/buf_comp.cpp
new file mode 100644
index 000000000..1611d6ab5
--- /dev/null
+++ b/src/core/buf_comp.cpp
@@ -0,0 +1,86 @@
+/**
+* BufferedComputation
+* (C) 1999-2007 Jack Lloyd
+*/
+
+#include <botan/buf_comp.h>
+
+namespace Botan {
+
+/*************************************************
+* BufferedComputation Constructor *
+*************************************************/
+BufferedComputation::BufferedComputation(u32bit olen) : OUTPUT_LENGTH(olen)
+ {
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+void BufferedComputation::update(const byte in[], u32bit n)
+ {
+ add_data(in, n);
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+void BufferedComputation::update(const MemoryRegion<byte>& in)
+ {
+ add_data(in, in.size());
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+void BufferedComputation::update(const std::string& str)
+ {
+ update(reinterpret_cast<const byte*>(str.data()), str.size());
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+void BufferedComputation::update(byte in)
+ {
+ update(&in, 1);
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+SecureVector<byte> BufferedComputation::final()
+ {
+ SecureVector<byte> output(OUTPUT_LENGTH);
+ final_result(output);
+ return output;
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+SecureVector<byte> BufferedComputation::process(const byte in[], u32bit len)
+ {
+ update(in, len);
+ return final();
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+SecureVector<byte> BufferedComputation::process(const MemoryRegion<byte>& in)
+ {
+ update(in, in.size());
+ return final();
+ }
+
+/*************************************************
+* Hashing/MACing *
+*************************************************/
+SecureVector<byte> BufferedComputation::process(const std::string& in)
+ {
+ update(in);
+ return final();
+ }
+
+}
diff --git a/src/core/buf_comp.h b/src/core/buf_comp.h
new file mode 100644
index 000000000..dd7430c50
--- /dev/null
+++ b/src/core/buf_comp.h
@@ -0,0 +1,104 @@
+/**
+* BufferedComputation
+* (C) 1999-2007 Jack Lloyd
+*/
+
+#ifndef BOTAN_BUFFERED_COMPUTATION_H__
+#define BOTAN_BUFFERED_COMPUTATION_H__
+
+#include <botan/secmem.h>
+
+namespace Botan {
+
+/**
+* This class represents any kind of computation which
+* uses an internal state,
+* such as hash functions.
+*/
+class BOTAN_DLL BufferedComputation
+ {
+ public:
+
+ /**
+ * The length of the output of this function in bytes.
+ */
+ const u32bit OUTPUT_LENGTH;
+
+ /**
+ * Add new input to process.
+ * @param in the input to process as a byte array
+ * @param the length of the byte array
+ */
+ void update(const byte in[], u32bit length);
+
+ /**
+ * Add new input to process.
+ * @param in the input to process as a MemoryRegion
+ */
+ void update(const MemoryRegion<byte>& in);
+
+ /**
+ * Add new input to process.
+ * @param in 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&);
+
+ /**
+ * Process a single byte.
+ * @param in the byte to process
+ */
+ void update(byte in);
+
+ /**
+ * 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 a SecureVector holding the result
+ */
+ SecureVector<byte> final();
+
+ /**
+ * 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()
+ */
+ SecureVector<byte> process(const byte in[], u32bit length);
+
+ /**
+ * 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()
+ */
+ SecureVector<byte> process(const MemoryRegion<byte>& in);
+
+ /**
+ * 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()
+ */
+ SecureVector<byte> process(const std::string& in);
+
+ BufferedComputation(u32bit);
+ virtual ~BufferedComputation() {}
+ private:
+ BufferedComputation& operator=(const BufferedComputation&);
+ virtual void add_data(const byte[], u32bit) = 0;
+ virtual void final_result(byte[]) = 0;
+ };
+
+}
+
+#endif
diff --git a/src/core/hash.h b/src/core/hash.h
index 9d4013b75..d42ee0d82 100644
--- a/src/core/hash.h
+++ b/src/core/hash.h
@@ -7,7 +7,7 @@
#define BOTAN_HASH_FUNCTION_BASE_CLASS_H__
#include <botan/types.h>
-#include <botan/base.h>
+#include <botan/buf_comp.h>
#include <string>
namespace Botan {
diff --git a/src/core/info.txt b/src/core/info.txt
index 34705048b..f40148dd9 100644
--- a/src/core/info.txt
+++ b/src/core/info.txt
@@ -19,6 +19,8 @@ base.cpp
base.h
botan.h
data_src.cpp
+buf_comp.h
+buf_comp.cpp
data_src.h
defalloc.cpp
defalloc.h
diff --git a/src/hash/mdx_hash/mdx_hash.cpp b/src/hash/mdx_hash/mdx_hash.cpp
index 96b885d87..0d88afba1 100644
--- a/src/hash/mdx_hash/mdx_hash.cpp
+++ b/src/hash/mdx_hash/mdx_hash.cpp
@@ -4,6 +4,7 @@
*************************************************/
#include <botan/mdx_hash.h>
+#include <botan/exceptn.h>
#include <botan/loadstor.h>
namespace Botan {
diff --git a/src/hash/tiger/tiger.cpp b/src/hash/tiger/tiger.cpp
index 78bba0521..055819dbd 100644
--- a/src/hash/tiger/tiger.cpp
+++ b/src/hash/tiger/tiger.cpp
@@ -4,6 +4,7 @@
*************************************************/
#include <botan/tiger.h>
+#include <botan/exceptn.h>
#include <botan/loadstor.h>
#include <botan/parsing.h>
diff --git a/src/kdf/mgf1/mgf1.cpp b/src/kdf/mgf1/mgf1.cpp
index c2cda7f4c..c54675c1e 100644
--- a/src/kdf/mgf1/mgf1.cpp
+++ b/src/kdf/mgf1/mgf1.cpp
@@ -5,6 +5,7 @@
#include <botan/mgf1.h>
#include <botan/loadstor.h>
+#include <botan/exceptn.h>
#include <botan/xor_buf.h>
#include <algorithm>
#include <memory>
diff --git a/src/kdf/ssl_prf/prf_ssl3.cpp b/src/kdf/ssl_prf/prf_ssl3.cpp
index 29c29ba7e..3d4444613 100644
--- a/src/kdf/ssl_prf/prf_ssl3.cpp
+++ b/src/kdf/ssl_prf/prf_ssl3.cpp
@@ -4,6 +4,8 @@
*************************************************/
#include <botan/prf_ssl3.h>
+#include <botan/symkey.h>
+#include <botan/exceptn.h>
#include <botan/sha160.h>
#include <botan/md5.h>
#include <memory>
diff --git a/src/mac/info.txt b/src/mac/info.txt
new file mode 100644
index 000000000..0e4dc11a2
--- /dev/null
+++ b/src/mac/info.txt
@@ -0,0 +1,12 @@
+realname "Message Authentication Codes"
+
+load_on auto
+
+<requires>
+utils
+</requires>
+
+<add>
+mac.h
+mac.cpp
+</add>
diff --git a/src/mac/mac.cpp b/src/mac/mac.cpp
new file mode 100644
index 000000000..63be1ea17
--- /dev/null
+++ b/src/mac/mac.cpp
@@ -0,0 +1,24 @@
+/**
+Message Authentication Code base class
+(C) 1999-2008 Jack Lloyd
+*/
+
+#include <botan/mac.h>
+
+namespace Botan {
+
+/**
+* Default (deterministic) MAC verification operation
+*/
+bool MessageAuthenticationCode::verify_mac(const byte mac[], u32bit length)
+ {
+ SecureVector<byte> our_mac = final();
+ if(our_mac.size() != length)
+ return false;
+ for(u32bit j = 0; j != length; ++j)
+ if(mac[j] != our_mac[j])
+ return false;
+ return true;
+ }
+
+}
diff --git a/src/mac/mac.h b/src/mac/mac.h
index e7bdada14..99184fd3f 100644
--- a/src/mac/mac.h
+++ b/src/mac/mac.h
@@ -6,7 +6,9 @@
#ifndef BOTAN_MESSAGE_AUTH_CODE_BASE_H__
#define BOTAN_MESSAGE_AUTH_CODE_BASE_H__
+#include <botan/buf_comp.h>
#include <botan/base.h>
+#include <string>
namespace Botan {