duckstation/src/common/sha1_digest.h

37 lines
734 B
C
Raw Normal View History

2024-08-26 11:27:51 +00:00
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
2024-09-01 12:08:31 +00:00
// SPDX-License-Identifier: CC-BY-NC-ND-4.0
2022-08-15 13:53:31 +00:00
#pragma once
2024-08-26 11:27:51 +00:00
2022-08-15 13:53:31 +00:00
#include "types.h"
2024-08-26 11:27:51 +00:00
#include <array>
#include <span>
2024-09-19 12:19:51 +00:00
#include <string>
2022-08-15 13:53:31 +00:00
class SHA1Digest
{
public:
enum : u32
{
DIGEST_SIZE = 20
};
SHA1Digest();
2024-08-26 11:27:51 +00:00
void Update(const void* data, size_t len);
void Update(std::span<const u8> data);
2022-08-15 13:53:31 +00:00
void Final(u8 digest[DIGEST_SIZE]);
void Reset();
2024-09-19 12:19:51 +00:00
static std::string DigestToString(const std::span<const u8, DIGEST_SIZE> digest);
2024-08-26 11:27:51 +00:00
static std::array<u8, DIGEST_SIZE> GetDigest(const void* data, size_t len);
static std::array<u8, DIGEST_SIZE> GetDigest(std::span<const u8> data);
2022-08-15 13:53:31 +00:00
private:
u32 state[5];
u32 count[2];
u8 buffer[64];
};