sha256_transform

DECLSPEC void sha256_transform (const u32 *w0, const u32 *w1, const u32 *w2, const u32 *w3, u32 *digest)
{
  u32 a = digest[0];
  u32 b = digest[1];
  u32 c = digest[2];
  u32 d = digest[3];
  u32 e = digest[4];
  u32 f = digest[5];
  u32 g = digest[6];
  u32 h = digest[7];

  u32 w0_t = w0[0];
  u32 w1_t = w0[1];
  u32 w2_t = w0[2];
  u32 w3_t = w0[3];
  u32 w4_t = w1[0];
  u32 w5_t = w1[1];
  u32 w6_t = w1[2];
  u32 w7_t = w1[3];
  u32 w8_t = w2[0];
  u32 w9_t = w2[1];
  u32 wa_t = w2[2];
  u32 wb_t = w2[3];
  u32 wc_t = w3[0];
  u32 wd_t = w3[1];
  u32 we_t = w3[2];
  u32 wf_t = w3[3];

  #define ROUND_EXPAND_S()                            \
  {                                                       w0_t = SHA256_EXPAND_S (we_t, w9_t, w1_t, w0_t);      w1_t = SHA256_EXPAND_S (wf_t, wa_t, w2_t, w1_t);      w2_t = SHA256_EXPAND_S (w0_t, wb_t, w3_t, w2_t);      w3_t = SHA256_EXPAND_S (w1_t, wc_t, w4_t, w3_t);      w4_t = SHA256_EXPAND_S (w2_t, wd_t, w5_t, w4_t);      w5_t = SHA256_EXPAND_S (w3_t, we_t, w6_t, w5_t);      w6_t = SHA256_EXPAND_S (w4_t, wf_t, w7_t, w6_t);      w7_t = SHA256_EXPAND_S (w5_t, w0_t, w8_t, w7_t);      w8_t = SHA256_EXPAND_S (w6_t, w1_t, w9_t, w8_t);      w9_t = SHA256_EXPAND_S (w7_t, w2_t, wa_t, w9_t);      wa_t = SHA256_EXPAND_S (w8_t, w3_t, wb_t, wa_t);      wb_t = SHA256_EXPAND_S (w9_t, w4_t, wc_t, wb_t);      wc_t = SHA256_EXPAND_S (wa_t, w5_t, wd_t, wc_t);      wd_t = SHA256_EXPAND_S (wb_t, w6_t, we_t, wd_t);      we_t = SHA256_EXPAND_S (wc_t, w7_t, wf_t, we_t);      wf_t = SHA256_EXPAND_S (wd_t, w8_t, w0_t, wf_t);    }

  #define ROUND_STEP_S(i)                                                                   \
  {                                                                                             SHA256_STEP_S (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, k_sha256[i +  0]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, k_sha256[i +  1]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, k_sha256[i +  2]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, k_sha256[i +  3]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, k_sha256[i +  4]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, k_sha256[i +  5]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, k_sha256[i +  6]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, k_sha256[i +  7]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, k_sha256[i +  8]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, k_sha256[i +  9]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, k_sha256[i + 10]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, k_sha256[i + 11]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, k_sha256[i + 12]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, k_sha256[i + 13]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, k_sha256[i + 14]);     SHA256_STEP_S (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, k_sha256[i + 15]);   }

  ROUND_STEP_S (0);

  #ifdef _unroll
  #pragma unroll
  #endif
  for (int i = 16; i < 64; i += 16)
  {
    ROUND_EXPAND_S (); ROUND_STEP_S (i);
  }

  #undef ROUND_EXPAND_S
  #undef ROUND_STEP_S

  digest[0] += a;
  digest[1] += b;
  digest[2] += c;
  digest[3] += d;
  digest[4] += e;
  digest[5] += f;
  digest[6] += g;
  digest[7] += h;
}

原文地址:https://www.cnblogs.com/INT18/p/10203589.html

时间: 2024-10-06 23:23:04

sha256_transform的相关文章

XDAG_Miner客户端到底做了什么

开篇之前先聊聊背景:本人本身是想打造一个Python版本节点的,但是坑在了两个函数 dfslib_crypt_set_sector0 dfslib_encrypt_sector 这两个函数在节点和挖矿程序中都出现了,主要是对用户密码进行加密解密的函数,我尝试用Python翻译了一遍,效率极低,甚至都影响调试就放弃了. 再对Python开发者说几句,整个XDAG代码并不多,但是其中运用了大量宏,字节截取,二进制处理,内存偏移等.导致对于Python这个语言来说,增加了大量转换工作,许多源码中一行的