"Fossies" - the Fresh Open Source Software Archive

Member "src/Volume/Hash.h" (10 Oct 2018, 4814 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 "Hash.h" see the Fossies "Dox" file reference documentation.

    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_Hash
   14 #define TC_HEADER_Encryption_Hash
   15 
   16 #include "Platform/Platform.h"
   17 
   18 namespace VeraCrypt
   19 {
   20     class Hash;
   21     typedef list < shared_ptr <Hash> > HashList;
   22 
   23     class Hash
   24     {
   25     public:
   26         Hash () : Deprecated (false) { }
   27         virtual ~Hash () { }
   28 
   29         static HashList GetAvailableAlgorithms ();
   30         virtual void GetDigest (const BufferPtr &buffer) = 0;
   31         virtual size_t GetBlockSize () const = 0;
   32         virtual size_t GetDigestSize () const = 0;
   33         virtual wstring GetName () const = 0;
   34         virtual wstring GetAltName () const = 0;
   35         virtual shared_ptr <Hash> GetNew () const = 0;
   36         virtual void Init () = 0;
   37         bool IsDeprecated () const { return Deprecated; }
   38         virtual void ProcessData (const ConstBufferPtr &data) = 0;
   39         virtual void ValidateDataParameters (const ConstBufferPtr &data) const;
   40         virtual void ValidateDigestParameters (const BufferPtr &buffer) const;
   41 
   42     protected:
   43         SecureBuffer Context;
   44         bool Deprecated;
   45 
   46     private:
   47         Hash (const Hash &);
   48         Hash &operator= (const Hash &);
   49     };
   50 
   51     // RIPEMD-160
   52     class Ripemd160 : public Hash
   53     {
   54     public:
   55         Ripemd160 ();
   56         virtual ~Ripemd160 () { }
   57 
   58         virtual void GetDigest (const BufferPtr &buffer);
   59         virtual size_t GetBlockSize () const { return 64; }
   60         virtual size_t GetDigestSize () const { return 160 / 8; }
   61         virtual wstring GetName () const { return L"RIPEMD-160"; }
   62         virtual wstring GetAltName () const { return L"RIPEMD160"; }
   63         virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Ripemd160); }
   64         virtual void Init ();
   65         virtual void ProcessData (const ConstBufferPtr &data);
   66 
   67     protected:
   68 
   69     private:
   70         Ripemd160 (const Ripemd160 &);
   71         Ripemd160 &operator= (const Ripemd160 &);
   72     };
   73 
   74     // SHA-256
   75     class Sha256 : public Hash
   76     {
   77     public:
   78         Sha256 ();
   79         virtual ~Sha256 () { }
   80 
   81         virtual void GetDigest (const BufferPtr &buffer);
   82         virtual size_t GetBlockSize () const { return 64; }
   83         virtual size_t GetDigestSize () const { return 256 / 8; }
   84         virtual wstring GetName () const { return L"SHA-256"; }
   85         virtual wstring GetAltName () const { return L"SHA256"; }
   86         virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Sha256); }
   87         virtual void Init ();
   88         virtual void ProcessData (const ConstBufferPtr &data);
   89 
   90     protected:
   91 
   92     private:
   93         Sha256 (const Sha256 &);
   94         Sha256 &operator= (const Sha256 &);
   95     };
   96 
   97     // SHA-512
   98     class Sha512 : public Hash
   99     {
  100     public:
  101         Sha512 ();
  102         virtual ~Sha512 () { }
  103 
  104         virtual void GetDigest (const BufferPtr &buffer);
  105         virtual size_t GetBlockSize () const { return 128; }
  106         virtual size_t GetDigestSize () const { return 512 / 8; }
  107         virtual wstring GetName () const { return L"SHA-512"; }
  108         virtual wstring GetAltName () const { return L"SHA512"; }
  109         virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Sha512); }
  110         virtual void Init ();
  111         virtual void ProcessData (const ConstBufferPtr &data);
  112 
  113     protected:
  114 
  115     private:
  116         Sha512 (const Sha512 &);
  117         Sha512 &operator= (const Sha512 &);
  118     };
  119 
  120     // Whirlpool
  121     class Whirlpool : public Hash
  122     {
  123     public:
  124         Whirlpool ();
  125         virtual ~Whirlpool () { }
  126 
  127         virtual void GetDigest (const BufferPtr &buffer);
  128         virtual size_t GetBlockSize () const { return 64; }
  129         virtual size_t GetDigestSize () const { return 512 / 8; }
  130         virtual wstring GetName () const { return L"Whirlpool"; }
  131         virtual wstring GetAltName () const { return L"Whirlpool"; }
  132         virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Whirlpool); }
  133         virtual void Init ();
  134         virtual void ProcessData (const ConstBufferPtr &data);
  135 
  136     protected:
  137 
  138     private:
  139         Whirlpool (const Whirlpool &);
  140         Whirlpool &operator= (const Whirlpool &);
  141     };
  142     
  143     // Streebog
  144     class Streebog : public Hash
  145     {
  146     public:
  147         Streebog ();
  148         virtual ~Streebog () { }
  149 
  150         virtual void GetDigest (const BufferPtr &buffer);
  151         virtual size_t GetBlockSize () const { return 64; }
  152         virtual size_t GetDigestSize () const { return 512 / 8; }
  153         virtual wstring GetName () const { return L"Streebog"; }
  154         virtual wstring GetAltName () const { return L"Streebog"; }
  155         virtual shared_ptr <Hash> GetNew () const { return shared_ptr <Hash> (new Streebog); }
  156         virtual void Init ();
  157         virtual void ProcessData (const ConstBufferPtr &data);
  158 
  159     protected:
  160 
  161     private:
  162         Streebog (const Streebog &);
  163         Streebog &operator= (const Streebog &);
  164     };
  165 }
  166 
  167 #endif // TC_HEADER_Encryption_Hash