From c70ed002305682468a12726b03249454307b6577 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Mon, 10 Mar 2014 13:57:25 +0100 Subject: [PATCH] hash: hash_proc, cubehashproc --- src/cube_hash.h | 50 +++++++++++++++++++++++++++++++++++++++++++++++++ src/hash.h | 9 +++++++++ 2 files changed, 59 insertions(+) diff --git a/src/cube_hash.h b/src/cube_hash.h index 3477df3..3f8ff3c 100644 --- a/src/cube_hash.h +++ b/src/cube_hash.h @@ -45,9 +45,59 @@ public: } }; +template +class cubehashproc : public hash_proc +{ + cubehash_state state; + byte buf[B]; + int bpos; +public: + uint size() { + return H; + } + + void init() { + state.init(); + bpos = 0; + } + + void eat (const std::vector&a) { + int apos = 0; + if (bpos) { + for (; bpos < B && apos < a.size(); ++bpos, ++apos) + buf[bpos] = a[apos]; + if (bpos == B) { + state.process_block (buf); + bpos = 0; + } + } + while (apos + B <= a.size() ) { + state.process_block (& (a[apos]) ); + apos += B; + } + for (; apos < a.size(); ++apos, ++bpos) + buf[bpos] = a[apos]; + } + + std::vector finish() { + state.process_final_incomplete_block (buf, bpos); + std::vector result; + result.resize (H, 0); + state.get_hash (& (result[0]) ); + return result; + } +}; + + + class cube128hash : public cubehash<16, 16, 32, 32, 16> {}; class cube192hash : public cubehash<16, 16, 32, 32, 24> {}; class cube256hash : public cubehash<16, 16, 32, 32, 32> {}; class cube384hash : public cubehash<16, 16, 32, 32, 48> {}; class cube512hash : public cubehash<16, 16, 32, 32, 64> {}; +class cube128proc : public cubehashproc<16, 16, 32, 32, 16> {}; +class cube192proc : public cubehashproc<16, 16, 32, 32, 24> {}; +class cube256proc : public cubehashproc<16, 16, 32, 32, 32> {}; +class cube384proc : public cubehashproc<16, 16, 32, 32, 48> {}; +class cube512proc : public cubehashproc<16, 16, 32, 32, 64> {}; diff --git a/src/hash.h b/src/hash.h index a94c2d4..ccb8298 100644 --- a/src/hash.h +++ b/src/hash.h @@ -32,5 +32,14 @@ public: virtual uint size() = 0; //in bytes }; +class hash_proc +{ +public: + virtual uint size() = 0; + virtual void init() = 0; + virtual void eat (const std::vector&) = 0; + virtual std::vector finish() = 0; +}; + #endif