lib/keccak.c
void theta(uint64_t a[5][5], uint64_t b[5][5], KECCAK_CTX *ctx) {
    uint8_t x, y;
    uint64_t z;

    size_t w = ctx->w;

    // Build a lookup table of column XOR sums
    // For all pairs (x, z) such that 0 ≤ x < 5 and 0 ≤ z < w, let
    // C[x,z]=a[x,0,z] ⊕ a[x,1,z] ⊕ a[x,2,z] ⊕ a[x,3,z] ⊕ a[x,4,z]
    uint64_t c[5];
    for (x = 0; x < 5; x++) {
        for (z = 0; z < w; z++) {
            c[x] = (c[x] & (~(1 << z))) | (((a[x][0] & (1 << z)) ^ (a[x][1] & (1 << z)) ^ (a[x][2] & (1 << z)) ^ (a[x][3] & (1 << z)) ^ (a[x][4] & (1 << z))) << z);
        }
    }

    // Build a lookup table of the xor sum of two column xor sums
    // For all pairs (x, z) such that 0 ≤ x < 5 and 0 ≤ z < w let
    // D[x, z]=C[(x-1) mod 5, z] ⊕ C[(x+1) mod 5, (z – 1) mod w]
    uint64_t d[5];
    for (x = 0; x < 5; x++) {
        for (z = 0; z < w; z++) {
            d[x] = (d[x] & (~(1 << z))) | (((c[x - 1 % 5] & (1 << z)) ^ ((c[x + 1] & (1 << (z - 1 % 5))))) << z);
        }
    }

    // Assign the correct bit in the output by using the d lookup table
    // For all triples (x, y, z) such that 0 ≤ x < 5, 0 ≤ y < 5, and 0 ≤ z < w, let
    // b[x,y,z] = a[x,y,z] ⊕ D[x,z]
    for (x = 0; x < 5; x++) {
        for (y = 0; y < 5; y++) {
            for (z = 0; z < w; z++) {
                b[x][y] = (a[x][y] & (~(1 << z))) | ((d[x] & (1 << z)) << z);
            }
        }
    }
}
// TODO: Change to use get/set bit
Change to use get/set bit
Change to use get / set bit
void theta(uint64_t a[5][5], uint64_t b[5][5], KECCAK_CTX *ctx) {
    uint8_t x, y;
    uint64_t z;
    size_t w = ctx->w;
    uint64_t c[5];
    for (x = 0; x < 5; x++) {
        for (z = 0; z < w; z++) {
            c[x] = (c[x] & (~(1 << z))) | (((a[x][0] & (1 << z)) ^ (a[x][1] & (1 << z)) ^ (a[x][2] & (1 << z)) ^ (a[x][3] & (1 << z)) ^ (a[x][4] & (1 << z))) << z);
        }
    }
    uint64_t d[5];
    for (x = 0; x < 5; x++) {
        for (z = 0; z < w; z++) {
            d[x] = (d[x] & (~(1 << z))) | (((c[x - 1 % 5] & (1 << z)) ^ ((c[x + 1] & (1 << (z - 1 % 5))))) << z);
        }
    }
    for (x = 0; x < 5; x++) {
        for (y = 0; y < 5; y++) {
            for (z = 0; z < w; z++) {
                b[x][y] = (a[x][y] & (~(1 << z))) | ((d[x] & (1 << z)) << z);
            }
        }
    }
}
void theta ( uint64_t a [ 5 ] [ 5 ] , uint64_t b [ 5 ] [ 5 ] , KECCAK_CTX * ctx ) { uint8_t x , y ; uint64_t z ; size_t w = ctx -> w ; uint64_t c [ 5 ] ; for ( x = 0 ; x < 5 ; x ++ ) { for ( z = 0 ; z < w ; z ++ ) { c [ x ] = ( c [ x ] & ( ~ ( 1 << z ) ) ) | ( ( ( a [ x ] [ 0 ] & ( 1 << z ) ) ^ ( a [ x ] [ 1 ] & ( 1 << z ) ) ^ ( a [ x ] [ 2 ] & ( 1 << z ) ) ^ ( a [ x ] [ 3 ] & ( 1 << z ) ) ^ ( a [ x ] [ 4 ] & ( 1 << z ) ) ) << z ) ; } } uint64_t d [ 5 ] ; for ( x = 0 ; x < 5 ; x ++ ) { for ( z = 0 ; z < w ; z ++ ) { d [ x ] = ( d [ x ] & ( ~ ( 1 << z ) ) ) | ( ( ( c [ x - 1 % 5 ] & ( 1 << z ) ) ^ ( ( c [ x + 1 ] & ( 1 << ( z - 1 % 5 ) ) ) ) ) << z ) ; } } for ( x = 0 ; x < 5 ; x ++ ) { for ( y = 0 ; y < 5 ; y ++ ) { for ( z = 0 ; z < w ; z ++ ) { b [ x ] [ y ] = ( a [ x ] [ y ] & ( ~ ( 1 << z ) ) ) | ( ( d [ x ] & ( 1 << z ) ) << z ) ; } } } }
TODO: Change to use get/set bit
TODO : Change to use get / set bit
// Build a lookup table of column XOR sums // For all pairs (x, z) such that 0 ≤ x < 5 and 0 ≤ z < w, let // C[x,z]=a[x,0,z] ⊕ a[x,1,z] ⊕ a[x,2,z] ⊕ a[x,3,z] ⊕ a[x,4,z] // Build a lookup table of the xor sum of two column xor sums // For all pairs (x, z) such that 0 ≤ x < 5 and 0 ≤ z < w let // D[x, z]=C[(x-1) mod 5, z] ⊕ C[(x+1) mod 5, (z – 1) mod w] // Assign the correct bit in the output by using the d lookup table // For all triples (x, y, z) such that 0 ≤ x < 5, 0 ≤ y < 5, and 0 ≤ z < w, let // b[x,y,z] = a[x,y,z] ⊕ D[x,z]