diff options
Diffstat (limited to 'src/block/lubyrack/lubyrack.cpp')
-rw-r--r-- | src/block/lubyrack/lubyrack.cpp | 40 |
1 files changed, 22 insertions, 18 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) { |