Browse Source

separate hash for merkle and block

master
orignal 7 years ago
parent
commit
841ee3c24f
  1. 6
      src/server/shared/Bitcoin/Block.cpp
  2. 22
      src/server/shared/Crypto.cpp
  3. 4
      src/server/shared/Crypto.h

6
src/server/shared/Bitcoin/Block.cpp

@ -16,7 +16,7 @@ namespace Bitcoin @@ -16,7 +16,7 @@ namespace Bitcoin
for (uint32 i = 0; i < size; i += 2)
{
uint32 i2 = std::min(i+1, size-1);
merkleTree.push_back(Crypto::GOSTD(merkleTree[j+i], merkleTree[j+i2]));
merkleTree.push_back(Crypto::GOSTD(Util::Join(merkleTree[j+i], merkleTree[j+i2])));
}
j += size;
@ -35,7 +35,7 @@ namespace Bitcoin @@ -35,7 +35,7 @@ namespace Bitcoin
uint32 j = 0;
for (uint32 size = tx.size(); size > 1; size = (size+1)/2)
{
merkleTree[j+size] = Crypto::GOSTD(merkleTree[j], merkleTree[j+1]);
merkleTree[j+size] = Crypto::GOSTD(Util::Join(merkleTree[j], merkleTree[j+1]));
j += size;
}
@ -52,6 +52,6 @@ namespace Bitcoin @@ -52,6 +52,6 @@ namespace Bitcoin
buf << time;
buf << bits;
buf << nonce;
return Crypto::GOSTD(buf.Binary());
return Crypto::GOSTDBlock(buf.Binary());
}
}

22
src/server/shared/Crypto.cpp

@ -4,6 +4,16 @@ @@ -4,6 +4,16 @@
namespace Crypto
{
BinaryData GOSTD(BinaryData data)
{
uint8_t hash1[64];
std::vector<byte> hash(32);
i2p::crypto::GOSTR3411_2012_512 (&data[0], data.size (), hash1);
i2p::crypto::GOSTR3411_2012_256 (hash1, 64, &hash[0]);
// we don't convert to Little Endian here
return hash;
}
BinaryData GOSTDBlock(BinaryData data)
{
uint8_t hash1[64], hash2[32];
i2p::crypto::GOSTR3411_2012_512 (&data[0], data.size (), hash1);
@ -14,16 +24,4 @@ namespace Crypto @@ -14,16 +24,4 @@ namespace Crypto
hash.push_back (hash2[31-i]);
return hash;
}
BinaryData GOSTD(BinaryData data1, BinaryData data2)
{
BinaryData data3 = data1;
data3.insert(data3.end(), data2.begin(), data2.end());
uint8_t hash1[64];
std::vector<byte> hash(32);
i2p::crypto::GOSTR3411_2012_512 (&data3[0], data3.size (), hash1);
i2p::crypto::GOSTR3411_2012_256 (hash1, 64, &hash[0]);
// we don't convert to Little Endian here
return hash;
}
}

4
src/server/shared/Crypto.h

@ -9,8 +9,8 @@ @@ -9,8 +9,8 @@
namespace Crypto
{
BinaryData GOSTD(BinaryData data);
BinaryData GOSTD(BinaryData data1, BinaryData data2); // for merkle
BinaryData GOSTD(BinaryData data); // for Merkle
BinaryData GOSTDBlock (BinaryData data); // for 80 bytes header
}
#endif

Loading…
Cancel
Save