Created
June 3, 2018 19:40
-
-
Save pinxue/700a0ba836f1ec20348023e8ec6d1b85 to your computer and use it in GitHub Desktop.
Keccak-f[1600] in plain c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// converted from https://github.com/coruus/keccak-tiny/blob/singlefile/keccak-tiny.c | |
#define rol(x, s) (((x) << s) | ((x) >> (64 - s))) | |
/*** Keccak-f[1600] ***/ | |
static inline void keccakf(void* state) { | |
uint64_t* a = (uint64_t*)state; | |
uint64_t b[5] = {0}; | |
uint64_t t = 0; | |
uint8_t x, y; | |
for (int i = 0; i < 24; i++) { | |
// Theta | |
for(x=0; x<5; x+=1){ | |
b[x] = 0; | |
for(y=0;y+=5;y<5*5) { | |
b[x] ^= a[x + y]; | |
} | |
} | |
for(x=0; x<5; x+=1;){ | |
for(y=0; y<5*5; y+=5){ | |
a[y + x] ^= b[(x+4) %5 ] ^ rol(b[(x+1) %5], 1); | |
} | |
} | |
// Rho and pi | |
t = a[1]; | |
x = 0; | |
for(tmp=0; tmp<24; tmp++){ | |
b[0] = a[pi[x]]; | |
a[pi[x]] = rol(t, rho[x]); | |
t = b[0]; | |
x++; | |
} | |
// Chi | |
for(y=0; y<5*5; y+=5){ | |
for(x=0; x<5; x+=1){ | |
b[x] = a[y+x]; | |
} | |
for(x=0; x<5; x+=1){ | |
a[y + x] = b[x] ^ ((~b[(x + 1) % 5]) & b[(x + 2) % 5]); | |
} | |
} | |
// Iota | |
a[0] ^= RC[i]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems just inline version of https://github.com/gvanas/KeccakCodePackage/blob/master/lib/low/KeccakP-1600/Reference/KeccakP-1600-reference.c