64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
/*
|
|
* This file is part of the Flowee project
|
|
* Copyright (C) 2014 The Bitcoin Core developers
|
|
* Copyright (C) 2019 Tom Zander <tom@flowee.org>
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#ifndef FLOWEE_CRYPTO_SHA256_H
|
|
#define FLOWEE_CRYPTO_SHA256_H
|
|
|
|
#include <cstdint>
|
|
#include <cassert>
|
|
#include <string>
|
|
|
|
/** A hasher class for SHA-256. */
|
|
class CSHA256
|
|
{
|
|
private:
|
|
uint32_t s[8];
|
|
unsigned char buf[64];
|
|
uint64_t bytes;
|
|
|
|
public:
|
|
static const size_t OUTPUT_SIZE = 32;
|
|
|
|
CSHA256();
|
|
inline CSHA256& Write(const char* data, int len) {
|
|
assert(len >= 0);
|
|
return Write(reinterpret_cast<const unsigned char*>(data), size_t(len));
|
|
}
|
|
CSHA256& Write(const unsigned char* data, size_t len);
|
|
inline void Finalize(char *hash) {
|
|
return Finalize(reinterpret_cast<unsigned char*>(hash));
|
|
}
|
|
void Finalize(unsigned char *hash);
|
|
CSHA256& Reset();
|
|
};
|
|
|
|
/** Autodetect the best available SHA256 implementation.
|
|
* Returns the name of the implementation.
|
|
*/
|
|
std::string SHA256AutoDetect();
|
|
|
|
/** Compute multiple double-SHA256's of 64-byte blobs.
|
|
* output: pointer to a blocks*32 byte output buffer
|
|
* input: pointer to a blocks*64 byte input buffer
|
|
* blocks: the number of hashes to compute.
|
|
*/
|
|
void SHA256D64(unsigned char* output, const unsigned char* input, size_t blocks);
|
|
|
|
#endif
|