Blame view
crypto/aegis.h
1.79 KB
ea5d8cfa3 crypto: aegis - C... |
1 |
/* SPDX-License-Identifier: GPL-2.0-or-later */ |
f606a88e5 crypto: aegis - A... |
2 3 4 5 6 |
/* * AEGIS common definitions * * Copyright (c) 2018 Ondrej Mosnacek <omosnacek@gmail.com> * Copyright (c) 2018 Red Hat, Inc. All rights reserved. |
f606a88e5 crypto: aegis - A... |
7 8 9 10 11 12 |
*/ #ifndef _CRYPTO_AEGIS_H #define _CRYPTO_AEGIS_H #include <crypto/aes.h> |
521cdde75 crypto: aegis - a... |
13 |
#include <linux/bitops.h> |
f606a88e5 crypto: aegis - A... |
14 15 16 17 18 19 |
#include <linux/types.h> #define AEGIS_BLOCK_SIZE 16 union aegis_block { __le64 words64[AEGIS_BLOCK_SIZE / sizeof(__le64)]; |
4a34e3c2f crypto: aegis/gen... |
20 |
__le32 words32[AEGIS_BLOCK_SIZE / sizeof(__le32)]; |
f606a88e5 crypto: aegis - A... |
21 22 23 24 25 |
u8 bytes[AEGIS_BLOCK_SIZE]; }; #define AEGIS_BLOCK_ALIGN (__alignof__(union aegis_block)) #define AEGIS_ALIGNED(p) IS_ALIGNED((uintptr_t)p, AEGIS_BLOCK_ALIGN) |
97ac82d91 crypto: aegis - f... |
26 27 |
static __always_inline void crypto_aegis_block_xor(union aegis_block *dst, const union aegis_block *src) |
f606a88e5 crypto: aegis - A... |
28 29 30 31 |
{ dst->words64[0] ^= src->words64[0]; dst->words64[1] ^= src->words64[1]; } |
97ac82d91 crypto: aegis - f... |
32 33 |
static __always_inline void crypto_aegis_block_and(union aegis_block *dst, const union aegis_block *src) |
f606a88e5 crypto: aegis - A... |
34 35 36 37 |
{ dst->words64[0] &= src->words64[0]; dst->words64[1] &= src->words64[1]; } |
97ac82d91 crypto: aegis - f... |
38 39 40 |
static __always_inline void crypto_aegis_aesenc(union aegis_block *dst, const union aegis_block *src, const union aegis_block *key) |
f606a88e5 crypto: aegis - A... |
41 |
{ |
f606a88e5 crypto: aegis - A... |
42 |
const u8 *s = src->bytes; |
521cdde75 crypto: aegis - a... |
43 |
const u32 *t = crypto_ft_tab[0]; |
f606a88e5 crypto: aegis - A... |
44 |
u32 d0, d1, d2, d3; |
521cdde75 crypto: aegis - a... |
45 46 47 48 |
d0 = t[s[ 0]] ^ rol32(t[s[ 5]], 8) ^ rol32(t[s[10]], 16) ^ rol32(t[s[15]], 24); d1 = t[s[ 4]] ^ rol32(t[s[ 9]], 8) ^ rol32(t[s[14]], 16) ^ rol32(t[s[ 3]], 24); d2 = t[s[ 8]] ^ rol32(t[s[13]], 8) ^ rol32(t[s[ 2]], 16) ^ rol32(t[s[ 7]], 24); d3 = t[s[12]] ^ rol32(t[s[ 1]], 8) ^ rol32(t[s[ 6]], 16) ^ rol32(t[s[11]], 24); |
f606a88e5 crypto: aegis - A... |
49 |
|
4a34e3c2f crypto: aegis/gen... |
50 51 52 53 |
dst->words32[0] = cpu_to_le32(d0) ^ key->words32[0]; dst->words32[1] = cpu_to_le32(d1) ^ key->words32[1]; dst->words32[2] = cpu_to_le32(d2) ^ key->words32[2]; dst->words32[3] = cpu_to_le32(d3) ^ key->words32[3]; |
f606a88e5 crypto: aegis - A... |
54 55 56 |
} #endif /* _CRYPTO_AEGIS_H */ |