1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-19 08:52:25 +00:00

exo2: use N's strategy for randcache, it's better

This commit is contained in:
Michael Scire 2020-05-13 20:44:13 -07:00 committed by SciresM
parent b7ff9e8fcc
commit 63629b22a1

View file

@ -86,17 +86,15 @@ namespace ams::secmon::smc {
u8 * const cache = GetRandomBytesCache(); u8 * const cache = GetRandomBytesCache();
u8 * cur_dst = static_cast<u8 *>(dst); u8 * cur_dst = static_cast<u8 *>(dst);
/* NOTE: Nintendo does not do bounds checking here, and does not do multiple reads when the get would wrap around. */ /* Copy out the requested size. */
while (size > 0) { std::memcpy(dst, cache + g_random_offset_low, size);
const size_t copy_size = std::min(size, static_cast<size_t>(GetRandomBytesCacheSize() - g_random_offset_low));
std::memcpy(cur_dst, cache + g_random_offset_low, copy_size);
cur_dst += copy_size; /* Advance. */
size -= copy_size; g_random_offset_low += size;
if (g_random_offset_low + copy_size >= GetRandomBytesCacheSize()) { /* Ensure that at all times g_random_offset_low is not within 0x38 bytes of the end of the pool. */
g_random_offset_low = 0; if (g_random_offset_low + MaxRandomBytes >= GetRandomBytesCacheSize()) {
} g_random_offset_low = 0;
} }
} }