From 34323d51e9ae79e1e86696e5b6f2e51acd806510 Mon Sep 17 00:00:00 2001 From: Tino Reichardt Date: Sat, 26 Jan 2019 09:10:09 +0100 Subject: [PATCH] Use RtlGenRandom() as an additional source of entropy for CRandomGenerator::Init() and 16 bytes IV for AES. --- C/7zVersion.h | 2 +- CPP/7zip/Crypto/7zAes.cpp | 16 ++-------------- CPP/7zip/Crypto/RandGen.cpp | 5 +++++ 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/C/7zVersion.h b/C/7zVersion.h index 393b084d..2bd86053 100644 --- a/C/7zVersion.h +++ b/C/7zVersion.h @@ -10,7 +10,7 @@ #define MY_VERSION_CPU MY_VERSION #endif -#define MY_DATE "2019-01-07" +#define MY_DATE "2019-01-26" #undef MY_COPYRIGHT #undef MY_VERSION_COPYRIGHT_DATE #define MY_AUTHOR_NAME "Igor Pavlov, Tino Reichardt" diff --git a/CPP/7zip/Crypto/7zAes.cpp b/CPP/7zip/Crypto/7zAes.cpp index f412bf9d..e386f390 100644 --- a/CPP/7zip/Crypto/7zAes.cpp +++ b/CPP/7zip/Crypto/7zAes.cpp @@ -151,21 +151,10 @@ void CBase::PrepareKey() #ifndef EXTRACT_ONLY -/* -STDMETHODIMP CEncoder::ResetSalt() -{ - _key.SaltSize = 4; - g_RandomGenerator.Generate(_key.Salt, _key.SaltSize); - return S_OK; -} -*/ - STDMETHODIMP CEncoder::ResetInitVector() { - for (unsigned i = 0; i < sizeof(_iv); i++) - _iv[i] = 0; - _ivSize = 8; - g_RandomGenerator.Generate(_iv, _ivSize); + _ivSize = sizeof(_iv); + g_RandomGenerator.Generate(_iv, sizeof(_iv)); return S_OK; } @@ -245,7 +234,6 @@ STDMETHODIMP CDecoder::SetDecoderProperties2(const Byte *data, UInt32 size) || _key.NumCyclesPower == 0x3F) ? S_OK : E_NOTIMPL; } - STDMETHODIMP CBaseCoder::CryptoSetPassword(const Byte *data, UInt32 size) { COM_TRY_BEGIN diff --git a/CPP/7zip/Crypto/RandGen.cpp b/CPP/7zip/Crypto/RandGen.cpp index 542f39bd..d585f525 100644 --- a/CPP/7zip/Crypto/RandGen.cpp +++ b/CPP/7zip/Crypto/RandGen.cpp @@ -12,6 +12,9 @@ #include #define USE_POSIX_TIME #define USE_POSIX_TIME2 +#else +# define RtlGenRandom SystemFunction036 +extern "C" BOOLEAN NTAPI RtlGenRandom(PVOID RandomBuffer, ULONG RandomBufferLength); #endif #ifdef USE_POSIX_TIME @@ -39,6 +42,8 @@ void CRandomGenerator::Init() HASH_UPD(w); w = ::GetCurrentThreadId(); HASH_UPD(w); + if (RtlGenRandom(&w, sizeof(DWORD))) + HASH_UPD(w); #else pid_t pid = getpid(); HASH_UPD(pid);