Botan 3.11.0
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* HM_mm = reinterpret_cast<const SIMD_2x64::native_simd_type*>(HM);
20 const auto ones = SIMD_2x64::all_ones();
21
22 for(size_t b = 0; b != blocks; ++b) {
23 const auto M = SIMD_2x64::load_le(input_bytes + b * 16).reverse_all_bytes();
24 X ^= M;
25
26 SIMD_2x64 Z = {};
27
28 for(size_t i = 0; i != 64; i += 2) {
29 const auto HM0 = SIMD_2x64::load_le(HM_mm + 2 * i);
30 const auto HM1 = SIMD_2x64::load_le(HM_mm + 2 * i + 1);
31 const auto HM2 = SIMD_2x64::load_le(HM_mm + 2 * i + 2);
32 const auto HM3 = SIMD_2x64::load_le(HM_mm + 2 * i + 3);
33
34 const auto XMASK1 = X.shr<63>() + ones;
35 X = X.shl<1>();
36 const auto XMASK2 = X.shr<63>() + ones;
37 X = X.shl<1>();
38
39 Z ^= SIMD_2x64::interleave_high(XMASK1, XMASK1).andc(HM0);
40 Z ^= SIMD_2x64::interleave_low(XMASK1, XMASK1).andc(HM1);
41 Z ^= SIMD_2x64::interleave_high(XMASK2, XMASK2).andc(HM2);
42 Z ^= SIMD_2x64::interleave_low(XMASK2, XMASK2).andc(HM3);
43 }
44
45 X = Z.swap_lanes();
46 }
47
48 X.reverse_all_bytes().store_le(x);
49}
50
51} // namespace Botan
SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 reverse_all_bytes() const
Definition simd_2x64.h:109
SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 swap_lanes() const
Definition simd_2x64.h:101
SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 andc(const SIMD_2x64 &other) const noexcept
Definition simd_2x64.h:164
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 all_ones()
Definition simd_2x64.h:57
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 load_le(const void *in)
Definition simd_2x64.h:74
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 interleave_high(const SIMD_2x64 &a, const SIMD_2x64 &b)
Definition simd_2x64.h:249
static SIMD_2x64 BOTAN_FN_ISA_SIMD_2X64 interleave_low(const SIMD_2x64 &a, const SIMD_2x64 &b)
Definition simd_2x64.h:241