From 6879be691bf636a53208ef058f2ebe18bfa8017c Mon Sep 17 00:00:00 2001 From: Ben Woosley Date: Mon, 28 Jan 2019 11:57:50 -0800 Subject: [PATCH] refactor: Extract RIPEMD160 To directly return a CRIPEMD160 hash from data. Incidentally, decoding this acronym: * RIPEMD -> RIPE Message Digest * RIPE -> RACE Integrity Primitives Evaluation * RACE -> Research and Development in Advanced Communications Technologies in Europe --- src/bench/crypto_hash.cpp | 4 ++-- src/hash.h | 9 +++++++++ src/script/descriptor.cpp | 5 +++-- src/script/sign.cpp | 10 ++++------ src/script/sign.h | 1 + src/wallet/rpc/backup.cpp | 6 +++--- src/wallet/rpc/coins.cpp | 7 +++---- src/wallet/scriptpubkeyman.cpp | 5 ++--- 8 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/bench/crypto_hash.cpp b/src/bench/crypto_hash.cpp index 162b02f344d..96d707f5c54 100644 --- a/src/bench/crypto_hash.cpp +++ b/src/bench/crypto_hash.cpp @@ -18,7 +18,7 @@ /* Number of bytes to hash per iteration */ static const uint64_t BUFFER_SIZE = 1000*1000; -static void RIPEMD160(benchmark::Bench& bench) +static void BenchRIPEMD160(benchmark::Bench& bench) { uint8_t hash[CRIPEMD160::OUTPUT_SIZE]; std::vector in(BUFFER_SIZE,0); @@ -150,7 +150,7 @@ static void MuHashPrecompute(benchmark::Bench& bench) }); } -BENCHMARK(RIPEMD160, benchmark::PriorityLevel::HIGH); +BENCHMARK(BenchRIPEMD160, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA1, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA256, benchmark::PriorityLevel::HIGH); BENCHMARK(SHA512, benchmark::PriorityLevel::HIGH); diff --git a/src/hash.h b/src/hash.h index b1ff3acc7df..40e809e85e4 100644 --- a/src/hash.h +++ b/src/hash.h @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -223,4 +224,12 @@ void BIP32Hash(const ChainCode &chainCode, unsigned int nChild, unsigned char he */ HashWriter TaggedHash(const std::string& tag); +/** Compute the 160-bit RIPEMD-160 hash of an array. */ +inline uint160 RIPEMD160(Span data) +{ + uint160 result; + CRIPEMD160().Write(data.data(), data.size()).Finalize(result.begin()); + return result; +} + #endif // BITCOIN_HASH_H diff --git a/src/script/descriptor.cpp b/src/script/descriptor.cpp index 864eb8864fd..ca5183ded45 100644 --- a/src/script/descriptor.cpp +++ b/src/script/descriptor.cpp @@ -4,11 +4,13 @@ #include