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