mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-30 05:08:56 +00:00
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:
21
Libraries/LibCrypto/SecureRandom.cpp
Normal file
21
Libraries/LibCrypto/SecureRandom.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright (c) 2024, the Ladybird developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCrypto/SecureRandom.h>
|
||||
|
||||
#include <openssl/rand.h>
|
||||
|
||||
namespace Crypto {
|
||||
|
||||
void fill_with_secure_random(Bytes bytes)
|
||||
{
|
||||
auto const size = static_cast<int>(bytes.size());
|
||||
|
||||
if (RAND_bytes(bytes.data(), size) != 1)
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user