diff options
Diffstat (limited to 'speck.c')
-rw-r--r-- | speck.c | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -0,0 +1,29 @@ +#include <linux/kernel.h> + +#define R(x, y, k) (x = ror64(x, 8), x += y, x ^= k, y = rol64(y, 3), y ^= x) +#define ROUNDS 32 + +static inline void speck(u64 ct[2], const u64 pt[2], const u64 key[2]) +{ + u64 y = pt[0], x = pt[1], b = key[0], a = key[1]; + int i; + + R(x, y, b); + for (i = 0; i < ROUNDS - 1; ++i) { + R(a, b, i); + R(x, y, b); + } + ct[0] = y; + ct[1] = x; +} + +void mix_speck(u32 h[4], const u32 v[4]) +{ + u32 n[4]; + + speck((u64 *)n, (u64 *)h, (const u64 *)v); + h[0] ^= n[0]; + h[1] ^= n[1]; + h[2] ^= n[2]; + h[3] ^= n[3]; +} |