A hasher class for Bitcoin's 256-bit hash (double SHA-256). */
| 22 | |
| 23 | /** A hasher class for Bitcoin's 256-bit hash (double SHA-256). */ |
| 24 | class CHash256 { |
| 25 | private: |
| 26 | CSHA256 sha; |
| 27 | public: |
| 28 | static const size_t OUTPUT_SIZE = CSHA256::OUTPUT_SIZE; |
| 29 | |
| 30 | void Finalize(Span<unsigned char> output) { |
| 31 | assert(output.size() == OUTPUT_SIZE); |
| 32 | unsigned char buf[CSHA256::OUTPUT_SIZE]; |
| 33 | sha.Finalize(buf); |
| 34 | sha.Reset().Write(buf, CSHA256::OUTPUT_SIZE).Finalize(output.data()); |
| 35 | } |
| 36 | |
| 37 | CHash256& Write(Span<const unsigned char> input) { |
| 38 | sha.Write(input.data(), input.size()); |
| 39 | return *this; |
| 40 | } |
| 41 | |
| 42 | CHash256& Reset() { |
| 43 | sha.Reset(); |
| 44 | return *this; |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | /** A hasher class for Bitcoin's 160-bit hash (SHA-256 + RIPEMD-160). */ |
| 49 | class CHash160 { |