github.com/Bytom/bytom@v1.1.2-0.20210127130405-ae40204c0b09/mining/tensority/cgo_algorithm/lib/seed.h (about)

     1  /* seed.h */
     2  #ifndef SEED_H
     3  #define SEED_H
     4  
     5  inline void extend(uint32_t* exted, uint8_t *g_seed){
     6      sha3_ctx *ctx = (sha3_ctx*)calloc(1, sizeof(*ctx));
     7      // uint8_t seedHash[4*32];
     8      uint8_t seedHash[4][32];
     9  
    10      //  std::copy beats memcpy
    11      // std::copy(g_seed, g_seed + 32, seedHash);
    12      std::copy(g_seed, g_seed + 32, seedHash[0]);
    13      
    14      for(int i = 0; i < 3; ++i) {
    15          rhash_sha3_256_init(ctx);
    16          // rhash_sha3_update(ctx, seedHash+i*32, 32);
    17          // rhash_sha3_final(ctx, seedHash+(i+1)*32);
    18          rhash_sha3_update(ctx, seedHash[i], 32);
    19          rhash_sha3_final(ctx, seedHash[i+1]);
    20      }
    21  
    22      for(int i = 0; i < 32; ++i) {
    23  //        exted[i] =  ((*(seedHash+i*4+3))<<24) +
    24  //                    ((*(seedHash+i*4+2))<<16) +
    25  //                    ((*(seedHash+i*4+1))<<8) +
    26  //                    (*(seedHash+i*4));
    27          exted[i] =  (seedHash[i/8][(i*4+3)%32]<<24) +
    28                      (seedHash[i/8][(i*4+2)%32]<<16) +
    29                      (seedHash[i/8][(i*4+1)%32]<<8) +
    30                      seedHash[i/8][(i*4)%32];
    31      }
    32  
    33      free(ctx);
    34  }
    35  
    36  inline void init_seed(Words32 &seed, uint32_t _seed[32])
    37  {
    38      for (int i = 0; i < 16; i++)
    39          seed.lo.w[i] = _seed[i];
    40      for (int i = 0; i < 16; i++)
    41          seed.hi.w[i] = _seed[16 + i];
    42  }
    43  
    44  #endif