Hi, I am new here, so if this is the wrong forum, please let me know where this post is better placed.
I was trying to write my own miner, but simply don't understand what the Hash() function in hash.h is doing.
This is my code:
// allocate 80 bytes of 0x00s
unsigned char* memory = (unsigned char*)malloc(80);
int* result = (unsigned int*)malloc(32);
memory,0,80);
memory,0,32);
seems to be doing hashes under the SHA-256 name
hash = Hash(memory, memory+80);
hash:%s\n",hash.GetHex().c_str());
//14508459...0e57e74b
However when I try to do this with _any_ other SHA256 implementation I always get a different result (I tried three, which gave me the same result). Here is my Java code:
MessageDigest md = MessageDigest.getInstance("SHA-256");
byte[] digest = md.digest(ByteBuffer.allocate(80).array());
for(byte c : digest) {
System.out.format("%x", c);
}
//5b6fb58e61fa475939767d68a446f97f1bff2c0e5935a3ea8bb51e6515783d8
I thought maybe I have to double hash, but this leaves me with this:
MessageDigest md2 = MessageDigest.getInstance("SHA-256");
byte[] digest2 = md2.digest(md2.digest(ByteBuffer.allocate(80).array()));
for(byte c : digest2) {
System.out.format("%x", c);
}
//4be757e8f70eb93640c8468274ba759745a7aa2b7d25ab1e421b259845014
So the hash I get from the Bitcoin implementation differs from any other SHA256 implementation for some reason... what am I missing? Am I using the algorithm wrong? Is it initialized differently (other implementation don't give me a possibility to parametrize the function)? Does it simply work differently (not according to the standard)?
Any help would be appreciated