Truly independent web browser
LibCrypto: Remove MD5 and BLAKE2b
Shannon Booth2e7e07aad2bb
diff --git a/Libraries/LibCrypto/CMakeLists.txt b/Libraries/LibCrypto/CMakeLists.txtindex 0d26f683df8..9fee8705ae9 100644--- a/Libraries/LibCrypto/CMakeLists.txt+++ b/Libraries/LibCrypto/CMakeLists.txt@@ -17,9 +17,7 @@ set(SOURCESCurves/SECPxxxr1.cppHash/Argon2.cppHash/SHAKE.cpp- Hash/BLAKE2b.cppHash/HKDF.cpp- Hash/MD5.cppHash/PBKDF2.cppHash/SHA1.cppHash/SHA2.cppdiff --git a/Libraries/LibCrypto/Hash/BLAKE2b.cpp b/Libraries/LibCrypto/Hash/BLAKE2b.cppdeleted file mode 100644index f9a8ab0d38a..00000000000--- a/Libraries/LibCrypto/Hash/BLAKE2b.cpp+++ /dev/null@@ -1,18 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibCrypto/Hash/BLAKE2b.h>--#include <openssl/evp.h>--namespace Crypto::Hash {--BLAKE2b::BLAKE2b(EVP_MD_CTX* context)- : OpenSSLHashFunction(EVP_blake2b512(), context)-{-}--}diff --git a/Libraries/LibCrypto/Hash/BLAKE2b.h b/Libraries/LibCrypto/Hash/BLAKE2b.hdeleted file mode 100644index cd1b37cdd02..00000000000--- a/Libraries/LibCrypto/Hash/BLAKE2b.h+++ /dev/null@@ -1,26 +0,0 @@-/*- * Copyright (c) 2023, the SerenityOS developers- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/ByteString.h>-#include <LibCrypto/Hash/OpenSSLHashFunction.h>--namespace Crypto::Hash {--class BLAKE2b final : public OpenSSLHashFunction<BLAKE2b, 1024, 512> {- AK_MAKE_NONCOPYABLE(BLAKE2b);--public:- explicit BLAKE2b(EVP_MD_CTX* context);-- virtual ByteString class_name() const override- {- return "BLAKE2b";- }-};--};diff --git a/Libraries/LibCrypto/Hash/HashManager.h b/Libraries/LibCrypto/Hash/HashManager.hindex 9ec4d8b2e80..237292928b8 100644--- a/Libraries/LibCrypto/Hash/HashManager.h+++ b/Libraries/LibCrypto/Hash/HashManager.h@@ -9,9 +9,7 @@#include <AK/Optional.h>#include <AK/OwnPtr.h>#include <AK/Variant.h>-#include <LibCrypto/Hash/BLAKE2b.h>#include <LibCrypto/Hash/HashFunction.h>-#include <LibCrypto/Hash/MD5.h>#include <LibCrypto/Hash/SHA1.h>#include <LibCrypto/Hash/SHA2.h>#include <LibCrypto/Hash/SHA3.h>@@ -21,8 +19,6 @@ namespace Crypto::Hash {enum class HashKind {Unknown,None,- BLAKE2b,- MD5,SHA1,SHA256,SHA384,@@ -40,11 +36,6 @@ struct MultiHashDigestVariant {{}- MultiHashDigestVariant(MD5::DigestType digest)- : m_digest(move(digest))- {- }-MultiHashDigestVariant(SHA1::DigestType digest): m_digest(move(digest)){@@ -86,7 +77,7 @@ struct MultiHashDigestVariant {[&](auto const& value) { return value.bytes(); });}- using DigestVariant = Variant<Empty, MD5::DigestType, SHA1::DigestType, SHA256::DigestType, SHA384::DigestType, SHA512::DigestType>;+ using DigestVariant = Variant<Empty, SHA1::DigestType, SHA256::DigestType, SHA384::DigestType, SHA512::DigestType>;DigestVariant m_digest {};};@@ -143,12 +134,6 @@ public:m_kind = kind;switch (kind) {- case HashKind::BLAKE2b:- m_algorithm = BLAKE2b::create();- break;- case HashKind::MD5:- m_algorithm = MD5::create();- break;case HashKind::SHA1:m_algorithm = SHA1::create();break;@@ -246,8 +231,6 @@ public:private:using AlgorithmVariant = Variant<Empty,- NonnullOwnPtr<BLAKE2b>,- NonnullOwnPtr<MD5>,NonnullOwnPtr<SHA1>,NonnullOwnPtr<SHA256>,NonnullOwnPtr<SHA384>,diff --git a/Libraries/LibCrypto/Hash/MD5.cpp b/Libraries/LibCrypto/Hash/MD5.cppdeleted file mode 100644index c33edaed8a6..00000000000--- a/Libraries/LibCrypto/Hash/MD5.cpp+++ /dev/null@@ -1,18 +0,0 @@-/*- * Copyright (c) 2025, Altomani Gianluca <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibCrypto/Hash/MD5.h>--#include <openssl/evp.h>--namespace Crypto::Hash {--MD5::MD5(EVP_MD_CTX* context)- : OpenSSLHashFunction(EVP_md5(), context)-{-}--}diff --git a/Libraries/LibCrypto/Hash/MD5.h b/Libraries/LibCrypto/Hash/MD5.hdeleted file mode 100644index c140b0fe52f..00000000000--- a/Libraries/LibCrypto/Hash/MD5.h+++ /dev/null@@ -1,26 +0,0 @@-/*- * Copyright (c) 2020, Ali Mohammad Pur <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/ByteString.h>-#include <LibCrypto/Hash/OpenSSLHashFunction.h>--namespace Crypto::Hash {--class MD5 final : public OpenSSLHashFunction<MD5, 512, 128> {- AK_MAKE_NONCOPYABLE(MD5);--public:- explicit MD5(EVP_MD_CTX* context);-- virtual ByteString class_name() const override- {- return "MD5";- }-};--}diff --git a/Libraries/LibCrypto/OpenSSL.cpp b/Libraries/LibCrypto/OpenSSL.cppindex 2a61680b6cb..9a33f92b006 100644--- a/Libraries/LibCrypto/OpenSSL.cpp+++ b/Libraries/LibCrypto/OpenSSL.cpp@@ -52,8 +52,6 @@ ErrorOr<UnsignedBigInteger> openssl_bignum_to_unsigned_big_integer(OpenSSL_BN coErrorOr<StringView> hash_kind_to_openssl_digest_name(Hash::HashKind hash){switch (hash) {- case Hash::HashKind::MD5:- return "MD5"sv;case Hash::HashKind::SHA1:return "SHA1"sv;case Hash::HashKind::SHA256:diff --git a/Libraries/LibCrypto/PK/RSA.cpp b/Libraries/LibCrypto/PK/RSA.cppindex f7dcbe3b01c..2d629a02816 100644--- a/Libraries/LibCrypto/PK/RSA.cpp+++ b/Libraries/LibCrypto/PK/RSA.cpp@@ -447,10 +447,6 @@ ErrorOr<EVP_MD const*> hash_kind_to_hash_type(Hash::HashKind hash_kind)switch (hash_kind) {case Hash::HashKind::None:return nullptr;- case Hash::HashKind::BLAKE2b:- return EVP_blake2b512();- case Hash::HashKind::MD5:- return EVP_md5();case Hash::HashKind::SHA1:return EVP_sha1();case Hash::HashKind::SHA256:diff --git a/Libraries/LibCrypto/Rust/src/lib.rs b/Libraries/LibCrypto/Rust/src/lib.rsindex 617e3b8c508..b4597a4ebd1 100644--- a/Libraries/LibCrypto/Rust/src/lib.rs+++ b/Libraries/LibCrypto/Rust/src/lib.rs@@ -27,7 +27,7 @@ pub struct BackendError;#[repr(i32)]pub enum ShaHashKind {- Sha1 = 4,+ Sha1 = 2,Sha256,Sha384,Sha512,diff --git a/Libraries/LibCrypto/RustBindings.cpp b/Libraries/LibCrypto/RustBindings.cppindex da11d05e5ba..4a5b902fc52 100644--- a/Libraries/LibCrypto/RustBindings.cpp+++ b/Libraries/LibCrypto/RustBindings.cpp@@ -431,13 +431,13 @@ FlatPtr crypto_aes_ocb_cipher(bool encrypt, ReadonlyBytes key, ReadonlyBytes inpreturn 0;}-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA1) == 4);-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA256) == 5);-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA384) == 6);-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA512) == 7);-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA3_256) == 8);-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA3_384) == 9);-static_assert(to_underlying(::Crypto::Hash::HashKind::SHA3_512) == 10);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA1) == 2);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA256) == 3);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA384) == 4);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA512) == 5);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA3_256) == 6);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA3_384) == 7);+static_assert(to_underlying(::Crypto::Hash::HashKind::SHA3_512) == 8);extern "C" bool crypto_sha_digest(::Crypto::Hash::HashKind, ReadonlyBytes, void*, ReceiveEncodedBytes);diff --git a/Tests/LibCrypto/TestHMAC.cpp b/Tests/LibCrypto/TestHMAC.cppindex 42703cf1c98..a2e4281dd38 100644--- a/Tests/LibCrypto/TestHMAC.cpp+++ b/Tests/LibCrypto/TestHMAC.cpp@@ -13,17 +13,6 @@ static ByteBuffer operator""_b(char const* string, size_t length)return MUST(ByteBuffer::copy(string, length));}-TEST_CASE(test_hmac_md5_process)-{- auto key = "Well Hello Friends"_b;- Crypto::Authentication::HMAC hmac(Crypto::Hash::HashKind::MD5, key);- u8 result[] {- 0x3b, 0x5b, 0xde, 0x30, 0x3a, 0x54, 0x7b, 0xbb, 0x09, 0xfe, 0x78, 0x89, 0xbc, 0x9f, 0x22, 0xa3- };- auto mac = hmac.process("Some bogus data"sv);- EXPECT(memcmp(result, mac.data(), hmac.digest_size()) == 0);-}-TEST_CASE(test_hmac_sha256_process){auto key = "Well Hello Friends"_b;diff --git a/Tests/LibCrypto/TestHash.cpp b/Tests/LibCrypto/TestHash.cppindex 2504fa9ae0c..ff2212ff1f4 100644--- a/Tests/LibCrypto/TestHash.cpp+++ b/Tests/LibCrypto/TestHash.cpp@@ -5,104 +5,11 @@*/#include <LibCrypto/Authentication/HMAC.h>-#include <LibCrypto/Hash/BLAKE2b.h>-#include <LibCrypto/Hash/MD5.h>#include <LibCrypto/Hash/SHA1.h>#include <LibCrypto/Hash/SHA2.h>#include <LibTest/TestCase.h>#include <cstring>-TEST_CASE(test_BLAKE2b_hash_string)-{- u8 result[] {- 0x9d, 0xaa, 0x2e, 0x57, 0xc4, 0x94, 0xb6, 0xfd, 0x61, 0x6e, 0x39, 0x0b, 0x71, 0xf4, 0x19, 0x03, 0x41, 0x5c, 0x5c, 0x61, 0x7e, 0x30, 0x0a, 0xf0, 0x0b, 0x3e, 0x9c, 0x77, 0x23, 0x1f, 0x11, 0x4d, 0x83, 0x9d, 0xd6, 0xe0, 0x4a, 0x92, 0x19, 0xae, 0xec, 0xc9, 0x13, 0x57, 0xc6, 0xf1, 0x06, 0x92, 0xb9, 0xf9, 0x97, 0x3e, 0xfd, 0xb3, 0x6f, 0xc8, 0xe1, 0x94, 0xad, 0x8e, 0x33, 0xc2, 0x66, 0x3f- };- auto digest = Crypto::Hash::BLAKE2b::hash("Well hello friends"sv);- EXPECT(memcmp(result, digest.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);-}--TEST_CASE(test_BLAKE2b_hash_empty_string)-{- u8 result[] {- 0x78, 0x6a, 0x02, 0xf7, 0x42, 0x01, 0x59, 0x03, 0xc6, 0xc6, 0xfd, 0x85, 0x25, 0x52, 0xd2, 0x72, 0x91, 0x2f, 0x47, 0x40, 0xe1, 0x58, 0x47, 0x61, 0x8a, 0x86, 0xe2, 0x17, 0xf7, 0x1f, 0x54, 0x19, 0xd2, 0x5e, 0x10, 0x31, 0xaf, 0xee, 0x58, 0x53, 0x13, 0x89, 0x64, 0x44, 0x93, 0x4e, 0xb0, 0x4b, 0x90, 0x3a, 0x68, 0x5b, 0x14, 0x48, 0xb7, 0x55, 0xd5, 0x6f, 0x70, 0x1a, 0xfe, 0x9b, 0xe2, 0xce- };- auto digest = Crypto::Hash::BLAKE2b::hash(""sv);- EXPECT(memcmp(result, digest.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);-}--TEST_CASE(test_BLAKE2b_consecutive_multiple_updates)-{- u8 result[] {- 0x9d, 0xaa, 0x2e, 0x57, 0xc4, 0x94, 0xb6, 0xfd, 0x61, 0x6e, 0x39, 0x0b, 0x71, 0xf4, 0x19, 0x03, 0x41, 0x5c, 0x5c, 0x61, 0x7e, 0x30, 0x0a, 0xf0, 0x0b, 0x3e, 0x9c, 0x77, 0x23, 0x1f, 0x11, 0x4d, 0x83, 0x9d, 0xd6, 0xe0, 0x4a, 0x92, 0x19, 0xae, 0xec, 0xc9, 0x13, 0x57, 0xc6, 0xf1, 0x06, 0x92, 0xb9, 0xf9, 0x97, 0x3e, 0xfd, 0xb3, 0x6f, 0xc8, 0xe1, 0x94, 0xad, 0x8e, 0x33, 0xc2, 0x66, 0x3f- };- auto blake2b = Crypto::Hash::BLAKE2b::create();-- blake2b->update("Well"sv);- blake2b->update(" hello "sv);- blake2b->update("friends"sv);- auto digest = blake2b->digest();-- EXPECT(memcmp(result, digest.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);-}--TEST_CASE(test_BLAKE2b_consecutive_updates_reuse)-{- auto blake2b = Crypto::Hash::BLAKE2b::create();-- blake2b->update("Well"sv);- blake2b->update(" hello "sv);- blake2b->update("friends"sv);- auto digest0 = blake2b->digest();-- blake2b->update("Well"sv);- blake2b->update(" hello "sv);- blake2b->update("friends"sv);- auto digest1 = blake2b->digest();-- EXPECT(memcmp(digest0.data, digest1.data, Crypto::Hash::BLAKE2b::digest_size()) == 0);-}--TEST_CASE(test_MD5_hash_string)-{- u8 result[] {- 0xaf, 0x04, 0x3a, 0x08, 0x94, 0x38, 0x6e, 0x7f, 0xbf, 0x73, 0xe4, 0xaa, 0xf0, 0x8e, 0xee, 0x4c- };- auto digest = Crypto::Hash::MD5::hash("Well hello friends"sv);- EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);-}--TEST_CASE(test_MD5_consecutive_multiple_updates)-{- u8 result[] {- 0xaf, 0x04, 0x3a, 0x08, 0x94, 0x38, 0x6e, 0x7f, 0xbf, 0x73, 0xe4, 0xaa, 0xf0, 0x8e, 0xee, 0x4c- };- auto md5 = Crypto::Hash::MD5::create();-- md5->update("Well"sv);- md5->update(" hello "sv);- md5->update("friends"sv);- auto digest = md5->digest();-- EXPECT(memcmp(result, digest.data, Crypto::Hash::MD5::digest_size()) == 0);-}--TEST_CASE(test_MD5_consecutive_updates_reuse)-{- auto md5 = Crypto::Hash::MD5::create();-- md5->update("Well"sv);- md5->update(" hello "sv);- md5->update("friends"sv);- auto digest0 = md5->digest();-- md5->update("Well"sv);- md5->update(" hello "sv);- md5->update("friends"sv);- auto digest1 = md5->digest();-- EXPECT(memcmp(digest0.data, digest1.data, Crypto::Hash::MD5::digest_size()) == 0);-}-TEST_CASE(test_SHA1_hash_successive_updates){u8 result[] {