From b4a07538dfe3fb3642d397b6f114e7b0de55df05 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 9 May 2014 14:43:40 +1000 Subject: [PATCH] hash: make finish public in accumulators --- hash/md2.cpp | 4 +--- hash/md2.hpp | 5 ++--- hash/md4.cpp | 4 +--- hash/md4.hpp | 4 ++-- hash/md5.cpp | 4 +--- hash/md5.hpp | 4 ++-- hash/ripemd.cpp | 2 +- hash/ripemd.hpp | 10 ++++++---- 8 files changed, 16 insertions(+), 21 deletions(-) diff --git a/hash/md2.cpp b/hash/md2.cpp index 9608d8f0..8111fa9a 100644 --- a/hash/md2.cpp +++ b/hash/md2.cpp @@ -108,9 +108,7 @@ MD2::update (const uint8_t *data, size_t size) { MD2::digest_t -MD2::digest (void) { - finish (); - +MD2::digest (void) const { digest_t d; memcpy (d.data (), X, sizeof (d)); return d; diff --git a/hash/md2.hpp b/hash/md2.hpp index dd19dd43..6c35c6ff 100644 --- a/hash/md2.hpp +++ b/hash/md2.hpp @@ -36,13 +36,12 @@ namespace util { void update (const uint8_t *data, size_t len); void update (const void *data, size_t len); - digest_t digest (void); - + void finish (void); + digest_t digest (void) const; void reset (void); private: void transform (void); - void finish (void); uint64_t m_total; diff --git a/hash/md4.cpp b/hash/md4.cpp index dae617b8..932da07d 100644 --- a/hash/md4.cpp +++ b/hash/md4.cpp @@ -110,9 +110,7 @@ MD4::update (const uint8_t *data, size_t size) { MD4::digest_t -MD4::digest (void) { - finish (); - +MD4::digest (void) const { digest_t d; memcpy (d.data (), ABCD.data(), sizeof (ABCD)); return d; diff --git a/hash/md4.hpp b/hash/md4.hpp index 07816b6c..c99b71e3 100644 --- a/hash/md4.hpp +++ b/hash/md4.hpp @@ -35,12 +35,12 @@ namespace util { void update (const void *data, size_t len); void update (const uint8_t *data, size_t len); - digest_t digest (void); + void finish (void); + digest_t digest (void) const; void reset (void); private: void transform (void); - void finish (void); uint64_t m_total; diff --git a/hash/md5.cpp b/hash/md5.cpp index 973d0c1d..0be92e55 100644 --- a/hash/md5.cpp +++ b/hash/md5.cpp @@ -141,9 +141,7 @@ MD5::update (const uint8_t *data, size_t size) { MD5::digest_t -MD5::digest (void) { - finish (); - +MD5::digest (void) const { static_assert (sizeof (ABCD) == sizeof (digest_t), "Hash state must be the same size as the final digest"); diff --git a/hash/md5.hpp b/hash/md5.hpp index 9dd2debf..0d1ee238 100644 --- a/hash/md5.hpp +++ b/hash/md5.hpp @@ -36,12 +36,12 @@ namespace util { void update (const void *data, size_t len); void update (const uint8_t *data, size_t len); - digest_t digest (void); + void finish (void); + digest_t digest (void) const; void reset (void); private: void transform (void); - void finish (void); uint64_t m_total; std::array ABCD; diff --git a/hash/ripemd.cpp b/hash/ripemd.cpp index cae7b0c9..a95d5799 100644 --- a/hash/ripemd.cpp +++ b/hash/ripemd.cpp @@ -42,7 +42,7 @@ RIPEMD::reset (void) { /////////////////////////////////////////////////////////////////////////////// void -RIPEMD::update(const uint8_t *data, size_t len) { +RIPEMD::update (const uint8_t *data, size_t len) { CHECK_HARD (data); size_t cursor = 0; diff --git a/hash/ripemd.hpp b/hash/ripemd.hpp index e624e501..c78bb940 100644 --- a/hash/ripemd.hpp +++ b/hash/ripemd.hpp @@ -22,14 +22,16 @@ namespace util { public: RIPEMD(); - void update(const uint8_t*, size_t); - void finish(void); - digest_t digest(void) const; - void reset(void); + void update (const uint8_t*, size_t); + digest_t digest (void) const; + void finish (void); + void reset (void); protected: void transform (); + bool m_finished; + uint32_t m_state[5]; uint64_t m_length;