Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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