2020-07-29 18:24:54 +00:00
|
|
|
/*
|
2022-02-26 17:32:08 +00:00
|
|
|
* Copyright (c) 2020-2022, the SerenityOS developers.
|
2020-07-29 18:24:54 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-07-29 18:24:54 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Span.h>
|
|
|
|
#include <AK/Types.h>
|
2020-08-17 13:25:49 +00:00
|
|
|
#include <LibCrypto/Checksum/ChecksumFunction.h>
|
2020-07-29 18:24:54 +00:00
|
|
|
|
|
|
|
namespace Crypto::Checksum {
|
|
|
|
|
|
|
|
class Adler32 : public ChecksumFunction<u32> {
|
|
|
|
public:
|
2022-02-26 17:32:08 +00:00
|
|
|
Adler32() = default;
|
2020-07-29 18:24:54 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-04 09:09:09 +00:00
|
|
|
virtual void update(ReadonlyBytes data) override;
|
|
|
|
virtual u32 digest() override;
|
2020-07-29 18:24:54 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
u32 m_state_a { 1 };
|
|
|
|
u32 m_state_b { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|