Use RtlGenRandom() as an additional source of entropy

for CRandomGenerator::Init() and 16 bytes IV for AES.
This commit is contained in:
Tino Reichardt
2019-01-26 09:10:09 +01:00
parent 4b0a001320
commit 34323d51e9
3 changed files with 8 additions and 15 deletions

View File

@@ -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

View File

@@ -12,6 +12,9 @@
#include <unistd.h>
#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);