diff options
| author | Ed Baak <ed.baak@nokia.com> | 2010-07-26 14:06:13 +1000 |
|---|---|---|
| committer | Ed Baak <ed.baak@nokia.com> | 2010-07-26 14:06:13 +1000 |
| commit | 02e9b6740ff7851b52ab677800e94fb77e6092ed (patch) | |
| tree | a38a4f4d44b53a95b5db40e5ec12b513b5896e06 /botan/src/modes/ecb/ecb.cpp | |
| parent | eb2fbe409d1423c0b707b9986ee1e56fa19b355a (diff) | |
Included Botan and ssh code to make QtUItest compile again (as a separate package without creator). Note that this is a temporary hack and will go away when we moveQtUItest into creator.
Diffstat (limited to 'botan/src/modes/ecb/ecb.cpp')
| -rw-r--r-- | botan/src/modes/ecb/ecb.cpp | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/botan/src/modes/ecb/ecb.cpp b/botan/src/modes/ecb/ecb.cpp new file mode 100644 index 0000000..8da0a48 --- /dev/null +++ b/botan/src/modes/ecb/ecb.cpp @@ -0,0 +1,105 @@ +/* +* ECB Mode +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#include <botan/ecb.h> + +namespace Botan { + +/* +* Verify the IV is not set +*/ +bool ECB::valid_iv_size(u32bit iv_size) const + { + if(iv_size == 0) + return true; + return false; + } + +/* +* Return an ECB mode name +*/ +std::string ECB::name() const + { + return (cipher->name() + "/" + mode_name + "/" + padder->name()); + } + +/* +* Encrypt in ECB mode +*/ +void ECB_Encryption::write(const byte input[], u32bit length) + { + buffer.copy(position, input, length); + if(position + length >= BLOCK_SIZE) + { + cipher->encrypt(buffer); + send(buffer, BLOCK_SIZE); + input += (BLOCK_SIZE - position); + length -= (BLOCK_SIZE - position); + while(length >= BLOCK_SIZE) + { + cipher->encrypt(input, buffer); + send(buffer, BLOCK_SIZE); + input += BLOCK_SIZE; + length -= BLOCK_SIZE; + } + buffer.copy(input, length); + position = 0; + } + position += length; + } + +/* +* Finish encrypting in ECB mode +*/ +void ECB_Encryption::end_msg() + { + SecureVector<byte> padding(BLOCK_SIZE); + padder->pad(padding, padding.size(), position); + write(padding, padder->pad_bytes(BLOCK_SIZE, position)); + if(position != 0) + throw Encoding_Error(name() + ": Did not pad to full blocksize"); + } + +/* +* Decrypt in ECB mode +*/ +void ECB_Decryption::write(const byte input[], u32bit length) + { + buffer.copy(position, input, length); + if(position + length > BLOCK_SIZE) + { + cipher->decrypt(buffer); + send(buffer, BLOCK_SIZE); + input += (BLOCK_SIZE - position); + length -= (BLOCK_SIZE - position); + while(length > BLOCK_SIZE) + { + cipher->decrypt(input, buffer); + send(buffer, BLOCK_SIZE); + input += BLOCK_SIZE; + length -= BLOCK_SIZE; + } + buffer.copy(input, length); + position = 0; + } + position += length; + } + +/* +* Finish decrypting in ECB mode +*/ +void ECB_Decryption::end_msg() + { + if(position != BLOCK_SIZE) + throw Decoding_Error(name()); + cipher->decrypt(buffer); + send(buffer, padder->unpad(buffer, BLOCK_SIZE)); + state = buffer; + position = 0; + } + +} |
