aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/lubyrack.h5
-rw-r--r--src/def_alg.cpp8
-rw-r--r--src/lubyrack.cpp52
3 files changed, 36 insertions, 29 deletions
diff --git a/include/lubyrack.h b/include/lubyrack.h
index e5a2e2a20..2c4813cb6 100644
--- a/include/lubyrack.h
+++ b/include/lubyrack.h
@@ -1,6 +1,6 @@
/*************************************************
* Luby-Rackoff Header File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
*************************************************/
#ifndef BOTAN_LUBY_RACKOFF_H__
@@ -19,7 +19,8 @@ class BOTAN_DLL LubyRackoff : public BlockCipher
void clear() throw();
std::string name() const;
BlockCipher* clone() const;
- LubyRackoff(const std::string&);
+
+ LubyRackoff(HashFunction* hash);
~LubyRackoff() { delete hash; }
private:
void enc(const byte[], byte[]) const;
diff --git a/src/def_alg.cpp b/src/def_alg.cpp
index 10c8e49d9..29e99d6a0 100644
--- a/src/def_alg.cpp
+++ b/src/def_alg.cpp
@@ -130,7 +130,6 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const
HANDLE_TYPE_NO_ARGS("GOST", GOST);
HANDLE_TYPE_NO_ARGS("IDEA", IDEA);
HANDLE_TYPE_NO_ARGS("KASUMI", KASUMI);
- HANDLE_TYPE_ONE_STRING("Luby-Rackoff", LubyRackoff);
HANDLE_TYPE_NO_ARGS("MARS", MARS);
HANDLE_TYPE_ONE_U32BIT("MISTY1", MISTY1, 8);
HANDLE_TYPE_NO_ARGS("Noekeon", Noekeon);
@@ -146,6 +145,13 @@ Default_Engine::find_block_cipher(const std::string& algo_spec) const
HANDLE_TYPE_NO_ARGS("Twofish", Twofish);
HANDLE_TYPE_NO_ARGS("XTEA", XTEA);
+ if(algo_name == "Luby-Rackoff" && name.size() >= 2)
+ {
+ HashFunction* hash = find_hash(name[1]);
+ if(hash)
+ return new LubyRackoff(hash);
+ }
+
if(algo_name == "Lion")
{
if(name.size() != 4)
diff --git a/src/lubyrack.cpp b/src/lubyrack.cpp
index 4a5408e1d..c9e6fc531 100644
--- a/src/lubyrack.cpp
+++ b/src/lubyrack.cpp
@@ -1,10 +1,9 @@
/*************************************************
* Luby-Rackoff Source File *
-* (C) 1999-2007 Jack Lloyd *
+* (C) 1999-2008 Jack Lloyd *
*************************************************/
#include <botan/lubyrack.h>
-#include <botan/lookup.h>
#include <botan/xor_buf.h>
namespace Botan {
@@ -14,28 +13,28 @@ namespace Botan {
*************************************************/
void LubyRackoff::enc(const byte in[], byte out[]) const
{
- const u32bit OUTPUT_LENGTH = hash->OUTPUT_LENGTH;
+ const u32bit len = hash->OUTPUT_LENGTH;
- SecureVector<byte> buffer(OUTPUT_LENGTH);
+ SecureVector<byte> buffer(len);
hash->update(K1);
- hash->update(in, OUTPUT_LENGTH);
+ hash->update(in, len);
hash->final(buffer);
- xor_buf(out + OUTPUT_LENGTH, in + OUTPUT_LENGTH, buffer, OUTPUT_LENGTH);
+ xor_buf(out + len, in + len, buffer, len);
hash->update(K2);
- hash->update(out + OUTPUT_LENGTH, OUTPUT_LENGTH);
+ hash->update(out + len, len);
hash->final(buffer);
- xor_buf(out, in, buffer, OUTPUT_LENGTH);
+ xor_buf(out, in, buffer, len);
hash->update(K1);
- hash->update(out, OUTPUT_LENGTH);
+ hash->update(out, len);
hash->final(buffer);
- xor_buf(out + OUTPUT_LENGTH, buffer, OUTPUT_LENGTH);
+ xor_buf(out + len, buffer, len);
hash->update(K2);
- hash->update(out + OUTPUT_LENGTH, OUTPUT_LENGTH);
+ hash->update(out + len, len);
hash->final(buffer);
- xor_buf(out, buffer, OUTPUT_LENGTH);
+ xor_buf(out, buffer, len);
}
/*************************************************
@@ -43,28 +42,28 @@ void LubyRackoff::enc(const byte in[], byte out[]) const
*************************************************/
void LubyRackoff::dec(const byte in[], byte out[]) const
{
- const u32bit OUTPUT_LENGTH = hash->OUTPUT_LENGTH;
+ const u32bit len = hash->OUTPUT_LENGTH;
- SecureVector<byte> buffer(OUTPUT_LENGTH);
+ SecureVector<byte> buffer(len);
hash->update(K2);
- hash->update(in + OUTPUT_LENGTH, OUTPUT_LENGTH);
+ hash->update(in + len, len);
hash->final(buffer);
- xor_buf(out, in, buffer, OUTPUT_LENGTH);
+ xor_buf(out, in, buffer, len);
hash->update(K1);
- hash->update(out, OUTPUT_LENGTH);
+ hash->update(out, len);
hash->final(buffer);
- xor_buf(out + OUTPUT_LENGTH, in + OUTPUT_LENGTH, buffer, OUTPUT_LENGTH);
+ xor_buf(out + len, in + len, buffer, len);
hash->update(K2);
- hash->update(out + OUTPUT_LENGTH, OUTPUT_LENGTH);
+ hash->update(out + len, len);
hash->final(buffer);
- xor_buf(out, buffer, OUTPUT_LENGTH);
+ xor_buf(out, buffer, len);
hash->update(K1);
- hash->update(out, OUTPUT_LENGTH);
+ hash->update(out, len);
hash->final(buffer);
- xor_buf(out + OUTPUT_LENGTH, buffer, OUTPUT_LENGTH);
+ xor_buf(out + len, buffer, len);
}
/*************************************************
@@ -91,7 +90,7 @@ void LubyRackoff::clear() throw()
*************************************************/
BlockCipher* LubyRackoff::clone() const
{
- return new LubyRackoff(hash->name());
+ return new LubyRackoff(hash->clone());
}
/*************************************************
@@ -105,9 +104,10 @@ std::string LubyRackoff::name() const
/*************************************************
* Luby-Rackoff Constructor *
*************************************************/
-LubyRackoff::LubyRackoff(const std::string& hash_name) :
- BlockCipher(2*output_length_of(hash_name), 2, 32, 2),
- hash(get_hash(hash_name))
+LubyRackoff::LubyRackoff(HashFunction* h) :
+ BlockCipher(2 * (h ? h->OUTPUT_LENGTH: 0),
+ 2, 32, 2),
+ hash(h)
{
}