commit 3d06f9d20ff097d7c3a273c7059c8ca6ed4fe6db
parent 93a427d2a8ae7630a7582933a8236be4bbdd7b8d
Author: Armin Preiml <apreiml@strohwolke.at>
Date: Thu, 9 Nov 2023 16:01:28 +0100
speed up crypto::argon2 a bit
Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
Diffstat:
1 file changed, 7 insertions(+), 11 deletions(-)
diff --git a/crypto/argon2/argon2.ha b/crypto/argon2/argon2.ha
@@ -382,9 +382,9 @@ fn divceil(dividend: u32, divisor: u32) u32 = {
};
fn xorblock(dest: []u64, x: []u64, y: []u64) void = {
- math::xor((dest: *[*]u8)[..len(dest) * size(u64)],
- (x: *[*]u8)[..len(dest) * size(u64)],
- (y: *[*]u8)[..len(dest) * size(u64)]);
+ for (let i = 0z; i < len(dest); i += 1) {
+ dest[i] = x[i] ^ y[i];
+ };
};
fn segproc(cfg: *conf, ctx: *context, i: size, slice: size) void = {
@@ -508,17 +508,13 @@ fn perm(
};
fn mix(a: *u64, b: *u64, c: *u64, d: *u64) void = {
- *a = *a + *b + 2 * trunc(*a) * trunc(*b);
+ *a = *a + *b + 2 * (*a & 0xffffffff) * (*b & 0xffffffff);
*d = math::rotr64(*d ^ *a, 32);
- *c = *c + *d + 2 * trunc(*c) * trunc(*d);
+ *c = *c + *d + 2 * (*c & 0xffffffff) * (*d & 0xffffffff);
*b = math::rotr64(*b ^ *c, 24);
- *a = *a + *b + 2 * trunc(*a) * trunc(*b);
+ *a = *a + *b + 2 * (*a & 0xffffffff) * (*b & 0xffffffff);
*d = math::rotr64(*d ^ *a, 16);
- *c = *c + *d + 2 * trunc(*c) * trunc(*d);
+ *c = *c + *d + 2 * (*c & 0xffffffff) * (*d & 0xffffffff);
*b = math::rotr64(*b ^ *c, 63);
};
-
-fn trunc(a: u64) u64 = {
- return a & 0xffffffff;
-};