|
|
1.1 ! root 1: /* ! 2: Copyright (c) 2008 TrueCrypt Foundation. All rights reserved. ! 3: ! 4: Governed by the TrueCrypt License 2.4 the full text of which is contained ! 5: in the file License.txt included in TrueCrypt binary and source code ! 6: distribution packages. ! 7: */ ! 8: ! 9: #ifndef TC_HEADER_Encryption_EncryptionAlgorithm ! 10: #define TC_HEADER_Encryption_EncryptionAlgorithm ! 11: ! 12: #include "Platform/Platform.h" ! 13: #include "Cipher.h" ! 14: #include "EncryptionMode.h" ! 15: ! 16: namespace TrueCrypt ! 17: { ! 18: class EncryptionAlgorithm; ! 19: typedef list < shared_ptr <EncryptionAlgorithm> > EncryptionAlgorithmList; ! 20: ! 21: class EncryptionAlgorithm ! 22: { ! 23: public: ! 24: virtual ~EncryptionAlgorithm (); ! 25: ! 26: virtual void Decrypt (byte *data, uint64 length) const; ! 27: virtual void Decrypt (const BufferPtr &data) const; ! 28: virtual void DecryptSectors (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const; ! 29: virtual void Encrypt (byte *data, uint64 length) const; ! 30: virtual void Encrypt (const BufferPtr &data) const; ! 31: virtual void EncryptSectors (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const; ! 32: static EncryptionAlgorithmList GetAvailableAlgorithms (); ! 33: virtual const CipherList &GetCiphers () const { return Ciphers; } ! 34: virtual shared_ptr <EncryptionAlgorithm> GetNew () const = 0; ! 35: virtual size_t GetMaxBlockSize () const; ! 36: virtual size_t GetMinBlockSize () const; ! 37: static size_t GetLargestKeySize (const EncryptionAlgorithmList &algorithms); ! 38: virtual size_t GetKeySize () const; ! 39: virtual shared_ptr <EncryptionMode> GetMode () const; ! 40: virtual wstring GetName () const; ! 41: bool IsDeprecated () const { return Deprecated; } ! 42: virtual bool IsModeSupported (const EncryptionMode &mode) const; ! 43: virtual bool IsModeSupported (const shared_ptr <EncryptionMode> mode) const; ! 44: virtual void SetKey (const ConstBufferPtr &key); ! 45: virtual void SetMode (shared_ptr <EncryptionMode> mode); ! 46: ! 47: protected: ! 48: EncryptionAlgorithm (); ! 49: ! 50: void ValidateState () const; ! 51: ! 52: CipherList Ciphers; ! 53: bool Deprecated; ! 54: shared_ptr <EncryptionMode> Mode; ! 55: EncryptionModeList SupportedModes; ! 56: ! 57: private: ! 58: EncryptionAlgorithm (const EncryptionAlgorithm &); ! 59: EncryptionAlgorithm &operator= (const EncryptionAlgorithm &); ! 60: }; ! 61: ! 62: #define TC_ENCRYPTION_ALGORITHM(NAME) \ ! 63: class NAME : public EncryptionAlgorithm \ ! 64: { \ ! 65: public: \ ! 66: NAME (); \ ! 67: virtual ~NAME () { } \ ! 68: \ ! 69: virtual shared_ptr <EncryptionAlgorithm> GetNew () const { return shared_ptr <EncryptionAlgorithm> (new NAME()); } \ ! 70: \ ! 71: private: \ ! 72: NAME (const NAME &); \ ! 73: NAME &operator= (const NAME &); \ ! 74: } ! 75: ! 76: TC_ENCRYPTION_ALGORITHM (AES); ! 77: TC_ENCRYPTION_ALGORITHM (AESBlowfish); ! 78: TC_ENCRYPTION_ALGORITHM (AESBlowfishSerpent); ! 79: TC_ENCRYPTION_ALGORITHM (AESTwofish); ! 80: TC_ENCRYPTION_ALGORITHM (AESTwofishSerpent); ! 81: TC_ENCRYPTION_ALGORITHM (Blowfish); ! 82: TC_ENCRYPTION_ALGORITHM (Cast5); ! 83: TC_ENCRYPTION_ALGORITHM (Serpent); ! 84: TC_ENCRYPTION_ALGORITHM (SerpentAES); ! 85: TC_ENCRYPTION_ALGORITHM (TripleDES); ! 86: TC_ENCRYPTION_ALGORITHM (Twofish); ! 87: TC_ENCRYPTION_ALGORITHM (TwofishSerpent); ! 88: TC_ENCRYPTION_ALGORITHM (SerpentTwofishAES); ! 89: ! 90: #undef TC_ENCRYPTION_ALGORITHM ! 91: } ! 92: ! 93: #endif // TC_HEADER_Encryption_EncryptionAlgorithm
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.