diff --git a/Serializer.cpp b/Serializer.cpp index 9dea65629e..68f4cef54a 100644 --- a/Serializer.cpp +++ b/Serializer.cpp @@ -125,22 +125,27 @@ std::vector Serializer::getRaw(int offset, int length) const uint160 Serializer::getRIPEMD160(int size) const { uint160 ret; - if((size==0)||(size>mData.size())) size=mData.size(); + if((size<0)||(size>mData.size())) size=mData.size(); RIPEMD160(&(mData.front()), size, (unsigned char *) &ret); } uint256 Serializer::getSHA256(int size) const { uint256 ret; - if((size==0)||(size>mData.size())) size=mData.size(); + if((size<0)||(size>mData.size())) size=mData.size(); SHA256(&(mData.front()), size, (unsigned char *) &ret); } uint256 Serializer::getSHA512Half(int size) const +{ + return getSHA512Half(mData, size); +} + +uint256 Serializer::getSHA512Half(const std::vector& data, int size) { char buf[64]; - if((size==0)||(size>mData.size())) size=mData.size(); - SHA512(&(mData.front()), size, (unsigned char *) buf); + if((size<0)||(size>data.size())) size=data.size(); + SHA512(&(data.front()), size, (unsigned char *) buf); return * (uint256 *) buf; } diff --git a/Serializer.h b/Serializer.h index 0d5688d7e1..bcf62dfe80 100644 --- a/Serializer.h +++ b/Serializer.h @@ -39,9 +39,10 @@ class Serializer std::vector getRaw(int offset, int length) const; // hash functions - uint160 getRIPEMD160(int size=0) const; - uint256 getSHA256(int size=0) const; - uint256 getSHA512Half(int size=0) const; + uint160 getRIPEMD160(int size=-1) const; + uint256 getSHA256(int size=-1) const; + uint256 getSHA512Half(int size=-1) const; + static uint256 getSHA512Half(const std::vector& data, int size=-1); // totality functions int getLength() const { return mData.size(); }