From f05f6a00a6b0f150b0a0b51cd7b44b9c9193e3de Mon Sep 17 00:00:00 2001 From: Mounir IDRASSI Date: Tue, 14 Oct 2014 21:19:53 +0200 Subject: Integrate SHA-256 support into Linux/MacOSX code. Set PRF priority to SHA-512 -> Whirlpool -> SHA-256 -> RIPEMD-160 . --- src/Volume/Hash.cpp | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src/Volume/Hash.cpp') diff --git a/src/Volume/Hash.cpp b/src/Volume/Hash.cpp index b917a8e5..cc582b92 100644 --- a/src/Volume/Hash.cpp +++ b/src/Volume/Hash.cpp @@ -17,10 +17,11 @@ namespace VeraCrypt HashList Hash::GetAvailableAlgorithms () { HashList l; - - l.push_back (shared_ptr (new Ripemd160 ())); + l.push_back (shared_ptr (new Sha512 ())); l.push_back (shared_ptr (new Whirlpool ())); + l.push_back (shared_ptr (new Sha256 ())); + l.push_back (shared_ptr (new Ripemd160 ())); return l; } @@ -60,6 +61,30 @@ namespace VeraCrypt if_debug (ValidateDataParameters (data)); RMD160Update ((RMD160_CTX *) Context.Ptr(), data.Get(), (int) data.Size()); } + + // SHA-256 + Sha256::Sha256 () + { + Context.Allocate (sizeof (sha256_ctx)); + Init(); + } + + void Sha256::GetDigest (const BufferPtr &buffer) + { + if_debug (ValidateDigestParameters (buffer)); + sha256_end (buffer, (sha256_ctx *) Context.Ptr()); + } + + void Sha256::Init () + { + sha256_begin ((sha256_ctx *) Context.Ptr()); + } + + void Sha256::ProcessData (const ConstBufferPtr &data) + { + if_debug (ValidateDataParameters (data)); + sha256_hash (data.Get(), (int) data.Size(), (sha256_ctx *) Context.Ptr()); + } // SHA-512 Sha512::Sha512 () -- cgit v1.2.3