|
|
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_Pkcs5 ! 10: #define TC_HEADER_Encryption_Pkcs5 ! 11: ! 12: #include "Platform/Platform.h" ! 13: #include "Hash.h" ! 14: #include "VolumePassword.h" ! 15: ! 16: namespace TrueCrypt ! 17: { ! 18: class Pkcs5Kdf; ! 19: typedef list < shared_ptr <Pkcs5Kdf> > Pkcs5KdfList; ! 20: ! 21: class Pkcs5Kdf ! 22: { ! 23: public: ! 24: virtual ~Pkcs5Kdf (); ! 25: ! 26: virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt) const; ! 27: virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const = 0; ! 28: static shared_ptr <Pkcs5Kdf> GetAlgorithm (const wstring &name); ! 29: static shared_ptr <Pkcs5Kdf> GetAlgorithm (const Hash &hash); ! 30: static Pkcs5KdfList GetAvailableAlgorithms (); ! 31: virtual shared_ptr <Hash> GetHash () const = 0; ! 32: virtual int GetIterationCount () const = 0; ! 33: virtual wstring GetName () const = 0; ! 34: virtual bool IsDeprecated () const { return GetHash()->IsDeprecated(); } ! 35: ! 36: protected: ! 37: Pkcs5Kdf (); ! 38: ! 39: void ValidateParameters (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const; ! 40: ! 41: private: ! 42: Pkcs5Kdf (const Pkcs5Kdf &); ! 43: Pkcs5Kdf &operator= (const Pkcs5Kdf &); ! 44: }; ! 45: ! 46: class Pkcs5HmacRipemd160 : public Pkcs5Kdf ! 47: { ! 48: public: ! 49: Pkcs5HmacRipemd160 () { } ! 50: virtual ~Pkcs5HmacRipemd160 () { } ! 51: ! 52: virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const; ! 53: virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Ripemd160); } ! 54: virtual int GetIterationCount () const { return 2000; } ! 55: virtual wstring GetName () const { return L"HMAC-RIPEMD-160"; } ! 56: ! 57: private: ! 58: Pkcs5HmacRipemd160 (const Pkcs5HmacRipemd160 &); ! 59: Pkcs5HmacRipemd160 &operator= (const Pkcs5HmacRipemd160 &); ! 60: }; ! 61: ! 62: class Pkcs5HmacSha1 : public Pkcs5Kdf ! 63: { ! 64: public: ! 65: Pkcs5HmacSha1 () { } ! 66: virtual ~Pkcs5HmacSha1 () { } ! 67: ! 68: virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const; ! 69: virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha1); } ! 70: virtual int GetIterationCount () const { return 2000; } ! 71: virtual wstring GetName () const { return L"HMAC-SHA-1"; } ! 72: ! 73: private: ! 74: Pkcs5HmacSha1 (const Pkcs5HmacSha1 &); ! 75: Pkcs5HmacSha1 &operator= (const Pkcs5HmacSha1 &); ! 76: }; ! 77: ! 78: class Pkcs5HmacSha512 : public Pkcs5Kdf ! 79: { ! 80: public: ! 81: Pkcs5HmacSha512 () { } ! 82: virtual ~Pkcs5HmacSha512 () { } ! 83: ! 84: virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const; ! 85: virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Sha512); } ! 86: virtual int GetIterationCount () const { return 1000; } ! 87: virtual wstring GetName () const { return L"HMAC-SHA-512"; } ! 88: ! 89: private: ! 90: Pkcs5HmacSha512 (const Pkcs5HmacSha512 &); ! 91: Pkcs5HmacSha512 &operator= (const Pkcs5HmacSha512 &); ! 92: }; ! 93: ! 94: class Pkcs5HmacWhirlpool : public Pkcs5Kdf ! 95: { ! 96: public: ! 97: Pkcs5HmacWhirlpool () { } ! 98: virtual ~Pkcs5HmacWhirlpool () { } ! 99: ! 100: virtual void DeriveKey (const BufferPtr &key, const VolumePassword &password, const ConstBufferPtr &salt, int iterationCount) const; ! 101: virtual shared_ptr <Hash> GetHash () const { return shared_ptr <Hash> (new Whirlpool); } ! 102: virtual int GetIterationCount () const { return 1000; } ! 103: virtual wstring GetName () const { return L"HMAC-Whirlpool"; } ! 104: ! 105: private: ! 106: Pkcs5HmacWhirlpool (const Pkcs5HmacWhirlpool &); ! 107: Pkcs5HmacWhirlpool &operator= (const Pkcs5HmacWhirlpool &); ! 108: }; ! 109: } ! 110: ! 111: #endif // TC_HEADER_Encryption_Pkcs5
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.