void sha256_64 (uint block[16], uint digest[8]) { #define SHIFT_RIGHT_32(x,n) ((x) >> (n)) #define SHA256_S0(x) (rotl32 ((x), 25u) ^ rotl32 ((x), 14u) ^ SHIFT_RIGHT_32 ((x), 3u)) #define SHA256_S1(x) (rotl32 ((x), 15u) ^ rotl32 ((x), 13u) ^ SHIFT_RIGHT_32 ((x), 10u)) #define SHA256_S2(x) (rotl32 ((x), 30u) ^ rotl32 ((x), 19u) ^ rotl32 ((x), 10u)) #define SHA256_S3(x) (rotl32 ((x), 26u) ^ rotl32 ((x), 21u) ^ rotl32 ((x), 7u)) #define SHA256_F0(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) #define SHA256_F1(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) #define SHA256_F0o(x,y,z) (SHA256_F0 ((x), (y), (z))) #define SHA256_F1o(x,y,z) (SHA256_F1 ((x), (y), (z))) #define SHA256_STEP(F0,F1,a,b,c,d,e,f,g,h,x,K) \ { \ h += K; \ h += x; \ h += SHA256_S3 (e); \ h += F1 (e,f,g); \ d += h; \ h += SHA256_S2 (a); \ h += F0 (a,b,c); \ } #define SHA256_EXPAND(x,y,z,w) (SHA256_S1 (x) + y + SHA256_S0 (z) + w) uint w0_t = block[ 0]; uint w1_t = block[ 1]; uint w2_t = block[ 2]; uint w3_t = block[ 3]; uint w4_t = block[ 4]; uint w5_t = block[ 5]; uint w6_t = block[ 6]; uint w7_t = block[ 7]; uint w8_t = block[ 8]; uint w9_t = block[ 9]; uint wa_t = block[10]; uint wb_t = block[11]; uint wc_t = block[12]; uint wd_t = block[13]; uint we_t = block[14]; uint wf_t = block[15]; uint a = digest[0]; uint b = digest[1]; uint c = digest[2]; uint d = digest[3]; uint e = digest[4]; uint f = digest[5]; uint g = digest[6]; uint h = digest[7]; SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, SHA256C00); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, SHA256C01); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, SHA256C02); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, SHA256C03); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, SHA256C04); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, SHA256C05); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, SHA256C06); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, SHA256C07); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, SHA256C08); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, SHA256C09); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, SHA256C0a); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, SHA256C0b); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, SHA256C0c); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, SHA256C0d); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, SHA256C0e); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, SHA256C0f); w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, SHA256C10); w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, SHA256C11); w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, SHA256C12); w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, SHA256C13); w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, SHA256C14); w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, SHA256C15); w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, SHA256C16); w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, SHA256C17); w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, SHA256C18); w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, SHA256C19); wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, SHA256C1a); wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, SHA256C1b); wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, SHA256C1c); wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, SHA256C1d); we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, SHA256C1e); wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, SHA256C1f); w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, SHA256C20); w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, SHA256C21); w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, SHA256C22); w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, SHA256C23); w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, SHA256C24); w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, SHA256C25); w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, SHA256C26); w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, SHA256C27); w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, SHA256C28); w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, SHA256C29); wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, SHA256C2a); wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, SHA256C2b); wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, SHA256C2c); wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, SHA256C2d); we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, SHA256C2e); wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, SHA256C2f); w0_t = SHA256_EXPAND (we_t, w9_t, w1_t, w0_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w0_t, SHA256C30); w1_t = SHA256_EXPAND (wf_t, wa_t, w2_t, w1_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w1_t, SHA256C31); w2_t = SHA256_EXPAND (w0_t, wb_t, w3_t, w2_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, w2_t, SHA256C32); w3_t = SHA256_EXPAND (w1_t, wc_t, w4_t, w3_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, w3_t, SHA256C33); w4_t = SHA256_EXPAND (w2_t, wd_t, w5_t, w4_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, w4_t, SHA256C34); w5_t = SHA256_EXPAND (w3_t, we_t, w6_t, w5_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, w5_t, SHA256C35); w6_t = SHA256_EXPAND (w4_t, wf_t, w7_t, w6_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, w6_t, SHA256C36); w7_t = SHA256_EXPAND (w5_t, w0_t, w8_t, w7_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, w7_t, SHA256C37); w8_t = SHA256_EXPAND (w6_t, w1_t, w9_t, w8_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, a, b, c, d, e, f, g, h, w8_t, SHA256C38); w9_t = SHA256_EXPAND (w7_t, w2_t, wa_t, w9_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, h, a, b, c, d, e, f, g, w9_t, SHA256C39); wa_t = SHA256_EXPAND (w8_t, w3_t, wb_t, wa_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, g, h, a, b, c, d, e, f, wa_t, SHA256C3a); wb_t = SHA256_EXPAND (w9_t, w4_t, wc_t, wb_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, f, g, h, a, b, c, d, e, wb_t, SHA256C3b); wc_t = SHA256_EXPAND (wa_t, w5_t, wd_t, wc_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, e, f, g, h, a, b, c, d, wc_t, SHA256C3c); wd_t = SHA256_EXPAND (wb_t, w6_t, we_t, wd_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, d, e, f, g, h, a, b, c, wd_t, SHA256C3d); we_t = SHA256_EXPAND (wc_t, w7_t, wf_t, we_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, c, d, e, f, g, h, a, b, we_t, SHA256C3e); wf_t = SHA256_EXPAND (wd_t, w8_t, w0_t, wf_t); SHA256_STEP (SHA256_F0o, SHA256_F1o, b, c, d, e, f, g, h, a, wf_t, SHA256C3f); digest[0] += a; digest[1] += b; digest[2] += c; digest[3] += d; digest[4] += e; digest[5] += f; digest[6] += g; digest[7] += h; }
static void crypt_all (int count) #endif { #if FMT_MAIN_VERSION > 10 int count = *pcount; #endif int index = 0; #ifdef _OPENMP #pragma omp parallel for for (index = 0; index < count; index += VWIDTH) #endif { __m128i a, b, c, d, e, f, g, h; __m128i w[64], tmp1, tmp2; int i; #ifdef __SSE4_1__ for (i=0; i < 16; i++) GATHER (w[i], saved_key, i); for (i=0; i < 15; i++) SWAP_ENDIAN (w[i]); #else JTR_ALIGN(16) uint32_t __w[16][VWIDTH]; int j; for (i=0; i < VWIDTH; i++) for (j=0; j < 16; j++) __w[j][i] = saved_key[index + i][j]; for (i=0; i < 15; i++) { w[i] = _mm_load_si128 ((__m128i *) __w[i]); SWAP_ENDIAN (w[i]); } w[15] = _mm_load_si128 ((__m128i *) __w[15]); #endif a = _mm_set1_epi32 (0x6a09e667); b = _mm_set1_epi32 (0xbb67ae85); c = _mm_set1_epi32 (0x3c6ef372); d = _mm_set1_epi32 (0xa54ff53a); e = _mm_set1_epi32 (0x510e527f); f = _mm_set1_epi32 (0x9b05688c); g = _mm_set1_epi32 (0x1f83d9ab); h = _mm_set1_epi32 (0x5be0cd19); SHA256_STEP(a, b, c, d, e, f, g, h, 0, 0x428a2f98); SHA256_STEP(h, a, b, c, d, e, f, g, 1, 0x71374491); SHA256_STEP(g, h, a, b, c, d, e, f, 2, 0xb5c0fbcf); SHA256_STEP(f, g, h, a, b, c, d, e, 3, 0xe9b5dba5); SHA256_STEP(e, f, g, h, a, b, c, d, 4, 0x3956c25b); SHA256_STEP(d, e, f, g, h, a, b, c, 5, 0x59f111f1); SHA256_STEP(c, d, e, f, g, h, a, b, 6, 0x923f82a4); SHA256_STEP(b, c, d, e, f, g, h, a, 7, 0xab1c5ed5); SHA256_STEP(a, b, c, d, e, f, g, h, 8, 0xd807aa98); SHA256_STEP(h, a, b, c, d, e, f, g, 9, 0x12835b01); SHA256_STEP(g, h, a, b, c, d, e, f, 10, 0x243185be); SHA256_STEP(f, g, h, a, b, c, d, e, 11, 0x550c7dc3); SHA256_STEP(e, f, g, h, a, b, c, d, 12, 0x72be5d74); SHA256_STEP(d, e, f, g, h, a, b, c, 13, 0x80deb1fe); SHA256_STEP(c, d, e, f, g, h, a, b, 14, 0x9bdc06a7); SHA256_STEP(b, c, d, e, f, g, h, a, 15, 0xc19bf174); SHA256_STEP(a, b, c, d, e, f, g, h, 16, 0xe49b69c1); SHA256_STEP(h, a, b, c, d, e, f, g, 17, 0xefbe4786); SHA256_STEP(g, h, a, b, c, d, e, f, 18, 0x0fc19dc6); SHA256_STEP(f, g, h, a, b, c, d, e, 19, 0x240ca1cc); SHA256_STEP(e, f, g, h, a, b, c, d, 20, 0x2de92c6f); SHA256_STEP(d, e, f, g, h, a, b, c, 21, 0x4a7484aa); SHA256_STEP(c, d, e, f, g, h, a, b, 22, 0x5cb0a9dc); SHA256_STEP(b, c, d, e, f, g, h, a, 23, 0x76f988da); SHA256_STEP(a, b, c, d, e, f, g, h, 24, 0x983e5152); SHA256_STEP(h, a, b, c, d, e, f, g, 25, 0xa831c66d); SHA256_STEP(g, h, a, b, c, d, e, f, 26, 0xb00327c8); SHA256_STEP(f, g, h, a, b, c, d, e, 27, 0xbf597fc7); SHA256_STEP(e, f, g, h, a, b, c, d, 28, 0xc6e00bf3); SHA256_STEP(d, e, f, g, h, a, b, c, 29, 0xd5a79147); SHA256_STEP(c, d, e, f, g, h, a, b, 30, 0x06ca6351); SHA256_STEP(b, c, d, e, f, g, h, a, 31, 0x14292967); SHA256_STEP(a, b, c, d, e, f, g, h, 32, 0x27b70a85); SHA256_STEP(h, a, b, c, d, e, f, g, 33, 0x2e1b2138); SHA256_STEP(g, h, a, b, c, d, e, f, 34, 0x4d2c6dfc); SHA256_STEP(f, g, h, a, b, c, d, e, 35, 0x53380d13); SHA256_STEP(e, f, g, h, a, b, c, d, 36, 0x650a7354); SHA256_STEP(d, e, f, g, h, a, b, c, 37, 0x766a0abb); SHA256_STEP(c, d, e, f, g, h, a, b, 38, 0x81c2c92e); SHA256_STEP(b, c, d, e, f, g, h, a, 39, 0x92722c85); SHA256_STEP(a, b, c, d, e, f, g, h, 40, 0xa2bfe8a1); SHA256_STEP(h, a, b, c, d, e, f, g, 41, 0xa81a664b); SHA256_STEP(g, h, a, b, c, d, e, f, 42, 0xc24b8b70); SHA256_STEP(f, g, h, a, b, c, d, e, 43, 0xc76c51a3); SHA256_STEP(e, f, g, h, a, b, c, d, 44, 0xd192e819); SHA256_STEP(d, e, f, g, h, a, b, c, 45, 0xd6990624); SHA256_STEP(c, d, e, f, g, h, a, b, 46, 0xf40e3585); SHA256_STEP(b, c, d, e, f, g, h, a, 47, 0x106aa070); SHA256_STEP(a, b, c, d, e, f, g, h, 48, 0x19a4c116); SHA256_STEP(h, a, b, c, d, e, f, g, 49, 0x1e376c08); SHA256_STEP(g, h, a, b, c, d, e, f, 50, 0x2748774c); SHA256_STEP(f, g, h, a, b, c, d, e, 51, 0x34b0bcb5); SHA256_STEP(e, f, g, h, a, b, c, d, 52, 0x391c0cb3); SHA256_STEP(d, e, f, g, h, a, b, c, 53, 0x4ed8aa4a); SHA256_STEP(c, d, e, f, g, h, a, b, 54, 0x5b9cca4f); SHA256_STEP(b, c, d, e, f, g, h, a, 55, 0x682e6ff3); SHA256_STEP(a, b, c, d, e, f, g, h, 56, 0x748f82ee); SHA256_STEP(h, a, b, c, d, e, f, g, 57, 0x78a5636f); SHA256_STEP(g, h, a, b, c, d, e, f, 58, 0x84c87814); SHA256_STEP(f, g, h, a, b, c, d, e, 59, 0x8cc70208); SHA256_STEP(e, f, g, h, a, b, c, d, 60, 0x90befffa); SHA256_STEP(d, e, f, g, h, a, b, c, 61, 0xa4506ceb); SHA256_STEP(c, d, e, f, g, h, a, b, 62, 0xbef9a3f7); SHA256_STEP(b, c, d, e, f, g, h, a, 63, 0xc67178f2); a = _mm_add_epi32 (a, _mm_set1_epi32 (0x6a09e667)); b = _mm_add_epi32 (b, _mm_set1_epi32 (0xbb67ae85)); c = _mm_add_epi32 (c, _mm_set1_epi32 (0x3c6ef372)); d = _mm_add_epi32 (d, _mm_set1_epi32 (0xa54ff53a)); e = _mm_add_epi32 (e, _mm_set1_epi32 (0x510e527f)); f = _mm_add_epi32 (f, _mm_set1_epi32 (0x9b05688c)); g = _mm_add_epi32 (g, _mm_set1_epi32 (0x1f83d9ab)); h = _mm_add_epi32 (h, _mm_set1_epi32 (0x5be0cd19)); _mm_store_si128 ((__m128i *) &crypt_key[0][index], a); _mm_store_si128 ((__m128i *) &crypt_key[1][index], b); _mm_store_si128 ((__m128i *) &crypt_key[2][index], c); _mm_store_si128 ((__m128i *) &crypt_key[3][index], d); _mm_store_si128 ((__m128i *) &crypt_key[4][index], e); _mm_store_si128 ((__m128i *) &crypt_key[5][index], f); _mm_store_si128 ((__m128i *) &crypt_key[6][index], g); _mm_store_si128 ((__m128i *) &crypt_key[7][index], h); } #if FMT_MAIN_VERSION > 10 return count; #endif }