| 39 | #include <utility> |
| 40 | |
| 41 | void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata) |
| 42 | { |
| 43 | struct { |
| 44 | struct unnamed |
| 45 | { |
| 46 | int nVersion; |
| 47 | uint256 hashPrevBlock; |
| 48 | uint256 hashMerkleRoot; |
| 49 | unsigned int nTime; |
| 50 | unsigned int nBits; |
| 51 | unsigned int nNonce; |
| 52 | uint256 hashStateRoot; |
| 53 | uint256 hashUTXORoot; |
| 54 | } block; |
| 55 | } tmp; |
| 56 | |
| 57 | // Check all field below |
| 58 | //memset(&tmp, 0, sizeof(tmp)); |
| 59 | |
| 60 | tmp.block.nVersion = pblock->nVersion; |
| 61 | tmp.block.hashPrevBlock = pblock->hashPrevBlock; |
| 62 | tmp.block.hashMerkleRoot = pblock->hashMerkleRoot; |
| 63 | tmp.block.nTime = pblock->nTime; |
| 64 | tmp.block.nBits = pblock->nBits; |
| 65 | tmp.block.nNonce = pblock->nNonce; |
| 66 | // SC fields |
| 67 | tmp.block.hashStateRoot = pblock->hashStateRoot; |
| 68 | tmp.block.hashUTXORoot = pblock->hashUTXORoot; |
| 69 | |
| 70 | // Byte swap all the input buffer |
| 71 | for (unsigned int i = 0; i < sizeof(tmp)/4; i++) |
| 72 | ((unsigned int*)&tmp)[i] = ByteReverse(((unsigned int*)&tmp)[i]); |
| 73 | |
| 74 | // Precalc the first half of the first hash algo, which stays constant |
| 75 | // midstate requires cubehash on phi2, but this field is not used... |
| 76 | sph_cubehash512_context ctx_cubehash; |
| 77 | sph_cubehash512_init(&ctx_cubehash); |
| 78 | sph_cubehash512(&ctx_cubehash, pdata, 64); |
| 79 | memcpy(pmidstate, ctx_cubehash.state, 128); |
| 80 | |
| 81 | if (pblock->nVersion & (1 << 30)) |
| 82 | memcpy(pdata, &tmp.block, 144); |
| 83 | else |
| 84 | memcpy(pdata, &tmp.block, 80); |
| 85 | } |
| 86 | |
| 87 | ////////////////////////////////////////////////////////////////////////////// |
| 88 | // |
no test coverage detected