Botan 3.14.1
Crypto and TLS for C&
ghash_vperm.cpp
Go to the documentation of this file.
1/*
2* (C) 2017 Jack Lloyd
3* (C) 2025 polarnis
4*
5* Botan is released under the Simplified BSD License (see license.txt)
6*/
7
8#include <botan/internal/ghash.h>
9
10#include <botan/internal/isa_extn.h>
11#include <botan/internal/simd_2x64.h>
12
13namespace Botan {
14
15BOTAN_FN_ISA_SIMD_2X64
16void GHASH::ghash_multiply_vperm(uint8_t x[16], const uint64_t HM[256], const uint8_t input_bytes[], size_t blocks) {
18
19 const auto ones = SIMD_2x64::all_ones();
20
21 for(size_t b = 0; b != blocks; ++b) {
22 const auto M = SIMD_2x64::load_le(input_bytes + b * 16).reverse_all_bytes();
23 X ^= M;
24
25 SIMD_2x64 Z = {};
26
27 for(size_t i = 0; i != 64; i += 2) {
28 const auto HM0 = SIMD_2x64::load_native(HM + 4 * i);
29 const auto HM1 = SIMD_2x64::load_native(HM + 4 * i + 2);
30 const auto HM2 = SIMD_2x64::load_native(HM + 4 * i + 4);
31 const auto HM3 = SIMD_2x64::load_native(HM + 4 * i + 6);
32
33 const auto XMASK1 = X.shr<63>() + ones;
34 X = X.shl<1>();
35 const auto XMASK2 = X.shr<63>() + ones;
36 X = X.shl<1>();
37
38 Z ^= SIMD_2x64::interleave_high(XMASK1, XMASK1).andc(HM0);
39 Z ^= SIMD_2x64::interleave_low(XMASK1, XMASK1).andc(HM1);
40 Z ^= SIMD_2x64::interleave_high(XMASK2, XMASK2).andc(HM2);
41 Z ^= SIMD_2x64::interleave_low(XMASK2, XMASK2).andc(HM3);
42 }
43
44 X = Z.swap_lanes();
45 }
46
47 X.reverse_all_bytes().store_le(x);
48}
49
50} // namespace Botan
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 load_native(const void *in)
Definition simd_2x64.h:112
SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 reverse_all_bytes() const
Definition simd_2x64.h:174
SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 swap_lanes() const
Definition simd_2x64.h:161
SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 andc(const SIMD_2x64 &other) const noexcept
Definition simd_2x64.h:278
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 all_ones()
Definition simd_2x64.h:84
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 load_le(const void *in)
Definition simd_2x64.h:124
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 interleave_high(const SIMD_2x64 &a, const SIMD_2x64 &b)
Definition simd_2x64.h:428
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 interleave_low(const SIMD_2x64 &a, const SIMD_2x64 &b)
Definition simd_2x64.h:415