~tomleb/hare

3d06f9d20ff097d7c3a273c7059c8ca6ed4fe6db — Armin Preiml 9 months ago 93a427d
speed up crypto::argon2 a bit

Signed-off-by: Armin Preiml <apreiml@strohwolke.at>
1 files changed, 7 insertions(+), 11 deletions(-)

M crypto/argon2/argon2.ha
M crypto/argon2/argon2.ha => crypto/argon2/argon2.ha +7 -11
@@ 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;
};