hash/ripemd: use cruft::std types

This commit is contained in:
Danny Robson 2019-02-04 19:37:26 +11:00
parent dcc81c5e97
commit 88ad70df40

View File

@ -9,6 +9,7 @@
#include "ripemd.hpp"
#include <cruft/util/std.hpp>
#include <cruft/util/debug.hpp>
#include <cruft/util/bitwise.hpp>
@ -19,8 +20,8 @@ using cruft::crypto::hash::RIPEMD;
///////////////////////////////////////////////////////////////////////////////
static constexpr
uint32_t
f1 (uint32_t x, uint32_t y, uint32_t z)
u32
f1 (u32 x, u32 y, u32 z)
{
return x ^ y ^ z;
}
@ -28,8 +29,8 @@ f1 (uint32_t x, uint32_t y, uint32_t z)
//-----------------------------------------------------------------------------
static constexpr
uint32_t
f2 (uint32_t x, uint32_t y, uint32_t z)
u32
f2 (u32 x, u32 y, u32 z)
{
return (x & y) | (~x & z);
}
@ -37,8 +38,8 @@ f2 (uint32_t x, uint32_t y, uint32_t z)
//-----------------------------------------------------------------------------
static constexpr
uint32_t
f3 (uint32_t x, uint32_t y, uint32_t z)
u32
f3 (u32 x, u32 y, u32 z)
{
return (x | ~y) ^ z;
}
@ -46,8 +47,8 @@ f3 (uint32_t x, uint32_t y, uint32_t z)
//-----------------------------------------------------------------------------
static constexpr
uint32_t
f4 (uint32_t x, uint32_t y, uint32_t z)
u32
f4 (u32 x, u32 y, u32 z)
{
return (x & z) | (y & ~z);
}
@ -55,8 +56,8 @@ f4 (uint32_t x, uint32_t y, uint32_t z)
//-----------------------------------------------------------------------------
static constexpr
uint32_t
f5 (uint32_t x, uint32_t y, uint32_t z)
u32
f5 (u32 x, u32 y, u32 z)
{
return x ^ (y | ~z);
}
@ -64,7 +65,7 @@ f5 (uint32_t x, uint32_t y, uint32_t z)
///////////////////////////////////////////////////////////////////////////////
static void
transform (uint32_t state[5], const uint32_t d32[16])
transform (u32 state[5], const u32 d32[16])
{
// Use: boolean function f
// state parameters a, b, c, d, e
@ -92,8 +93,8 @@ transform (uint32_t state[5], const uint32_t d32[16])
#define R4b(a,b,c,d,e,x,s) ROUND(f2,a,b,c,d,e,0x7A6D76E9u,x,s)
#define R5b(a,b,c,d,e,x,s) ROUND(f1,a,b,c,d,e,0x00000000u,x,s)
uint32_t a1, b1, c1, d1, e1;
uint32_t a2, b2, c2, d2, e2;
u32 a1, b1, c1, d1, e1;
u32 a2, b2, c2, d2, e2;
a1 = a2 = state[0];
b1 = b2 = state[1];
@ -293,18 +294,18 @@ transform (uint32_t state[5], const uint32_t d32[16])
///////////////////////////////////////////////////////////////////////////////
RIPEMD::digest_t
RIPEMD::operator() (const cruft::view<const uint8_t*> data)
RIPEMD::operator() (const cruft::view<u08 const*> data)
{
struct {
union {
uint32_t d32[16];
uint8_t d08[64];
u32 d32[16];
u08 d08[64];
};
size_t size;
} m_buffer;
/* INIT */
uint32_t m_state[5] {
u32 m_state[5] {
0x67452301u,
0xEFCDAB89u,
0x98BADCFEu,
@ -351,7 +352,7 @@ RIPEMD::operator() (const cruft::view<const uint8_t*> data)
uint64_t length = m_length * 8;
// Push a padding byte into the buffer
uint8_t padding = 0x80;
u08 padding = 0x80;
assert (m_buffer.size != sizeof (m_buffer.d08));
m_buffer.d08[m_buffer.size] = padding;
m_buffer.size++;
@ -376,8 +377,8 @@ RIPEMD::operator() (const cruft::view<const uint8_t*> data)
// Write the length to the end of the buffer
union {
uint32_t d32[16];
uint8_t d08[64];
u32 d32[16];
u08 d08[64];
};
std::fill (std::begin (d32), std::end (d32), 0);