aboutsummaryrefslogtreecommitdiffstats
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/block_cipher.h (renamed from src/core/base.h)12
-rw-r--r--src/core/data_src.cpp2
-rw-r--r--src/core/data_src.h3
-rw-r--r--src/core/info.txt2
-rw-r--r--src/core/stream_cipher.h92
-rw-r--r--src/core/sym_algo.h93
6 files changed, 196 insertions, 8 deletions
diff --git a/src/core/base.h b/src/core/block_cipher.h
index 8e4341713..1a4302581 100644
--- a/src/core/base.h
+++ b/src/core/block_cipher.h
@@ -1,10 +1,10 @@
-/*************************************************
-* Base Classes Header File *
-* (C) 1999-2007 Jack Lloyd *
-*************************************************/
+/**
+* Block Cipher Base Class
+* (C) 1999-2007 Jack Lloyd
+*/
-#ifndef BOTAN_BASE_H__
-#define BOTAN_BASE_H__
+#ifndef BOTAN_BLOCK_CIPHER__
+#define BOTAN_BLOCK_CIPHER__
#include <botan/exceptn.h>
#include <botan/symkey.h>
diff --git a/src/core/data_src.cpp b/src/core/data_src.cpp
index 1ec1ae090..de5544885 100644
--- a/src/core/data_src.cpp
+++ b/src/core/data_src.cpp
@@ -5,6 +5,8 @@
*************************************************/
#include <botan/data_src.h>
+#include <botan/exceptn.h>
+
#include <fstream>
#include <algorithm>
diff --git a/src/core/data_src.h b/src/core/data_src.h
index d250addfc..25bdce00f 100644
--- a/src/core/data_src.h
+++ b/src/core/data_src.h
@@ -6,7 +6,8 @@
#ifndef BOTAN_DATA_SRC_H__
#define BOTAN_DATA_SRC_H__
-#include <botan/base.h>
+#include <botan/secmem.h>
+#include <string>
#include <iosfwd>
namespace Botan {
diff --git a/src/core/info.txt b/src/core/info.txt
index fd62867e0..c5276ce46 100644
--- a/src/core/info.txt
+++ b/src/core/info.txt
@@ -15,7 +15,7 @@ timer
<add>
allocate.h
-base.h
+block_cipher.h
botan.h
data_src.cpp
buf_comp.h
diff --git a/src/core/stream_cipher.h b/src/core/stream_cipher.h
new file mode 100644
index 000000000..6c013c6d6
--- /dev/null
+++ b/src/core/stream_cipher.h
@@ -0,0 +1,92 @@
+/**
+* Stream Cipher
+* (C) 1999-2007 Jack Lloyd
+*/
+
+#ifndef BOTAN_STREAM_CIPHER_H__
+#define BOTAN_STREAM_CIPHER_H__
+
+#include <botan/exceptn.h>
+#include <botan/symkey.h>
+#include <botan/sym_algo.h>
+
+namespace Botan {
+
+/*************************************************
+* Stream Cipher *
+*************************************************/
+class BOTAN_DLL StreamCipher : public SymmetricAlgorithm
+ {
+ public:
+ const u32bit IV_LENGTH;
+
+ /**
+ * Encrypt a message.
+ * @param i the plaintext
+ * @param o the byte array to hold the output, i.e. the ciphertext
+ * @param len the length of both i and o
+ */
+ void encrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); }
+
+ /**
+ * Decrypt a message.
+ * @param i the ciphertext to decrypt
+ * @param o the byte array to hold the output, i.e. the plaintext
+ * @param len the length of both i and o
+ */
+ void decrypt(const byte i[], byte o[], u32bit len) { cipher(i, o, len); }
+
+ /**
+ * Encrypt a message.
+ * @param in the plaintext as input, after the function has
+ * returned it will hold the ciphertext
+
+ * @param len the length of in
+ */
+ void encrypt(byte in[], u32bit len) { cipher(in, in, len); }
+
+ /**
+ * Decrypt a message.
+ * @param in the ciphertext as input, after the function has
+ * returned it will hold the plaintext
+ * @param len the length of in
+ */
+ void decrypt(byte in[], u32bit len) { cipher(in, in, len); }
+
+ /**
+ * Resync the cipher using the IV
+ * @param iv the initialization vector
+ * @param iv_len the length of the IV in bytes
+ */
+ virtual void resync(const byte iv[], u32bit iv_len);
+
+ /**
+ * Seek ahead in the stream.
+ * @param len the length to seek ahead.
+ */
+ virtual void seek(u32bit len);
+
+ /**
+ * Get a new object representing the same algorithm as *this
+ */
+ virtual StreamCipher* clone() const = 0;
+
+ /**
+ * Zeroize internal state
+ */
+ virtual void clear() throw() = 0;
+
+ StreamCipher(u32bit key_min, u32bit key_max = 0,
+ u32bit key_mod = 1,
+ u32bit iv_len = 0) :
+ SymmetricAlgorithm(key_min, key_max, key_mod),
+ IV_LENGTH(iv_len) {}
+
+ virtual ~StreamCipher() {}
+ private:
+ virtual void cipher(const byte[], byte[], u32bit) = 0;
+ };
+
+}
+
+#endif
diff --git a/src/core/sym_algo.h b/src/core/sym_algo.h
new file mode 100644
index 000000000..02343ed56
--- /dev/null
+++ b/src/core/sym_algo.h
@@ -0,0 +1,93 @@
+/**
+* Symmetric Algorithm Base Class
+* (C) 1999-2007 Jack Lloyd
+*/
+
+#ifndef BOTAN_SYMMETRIC_ALGORITHM_H__
+#define BOTAN_SYMMETRIC_ALGORITHM_H__
+
+#include <botan/types.h>
+#include <botan/exceptn.h>
+#include <botan/symkey.h>
+
+namespace Botan {
+
+/**
+* This class represents a symmetric algorithm object.
+*/
+class BOTAN_DLL SymmetricAlgorithm
+ {
+ public:
+
+ /**
+ * The maximum allowed key length.
+ */
+ const u32bit MAXIMUM_KEYLENGTH;
+
+ /**
+ * The minimal allowed key length.
+ */
+ const u32bit MINIMUM_KEYLENGTH;
+
+ /**
+ * A valid keylength is a multiple of this value.
+ */
+ const u32bit KEYLENGTH_MULTIPLE;
+
+ /**
+ * The name of the algorithm.
+ * @return the name of the algorithm
+ */
+ virtual std::string name() const = 0;
+
+ /**
+ * Set the symmetric key of this object.
+ * @param key the SymmetricKey to be set.
+ */
+ void set_key(const SymmetricKey& skey) throw(Invalid_Key_Length)
+ { set_key(skey.begin(), skey.length()); }
+
+ /**
+ * Set the symmetric key of this object.
+ * @param key the to be set as a byte array.
+ * @param the length of the byte array.
+ */
+ void set_key(const byte skey[], u32bit length) throw(Invalid_Key_Length)
+ {
+ if(!valid_keylength(length))
+ throw Invalid_Key_Length(name(), length);
+ key(skey, length);
+ }
+
+ /**
+ * Check whether a given key length is valid for this algorithm.
+ * @param length the key length to be checked.
+ * @return true if the key length is valid.
+ */
+ bool valid_keylength(u32bit length) const
+ {
+ return ((length >= MINIMUM_KEYLENGTH) &&
+ (length <= MAXIMUM_KEYLENGTH) &&
+ (length % KEYLENGTH_MULTIPLE == 0));
+ }
+
+ /**
+ * Construct a SymmetricAlgorithm.
+ * @param key_min the minimum allowed key length
+ * @param key_max the maximum allowed key length
+ * @param key_mod any valid key length must be a multiple of this value
+ */
+ SymmetricAlgorithm(u32bit key_min, u32bit key_max, u32bit key_mod) :
+ MAXIMUM_KEYLENGTH(key_max ? key_max : key_min),
+ MINIMUM_KEYLENGTH(key_min),
+ KEYLENGTH_MULTIPLE(key_mod)
+ {}
+
+ virtual ~SymmetricAlgorithm() {}
+ private:
+ virtual void key(const byte[], u32bit) = 0;
+ };
+
+}
+
+#endif