diff options
author | Andreas Kling <kling@serenityos.org> | 2020-05-27 12:28:17 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-27 12:28:17 +0200 |
commit | c1dd67e7929b94700bd4bdb2e1856d95e5b30cc4 (patch) | |
tree | f5f7e2b31ff3923af33c16a7265882fb89578013 /Libraries/LibTLS | |
parent | 9a113b0229dbebfd5f880cd40661c1d0a11a8ff8 (diff) | |
download | serenity-c1dd67e7929b94700bd4bdb2e1856d95e5b30cc4.zip |
LibCrypto+LibTLS: Use AK/Random.h
This makes it possible to build both of these on Linux.
Diffstat (limited to 'Libraries/LibTLS')
-rw-r--r-- | Libraries/LibTLS/ClientHandshake.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibTLS/Handshake.cpp | 5 |
2 files changed, 8 insertions, 5 deletions
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 <AK/Random.h> #include <LibCore/Timer.h> #include <LibCrypto/ASN1/DER.h> #include <LibCrypto/PK/Code/EMSA_PSS.h> @@ -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<u8>(); + } 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 <AK/Random.h> #include <LibCore/Timer.h> #include <LibCrypto/ASN1/DER.h> #include <LibCrypto/PK/Code/EMSA_PSS.h> @@ -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(); |