* Hardcode the key and ensure buffers are appropriately sized. If you do want to build the key at runtime the following initial state gets the right sequence: ```cpp std::linear_congruential_engine<uint32_t, 214013, 2531011, 0> engine(3193970784); for (auto ¬ch: key) notch = static_cast<byte>(engine() >> 16); ``` * Move public defines into sha.h, move private struct into .cpp * Remove unused count member, clarify loop in SHA1Input * Update circular shift to indicate desired behaviour, remove unnecessary negation. The parameters are also reordered to match C++20 rotl/rotr and the usual order for shift operators.
22 lines
523 B
C++
22 lines
523 B
C++
/**
|
|
* @file sha.cpp
|
|
*
|
|
* Interface of functionality for calculating X-SHA-1 (a flawed implementation of SHA-1).
|
|
*/
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include "utils/stdcompat/cstddef.hpp"
|
|
|
|
namespace devilution {
|
|
|
|
constexpr size_t BlockSize = 64;
|
|
constexpr size_t SHA1HashSize = 20;
|
|
|
|
void SHA1Clear();
|
|
void SHA1Result(int n, byte messageDigest[SHA1HashSize]);
|
|
void SHA1Calculate(int n, const byte data[BlockSize], byte messageDigest[SHA1HashSize]);
|
|
void SHA1Reset(int n);
|
|
|
|
} // namespace devilution
|