// keccak256(challenge[32] || sender[20] || nonce[32]) search. One 136-byte block. // The 8 searched bytes are nonce[12..20), which is exactly lane 8. #define ROL(x, n) rotate((ulong)(x), (ulong)(n)) static const ulong RC[24] = { 0x0000000000000001UL,0x0000000000008082UL,0x800000000000808aUL,0x8000000080008000UL, 0x000000000000808bUL,0x0000000080000001UL,0x8000000080008081UL,0x8000000000008009UL, 0x000000000000008aUL,0x0000000000000088UL,0x0000000080008009UL,0x000000008000000aUL, 0x000000008000808bUL,0x800000000000008bUL,0x8000000000008089UL,0x8000000000008003UL, 0x8000000000008002UL,0x8000000000000080UL,0x000000000000800aUL,0x800000008000000aUL, 0x8000000080008081UL,0x8000000000008080UL,0x0000000080000001UL,0x8000000080008008UL}; static const int ROTC[24] = {1,3,6,10,15,21,28,36,45,55,2,14,27,41,56,8,25,43,62,18,39,61,20,44}; static const int PIL[24] = {10,7,11,17,18,3,5,16,8,21,24,4,15,23,19,13,12,2,20,14,22,9,6,1}; __kernel void search(__constant ulong *fixed, ulong base, ulong thi, __global volatile uint *found, __global ulong *out) { ulong s[25]; for (int i = 0; i < 25; i++) s[i] = 0; for (int i = 0; i < 11; i++) s[i] = fixed[i]; s[8] = base + get_global_id(0); s[16] = 0x8000000000000000UL; ulong bc[5], t; for (int r = 0; r < 24; r++) { for (int i = 0; i < 5; i++) bc[i] = s[i] ^ s[i+5] ^ s[i+10] ^ s[i+15] ^ s[i+20]; for (int i = 0; i < 5; i++) { t = bc[(i+4)%5] ^ ROL(bc[(i+1)%5], 1); for (int j = 0; j < 25; j += 5) s[j+i] ^= t; } t = s[1]; for (int i = 0; i < 24; i++) { int j = PIL[i]; ulong b = s[j]; s[j] = ROL(t, ROTC[i]); t = b; } for (int j = 0; j < 25; j += 5) { for (int i = 0; i < 5; i++) bc[i] = s[j+i]; for (int i = 0; i < 5; i++) s[j+i] ^= (~bc[(i+1)%5]) & bc[(i+2)%5]; } s[0] ^= RC[r]; } ulong x = s[0]; ulong be = ((x & 0xffUL) << 56) | ((x & 0xff00UL) << 40) | ((x & 0xff0000UL) << 24) | ((x & 0xff000000UL) << 8) | ((x >> 8) & 0xff000000UL) | ((x >> 24) & 0xff0000UL) | ((x >> 40) & 0xff00UL) | (x >> 56); if (be <= thi) { uint idx = atomic_inc(found); if (idx < 16u) out[idx] = base + get_global_id(0); } }