"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/EncryptionAlgorithm.h" (10 Oct 2018, 3547 Bytes) of package /windows/misc/VeraCrypt_1.23-Hotfix-2_Source.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "EncryptionAlgorithm.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 1.21_Source_vs_1.22_Source.

    1 /*
    2  Derived from source code of TrueCrypt 7.1a, which is
    3  Copyright (c) 2008-2012 TrueCrypt Developers Association and which is governed
    4  by the TrueCrypt License 3.0.
    5 
    6  Modifications and additions to the original source code (contained in this file)
    7  and all other portions of this file are Copyright (c) 2013-2017 IDRIX
    8  and are governed by the Apache License 2.0 the full text of which is
    9  contained in the file License.txt included in VeraCrypt binary and source
   10  code distribution packages.
   11 */
   12 
   13 #ifndef TC_HEADER_Encryption_EncryptionAlgorithm
   14 #define TC_HEADER_Encryption_EncryptionAlgorithm
   15 
   16 #include "Platform/Platform.h"
   17 #include "Cipher.h"
   18 #include "EncryptionMode.h"
   19 
   20 namespace VeraCrypt
   21 {
   22     class EncryptionAlgorithm;
   23     typedef list < shared_ptr <EncryptionAlgorithm> > EncryptionAlgorithmList;
   24 
   25     class EncryptionAlgorithm
   26     {
   27     public:
   28         virtual ~EncryptionAlgorithm ();
   29 
   30         virtual void Decrypt (byte *data, uint64 length) const;
   31         virtual void Decrypt (const BufferPtr &data) const;
   32         virtual void DecryptSectors (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const;
   33         virtual void Encrypt (byte *data, uint64 length) const;
   34         virtual void Encrypt (const BufferPtr &data) const;
   35         virtual void EncryptSectors (byte *data, uint64 sectorIndex, uint64 sectorCount, size_t sectorSize) const;
   36         static EncryptionAlgorithmList GetAvailableAlgorithms ();
   37         virtual const CipherList &GetCiphers () const { return Ciphers; }
   38         virtual shared_ptr <EncryptionAlgorithm> GetNew () const = 0;
   39         virtual size_t GetMaxBlockSize () const;
   40         virtual size_t GetMinBlockSize () const;
   41         static size_t GetLargestKeySize (const EncryptionAlgorithmList &algorithms);
   42         virtual size_t GetKeySize () const;
   43         virtual shared_ptr <EncryptionMode> GetMode () const;
   44         virtual wstring GetName (bool forGuiDisplay = false) const;
   45         bool IsDeprecated () const { return Deprecated; }
   46         virtual bool IsModeSupported (const EncryptionMode &mode) const;
   47         virtual bool IsModeSupported (const shared_ptr <EncryptionMode> mode) const;
   48         virtual void SetKey (const ConstBufferPtr &key);
   49         virtual void SetMode (shared_ptr <EncryptionMode> mode);
   50 
   51     protected:
   52         EncryptionAlgorithm ();
   53 
   54         void ValidateState () const;
   55 
   56         CipherList Ciphers;
   57         bool Deprecated;
   58         shared_ptr <EncryptionMode> Mode;
   59         EncryptionModeList SupportedModes;
   60 
   61     private:
   62         EncryptionAlgorithm (const EncryptionAlgorithm &);
   63         EncryptionAlgorithm &operator= (const EncryptionAlgorithm &);
   64     };
   65 
   66 #define TC_ENCRYPTION_ALGORITHM(NAME) \
   67     class NAME : public EncryptionAlgorithm \
   68     { \
   69     public: \
   70         NAME (); \
   71         virtual ~NAME () { } \
   72 \
   73         virtual shared_ptr <EncryptionAlgorithm> GetNew () const { return shared_ptr <EncryptionAlgorithm> (new NAME()); } \
   74 \
   75     private: \
   76         NAME (const NAME &); \
   77         NAME &operator= (const NAME &); \
   78     }
   79 
   80     TC_ENCRYPTION_ALGORITHM (AES);
   81     TC_ENCRYPTION_ALGORITHM (AESTwofish);
   82     TC_ENCRYPTION_ALGORITHM (AESTwofishSerpent);
   83     TC_ENCRYPTION_ALGORITHM (Serpent);
   84     TC_ENCRYPTION_ALGORITHM (SerpentAES);
   85     TC_ENCRYPTION_ALGORITHM (Twofish);
   86     TC_ENCRYPTION_ALGORITHM (TwofishSerpent);
   87     TC_ENCRYPTION_ALGORITHM (SerpentTwofishAES);
   88     TC_ENCRYPTION_ALGORITHM (Camellia);
   89     TC_ENCRYPTION_ALGORITHM (GOST89);
   90     TC_ENCRYPTION_ALGORITHM (Kuznyechik);
   91     TC_ENCRYPTION_ALGORITHM (KuznyechikTwofish);
   92     TC_ENCRYPTION_ALGORITHM (KuznyechikAES);
   93     TC_ENCRYPTION_ALGORITHM (KuznyechikSerpentCamellia);
   94     TC_ENCRYPTION_ALGORITHM (CamelliaKuznyechik);
   95     TC_ENCRYPTION_ALGORITHM (CamelliaSerpent);
   96 
   97 #undef TC_ENCRYPTION_ALGORITHM
   98 }
   99 
  100 #endif // TC_HEADER_Encryption_EncryptionAlgorithm