Botan 3.7.1
Crypto and TLS for C&
shacal2_arvm8.cpp
Go to the documentation of this file.
1/*
2* (C) 2020 Jack Lloyd
3*
4* Botan is released under the Simplified BSD License (see license.txt)
5*/
6
7#include <botan/internal/shacal2.h>
8
9#include <botan/compiler.h>
10#include <arm_neon.h>
11
12namespace Botan {
13
14/*
15Only encryption is supported since the inverse round function would
16require a different instruction
17*/
18BOTAN_FUNC_ISA("+crypto+sha2")
19void SHACAL2::armv8_encrypt_blocks(const uint8_t in[], uint8_t out[], size_t blocks) const {
20 const uint32_t* input32 = reinterpret_cast<const uint32_t*>(in);
21 uint32_t* output32 = reinterpret_cast<uint32_t*>(out);
22
23 while(blocks >= 2) {
24 uint32x4_t B0_0 = vld1q_u32(input32 + 0);
25 uint32x4_t B0_1 = vld1q_u32(input32 + 4);
26 uint32x4_t B1_0 = vld1q_u32(input32 + 8);
27 uint32x4_t B1_1 = vld1q_u32(input32 + 12);
28
29 B0_0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B0_0)));
30 B0_1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B0_1)));
31 B1_0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B1_0)));
32 B1_1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B1_1)));
33
34 for(size_t i = 0; i != 8; ++i) {
35 const auto RK0 = vld1q_u32(&m_RK[8 * i]);
36 const auto RK1 = vld1q_u32(&m_RK[8 * i + 4]);
37
38 const auto T0_0 = vsha256hq_u32(B0_0, B0_1, RK0);
39 const auto T0_1 = vsha256h2q_u32(B0_1, B0_0, RK0);
40 const auto T1_0 = vsha256hq_u32(B1_0, B1_1, RK0);
41 const auto T1_1 = vsha256h2q_u32(B1_1, B1_0, RK0);
42
43 B0_0 = vsha256hq_u32(T0_0, T0_1, RK1);
44 B0_1 = vsha256h2q_u32(T0_1, T0_0, RK1);
45 B1_0 = vsha256hq_u32(T1_0, T1_1, RK1);
46 B1_1 = vsha256h2q_u32(T1_1, T1_0, RK1);
47 }
48
49 B0_0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B0_0)));
50 B0_1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B0_1)));
51 B1_0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B1_0)));
52 B1_1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B1_1)));
53
54 vst1q_u32(&output32[0], B0_0);
55 vst1q_u32(&output32[4], B0_1);
56 vst1q_u32(&output32[8], B1_0);
57 vst1q_u32(&output32[12], B1_1);
58
59 blocks -= 2;
60 input32 += 16;
61 output32 += 16;
62 }
63
64 while(blocks > 0) {
65 uint32x4_t B0 = vld1q_u32(input32 + 0);
66 uint32x4_t B1 = vld1q_u32(input32 + 4);
67
68 B0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B0)));
69 B1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B1)));
70
71 for(size_t i = 0; i != 8; ++i) {
72 const auto RK0 = vld1q_u32(&m_RK[8 * i]);
73 const auto RK1 = vld1q_u32(&m_RK[8 * i + 4]);
74
75 const auto T0 = vsha256hq_u32(B0, B1, RK0);
76 const auto T1 = vsha256h2q_u32(B1, B0, RK0);
77
78 B0 = vsha256hq_u32(T0, T1, RK1);
79 B1 = vsha256h2q_u32(T1, T0, RK1);
80 }
81
82 B0 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B0)));
83 B1 = vreinterpretq_u32_u8(vrev32q_u8(vreinterpretq_u8_u32(B1)));
84
85 vst1q_u32(&output32[0], B0);
86 vst1q_u32(&output32[4], B1);
87
88 blocks--;
89 input32 += 8;
90 output32 += 8;
91 }
92}
93
94} // namespace Botan
#define BOTAN_FUNC_ISA(isa)
Definition compiler.h:42