diff --git a/Libraries/LibCrypto/CMakeLists.txt b/Libraries/LibCrypto/CMakeLists.txt index 4277f33db6b..06248104ac3 100644 --- a/Libraries/LibCrypto/CMakeLists.txt +++ b/Libraries/LibCrypto/CMakeLists.txt @@ -17,7 +17,6 @@ set(SOURCES BigInt/SignedBigInteger.cpp BigInt/UnsignedBigInteger.cpp Certificate/Certificate.cpp - Checksum/Adler32.cpp Checksum/cksum.cpp Checksum/CRC32.cpp Cipher/AES.cpp diff --git a/Libraries/LibCrypto/Checksum/Adler32.cpp b/Libraries/LibCrypto/Checksum/Adler32.cpp deleted file mode 100644 index eaff83f7d3c..00000000000 --- a/Libraries/LibCrypto/Checksum/Adler32.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (c) 2020, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include -#include - -namespace Crypto::Checksum { - -void Adler32::update(ReadonlyBytes data) -{ - // See https://github.com/SerenityOS/serenity/pull/24408#discussion_r1609051678 - constexpr size_t iterations_without_overflow = 380368439; - - u64 state_a = m_state_a; - u64 state_b = m_state_b; - while (data.size()) { - // You can verify that no overflow will happen here during at least - // `iterations_without_overflow` iterations using the following Python script: - // - // state_a = 65520 - // state_b = 65520 - // for i in range(380368439): - // state_a += 255 - // state_b += state_a - // print(state_b < 2 ** 64) - auto chunk = data.slice(0, min(data.size(), iterations_without_overflow)); - for (u8 byte : chunk) { - state_a += byte; - state_b += state_a; - } - state_a %= 65521; - state_b %= 65521; - data = data.slice(chunk.size()); - } - m_state_a = state_a; - m_state_b = state_b; -} - -u32 Adler32::digest() -{ - return (m_state_b << 16) | m_state_a; -} - -} diff --git a/Libraries/LibCrypto/Checksum/Adler32.h b/Libraries/LibCrypto/Checksum/Adler32.h deleted file mode 100644 index 1f0292c0208..00000000000 --- a/Libraries/LibCrypto/Checksum/Adler32.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (c) 2020-2022, the SerenityOS developers. - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include -#include - -namespace Crypto::Checksum { - -class Adler32 : public ChecksumFunction { -public: - Adler32() = default; - Adler32(ReadonlyBytes data) - { - update(data); - } - - Adler32(u32 initial_a, u32 initial_b, ReadonlyBytes data) - : m_state_a(initial_a) - , m_state_b(initial_b) - { - update(data); - } - - virtual void update(ReadonlyBytes data) override; - virtual u32 digest() override; - -private: - u32 m_state_a { 1 }; - u32 m_state_b { 0 }; -}; - -} diff --git a/Tests/LibCrypto/TestChecksum.cpp b/Tests/LibCrypto/TestChecksum.cpp index 93b370a1330..2c5574266b3 100644 --- a/Tests/LibCrypto/TestChecksum.cpp +++ b/Tests/LibCrypto/TestChecksum.cpp @@ -4,25 +4,10 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include -TEST_CASE(test_adler32) -{ - auto do_test = [](ReadonlyBytes input, u32 expected_result) { - auto digest = Crypto::Checksum::Adler32(input).digest(); - EXPECT_EQ(digest, expected_result); - }; - - do_test(""sv.bytes(), 0x1); - do_test("a"sv.bytes(), 0x00620062); - do_test("abc"sv.bytes(), 0x024d0127); - do_test("message digest"sv.bytes(), 0x29750586); - do_test("abcdefghijklmnopqrstuvwxyz"sv.bytes(), 0x90860b20); -} - TEST_CASE(test_cksum) { auto do_test = [](ReadonlyBytes input, u32 expected_result) {