码迷,mamicode.com
首页 > 其他好文 > 详细

sha256_transform

时间:2018-12-31 23:45:05      阅读:396      评论:0      收藏:0      [点我收藏+]

标签:dig   iges   define   ifd   round   bsp   void   col   ges   

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;
}

 

sha256_transform

标签:dig   iges   define   ifd   round   bsp   void   col   ges   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!