1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:37:46 +00:00

AK+Everywhere: Change AK::fill_with_random to accept a Bytes object

Rather than the very C-like API we currently have, accepting a void* and
a length, let's take a Bytes object instead. In almost all existing
cases, the compiler figures out the length.
This commit is contained in:
Timothy Flynn 2023-04-02 13:08:43 -04:00 committed by Andreas Kling
parent 5c045b6934
commit 15532df83d
20 changed files with 37 additions and 39 deletions

View file

@ -343,12 +343,13 @@ void RSA_PKCS1_EME::encrypt(ReadonlyBytes in, Bytes& out)
Vector<u8, 8096> ps;
ps.resize(ps_length);
fill_with_random(ps.data(), ps_length);
fill_with_random(ps);
// since fill_with_random can create zeros (shocking!)
// we have to go through and un-zero the zeros
for (size_t i = 0; i < ps_length; ++i)
for (size_t i = 0; i < ps_length; ++i) {
while (!ps[i])
fill_with_random(ps.span().offset(i), 1);
ps[i] = get_random<u8>();
}
u8 paddings[] { 0x00, 0x02 };