| ... | @@ -123,35 +123,34 @@ fn keccak_f(comptime F: usize, d: []u8) void { | ... | @@ -123,35 +123,34 @@ fn keccak_f(comptime F: usize, d: []u8) void { |
| 123 | *r = mem.readIntLE(u64, d[8*i .. 8*i + 8]); | 123 | *r = mem.readIntLE(u64, d[8*i .. 8*i + 8]); |
| 124 | } | 124 | } |
| 125 | | 125 | |
| 126 | var x: usize = 0; | 126 | comptime var x: usize = 0; |
| 127 | var y: usize = 0; | 127 | comptime var y: usize = 0; |
| 128 | // TODO: Cannot unroll all loops here due to comptime differences. | 128 | for (RC[0..no_rounds]) |round| { |
| 129 | inline for (RC[0..no_rounds]) |round| { | | |
| 130 | // theta | 129 | // theta |
| 131 | x = 0; while (x < 5) : (x += 1) { | 130 | x = 0; inline while (x < 5) : (x += 1) { |
| 132 | c[x] = s[x] ^ s[x+5] ^ s[x+10] ^ s[x+15] ^ s[x+20]; | 131 | c[x] = s[x] ^ s[x+5] ^ s[x+10] ^ s[x+15] ^ s[x+20]; |
| 133 | } | 132 | } |
| 134 | x = 0; while (x < 5) : (x += 1) { | 133 | x = 0; inline while (x < 5) : (x += 1) { |
| 135 | t[0] = c[M5[x+4]] ^ math.rotl(u64, c[M5[x+1]], usize(1)); | 134 | t[0] = c[M5[x+4]] ^ math.rotl(u64, c[M5[x+1]], usize(1)); |
| 136 | y = 0; while (y < 5) : (y += 1) { | 135 | y = 0; inline while (y < 5) : (y += 1) { |
| 137 | s[x + y*5] ^= t[0]; | 136 | s[x + y*5] ^= t[0]; |
| 138 | } | 137 | } |
| 139 | } | 138 | } |
| 140 | | 139 | |
| 141 | // rho+pi | 140 | // rho+pi |
| 142 | t[0] = s[1]; | 141 | t[0] = s[1]; |
| 143 | x = 0; while (x < 24) : (x += 1) { | 142 | x = 0; inline while (x < 24) : (x += 1) { |
| 144 | c[0] = s[PIL[x]]; | 143 | c[0] = s[PIL[x]]; |
| 145 | s[PIL[x]] = math.rotl(u64, t[0], ROTC[x]); | 144 | s[PIL[x]] = math.rotl(u64, t[0], ROTC[x]); |
| 146 | t[0] = c[0]; | 145 | t[0] = c[0]; |
| 147 | } | 146 | } |
| 148 | | 147 | |
| 149 | // chi | 148 | // chi |
| 150 | y = 0; while (y < 5) : (y += 1) { | 149 | y = 0; inline while (y < 5) : (y += 1) { |
| 151 | x = 0; while (x < 5) : (x += 1) { | 150 | x = 0; inline while (x < 5) : (x += 1) { |
| 152 | c[x] = s[x + y*5]; | 151 | c[x] = s[x + y*5]; |
| 153 | } | 152 | } |
| 154 | x = 0; while (x < 5) : (x += 1) { | 153 | x = 0; inline while (x < 5) : (x += 1) { |
| 155 | s[x + y*5] = c[x] ^ (~c[M5[x+1]] & c[M5[x+2]]); | 154 | s[x + y*5] = c[x] ^ (~c[M5[x+1]] & c[M5[x+2]]); |
| 156 | } | 155 | } |
| 157 | } | 156 | } |