Skip to content

Commit f606a88

Browse files
WOnder93herbertx
authored andcommitted
crypto: aegis - Add generic AEGIS AEAD implementations
This patch adds the generic implementation of the AEGIS family of AEAD algorithms (AEGIS-128, AEGIS-128L, and AEGIS-256). The original authors of AEGIS are Hongjun Wu and Bart Preneel. At the time of writing, AEGIS is one of the finalists in CAESAR, an open competition intended to select a portfolio of alternatives to the problematic AES-GCM: https://competitions.cr.yp.to/caesar-submissions.html https://competitions.cr.yp.to/round3/aegisv11.pdf Signed-off-by: Ondrej Mosnacek <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent 15f47ce commit f606a88

File tree

6 files changed

+1572
-0
lines changed

6 files changed

+1572
-0
lines changed

crypto/Kconfig

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,27 @@ config CRYPTO_CHACHA20POLY1305
289289
with the Poly1305 authenticator. It is defined in RFC7539 for use in
290290
IETF protocols.
291291

292+
config CRYPTO_AEGIS128
293+
tristate "AEGIS-128 AEAD algorithm"
294+
select CRYPTO_AEAD
295+
select CRYPTO_AES # for AES S-box tables
296+
help
297+
Support for the AEGIS-128 dedicated AEAD algorithm.
298+
299+
config CRYPTO_AEGIS128L
300+
tristate "AEGIS-128L AEAD algorithm"
301+
select CRYPTO_AEAD
302+
select CRYPTO_AES # for AES S-box tables
303+
help
304+
Support for the AEGIS-128L dedicated AEAD algorithm.
305+
306+
config CRYPTO_AEGIS256
307+
tristate "AEGIS-256 AEAD algorithm"
308+
select CRYPTO_AEAD
309+
select CRYPTO_AES # for AES S-box tables
310+
help
311+
Support for the AEGIS-256 dedicated AEAD algorithm.
312+
292313
config CRYPTO_SEQIV
293314
tristate "Sequence Number IV Generator"
294315
select CRYPTO_AEAD

crypto/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ obj-$(CONFIG_CRYPTO_KEYWRAP) += keywrap.o
8686
obj-$(CONFIG_CRYPTO_GCM) += gcm.o
8787
obj-$(CONFIG_CRYPTO_CCM) += ccm.o
8888
obj-$(CONFIG_CRYPTO_CHACHA20POLY1305) += chacha20poly1305.o
89+
obj-$(CONFIG_CRYPTO_AEGIS128) += aegis128.o
90+
obj-$(CONFIG_CRYPTO_AEGIS128L) += aegis128l.o
91+
obj-$(CONFIG_CRYPTO_AEGIS256) += aegis256.o
8992
obj-$(CONFIG_CRYPTO_PCRYPT) += pcrypt.o
9093
obj-$(CONFIG_CRYPTO_CRYPTD) += cryptd.o
9194
obj-$(CONFIG_CRYPTO_MCRYPTD) += mcryptd.o

crypto/aegis.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* AEGIS common definitions
4+
*
5+
* Copyright (c) 2018 Ondrej Mosnacek <[email protected]>
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+
*/
13+
14+
#ifndef _CRYPTO_AEGIS_H
15+
#define _CRYPTO_AEGIS_H
16+
17+
#include <crypto/aes.h>
18+
#include <linux/types.h>
19+
20+
#define AEGIS_BLOCK_SIZE 16
21+
22+
union aegis_block {
23+
__le64 words64[AEGIS_BLOCK_SIZE / sizeof(__le64)];
24+
u32 words32[AEGIS_BLOCK_SIZE / sizeof(u32)];
25+
u8 bytes[AEGIS_BLOCK_SIZE];
26+
};
27+
28+
#define AEGIS_BLOCK_ALIGN (__alignof__(union aegis_block))
29+
#define AEGIS_ALIGNED(p) IS_ALIGNED((uintptr_t)p, AEGIS_BLOCK_ALIGN)
30+
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)
44+
{
45+
dst->words64[0] ^= src->words64[0];
46+
dst->words64[1] ^= src->words64[1];
47+
}
48+
49+
static void crypto_aegis_block_and(union aegis_block *dst,
50+
const union aegis_block *src)
51+
{
52+
dst->words64[0] &= src->words64[0];
53+
dst->words64[1] &= src->words64[1];
54+
}
55+
56+
static void crypto_aegis_aesenc(union aegis_block *dst,
57+
const union aegis_block *src,
58+
const union aegis_block *key)
59+
{
60+
u32 *d = dst->words32;
61+
const u8 *s = src->bytes;
62+
const u32 *k = key->words32;
63+
const u32 *t0 = crypto_ft_tab[0];
64+
const u32 *t1 = crypto_ft_tab[1];
65+
const u32 *t2 = crypto_ft_tab[2];
66+
const u32 *t3 = crypto_ft_tab[3];
67+
u32 d0, d1, d2, d3;
68+
69+
d0 = t0[s[ 0]] ^ t1[s[ 5]] ^ t2[s[10]] ^ t3[s[15]] ^ k[0];
70+
d1 = t0[s[ 4]] ^ t1[s[ 9]] ^ t2[s[14]] ^ t3[s[ 3]] ^ k[1];
71+
d2 = t0[s[ 8]] ^ t1[s[13]] ^ t2[s[ 2]] ^ t3[s[ 7]] ^ k[2];
72+
d3 = t0[s[12]] ^ t1[s[ 1]] ^ t2[s[ 6]] ^ t3[s[11]] ^ k[3];
73+
74+
d[0] = d0;
75+
d[1] = d1;
76+
d[2] = d2;
77+
d[3] = d3;
78+
}
79+
80+
#endif /* _CRYPTO_AEGIS_H */

0 commit comments

Comments
 (0)