diff options
Diffstat (limited to 'src/block/lubyrack')
-rw-r--r-- | src/block/lubyrack/lubyrack.cpp | 40 | ||||
-rw-r--r-- | src/block/lubyrack/lubyrack.h | 6 |
2 files changed, 25 insertions, 21 deletions
diff --git a/src/block/lubyrack/lubyrack.cpp b/src/block/lubyrack/lubyrack.cpp index bdb26837e..aa33c6bc4 100644 --- a/src/block/lubyrack/lubyrack.cpp +++ b/src/block/lubyrack/lubyrack.cpp @@ -13,13 +13,15 @@ namespace Botan { /* * Luby-Rackoff Encryption */ -void LubyRackoff::encrypt_n(const byte in[], byte out[], u32bit blocks) const +void LubyRackoff::encrypt_n(const byte in[], byte out[], size_t blocks) const { - for(u32bit i = 0; i != blocks; ++i) - { - const u32bit len = hash->OUTPUT_LENGTH; + const size_t len = hash->output_length(); + + SecureVector<byte> buffer_vec(len); + byte* buffer = &buffer_vec[0]; - SecureVector<byte> buffer(len); + for(size_t i = 0; i != blocks; ++i) + { hash->update(K1); hash->update(in, len); hash->final(buffer); @@ -40,21 +42,23 @@ void LubyRackoff::encrypt_n(const byte in[], byte out[], u32bit blocks) const hash->final(buffer); xor_buf(out, buffer, len); - in += BLOCK_SIZE; - out += BLOCK_SIZE; + in += block_size(); + out += block_size(); } } /* * Luby-Rackoff Decryption */ -void LubyRackoff::decrypt_n(const byte in[], byte out[], u32bit blocks) const +void LubyRackoff::decrypt_n(const byte in[], byte out[], size_t blocks) const { - for(u32bit i = 0; i != blocks; ++i) - { - const u32bit len = hash->OUTPUT_LENGTH; + const size_t len = hash->output_length(); + + SecureVector<byte> buffer_vec(len); + byte* buffer = &buffer_vec[0]; - SecureVector<byte> buffer(len); + for(size_t i = 0; i != blocks; ++i) + { hash->update(K2); hash->update(in + len, len); hash->final(buffer); @@ -75,15 +79,15 @@ void LubyRackoff::decrypt_n(const byte in[], byte out[], u32bit blocks) const hash->final(buffer); xor_buf(out + len, buffer, len); - in += BLOCK_SIZE; - out += BLOCK_SIZE; + in += block_size(); + out += block_size(); } } /* * Luby-Rackoff Key Schedule */ -void LubyRackoff::key_schedule(const byte key[], u32bit length) +void LubyRackoff::key_schedule(const byte key[], size_t length) { K1.set(key, length / 2); K2.set(key + length / 2, length / 2); @@ -94,8 +98,8 @@ void LubyRackoff::key_schedule(const byte key[], u32bit length) */ void LubyRackoff::clear() { - K1.clear(); - K2.clear(); + zeroise(K1); + zeroise(K2); hash->clear(); } @@ -119,7 +123,7 @@ std::string LubyRackoff::name() const * Luby-Rackoff Constructor */ LubyRackoff::LubyRackoff(HashFunction* h) : - BlockCipher(2 * (h ? h->OUTPUT_LENGTH: 0), + BlockCipher(2 * (h ? h->output_length(): 0), 2, 32, 2), hash(h) { diff --git a/src/block/lubyrack/lubyrack.h b/src/block/lubyrack/lubyrack.h index a69d2302f..4567215e1 100644 --- a/src/block/lubyrack/lubyrack.h +++ b/src/block/lubyrack/lubyrack.h @@ -19,8 +19,8 @@ namespace Botan { class BOTAN_DLL LubyRackoff : public BlockCipher { public: - void encrypt_n(const byte in[], byte out[], u32bit blocks) const; - void decrypt_n(const byte in[], byte out[], u32bit blocks) const; + void encrypt_n(const byte in[], byte out[], size_t blocks) const; + void decrypt_n(const byte in[], byte out[], size_t blocks) const; void clear(); std::string name() const; @@ -32,7 +32,7 @@ class BOTAN_DLL LubyRackoff : public BlockCipher LubyRackoff(HashFunction* hash); ~LubyRackoff() { delete hash; } private: - void key_schedule(const byte[], u32bit); + void key_schedule(const byte[], size_t); HashFunction* hash; SecureVector<byte> K1, K2; |