aboutsummaryrefslogtreecommitdiffstats
path: root/src/block/lion
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-08 19:46:52 +0000
committerlloyd <[email protected]>2008-11-08 19:46:52 +0000
commitf1c459725da56fd8ed5766e7779300182fa26bcf (patch)
tree32295cec92df1155563ae8a535dc695d6800d7f6 /src/block/lion
parent8dba7b5264403e781bbb86ff61850e4377dca7b9 (diff)
Split ciphers into block and stream ciphers. Move base class headers
Diffstat (limited to 'src/block/lion')
-rw-r--r--src/block/lion/info.txt10
-rw-r--r--src/block/lion/lion.cpp112
-rw-r--r--src/block/lion/lion.h41
3 files changed, 163 insertions, 0 deletions
diff --git a/src/block/lion/info.txt b/src/block/lion/info.txt
new file mode 100644
index 000000000..558d71d0c
--- /dev/null
+++ b/src/block/lion/info.txt
@@ -0,0 +1,10 @@
+realname "Lion"
+
+define LION
+
+load_on auto
+
+<add>
+lion.cpp
+lion.h
+</add>
diff --git a/src/block/lion/lion.cpp b/src/block/lion/lion.cpp
new file mode 100644
index 000000000..629badd3d
--- /dev/null
+++ b/src/block/lion/lion.cpp
@@ -0,0 +1,112 @@
+/*************************************************
+* Lion Source File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#include <botan/lion.h>
+#include <botan/xor_buf.h>
+#include <botan/parsing.h>
+
+namespace Botan {
+
+/*************************************************
+* Lion Encryption *
+*************************************************/
+void Lion::enc(const byte in[], byte out[]) const
+ {
+ SecureVector<byte> buffer(LEFT_SIZE);
+
+ xor_buf(buffer, in, key1, LEFT_SIZE);
+ cipher->set_key(buffer, LEFT_SIZE);
+ cipher->encrypt(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
+
+ hash->update(out + LEFT_SIZE, RIGHT_SIZE);
+ hash->final(buffer);
+ xor_buf(out, in, buffer, LEFT_SIZE);
+
+ xor_buf(buffer, out, key2, LEFT_SIZE);
+ cipher->set_key(buffer, LEFT_SIZE);
+ cipher->encrypt(out + LEFT_SIZE, RIGHT_SIZE);
+ }
+
+/*************************************************
+* Lion Decryption *
+*************************************************/
+void Lion::dec(const byte in[], byte out[]) const
+ {
+ SecureVector<byte> buffer(LEFT_SIZE);
+
+ xor_buf(buffer, in, key2, LEFT_SIZE);
+ cipher->set_key(buffer, LEFT_SIZE);
+ cipher->encrypt(in + LEFT_SIZE, out + LEFT_SIZE, RIGHT_SIZE);
+
+ hash->update(out + LEFT_SIZE, RIGHT_SIZE);
+ hash->final(buffer);
+ xor_buf(out, in, buffer, LEFT_SIZE);
+
+ xor_buf(buffer, out, key1, LEFT_SIZE);
+ cipher->set_key(buffer, LEFT_SIZE);
+ cipher->encrypt(out + LEFT_SIZE, RIGHT_SIZE);
+ }
+
+/*************************************************
+* Lion Key Schedule *
+*************************************************/
+void Lion::key(const byte key[], u32bit length)
+ {
+ clear();
+
+ key1.copy(key, length / 2);
+ key2.copy(key + length / 2, length / 2);
+ }
+
+/*************************************************
+* Return the name of this type *
+*************************************************/
+std::string Lion::name() const
+ {
+ return "Lion(" + hash->name() + "," +
+ cipher->name() + "," +
+ to_string(BLOCK_SIZE) + ")";
+ }
+
+/*************************************************
+* Return a clone of this object *
+*************************************************/
+BlockCipher* Lion::clone() const
+ {
+ return new Lion(hash->clone(), cipher->clone(), BLOCK_SIZE);
+ }
+
+/*************************************************
+* Clear memory of sensitive data *
+*************************************************/
+void Lion::clear() throw()
+ {
+ hash->clear();
+ cipher->clear();
+ key1.clear();
+ key2.clear();
+ }
+
+/*************************************************
+* Lion Constructor *
+*************************************************/
+Lion::Lion(HashFunction* hash_in, StreamCipher* sc_in, u32bit block_len) :
+ BlockCipher(std::max<u32bit>(2*hash_in->OUTPUT_LENGTH + 1, block_len),
+ 2, 2*hash_in->OUTPUT_LENGTH, 2),
+ LEFT_SIZE(hash_in->OUTPUT_LENGTH),
+ RIGHT_SIZE(BLOCK_SIZE - LEFT_SIZE),
+ hash(hash_in),
+ cipher(sc_in)
+ {
+ if(2*LEFT_SIZE + 1 > BLOCK_SIZE)
+ throw Invalid_Argument(name() + ": Chosen block size is too small");
+ if(!cipher->valid_keylength(LEFT_SIZE))
+ throw Exception(name() + ": This stream/hash combination is invalid");
+
+ key1.create(LEFT_SIZE);
+ key2.create(LEFT_SIZE);
+ }
+
+}
diff --git a/src/block/lion/lion.h b/src/block/lion/lion.h
new file mode 100644
index 000000000..d541eb76e
--- /dev/null
+++ b/src/block/lion/lion.h
@@ -0,0 +1,41 @@
+/*************************************************
+* Lion Header File *
+* (C) 1999-2007 Jack Lloyd *
+*************************************************/
+
+#ifndef BOTAN_LION_H__
+#define BOTAN_LION_H__
+
+#include <botan/block_cipher.h>
+#include <botan/stream_cipher.h>
+#include <botan/hash.h>
+
+namespace Botan {
+
+/*************************************************
+* Lion *
+*************************************************/
+class BOTAN_DLL Lion : public BlockCipher
+ {
+ public:
+ void clear() throw();
+ std::string name() const;
+ BlockCipher* clone() const;
+
+ Lion(HashFunction*, StreamCipher*, u32bit);
+ ~Lion() { delete hash; delete cipher; }
+ private:
+ void enc(const byte[], byte[]) const;
+ void dec(const byte[], byte[]) const;
+ void key(const byte[], u32bit);
+
+ const u32bit LEFT_SIZE, RIGHT_SIZE;
+
+ HashFunction* hash;
+ StreamCipher* cipher;
+ SecureVector<byte> key1, key2;
+ };
+
+}
+
+#endif