Browse Source

replaced SHA256D by GOSTD

master
orignal 7 years ago
parent
commit
bb314142a5
  1. 6
      src/server/shared/Bitcoin/Block.cpp
  2. 2
      src/server/shared/Bitcoin/Transaction.cpp
  3. 23
      src/server/shared/Crypto.cpp
  4. 4
      src/server/shared/Crypto.h

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

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

2
src/server/shared/Bitcoin/Transaction.cpp

@ -7,6 +7,6 @@ namespace Bitcoin
{ {
ByteBuffer buf; ByteBuffer buf;
buf << *this; buf << *this;
return Crypto::SHA256D(buf.Binary()); return Crypto::GOSTD(buf.Binary());
} }
} }

23
src/server/shared/Crypto.cpp

@ -3,32 +3,11 @@
namespace Crypto namespace Crypto
{ {
BinaryData SHA256(BinaryData data)
{
std::vector<byte> hash;
hash.resize(SHA256_DIGEST_LENGTH);
SHA256_CTX sha256;
SHA256_Init(&sha256);
SHA256_Update(&sha256, &data[0], data.size());
SHA256_Final(&hash[0], &sha256);
return std::vector<byte>(hash.begin(), hash.end());
}
BinaryData SHA256(std::string data)
{
return SHA256(BinaryData(data.begin(), data.end()));
}
BinaryData SHA256D(BinaryData data)
{
return SHA256(SHA256(data));
}
BinaryData GOSTD(BinaryData data) BinaryData GOSTD(BinaryData data)
{ {
uint8_t hash1[64]; uint8_t hash1[64];
i2p::crypto::GOSTR3411_2012_512 (&data[0], data.size (), hash1); i2p::crypto::GOSTR3411_2012_512 (&data[0], data.size (), hash1);
std::vector<byte> hash; std::vector<byte> hash(32);
i2p::crypto::GOSTR3411_2012_256 (hash1, 64, &hash[0]); i2p::crypto::GOSTR3411_2012_256 (hash1, 64, &hash[0]);
return std::vector<byte>(hash.begin(), hash.end()); return std::vector<byte>(hash.begin(), hash.end());
} }

4
src/server/shared/Crypto.h

@ -9,10 +9,6 @@
namespace Crypto namespace Crypto
{ {
BinaryData SHA256(BinaryData data);
BinaryData SHA256(std::string data);
BinaryData SHA256D(BinaryData data);
BinaryData GOSTD(BinaryData data); BinaryData GOSTD(BinaryData data);
} }

Loading…
Cancel
Save