mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibCrypto: Remove unused Adler32
class
This commit is contained in:
parent
1c2b373e9c
commit
0561d130f3
Notes:
github-actions[bot]
2025-03-19 12:48:34 +00:00
Author: https://github.com/devgianlu Commit: https://github.com/LadybirdBrowser/ladybird/commit/0561d130f3f Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3755 Reviewed-by: https://github.com/gmta ✅ Reviewed-by: https://github.com/trflynn89
4 changed files with 0 additions and 102 deletions
|
@ -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
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Span.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCrypto/Checksum/Adler32.h>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022, the SerenityOS developers.
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Span.h>
|
||||
#include <AK/Types.h>
|
||||
#include <LibCrypto/Checksum/ChecksumFunction.h>
|
||||
|
||||
namespace Crypto::Checksum {
|
||||
|
||||
class Adler32 : public ChecksumFunction<u32> {
|
||||
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 };
|
||||
};
|
||||
|
||||
}
|
|
@ -4,25 +4,10 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibCrypto/Checksum/Adler32.h>
|
||||
#include <LibCrypto/Checksum/CRC32.h>
|
||||
#include <LibCrypto/Checksum/cksum.h>
|
||||
#include <LibTest/TestCase.h>
|
||||
|
||||
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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue