Skip to content

Commit 963215b

Browse files
committed
crypto: implement ARM AES backend for Shavite512's CompressElement()
1 parent 959c9ee commit 963215b

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,8 @@ crypto_libbitcoin_crypto_arm_aes_la_CXXFLAGS += $(ARM_AES_CXXFLAGS)
786786
crypto_libbitcoin_crypto_arm_aes_la_CPPFLAGS += -DENABLE_ARM_AES
787787
crypto_libbitcoin_crypto_arm_aes_la_SOURCES = \
788788
crypto/x11/arm_crypto/aes.cpp \
789-
crypto/x11/arm_crypto/echo.cpp
789+
crypto/x11/arm_crypto/echo.cpp \
790+
crypto/x11/arm_crypto/shavite.cpp
790791

791792
# See explanation for -static in crypto_libbitcoin_crypto_base_la's LDFLAGS and
792793
# CXXFLAGS above
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2025 The Dash Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#if defined(ENABLE_ARM_AES)
6+
#include <crypto/x11/util/util.hpp>
7+
8+
#include <cstdint>
9+
10+
#include <arm_neon.h>
11+
12+
namespace sapphire {
13+
namespace arm_crypto_shavite {
14+
void CompressElement(uint32_t& l0, uint32_t& l1, uint32_t& l2, uint32_t& l3,
15+
uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3, const uint32_t* rk)
16+
{
17+
// Pack block + XOR with round key 1
18+
uint8x16_t block = util::pack_le(r0, r1, r2, r3);
19+
block = util::Xor(block, vreinterpretq_u8_u32(vld1q_u32(&rk[0])));
20+
// AES round + XOR with round key 2
21+
block = util::Xor(util::aes_round_nk(block), vreinterpretq_u8_u32(vld1q_u32(&rk[4])));
22+
// AES round + XOR with round key 3
23+
block = util::Xor(util::aes_round_nk(block), vreinterpretq_u8_u32(vld1q_u32(&rk[8])));
24+
// AES Round + XOR with round key 4
25+
block = util::Xor(util::aes_round_nk(block), vreinterpretq_u8_u32(vld1q_u32(&rk[12])));
26+
// AES round
27+
block = util::aes_round_nk(block);
28+
// Unpack + XOR with l values
29+
uint32x4_t result = vreinterpretq_u32_u8(block);
30+
l0 ^= vgetq_lane_u32(result, 0);
31+
l1 ^= vgetq_lane_u32(result, 1);
32+
l2 ^= vgetq_lane_u32(result, 2);
33+
l3 ^= vgetq_lane_u32(result, 3);
34+
}
35+
} // namespace arm_crypto_shavite
36+
} // namespace sapphire
37+
38+
#endif // ENABLE_ARM_AES

src/crypto/x11/dispatch.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ void RoundKeyless(uint32_t x0, uint32_t x1, uint32_t x2, uint32_t x3,
4949
namespace arm_crypto_echo {
5050
void FullStateRound(uint64_t W[16][2], uint32_t& k0, uint32_t& k1, uint32_t& k2, uint32_t& k3);
5151
} // namespace arm_crypto_echo
52+
namespace arm_crypto_shavite {
53+
void CompressElement(uint32_t& l0, uint32_t& l1, uint32_t& l2, uint32_t& l3,
54+
uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3, const uint32_t* rk);
55+
} // namespace arm_crypto_shavite
5256
#endif // ENABLE_ARM_AES
5357

5458
#if defined(ENABLE_SSSE3)
@@ -165,6 +169,7 @@ void SapphireAutoDetect()
165169
aes_round = sapphire::arm_crypto_aes::Round;
166170
aes_round_nk = sapphire::arm_crypto_aes::RoundKeyless;
167171
echo_round = sapphire::arm_crypto_echo::FullStateRound;
172+
shavite_c512e = sapphire::arm_crypto_shavite::CompressElement;
168173
}
169174
#endif // ENABLE_ARM_AES
170175
#endif // !DISABLE_OPTIMIZED_SHA256

0 commit comments

Comments
 (0)