mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-11-10 06:01:52 +00:00
exo2: use N's strategy for randcache, it's better
This commit is contained in:
parent
b7ff9e8fcc
commit
63629b22a1
1 changed files with 7 additions and 9 deletions
|
@ -86,18 +86,16 @@ namespace ams::secmon::smc {
|
|||
u8 * const cache = GetRandomBytesCache();
|
||||
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. */
|
||||
while (size > 0) {
|
||||
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);
|
||||
/* Copy out the requested size. */
|
||||
std::memcpy(dst, cache + g_random_offset_low, size);
|
||||
|
||||
cur_dst += copy_size;
|
||||
size -= copy_size;
|
||||
/* Advance. */
|
||||
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. */
|
||||
if (g_random_offset_low + MaxRandomBytes >= GetRandomBytesCacheSize()) {
|
||||
g_random_offset_low = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue