Botan  1.11.15
src/lib/modes/ecb/ecb.h
Go to the documentation of this file.
00001 /*
00002 * ECB Mode
00003 * (C) 1999-2009,2013 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #ifndef BOTAN_MODE_ECB_H__
00009 #define BOTAN_MODE_ECB_H__
00010 
00011 #include <botan/cipher_mode.h>
00012 #include <botan/block_cipher.h>
00013 #include <botan/mode_pad.h>
00014 
00015 namespace Botan {
00016 
00017 /**
00018 * ECB mode
00019 */
00020 class BOTAN_DLL ECB_Mode : public Cipher_Mode
00021    {
00022    public:
00023       std::string name() const override;
00024 
00025       size_t update_granularity() const override;
00026 
00027       Key_Length_Specification key_spec() const override;
00028 
00029       size_t default_nonce_length() const override;
00030 
00031       bool valid_nonce_length(size_t n) const override;
00032 
00033       void clear() override;
00034    protected:
00035       ECB_Mode(BlockCipher* cipher, BlockCipherModePaddingMethod* padding);
00036 
00037       const BlockCipher& cipher() const { return *m_cipher; }
00038 
00039       const BlockCipherModePaddingMethod& padding() const { return *m_padding; }
00040 
00041    private:
00042       secure_vector<byte> start_raw(const byte nonce[], size_t nonce_len) override;
00043       void key_schedule(const byte key[], size_t length) override;
00044 
00045       std::unique_ptr<BlockCipher> m_cipher;
00046       std::unique_ptr<BlockCipherModePaddingMethod> m_padding;
00047    };
00048 
00049 /**
00050 * ECB Encryption
00051 */
00052 class BOTAN_DLL ECB_Encryption : public ECB_Mode
00053    {
00054    public:
00055       ECB_Encryption(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
00056          ECB_Mode(cipher, padding) {}
00057 
00058       void update(secure_vector<byte>& blocks, size_t offset = 0) override;
00059 
00060       void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
00061 
00062       size_t output_length(size_t input_length) const override;
00063 
00064       size_t minimum_final_size() const override;
00065    };
00066 
00067 /**
00068 * ECB Decryption
00069 */
00070 class BOTAN_DLL ECB_Decryption : public ECB_Mode
00071    {
00072    public:
00073       ECB_Decryption(BlockCipher* cipher, BlockCipherModePaddingMethod* padding) :
00074          ECB_Mode(cipher, padding) {}
00075 
00076       void update(secure_vector<byte>& blocks, size_t offset = 0) override;
00077 
00078       void finish(secure_vector<byte>& final_block, size_t offset = 0) override;
00079 
00080       size_t output_length(size_t input_length) const override;
00081 
00082       size_t minimum_final_size() const override;
00083    };
00084 
00085 }
00086 
00087 #endif