aboutsummaryrefslogtreecommitdiffstats
path: root/quarcha.c
blob: 5643a97abeca9f978e4adbefd571a9a157a3f383 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <linux/kernel.h>
#include <linux/string.h>

#define R(r, a, b, c, d) ( \
	a += b + (r ^ key[0]), \
	d = rol32(d ^ a, 16), \
	c += d + (r ^ key[1]), \
	b = rol32(b ^ c, 12), \
	a += b + (r ^ key[2]), \
	d = rol32(d ^ a, 8), \
	c += d + (r ^ key[3]), \
	b = rol32(b ^ c, 7))

static const u32 rc[4] = {
	/* expand 32-byte k */
	0x61707865U, 0x3320646eU, 0x79622d32U, 0x6b206574U
};

static inline void blockcipher(u32 block[4], const u32 key[4])
{
	R(rc[0], block[0], block[1], block[2], block[3]);
	R(rc[1], block[3], block[2], block[1], block[0]);
	R(rc[2], block[2], block[3], block[0], block[1]);
	R(rc[3], block[1], block[0], block[3], block[2]);
}

void mix_quarcha(u32 h[4], const u32 m[4])
{
	u32 n[4];
	memcpy(n, h, sizeof(n));
	blockcipher(h, m);
	h[0] ^= n[0];
	h[1] ^= n[1];
	h[2] ^= n[2];
	h[3] ^= n[3];
}