mirror of
https://github.com/GOSTSec/gostcoin
synced 2025-01-19 19:20:02 +00:00
use GOST R 34.11 in hash serializer
This commit is contained in:
parent
742f670895
commit
ec36620d6a
2
i2pd
2
i2pd
@ -1 +1 @@
|
|||||||
Subproject commit 249bc426673a3d8088a674b5661b84db6bcb16fc
|
Subproject commit d9b79f47c81c72dfe937136eacb9ad8ed73f6e92
|
17
src/hash.h
17
src/hash.h
@ -12,6 +12,7 @@
|
|||||||
#include <openssl/sha.h>
|
#include <openssl/sha.h>
|
||||||
#include <openssl/ripemd.h>
|
#include <openssl/ripemd.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
template<typename T1>
|
template<typename T1>
|
||||||
inline uint256 Hash(const T1 pbegin, const T1 pend)
|
inline uint256 Hash(const T1 pbegin, const T1 pend)
|
||||||
@ -21,21 +22,21 @@ inline uint256 Hash(const T1 pbegin, const T1 pend)
|
|||||||
uint8_t hash1[64];
|
uint8_t hash1[64];
|
||||||
i2p::crypto::GOSTR3411_2012_512 ((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), hash1);
|
i2p::crypto::GOSTR3411_2012_512 ((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), hash1);
|
||||||
uint256 hash2;
|
uint256 hash2;
|
||||||
i2p::crypto::GOSTR3411_2012_256 ((unsigned char*)&hash1, 61, hash2.begin ());
|
i2p::crypto::GOSTR3411_2012_256 (hash1, 61, hash2.begin ());
|
||||||
return hash2;
|
return hash2;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CHashWriter
|
class CHashWriter
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
SHA256_CTX ctx;
|
std::stringstream ctx;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int nType;
|
int nType;
|
||||||
int nVersion;
|
int nVersion;
|
||||||
|
|
||||||
void Init() {
|
void Init() {
|
||||||
SHA256_Init(&ctx);
|
ctx.str("");
|
||||||
}
|
}
|
||||||
|
|
||||||
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {
|
CHashWriter(int nTypeIn, int nVersionIn) : nType(nTypeIn), nVersion(nVersionIn) {
|
||||||
@ -43,16 +44,16 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
CHashWriter& write(const char *pch, size_t size) {
|
CHashWriter& write(const char *pch, size_t size) {
|
||||||
SHA256_Update(&ctx, pch, size);
|
ctx.write (pch, size);
|
||||||
return (*this);
|
return (*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalidates the object
|
// invalidates the object
|
||||||
uint256 GetHash() {
|
uint256 GetHash() {
|
||||||
uint256 hash1;
|
uint8_t hash1[64];
|
||||||
SHA256_Final((unsigned char*)&hash1, &ctx);
|
i2p::crypto::GOSTR3411_2012_512 ((uint8_t *)ctx.str ().c_str (), ctx.str ().length (), hash1);
|
||||||
uint256 hash2;
|
uint256 hash2;
|
||||||
SHA256((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
|
i2p::crypto::GOSTR3411_2012_256 (hash1, 64, (unsigned char*)&hash2);
|
||||||
return hash2;
|
return hash2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +113,7 @@ inline uint160 Hash160(const T1 pbegin, const T1 pend)
|
|||||||
{
|
{
|
||||||
static unsigned char pblank[1];
|
static unsigned char pblank[1];
|
||||||
uint256 hash1;
|
uint256 hash1;
|
||||||
SHA256((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), (unsigned char*)&hash1);
|
i2p::crypto::GOSTR3411_2012_256((pbegin == pend ? pblank : (unsigned char*)&pbegin[0]), (pend - pbegin) * sizeof(pbegin[0]), (unsigned char*)&hash1);
|
||||||
uint160 hash2;
|
uint160 hash2;
|
||||||
RIPEMD160((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
|
RIPEMD160((unsigned char*)&hash1, sizeof(hash1), (unsigned char*)&hash2);
|
||||||
return hash2;
|
return hash2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user