hash/md2: prefer cruft::std types

This commit is contained in:
Danny Robson 2019-02-04 20:00:44 +11:00
parent 88ad70df40
commit c0e1e0b7b6

View File

@ -8,6 +8,7 @@
#include "md2.hpp"
#include <cruft/util/std.hpp>
#include <cruft/util/debug.hpp>
#include <cruft/util/types.hpp>
@ -21,7 +22,7 @@ using cruft::crypto::hash::MD2;
///////////////////////////////////////////////////////////////////////////////
static constexpr std::array<uint8_t,256> S = { {
static constexpr std::array<u08,256> S = { {
41, 46, 67, 201, 162, 216, 124, 1, 61, 54, 84, 161, 236, 240, 6, 19,
98, 167, 5, 243, 192, 199, 115, 140, 152, 147, 43, 217, 188, 76, 130, 202,
30, 155, 87, 60, 253, 212, 224, 22, 103, 66, 111, 24, 138, 23, 229, 18,
@ -48,7 +49,7 @@ static const size_t M_LENGTH = 16;
///////////////////////////////////////////////////////////////////////////////
static void
transform (std::array<uint8_t,16> &C, std::array<uint8_t,48> &X) noexcept
transform (std::array<u08,16> &C, std::array<u08,48> &X) noexcept
{
cruft::view M { X.data () + M_OFFSET, M_LENGTH };
@ -56,7 +57,7 @@ transform (std::array<uint8_t,16> &C, std::array<uint8_t,48> &X) noexcept
// XXX: I can't see why we need the xor-assign from the spec, but it's the
// only change keeping us from conforming to the test-cases. Pulled from a
// review of the reference implementation.
uint8_t L = C[15];
u08 L = C[15];
for (size_t i = 0; i < std::size (C); ++i)
L = C[i] ^= S[M[i] ^ L];
@ -77,12 +78,12 @@ transform (std::array<uint8_t,16> &C, std::array<uint8_t,48> &X) noexcept
///////////////////////////////////////////////////////////////////////////////
MD2::digest_t
MD2::operator() (const cruft::view<const uint8_t*> data) const noexcept
MD2::operator() (const cruft::view<const u08*> data) const noexcept
{
// zero initialise the state vectors, and create a simple window `M' into
// the middle of the `X' state vector.
std::array<uint8_t,16> C {};
std::array<uint8_t,48> X {};
std::array<u08,16> C {};
std::array<u08,48> X {};
const cruft::view M { std::begin (X) + M_OFFSET, M_LENGTH };
// process each complete block by copying to the window `M' and