From 2add7c158c409b19853608fd6736346f876984a2 Mon Sep 17 00:00:00 2001 From: Vas Crabb Date: Mon, 13 Apr 2020 06:48:15 +1000 Subject: [PATCH] split was using sha1.h directly - fix that (nw) --- src/lib/util/hashing.cpp | 2 +- src/tools/chdman.cpp | 15 +++++++-------- src/tools/split.cpp | 27 ++++++++++++--------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/lib/util/hashing.cpp b/src/lib/util/hashing.cpp index ebfc84fd33f..e554bd731b4 100644 --- a/src/lib/util/hashing.cpp +++ b/src/lib/util/hashing.cpp @@ -45,7 +45,7 @@ constexpr uint32_t sha1_rol(uint32_t x, unsigned n) return (x << n) | (x >> (32 - n)); } -uint32_t sha1_b(uint32_t *data, unsigned i) +inline uint32_t sha1_b(uint32_t *data, unsigned i) { uint32_t r = data[(i + 13) & 15U]; r ^= data[(i + 8) & 15U]; diff --git a/src/tools/chdman.cpp b/src/tools/chdman.cpp index 44e73083ff4..914ab850054 100644 --- a/src/tools/chdman.cpp +++ b/src/tools/chdman.cpp @@ -6,7 +6,6 @@ ****************************************************************************/ #include // must be stdio.h and here otherwise issues with I64FMT in MINGW -#include #include "osdcore.h" #include "corefile.h" @@ -15,17 +14,17 @@ #include "avhuff.h" #include "bitmap.h" #include "md5.h" -#include "sha1.h" +#include "hashing.h" #include "vbiparse.h" -#include -#include -#include -#include -#include -#include #include +#include +#include +#include +#include #include +#include +#include #include #include #include diff --git a/src/tools/split.cpp b/src/tools/split.cpp index ba455c04b51..1748edf7625 100644 --- a/src/tools/split.cpp +++ b/src/tools/split.cpp @@ -8,17 +8,19 @@ ****************************************************************************/ +#include "corefile.h" +#include "corestr.h" +#include "hashing.h" + #include #include #include #include #include -#include "corefile.h" -#include "corestr.h" -#include "sha1.h" #define DEFAULT_SPLIT_SIZE 100 #define MAX_PARTS 1000 +#define SHA1_DIGEST_SIZE 20 @@ -34,22 +36,17 @@ static void compute_hash_as_string(std::string &buffer, void *data, uint32_t length) { - char expanded[SHA1_DIGEST_SIZE * 2]; - uint8_t sha1digest[SHA1_DIGEST_SIZE]; - struct sha1_ctx sha1; - int ch; - // compute the SHA1 - sha1_init(&sha1); - sha1_update(&sha1, length, (const uint8_t *)data); - sha1_final(&sha1); - sha1_digest(&sha1, sizeof(sha1digest), sha1digest); + util::sha1_creator sha1; + sha1.append(data, length); + const util::sha1_t sha1digest = sha1.finish(); // expand the digest to a string - for (ch = 0; ch < SHA1_DIGEST_SIZE; ch++) + char expanded[sizeof(sha1digest.m_raw) * 2]; + for (int ch = 0; ch < sizeof(sha1digest.m_raw); ch++) { - expanded[ch * 2 + 0] = "0123456789ABCDEF"[sha1digest[ch] >> 4]; - expanded[ch * 2 + 1] = "0123456789ABCDEF"[sha1digest[ch] & 15]; + expanded[ch * 2 + 0] = "0123456789ABCDEF"[sha1digest.m_raw[ch] >> 4]; + expanded[ch * 2 + 1] = "0123456789ABCDEF"[sha1digest.m_raw[ch] & 15]; } // copy it to the buffer