Skip to content

Commit 49ae027

Browse files
committed
Improve ChaCha performance a little more
This replaces a few checked arithmetic operations with wrapping ones, improving the performance a bit.
1 parent 48734d3 commit 49ae027

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

std/src/std/crypto/chacha.inko

+4-4
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,8 @@ type pub inline ChaCha {
380380

381381
while i < MATRIX_SIZE {
382382
@tmp.set(i, to_u32(@tmp.get(i).wrapping_add(@matrix.get(i))))
383-
little.write_i32(@tmp.get(i), into: @buffer, at: i * 4)
384-
i += 1
383+
little.write_i32(@tmp.get(i), into: @buffer, at: i.wrapping_mul(4))
384+
i = i.wrapping_add(1)
385385
}
386386

387387
# The chance of this overflowing is practically zero, but we use checked
@@ -398,7 +398,7 @@ type pub inline ChaCha {
398398
let idx = offset.wrapping_add(i)
399399

400400
bytes.set(idx, bytes.get(idx) ^ @buffer.get(i))
401-
i += 1
401+
i = i.wrapping_add(1)
402402
}
403403

404404
return
@@ -410,7 +410,7 @@ type pub inline ChaCha {
410410
let idx = offset.wrapping_add(i)
411411

412412
bytes.set(idx, bytes.get(idx) ^ @buffer.get(i))
413-
i += 1
413+
i = i.wrapping_add(1)
414414
}
415415

416416
len = len.wrapping_sub(BLOCK_SIZE)

0 commit comments

Comments
 (0)