diff options
author | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-05-18 18:33:19 +0000 |
commit | a2c99d3270eb73ef2db5704fc54356c6b75096f8 (patch) | |
tree | ad3d6c4fcc8dd0f403f8105598943616246fe172 /src/ofb.cpp |
Initial checkin1.5.6
Diffstat (limited to 'src/ofb.cpp')
-rw-r--r-- | src/ofb.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/ofb.cpp b/src/ofb.cpp new file mode 100644 index 000000000..af0c6067d --- /dev/null +++ b/src/ofb.cpp @@ -0,0 +1,65 @@ +/************************************************* +* OFB Mode Source File * +* (C) 1999-2006 The Botan Project * +*************************************************/ + +#include <botan/ofb.h> +#include <botan/lookup.h> +#include <botan/bit_ops.h> +#include <algorithm> + +namespace Botan { + +/************************************************* +* OFB Constructor * +*************************************************/ +OFB::OFB(const std::string& cipher_name) : + BlockCipherMode(cipher_name, "OFB", block_size_of(cipher_name), 2) + { + } + +/************************************************* +* OFB Constructor * +*************************************************/ +OFB::OFB(const std::string& cipher_name, const SymmetricKey& key, + const InitializationVector& iv) : + BlockCipherMode(cipher_name, "OFB", block_size_of(cipher_name), 2) + { + set_key(key); + set_iv(iv); + } + +/************************************************* +* OFB Encryption/Decryption * +*************************************************/ +void OFB::write(const byte input[], u32bit length) + { + u32bit copied = std::min(BLOCK_SIZE - position, length); + xor_buf(buffer, input, state + position, copied); + send(buffer, copied); + input += copied; + length -= copied; + position += copied; + + if(position == BLOCK_SIZE) + { + cipher->encrypt(state); + position = 0; + } + + while(length >= BLOCK_SIZE) + { + xor_buf(buffer, input, state, BLOCK_SIZE); + send(buffer, BLOCK_SIZE); + + input += BLOCK_SIZE; + length -= BLOCK_SIZE; + cipher->encrypt(state); + } + + xor_buf(buffer, input, state + position, length); + send(buffer, length); + position += length; + } + +} |