From abd8b7a991e24a3b5fdd80be6a60c904c092b7a0 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Mon, 27 Jul 2020 11:41:28 -0400 Subject: Update Padlock RNG GenerateBlock --- padlkrng.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'padlkrng.cpp') diff --git a/padlkrng.cpp b/padlkrng.cpp index 0a3620e4..38380fee 100644 --- a/padlkrng.cpp +++ b/padlkrng.cpp @@ -47,8 +47,16 @@ void PadlockRNG::GenerateBlock(byte *output, size_t size) "movl %2, %%edx ;\n" #endif + // xstore-rng ".byte 0x0f, 0xa7, 0xc0 ;\n" + +#if (CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) + "andq %%rax, 0x1f ;\n" "movl %%eax, %0 ;\n" +#else + "andl %%eax, 0x1f ;\n" + "movl %%eax, %0 ;\n" +#endif : "=g" (m_msr) : "g" (m_buffer.data()), "g" (m_divisor) #if (CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64) @@ -58,8 +66,7 @@ void PadlockRNG::GenerateBlock(byte *output, size_t size) #endif ); - const size_t ret = m_msr & 0x1f; - const size_t rem = STDMIN(ret, STDMIN(size, 16U /*buffer size*/)); + const size_t rem = STDMIN(m_msr, STDMIN(size, 16U /*buffer size*/)); std::memcpy(output, m_buffer, rem); size -= rem; output += rem; } @@ -74,11 +81,11 @@ void PadlockRNG::GenerateBlock(byte *output, size_t size) _emit 0x0f _emit 0xa7 _emit 0xc0 + and eax, 0x1f mov result, eax } - const size_t ret = (m_msr = result) & 0x1f; - const size_t rem = STDMIN(ret, STDMIN(size, 16U /*buffer size*/)); + const size_t rem = STDMIN(m_msr, STDMIN(size, 16U /*buffer size*/)); std::memcpy(output, buffer, rem); size -= rem; output += rem; } -- cgit v1.2.1