| ... | ... | @@ -40,8 +40,8 @@ pub const State = struct { |
| 40 | 40 | |
| 41 | 41 | pub fn permute(self: *Self) void { |
| 42 | 42 | const state = &self.data; |
| 43 | | var round = @as(u32, 24); |
| 44 | | while (round > 0) : (round -= 1) { |
| 43 | comptime var round = @as(u32, 24); |
| 44 | inline while (round > 0) : (round -= 1) { |
| 45 | 45 | var column = @as(usize, 0); |
| 46 | 46 | while (column < 4) : (column += 1) { |
| 47 | 47 | const x = math.rotl(u32, state[column], 24); |
| ... | ... | @@ -249,15 +249,19 @@ pub const Aead = struct { |
| 249 | 249 | in = in[State.RATE..]; |
| 250 | 250 | out = out[State.RATE..]; |
| 251 | 251 | }) { |
| 252 | | for (buf[0..State.RATE]) |*p, i| { |
| 253 | | p.* ^= in[i]; |
| 254 | | out[i] = p.*; |
| 252 | const d = in[0..State.RATE]; |
| 253 | for (d) |v, i| { |
| 254 | buf[i] ^= v; |
| 255 | } |
| 256 | for (d) |_, i| { |
| 257 | out[i] = buf[i]; |
| 255 | 258 | } |
| 256 | 259 | state.permute(); |
| 257 | 260 | } |
| 258 | | for (buf[0..in.len]) |*p, i| { |
| 259 | | p.* ^= in[i]; |
| 260 | | out[i] = p.*; |
| 261 | const d = in[0..]; |
| 262 | for (d) |v, i| { |
| 263 | buf[i] ^= v; |
| 264 | out[i] = buf[i]; |
| 261 | 265 | } |
| 262 | 266 | |
| 263 | 267 | // XOR 1 into the next byte of the state |
| ... | ... | @@ -291,15 +295,19 @@ pub const Aead = struct { |
| 291 | 295 | in = in[State.RATE..]; |
| 292 | 296 | out = out[State.RATE..]; |
| 293 | 297 | }) { |
| 294 | | for (buf[0..State.RATE]) |*p, i| { |
| 295 | | out[i] = p.* ^ in[i]; |
| 296 | | p.* = in[i]; |
| 298 | const d = in[0..State.RATE].*; |
| 299 | for (d) |v, i| { |
| 300 | out[i] = buf[i] ^ v; |
| 301 | } |
| 302 | for (d) |v, i| { |
| 303 | buf[i] = v; |
| 297 | 304 | } |
| 298 | 305 | state.permute(); |
| 299 | 306 | } |
| 300 | 307 | for (buf[0..in.len]) |*p, i| { |
| 301 | | out[i] = p.* ^ in[i]; |
| 302 | | p.* = in[i]; |
| 308 | const d = in[i]; |
| 309 | out[i] = p.* ^ d; |
| 310 | p.* = d; |
| 303 | 311 | } |
| 304 | 312 | |
| 305 | 313 | // XOR 1 into the next byte of the state |