.. | .. |
---|
1 | | -/* SPDX-License-Identifier: GPL-2.0 */ |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-or-later */ |
---|
2 | 2 | /* |
---|
3 | 3 | * AEGIS common definitions |
---|
4 | 4 | * |
---|
5 | 5 | * Copyright (c) 2018 Ondrej Mosnacek <omosnacek@gmail.com> |
---|
6 | 6 | * Copyright (c) 2018 Red Hat, Inc. All rights reserved. |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify it |
---|
9 | | - * under the terms of the GNU General Public License as published by the Free |
---|
10 | | - * Software Foundation; either version 2 of the License, or (at your option) |
---|
11 | | - * any later version. |
---|
12 | 7 | */ |
---|
13 | 8 | |
---|
14 | 9 | #ifndef _CRYPTO_AEGIS_H |
---|
15 | 10 | #define _CRYPTO_AEGIS_H |
---|
16 | 11 | |
---|
17 | 12 | #include <crypto/aes.h> |
---|
| 13 | +#include <linux/bitops.h> |
---|
18 | 14 | #include <linux/types.h> |
---|
19 | 15 | |
---|
20 | 16 | #define AEGIS_BLOCK_SIZE 16 |
---|
.. | .. |
---|
28 | 24 | #define AEGIS_BLOCK_ALIGN (__alignof__(union aegis_block)) |
---|
29 | 25 | #define AEGIS_ALIGNED(p) IS_ALIGNED((uintptr_t)p, AEGIS_BLOCK_ALIGN) |
---|
30 | 26 | |
---|
31 | | -static const union aegis_block crypto_aegis_const[2] = { |
---|
32 | | - { .words64 = { |
---|
33 | | - cpu_to_le64(U64_C(0x0d08050302010100)), |
---|
34 | | - cpu_to_le64(U64_C(0x6279e99059372215)), |
---|
35 | | - } }, |
---|
36 | | - { .words64 = { |
---|
37 | | - cpu_to_le64(U64_C(0xf12fc26d55183ddb)), |
---|
38 | | - cpu_to_le64(U64_C(0xdd28b57342311120)), |
---|
39 | | - } }, |
---|
40 | | -}; |
---|
41 | | - |
---|
42 | | -static void crypto_aegis_block_xor(union aegis_block *dst, |
---|
43 | | - const union aegis_block *src) |
---|
| 27 | +static __always_inline void crypto_aegis_block_xor(union aegis_block *dst, |
---|
| 28 | + const union aegis_block *src) |
---|
44 | 29 | { |
---|
45 | 30 | dst->words64[0] ^= src->words64[0]; |
---|
46 | 31 | dst->words64[1] ^= src->words64[1]; |
---|
47 | 32 | } |
---|
48 | 33 | |
---|
49 | | -static void crypto_aegis_block_and(union aegis_block *dst, |
---|
50 | | - const union aegis_block *src) |
---|
| 34 | +static __always_inline void crypto_aegis_block_and(union aegis_block *dst, |
---|
| 35 | + const union aegis_block *src) |
---|
51 | 36 | { |
---|
52 | 37 | dst->words64[0] &= src->words64[0]; |
---|
53 | 38 | dst->words64[1] &= src->words64[1]; |
---|
54 | 39 | } |
---|
55 | 40 | |
---|
56 | | -static void crypto_aegis_aesenc(union aegis_block *dst, |
---|
57 | | - const union aegis_block *src, |
---|
58 | | - const union aegis_block *key) |
---|
| 41 | +static __always_inline void crypto_aegis_aesenc(union aegis_block *dst, |
---|
| 42 | + const union aegis_block *src, |
---|
| 43 | + const union aegis_block *key) |
---|
59 | 44 | { |
---|
60 | 45 | const u8 *s = src->bytes; |
---|
61 | | - const u32 *t0 = crypto_ft_tab[0]; |
---|
62 | | - const u32 *t1 = crypto_ft_tab[1]; |
---|
63 | | - const u32 *t2 = crypto_ft_tab[2]; |
---|
64 | | - const u32 *t3 = crypto_ft_tab[3]; |
---|
| 46 | + const u32 *t = crypto_ft_tab[0]; |
---|
65 | 47 | u32 d0, d1, d2, d3; |
---|
66 | 48 | |
---|
67 | | - d0 = t0[s[ 0]] ^ t1[s[ 5]] ^ t2[s[10]] ^ t3[s[15]]; |
---|
68 | | - d1 = t0[s[ 4]] ^ t1[s[ 9]] ^ t2[s[14]] ^ t3[s[ 3]]; |
---|
69 | | - d2 = t0[s[ 8]] ^ t1[s[13]] ^ t2[s[ 2]] ^ t3[s[ 7]]; |
---|
70 | | - d3 = t0[s[12]] ^ t1[s[ 1]] ^ t2[s[ 6]] ^ t3[s[11]]; |
---|
| 49 | + d0 = t[s[ 0]] ^ rol32(t[s[ 5]], 8) ^ rol32(t[s[10]], 16) ^ rol32(t[s[15]], 24); |
---|
| 50 | + d1 = t[s[ 4]] ^ rol32(t[s[ 9]], 8) ^ rol32(t[s[14]], 16) ^ rol32(t[s[ 3]], 24); |
---|
| 51 | + d2 = t[s[ 8]] ^ rol32(t[s[13]], 8) ^ rol32(t[s[ 2]], 16) ^ rol32(t[s[ 7]], 24); |
---|
| 52 | + d3 = t[s[12]] ^ rol32(t[s[ 1]], 8) ^ rol32(t[s[ 6]], 16) ^ rol32(t[s[11]], 24); |
---|
71 | 53 | |
---|
72 | 54 | dst->words32[0] = cpu_to_le32(d0) ^ key->words32[0]; |
---|
73 | 55 | dst->words32[1] = cpu_to_le32(d1) ^ key->words32[1]; |
---|