Meta+LibCrypto: Add SecureRandom and replace PRNG usage with it

This adds a thin wrapper to LibCrypto for generating cryptographically
secure random values and replaces current usages of PRNG within
LibCrypto as well.
This commit is contained in:
rmg-x 2024-12-20 10:32:11 -06:00 committed by Ali Mohammad Pur
parent b981e6f7bc
commit f55f507e56
Notes: github-actions[bot] 2024-12-24 16:56:11 +00:00
10 changed files with 50 additions and 6 deletions

View file

@ -8,6 +8,7 @@
#include <AK/Random.h>
#include <LibCrypto/BigInt/Algorithms/UnsignedBigIntegerAlgorithms.h>
#include <LibCrypto/NumberTheory/ModularFunctions.h>
#include <LibCrypto/SecureRandom.h>
namespace Crypto::NumberTheory {
@ -172,7 +173,7 @@ UnsignedBigInteger random_number(UnsignedBigInteger const& min, UnsignedBigInteg
auto buffer = ByteBuffer::create_uninitialized(size).release_value_but_fixme_should_propagate_errors(); // FIXME: Handle possible OOM situation.
auto* buf = buffer.data();
fill_with_random(buffer);
fill_with_secure_random(buffer);
UnsignedBigInteger random { buf, size };
// At this point, `random` is a large number, in the range [0, 256^size).
// To get down to the actual range, we could just compute random % range.