hash: remove uint8/size_t update functions

This commit is contained in:
Danny Robson 2016-06-17 16:27:16 +10:00
parent ce26ce1238
commit 73579f57aa
12 changed files with 25 additions and 39 deletions

View File

@ -81,14 +81,6 @@ MD2::update (const uint8_t *restrict first, const uint8_t *restrict last) noexce
} }
//-----------------------------------------------------------------------------
void
MD2::update (const void *restrict data, size_t size) noexcept
{
update (static_cast<const uint8_t*> (data), size);
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
static const size_t M_OFFSET = 16; static const size_t M_OFFSET = 16;
static const size_t M_LENGTH = 16; static const size_t M_LENGTH = 16;
@ -96,8 +88,10 @@ static const size_t M_LENGTH = 16;
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
MD2::update (const uint8_t *restrict data, size_t size) noexcept MD2::update (const void *restrict _data, size_t size) noexcept
{ {
auto data = static_cast<const uint8_t *restrict> (_data);
uint8_t *M = X + M_OFFSET; uint8_t *M = X + M_OFFSET;
size_t offset = m_total % M_LENGTH; size_t offset = m_total % M_LENGTH;
size_t remain = M_LENGTH - offset; size_t remain = M_LENGTH - offset;

View File

@ -30,7 +30,6 @@ namespace util { namespace hash {
public: public:
MD2 (); MD2 ();
void update (const uint8_t *restrict data, size_t len) noexcept;
void update (const void *restrict data, size_t len) noexcept; void update (const void *restrict data, size_t len) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;

View File

@ -100,16 +100,11 @@ MD4::update (const uint8_t *restrict first, const uint8_t *restrict last) noexce
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
MD4::update (const void *restrict data, size_t size) noexcept MD4::update (const void *restrict _data, size_t size) noexcept
{ {
update (static_cast<const uint8_t*> (data), size); CHECK (_data);
} auto data = static_cast<const uint8_t *restrict> (_data);
//-----------------------------------------------------------------------------
void
MD4::update (const uint8_t *restrict data, size_t size) noexcept
{
size_t offset = m_total % sizeof (Xb); size_t offset = m_total % sizeof (Xb);
size_t remain = sizeof (Xb) - offset; size_t remain = sizeof (Xb) - offset;

View File

@ -31,7 +31,6 @@ namespace util { namespace hash {
MD4(); MD4();
void update (const void *restrict data, size_t len) noexcept; void update (const void *restrict data, size_t len) noexcept;
void update (const uint8_t *restrict data, size_t len) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);

View File

@ -132,16 +132,11 @@ MD5::update (const uint8_t *restrict first, const uint8_t *restrict last) noexce
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
MD5::update (const void *restrict data, size_t len) noexcept MD5::update (const void *restrict _data, size_t size) noexcept
{ {
MD5::update (static_cast<const uint8_t*> (data), len); CHECK (_data);
} auto data = static_cast<const uint8_t *restrict> (_data);
//-----------------------------------------------------------------------------
void
MD5::update (const uint8_t *restrict data, size_t size) noexcept
{
size_t offset = m_total % sizeof (Xb); size_t offset = m_total % sizeof (Xb);
size_t remain = sizeof (Xb) - offset; size_t remain = sizeof (Xb) - offset;

View File

@ -34,7 +34,6 @@ namespace util { namespace hash {
MD5(); MD5();
void update (const void *restrict data, size_t len) noexcept; void update (const void *restrict data, size_t len) noexcept;
void update (const uint8_t *restrict data, size_t len) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);
@ -52,9 +51,6 @@ namespace util { namespace hash {
uint8_t Xb[64]; uint8_t Xb[64];
}; };
}; };
typedef uint8_t md5_t;
md5_t md5 (const void *restrict data, size_t len);
} } } }
#endif #endif

View File

@ -63,9 +63,11 @@ RIPEMD::update (
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
RIPEMD::update (const uint8_t *restrict data, size_t len) noexcept RIPEMD::update (const void *restrict _data, size_t len) noexcept
{ {
CHECK (data); CHECK (_data);
auto data = static_cast<const uint8_t *restrict> (_data);
size_t cursor = 0; size_t cursor = 0;

View File

@ -30,7 +30,7 @@ namespace util { namespace hash {
public: public:
RIPEMD(); RIPEMD();
void update (const uint8_t *restrict, size_t) noexcept; void update (const void *restrict, size_t) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
digest_t digest (void) const; digest_t digest (void) const;

View File

@ -135,11 +135,14 @@ SHA1::update (
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
SHA1::update (const uint8_t *restrict data, size_t size) noexcept SHA1::update (const void *restrict _data, size_t size) noexcept
{ {
CHECK (_data);
CHECK_EQ (state, READY); CHECK_EQ (state, READY);
CHECK_GE (std::numeric_limits<decltype(total)>::max () - total, size); CHECK_GE (std::numeric_limits<decltype(total)>::max () - total, size);
auto data = static_cast<const uint8_t *restrict> (_data);
while (size > 0) { while (size > 0) {
// Copy the data into the remaining available buffer slots // Copy the data into the remaining available buffer slots
const size_t offset = total % BLOCK_BYTES; const size_t offset = total % BLOCK_BYTES;

View File

@ -34,7 +34,7 @@ namespace util { namespace hash {
public: public:
SHA1(); SHA1();
void update (const uint8_t *restrict, size_t) noexcept; void update (const void *restrict, size_t) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);

View File

@ -183,8 +183,11 @@ SHA256::update (const uint8_t *restrict first, const uint8_t *restrict last) noe
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void void
SHA256::update (const uint8_t *restrict data, size_t length) noexcept SHA256::update (const void *restrict _data, size_t length) noexcept
{ {
CHECK (_data);
auto data = static_cast<const uint8_t *restrict> (_data);
while (length) { while (length) {
size_t buffered = m_total % sizeof (M); size_t buffered = m_total % sizeof (M);
size_t chunk = std::min (sizeof (M) - buffered, length); size_t chunk = std::min (sizeof (M) - buffered, length);

View File

@ -31,7 +31,7 @@ namespace util { namespace hash {
public: public:
SHA256(); SHA256();
void update (const uint8_t *restrict, size_t) noexcept; void update (const void *restrict, size_t) noexcept;
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept; void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
void finish (void); void finish (void);