Skip to content

Commit

Permalink
aes ARM support
Browse files Browse the repository at this point in the history
  • Loading branch information
ladnir committed Oct 25, 2024
1 parent 40bdf00 commit 512361f
Show file tree
Hide file tree
Showing 10 changed files with 1,284 additions and 1,134 deletions.
16 changes: 15 additions & 1 deletion cmake/cryptoToolsBuildOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ if(DEFINED OC_PIC)
unset(OC_PIC CACHE)
endif()

if(CMAKE_SYSTEM_PROCESSOR MATCHES "arm")
# Code for ARM architecture
message(STATUS "Building for ARM")
set(ENABLE_ARM_AES_DEFAULT true)
set(ENABLE_SSE_DEFAULT false)
else()
# Code for other architectures
message(STATUS "Not building for x86-64")
set(ENABLE_ARM_AES_DEFAULT false)
set(ENABLE_SSE_DEFAULT true)
endif()



#############################################
# CONFIGURE #
Expand All @@ -28,7 +41,8 @@ option(ENABLE_SODIUM "use libsodium" OFF)
option(ENABLE_CIRCUITS "compile the circuit module" OFF)
option(ENABLE_NET_LOG "compile with network logging" OFF)
option(ENABLE_WOLFSSL "compiler with WolfSSL enabled" OFF)
option(ENABLE_SSE "compile with SSE instructions" ON)
option(ENABLE_ARM_AES "compile with ARM AES instructions" ${ENABLE_ARM_AES_DEFAULT})
option(ENABLE_SSE "compile with SSE instructions" ${ENABLE_SSE_DEFAULT})
option(ENABLE_AVX "compile with AVX instructions" ${ENABLE_SSE})
option(ENABLE_BOOST "compile with BOOST networking integration" OFF)
option(ENABLE_OPENSSL "compile with OpenSSL networking integration" OFF)
Expand Down
7 changes: 6 additions & 1 deletion cryptoTools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ else()
if(ENABLE_AVX)
target_compile_options(cryptoTools PUBLIC -mavx2)
endif()

if(ENABLE_ARM_AES)
if(NOT DEFINED ARM_ARCHITECTURE)
set(ARM_ARCHITECTURE native)
endif()
target_compile_options(cryptoTools PUBLIC -march=${ARM_ARCHITECTURE}+crypto)
endif()
if(ENABLE_PIC)
target_compile_options(cryptoTools PUBLIC -fPIC)
endif()
Expand Down
4 changes: 2 additions & 2 deletions cryptoTools/Circuit/BetaCircuit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ namespace osuCrypto

auto levelRemIter = mLevelCounts.begin();
auto curLevelRem = mLevelCounts.size() ? *levelRemIter++ : u64(-1);
u64 level = 0;
//u64 level = 0;

for (u64 i = 0; i < mGates.size(); ++i)
{
Expand Down Expand Up @@ -468,7 +468,7 @@ namespace osuCrypto
{
std::fill(outOfDate.begin(), outOfDate.end(), 0);
curLevelRem = *levelRemIter++;
++level;
//++level;
}

}
Expand Down
2 changes: 1 addition & 1 deletion cryptoTools/Circuit/MxCircuitLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace osuCrypto


BVector P(sSize), G(sSize - 1);
Bit tempWire;
//Bit tempWire;
//auto a1 = signExtendResize(a1_, sSize, it);
//auto a2 = signExtendResize(a2_, sSize, it);;

Expand Down
19 changes: 19 additions & 0 deletions cryptoTools/Common/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,23 @@
#include <wmmintrin.h>
#endif

#ifdef ENABLE_ARM_AES
#if defined(__arm__) || defined(__aarch32__) || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM) || defined(_M_ARM64)
# if defined(__GNUC__)
# include <stdint.h>
# endif
# if defined(__ARM_NEON) || defined(_MSC_VER)
# include <arm_neon.h>
# endif
/* GCC and LLVM Clang, but not Apple Clang */
# if defined(__GNUC__) && !defined(__apple_build_version__)
# if defined(__ARM_ACLE) || defined(__ARM_FEATURE_CRYPTO)
# include <arm_acle.h>
# endif
# endif
#endif /* ARM Headers */
#endif

// OC_FORCEINLINE ---------------------------------------------//
// Macro to use in place of 'inline' to force a function to be inline
#if !defined(OC_FORCEINLINE)
Expand All @@ -36,6 +53,8 @@ namespace osuCrypto
{
#ifdef OC_ENABLE_SSE2
__m128i mData;
#elif defined(ENABLE_ARM_AES)
uint8x16_t mData;
#else
std::uint64_t mData[2];
#endif
Expand Down
11 changes: 8 additions & 3 deletions cryptoTools/Common/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,17 @@
// enable integration with boost for networking.
#cmakedefine ENABLE_BOOST @ENABLE_BOOST@

// enable the use of ARM AES instructions.
#cmakedefine ENABLE_ARM_AES @ENABLE_ARM_AES@

// enable the use of intel SSE instructions.
#cmakedefine ENABLE_SSE @ENABLE_SSE@

// enable the use of intel AVX instructions.
#cmakedefine ENABLE_AVX @ENABLE_AVX@

// enable the use of the portable AES implementation.
// #cmakedefine ENABLE_PORTABLE_AES @ENABLE_PORTABLE_AES@
#cmakedefine ENABLE_PORTABLE_AES @ENABLE_PORTABLE_AES@

#if (defined(_MSC_VER) || defined(__SSE2__)) && defined(ENABLE_SSE)
#define ENABLE_SSE_BLAKE2 ON
Expand All @@ -52,8 +55,10 @@

#if (defined(_MSC_VER) || defined(__AES__)) && defined(ENABLE_SSE)
#define OC_ENABLE_AESNI ON
#else
#define OC_ENABLE_PORTABLE_AES ON
#endif

#if defined(ENABLE_PORTABLE_AES)
#define OC_ENABLE_PORTABLE_AES ON
#endif

#if (defined(_MSC_VER) || defined(__AVX2__)) && defined(ENABLE_AVX)
Expand Down
Loading

0 comments on commit 512361f

Please sign in to comment.