summaryrefslogtreecommitdiff
path: root/padlkrng.cpp
diff options
context:
space:
mode:
authorJeffrey Walton <noloader@gmail.com>2020-07-27 11:41:28 -0400
committerJeffrey Walton <noloader@gmail.com>2020-07-27 11:41:28 -0400
commitabd8b7a991e24a3b5fdd80be6a60c904c092b7a0 (patch)
treec4f5e42604b4bf264c8fe56c0625a0affcb266f7 /padlkrng.cpp
parent24dd6960fc278b45efa25a56b5fba37d8ffa174f (diff)
downloadcryptopp-git-abd8b7a991e24a3b5fdd80be6a60c904c092b7a0.tar.gz
Update Padlock RNG GenerateBlock
Diffstat (limited to 'padlkrng.cpp')
-rw-r--r--padlkrng.cpp15
1 files changed, 11 insertions, 4 deletions
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<size_t>(ret, STDMIN<size_t>(size, 16U /*buffer size*/));
+ const size_t rem = STDMIN<size_t>(m_msr, STDMIN<size_t>(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<size_t>(ret, STDMIN<size_t>(size, 16U /*buffer size*/));
+ const size_t rem = STDMIN<size_t>(m_msr, STDMIN<size_t>(size, 16U /*buffer size*/));
std::memcpy(output, buffer, rem);
size -= rem; output += rem;
}