diff options
author | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
---|---|---|
committer | Keith Isdale <keith.isdale@nokia.com> | 2010-07-26 14:56:53 +1000 |
commit | 9f034793bcfc51c2b7c1dd14db806f7258f9a9eb (patch) | |
tree | 63bd0f50ce5b77828ad8205eafd7b9412810499e /botan/build/botan/block_cipher.h | |
parent | 619d92cfef29e653bfdf852e83888e50cfc4348f (diff) | |
parent | 65271649dbc90f3af1184ad1b23bdb64c0c07d07 (diff) |
Merge branch 'master' of git://git-nokia.trolltech.com.au/qtsoftware/research/qtuitest
Diffstat (limited to 'botan/build/botan/block_cipher.h')
-rw-r--r-- | botan/build/botan/block_cipher.h | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/botan/build/botan/block_cipher.h b/botan/build/botan/block_cipher.h new file mode 100644 index 0000000..01c45af --- /dev/null +++ b/botan/build/botan/block_cipher.h @@ -0,0 +1,100 @@ +/** +* Block Cipher Base Class +* (C) 1999-2007 Jack Lloyd +* +* Distributed under the terms of the Botan license +*/ + +#ifndef BOTAN_BLOCK_CIPHER_H__ +#define BOTAN_BLOCK_CIPHER_H__ + +#include <botan/sym_algo.h> + +namespace Botan { + +/** +* This class represents a block cipher object. +* +* It would be very useful to extend this interface to support the +* encryption of multiple blocks at a time. This could help +* performance, wrt cache effects in the software implementations, and +* could be a big deal when supporting block ciphers implemented as +* hardware devices. It could be used by implementations of ECB, and +* more importantly counter mode (which most designs are moving to, due +* to the parallelism possible in counter mode which is not the case +* with feedback-based modes like CBC). +* +* Probable future API here: +* virtual void encrypt_n(const byte in[], byte out[], +* u32bit blocks) const = 0; +* virtual void decrypt_n(const byte in[], byte out[], +* u32bit blocks) const = 0; +*/ +class BOTAN_DLL BlockCipher : public SymmetricAlgorithm + { + public: + /** + * The block size of this algorithm. + */ + const u32bit BLOCK_SIZE; + + /** + * Encrypt a block. + * @param in The plaintext block to be encrypted as a byte array. + * Must be of length BLOCK_SIZE. + * @param out The byte array designated to hold the encrypted block. + * Must be of length BLOCK_SIZE. + */ + void encrypt(const byte in[], byte out[]) const { enc(in, out); } + + /** + * Decrypt a block. + * @param in The ciphertext block to be decypted as a byte array. + * Must be of length BLOCK_SIZE. + * @param out The byte array designated to hold the decrypted block. + * Must be of length BLOCK_SIZE. + */ + void decrypt(const byte in[], byte out[]) const { dec(in, out); } + + /** + * Encrypt a block. + * @param in The plaintext block to be encrypted as a byte array. + * Must be of length BLOCK_SIZE. Will hold the result when the function + * has finished. + */ + void encrypt(byte block[]) const { enc(block, block); } + + /** + * Decrypt a block. + * @param in The ciphertext block to be decrypted as a byte array. + * Must be of length BLOCK_SIZE. Will hold the result when the function + * has finished. + */ + void decrypt(byte block[]) const { dec(block, block); } + + /** + * Get a new object representing the same algorithm as *this + */ + virtual BlockCipher* clone() const = 0; + + /** + * Zeroize internal state + */ + virtual void clear() throw() = 0; + + BlockCipher(u32bit block_size, + u32bit key_min, + u32bit key_max = 0, + u32bit key_mod = 1) : + SymmetricAlgorithm(key_min, key_max, key_mod), + BLOCK_SIZE(block_size) {} + + virtual ~BlockCipher() {} + private: + virtual void enc(const byte[], byte[]) const = 0; + virtual void dec(const byte[], byte[]) const = 0; + }; + +} + +#endif |