A hasher class for SHA-256. */
| 12 | |
| 13 | /** A hasher class for SHA-256. */ |
| 14 | class CSHA256 |
| 15 | { |
| 16 | private: |
| 17 | uint32_t s[8]; |
| 18 | unsigned char buf[64]; |
| 19 | uint64_t bytes; |
| 20 | |
| 21 | public: |
| 22 | static const size_t OUTPUT_SIZE = 32; |
| 23 | |
| 24 | CSHA256(); |
| 25 | CSHA256& Write(const unsigned char* data, size_t len); |
| 26 | void Finalize(unsigned char hash[OUTPUT_SIZE]); |
| 27 | //TODO: Midstate is a hack'ish speedup that probably should make way for something |
| 28 | //akin to the SHA256D64 speedups |
| 29 | void Midstate(unsigned char hash[OUTPUT_SIZE], uint64_t* len, unsigned char *buffer); |
| 30 | std::vector<unsigned char> Save() const; |
| 31 | bool Load(const std::vector<unsigned char>& vch); |
| 32 | CSHA256& Reset(); |
| 33 | bool SafeWrite(const unsigned char* data, size_t len); |
| 34 | }; |
| 35 | |
| 36 | /** Autodetect the best available SHA256 implementation. |
| 37 | * Returns the name of the implementation. |
no outgoing calls