aegis.h (c74a7469f97c0f40b46e82ee979f9fb1bb6e847c) aegis.h (4a34e3c2f2f48f47213702a84a123af0fe21ad60)
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * AEGIS common definitions
4 *
5 * Copyright (c) 2018 Ondrej Mosnacek <omosnacek@gmail.com>
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

--- 7 unchanged lines hidden (view full) ---

16
17#include <crypto/aes.h>
18#include <linux/types.h>
19
20#define AEGIS_BLOCK_SIZE 16
21
22union aegis_block {
23 __le64 words64[AEGIS_BLOCK_SIZE / sizeof(__le64)];
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * AEGIS common definitions
4 *
5 * Copyright (c) 2018 Ondrej Mosnacek <omosnacek@gmail.com>
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

--- 7 unchanged lines hidden (view full) ---

16
17#include <crypto/aes.h>
18#include <linux/types.h>
19
20#define AEGIS_BLOCK_SIZE 16
21
22union aegis_block {
23 __le64 words64[AEGIS_BLOCK_SIZE / sizeof(__le64)];
24 u32 words32[AEGIS_BLOCK_SIZE / sizeof(u32)];
24 __le32 words32[AEGIS_BLOCK_SIZE / sizeof(__le32)];
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
31static const union aegis_block crypto_aegis_const[2] = {
32 { .words64 = {

--- 19 unchanged lines hidden (view full) ---

52 dst->words64[0] &= src->words64[0];
53 dst->words64[1] &= src->words64[1];
54}
55
56static void crypto_aegis_aesenc(union aegis_block *dst,
57 const union aegis_block *src,
58 const union aegis_block *key)
59{
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
31static const union aegis_block crypto_aegis_const[2] = {
32 { .words64 = {

--- 19 unchanged lines hidden (view full) ---

52 dst->words64[0] &= src->words64[0];
53 dst->words64[1] &= src->words64[1];
54}
55
56static 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;
60 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
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];
65 u32 d0, d1, d2, d3;
66
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];
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]];
73
71
74 d[0] = d0;
75 d[1] = d1;
76 d[2] = d2;
77 d[3] = d3;
72 dst->words32[0] = cpu_to_le32(d0) ^ key->words32[0];
73 dst->words32[1] = cpu_to_le32(d1) ^ key->words32[1];
74 dst->words32[2] = cpu_to_le32(d2) ^ key->words32[2];
75 dst->words32[3] = cpu_to_le32(d3) ^ key->words32[3];
78}
79
80#endif /* _CRYPTO_AEGIS_H */
76}
77
78#endif /* _CRYPTO_AEGIS_H */