Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sha2: added armv8 and armv8.2 crypto #231

Open
wants to merge 1 commit into
base: 0.1.4-dogebox-pre
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
os: ubuntu-20.04
packages: g++-aarch64-linux-gnu qemu-user-static qemu-user
dep-opts: "CROSS_COMPILE='yes' SPEED=slow V=1"
config-opts: "LIBS='-levent_pthreads' --enable-static --disable-shared --enable-test-passwd"
config-opts: "LIBS='-levent_pthreads' --enable-static --disable-shared --enable-test-passwd --with-armv8-crypto --with-armv82-crypto"
run-tests: true
goal: install
- name: aarch64-android
Expand Down
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ SET(WITH_WALLET TRUE CACHE BOOL "enable wallet")
SET(USE_AVX2 FALSE CACHE BOOL "enable intel avx2")
SET(USE_SSE FALSE CACHE BOOL "enable intel sse")
SET(USE_SSE2 FALSE CACHE BOOL "enable scrypt sse2")
SET(USE_ARMV8 FALSE CACHE BOOL "enable armv8 crypto")
SET(USE_ARMV82 FALSE CACHE BOOL "enable armv8.2 crypto")
SET(USE_TPM2 TRUE CACHE BOOL "enable tpm2")
SET(USE_OPENENCLAVE FALSE CACHE BOOL "enable openenclave")
SET(TEST_PASSWD FALSE CACHE BOOL "enable test password")
Expand Down Expand Up @@ -153,6 +155,37 @@ ENDIF()
IF(USE_SSE2)
ADD_DEFINITIONS(-DUSE_SSE2=1)
ENDIF()
IF(USE_ARMV8)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto")

ADD_DEFINITIONS(-DUSE_ARMV8=1)
ENDIF()
IF(USE_ARMV82)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8.2-a+crypto+sha3")
message(STATUS "Checking whether to build with armv8.2-a crypto")

include(CheckCXXSourceCompiles)
set(CMAKE_REQUIRED_FLAGS "-march=armv8.2-a+crypto+sha3")
check_cxx_source_compiles("
#include <arm_neon.h>
int main() {
uint64x2_t x;
x = vsha512su0q_u64(x, x);
return 0;
}
" ARMV82_CRYPTO_WORKS)

if (ARMV82_CRYPTO_WORKS)
add_definitions(-DUSE_ARMV82)
message(STATUS "yes")
else()
message(WARNING "sha512 missing, using armv8-a crypto without sha512")
string(REPLACE "-march=armv8.2-a+crypto+sha3" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=armv8-a+crypto")
endif()

ADD_DEFINITIONS(-DUSE_ARMV82=1)
ENDIF()
IF(USE_TPM2)
ADD_DEFINITIONS(-DUSE_TPM2=1)
ENDIF()
Expand All @@ -177,6 +210,8 @@ MESSAGE(STATUS "")
MESSAGE(STATUS " USE_AVX2 = ${USE_AVX2}")
MESSAGE(STATUS " USE_SSE = ${USE_SSE}")
MESSAGE(STATUS " USE_SSE2 = ${USE_SSE2}")
MESSAGE(STATUS " USE_ARMV8 = ${USE_ARMV8}")
MESSAGE(STATUS " USE_ARMV82 = ${USE_ARMV82}")
MESSAGE(STATUS " USE_TPM2 = ${USE_TPM2}")
MESSAGE(STATUS " TEST_PASSWD = ${TEST_PASSWD}")
IF(TEST_PASSWD)
Expand Down
37 changes: 37 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,18 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[char foo;]])],
CFLAGS="$saved_CFLAGS"
])

AC_ARG_WITH([armv8-crypto],
[AS_HELP_STRING([--with-armv8-crypto],
[Build with armv8 crypto (default is no)])],
[armv8_crypto=$withval],
[armv8_crypto=no])

AC_ARG_WITH([armv82-crypto],
[AS_HELP_STRING([--with-armv82-crypto],
[Build with armv8.2 crypto sha512 (default is no)])],
[armv82_crypto=$withval],
[armv82_crypto=no])

AC_ARG_ENABLE([intel-avx2],
[AS_HELP_STRING([--enable-intel-avx2],
[Build with Intel AVX2 implementation (default is no)])],
Expand Down Expand Up @@ -203,6 +215,26 @@ if test x$use_scrypt_sse2 = xyes; then
CFLAGS="$CFLAGS -msse4.2"
fi

if test x$armv8_crypto = xyes; then
AC_MSG_CHECKING([whether to build with armv8 crypto])
AC_MSG_RESULT(yes)
AC_DEFINE(USE_ARMV8, 1, [Define this symbol if armv8 crypto works])
CPPFLAGS="$CPPFLAGS -march=armv8-a+crypto"
fi

if test x$armv82_crypto = xyes; then
CPPFLAGS="$CPPFLAGS -march=armv8.2-a+crypto+sha3"
AC_MSG_CHECKING([whether to build with armv8.2-a crypto])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <arm_neon.h>]], [[uint64x2_t x; x = vsha512su0q_u64(x, x);]])],
[AC_DEFINE(USE_ARMV82, 1, [Define this symbol if armv8.2 crypto works])
CFLAGS="$CFLAGS -march=armv8.2-a+crypto+sha3"]
AC_MSG_RESULT(yes),
[AC_MSG_WARN([sha512 missing, using armv8-a crypto without sha512])
AC_DEFINE(USE_ARMV8, 1, [Define this symbol if armv8 crypto works])
CFLAGS=${CFLAGS/"-march=armv8.2-a+crypto+shqa3"/}
CFLAGS+="-march=armv8-a+crypto"])
fi

if test "x$with_bench" = xyes; then
AC_DEFINE_UNQUOTED([WITH_BENCH],[1],[Define to 1 to enable bench compilation])
fi
Expand Down Expand Up @@ -276,6 +308,8 @@ AM_CONDITIONAL([USE_AVX2], [test "x$use_intel_avx2" = "xyes"])
AM_CONDITIONAL([USE_SSE], [test "x$use_intel_sse" = "xyes"])
AM_CONDITIONAL([USE_SSE2], [test "x$use_scrypt_sse2" = "xyes"])
AM_CONDITIONAL([USE_OPENENCLAVE], [test "x$use_openenclave" = "xyes"])
AM_CONDITIONAL([USE_ARMV8], [test "x$armv8_crypto" = "xyes"])
AM_CONDITIONAL([USE_ARMV82], [test "x$armv82_crypto" = "xyes"])
AC_SUBST(LIB_VERSION_CURRENT, _LIB_VERSION_CURRENT)
AC_SUBST(LIB_VERSION_REVISION, _LIB_VERSION_REVISION)
AC_SUBST(LIB_VERSION_AGE, _LIB_VERSION_AGE)
Expand All @@ -298,6 +332,9 @@ echo
echo " Intel AVX2 = $use_intel_avx2"
echo " Intel SSE = $use_intel_sse"
echo " SSE2 Scrypt = $use_scrypt_sse2"
echo " ARMv8 crypto = $armv8_crypto"
echo " ARMv8.2 crypto = $armv82_crypto"
echo
echo " test password = $test_passwd"
if test "x$test_passwd" = xyes; then
echo " $PASSWD_STR"
Expand Down
Loading
Loading