sha2: rename SHA2 class to SHA256
temporary rename for clarity in existing algorithm code. revisit when/if we get implementations for each bit length.
This commit is contained in:
parent
77ea57f530
commit
513b09c1c9
@ -156,7 +156,7 @@ uint64_t H_512[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
SHA2::SHA2 ():
|
SHA256::SHA256 ():
|
||||||
m_total (0)
|
m_total (0)
|
||||||
{
|
{
|
||||||
std::copy (std::begin (H_256), std::end (H_256), std::begin (H));
|
std::copy (std::begin (H_256), std::end (H_256), std::begin (H));
|
||||||
@ -164,7 +164,7 @@ SHA2::SHA2 ():
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SHA2::update (const uint8_t *data, size_t length) {
|
SHA256::update (const uint8_t *data, size_t length) {
|
||||||
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);
|
||||||
@ -180,7 +180,7 @@ SHA2::update (const uint8_t *data, size_t length) {
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SHA2::finish (void) {
|
SHA256::finish (void) {
|
||||||
// Append a single 1 bit followed by 0s.
|
// Append a single 1 bit followed by 0s.
|
||||||
size_t buffered = m_total % sizeof (M);
|
size_t buffered = m_total % sizeof (M);
|
||||||
size_t used = m_total * 8;
|
size_t used = m_total * 8;
|
||||||
@ -219,7 +219,7 @@ SHA2::finish (void) {
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SHA2::process (void) {
|
SHA256::process (void) {
|
||||||
CHECK_EQ (m_total % sizeof (M), 0);
|
CHECK_EQ (m_total % sizeof (M), 0);
|
||||||
|
|
||||||
// Initialise the message schedule, W
|
// Initialise the message schedule, W
|
||||||
@ -264,8 +264,8 @@ SHA2::process (void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SHA2::digest_t
|
SHA256::digest_t
|
||||||
SHA2::digest (void) const {
|
SHA256::digest (void) const {
|
||||||
digest_t out;
|
digest_t out;
|
||||||
|
|
||||||
auto cursor = out.begin ();
|
auto cursor = out.begin ();
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
namespace hash {
|
namespace hash {
|
||||||
class SHA2 {
|
class SHA256 {
|
||||||
public:
|
public:
|
||||||
typedef std::array<uint8_t,32> digest_t;
|
typedef std::array<uint8_t,32> digest_t;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHA2();
|
SHA256();
|
||||||
|
|
||||||
void update (const uint8_t *, size_t);
|
void update (const uint8_t *, size_t);
|
||||||
void finish (void);
|
void finish (void);
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
using util::hash::SHA2;
|
using util::hash::SHA256;
|
||||||
|
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *input;
|
const char *input;
|
||||||
SHA2::digest_t output;
|
SHA256::digest_t output;
|
||||||
} TESTS[] = {
|
} TESTS[] = {
|
||||||
{ "",
|
{ "",
|
||||||
{ 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
|
{ 0xE3, 0xB0, 0xC4, 0x42, 0x98, 0xFC, 0x1C, 0x14, 0x9A, 0xFB, 0xF4, 0xC8, 0x99, 0x6F, 0xB9, 0x24,
|
||||||
@ -40,7 +40,7 @@ static const struct {
|
|||||||
int
|
int
|
||||||
main (int, char **) {
|
main (int, char **) {
|
||||||
for (auto i: TESTS) {
|
for (auto i: TESTS) {
|
||||||
SHA2 obj;
|
SHA256 obj;
|
||||||
obj.update (reinterpret_cast<const uint8_t*> (i.input), strlen (i.input));
|
obj.update (reinterpret_cast<const uint8_t*> (i.input), strlen (i.input));
|
||||||
obj.finish ();
|
obj.finish ();
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user