Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.33 KB | None | 0 0
  1. void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1)
  2. {
  3.     //
  4.     // Prebuild hash buffers
  5.     //
  6.     struct
  7.     {
  8.         struct unnamed2
  9.         {
  10.             int nVersion;
  11.             uint256 hashPrevBlock;
  12.             uint256 hashMerkleRoot;
  13.             unsigned int nTime;
  14.             unsigned int nBits;
  15.             unsigned int nNonce;
  16.         }
  17.         block;
  18.         unsigned char pchPadding0[64];
  19.         uint256 hash1;
  20.         unsigned char pchPadding1[64];
  21.     }
  22.     tmp;
  23.     memset(&tmp, 0, sizeof(tmp));
  24.  
  25.     tmp.block.nVersion       = pblock->nVersion;
  26.     tmp.block.hashPrevBlock  = pblock->hashPrevBlock;
  27.     tmp.block.hashMerkleRoot = pblock->hashMerkleRoot;
  28.     tmp.block.nTime          = pblock->nTime;
  29.     tmp.block.nBits          = pblock->nBits;
  30.     tmp.block.nNonce         = pblock->nNonce;
  31.  
  32.     FormatHashBlocks(&tmp.block, sizeof(tmp.block));
  33.     FormatHashBlocks(&tmp.hash1, sizeof(tmp.hash1));
  34.  
  35.     // Byte swap all the input buffer
  36.     for (int i = 0; i < sizeof(tmp)/4; i++)
  37.         ((unsigned int*)&tmp)[i] = ByteReverse(((unsigned int*)&tmp)[i]);
  38.  
  39.     // Precalc the first half of the first hash, which stays constant
  40.     SHA256Transform(pmidstate, &tmp.block, pSHA256InitState);
  41.  
  42.     memcpy(pdata, &tmp.block, 128);
  43.     memcpy(phash1, &tmp.hash1, 64);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement