| 1 |
/* camellia-simd128.h - Camellia cipher SIMD128 intrinsics implementation |
| 2 |
* Copyright (C) 2023,2025 Jussi Kivilinna <[email protected]> |
| 3 |
* |
| 4 |
* This file is part of Libgcrypt. |
| 5 |
* |
| 6 |
* Libgcrypt is free software; you can redistribute it and/or modify |
| 7 |
* it under the terms of the GNU Lesser General Public License as |
| 8 |
* published by the Free Software Foundation; either version 2.1 of |
| 9 |
* the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* Libgcrypt is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU Lesser General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU Lesser General Public |
| 17 |
* License along with this program; if not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
/* |
| 21 |
* SSE/AVX/NEON implementation of Camellia cipher, using AES-NI/ARMv8-CE/ |
| 22 |
* PPC-crypto for sbox calculations. This implementation takes 16 input blocks |
| 23 |
* and process them in parallel. Vectorized key setup is also available at |
| 24 |
* the end of file. This implementation is from |
| 25 |
* - https://github.com/jkivilin/camellia-simd-aesni |
| 26 |
* |
| 27 |
* This work was originally presented in Master's Thesis, |
| 28 |
* "Block Ciphers: Fast Implementations on x86-64 Architecture" (pages 42-50) |
| 29 |
* http://urn.fi/URN:NBN:fi:oulu-201305311409 |
| 30 |
*/ |
| 31 |
|
| 32 |
#include <config.h> |
| 33 |
#include "types.h" |
| 34 |
|
| 35 |
|
| 36 |
#define ALWAYS_INLINE inline __attribute__((always_inline)) |
| 37 |
#define NO_INLINE __attribute__((noinline)) |
| 38 |
#define NO_INSTRUMENT_FUNCTION __attribute__((no_instrument_function)) |
| 39 |
|
| 40 |
#define ASM_FUNC_ATTR NO_INSTRUMENT_FUNCTION |
| 41 |
#define ASM_FUNC_ATTR_INLINE ASM_FUNC_ATTR ALWAYS_INLINE |
| 42 |
#define ASM_FUNC_ATTR_NOINLINE ASM_FUNC_ATTR NO_INLINE SIMD128_OPT_ATTR |
| 43 |
|
| 44 |
|
| 45 |
#if defined(HAVE_GCC_INLINE_ASM_PPC_ALTIVEC) && !defined(WORDS_BIGENDIAN) |
| 46 |
|
| 47 |
/********************************************************************** |
| 48 |
AT&T x86 asm to intrinsics conversion macros (PowerPC VSX+crypto) |
| 49 |
**********************************************************************/ |
| 50 |
#include "simd-common-ppc.h" |
| 51 |
#include <altivec.h> |
| 52 |
|
| 53 |
typedef vector signed char int8x16_t; |
| 54 |
typedef vector unsigned char uint8x16_t; |
| 55 |
typedef vector unsigned short uint16x8_t; |
| 56 |
typedef vector unsigned int uint32x4_t; |
| 57 |
typedef vector unsigned long long uint64x2_t; |
| 58 |
typedef uint64x2_t __m128i; |
| 59 |
|
| 60 |
#ifdef __clang__ |
| 61 |
/* clang has mismatching prototype for vec_sbox_be. */ |
| 62 |
static ASM_FUNC_ATTR_INLINE uint8x16_t |
| 63 |
asm_sbox_be(uint8x16_t b) |
| 64 |
{ |
| 65 |
uint8x16_t o; |
| 66 |
__asm__ ("vsbox %0, %1\n\t" : "=v" (o) : "v" (b)); |
| 67 |
return o; |
| 68 |
} |
| 69 |
#undef vec_sbox_be |
| 70 |
#define vec_sbox_be asm_sbox_be |
| 71 |
#endif |
| 72 |
|
| 73 |
#define vec_bswap(a) ((__m128i)vec_reve((uint8x16_t)a)) |
| 74 |
|
| 75 |
#define vpand128(a, b, o) (o = vec_and(b, a)) |
| 76 |
#define vpandn128(a, b, o) (o = vec_andc(a, b)) |
| 77 |
#define vpxor128(a, b, o) (o = vec_xor(b, a)) |
| 78 |
#define vpor128(a, b, o) (o = vec_or(b, a)) |
| 79 |
|
| 80 |
#define vpsrlb128(s, a, o) ({ o = (__m128i)((uint8x16_t)a >> s); }) |
| 81 |
#define vpsllb128(s, a, o) ({ o = (__m128i)((uint8x16_t)a << s); }) |
| 82 |
#define vpsrlw128(s, a, o) ({ o = (__m128i)((uint16x8_t)a >> s); }) |
| 83 |
#define vpsllw128(s, a, o) ({ o = (__m128i)((uint16x8_t)a << s); }) |
| 84 |
#define vpsrld128(s, a, o) ({ o = (__m128i)((uint32x4_t)a >> s); }) |
| 85 |
#define vpslld128(s, a, o) ({ o = (__m128i)((uint32x4_t)a << s); }) |
| 86 |
#define vpsrlq128(s, a, o) ({ o = (__m128i)((uint64x2_t)a >> s); }) |
| 87 |
#define vpsllq128(s, a, o) ({ o = (__m128i)((uint64x2_t)a << s); }) |
| 88 |
#define vpsrldq128(s, a, o) ({ uint64x2_t __tmp = { 0, 0 }; \ |
| 89 |
o = (__m128i)vec_sld((uint8x16_t)__tmp, \ |
| 90 |
(uint8x16_t)a, (16 - (s)) & 15);}) |
| 91 |
#define vpslldq128(s, a, o) ({ uint64x2_t __tmp = { 0, 0 }; \ |
| 92 |
o = (__m128i)vec_sld((uint8x16_t)a, \ |
| 93 |
(uint8x16_t)__tmp, (s) & 15);}) |
| 94 |
|
| 95 |
#define if_vpsrlb128(...) __VA_ARGS__ |
| 96 |
#define if_not_vpsrlb128(...) /*_*/ |
| 97 |
#define vpsrl_byte_128(s, a, o) vpsrlb128(s, a, o) |
| 98 |
#define vpsll_byte_128(s, a, o) vpsllb128(s, a, o) |
| 99 |
|
| 100 |
#define if_vprolb128(...) __VA_ARGS__ |
| 101 |
#define if_not_vprolb128(...) /*_*/ |
| 102 |
#define vprolb128(s, a, o, tmp) ({ vpsllb128((s), a, tmp); \ |
| 103 |
vpsrlb128((8-(s)), a, o); \ |
| 104 |
vpxor128(tmp, o, o); }) |
| 105 |
|
| 106 |
#define vpaddb128(a, b, o) (o = (__m128i)vec_add((uint8x16_t)b, (uint8x16_t)a)) |
| 107 |
|
| 108 |
#define vpcmpgtb128(a, b, o) (o = (__m128i)vec_cmpgt((int8x16_t)b, (int8x16_t)a)) |
| 109 |
#define vpabsb128(a, o) (o = (__m128i)vec_abs((int8x16_t)a)) |
| 110 |
|
| 111 |
#define vpshufd128_0x4e(a, o) (o = (__m128i)vec_reve((uint64x2_t)a)) |
| 112 |
#define vpshufd128_0x1b(a, o) (o = (__m128i)vec_reve((uint32x4_t)a)) |
| 113 |
|
| 114 |
#define vpshufb128(m, a, o) \ |
| 115 |
({ uint64x2_t __tmpz = { 0, 0 }; \ |
| 116 |
o = (__m128i)vec_perm((uint8x16_t)a, (uint8x16_t)__tmpz, (uint8x16_t)m); }) |
| 117 |
|
| 118 |
#define vpunpckhdq128(a, b, o) (o = (__m128i)vec_mergel((uint32x4_t)b, (uint32x4_t)a)) |
| 119 |
#define vpunpckldq128(a, b, o) (o = (__m128i)vec_mergeh((uint32x4_t)b, (uint32x4_t)a)) |
| 120 |
#define vpunpckhqdq128(a, b, o) (o = (__m128i)vec_mergel((uint64x2_t)b, (uint64x2_t)a)) |
| 121 |
#define vpunpcklqdq128(a, b, o) (o = (__m128i)vec_mergeh((uint64x2_t)b, (uint64x2_t)a)) |
| 122 |
|
| 123 |
#define vmovdqa128(a, o) (o = a) |
| 124 |
#define vmovd128(a, o) ({ uint32x4_t __tmp = { (a), 0, 0, 0 }; \ |
| 125 |
o = (__m128i)(__tmp); }) |
| 126 |
#define vmovq128(a, o) ({ uint64x2_t __tmp = { (a), 0 }; \ |
| 127 |
o = (__m128i)(__tmp); }) |
| 128 |
|
| 129 |
#define vmovd128_amemld(z, a, o) ({ \ |
| 130 |
const uint32_t *__tmp_ptr = (const void *)(a); \ |
| 131 |
uint32x4_t __tmp = { __tmp_ptr[z], 0, 0, 0 }; \ |
| 132 |
o = (__m128i)(__tmp); }) |
| 133 |
#define vmovq128_amemld(a, o) ({ uint64x2_t __tmp = { *(const uint64_t *)(a), 0 }; \ |
| 134 |
o = (__m128i)(__tmp); }) |
| 135 |
|
| 136 |
#define vmovdqa128_memld(a, o) (o = *(const __m128i *)(a)) |
| 137 |
#define vmovdqa128_memst(a, o) (*(__m128i *)(o) = (a)) |
| 138 |
#define vpshufb128_amemld(m, a, o) vpshufb128(*(const __m128i *)(m), a, o) |
| 139 |
|
| 140 |
/* Following operations may have unaligned memory input */ |
| 141 |
#define vmovdqu128_memld(a, o) (o = (__m128i)vec_xl(0, (const uint8_t *)(a))) |
| 142 |
#define vpxor128_memld(a, b, o) vpxor128(b, (__m128i)vec_xl(0, (const uint8_t *)(a)), o) |
| 143 |
#define vmovq128_memld(a, o) ({ uint64x2_t __tmp = { *(const uint64_unaligned_t *)(a), 0 }; \ |
| 144 |
o = (__m128i)(__tmp); }) |
| 145 |
|
| 146 |
/* Following operations may have unaligned memory output */ |
| 147 |
#define vmovdqu128_memst(a, o) vec_xst((uint8x16_t)(a), 0, (uint8_t *)(o)) |
| 148 |
#define vmovq128_memst(a, o) (((uint64_unaligned_t *)(o))[0] = ((__m128i)(a))[0]) |
| 149 |
|
| 150 |
/* PowerPC AES encrypt last round => ShiftRows + SubBytes + XOR round key */ |
| 151 |
static const uint8x16_t shift_row __attribute__((unused)) = |
| 152 |
{ 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, 1, 6, 11 }; |
| 153 |
#define vaesenclast128(a, b, o) \ |
| 154 |
({ uint64x2_t __tmp = (__m128i)vec_sbox_be((uint8x16_t)(b)); \ |
| 155 |
vpshufb128(shift_row, __tmp, __tmp); \ |
| 156 |
vpxor128(a, __tmp, o); }) |
| 157 |
|
| 158 |
/* Macros for exposing SubBytes from PowerPC crypto instructions. */ |
| 159 |
#define aes_subbytes(a, o) \ |
| 160 |
(o = (__m128i)vec_sbox_be((uint8x16_t)(a))) |
| 161 |
#define aes_subbytes_and_shuf_and_xor(zero, a, o) \ |
| 162 |
vaesenclast128((zero), (a), (o)) |
| 163 |
/*#define aes_load_inv_shufmask(shufmask_reg) \ |
| 164 |
load_frequent_const(inv_shift_row, (shufmask_reg))*/ |
| 165 |
#define aes_inv_shuf(shufmask_reg, a, o) \ |
| 166 |
vpshufb128(shufmask_reg, (a), (o)) |
| 167 |
#define if_aes_subbytes(...) __VA_ARGS__ |
| 168 |
#define if_not_aes_subbytes(...) /*_*/ |
| 169 |
|
| 170 |
#define memory_barrier_with_vec(a) __asm__("" : "+wa"(a) :: "memory") |
| 171 |
|
| 172 |
#endif /* __powerpc__ */ |
| 173 |
|
| 174 |
#ifdef __ARM_NEON |
| 175 |
|
| 176 |
/********************************************************************** |
| 177 |
AT&T x86 asm to intrinsics conversion macros (ARMv8-CE) |
| 178 |
**********************************************************************/ |
| 179 |
#include "simd-common-aarch64.h" |
| 180 |
#include <arm_neon.h> |
| 181 |
|
| 182 |
#define __m128i uint64x2_t |
| 183 |
|
| 184 |
#define vpand128(a, b, o) (o = vandq_u64(b, a)) |
| 185 |
#define vpandn128(a, b, o) (o = vbicq_u64(a, b)) |
| 186 |
#define vpxor128(a, b, o) (o = veorq_u64(b, a)) |
| 187 |
#define vpor128(a, b, o) (o = vorrq_u64(b, a)) |
| 188 |
|
| 189 |
#define vpsrlb128(s, a, o) (o = (__m128i)vshrq_n_u8((uint8x16_t)a, s)) |
| 190 |
#define vpsllb128(s, a, o) (o = (__m128i)vshlq_n_u8((uint8x16_t)a, s)) |
| 191 |
#define vpsrlw128(s, a, o) (o = (__m128i)vshrq_n_u16((uint16x8_t)a, s)) |
| 192 |
#define vpsllw128(s, a, o) (o = (__m128i)vshlq_n_u16((uint16x8_t)a, s)) |
| 193 |
#define vpsrld128(s, a, o) (o = (__m128i)vshrq_n_u32((uint32x4_t)a, s)) |
| 194 |
#define vpslld128(s, a, o) (o = (__m128i)vshlq_n_u32((uint32x4_t)a, s)) |
| 195 |
#define vpsrlq128(s, a, o) (o = (__m128i)vshrq_n_u64(a, s)) |
| 196 |
#define vpsllq128(s, a, o) (o = (__m128i)vshlq_n_u64(a, s)) |
| 197 |
#define vpsrldq128(s, a, o) ({ uint64x2_t __tmp = { 0, 0 }; \ |
| 198 |
o = (__m128i)vextq_u8((uint8x16_t)a, \ |
| 199 |
(uint8x16_t)__tmp, (s) & 15);}) |
| 200 |
#define vpslldq128(s, a, o) ({ uint64x2_t __tmp = { 0, 0 }; \ |
| 201 |
o = (__m128i)vextq_u8((uint8x16_t)__tmp, \ |
| 202 |
(uint8x16_t)a, (16 - (s)) & 15);}) |
| 203 |
|
| 204 |
#define if_vpsrlb128(...) __VA_ARGS__ |
| 205 |
#define if_not_vpsrlb128(...) /*_*/ |
| 206 |
#define vpsrl_byte_128(s, a, o) vpsrlb128(s, a, o) |
| 207 |
#define vpsll_byte_128(s, a, o) vpsllb128(s, a, o) |
| 208 |
|
| 209 |
#define if_vprolb128(...) __VA_ARGS__ |
| 210 |
#define if_not_vprolb128(...) /*_*/ |
| 211 |
#define vprolb128(s, a, o, t) ({ t = (__m128i)vshlq_n_u8((uint8x16_t)a, s); \ |
| 212 |
o = (__m128i)vsriq_n_u8((uint8x16_t)t, \ |
| 213 |
(uint8x16_t)a, \ |
| 214 |
8-(s)); }) |
| 215 |
|
| 216 |
#define vpaddb128(a, b, o) (o = (__m128i)vaddq_u8((uint8x16_t)b, (uint8x16_t)a)) |
| 217 |
|
| 218 |
#define vpcmpgtb128(a, b, o) (o = (__m128i)vcgtq_s8((int8x16_t)b, (int8x16_t)a)) |
| 219 |
#define vpabsb128(a, o) (o = (__m128i)vabsq_s8((int8x16_t)a)) |
| 220 |
|
| 221 |
#define vpshufd128_0x4e(a, o) (o = (__m128i)vextq_u8((uint8x16_t)a, (uint8x16_t)a, 8)) |
| 222 |
#define vpshufd128_0x1b(a, o) (o = (__m128i)vrev64q_u32((uint32x4_t)vextq_u8((uint8x16_t)a, (uint8x16_t)a, 8))) |
| 223 |
#define vpshufb128(m, a, o) (o = (__m128i)vqtbl1q_u8((uint8x16_t)a, (uint8x16_t)m)) |
| 224 |
|
| 225 |
#define vpunpckhdq128(a, b, o) (o = (__m128i)vzip2q_u32((uint32x4_t)b, (uint32x4_t)a)) |
| 226 |
#define vpunpckldq128(a, b, o) (o = (__m128i)vzip1q_u32((uint32x4_t)b, (uint32x4_t)a)) |
| 227 |
#define vpunpckhqdq128(a, b, o) (o = (__m128i)vzip2q_u64(b, a)) |
| 228 |
#define vpunpcklqdq128(a, b, o) (o = (__m128i)vzip1q_u64(b, a)) |
| 229 |
|
| 230 |
/* CE AES encrypt last round => ShiftRows + SubBytes + XOR round key */ |
| 231 |
#define vaesenclast128(a, b, o) (o = (__m128i)vaeseq_u8((uint8x16_t)b, (uint8x16_t)a)) |
| 232 |
|
| 233 |
#define vmovdqa128(a, o) (o = a) |
| 234 |
#define vmovd128(a, o) ({ uint32x4_t __tmp = { a, 0, 0, 0 }; o = (__m128i)__tmp; }) |
| 235 |
#define vmovq128(a, o) ({ uint64x2_t __tmp = { a, 0 }; o = (__m128i)__tmp; }) |
| 236 |
|
| 237 |
#define vmovd128_amemld(z, a, o) ({ \ |
| 238 |
const uint32_t *__tmp_ptr = (const void *)(a); \ |
| 239 |
uint32x4_t __tmp = { __tmp_ptr[z], 0, 0, 0 }; \ |
| 240 |
o = (__m128i)(__tmp); }) |
| 241 |
#define vmovq128_amemld(a, o) ({ uint64x1_t __tmp = vld1_u64((const uint64_t *)(a)); \ |
| 242 |
o = (__m128i)vcombine_u64(__tmp, vcreate_u64(0)); }) |
| 243 |
|
| 244 |
#define vmovdqa128_memld(a, o) (o = (*(const __m128i *)(a))) |
| 245 |
#define vmovdqa128_memst(a, o) (*(__m128i *)(o) = (a)) |
| 246 |
#define vpshufb128_amemld(m, a, o) vpshufb128(*(const __m128i *)(m), a, o) |
| 247 |
|
| 248 |
/* Following operations may have unaligned memory input */ |
| 249 |
#define vmovdqu128_memld(a, o) (o = (__m128i)vld1q_u8((const uint8_t *)(a))) |
| 250 |
#define vpxor128_memld(a, b, o) vpxor128(b, (__m128i)vld1q_u8((const uint8_t *)(a)), o) |
| 251 |
#define vmovq128_memld(a, o) ({ uint8x8_t __tmp = vld1_u8((const uint8_t *)(a)); \ |
| 252 |
o = (__m128i)vcombine_u8(__tmp, vcreate_u8(0)); }) |
| 253 |
|
| 254 |
/* Following operations may have unaligned memory output */ |
| 255 |
#define vmovdqu128_memst(a, o) vst1q_u8((uint8_t *)(o), (uint8x16_t)a) |
| 256 |
#define vmovq128_memst(a, o) (((uint64_unaligned_t *)(o))[0] = (a)[0]) |
| 257 |
|
| 258 |
/* Macros for exposing SubBytes from Crypto-Extension instruction set. */ |
| 259 |
#define aes_subbytes_and_shuf_and_xor(zero, a, o) \ |
| 260 |
vaesenclast128(zero, a, o) |
| 261 |
#define aes_load_inv_shufmask(shufmask_reg) \ |
| 262 |
load_frequent_const(inv_shift_row, shufmask_reg) |
| 263 |
#define aes_inv_shuf(shufmask_reg, a, o) \ |
| 264 |
vpshufb128(shufmask_reg, a, o) |
| 265 |
#define if_aes_subbytes(...) /*_*/ |
| 266 |
#define if_not_aes_subbytes(...) __VA_ARGS__ |
| 267 |
|
| 268 |
#define memory_barrier_with_vec(a) __asm__("" : "+w"(a) :: "memory") |
| 269 |
|
| 270 |
#endif /* __ARM_NEON */ |
| 271 |
|
| 272 |
#if defined(__x86_64__) || defined(__i386__) |
| 273 |
|
| 274 |
/********************************************************************** |
| 275 |
AT&T x86 asm to intrinsics conversion macros |
| 276 |
**********************************************************************/ |
| 277 |
#include <x86intrin.h> |
| 278 |
|
| 279 |
#define vpand128(a, b, o) (o = _mm_and_si128(b, a)) |
| 280 |
#define vpandn128(a, b, o) (o = _mm_andnot_si128(b, a)) |
| 281 |
#define vpxor128(a, b, o) (o = _mm_xor_si128(b, a)) |
| 282 |
#define vpor128(a, b, o) (o = _mm_or_si128(b, a)) |
| 283 |
|
| 284 |
#define vpsrlw128(s, a, o) (o = _mm_srli_epi16(a, s)) |
| 285 |
#define vpsllw128(s, a, o) (o = _mm_slli_epi16(a, s)) |
| 286 |
#define vpsrld128(s, a, o) (o = _mm_srli_epi32(a, s)) |
| 287 |
#define vpslld128(s, a, o) (o = _mm_slli_epi32(a, s)) |
| 288 |
#define vpsrlq128(s, a, o) (o = _mm_srli_epi64(a, s)) |
| 289 |
#define vpsllq128(s, a, o) (o = _mm_slli_epi64(a, s)) |
| 290 |
#define vpsrldq128(s, a, o) (o = _mm_srli_si128(a, s)) |
| 291 |
#define vpslldq128(s, a, o) (o = _mm_slli_si128(a, s)) |
| 292 |
|
| 293 |
#define if_vpsrlb128(...) /*_*/ |
| 294 |
#define if_not_vpsrlb128(...) __VA_ARGS__ |
| 295 |
#define vpsrl_byte_128(s, a, o) vpsrld128(s, a, o) |
| 296 |
#define vpsll_byte_128(s, a, o) vpslld128(s, a, o) |
| 297 |
|
| 298 |
#define if_vprolb128(...) /*_*/ |
| 299 |
#define if_not_vprolb128(...) __VA_ARGS__ |
| 300 |
|
| 301 |
#define vpaddb128(a, b, o) (o = _mm_add_epi8(b, a)) |
| 302 |
|
| 303 |
#define vpcmpgtb128(a, b, o) (o = _mm_cmpgt_epi8(b, a)) |
| 304 |
#define vpabsb128(a, o) (o = _mm_abs_epi8(a)) |
| 305 |
|
| 306 |
#define vpshufd128_0x1b(a, o) (o = _mm_shuffle_epi32(a, 0x1b)) |
| 307 |
#define vpshufd128_0x4e(a, o) (o = _mm_shuffle_epi32(a, 0x4e)) |
| 308 |
#define vpshufb128(m, a, o) (o = _mm_shuffle_epi8(a, m)) |
| 309 |
|
| 310 |
#define vpunpckhdq128(a, b, o) (o = _mm_unpackhi_epi32(b, a)) |
| 311 |
#define vpunpckldq128(a, b, o) (o = _mm_unpacklo_epi32(b, a)) |
| 312 |
#define vpunpckhqdq128(a, b, o) (o = _mm_unpackhi_epi64(b, a)) |
| 313 |
#define vpunpcklqdq128(a, b, o) (o = _mm_unpacklo_epi64(b, a)) |
| 314 |
|
| 315 |
/* AES-NI encrypt last round => ShiftRows + SubBytes + XOR round key */ |
| 316 |
#define vaesenclast128(a, b, o) (o = _mm_aesenclast_si128(b, a)) |
| 317 |
|
| 318 |
#define vmovdqa128(a, o) (o = a) |
| 319 |
#define vmovd128(a, o) (o = _mm_set_epi32(0, 0, 0, a)) |
| 320 |
#define vmovq128(a, o) (o = _mm_set_epi64x(0, a)) |
| 321 |
|
| 322 |
#define vmovd128_amemld(z, a, o) ({ \ |
| 323 |
const uint32_t *__tmp_ptr = (const void *)(a); \ |
| 324 |
o = (__m128i)_mm_loadu_si32(__tmp_ptr + (z)); }) |
| 325 |
#define vmovq128_amemld(a, o) (o = (__m128i)_mm_loadu_si64(a)) |
| 326 |
|
| 327 |
#define vmovdqa128_memld(a, o) (o = (*(const __m128i *)(a))) |
| 328 |
#define vmovdqa128_memst(a, o) (*(__m128i *)(o) = (a)) |
| 329 |
#define vpshufb128_amemld(m, a, o) vpshufb128(*(const __m128i *)(m), a, o) |
| 330 |
|
| 331 |
/* Following operations may have unaligned memory input */ |
| 332 |
#define vmovdqu128_memld(a, o) (o = _mm_loadu_si128((const __m128i *)(a))) |
| 333 |
#define vpxor128_memld(a, b, o) \ |
| 334 |
vpxor128(b, _mm_loadu_si128((const __m128i *)(a)), o) |
| 335 |
#define vmovq128_memld(a, o) vmovq128_amemld(a, o) |
| 336 |
|
| 337 |
/* Following operations may have unaligned memory output */ |
| 338 |
#define vmovdqu128_memst(a, o) _mm_storeu_si128((__m128i *)(o), a) |
| 339 |
#define vmovq128_memst(a, o) _mm_storel_epi64((__m128i *)(o), a) |
| 340 |
|
| 341 |
/* Macros for exposing SubBytes from AES-NI instruction set. */ |
| 342 |
#define aes_subbytes_and_shuf_and_xor(zero, a, o) \ |
| 343 |
vaesenclast128(zero, a, o) |
| 344 |
#define aes_load_inv_shufmask(shufmask_reg) \ |
| 345 |
load_frequent_const(inv_shift_row, shufmask_reg) |
| 346 |
#define aes_inv_shuf(shufmask_reg, a, o) \ |
| 347 |
vpshufb128(shufmask_reg, a, o) |
| 348 |
#define if_aes_subbytes(...) /*_*/ |
| 349 |
#define if_not_aes_subbytes(...) __VA_ARGS__ |
| 350 |
|
| 351 |
#define memory_barrier_with_vec(a) __asm__("" : "+x"(a) :: "memory") |
| 352 |
|
| 353 |
#endif /* defined(__x86_64__) || defined(__i386__) */ |
| 354 |
|
| 355 |
/********************************************************************** |
| 356 |
helper macros |
| 357 |
**********************************************************************/ |
| 358 |
#define filter_8bit(x, lo_t, hi_t, mask4bit, tmp0) \ |
| 359 |
vpand128(x, mask4bit, tmp0); \ |
| 360 |
if_vpsrlb128(vpsrlb128(4, x, x)); \ |
| 361 |
if_not_vpsrlb128(vpandn128(x, mask4bit, x)); \ |
| 362 |
if_not_vpsrlb128(vpsrld128(4, x, x)); \ |
| 363 |
\ |
| 364 |
vpshufb128(tmp0, lo_t, tmp0); \ |
| 365 |
vpshufb128(x, hi_t, x); \ |
| 366 |
vpxor128(tmp0, x, x); |
| 367 |
|
| 368 |
#define filter_8bit_3op(out, in, lo_t, hi_t, mask4bit, tmp0) \ |
| 369 |
vmovdqa128(in, out); \ |
| 370 |
filter_8bit(out, lo_t, hi_t, mask4bit, tmp0); |
| 371 |
|
| 372 |
#define transpose_4x4(x0, x1, x2, x3, t1, t2) \ |
| 373 |
vpunpckhdq128(x1, x0, t2); \ |
| 374 |
vpunpckldq128(x1, x0, x0); \ |
| 375 |
\ |
| 376 |
vpunpckldq128(x3, x2, t1); \ |
| 377 |
vpunpckhdq128(x3, x2, x2); \ |
| 378 |
\ |
| 379 |
vpunpckhqdq128(t1, x0, x1); \ |
| 380 |
vpunpcklqdq128(t1, x0, x0); \ |
| 381 |
\ |
| 382 |
vpunpckhqdq128(x2, t2, x3); \ |
| 383 |
vpunpcklqdq128(x2, t2, x2); |
| 384 |
|
| 385 |
#define load_zero(o) vmovq128(0, o) |
| 386 |
|
| 387 |
#define load_frequent_const(constant, o) vmovdqa128(constant ## _stack, o) |
| 388 |
|
| 389 |
#define prepare_frequent_const(constant) \ |
| 390 |
vmovdqa128_memld(&(constant), constant ## _stack); \ |
| 391 |
memory_barrier_with_vec(constant ## _stack) |
| 392 |
|
| 393 |
#define prepare_frequent_constants() \ |
| 394 |
prepare_frequent_const(inv_shift_row); \ |
| 395 |
prepare_frequent_const(pack_bswap); \ |
| 396 |
prepare_frequent_const(shufb_16x16b); \ |
| 397 |
prepare_frequent_const(mask_0f); \ |
| 398 |
prepare_frequent_const(pre_tf_lo_s1); \ |
| 399 |
prepare_frequent_const(pre_tf_hi_s1); \ |
| 400 |
prepare_frequent_const(pre_tf_lo_s4); \ |
| 401 |
prepare_frequent_const(pre_tf_hi_s4); \ |
| 402 |
prepare_frequent_const(post_tf_lo_s1); \ |
| 403 |
prepare_frequent_const(post_tf_hi_s1); \ |
| 404 |
prepare_frequent_const(post_tf_lo_s3); \ |
| 405 |
prepare_frequent_const(post_tf_hi_s3); \ |
| 406 |
prepare_frequent_const(post_tf_lo_s2); \ |
| 407 |
prepare_frequent_const(post_tf_hi_s2) |
| 408 |
|
| 409 |
#define frequent_constants_declare \ |
| 410 |
__m128i inv_shift_row_stack; \ |
| 411 |
__m128i pack_bswap_stack; \ |
| 412 |
__m128i shufb_16x16b_stack; \ |
| 413 |
__m128i mask_0f_stack; \ |
| 414 |
__m128i pre_tf_lo_s1_stack; \ |
| 415 |
__m128i pre_tf_hi_s1_stack; \ |
| 416 |
__m128i pre_tf_lo_s4_stack; \ |
| 417 |
__m128i pre_tf_hi_s4_stack; \ |
| 418 |
__m128i post_tf_lo_s1_stack; \ |
| 419 |
__m128i post_tf_hi_s1_stack; \ |
| 420 |
__m128i post_tf_lo_s3_stack; \ |
| 421 |
__m128i post_tf_hi_s3_stack; \ |
| 422 |
__m128i post_tf_lo_s2_stack; \ |
| 423 |
__m128i post_tf_hi_s2_stack |
| 424 |
|
| 425 |
/********************************************************************** |
| 426 |
16-way camellia macros |
| 427 |
**********************************************************************/ |
| 428 |
|
| 429 |
/* |
| 430 |
* IN: |
| 431 |
* x0..x7: byte-sliced AB state |
| 432 |
* mem_cd: register pointer storing CD state |
| 433 |
* key: index for key material |
| 434 |
* OUT: |
| 435 |
* x0..x7: new byte-sliced CD state |
| 436 |
*/ |
| 437 |
#define roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, t0, t1, t2, t3, t4, t5, t6, \ |
| 438 |
t7, mem_cd, key) \ |
| 439 |
/* \ |
| 440 |
* S-function with AES subbytes \ |
| 441 |
*/ \ |
| 442 |
if_not_aes_subbytes(aes_load_inv_shufmask(t4);) \ |
| 443 |
load_frequent_const(mask_0f, t7); \ |
| 444 |
load_frequent_const(pre_tf_lo_s1, t0); \ |
| 445 |
load_frequent_const(pre_tf_hi_s1, t1); \ |
| 446 |
\ |
| 447 |
/* AES inverse shift rows */ \ |
| 448 |
if_not_aes_subbytes( \ |
| 449 |
aes_inv_shuf(t4, x0, x0); \ |
| 450 |
aes_inv_shuf(t4, x7, x7); \ |
| 451 |
aes_inv_shuf(t4, x1, x1); \ |
| 452 |
aes_inv_shuf(t4, x4, x4); \ |
| 453 |
aes_inv_shuf(t4, x2, x2); \ |
| 454 |
aes_inv_shuf(t4, x5, x5); \ |
| 455 |
aes_inv_shuf(t4, x3, x3); \ |
| 456 |
aes_inv_shuf(t4, x6, x6); \ |
| 457 |
) \ |
| 458 |
\ |
| 459 |
/* prefilter sboxes 1, 2 and 3 */ \ |
| 460 |
load_frequent_const(pre_tf_lo_s4, t2); \ |
| 461 |
load_frequent_const(pre_tf_hi_s4, t3); \ |
| 462 |
filter_8bit(x0, t0, t1, t7, t6); \ |
| 463 |
filter_8bit(x7, t0, t1, t7, t6); \ |
| 464 |
filter_8bit(x1, t0, t1, t7, t6); \ |
| 465 |
filter_8bit(x4, t0, t1, t7, t6); \ |
| 466 |
filter_8bit(x2, t0, t1, t7, t6); \ |
| 467 |
filter_8bit(x5, t0, t1, t7, t6); \ |
| 468 |
\ |
| 469 |
/* prefilter sbox 4 */ \ |
| 470 |
if_not_aes_subbytes(load_zero(t4);) \ |
| 471 |
filter_8bit(x3, t2, t3, t7, t6); \ |
| 472 |
filter_8bit(x6, t2, t3, t7, t6); \ |
| 473 |
\ |
| 474 |
/* AES subbytes + AES shift rows */ \ |
| 475 |
load_frequent_const(post_tf_lo_s1, t0); \ |
| 476 |
load_frequent_const(post_tf_hi_s1, t1); \ |
| 477 |
if_not_aes_subbytes( \ |
| 478 |
aes_subbytes_and_shuf_and_xor(t4, x0, x0); \ |
| 479 |
aes_subbytes_and_shuf_and_xor(t4, x7, x7); \ |
| 480 |
aes_subbytes_and_shuf_and_xor(t4, x1, x1); \ |
| 481 |
aes_subbytes_and_shuf_and_xor(t4, x4, x4); \ |
| 482 |
aes_subbytes_and_shuf_and_xor(t4, x2, x2); \ |
| 483 |
aes_subbytes_and_shuf_and_xor(t4, x5, x5); \ |
| 484 |
aes_subbytes_and_shuf_and_xor(t4, x3, x3); \ |
| 485 |
aes_subbytes_and_shuf_and_xor(t4, x6, x6); \ |
| 486 |
) \ |
| 487 |
if_aes_subbytes( \ |
| 488 |
aes_subbytes(x0, x0); \ |
| 489 |
aes_subbytes(x7, x7); \ |
| 490 |
aes_subbytes(x1, x1); \ |
| 491 |
aes_subbytes(x4, x4); \ |
| 492 |
aes_subbytes(x2, x2); \ |
| 493 |
aes_subbytes(x5, x5); \ |
| 494 |
aes_subbytes(x3, x3); \ |
| 495 |
aes_subbytes(x6, x6); \ |
| 496 |
) \ |
| 497 |
\ |
| 498 |
/* postfilter sboxes 1 and 4 */ \ |
| 499 |
load_frequent_const(post_tf_lo_s3, t2); \ |
| 500 |
load_frequent_const(post_tf_hi_s3, t3); \ |
| 501 |
filter_8bit(x0, t0, t1, t7, t6); \ |
| 502 |
filter_8bit(x7, t0, t1, t7, t6); \ |
| 503 |
filter_8bit(x3, t0, t1, t7, t6); \ |
| 504 |
filter_8bit(x6, t0, t1, t7, t6); \ |
| 505 |
\ |
| 506 |
/* postfilter sbox 3 */ \ |
| 507 |
load_frequent_const(post_tf_lo_s2, t4); \ |
| 508 |
load_frequent_const(post_tf_hi_s2, t5); \ |
| 509 |
filter_8bit(x2, t2, t3, t7, t6); \ |
| 510 |
filter_8bit(x5, t2, t3, t7, t6); \ |
| 511 |
\ |
| 512 |
vmovq128_amemld(&(key), t0); \ |
| 513 |
\ |
| 514 |
/* postfilter sbox 2 */ \ |
| 515 |
filter_8bit(x1, t4, t5, t7, t2); \ |
| 516 |
filter_8bit(x4, t4, t5, t7, t2); \ |
| 517 |
\ |
| 518 |
/* P-function */ \ |
| 519 |
vpxor128(x5, x0, x0); \ |
| 520 |
vpxor128(x6, x1, x1); \ |
| 521 |
vpxor128(x7, x2, x2); \ |
| 522 |
vpxor128(x4, x3, x3); \ |
| 523 |
\ |
| 524 |
vpxor128(x2, x4, x4); \ |
| 525 |
vpxor128(x3, x5, x5); \ |
| 526 |
vpxor128(x0, x6, x6); \ |
| 527 |
vpxor128(x1, x7, x7); \ |
| 528 |
\ |
| 529 |
vpxor128(x7, x0, x0); \ |
| 530 |
vpxor128(x4, x1, x1); \ |
| 531 |
vpxor128(x5, x2, x2); \ |
| 532 |
vpxor128(x6, x3, x3); \ |
| 533 |
\ |
| 534 |
vpxor128(x3, x4, x4); \ |
| 535 |
vpxor128(x0, x5, x5); \ |
| 536 |
vpxor128(x1, x6, x6); \ |
| 537 |
vpxor128(x2, x7, x7); /* note: high and low parts swapped */ \ |
| 538 |
\ |
| 539 |
/* Add key material and result to CD (x becomes new CD) */ \ |
| 540 |
\ |
| 541 |
vpshufb128(bcast[7], t0, t7); \ |
| 542 |
vpshufb128(bcast[6], t0, t6); \ |
| 543 |
vpshufb128(bcast[5], t0, t5); \ |
| 544 |
vpshufb128(bcast[4], t0, t4); \ |
| 545 |
vpshufb128(bcast[3], t0, t3); \ |
| 546 |
vpshufb128(bcast[2], t0, t2); \ |
| 547 |
vpshufb128(bcast[1], t0, t1); \ |
| 548 |
\ |
| 549 |
vpxor128(t3, x4, x4); \ |
| 550 |
vpxor128(mem_cd[0], x4, x4); \ |
| 551 |
\ |
| 552 |
load_zero(t3); \ |
| 553 |
vpshufb128(t3, t0, t0); \ |
| 554 |
\ |
| 555 |
vpxor128(t2, x5, x5); \ |
| 556 |
vpxor128(mem_cd[1], x5, x5); \ |
| 557 |
\ |
| 558 |
vpxor128(t1, x6, x6); \ |
| 559 |
vpxor128(mem_cd[2], x6, x6); \ |
| 560 |
\ |
| 561 |
vpxor128(t0, x7, x7); \ |
| 562 |
vpxor128(mem_cd[3], x7, x7); \ |
| 563 |
\ |
| 564 |
vpxor128(t7, x0, x0); \ |
| 565 |
vpxor128(mem_cd[4], x0, x0); \ |
| 566 |
\ |
| 567 |
vpxor128(t6, x1, x1); \ |
| 568 |
vpxor128(mem_cd[5], x1, x1); \ |
| 569 |
\ |
| 570 |
vpxor128(t5, x2, x2); \ |
| 571 |
vpxor128(mem_cd[6], x2, x2); \ |
| 572 |
\ |
| 573 |
vpxor128(t4, x3, x3); \ |
| 574 |
vpxor128(mem_cd[7], x3, x3); |
| 575 |
|
| 576 |
/* |
| 577 |
* IN/OUT: |
| 578 |
* x0..x7: byte-sliced AB state preloaded |
| 579 |
* mem_ab: byte-sliced AB state in memory |
| 580 |
* mem_cb: byte-sliced CD state in memory |
| 581 |
*/ |
| 582 |
#define two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 583 |
y6, y7, mem_ab, mem_cd, i, dir, store_ab) \ |
| 584 |
roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 585 |
y6, y7, mem_cd, ctx->key_table[(i)]); \ |
| 586 |
\ |
| 587 |
vmovdqa128(x4, mem_cd[0]); \ |
| 588 |
vmovdqa128(x5, mem_cd[1]); \ |
| 589 |
vmovdqa128(x6, mem_cd[2]); \ |
| 590 |
vmovdqa128(x7, mem_cd[3]); \ |
| 591 |
vmovdqa128(x0, mem_cd[4]); \ |
| 592 |
vmovdqa128(x1, mem_cd[5]); \ |
| 593 |
vmovdqa128(x2, mem_cd[6]); \ |
| 594 |
vmovdqa128(x3, mem_cd[7]); \ |
| 595 |
\ |
| 596 |
roundsm16(x4, x5, x6, x7, x0, x1, x2, x3, y0, y1, y2, y3, y4, y5, \ |
| 597 |
y6, y7, mem_ab, ctx->key_table[(i) + (dir)]); \ |
| 598 |
\ |
| 599 |
store_ab(x0, x1, x2, x3, x4, x5, x6, x7, mem_ab); |
| 600 |
|
| 601 |
#define dummy_store(x0, x1, x2, x3, x4, x5, x6, x7, mem_ab) /* do nothing */ |
| 602 |
|
| 603 |
#define store_ab_state(x0, x1, x2, x3, x4, x5, x6, x7, mem_ab) \ |
| 604 |
/* Store new AB state */ \ |
| 605 |
vmovdqa128(x0, mem_ab[0]); \ |
| 606 |
vmovdqa128(x1, mem_ab[1]); \ |
| 607 |
vmovdqa128(x2, mem_ab[2]); \ |
| 608 |
vmovdqa128(x3, mem_ab[3]); \ |
| 609 |
vmovdqa128(x4, mem_ab[4]); \ |
| 610 |
vmovdqa128(x5, mem_ab[5]); \ |
| 611 |
vmovdqa128(x6, mem_ab[6]); \ |
| 612 |
vmovdqa128(x7, mem_ab[7]); |
| 613 |
|
| 614 |
#define enc_rounds16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 615 |
y6, y7, mem_ab, mem_cd, i) \ |
| 616 |
two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 617 |
y6, y7, mem_ab, mem_cd, (i) + 2, 1, store_ab_state); \ |
| 618 |
two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 619 |
y6, y7, mem_ab, mem_cd, (i) + 4, 1, store_ab_state); \ |
| 620 |
two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 621 |
y6, y7, mem_ab, mem_cd, (i) + 6, 1, dummy_store); |
| 622 |
|
| 623 |
#define dec_rounds16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 624 |
y6, y7, mem_ab, mem_cd, i) \ |
| 625 |
two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 626 |
y6, y7, mem_ab, mem_cd, (i) + 7, -1, store_ab_state); \ |
| 627 |
two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 628 |
y6, y7, mem_ab, mem_cd, (i) + 5, -1, store_ab_state); \ |
| 629 |
two_roundsm16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 630 |
y6, y7, mem_ab, mem_cd, (i) + 3, -1, dummy_store); |
| 631 |
|
| 632 |
/* |
| 633 |
* IN: |
| 634 |
* v0..3: byte-sliced 32-bit integers |
| 635 |
* OUT: |
| 636 |
* v0..3: (IN <<< 1) |
| 637 |
*/ |
| 638 |
#define rol32_1_16(v0, v1, v2, v3, t0, t1, t2, zero) \ |
| 639 |
if_vpsrlb128(vpsrlb128(7, v0, t0)); \ |
| 640 |
if_not_vpsrlb128(vpcmpgtb128(v0, zero, t0)); \ |
| 641 |
vpaddb128(v0, v0, v0); \ |
| 642 |
if_not_vpsrlb128(vpabsb128(t0, t0)); \ |
| 643 |
\ |
| 644 |
if_vpsrlb128(vpsrlb128(7, v1, t1)); \ |
| 645 |
if_not_vpsrlb128(vpcmpgtb128(v1, zero, t1)); \ |
| 646 |
vpaddb128(v1, v1, v1); \ |
| 647 |
if_not_vpsrlb128(vpabsb128(t1, t1)); \ |
| 648 |
\ |
| 649 |
if_vpsrlb128(vpsrlb128(7, v2, t2)); \ |
| 650 |
if_not_vpsrlb128(vpcmpgtb128(v2, zero, t2)); \ |
| 651 |
vpaddb128(v2, v2, v2); \ |
| 652 |
if_not_vpsrlb128(vpabsb128(t2, t2)); \ |
| 653 |
\ |
| 654 |
vpor128(t0, v1, v1); \ |
| 655 |
\ |
| 656 |
if_vpsrlb128(vpsrlb128(7, v3, t0)); \ |
| 657 |
if_not_vpsrlb128(vpcmpgtb128(v3, zero, t0)); \ |
| 658 |
vpaddb128(v3, v3, v3); \ |
| 659 |
if_not_vpsrlb128(vpabsb128(t0, t0)); \ |
| 660 |
\ |
| 661 |
vpor128(t1, v2, v2); \ |
| 662 |
vpor128(t2, v3, v3); \ |
| 663 |
vpor128(t0, v0, v0); |
| 664 |
|
| 665 |
/* |
| 666 |
* IN: |
| 667 |
* r: byte-sliced AB state in memory |
| 668 |
* l: byte-sliced CD state in memory |
| 669 |
* OUT: |
| 670 |
* x0..x7: new byte-sliced CD state |
| 671 |
*/ |
| 672 |
#define fls16(l, l0, l1, l2, l3, l4, l5, l6, l7, r, t0, t1, t2, t3, tt0, \ |
| 673 |
tt1, tt2, tt3, kl, kr) \ |
| 674 |
/* \ |
| 675 |
* t0 = kll; \ |
| 676 |
* t0 &= ll; \ |
| 677 |
* lr ^= rol32(t0, 1); \ |
| 678 |
*/ \ |
| 679 |
load_zero(tt0); \ |
| 680 |
vmovd128_amemld(0, kl, t0); \ |
| 681 |
vpshufb128(tt0, t0, t3); \ |
| 682 |
vpshufb128(bcast[1], t0, t2); \ |
| 683 |
vpshufb128(bcast[2], t0, t1); \ |
| 684 |
vpshufb128(bcast[3], t0, t0); \ |
| 685 |
\ |
| 686 |
vpand128(l0, t0, t0); \ |
| 687 |
vpand128(l1, t1, t1); \ |
| 688 |
vpand128(l2, t2, t2); \ |
| 689 |
vpand128(l3, t3, t3); \ |
| 690 |
\ |
| 691 |
rol32_1_16(t3, t2, t1, t0, tt1, tt2, tt3, tt0); \ |
| 692 |
\ |
| 693 |
vpxor128(l4, t0, l4); \ |
| 694 |
vmovdqa128(l4, l[4]); \ |
| 695 |
vpxor128(l5, t1, l5); \ |
| 696 |
vmovdqa128(l5, l[5]); \ |
| 697 |
vpxor128(l6, t2, l6); \ |
| 698 |
vmovdqa128(l6, l[6]); \ |
| 699 |
vpxor128(l7, t3, l7); \ |
| 700 |
vmovdqa128(l7, l[7]); \ |
| 701 |
\ |
| 702 |
/* \ |
| 703 |
* t2 = krr; \ |
| 704 |
* t2 |= rr; \ |
| 705 |
* rl ^= t2; \ |
| 706 |
*/ \ |
| 707 |
\ |
| 708 |
vmovd128_amemld(1, kr, t0); \ |
| 709 |
vpshufb128(tt0, t0, t3); \ |
| 710 |
vpshufb128(bcast[1], t0, t2); \ |
| 711 |
vpshufb128(bcast[2], t0, t1); \ |
| 712 |
vpshufb128(bcast[3], t0, t0); \ |
| 713 |
\ |
| 714 |
vpor128(r[4], t0, t0); \ |
| 715 |
vpor128(r[5], t1, t1); \ |
| 716 |
vpor128(r[6], t2, t2); \ |
| 717 |
vpor128(r[7], t3, t3); \ |
| 718 |
\ |
| 719 |
vpxor128(r[0], t0, t0); \ |
| 720 |
vpxor128(r[1], t1, t1); \ |
| 721 |
vpxor128(r[2], t2, t2); \ |
| 722 |
vpxor128(r[3], t3, t3); \ |
| 723 |
vmovdqa128(t0, r[0]); \ |
| 724 |
vmovdqa128(t1, r[1]); \ |
| 725 |
vmovdqa128(t2, r[2]); \ |
| 726 |
vmovdqa128(t3, r[3]); \ |
| 727 |
\ |
| 728 |
/* \ |
| 729 |
* t2 = krl; \ |
| 730 |
* t2 &= rl; \ |
| 731 |
* rr ^= rol32(t2, 1); \ |
| 732 |
*/ \ |
| 733 |
vmovd128_amemld(0, kr, t0); \ |
| 734 |
vpshufb128(tt0, t0, t3); \ |
| 735 |
vpshufb128(bcast[1], t0, t2); \ |
| 736 |
vpshufb128(bcast[2], t0, t1); \ |
| 737 |
vpshufb128(bcast[3], t0, t0); \ |
| 738 |
\ |
| 739 |
vpand128(r[0], t0, t0); \ |
| 740 |
vpand128(r[1], t1, t1); \ |
| 741 |
vpand128(r[2], t2, t2); \ |
| 742 |
vpand128(r[3], t3, t3); \ |
| 743 |
\ |
| 744 |
rol32_1_16(t3, t2, t1, t0, tt1, tt2, tt3, tt0); \ |
| 745 |
\ |
| 746 |
vpxor128(r[4], t0, t0); \ |
| 747 |
vpxor128(r[5], t1, t1); \ |
| 748 |
vpxor128(r[6], t2, t2); \ |
| 749 |
vpxor128(r[7], t3, t3); \ |
| 750 |
vmovdqa128(t0, r[4]); \ |
| 751 |
vmovdqa128(t1, r[5]); \ |
| 752 |
vmovdqa128(t2, r[6]); \ |
| 753 |
vmovdqa128(t3, r[7]); \ |
| 754 |
\ |
| 755 |
/* \ |
| 756 |
* t0 = klr; \ |
| 757 |
* t0 |= lr; \ |
| 758 |
* ll ^= t0; \ |
| 759 |
*/ \ |
| 760 |
\ |
| 761 |
vmovd128_amemld(1, kl, t0); \ |
| 762 |
vpshufb128(tt0, t0, t3); \ |
| 763 |
vpshufb128(bcast[1], t0, t2); \ |
| 764 |
vpshufb128(bcast[2], t0, t1); \ |
| 765 |
vpshufb128(bcast[3], t0, t0); \ |
| 766 |
\ |
| 767 |
vpor128(l4, t0, t0); \ |
| 768 |
vpor128(l5, t1, t1); \ |
| 769 |
vpor128(l6, t2, t2); \ |
| 770 |
vpor128(l7, t3, t3); \ |
| 771 |
\ |
| 772 |
vpxor128(l0, t0, l0); \ |
| 773 |
vmovdqa128(l0, l[0]); \ |
| 774 |
vpxor128(l1, t1, l1); \ |
| 775 |
vmovdqa128(l1, l[1]); \ |
| 776 |
vpxor128(l2, t2, l2); \ |
| 777 |
vmovdqa128(l2, l[2]); \ |
| 778 |
vpxor128(l3, t3, l3); \ |
| 779 |
vmovdqa128(l3, l[3]); |
| 780 |
|
| 781 |
#define byteslice_16x16b_fast(a0, b0, c0, d0, a1, b1, c1, d1, a2, b2, c2, d2, \ |
| 782 |
a3, b3, c3, d3, st0, st1) \ |
| 783 |
vmovdqa128(d2, st0); \ |
| 784 |
vmovdqa128(d3, st1); \ |
| 785 |
transpose_4x4(a0, a1, a2, a3, d2, d3); \ |
| 786 |
transpose_4x4(b0, b1, b2, b3, d2, d3); \ |
| 787 |
vmovdqa128(st0, d2); \ |
| 788 |
vmovdqa128(st1, d3); \ |
| 789 |
\ |
| 790 |
vmovdqa128(a0, st0); \ |
| 791 |
vmovdqa128(a1, st1); \ |
| 792 |
transpose_4x4(c0, c1, c2, c3, a0, a1); \ |
| 793 |
transpose_4x4(d0, d1, d2, d3, a0, a1); \ |
| 794 |
\ |
| 795 |
vmovdqa128(shufb_16x16b_stack, a0); \ |
| 796 |
vmovdqa128(st1, a1); \ |
| 797 |
vpshufb128(a0, a2, a2); \ |
| 798 |
vpshufb128(a0, a3, a3); \ |
| 799 |
vpshufb128(a0, b0, b0); \ |
| 800 |
vpshufb128(a0, b1, b1); \ |
| 801 |
vpshufb128(a0, b2, b2); \ |
| 802 |
vpshufb128(a0, b3, b3); \ |
| 803 |
vpshufb128(a0, a1, a1); \ |
| 804 |
vpshufb128(a0, c0, c0); \ |
| 805 |
vpshufb128(a0, c1, c1); \ |
| 806 |
vpshufb128(a0, c2, c2); \ |
| 807 |
vpshufb128(a0, c3, c3); \ |
| 808 |
vpshufb128(a0, d0, d0); \ |
| 809 |
vpshufb128(a0, d1, d1); \ |
| 810 |
vpshufb128(a0, d2, d2); \ |
| 811 |
vpshufb128(a0, d3, d3); \ |
| 812 |
vmovdqa128(d3, st1); \ |
| 813 |
vmovdqa128(st0, d3); \ |
| 814 |
vpshufb128(a0, d3, a0); \ |
| 815 |
vmovdqa128(d2, st0); \ |
| 816 |
\ |
| 817 |
transpose_4x4(a0, b0, c0, d0, d2, d3); \ |
| 818 |
transpose_4x4(a1, b1, c1, d1, d2, d3); \ |
| 819 |
vmovdqa128(st0, d2); \ |
| 820 |
vmovdqa128(st1, d3); \ |
| 821 |
\ |
| 822 |
vmovdqa128(b0, st0); \ |
| 823 |
vmovdqa128(b1, st1); \ |
| 824 |
transpose_4x4(a2, b2, c2, d2, b0, b1); \ |
| 825 |
transpose_4x4(a3, b3, c3, d3, b0, b1); \ |
| 826 |
vmovdqa128(st0, b0); \ |
| 827 |
vmovdqa128(st1, b1); \ |
| 828 |
/* does not adjust output bytes inside vectors */ |
| 829 |
|
| 830 |
/* load blocks to registers and apply pre-whitening */ |
| 831 |
#define inpack16_pre(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 832 |
y6, y7, rio, key) \ |
| 833 |
vmovq128_amemld(&(key), x0); \ |
| 834 |
vpshufb128(pack_bswap_stack, x0, x0); \ |
| 835 |
\ |
| 836 |
vpxor128_memld((rio) + 0 * 16, x0, y7); \ |
| 837 |
vpxor128_memld((rio) + 1 * 16, x0, y6); \ |
| 838 |
vpxor128_memld((rio) + 2 * 16, x0, y5); \ |
| 839 |
vpxor128_memld((rio) + 3 * 16, x0, y4); \ |
| 840 |
vpxor128_memld((rio) + 4 * 16, x0, y3); \ |
| 841 |
vpxor128_memld((rio) + 5 * 16, x0, y2); \ |
| 842 |
vpxor128_memld((rio) + 6 * 16, x0, y1); \ |
| 843 |
vpxor128_memld((rio) + 7 * 16, x0, y0); \ |
| 844 |
vpxor128_memld((rio) + 8 * 16, x0, x7); \ |
| 845 |
vpxor128_memld((rio) + 9 * 16, x0, x6); \ |
| 846 |
vpxor128_memld((rio) + 10 * 16, x0, x5); \ |
| 847 |
vpxor128_memld((rio) + 11 * 16, x0, x4); \ |
| 848 |
vpxor128_memld((rio) + 12 * 16, x0, x3); \ |
| 849 |
vpxor128_memld((rio) + 13 * 16, x0, x2); \ |
| 850 |
vpxor128_memld((rio) + 14 * 16, x0, x1); \ |
| 851 |
vpxor128_memld((rio) + 15 * 16, x0, x0); |
| 852 |
|
| 853 |
/* byteslice pre-whitened blocks and store to temporary memory */ |
| 854 |
#define inpack16_post(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 855 |
y6, y7, mem_ab, mem_cd) \ |
| 856 |
byteslice_16x16b_fast(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, \ |
| 857 |
y4, y5, y6, y7, mem_ab[0], mem_cd[0]); \ |
| 858 |
\ |
| 859 |
vmovdqa128(x0, mem_ab[0]); \ |
| 860 |
vmovdqa128(x1, mem_ab[1]); \ |
| 861 |
vmovdqa128(x2, mem_ab[2]); \ |
| 862 |
vmovdqa128(x3, mem_ab[3]); \ |
| 863 |
vmovdqa128(x4, mem_ab[4]); \ |
| 864 |
vmovdqa128(x5, mem_ab[5]); \ |
| 865 |
vmovdqa128(x6, mem_ab[6]); \ |
| 866 |
vmovdqa128(x7, mem_ab[7]); \ |
| 867 |
vmovdqa128(y0, mem_cd[0]); \ |
| 868 |
vmovdqa128(y1, mem_cd[1]); \ |
| 869 |
vmovdqa128(y2, mem_cd[2]); \ |
| 870 |
vmovdqa128(y3, mem_cd[3]); \ |
| 871 |
vmovdqa128(y4, mem_cd[4]); \ |
| 872 |
vmovdqa128(y5, mem_cd[5]); \ |
| 873 |
vmovdqa128(y6, mem_cd[6]); \ |
| 874 |
vmovdqa128(y7, mem_cd[7]); |
| 875 |
|
| 876 |
/* de-byteslice, apply post-whitening and store blocks */ |
| 877 |
#define outunpack16(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, \ |
| 878 |
y5, y6, y7, key, stack_tmp0, stack_tmp1) \ |
| 879 |
byteslice_16x16b_fast(y0, y4, x0, x4, y1, y5, x1, x5, y2, y6, x2, x6, \ |
| 880 |
y3, y7, x3, x7, stack_tmp0, stack_tmp1); \ |
| 881 |
\ |
| 882 |
vmovdqa128(x0, stack_tmp0); \ |
| 883 |
\ |
| 884 |
vmovq128_amemld(&(key), x0); \ |
| 885 |
vpshufb128(pack_bswap_stack, x0, x0); \ |
| 886 |
\ |
| 887 |
vpxor128(x0, y7, y7); \ |
| 888 |
vpxor128(x0, y6, y6); \ |
| 889 |
vpxor128(x0, y5, y5); \ |
| 890 |
vpxor128(x0, y4, y4); \ |
| 891 |
vpxor128(x0, y3, y3); \ |
| 892 |
vpxor128(x0, y2, y2); \ |
| 893 |
vpxor128(x0, y1, y1); \ |
| 894 |
vpxor128(x0, y0, y0); \ |
| 895 |
vpxor128(x0, x7, x7); \ |
| 896 |
vpxor128(x0, x6, x6); \ |
| 897 |
vpxor128(x0, x5, x5); \ |
| 898 |
vpxor128(x0, x4, x4); \ |
| 899 |
vpxor128(x0, x3, x3); \ |
| 900 |
vpxor128(x0, x2, x2); \ |
| 901 |
vpxor128(x0, x1, x1); \ |
| 902 |
vpxor128(stack_tmp0, x0, x0); |
| 903 |
|
| 904 |
#define write_output(x0, x1, x2, x3, x4, x5, x6, x7, y0, y1, y2, y3, y4, y5, \ |
| 905 |
y6, y7, rio) \ |
| 906 |
vmovdqu128_memst(x0, (rio) + 0 * 16); \ |
| 907 |
vmovdqu128_memst(x1, (rio) + 1 * 16); \ |
| 908 |
vmovdqu128_memst(x2, (rio) + 2 * 16); \ |
| 909 |
vmovdqu128_memst(x3, (rio) + 3 * 16); \ |
| 910 |
vmovdqu128_memst(x4, (rio) + 4 * 16); \ |
| 911 |
vmovdqu128_memst(x5, (rio) + 5 * 16); \ |
| 912 |
vmovdqu128_memst(x6, (rio) + 6 * 16); \ |
| 913 |
vmovdqu128_memst(x7, (rio) + 7 * 16); \ |
| 914 |
vmovdqu128_memst(y0, (rio) + 8 * 16); \ |
| 915 |
vmovdqu128_memst(y1, (rio) + 9 * 16); \ |
| 916 |
vmovdqu128_memst(y2, (rio) + 10 * 16); \ |
| 917 |
vmovdqu128_memst(y3, (rio) + 11 * 16); \ |
| 918 |
vmovdqu128_memst(y4, (rio) + 12 * 16); \ |
| 919 |
vmovdqu128_memst(y5, (rio) + 13 * 16); \ |
| 920 |
vmovdqu128_memst(y6, (rio) + 14 * 16); \ |
| 921 |
vmovdqu128_memst(y7, (rio) + 15 * 16); |
| 922 |
|
| 923 |
/********************************************************************** |
| 924 |
macros for defining constant vectors |
| 925 |
**********************************************************************/ |
| 926 |
#define SWAP_LE64(x) (x) |
| 927 |
|
| 928 |
#define M128I_BYTE(a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3, b4, b5, b6, b7) \ |
| 929 |
{ \ |
| 930 |
SWAP_LE64((((a0) & 0xffULL) << 0) | \ |
| 931 |
(((a1) & 0xffULL) << 8) | \ |
| 932 |
(((a2) & 0xffULL) << 16) | \ |
| 933 |
(((a3) & 0xffULL) << 24) | \ |
| 934 |
(((a4) & 0xffULL) << 32) | \ |
| 935 |
(((a5) & 0xffULL) << 40) | \ |
| 936 |
(((a6) & 0xffULL) << 48) | \ |
| 937 |
(((a7) & 0xffULL) << 56)), \ |
| 938 |
SWAP_LE64((((b0) & 0xffULL) << 0) | \ |
| 939 |
(((b1) & 0xffULL) << 8) | \ |
| 940 |
(((b2) & 0xffULL) << 16) | \ |
| 941 |
(((b3) & 0xffULL) << 24) | \ |
| 942 |
(((b4) & 0xffULL) << 32) | \ |
| 943 |
(((b5) & 0xffULL) << 40) | \ |
| 944 |
(((b6) & 0xffULL) << 48) | \ |
| 945 |
(((b7) & 0xffULL) << 56)) \ |
| 946 |
} |
| 947 |
|
| 948 |
#define M128I_U32(a0, a1, b0, b1) \ |
| 949 |
{ \ |
| 950 |
SWAP_LE64((((a0) & 0xffffffffULL) << 0) | \ |
| 951 |
(((a1) & 0xffffffffULL) << 32)), \ |
| 952 |
SWAP_LE64((((b0) & 0xffffffffULL) << 0) | \ |
| 953 |
(((b1) & 0xffffffffULL) << 32)) \ |
| 954 |
} |
| 955 |
|
| 956 |
#define M128I_REP16(x) { (0x0101010101010101ULL * (x)), (0x0101010101010101ULL * (x)) } |
| 957 |
|
| 958 |
#define SHUFB_BYTES(idx) \ |
| 959 |
(((0 + (idx)) << 0) | ((4 + (idx)) << 8) | \ |
| 960 |
((8 + (idx)) << 16) | ((12 + (idx)) << 24)) |
| 961 |
|
| 962 |
typedef u64 uint64_unaligned_t __attribute__((aligned(1), may_alias)); |
| 963 |
|
| 964 |
static const __m128i shufb_16x16b = |
| 965 |
M128I_U32(SHUFB_BYTES(0), SHUFB_BYTES(1), SHUFB_BYTES(2), SHUFB_BYTES(3)); |
| 966 |
|
| 967 |
static const __m128i pack_bswap = |
| 968 |
M128I_U32(0x00010203, 0x04050607, 0x0f0f0f0f, 0x0f0f0f0f); |
| 969 |
|
| 970 |
static const __m128i bcast[8] = |
| 971 |
{ |
| 972 |
M128I_REP16(0), M128I_REP16(1), M128I_REP16(2), M128I_REP16(3), |
| 973 |
M128I_REP16(4), M128I_REP16(5), M128I_REP16(6), M128I_REP16(7) |
| 974 |
}; |
| 975 |
|
| 976 |
/* |
| 977 |
* pre-SubByte transform |
| 978 |
* |
| 979 |
* pre-lookup for sbox1, sbox2, sbox3: |
| 980 |
* swap_bitendianness( |
| 981 |
* isom_map_camellia_to_aes( |
| 982 |
* camellia_f( |
| 983 |
* swap_bitendianess(in) |
| 984 |
* ) |
| 985 |
* ) |
| 986 |
* ) |
| 987 |
* |
| 988 |
* (note: '⊕ 0xc5' inside camellia_f()) |
| 989 |
*/ |
| 990 |
static const __m128i pre_tf_lo_s1 = |
| 991 |
M128I_BYTE(0x45, 0xe8, 0x40, 0xed, 0x2e, 0x83, 0x2b, 0x86, |
| 992 |
0x4b, 0xe6, 0x4e, 0xe3, 0x20, 0x8d, 0x25, 0x88); |
| 993 |
|
| 994 |
static const __m128i pre_tf_hi_s1 = |
| 995 |
M128I_BYTE(0x00, 0x51, 0xf1, 0xa0, 0x8a, 0xdb, 0x7b, 0x2a, |
| 996 |
0x09, 0x58, 0xf8, 0xa9, 0x83, 0xd2, 0x72, 0x23); |
| 997 |
|
| 998 |
/* |
| 999 |
* pre-SubByte transform |
| 1000 |
* |
| 1001 |
* pre-lookup for sbox4: |
| 1002 |
* swap_bitendianness( |
| 1003 |
* isom_map_camellia_to_aes( |
| 1004 |
* camellia_f( |
| 1005 |
* swap_bitendianess(in <<< 1) |
| 1006 |
* ) |
| 1007 |
* ) |
| 1008 |
* ) |
| 1009 |
* |
| 1010 |
* (note: '⊕ 0xc5' inside camellia_f()) |
| 1011 |
*/ |
| 1012 |
static const __m128i pre_tf_lo_s4 = |
| 1013 |
M128I_BYTE(0x45, 0x40, 0x2e, 0x2b, 0x4b, 0x4e, 0x20, 0x25, |
| 1014 |
0x14, 0x11, 0x7f, 0x7a, 0x1a, 0x1f, 0x71, 0x74); |
| 1015 |
|
| 1016 |
static const __m128i pre_tf_hi_s4 = |
| 1017 |
M128I_BYTE(0x00, 0xf1, 0x8a, 0x7b, 0x09, 0xf8, 0x83, 0x72, |
| 1018 |
0xad, 0x5c, 0x27, 0xd6, 0xa4, 0x55, 0x2e, 0xdf); |
| 1019 |
|
| 1020 |
/* |
| 1021 |
* post-SubByte transform |
| 1022 |
* |
| 1023 |
* post-lookup for sbox1, sbox4: |
| 1024 |
* swap_bitendianness( |
| 1025 |
* camellia_h( |
| 1026 |
* isom_map_aes_to_camellia( |
| 1027 |
* swap_bitendianness( |
| 1028 |
* aes_inverse_affine_transform(in) |
| 1029 |
* ) |
| 1030 |
* ) |
| 1031 |
* ) |
| 1032 |
* ) |
| 1033 |
* |
| 1034 |
* (note: '⊕ 0x6e' inside camellia_h()) |
| 1035 |
*/ |
| 1036 |
static const __m128i post_tf_lo_s1 = |
| 1037 |
M128I_BYTE(0x3c, 0xcc, 0xcf, 0x3f, 0x32, 0xc2, 0xc1, 0x31, |
| 1038 |
0xdc, 0x2c, 0x2f, 0xdf, 0xd2, 0x22, 0x21, 0xd1); |
| 1039 |
|
| 1040 |
static const __m128i post_tf_hi_s1 = |
| 1041 |
M128I_BYTE(0x00, 0xf9, 0x86, 0x7f, 0xd7, 0x2e, 0x51, 0xa8, |
| 1042 |
0xa4, 0x5d, 0x22, 0xdb, 0x73, 0x8a, 0xf5, 0x0c); |
| 1043 |
|
| 1044 |
/* |
| 1045 |
* post-SubByte transform |
| 1046 |
* |
| 1047 |
* post-lookup for sbox2: |
| 1048 |
* swap_bitendianness( |
| 1049 |
* camellia_h( |
| 1050 |
* isom_map_aes_to_camellia( |
| 1051 |
* swap_bitendianness( |
| 1052 |
* aes_inverse_affine_transform(in) |
| 1053 |
* ) |
| 1054 |
* ) |
| 1055 |
* ) |
| 1056 |
* ) <<< 1 |
| 1057 |
* |
| 1058 |
* (note: '⊕ 0x6e' inside camellia_h()) |
| 1059 |
*/ |
| 1060 |
static const __m128i post_tf_lo_s2 = |
| 1061 |
M128I_BYTE(0x78, 0x99, 0x9f, 0x7e, 0x64, 0x85, 0x83, 0x62, |
| 1062 |
0xb9, 0x58, 0x5e, 0xbf, 0xa5, 0x44, 0x42, 0xa3); |
| 1063 |
|
| 1064 |
static const __m128i post_tf_hi_s2 = |
| 1065 |
M128I_BYTE(0x00, 0xf3, 0x0d, 0xfe, 0xaf, 0x5c, 0xa2, 0x51, |
| 1066 |
0x49, 0xba, 0x44, 0xb7, 0xe6, 0x15, 0xeb, 0x18); |
| 1067 |
|
| 1068 |
/* |
| 1069 |
* post-SubByte transform |
| 1070 |
* |
| 1071 |
* post-lookup for sbox3: |
| 1072 |
* swap_bitendianness( |
| 1073 |
* camellia_h( |
| 1074 |
* isom_map_aes_to_camellia( |
| 1075 |
* swap_bitendianness( |
| 1076 |
* aes_inverse_affine_transform(in) |
| 1077 |
* ) |
| 1078 |
* ) |
| 1079 |
* ) |
| 1080 |
* ) >>> 1 |
| 1081 |
* |
| 1082 |
* (note: '⊕ 0x6e' inside camellia_h()) |
| 1083 |
*/ |
| 1084 |
static const __m128i post_tf_lo_s3 = |
| 1085 |
M128I_BYTE(0x1e, 0x66, 0xe7, 0x9f, 0x19, 0x61, 0xe0, 0x98, |
| 1086 |
0x6e, 0x16, 0x97, 0xef, 0x69, 0x11, 0x90, 0xe8); |
| 1087 |
|
| 1088 |
static const __m128i post_tf_hi_s3 = |
| 1089 |
M128I_BYTE(0x00, 0xfc, 0x43, 0xbf, 0xeb, 0x17, 0xa8, 0x54, |
| 1090 |
0x52, 0xae, 0x11, 0xed, 0xb9, 0x45, 0xfa, 0x06); |
| 1091 |
|
| 1092 |
/* For isolating SubBytes from AESENCLAST, inverse shift row */ |
| 1093 |
static const __m128i inv_shift_row = |
| 1094 |
M128I_BYTE(0x00, 0x0d, 0x0a, 0x07, 0x04, 0x01, 0x0e, 0x0b, |
| 1095 |
0x08, 0x05, 0x02, 0x0f, 0x0c, 0x09, 0x06, 0x03); |
| 1096 |
|
| 1097 |
/* 4-bit mask */ |
| 1098 |
static const __m128i mask_0f = |
| 1099 |
M128I_U32(0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f, 0x0f0f0f0f); |
| 1100 |
|
| 1101 |
/* Encrypts 16 input block from IN and writes result to OUT. IN and OUT may |
| 1102 |
* unaligned pointers. */ |
| 1103 |
void ASM_FUNC_ATTR_NOINLINE |
| 1104 |
FUNC_ENC_BLK16(const void *key_table, void *vout, const void *vin, |
| 1105 |
int key_length) |
| 1106 |
{ |
| 1107 |
const struct enc_ctx_s |
| 1108 |
{ |
| 1109 |
const u64 *key_table; |
| 1110 |
int key_length; |
| 1111 |
} sctx = |
| 1112 |
{ |
| 1113 |
.key_table = (const u64 *)key_table, |
| 1114 |
.key_length = key_length |
| 1115 |
}; |
| 1116 |
const struct enc_ctx_s *ctx = &sctx; |
| 1117 |
char *out = vout; |
| 1118 |
const char *in = vin; |
| 1119 |
__m128i x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; |
| 1120 |
__m128i ab[8]; |
| 1121 |
__m128i cd[8]; |
| 1122 |
__m128i tmp0, tmp1; |
| 1123 |
unsigned int lastk, k; |
| 1124 |
frequent_constants_declare; |
| 1125 |
|
| 1126 |
prepare_frequent_constants(); |
| 1127 |
|
| 1128 |
if (ctx->key_length > 16) |
| 1129 |
lastk = 32; |
| 1130 |
else |
| 1131 |
lastk = 24; |
| 1132 |
|
| 1133 |
inpack16_pre(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1134 |
x15, in, ctx->key_table[0]); |
| 1135 |
|
| 1136 |
inpack16_post(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1137 |
x15, ab, cd); |
| 1138 |
|
| 1139 |
k = 0; |
| 1140 |
while (1) |
| 1141 |
{ |
| 1142 |
enc_rounds16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1143 |
x15, ab, cd, k); |
| 1144 |
|
| 1145 |
if (k == lastk - 8) |
| 1146 |
break; |
| 1147 |
|
| 1148 |
fls16(ab, x0, x1, x2, x3, x4, x5, x6, x7, cd, x8, x9, x10, x11, x12, x13, x14, |
| 1149 |
x15, &ctx->key_table[k + 8], &ctx->key_table[k + 9]); |
| 1150 |
|
| 1151 |
k += 8; |
| 1152 |
} |
| 1153 |
|
| 1154 |
/* load CD for output */ |
| 1155 |
vmovdqa128(cd[0], x8); |
| 1156 |
vmovdqa128(cd[1], x9); |
| 1157 |
vmovdqa128(cd[2], x10); |
| 1158 |
vmovdqa128(cd[3], x11); |
| 1159 |
vmovdqa128(cd[4], x12); |
| 1160 |
vmovdqa128(cd[5], x13); |
| 1161 |
vmovdqa128(cd[6], x14); |
| 1162 |
vmovdqa128(cd[7], x15); |
| 1163 |
|
| 1164 |
outunpack16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1165 |
x15, ctx->key_table[lastk], tmp0, tmp1); |
| 1166 |
|
| 1167 |
write_output(x7, x6, x5, x4, x3, x2, x1, x0, x15, x14, x13, x12, x11, x10, x9, |
| 1168 |
x8, out); |
| 1169 |
|
| 1170 |
clear_vec_regs(); |
| 1171 |
} |
| 1172 |
|
| 1173 |
/* Decrypts 16 input block from IN and writes result to OUT. IN and OUT may |
| 1174 |
* unaligned pointers. */ |
| 1175 |
void ASM_FUNC_ATTR_NOINLINE |
| 1176 |
FUNC_DEC_BLK16(const void *key_table, void *vout, const void *vin, |
| 1177 |
int key_length) |
| 1178 |
{ |
| 1179 |
const struct dec_ctx_s |
| 1180 |
{ |
| 1181 |
const u64 *key_table; |
| 1182 |
int key_length; |
| 1183 |
} sctx = |
| 1184 |
{ |
| 1185 |
.key_table = (const u64 *)key_table, |
| 1186 |
.key_length = key_length |
| 1187 |
}; |
| 1188 |
const struct dec_ctx_s *ctx = &sctx; |
| 1189 |
char *out = vout; |
| 1190 |
const char *in = vin; |
| 1191 |
__m128i x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; |
| 1192 |
__m128i ab[8]; |
| 1193 |
__m128i cd[8]; |
| 1194 |
__m128i tmp0, tmp1; |
| 1195 |
unsigned int firstk, k; |
| 1196 |
frequent_constants_declare; |
| 1197 |
|
| 1198 |
prepare_frequent_constants(); |
| 1199 |
|
| 1200 |
if (ctx->key_length > 16) |
| 1201 |
firstk = 32; |
| 1202 |
else |
| 1203 |
firstk = 24; |
| 1204 |
|
| 1205 |
inpack16_pre(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1206 |
x15, in, ctx->key_table[firstk]); |
| 1207 |
|
| 1208 |
inpack16_post(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1209 |
x15, ab, cd); |
| 1210 |
|
| 1211 |
k = firstk - 8; |
| 1212 |
while (1) |
| 1213 |
{ |
| 1214 |
dec_rounds16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, |
| 1215 |
x14, x15, ab, cd, k); |
| 1216 |
|
| 1217 |
if (k == 0) |
| 1218 |
break; |
| 1219 |
|
| 1220 |
fls16(ab, x0, x1, x2, x3, x4, x5, x6, x7, cd, x8, x9, x10, x11, x12, x13, |
| 1221 |
x14, x15, &ctx->key_table[k + 1], &ctx->key_table[k]); |
| 1222 |
|
| 1223 |
k -= 8; |
| 1224 |
} |
| 1225 |
|
| 1226 |
/* load CD for output */ |
| 1227 |
vmovdqa128(cd[0], x8); |
| 1228 |
vmovdqa128(cd[1], x9); |
| 1229 |
vmovdqa128(cd[2], x10); |
| 1230 |
vmovdqa128(cd[3], x11); |
| 1231 |
vmovdqa128(cd[4], x12); |
| 1232 |
vmovdqa128(cd[5], x13); |
| 1233 |
vmovdqa128(cd[6], x14); |
| 1234 |
vmovdqa128(cd[7], x15); |
| 1235 |
|
| 1236 |
outunpack16(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, |
| 1237 |
x15, ctx->key_table[0], tmp0, tmp1); |
| 1238 |
|
| 1239 |
write_output(x7, x6, x5, x4, x3, x2, x1, x0, x15, x14, x13, x12, x11, x10, x9, |
| 1240 |
x8, out); |
| 1241 |
|
| 1242 |
clear_vec_regs(); |
| 1243 |
} |
| 1244 |
|
| 1245 |
/********* Key setup **********************************************************/ |
| 1246 |
|
| 1247 |
/* Camellia F-function, 1-way SIMD128. */ |
| 1248 |
#define camellia_f_core(ab, x, t0, t1, t2, t3, t4, inv_shift_row_n_s2n3_shuffle, \ |
| 1249 |
_0f0f0f0fmask, pre_s1lo_mask, pre_s1hi_mask, \ |
| 1250 |
sp1mask, sp2mask, sp3mask, sp4mask, fn_out_xor, \ |
| 1251 |
out_xor_dst) \ |
| 1252 |
/* \ |
| 1253 |
* S-function with AES subbytes \ |
| 1254 |
*/ \ |
| 1255 |
\ |
| 1256 |
vmovdqa128_memld(&pre_tf_lo_s4, t0); \ |
| 1257 |
vmovdqa128_memld(&pre_tf_hi_s4, t1); \ |
| 1258 |
if_not_aes_subbytes(load_zero(t3)); \ |
| 1259 |
\ |
| 1260 |
/* prefilter sboxes s1,s2,s3 */ \ |
| 1261 |
filter_8bit_3op(t4, ab, pre_s1lo_mask, pre_s1hi_mask, _0f0f0f0fmask, t2); \ |
| 1262 |
\ |
| 1263 |
/* prefilter sbox s4 */ \ |
| 1264 |
filter_8bit_3op(x, ab, t0, t1, _0f0f0f0fmask, t2); \ |
| 1265 |
\ |
| 1266 |
vmovdqa128_memld(&post_tf_lo_s1, t0); \ |
| 1267 |
vmovdqa128_memld(&post_tf_hi_s1, t1); \ |
| 1268 |
\ |
| 1269 |
if_not_aes_subbytes(/* AES subbytes + AES shift rows */); \ |
| 1270 |
if_not_aes_subbytes(aes_subbytes_and_shuf_and_xor(t3, t4, t4)); \ |
| 1271 |
if_not_aes_subbytes(aes_subbytes_and_shuf_and_xor(t3, x, x)); \ |
| 1272 |
\ |
| 1273 |
if_aes_subbytes(/* AES subbytes */); \ |
| 1274 |
if_aes_subbytes(aes_subbytes(t4, t4)); \ |
| 1275 |
if_aes_subbytes(aes_subbytes(x, x)); \ |
| 1276 |
\ |
| 1277 |
/* postfilter sboxes s1,s2,s3 */ \ |
| 1278 |
filter_8bit(t4, t0, t1, _0f0f0f0fmask, t2); \ |
| 1279 |
\ |
| 1280 |
/* postfilter sbox s4 */ \ |
| 1281 |
filter_8bit(x, t0, t1, _0f0f0f0fmask, t2); \ |
| 1282 |
\ |
| 1283 |
/* output rotation for sbox2 (<<< 1) */ \ |
| 1284 |
/* output rotation for sbox3 (>>> 1) */ \ |
| 1285 |
/* permutation */ \ |
| 1286 |
if_vprolb128(vpshufb128(sp2mask, t4, t0)); \ |
| 1287 |
if_vprolb128(vpshufb128(sp3mask, t4, t1)); \ |
| 1288 |
if_vprolb128(vpshufb128(sp1mask, t4, t4)); \ |
| 1289 |
if_vprolb128(vpshufb128(sp4mask, x, x)); \ |
| 1290 |
if_vprolb128(vprolb128(1, t0, t0, t2)); \ |
| 1291 |
if_vprolb128(vprolb128(7, t1, t1, t3)); \ |
| 1292 |
if_not_vprolb128(aes_inv_shuf(inv_shift_row_n_s2n3_shuffle, t4, t1)); \ |
| 1293 |
if_not_vprolb128(vpshufb128(sp1mask, t4, t4)); \ |
| 1294 |
if_not_vprolb128(vpshufb128(sp4mask, x, x)); \ |
| 1295 |
if_not_vprolb128(vpaddb128(t1, t1, t2)); \ |
| 1296 |
if_not_vprolb128(vpsrl_byte_128(7, t1, t0)); \ |
| 1297 |
if_not_vprolb128(vpsll_byte_128(7, t1, t3)); \ |
| 1298 |
if_not_vprolb128(vpor128(t0, t2, t0)); \ |
| 1299 |
if_not_vprolb128(vpsrl_byte_128(1, t1, t1)); \ |
| 1300 |
if_not_vprolb128(vpshufb128(sp2mask, t0, t0)); \ |
| 1301 |
if_not_vprolb128(vpor128(t1, t3, t1)); \ |
| 1302 |
if_not_vprolb128(vpshufb128(sp3mask, t1, t1)); \ |
| 1303 |
\ |
| 1304 |
vpxor128(x, t4, t4); \ |
| 1305 |
vpxor128(t4, t0, t0); \ |
| 1306 |
vpxor128(t1, t0, t0); \ |
| 1307 |
vpsrldq128(8, t0, x); \ |
| 1308 |
fn_out_xor(t0, x, out_xor_dst); |
| 1309 |
|
| 1310 |
#define camellia_f_xor_x(t0, x, _) \ |
| 1311 |
vpxor128(t0, x, x); |
| 1312 |
|
| 1313 |
/* |
| 1314 |
* IN: |
| 1315 |
* ab: 64-bit AB state |
| 1316 |
* cd: 64-bit CD state |
| 1317 |
*/ |
| 1318 |
#define camellia_f(ab, x, t0, t1, t2, t3, t4, inv_shift_row, \ |
| 1319 |
_0f0f0f0fmask, pre_s1lo_mask, pre_s1hi_mask, key) \ |
| 1320 |
({ \ |
| 1321 |
__m128i sp1mask, sp2mask, sp3mask, sp4mask; \ |
| 1322 |
vmovq128_amemld(&(key), t0); \ |
| 1323 |
vmovdqa128_memld(&sp1110111010011110mask, sp1mask); \ |
| 1324 |
vmovdqa128_memld(&sp0222022222000222mask, sp2mask); \ |
| 1325 |
vmovdqa128_memld(&sp3033303303303033mask, sp3mask); \ |
| 1326 |
vmovdqa128_memld(&sp0044440444044404mask, sp4mask); \ |
| 1327 |
vpxor128(ab, t0, x); \ |
| 1328 |
camellia_f_core(x, x, t0, t1, t2, t3, t4, inv_shift_row, \ |
| 1329 |
_0f0f0f0fmask, pre_s1lo_mask, pre_s1hi_mask, \ |
| 1330 |
sp1mask, sp2mask, sp3mask, sp4mask, \ |
| 1331 |
camellia_f_xor_x, _); \ |
| 1332 |
}) |
| 1333 |
|
| 1334 |
#define vec_rol128(in, out, nrol, t0) \ |
| 1335 |
vpshufd128_0x4e(in, out); \ |
| 1336 |
vpsllq128((nrol), in, t0); \ |
| 1337 |
vpsrlq128((64-(nrol)), out, out); \ |
| 1338 |
vpaddb128(t0, out, out); |
| 1339 |
|
| 1340 |
#define vec_ror128(in, out, nror, t0) \ |
| 1341 |
vpshufd128_0x4e(in, out); \ |
| 1342 |
vpsrlq128((nror), in, t0); \ |
| 1343 |
vpsllq128((64-(nror)), out, out); \ |
| 1344 |
vpaddb128(t0, out, out); |
| 1345 |
|
| 1346 |
#define U64_BYTE(a0, a1, a2, a3, b0, b1, b2, b3) \ |
| 1347 |
( \ |
| 1348 |
SWAP_LE64((((a0) & 0xffULL) << 0) | \ |
| 1349 |
(((a1) & 0xffULL) << 8) | \ |
| 1350 |
(((a2) & 0xffULL) << 16) | \ |
| 1351 |
(((a3) & 0xffULL) << 24) | \ |
| 1352 |
(((b0) & 0xffULL) << 32) | \ |
| 1353 |
(((b1) & 0xffULL) << 40) | \ |
| 1354 |
(((b2) & 0xffULL) << 48) | \ |
| 1355 |
(((b3) & 0xffULL) << 56)) \ |
| 1356 |
) |
| 1357 |
|
| 1358 |
#define U64_U32(a0, b0) \ |
| 1359 |
( \ |
| 1360 |
SWAP_LE64((((a0) & 0xffffffffULL) << 0) | \ |
| 1361 |
(((b0) & 0xffffffffULL) << 32)) \ |
| 1362 |
) |
| 1363 |
|
| 1364 |
static const __m128i bswap128_mask = |
| 1365 |
M128I_BYTE(15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0); |
| 1366 |
|
| 1367 |
if_not_vprolb128( |
| 1368 |
static const __m128i inv_shift_row_and_unpcklbw = |
| 1369 |
M128I_BYTE(0x00, 0xff, 0x0d, 0xff, 0x0a, 0xff, 0x07, 0xff, |
| 1370 |
0x04, 0xff, 0x01, 0xff, 0x0e, 0xff, 0x0b, 0xff); |
| 1371 |
) |
| 1372 |
|
| 1373 |
static const __m128i sp0044440444044404mask = |
| 1374 |
if_aes_subbytes(M128I_U32(0xffff0404, 0x0404ff04, 0x0101ff01, 0x0101ff01)) |
| 1375 |
if_not_aes_subbytes(M128I_U32(0xffff0404, 0x0404ff04, 0x0d0dff0d, 0x0d0dff0d)); |
| 1376 |
|
| 1377 |
static const __m128i sp1110111010011110mask = |
| 1378 |
if_aes_subbytes(M128I_U32(0x000000ff, 0x000000ff, 0x07ffff07, 0x070707ff)) |
| 1379 |
if_not_aes_subbytes(M128I_U32(0x000000ff, 0x000000ff, 0x0bffff0b, 0x0b0b0bff)); |
| 1380 |
|
| 1381 |
static const __m128i sp0222022222000222mask = |
| 1382 |
if_aes_subbytes(if_vprolb128(M128I_U32(0xff030303, 0xff030303, 0x0606ffff, 0xff060606))) |
| 1383 |
if_aes_subbytes(if_not_vprolb128(M128I_U32(0xff0e0e0e, 0xff0e0e0e, 0x0c0cffff, 0xff0c0c0c))) |
| 1384 |
if_not_aes_subbytes(if_vprolb128(M128I_U32(0xff070707, 0xff070707, 0x0e0effff, 0xff0e0e0e))) |
| 1385 |
if_not_aes_subbytes(if_not_vprolb128(M128I_U32(0xff060606, 0xff060606, 0x0c0cffff, 0xff0c0c0c))); |
| 1386 |
|
| 1387 |
static const __m128i sp3033303303303033mask = |
| 1388 |
if_aes_subbytes(if_vprolb128(M128I_U32(0x02ff0202, 0x02ff0202, 0xff0505ff, 0x05ff0505))) |
| 1389 |
if_aes_subbytes(if_not_vprolb128(M128I_U32(0x04ff0404, 0x04ff0404, 0xff0202ff, 0x0202ff02))) |
| 1390 |
if_not_aes_subbytes(if_vprolb128(M128I_U32(0x0aff0a0a, 0x0aff0a0a, 0xff0101ff, 0x01ff0101))) |
| 1391 |
if_not_aes_subbytes(if_not_vprolb128(M128I_U32(0x04ff0404, 0x04ff0404, 0xff0a0aff, 0x0aff0a0a))); |
| 1392 |
|
| 1393 |
static const u64 sigma1 = |
| 1394 |
U64_U32(0x3BCC908B, 0xA09E667F); |
| 1395 |
|
| 1396 |
static const u64 sigma2 = |
| 1397 |
U64_U32(0x4CAA73B2, 0xB67AE858); |
| 1398 |
|
| 1399 |
static const u64 sigma3 = |
| 1400 |
U64_U32(0xE94F82BE, 0xC6EF372F); |
| 1401 |
|
| 1402 |
static const u64 sigma4 = |
| 1403 |
U64_U32(0xF1D36F1C, 0x54FF53A5); |
| 1404 |
|
| 1405 |
static const u64 sigma5 = |
| 1406 |
U64_U32(0xDE682D1D, 0x10E527FA); |
| 1407 |
|
| 1408 |
static const u64 sigma6 = |
| 1409 |
U64_U32(0xB3E6C1FD, 0xB05688C2); |
| 1410 |
|
| 1411 |
#define cmll_sub(n, ctx) &ctx->key_table[n] |
| 1412 |
|
| 1413 |
static ASM_FUNC_ATTR_INLINE void |
| 1414 |
camellia_setup128(void *key_table, __m128i x0) |
| 1415 |
{ |
| 1416 |
struct setup128_ctx_s |
| 1417 |
{ |
| 1418 |
u64 *key_table; |
| 1419 |
} sctx = { .key_table = (u64 *)key_table }; |
| 1420 |
struct setup128_ctx_s *ctx = &sctx; |
| 1421 |
|
| 1422 |
/* input: |
| 1423 |
* ctx: subkey storage at key_table(CTX) |
| 1424 |
* x0: key |
| 1425 |
*/ |
| 1426 |
|
| 1427 |
__m128i x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; |
| 1428 |
__m128i tmp0; |
| 1429 |
|
| 1430 |
#define KL128 x0 |
| 1431 |
#define KA128 x2 |
| 1432 |
|
| 1433 |
vpshufb128_amemld(&bswap128_mask, KL128, KL128); |
| 1434 |
|
| 1435 |
if_not_vprolb128(vmovdqa128_memld(&inv_shift_row_and_unpcklbw, x11)); |
| 1436 |
vmovdqa128_memld(&mask_0f, x13); |
| 1437 |
vmovdqa128_memld(&pre_tf_lo_s1, x14); |
| 1438 |
vmovdqa128_memld(&pre_tf_hi_s1, x15); |
| 1439 |
|
| 1440 |
/* |
| 1441 |
* Generate KA |
| 1442 |
*/ |
| 1443 |
vpsrldq128(8, KL128, x2); |
| 1444 |
vmovdqa128(KL128, x3); |
| 1445 |
vpslldq128(8, x3, x3); |
| 1446 |
vpsrldq128(8, x3, x3); |
| 1447 |
|
| 1448 |
camellia_f(x2, x4, x1, |
| 1449 |
x5, x6, x7, x8, |
| 1450 |
x11, x13, x14, x15, sigma1); |
| 1451 |
vpxor128(x4, x3, x3); |
| 1452 |
camellia_f(x3, x2, x1, |
| 1453 |
x5, x6, x7, x8, |
| 1454 |
x11, x13, x14, x15, sigma2); |
| 1455 |
camellia_f(x2, x3, x1, |
| 1456 |
x5, x6, x7, x8, |
| 1457 |
x11, x13, x14, x15, sigma3); |
| 1458 |
vpxor128(x4, x3, x3); |
| 1459 |
camellia_f(x3, x4, x1, |
| 1460 |
x5, x6, x7, x8, |
| 1461 |
x11, x13, x14, x15, sigma4); |
| 1462 |
|
| 1463 |
vpslldq128(8, x3, x3); |
| 1464 |
vpxor128(x4, x2, x2); |
| 1465 |
vpsrldq128(8, x3, x3); |
| 1466 |
vpslldq128(8, x2, KA128); |
| 1467 |
vpor128(x3, KA128, KA128); |
| 1468 |
|
| 1469 |
/* |
| 1470 |
* Generate subkeys |
| 1471 |
*/ |
| 1472 |
vmovdqu128_memst(KA128, cmll_sub(24, ctx)); |
| 1473 |
vec_rol128(KL128, x3, 15, x15); |
| 1474 |
vec_rol128(KA128, x4, 15, x15); |
| 1475 |
vec_rol128(KA128, x5, 30, x15); |
| 1476 |
vec_rol128(KL128, x6, 45, x15); |
| 1477 |
vec_rol128(KA128, x7, 45, x15); |
| 1478 |
vec_rol128(KL128, x8, 60, x15); |
| 1479 |
vec_rol128(KA128, x9, 60, x15); |
| 1480 |
vec_ror128(KL128, x10, 128-77, x15); |
| 1481 |
|
| 1482 |
/* absorb kw2 to other subkeys */ |
| 1483 |
vpslldq128(8, KL128, x15); |
| 1484 |
vpsrldq128(8, x15, x15); |
| 1485 |
vpxor128(x15, KA128, KA128); |
| 1486 |
vpxor128(x15, x3, x3); |
| 1487 |
vpxor128(x15, x4, x4); |
| 1488 |
|
| 1489 |
/* subl(1) ^= subr(1) & ~subr(9); */ |
| 1490 |
vpandn128(x15, x5, x13); |
| 1491 |
vpslldq128(12, x13, x13); |
| 1492 |
vpsrldq128(8, x13, x13); |
| 1493 |
vpxor128(x13, x15, x15); |
| 1494 |
/* dw = subl(1) & subl(9), subr(1) ^= CAMELLIA_RL1(dw); */ |
| 1495 |
vpand128(x15, x5, x14); |
| 1496 |
vpslld128(1, x14, x11); |
| 1497 |
vpsrld128(31, x14, x14); |
| 1498 |
vpaddb128(x11, x14, x14); |
| 1499 |
vpslldq128(8, x14, x14); |
| 1500 |
vpsrldq128(12, x14, x14); |
| 1501 |
vpxor128(x14, x15, x15); |
| 1502 |
|
| 1503 |
vpxor128(x15, x6, x6); |
| 1504 |
vpxor128(x15, x8, x8); |
| 1505 |
vpxor128(x15, x9, x9); |
| 1506 |
|
| 1507 |
/* subl(1) ^= subr(1) & ~subr(17); */ |
| 1508 |
vpandn128(x15, x10, x13); |
| 1509 |
vpslldq128(12, x13, x13); |
| 1510 |
vpsrldq128(8, x13, x13); |
| 1511 |
vpxor128(x13, x15, x15); |
| 1512 |
/* dw = subl(1) & subl(17), subr(1) ^= CAMELLIA_RL1(dw); */ |
| 1513 |
vpand128(x15, x10, x14); |
| 1514 |
vpslld128(1, x14, x11); |
| 1515 |
vpsrld128(31, x14, x14); |
| 1516 |
vpaddb128(x11, x14, x14); |
| 1517 |
vpslldq128(8, x14, x14); |
| 1518 |
vpsrldq128(12, x14, x14); |
| 1519 |
vpxor128(x14, x15, x15); |
| 1520 |
|
| 1521 |
vpshufd128_0x1b(KL128, KL128); |
| 1522 |
vpshufd128_0x1b(KA128, KA128); |
| 1523 |
vpshufd128_0x1b(x3, x3); |
| 1524 |
vpshufd128_0x1b(x4, x4); |
| 1525 |
vpshufd128_0x1b(x5, x5); |
| 1526 |
vpshufd128_0x1b(x6, x6); |
| 1527 |
vpshufd128_0x1b(x7, x7); |
| 1528 |
vpshufd128_0x1b(x8, x8); |
| 1529 |
vpshufd128_0x1b(x9, x9); |
| 1530 |
vpshufd128_0x1b(x10, x10); |
| 1531 |
|
| 1532 |
vmovdqu128_memst(KL128, cmll_sub(0, ctx)); |
| 1533 |
vpshufd128_0x1b(KL128, KL128); |
| 1534 |
vmovdqu128_memst(KA128, cmll_sub(2, ctx)); |
| 1535 |
vmovdqu128_memst(x3, cmll_sub(4, ctx)); |
| 1536 |
vmovdqu128_memst(x4, cmll_sub(6, ctx)); |
| 1537 |
vmovdqu128_memst(x5, cmll_sub(8, ctx)); |
| 1538 |
vmovdqu128_memst(x6, cmll_sub(10, ctx)); |
| 1539 |
vpsrldq128(8, x8, x8); |
| 1540 |
vmovq128_memst(x7, cmll_sub(12, ctx)); |
| 1541 |
vmovq128_memst(x8, cmll_sub(13, ctx)); |
| 1542 |
vmovdqu128_memst(x9, cmll_sub(14, ctx)); |
| 1543 |
vmovdqu128_memst(x10, cmll_sub(16, ctx)); |
| 1544 |
|
| 1545 |
vmovdqu128_memld(cmll_sub(24, ctx), KA128); |
| 1546 |
|
| 1547 |
vec_ror128(KL128, x3, 128 - 94, x7); |
| 1548 |
vec_ror128(KA128, x4, 128 - 94, x7); |
| 1549 |
vec_ror128(KL128, x5, 128 - 111, x7); |
| 1550 |
vec_ror128(KA128, x6, 128 - 111, x7); |
| 1551 |
|
| 1552 |
vpxor128(x15, x3, x3); |
| 1553 |
vpxor128(x15, x4, x4); |
| 1554 |
vpxor128(x15, x5, x5); |
| 1555 |
vpslldq128(8, x15, x15); |
| 1556 |
vpxor128(x15, x6, x6); |
| 1557 |
|
| 1558 |
/* absorb kw4 to other subkeys */ |
| 1559 |
vpslldq128(8, x6, x15); |
| 1560 |
vpxor128(x15, x5, x5); |
| 1561 |
vpxor128(x15, x4, x4); |
| 1562 |
vpxor128(x15, x3, x3); |
| 1563 |
|
| 1564 |
/* subl(25) ^= subr(25) & ~subr(16); */ |
| 1565 |
vmovdqu128_memld(cmll_sub(16, ctx), tmp0); |
| 1566 |
vpshufd128_0x1b(tmp0, x10); |
| 1567 |
vpandn128(x15, x10, x13); |
| 1568 |
vpslldq128(4, x13, x13); |
| 1569 |
vpxor128(x13, x15, x15); |
| 1570 |
/* dw = subl(25) & subl(16), subr(25) ^= CAMELLIA_RL1(dw); */ |
| 1571 |
vpand128(x15, x10, x14); |
| 1572 |
vpslld128(1, x14, x11); |
| 1573 |
vpsrld128(31, x14, x14); |
| 1574 |
vpaddb128(x11, x14, x14); |
| 1575 |
vpsrldq128(12, x14, x14); |
| 1576 |
vpslldq128(8, x14, x14); |
| 1577 |
vpxor128(x14, x15, x15); |
| 1578 |
|
| 1579 |
vpshufd128_0x1b(x3, x3); |
| 1580 |
vpshufd128_0x1b(x4, x4); |
| 1581 |
vpshufd128_0x1b(x5, x5); |
| 1582 |
vpshufd128_0x1b(x6, x6); |
| 1583 |
|
| 1584 |
vmovdqu128_memst(x3, cmll_sub(18, ctx)); |
| 1585 |
vmovdqu128_memst(x4, cmll_sub(20, ctx)); |
| 1586 |
vmovdqu128_memst(x5, cmll_sub(22, ctx)); |
| 1587 |
vmovdqu128_memst(x6, cmll_sub(24, ctx)); |
| 1588 |
|
| 1589 |
vmovdqu128_memld(cmll_sub(14, ctx), tmp0); |
| 1590 |
vpshufd128_0x1b(tmp0, x3); |
| 1591 |
vmovdqu128_memld(cmll_sub(12, ctx), tmp0); |
| 1592 |
vpshufd128_0x1b(tmp0, x4); |
| 1593 |
vmovdqu128_memld(cmll_sub(10, ctx), tmp0); |
| 1594 |
vpshufd128_0x1b(tmp0, x5); |
| 1595 |
vmovdqu128_memld(cmll_sub(8, ctx), tmp0); |
| 1596 |
vpshufd128_0x1b(tmp0, x6); |
| 1597 |
|
| 1598 |
vpxor128(x15, x3, x3); |
| 1599 |
vpxor128(x15, x4, x4); |
| 1600 |
vpxor128(x15, x5, x5); |
| 1601 |
|
| 1602 |
/* subl(25) ^= subr(25) & ~subr(8); */ |
| 1603 |
vpandn128(x15, x6, x13); |
| 1604 |
vpslldq128(4, x13, x13); |
| 1605 |
vpxor128(x13, x15, x15); |
| 1606 |
/* dw = subl(25) & subl(8), subr(25) ^= CAMELLIA_RL1(dw); */ |
| 1607 |
vpand128(x15, x6, x14); |
| 1608 |
vpslld128(1, x14, x11); |
| 1609 |
vpsrld128(31, x14, x14); |
| 1610 |
vpaddb128(x11, x14, x14); |
| 1611 |
vpsrldq128(12, x14, x14); |
| 1612 |
vpslldq128(8, x14, x14); |
| 1613 |
vpxor128(x14, x15, x15); |
| 1614 |
|
| 1615 |
vpshufd128_0x1b(x3, x3); |
| 1616 |
vpshufd128_0x1b(x4, x4); |
| 1617 |
vpshufd128_0x1b(x5, x5); |
| 1618 |
|
| 1619 |
vmovdqu128_memst(x3, cmll_sub(14, ctx)); |
| 1620 |
vmovdqu128_memst(x4, cmll_sub(12, ctx)); |
| 1621 |
vmovdqu128_memst(x5, cmll_sub(10, ctx)); |
| 1622 |
|
| 1623 |
vmovdqu128_memld(cmll_sub(6, ctx), tmp0); |
| 1624 |
vpshufd128_0x1b(tmp0, x6); |
| 1625 |
vmovdqu128_memld(cmll_sub(4, ctx), tmp0); |
| 1626 |
vpshufd128_0x1b(tmp0, x4); |
| 1627 |
vmovdqu128_memld(cmll_sub(2, ctx), tmp0); |
| 1628 |
vpshufd128_0x1b(tmp0, x2); |
| 1629 |
vmovdqu128_memld(cmll_sub(0, ctx), tmp0); |
| 1630 |
vpshufd128_0x1b(tmp0, x0); |
| 1631 |
|
| 1632 |
vpxor128(x15, x6, x6); |
| 1633 |
vpxor128(x15, x4, x4); |
| 1634 |
vpxor128(x15, x2, x2); |
| 1635 |
vpxor128(x15, x0, x0); |
| 1636 |
|
| 1637 |
vpshufd128_0x1b(x6, x6); |
| 1638 |
vpshufd128_0x1b(x4, x4); |
| 1639 |
vpshufd128_0x1b(x2, x2); |
| 1640 |
vpshufd128_0x1b(x0, x0); |
| 1641 |
|
| 1642 |
vpsrldq128(8, x2, x3); |
| 1643 |
vpsrldq128(8, x4, x5); |
| 1644 |
vpsrldq128(8, x6, x7); |
| 1645 |
|
| 1646 |
/* |
| 1647 |
* key XOR is end of F-function. |
| 1648 |
*/ |
| 1649 |
vpxor128(x2, x0, x0); |
| 1650 |
vpxor128(x4, x2, x2); |
| 1651 |
|
| 1652 |
vmovq128_memst(x0, cmll_sub(0, ctx)); |
| 1653 |
vmovq128_memst(x3, cmll_sub(2, ctx)); |
| 1654 |
vpxor128(x5, x3, x3); |
| 1655 |
vpxor128(x6, x4, x4); |
| 1656 |
vpxor128(x7, x5, x5); |
| 1657 |
vmovq128_memst(x2, cmll_sub(3, ctx)); |
| 1658 |
vmovq128_memst(x3, cmll_sub(4, ctx)); |
| 1659 |
vmovq128_memst(x4, cmll_sub(5, ctx)); |
| 1660 |
vmovq128_memst(x5, cmll_sub(6, ctx)); |
| 1661 |
|
| 1662 |
vmovq128_amemld(cmll_sub(7, ctx), x7); |
| 1663 |
vmovq128_amemld(cmll_sub(8, ctx), x8); |
| 1664 |
vmovq128_amemld(cmll_sub(9, ctx), x9); |
| 1665 |
vmovq128_amemld(cmll_sub(10, ctx), x10); |
| 1666 |
/* tl = subl(10) ^ (subr(10) & ~subr(8)); */ |
| 1667 |
vpandn128(x10, x8, x15); |
| 1668 |
vpsrldq128(4, x15, x15); |
| 1669 |
vpxor128(x15, x10, x0); |
| 1670 |
/* dw = tl & subl(8), tr = subr(10) ^ CAMELLIA_RL1(dw); */ |
| 1671 |
vpand128(x8, x0, x15); |
| 1672 |
vpslld128(1, x15, x14); |
| 1673 |
vpsrld128(31, x15, x15); |
| 1674 |
vpaddb128(x14, x15, x15); |
| 1675 |
vpslldq128(12, x15, x15); |
| 1676 |
vpsrldq128(8, x15, x15); |
| 1677 |
vpxor128(x15, x0, x0); |
| 1678 |
|
| 1679 |
vpxor128(x0, x6, x6); |
| 1680 |
vmovq128_memst(x6, cmll_sub(7, ctx)); |
| 1681 |
|
| 1682 |
vmovq128_amemld(cmll_sub(11, ctx), x11); |
| 1683 |
vmovq128_amemld(cmll_sub(12, ctx), x12); |
| 1684 |
vmovq128_amemld(cmll_sub(13, ctx), x13); |
| 1685 |
vmovq128_amemld(cmll_sub(14, ctx), x14); |
| 1686 |
vmovq128_amemld(cmll_sub(15, ctx), x15); |
| 1687 |
/* tl = subl(7) ^ (subr(7) & ~subr(9)); */ |
| 1688 |
vpandn128(x7, x9, x1); |
| 1689 |
vpsrldq128(4, x1, x1); |
| 1690 |
vpxor128(x1, x7, x0); |
| 1691 |
/* dw = tl & subl(9), tr = subr(7) ^ CAMELLIA_RL1(dw); */ |
| 1692 |
vpand128(x9, x0, x1); |
| 1693 |
vpslld128(1, x1, x2); |
| 1694 |
vpsrld128(31, x1, x1); |
| 1695 |
vpaddb128(x2, x1, x1); |
| 1696 |
vpslldq128(12, x1, x1); |
| 1697 |
vpsrldq128(8, x1, x1); |
| 1698 |
vpxor128(x1, x0, x0); |
| 1699 |
|
| 1700 |
vpxor128(x11, x0, x0); |
| 1701 |
vpxor128(x12, x10, x10); |
| 1702 |
vpxor128(x13, x11, x11); |
| 1703 |
vpxor128(x14, x12, x12); |
| 1704 |
vpxor128(x15, x13, x13); |
| 1705 |
vmovq128_memst(x0, cmll_sub(10, ctx)); |
| 1706 |
vmovq128_memst(x10, cmll_sub(11, ctx)); |
| 1707 |
vmovq128_memst(x11, cmll_sub(12, ctx)); |
| 1708 |
vmovq128_memst(x12, cmll_sub(13, ctx)); |
| 1709 |
vmovq128_memst(x13, cmll_sub(14, ctx)); |
| 1710 |
|
| 1711 |
vmovq128_amemld(cmll_sub(16, ctx), x6); |
| 1712 |
vmovq128_amemld(cmll_sub(17, ctx), x7); |
| 1713 |
vmovq128_amemld(cmll_sub(18, ctx), x8); |
| 1714 |
vmovq128_amemld(cmll_sub(19, ctx), x9); |
| 1715 |
vmovq128_amemld(cmll_sub(20, ctx), x10); |
| 1716 |
/* tl = subl(18) ^ (subr(18) & ~subr(16)); */ |
| 1717 |
vpandn128(x8, x6, x1); |
| 1718 |
vpsrldq128(4, x1, x1); |
| 1719 |
vpxor128(x1, x8, x0); |
| 1720 |
/* dw = tl & subl(16), tr = subr(18) ^ CAMELLIA_RL1(dw); */ |
| 1721 |
vpand128(x6, x0, x1); |
| 1722 |
vpslld128(1, x1, x2); |
| 1723 |
vpsrld128(31, x1, x1); |
| 1724 |
vpaddb128(x2, x1, x1); |
| 1725 |
vpslldq128(12, x1, x1); |
| 1726 |
vpsrldq128(8, x1, x1); |
| 1727 |
vpxor128(x1, x0, x0); |
| 1728 |
|
| 1729 |
vpxor128(x14, x0, x0); |
| 1730 |
vmovq128_memst(x0, cmll_sub(15, ctx)); |
| 1731 |
|
| 1732 |
/* tl = subl(15) ^ (subr(15) & ~subr(17)); */ |
| 1733 |
vpandn128(x15, x7, x1); |
| 1734 |
vpsrldq128(4, x1, x1); |
| 1735 |
vpxor128(x1, x15, x0); |
| 1736 |
/* dw = tl & subl(17), tr = subr(15) ^ CAMELLIA_RL1(dw); */ |
| 1737 |
vpand128(x7, x0, x1); |
| 1738 |
vpslld128(1, x1, x2); |
| 1739 |
vpsrld128(31, x1, x1); |
| 1740 |
vpaddb128(x2, x1, x1); |
| 1741 |
vpslldq128(12, x1, x1); |
| 1742 |
vpsrldq128(8, x1, x1); |
| 1743 |
vpxor128(x1, x0, x0); |
| 1744 |
|
| 1745 |
vmovq128_amemld(cmll_sub(21, ctx), x1); |
| 1746 |
vmovq128_amemld(cmll_sub(22, ctx), x2); |
| 1747 |
vmovq128_amemld(cmll_sub(23, ctx), x3); |
| 1748 |
vmovq128_amemld(cmll_sub(24, ctx), x4); |
| 1749 |
|
| 1750 |
vpxor128(x9, x0, x0); |
| 1751 |
vpxor128(x10, x8, x8); |
| 1752 |
vpxor128(x1, x9, x9); |
| 1753 |
vpxor128(x2, x10, x10); |
| 1754 |
vpxor128(x3, x1, x1); |
| 1755 |
vpxor128(x4, x3, x3); |
| 1756 |
|
| 1757 |
vmovq128_memst(x0, cmll_sub(18, ctx)); |
| 1758 |
vmovq128_memst(x8, cmll_sub(19, ctx)); |
| 1759 |
vmovq128_memst(x9, cmll_sub(20, ctx)); |
| 1760 |
vmovq128_memst(x10, cmll_sub(21, ctx)); |
| 1761 |
vmovq128_memst(x1, cmll_sub(22, ctx)); |
| 1762 |
vmovq128_memst(x2, cmll_sub(23, ctx)); |
| 1763 |
vmovq128_memst(x3, cmll_sub(24, ctx)); |
| 1764 |
|
| 1765 |
#undef KL128 |
| 1766 |
#undef KA128 |
| 1767 |
|
| 1768 |
/* kw2 and kw4 are unused now. */ |
| 1769 |
load_zero(tmp0); |
| 1770 |
vmovq128_memst(tmp0, cmll_sub(1, ctx)); |
| 1771 |
vmovq128_memst(tmp0, cmll_sub(25, ctx)); |
| 1772 |
|
| 1773 |
clear_vec_regs(); |
| 1774 |
} |
| 1775 |
|
| 1776 |
static ASM_FUNC_ATTR_INLINE void |
| 1777 |
camellia_setup256(void *key_table, __m128i x0, __m128i x1) |
| 1778 |
{ |
| 1779 |
struct setup256_ctx_s |
| 1780 |
{ |
| 1781 |
u64 *key_table; |
| 1782 |
} sctx = { .key_table = (u64 *)key_table }; |
| 1783 |
struct setup256_ctx_s *ctx = &sctx; |
| 1784 |
|
| 1785 |
/* input: |
| 1786 |
* ctx: subkey storage at key_table(CTX) |
| 1787 |
* x0, x1: key |
| 1788 |
*/ |
| 1789 |
|
| 1790 |
__m128i x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; |
| 1791 |
__m128i tmp0; |
| 1792 |
|
| 1793 |
#define KL128 x0 |
| 1794 |
#define KR128 x1 |
| 1795 |
#define KA128 x2 |
| 1796 |
#define KB128 x3 |
| 1797 |
|
| 1798 |
vpshufb128_amemld(&bswap128_mask, KL128, KL128); |
| 1799 |
vpshufb128_amemld(&bswap128_mask, KR128, KR128); |
| 1800 |
|
| 1801 |
if_not_vprolb128(vmovdqa128_memld(&inv_shift_row_and_unpcklbw, x11)); |
| 1802 |
vmovdqa128_memld(&mask_0f, x13); |
| 1803 |
vmovdqa128_memld(&pre_tf_lo_s1, x14); |
| 1804 |
vmovdqa128_memld(&pre_tf_hi_s1, x15); |
| 1805 |
|
| 1806 |
/* |
| 1807 |
* Generate KA |
| 1808 |
*/ |
| 1809 |
vpxor128(KL128, KR128, x3); |
| 1810 |
vpsrldq128(8, KR128, x6); |
| 1811 |
vpsrldq128(8, x3, x2); |
| 1812 |
vpslldq128(8, x3, x3); |
| 1813 |
vpsrldq128(8, x3, x3); |
| 1814 |
|
| 1815 |
camellia_f(x2, x4, x5, |
| 1816 |
x7, x8, x9, x10, |
| 1817 |
x11, x13, x14, x15, sigma1); |
| 1818 |
vpxor128(x4, x3, x3); |
| 1819 |
camellia_f(x3, x2, x5, |
| 1820 |
x7, x8, x9, x10, |
| 1821 |
x11, x13, x14, x15, sigma2); |
| 1822 |
vpxor128(x6, x2, x2); |
| 1823 |
camellia_f(x2, x3, x5, |
| 1824 |
x7, x8, x9, x10, |
| 1825 |
x11, x13, x14, x15, sigma3); |
| 1826 |
vpxor128(x4, x3, x3); |
| 1827 |
vpxor128(KR128, x3, x3); |
| 1828 |
camellia_f(x3, x4, x5, |
| 1829 |
x7, x8, x9, x10, |
| 1830 |
x11, x13, x14, x15, sigma4); |
| 1831 |
|
| 1832 |
vpslldq128(8, x3, x3); |
| 1833 |
vpxor128(x4, x2, x2); |
| 1834 |
vpsrldq128(8, x3, x3); |
| 1835 |
vpslldq128(8, x2, KA128); |
| 1836 |
vpor128(x3, KA128, KA128); |
| 1837 |
|
| 1838 |
/* |
| 1839 |
* Generate KB |
| 1840 |
*/ |
| 1841 |
vpxor128(KA128, KR128, x3); |
| 1842 |
vpsrldq128(8, x3, x4); |
| 1843 |
vpslldq128(8, x3, x3); |
| 1844 |
vpsrldq128(8, x3, x3); |
| 1845 |
|
| 1846 |
camellia_f(x4, x5, x6, |
| 1847 |
x7, x8, x9, x10, |
| 1848 |
x11, x13, x14, x15, sigma5); |
| 1849 |
vpxor128(x5, x3, x3); |
| 1850 |
|
| 1851 |
camellia_f(x3, x5, x6, |
| 1852 |
x7, x8, x9, x10, |
| 1853 |
x11, x13, x14, x15, sigma6); |
| 1854 |
vpslldq128(8, x3, x3); |
| 1855 |
vpxor128(x5, x4, x4); |
| 1856 |
vpsrldq128(8, x3, x3); |
| 1857 |
vpslldq128(8, x4, x4); |
| 1858 |
vpor128(x3, x4, KB128); |
| 1859 |
|
| 1860 |
/* |
| 1861 |
* Generate subkeys |
| 1862 |
*/ |
| 1863 |
vmovdqu128_memst(KB128, cmll_sub(32, ctx)); |
| 1864 |
vec_rol128(KR128, x4, 15, x15); |
| 1865 |
vec_rol128(KA128, x5, 15, x15); |
| 1866 |
vec_rol128(KR128, x6, 30, x15); |
| 1867 |
vec_rol128(KB128, x7, 30, x15); |
| 1868 |
vec_rol128(KL128, x8, 45, x15); |
| 1869 |
vec_rol128(KA128, x9, 45, x15); |
| 1870 |
vec_rol128(KL128, x10, 60, x15); |
| 1871 |
vec_rol128(KR128, x11, 60, x15); |
| 1872 |
vec_rol128(KB128, x12, 60, x15); |
| 1873 |
|
| 1874 |
/* absorb kw2 to other subkeys */ |
| 1875 |
vpslldq128(8, KL128, x15); |
| 1876 |
vpsrldq128(8, x15, x15); |
| 1877 |
vpxor128(x15, KB128, KB128); |
| 1878 |
vpxor128(x15, x4, x4); |
| 1879 |
vpxor128(x15, x5, x5); |
| 1880 |
|
| 1881 |
/* subl(1) ^= subr(1) & ~subr(9); */ |
| 1882 |
vpandn128(x15, x6, x13); |
| 1883 |
vpslldq128(12, x13, x13); |
| 1884 |
vpsrldq128(8, x13, x13); |
| 1885 |
vpxor128(x13, x15, x15); |
| 1886 |
/* dw = subl(1) & subl(9), subr(1) ^= CAMELLIA_RL1(dw); */ |
| 1887 |
vpand128(x15, x6, x14); |
| 1888 |
vpslld128(1, x14, x13); |
| 1889 |
vpsrld128(31, x14, x14); |
| 1890 |
vpaddb128(x13, x14, x14); |
| 1891 |
vpslldq128(8, x14, x14); |
| 1892 |
vpsrldq128(12, x14, x14); |
| 1893 |
vpxor128(x14, x15, x15); |
| 1894 |
|
| 1895 |
vpxor128(x15, x7, x7); |
| 1896 |
vpxor128(x15, x8, x8); |
| 1897 |
vpxor128(x15, x9, x9); |
| 1898 |
|
| 1899 |
vpshufd128_0x1b(KL128, KL128); |
| 1900 |
vpshufd128_0x1b(KB128, KB128); |
| 1901 |
vpshufd128_0x1b(x4, x4); |
| 1902 |
vpshufd128_0x1b(x5, x5); |
| 1903 |
vpshufd128_0x1b(x6, x6); |
| 1904 |
vpshufd128_0x1b(x7, x7); |
| 1905 |
vpshufd128_0x1b(x8, x8); |
| 1906 |
vpshufd128_0x1b(x9, x9); |
| 1907 |
|
| 1908 |
vmovdqu128_memst(KL128, cmll_sub(0, ctx)); |
| 1909 |
vpshufd128_0x1b(KL128, KL128); |
| 1910 |
vmovdqu128_memst(KB128, cmll_sub(2, ctx)); |
| 1911 |
vmovdqu128_memst(x4, cmll_sub(4, ctx)); |
| 1912 |
vmovdqu128_memst(x5, cmll_sub(6, ctx)); |
| 1913 |
vmovdqu128_memst(x6, cmll_sub(8, ctx)); |
| 1914 |
vmovdqu128_memst(x7, cmll_sub(10, ctx)); |
| 1915 |
vmovdqu128_memst(x8, cmll_sub(12, ctx)); |
| 1916 |
vmovdqu128_memst(x9, cmll_sub(14, ctx)); |
| 1917 |
|
| 1918 |
vmovdqu128_memld(cmll_sub(32, ctx), KB128); |
| 1919 |
|
| 1920 |
/* subl(1) ^= subr(1) & ~subr(17); */ |
| 1921 |
vpandn128(x15, x10, x13); |
| 1922 |
vpslldq128(12, x13, x13); |
| 1923 |
vpsrldq128(8, x13, x13); |
| 1924 |
vpxor128(x13, x15, x15); |
| 1925 |
/* dw = subl(1) & subl(17), subr(1) ^= CAMELLIA_RL1(dw); */ |
| 1926 |
vpand128(x15, x10, x14); |
| 1927 |
vpslld128(1, x14, x13); |
| 1928 |
vpsrld128(31, x14, x14); |
| 1929 |
vpaddb128(x13, x14, x14); |
| 1930 |
vpslldq128(8, x14, x14); |
| 1931 |
vpsrldq128(12, x14, x14); |
| 1932 |
vpxor128(x14, x15, x15); |
| 1933 |
|
| 1934 |
vpxor128(x15, x11, x11); |
| 1935 |
vpxor128(x15, x12, x12); |
| 1936 |
|
| 1937 |
vec_ror128(KL128, x4, 128-77, x14); |
| 1938 |
vec_ror128(KA128, x5, 128-77, x14); |
| 1939 |
vec_ror128(KR128, x6, 128-94, x14); |
| 1940 |
vec_ror128(KA128, x7, 128-94, x14); |
| 1941 |
vec_ror128(KL128, x8, 128-111, x14); |
| 1942 |
vec_ror128(KB128, x9, 128-111, x14); |
| 1943 |
|
| 1944 |
vpxor128(x15, x4, x4); |
| 1945 |
|
| 1946 |
vpshufd128_0x1b(x10, x10); |
| 1947 |
vpshufd128_0x1b(x11, x11); |
| 1948 |
vpshufd128_0x1b(x12, x12); |
| 1949 |
vpshufd128_0x1b(x4, x4); |
| 1950 |
|
| 1951 |
vmovdqu128_memst(x10, cmll_sub(16, ctx)); |
| 1952 |
vmovdqu128_memst(x11, cmll_sub(18, ctx)); |
| 1953 |
vmovdqu128_memst(x12, cmll_sub(20, ctx)); |
| 1954 |
vmovdqu128_memst(x4, cmll_sub(22, ctx)); |
| 1955 |
|
| 1956 |
/* subl(1) ^= subr(1) & ~subr(25); */ |
| 1957 |
vpandn128(x15, x5, x13); |
| 1958 |
vpslldq128(12, x13, x13); |
| 1959 |
vpsrldq128(8, x13, x13); |
| 1960 |
vpxor128(x13, x15, x15); |
| 1961 |
/* dw = subl(1) & subl(25), subr(1) ^= CAMELLIA_RL1(dw); */ |
| 1962 |
vpand128(x15, x5, x14); |
| 1963 |
vpslld128(1, x14, x13); |
| 1964 |
vpsrld128(31, x14, x14); |
| 1965 |
vpaddb128(x13, x14, x14); |
| 1966 |
vpslldq128(8, x14, x14); |
| 1967 |
vpsrldq128(12, x14, x14); |
| 1968 |
vpxor128(x14, x15, x15); |
| 1969 |
|
| 1970 |
vpxor128(x15, x6, x6); |
| 1971 |
vpxor128(x15, x7, x7); |
| 1972 |
vpxor128(x15, x8, x8); |
| 1973 |
vpslldq128(8, x15, x15); |
| 1974 |
vpxor128(x15, x9, x9); |
| 1975 |
|
| 1976 |
/* absorb kw4 to other subkeys */ |
| 1977 |
vpslldq128(8, x9, x15); |
| 1978 |
vpxor128(x15, x8, x8); |
| 1979 |
vpxor128(x15, x7, x7); |
| 1980 |
vpxor128(x15, x6, x6); |
| 1981 |
|
| 1982 |
/* subl(33) ^= subr(33) & ~subr(24); */ |
| 1983 |
vpandn128(x15, x5, x14); |
| 1984 |
vpslldq128(4, x14, x14); |
| 1985 |
vpxor128(x14, x15, x15); |
| 1986 |
/* dw = subl(33) & subl(24), subr(33) ^= CAMELLIA_RL1(dw); */ |
| 1987 |
vpand128(x15, x5, x14); |
| 1988 |
vpslld128(1, x14, x13); |
| 1989 |
vpsrld128(31, x14, x14); |
| 1990 |
vpaddb128(x13, x14, x14); |
| 1991 |
vpsrldq128(12, x14, x14); |
| 1992 |
vpslldq128(8, x14, x14); |
| 1993 |
vpxor128(x14, x15, x15); |
| 1994 |
|
| 1995 |
vpshufd128_0x1b(x5, x5); |
| 1996 |
vpshufd128_0x1b(x6, x6); |
| 1997 |
vpshufd128_0x1b(x7, x7); |
| 1998 |
vpshufd128_0x1b(x8, x8); |
| 1999 |
vpshufd128_0x1b(x9, x9); |
| 2000 |
|
| 2001 |
vmovdqu128_memst(x5, cmll_sub(24, ctx)); |
| 2002 |
vmovdqu128_memst(x6, cmll_sub(26, ctx)); |
| 2003 |
vmovdqu128_memst(x7, cmll_sub(28, ctx)); |
| 2004 |
vmovdqu128_memst(x8, cmll_sub(30, ctx)); |
| 2005 |
vmovdqu128_memst(x9, cmll_sub(32, ctx)); |
| 2006 |
|
| 2007 |
vmovdqu128_memld(cmll_sub(22, ctx), tmp0); |
| 2008 |
vpshufd128_0x1b(tmp0, x0); |
| 2009 |
vmovdqu128_memld(cmll_sub(20, ctx), tmp0); |
| 2010 |
vpshufd128_0x1b(tmp0, x1); |
| 2011 |
vmovdqu128_memld(cmll_sub(18, ctx), tmp0); |
| 2012 |
vpshufd128_0x1b(tmp0, x2); |
| 2013 |
vmovdqu128_memld(cmll_sub(16, ctx), tmp0); |
| 2014 |
vpshufd128_0x1b(tmp0, x3); |
| 2015 |
vmovdqu128_memld(cmll_sub(14, ctx), tmp0); |
| 2016 |
vpshufd128_0x1b(tmp0, x4); |
| 2017 |
vmovdqu128_memld(cmll_sub(12, ctx), tmp0); |
| 2018 |
vpshufd128_0x1b(tmp0, x5); |
| 2019 |
vmovdqu128_memld(cmll_sub(10, ctx), tmp0); |
| 2020 |
vpshufd128_0x1b(tmp0, x6); |
| 2021 |
vmovdqu128_memld(cmll_sub(8, ctx), tmp0); |
| 2022 |
vpshufd128_0x1b(tmp0, x7); |
| 2023 |
|
| 2024 |
vpxor128(x15, x0, x0); |
| 2025 |
vpxor128(x15, x1, x1); |
| 2026 |
vpxor128(x15, x2, x2); |
| 2027 |
|
| 2028 |
/* subl(33) ^= subr(33) & ~subr(24); */ |
| 2029 |
vpandn128(x15, x3, x14); |
| 2030 |
vpslldq128(4, x14, x14); |
| 2031 |
vpxor128(x14, x15, x15); |
| 2032 |
/* dw = subl(33) & subl(24), subr(33) ^= CAMELLIA_RL1(dw); */ |
| 2033 |
vpand128(x15, x3, x14); |
| 2034 |
vpslld128(1, x14, x13); |
| 2035 |
vpsrld128(31, x14, x14); |
| 2036 |
vpaddb128(x13, x14, x14); |
| 2037 |
vpsrldq128(12, x14, x14); |
| 2038 |
vpslldq128(8, x14, x14); |
| 2039 |
vpxor128(x14, x15, x15); |
| 2040 |
|
| 2041 |
vpxor128(x15, x4, x4); |
| 2042 |
vpxor128(x15, x5, x5); |
| 2043 |
vpxor128(x15, x6, x6); |
| 2044 |
|
| 2045 |
vpshufd128_0x1b(x0, x0); |
| 2046 |
vpshufd128_0x1b(x1, x1); |
| 2047 |
vpshufd128_0x1b(x2, x2); |
| 2048 |
vpshufd128_0x1b(x4, x4); |
| 2049 |
vpshufd128_0x1b(x5, x5); |
| 2050 |
vpshufd128_0x1b(x6, x6); |
| 2051 |
|
| 2052 |
vmovdqu128_memst(x0, cmll_sub(22, ctx)); |
| 2053 |
vmovdqu128_memst(x1, cmll_sub(20, ctx)); |
| 2054 |
vmovdqu128_memst(x2, cmll_sub(18, ctx)); |
| 2055 |
vmovdqu128_memst(x4, cmll_sub(14, ctx)); |
| 2056 |
vmovdqu128_memst(x5, cmll_sub(12, ctx)); |
| 2057 |
vmovdqu128_memst(x6, cmll_sub(10, ctx)); |
| 2058 |
|
| 2059 |
vmovdqu128_memld(cmll_sub(6, ctx), tmp0); |
| 2060 |
vpshufd128_0x1b(tmp0, x6); |
| 2061 |
vmovdqu128_memld(cmll_sub(4, ctx), tmp0); |
| 2062 |
vpshufd128_0x1b(tmp0, x4); |
| 2063 |
vmovdqu128_memld(cmll_sub(2, ctx), tmp0); |
| 2064 |
vpshufd128_0x1b(tmp0, x2); |
| 2065 |
vmovdqu128_memld(cmll_sub(0, ctx), tmp0); |
| 2066 |
vpshufd128_0x1b(tmp0, x0); |
| 2067 |
|
| 2068 |
/* subl(33) ^= subr(33) & ~subr(24); */ |
| 2069 |
vpandn128(x15, x7, x14); |
| 2070 |
vpslldq128(4, x14, x14); |
| 2071 |
vpxor128(x14, x15, x15); |
| 2072 |
/* dw = subl(33) & subl(24), subr(33) ^= CAMELLIA_RL1(dw); */ |
| 2073 |
vpand128(x15, x7, x14); |
| 2074 |
vpslld128(1, x14, x13); |
| 2075 |
vpsrld128(31, x14, x14); |
| 2076 |
vpaddb128(x13, x14, x14); |
| 2077 |
vpsrldq128(12, x14, x14); |
| 2078 |
vpslldq128(8, x14, x14); |
| 2079 |
vpxor128(x14, x15, x15); |
| 2080 |
|
| 2081 |
vpxor128(x15, x6, x6); |
| 2082 |
vpxor128(x15, x4, x4); |
| 2083 |
vpxor128(x15, x2, x2); |
| 2084 |
vpxor128(x15, x0, x0); |
| 2085 |
|
| 2086 |
vpshufd128_0x1b(x6, x6); |
| 2087 |
vpshufd128_0x1b(x4, x4); |
| 2088 |
vpshufd128_0x1b(x2, x2); |
| 2089 |
vpshufd128_0x1b(x0, x0); |
| 2090 |
|
| 2091 |
vpsrldq128(8, x2, x3); |
| 2092 |
vpsrldq128(8, x4, x5); |
| 2093 |
vpsrldq128(8, x6, x7); |
| 2094 |
|
| 2095 |
/* |
| 2096 |
* key XOR is end of F-function. |
| 2097 |
*/ |
| 2098 |
vpxor128(x2, x0, x0); |
| 2099 |
vpxor128(x4, x2, x2); |
| 2100 |
|
| 2101 |
vmovq128_memst(x0, cmll_sub(0, ctx)); |
| 2102 |
vmovq128_memst(x3, cmll_sub(2, ctx)); |
| 2103 |
vpxor128(x5, x3, x3); |
| 2104 |
vpxor128(x6, x4, x4); |
| 2105 |
vpxor128(x7, x5, x5); |
| 2106 |
vmovq128_memst(x2, cmll_sub(3, ctx)); |
| 2107 |
vmovq128_memst(x3, cmll_sub(4, ctx)); |
| 2108 |
vmovq128_memst(x4, cmll_sub(5, ctx)); |
| 2109 |
vmovq128_memst(x5, cmll_sub(6, ctx)); |
| 2110 |
|
| 2111 |
vmovq128_amemld(cmll_sub(7, ctx), x7); |
| 2112 |
vmovq128_amemld(cmll_sub(8, ctx), x8); |
| 2113 |
vmovq128_amemld(cmll_sub(9, ctx), x9); |
| 2114 |
vmovq128_amemld(cmll_sub(10, ctx), x10); |
| 2115 |
/* tl = subl(10) ^ (subr(10) & ~subr(8)); */ |
| 2116 |
vpandn128(x10, x8, x15); |
| 2117 |
vpsrldq128(4, x15, x15); |
| 2118 |
vpxor128(x15, x10, x0); |
| 2119 |
/* dw = tl & subl(8), tr = subr(10) ^ CAMELLIA_RL1(dw); */ |
| 2120 |
vpand128(x8, x0, x15); |
| 2121 |
vpslld128(1, x15, x14); |
| 2122 |
vpsrld128(31, x15, x15); |
| 2123 |
vpaddb128(x14, x15, x15); |
| 2124 |
vpslldq128(12, x15, x15); |
| 2125 |
vpsrldq128(8, x15, x15); |
| 2126 |
vpxor128(x15, x0, x0); |
| 2127 |
|
| 2128 |
vpxor128(x0, x6, x6); |
| 2129 |
vmovq128_memst(x6, cmll_sub(7, ctx)); |
| 2130 |
|
| 2131 |
vmovq128_amemld(cmll_sub(11, ctx), x11); |
| 2132 |
vmovq128_amemld(cmll_sub(12, ctx), x12); |
| 2133 |
vmovq128_amemld(cmll_sub(13, ctx), x13); |
| 2134 |
vmovq128_amemld(cmll_sub(14, ctx), x14); |
| 2135 |
vmovq128_amemld(cmll_sub(15, ctx), x15); |
| 2136 |
/* tl = subl(7) ^ (subr(7) & ~subr(9)); */ |
| 2137 |
vpandn128(x7, x9, x1); |
| 2138 |
vpsrldq128(4, x1, x1); |
| 2139 |
vpxor128(x1, x7, x0); |
| 2140 |
/* dw = tl & subl(9), tr = subr(7) ^ CAMELLIA_RL1(dw); */ |
| 2141 |
vpand128(x9, x0, x1); |
| 2142 |
vpslld128(1, x1, x2); |
| 2143 |
vpsrld128(31, x1, x1); |
| 2144 |
vpaddb128(x2, x1, x1); |
| 2145 |
vpslldq128(12, x1, x1); |
| 2146 |
vpsrldq128(8, x1, x1); |
| 2147 |
vpxor128(x1, x0, x0); |
| 2148 |
|
| 2149 |
vpxor128(x11, x0, x0); |
| 2150 |
vpxor128(x12, x10, x10); |
| 2151 |
vpxor128(x13, x11, x11); |
| 2152 |
vpxor128(x14, x12, x12); |
| 2153 |
vpxor128(x15, x13, x13); |
| 2154 |
vmovq128_memst(x0, cmll_sub(10, ctx)); |
| 2155 |
vmovq128_memst(x10, cmll_sub(11, ctx)); |
| 2156 |
vmovq128_memst(x11, cmll_sub(12, ctx)); |
| 2157 |
vmovq128_memst(x12, cmll_sub(13, ctx)); |
| 2158 |
vmovq128_memst(x13, cmll_sub(14, ctx)); |
| 2159 |
|
| 2160 |
vmovq128_amemld(cmll_sub(16, ctx), x6); |
| 2161 |
vmovq128_amemld(cmll_sub(17, ctx), x7); |
| 2162 |
vmovq128_amemld(cmll_sub(18, ctx), x8); |
| 2163 |
vmovq128_amemld(cmll_sub(19, ctx), x9); |
| 2164 |
vmovq128_amemld(cmll_sub(20, ctx), x10); |
| 2165 |
/* tl = subl(18) ^ (subr(18) & ~subr(16)); */ |
| 2166 |
vpandn128(x8, x6, x1); |
| 2167 |
vpsrldq128(4, x1, x1); |
| 2168 |
vpxor128(x1, x8, x0); |
| 2169 |
/* dw = tl & subl(16), tr = subr(18) ^ CAMELLIA_RL1(dw); */ |
| 2170 |
vpand128(x6, x0, x1); |
| 2171 |
vpslld128(1, x1, x2); |
| 2172 |
vpsrld128(31, x1, x1); |
| 2173 |
vpaddb128(x2, x1, x1); |
| 2174 |
vpslldq128(12, x1, x1); |
| 2175 |
vpsrldq128(8, x1, x1); |
| 2176 |
vpxor128(x1, x0, x0); |
| 2177 |
|
| 2178 |
vpxor128(x14, x0, x0); |
| 2179 |
vmovq128_memst(x0, cmll_sub(15, ctx)); |
| 2180 |
|
| 2181 |
/* tl = subl(15) ^ (subr(15) & ~subr(17)); */ |
| 2182 |
vpandn128(x15, x7, x1); |
| 2183 |
vpsrldq128(4, x1, x1); |
| 2184 |
vpxor128(x1, x15, x0); |
| 2185 |
/* dw = tl & subl(17), tr = subr(15) ^ CAMELLIA_RL1(dw); */ |
| 2186 |
vpand128(x7, x0, x1); |
| 2187 |
vpslld128(1, x1, x2); |
| 2188 |
vpsrld128(31, x1, x1); |
| 2189 |
vpaddb128(x2, x1, x1); |
| 2190 |
vpslldq128(12, x1, x1); |
| 2191 |
vpsrldq128(8, x1, x1); |
| 2192 |
vpxor128(x1, x0, x0); |
| 2193 |
|
| 2194 |
vmovq128_amemld(cmll_sub(21, ctx), x1); |
| 2195 |
vmovq128_amemld(cmll_sub(22, ctx), x2); |
| 2196 |
vmovq128_amemld(cmll_sub(23, ctx), x3); |
| 2197 |
vmovq128_amemld(cmll_sub(24, ctx), x4); |
| 2198 |
|
| 2199 |
vpxor128(x9, x0, x0); |
| 2200 |
vpxor128(x10, x8, x8); |
| 2201 |
vpxor128(x1, x9, x9); |
| 2202 |
vpxor128(x2, x10, x10); |
| 2203 |
vpxor128(x3, x1, x1); |
| 2204 |
|
| 2205 |
vmovq128_memst(x0, cmll_sub(18, ctx)); |
| 2206 |
vmovq128_memst(x8, cmll_sub(19, ctx)); |
| 2207 |
vmovq128_memst(x9, cmll_sub(20, ctx)); |
| 2208 |
vmovq128_memst(x10, cmll_sub(21, ctx)); |
| 2209 |
vmovq128_memst(x1, cmll_sub(22, ctx)); |
| 2210 |
|
| 2211 |
vmovq128_amemld(cmll_sub(25, ctx), x5); |
| 2212 |
vmovq128_amemld(cmll_sub(26, ctx), x6); |
| 2213 |
vmovq128_amemld(cmll_sub(27, ctx), x7); |
| 2214 |
vmovq128_amemld(cmll_sub(28, ctx), x8); |
| 2215 |
vmovq128_amemld(cmll_sub(29, ctx), x9); |
| 2216 |
vmovq128_amemld(cmll_sub(30, ctx), x10); |
| 2217 |
vmovq128_amemld(cmll_sub(31, ctx), x11); |
| 2218 |
vmovq128_amemld(cmll_sub(32, ctx), x12); |
| 2219 |
|
| 2220 |
/* tl = subl(26) ^ (subr(26) & ~subr(24)); */ |
| 2221 |
vpandn128(x6, x4, x15); |
| 2222 |
vpsrldq128(4, x15, x15); |
| 2223 |
vpxor128(x15, x6, x0); |
| 2224 |
/* dw = tl & subl(26), tr = subr(24) ^ CAMELLIA_RL1(dw); */ |
| 2225 |
vpand128(x4, x0, x15); |
| 2226 |
vpslld128(1, x15, x14); |
| 2227 |
vpsrld128(31, x15, x15); |
| 2228 |
vpaddb128(x14, x15, x15); |
| 2229 |
vpslldq128(12, x15, x15); |
| 2230 |
vpsrldq128(8, x15, x15); |
| 2231 |
vpxor128(x15, x0, x0); |
| 2232 |
|
| 2233 |
vpxor128(x0, x2, x2); |
| 2234 |
vmovq128_memst(x2, cmll_sub(23, ctx)); |
| 2235 |
|
| 2236 |
/* tl = subl(23) ^ (subr(23) & ~subr(25)); */ |
| 2237 |
vpandn128(x3, x5, x15); |
| 2238 |
vpsrldq128(4, x15, x15); |
| 2239 |
vpxor128(x15, x3, x0); |
| 2240 |
/* dw = tl & subl(26), tr = subr(24) ^ CAMELLIA_RL1(dw); */ |
| 2241 |
vpand128(x5, x0, x15); |
| 2242 |
vpslld128(1, x15, x14); |
| 2243 |
vpsrld128(31, x15, x15); |
| 2244 |
vpaddb128(x14, x15, x15); |
| 2245 |
vpslldq128(12, x15, x15); |
| 2246 |
vpsrldq128(8, x15, x15); |
| 2247 |
vpxor128(x15, x0, x0); |
| 2248 |
|
| 2249 |
vpxor128(x7, x0, x0); |
| 2250 |
vpxor128(x8, x6, x6); |
| 2251 |
vpxor128(x9, x7, x7); |
| 2252 |
vpxor128(x10, x8, x8); |
| 2253 |
vpxor128(x11, x9, x9); |
| 2254 |
vpxor128(x12, x11, x11); |
| 2255 |
|
| 2256 |
vmovq128_memst(x0, cmll_sub(26, ctx)); |
| 2257 |
vmovq128_memst(x6, cmll_sub(27, ctx)); |
| 2258 |
vmovq128_memst(x7, cmll_sub(28, ctx)); |
| 2259 |
vmovq128_memst(x8, cmll_sub(29, ctx)); |
| 2260 |
vmovq128_memst(x9, cmll_sub(30, ctx)); |
| 2261 |
vmovq128_memst(x10, cmll_sub(31, ctx)); |
| 2262 |
vmovq128_memst(x11, cmll_sub(32, ctx)); |
| 2263 |
|
| 2264 |
#undef KL128 |
| 2265 |
#undef KR128 |
| 2266 |
#undef KA128 |
| 2267 |
#undef KB128 |
| 2268 |
|
| 2269 |
/* kw2 and kw4 are unused now. */ |
| 2270 |
load_zero(tmp0); |
| 2271 |
vmovq128_memst(tmp0, cmll_sub(1, ctx)); |
| 2272 |
vmovq128_memst(tmp0, cmll_sub(33, ctx)); |
| 2273 |
|
| 2274 |
clear_vec_regs(); |
| 2275 |
} |
| 2276 |
|
| 2277 |
void ASM_FUNC_ATTR_NOINLINE |
| 2278 |
FUNC_KEY_SETUP(void *key_table, const void *vkey, unsigned int keylen) |
| 2279 |
{ |
| 2280 |
const char *key = vkey; |
| 2281 |
|
| 2282 |
/* input: |
| 2283 |
* key_table: subkey storage at key_table(CTX) |
| 2284 |
* key_length_bits: output key length as number of bits |
| 2285 |
* key: input key buffer |
| 2286 |
* keylen: key length in bytes |
| 2287 |
*/ |
| 2288 |
|
| 2289 |
__m128i x0, x1, x2; |
| 2290 |
|
| 2291 |
switch (keylen) |
| 2292 |
{ |
| 2293 |
default: |
| 2294 |
return; /* Unsupported key length! */ |
| 2295 |
|
| 2296 |
case 16: |
| 2297 |
vmovdqu128_memld(key, x0); |
| 2298 |
camellia_setup128(key_table, x0); |
| 2299 |
return; |
| 2300 |
|
| 2301 |
case 24: |
| 2302 |
vmovdqu128_memld(key, x0); |
| 2303 |
vmovq128_amemld((uint64_unaligned_t *)(key + 16), x1); |
| 2304 |
|
| 2305 |
x2[0] = -1; |
| 2306 |
x2[1] = -1; |
| 2307 |
vpxor128(x1, x2, x2); |
| 2308 |
vpslldq128(8, x2, x2); |
| 2309 |
vpor128(x2, x1, x1); |
| 2310 |
break; |
| 2311 |
|
| 2312 |
case 32: |
| 2313 |
vmovdqu128_memld(key, x0); |
| 2314 |
vmovdqu128_memld(key + 16, x1); |
| 2315 |
break; |
| 2316 |
} |
| 2317 |
|
| 2318 |
camellia_setup256(key_table, x0, x1); |
| 2319 |
} |