Commit a5bc9c09 authored by Pieter Wuille's avatar Pieter Wuille

Add built-in RIPEMD-160 implementation

parent 13b5dfef
......@@ -77,6 +77,7 @@ BITCOIN_CORE_H = \
serialize.h \
crypto/sha2.h \
crypto/sha1.h \
crypto/ripemd160.h \
sync.h \
threadsafety.h \
tinyformat.h \
......@@ -156,6 +157,7 @@ libbitcoin_common_a_SOURCES = \
script.cpp \
crypto/sha1.cpp \
crypto/sha2.cpp \
crypto/ripemd160.cpp \
sync.cpp \
util.cpp \
version.cpp \
......
This diff is collapsed.
// Copyright (c) 2014 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_RIPEMD160_H
#define BITCOIN_RIPEMD160_H
#include <stdint.h>
#include <stdlib.h>
/** A hasher class for RIPEMD-160. */
class CRIPEMD160 {
private:
uint32_t s[5];
unsigned char buf[64];
size_t bytes;
public:
CRIPEMD160();
CRIPEMD160& Write(const unsigned char *data, size_t len);
void Finalize(unsigned char *hash);
CRIPEMD160& Reset();
};
#endif
......@@ -7,14 +7,13 @@
#define BITCOIN_HASH_H
#include "crypto/sha2.h"
#include "crypto/ripemd160.h"
#include "serialize.h"
#include "uint256.h"
#include "version.h"
#include <vector>
#include <openssl/ripemd.h>
/** A hasher class for Bitcoin's 256-bit hash (double SHA-256). */
class CHash256 {
private:
......@@ -45,7 +44,7 @@ public:
void Finalize(unsigned char *hash) {
unsigned char buf[32];
sha.Finalize(buf);
RIPEMD160(buf, 32, hash);
CRIPEMD160().Write(buf, 32).Finalize(hash);
}
CHash160& Write(const unsigned char *data, size_t len) {
......
......@@ -11,6 +11,7 @@
#include "keystore.h"
#include "crypto/sha1.h"
#include "crypto/sha2.h"
#include "crypto/ripemd160.h"
#include "sync.h"
#include "uint256.h"
#include "util.h"
......@@ -803,7 +804,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, co
valtype& vch = stacktop(-1);
valtype vchHash((opcode == OP_RIPEMD160 || opcode == OP_SHA1 || opcode == OP_HASH160) ? 20 : 32);
if (opcode == OP_RIPEMD160)
RIPEMD160(&vch[0], vch.size(), &vchHash[0]);
CRIPEMD160().Write(&vch[0], vch.size()).Finalize(&vchHash[0]);
else if (opcode == OP_SHA1)
CSHA1().Write(&vch[0], vch.size()).Finalize(&vchHash[0]);
else if (opcode == OP_SHA256)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment