hash: prefer iterator style over base/length
This commit is contained in:
parent
ba4b22c208
commit
aeba9033e0
@ -16,17 +16,33 @@
|
||||
|
||||
#include "bsdsum.hpp"
|
||||
|
||||
#include "../debug.hpp"
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
uint16_t
|
||||
bsdsum (const void *restrict _data, size_t size) {
|
||||
const uint8_t *restrict data = static_cast<const uint8_t*> (_data);
|
||||
bsdsum (const uint8_t *const restrict first, const uint8_t *const restrict last)
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
uint16_t accum = 0;
|
||||
|
||||
for (size_t i = 0; i < size; ++i) {
|
||||
for (auto cursor = first; cursor != last; ++cursor) {
|
||||
accum = (accum >> 1u) | ((accum & 0x01u) << 15u);
|
||||
accum += data[i];
|
||||
accum += *cursor;
|
||||
}
|
||||
|
||||
return accum;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
uint16_t
|
||||
bsdsum (const void *restrict data, size_t size)
|
||||
{
|
||||
return bsdsum (
|
||||
static_cast<const uint8_t*> (data),
|
||||
static_cast<const uint8_t*> (data) + size
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
uint16_t bsdsum (const void *restrict, size_t);
|
||||
uint16_t bsdsum (const void *restrict data, size_t bytes);
|
||||
uint16_t bsdsum (const uint8_t *restrict first, const uint8_t *restrict last);
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,14 @@
|
||||
#include "../endian.hpp"
|
||||
#include "../debug.hpp"
|
||||
|
||||
|
||||
uint32_t
|
||||
crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
not_implemented ();
|
||||
}
|
||||
|
||||
|
||||
uint32_t
|
||||
crc32 (const void *restrict, size_t) {
|
||||
not_implemented ();
|
||||
|
@ -20,7 +20,8 @@
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
|
||||
uint32_t crc32 (const void *restrict, size_t);
|
||||
uint32_t crc32 (const void *restrict data, size_t bytes);
|
||||
uint32_t crc32 (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
#endif
|
||||
|
||||
|
11
hash/md2.cpp
11
hash/md2.cpp
@ -16,6 +16,7 @@
|
||||
|
||||
#include "md2.hpp"
|
||||
|
||||
#include "../debug.hpp"
|
||||
#include "../types.hpp"
|
||||
|
||||
#include <array>
|
||||
@ -72,6 +73,16 @@ MD2::reset (void)
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
MD2::update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
update (first, last - first);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
MD2::update (const void *data, size_t size)
|
||||
{
|
||||
update (static_cast<const uint8_t*> (data), size);
|
||||
|
@ -32,6 +32,7 @@ namespace util {
|
||||
|
||||
void update (const uint8_t *data, size_t len);
|
||||
void update (const void *data, size_t len);
|
||||
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
void finish (void);
|
||||
digest_t digest (void) const;
|
||||
|
12
hash/md4.cpp
12
hash/md4.cpp
@ -17,8 +17,9 @@
|
||||
#include "md4.hpp"
|
||||
|
||||
#include "../bitwise.hpp"
|
||||
#include "../types.hpp"
|
||||
#include "../debug.hpp"
|
||||
#include "../endian.hpp"
|
||||
#include "../types.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
@ -71,6 +72,15 @@ MD4::reset (void) {
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MD4::update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
update (first, last - first);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MD4::update (const void *data, size_t size)
|
||||
{ update (static_cast<const uint8_t*> (data), size); }
|
||||
|
@ -31,6 +31,7 @@ namespace util {
|
||||
|
||||
void update (const void *data, size_t len);
|
||||
void update (const uint8_t *data, size_t len);
|
||||
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
void finish (void);
|
||||
digest_t digest (void) const;
|
||||
|
@ -102,6 +102,15 @@ MD5::reset (void) {
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MD5::update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
update (first, last - first);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
MD5::update (const void *data, size_t len)
|
||||
{ MD5::update (static_cast<const uint8_t*> (data), len); }
|
||||
|
@ -34,6 +34,7 @@ namespace util {
|
||||
|
||||
void update (const void *data, size_t len);
|
||||
void update (const uint8_t *data, size_t len);
|
||||
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
void finish (void);
|
||||
digest_t digest (void) const;
|
||||
|
@ -49,6 +49,16 @@ RIPEMD::reset (void) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void
|
||||
RIPEMD::update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
update (first, last - first);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
RIPEMD::update (const uint8_t *data, size_t len) {
|
||||
CHECK (data);
|
||||
|
||||
|
@ -30,6 +30,8 @@ namespace util {
|
||||
RIPEMD();
|
||||
|
||||
void update (const uint8_t*, size_t);
|
||||
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
digest_t digest (void) const;
|
||||
void finish (void);
|
||||
void reset (void);
|
||||
|
@ -104,6 +104,16 @@ SHA1::reset (void) {
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
SHA1::update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
update (first, last - first);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
void
|
||||
SHA1::update (const uint8_t *data, size_t size) {
|
||||
|
@ -35,6 +35,8 @@ namespace util { namespace hash {
|
||||
SHA1();
|
||||
|
||||
void update (const uint8_t *, size_t);
|
||||
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
void finish (void);
|
||||
digest_t digest (void) const;
|
||||
void reset (void);
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "sha2.hpp"
|
||||
|
||||
#include "../bitwise.hpp"
|
||||
#include "../debug.hpp"
|
||||
#include "../endian.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
@ -170,6 +171,15 @@ SHA256::SHA256 ():
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SHA256::update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept
|
||||
{
|
||||
CHECK_LE (first, last);
|
||||
|
||||
update (first, last - first);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SHA256::update (const uint8_t *data, size_t length) {
|
||||
while (length) {
|
||||
|
@ -31,6 +31,8 @@ namespace util {
|
||||
SHA256();
|
||||
|
||||
void update (const uint8_t *, size_t);
|
||||
void update (const uint8_t *restrict first, const uint8_t *restrict last) noexcept;
|
||||
|
||||
void finish (void);
|
||||
digest_t digest (void) const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user