From c1dd67e7929b94700bd4bdb2e1856d95e5b30cc4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Wed, 27 May 2020 12:28:17 +0200 Subject: LibCrypto+LibTLS: Use AK/Random.h This makes it possible to build both of these on Linux. --- Libraries/LibTLS/ClientHandshake.cpp | 8 +++++--- Libraries/LibTLS/Handshake.cpp | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'Libraries/LibTLS') diff --git a/Libraries/LibTLS/ClientHandshake.cpp b/Libraries/LibTLS/ClientHandshake.cpp index 31bff96e8d..dcf20543d9 100644 --- a/Libraries/LibTLS/ClientHandshake.cpp +++ b/Libraries/LibTLS/ClientHandshake.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -245,12 +246,13 @@ void TLSv12::build_random(PacketBuilder& builder) u8 random_bytes[48]; size_t bytes = 48; - arc4random_buf(random_bytes, bytes); + AK::fill_with_random(random_bytes, bytes); // remove zeros from the random bytes - for (size_t i = 0; i < bytes; ++i) + for (size_t i = 0; i < bytes; ++i) { if (!random_bytes[i]) - random_bytes[i--] = arc4random(); + random_bytes[i--] = AK::get_random(); + } if (m_context.is_server) { dbg() << "Server mode not supported"; diff --git a/Libraries/LibTLS/Handshake.cpp b/Libraries/LibTLS/Handshake.cpp index 1f059d5226..e209f11d8a 100644 --- a/Libraries/LibTLS/Handshake.cpp +++ b/Libraries/LibTLS/Handshake.cpp @@ -24,6 +24,7 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -33,7 +34,7 @@ namespace TLS { ByteBuffer TLSv12::build_hello() { - arc4random_buf(&m_context.local_random, 32); + AK::fill_with_random(&m_context.local_random, 32); auto packet_version = (u16)m_context.version; auto version = (u16)m_context.version; @@ -42,7 +43,7 @@ ByteBuffer TLSv12::build_hello() builder.append((u8)ClientHello); // hello length (for later) - u8 dummy[3]; + u8 dummy[3] = {}; builder.append(dummy, 3); auto start_length = builder.length(); -- cgit v1.2.3