From c0c4007c64775898e35d784bb7183dee67b401f3 Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Wed, 25 Sep 2024 10:16:41 +0300 Subject: [PATCH 1/7] build the static libcc.a library as in upstream komodo codebae build marmara for macos: - remove cpath, gcc in .github/workflows/marmara_mac_ci.yml - remove installing gcc from README.md - deleted darwin.host.mk.patch - deleted darwin.mk.patch - change cc/g++ -> clang/clang++ default in depends/builders/darwin.mk and in depends/hosts/darwin.mk - fix bdb build on native darwin in depends/packages/bdb.mk - fix libcurl linkage under darwin and disable HTTP/2, librtmp and brotli in depends/packages/libcurl.mk - fix MACOSX_DEPLOYMENT_TARGET in depends/packages/libsodium.mk - remove gcc specific linker flag -static-libgcc in src/Makefile.am - remove -enable-static --disable-shared from scripts in zcutil/build-mac-dtest.sh and zcutil/build-mac.sh - remove gcc related flags from Mac build in zcutil/build-mac-dtest.sh and zcutil/build-mac.sh - remove -Wno-builtin-declaration-mismatch for Mac in zcutil/build-mac-dtest.sh and zcutil/build-mac.sh - remove linker options -Wl,-undefined -Wl,dynamic_lookup in zcutil/build-mac-dtest.sh and zcutil/build-mac.sh --- .github/workflows/marmara_mac_ci.yml | 40 ++++--- README.md | 2 +- darwin.host.mk.patch | 21 ---- darwin.mk.patch | 40 ------- depends/builders/darwin.mk | 11 +- depends/hosts/darwin.mk | 49 ++++++-- depends/packages/bdb.mk | 8 +- depends/packages/libcurl.mk | 1 + depends/packages/libsodium.mk | 2 +- src/Makefile.am | 173 +++++++++++++++------------ zcutil/build-mac-dtest.sh | 46 ++++--- zcutil/build-mac.sh | 53 ++++---- 12 files changed, 214 insertions(+), 232 deletions(-) delete mode 100644 darwin.host.mk.patch delete mode 100644 darwin.mk.patch diff --git a/.github/workflows/marmara_mac_ci.yml b/.github/workflows/marmara_mac_ci.yml index d32e13facaa..e2c04770bae 100644 --- a/.github/workflows/marmara_mac_ci.yml +++ b/.github/workflows/marmara_mac_ci.yml @@ -10,7 +10,7 @@ jobs: macos-build: name: MacOS Build - runs-on: macos-latest + runs-on: macos-latest-large steps: - uses: actions/checkout@v4 @@ -31,47 +31,49 @@ jobs: - name: Install deps (macOS) run: | brew update - brew upgrade || true brew tap discoteq/discoteq; brew install flock brew install autoconf autogen automake - brew install gcc@8 brew install binutils brew install protobuf brew install coreutils brew install wget brew install python3 - brew install gmp - + + # https://www.jessesquires.com/blog/2020/01/06/selecting-an-xcode-version-on-github-ci/ + # https://github.com/actions/runner-images/issues/2619 (bsdtar issues) + # flag for some CC tests transactions - so DO NOT USE THIS CI ARTIFACTS IN PRODUCTION!!! - name: Build (macOS) run: | - # flag for some CC tests transactions - so DO NOT USE THIS CI ARTIFACTS IN PRODUCTION!!! - export CPATH=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/ ./zcutil/build-mac-dtest.sh -j4 - tar -czvf marmara-macos.tar.gz src/marmarad src/marmara-cli - + gtar -czvf marmara-macos.tar.gz src/marmarad src/marmara-cli src/wallet-utility src/komodo-tx + # env: + # DEVELOPER_DIR: /Applications/Xcode_13.2.1.app/Contents/Developer + - name: Upload marmara-macos.tar.gz as artifact uses: actions/upload-artifact@v4 with: name: marmara-macos - path: ./marmara-macos.tar.gz + path: | + ./marmara-macos.tar.gz - # macos-test-dice-token-reards-faucet-cc: + # macos-test-dice-token-rewards-faucet-cc: + # if: ${{ false }} # name: Test (MacOS/Dice, Token, Faucet, Rewards) # runs-on: macos-latest # needs: macos-build # steps: - # - uses: actions/checkout@v2 + # - uses: actions/checkout@v4 # - name: Install deps (Dice, Token, Faucet, Rewards CC) # run: | - # brew install curl + # brew install python3 curl # python3 -m pip install setuptools wheel # python3 -m pip install slick-bitcoinrpc pytest wget jsonschema # - name: Download komodo-macos.tar.gz - # uses: actions/download-artifact@v1 + # uses: actions/download-artifact@v4 # with: # name: komodo-macos @@ -150,11 +152,11 @@ jobs: # needs: macos-build # steps: - # - uses: actions/checkout@v2 + # - uses: actions/checkout@v4 # - name: Install deps (ChannelsCC) # run: | - # brew install curl + # brew install python3 curl # python3 -m pip install setuptools wheel # python3 -m pip install slick-bitcoinrpc pytest wget jsonschema # - name: Download komodo-macos.tar.gz @@ -183,11 +185,11 @@ jobs: # - name: Install deps (HeirCC) # run: | - # brew install curl + # brew install python3 curl # python3 -m pip install setuptools wheel - # python3 -m pip install slick-bitcoinrpc pytest wget jsonschema + # python3 -m pip install slick-bitcoinrpc pytest wget jsonschemaa # - name: Download komodo-macos.tar.gz - # uses: actions/download-artifact@v1 + # uses: actions/download-artifact@v4 # with: # name: komodo-macos diff --git a/README.md b/README.md index fc47a06196d..5466deb5a3c 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ brew update brew upgrade brew tap discoteq/discoteq; brew install flock brew install autoconf autogen automake -brew update && brew install gcc@8 +brew update brew install binutils brew install protobuf brew install coreutils diff --git a/darwin.host.mk.patch b/darwin.host.mk.patch deleted file mode 100644 index deeb7a81045..00000000000 --- a/darwin.host.mk.patch +++ /dev/null @@ -1,21 +0,0 @@ -*** depends/hosts/darwin.mk 2017-01-03 10:53:52.440371182 +0000 ---- ../../komodo-jl777/depends/hosts/darwin.mk 2017-01-03 09:48:21.650035146 +0000 -*************** -*** 2,9 **** - OSX_SDK_VERSION=10.9 - OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk - LD64_VERSION=241.9 -! darwin_CC=gcc-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -! darwin_CXX=g++-6 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) - - darwin_CFLAGS=-pipe - darwin_CXXFLAGS=$(darwin_CFLAGS) ---- 2,9 ---- - OSX_SDK_VERSION=10.9 - OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk - LD64_VERSION=241.9 -! darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -! darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) - - darwin_CFLAGS=-pipe - darwin_CXXFLAGS=$(darwin_CFLAGS) diff --git a/darwin.mk.patch b/darwin.mk.patch deleted file mode 100644 index fdfd7bc3899..00000000000 --- a/darwin.mk.patch +++ /dev/null @@ -1,40 +0,0 @@ -*** depends/builders/darwin.mk 2017-01-03 10:53:52.440371182 +0000 ---- ../../komodo-jl777/depends/builders/darwin.mk 2017-01-03 09:48:21.646034937 +0000 -*************** -*** 1,5 **** -! build_darwin_CC = gcc-6 -! build_darwin_CXX = g++-6 - build_darwin_AR: = $(shell xcrun -f ar) - build_darwin_RANLIB: = $(shell xcrun -f ranlib) - build_darwin_STRIP: = $(shell xcrun -f strip) ---- 1,5 ---- -! build_darwin_CC: = $(shell xcrun -f clang) -! build_darwin_CXX: = $(shell xcrun -f clang++) - build_darwin_AR: = $(shell xcrun -f ar) - build_darwin_RANLIB: = $(shell xcrun -f ranlib) - build_darwin_STRIP: = $(shell xcrun -f strip) -*************** -*** 7,17 **** - build_darwin_NM: = $(shell xcrun -f nm) - build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) - build_darwin_SHA256SUM = shasum -a 256 -! build_darwin_DOWNLOAD = wget --timeout=$(DOWNLOAD_CONNECT_TIMEOUT) --tries=$(DOWNLOAD_RETRIES) -nv -O - - #darwin host on darwin builder. overrides darwin host preferences. -! darwin_CC= gcc-6 -! darwin_CXX= g++-6 - darwin_AR:=$(shell xcrun -f ar) - darwin_RANLIB:=$(shell xcrun -f ranlib) - darwin_STRIP:=$(shell xcrun -f strip) ---- 7,17 ---- - build_darwin_NM: = $(shell xcrun -f nm) - build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) - build_darwin_SHA256SUM = shasum -a 256 -! build_darwin_DOWNLOAD = curl --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -L -o - - #darwin host on darwin builder. overrides darwin host preferences. -! darwin_CC=$(shell xcrun -f clang) -mmacosx-version-min=$(OSX_MIN_VERSION) -! darwin_CXX:=$(shell xcrun -f clang++) -mmacosx-version-min=$(OSX_MIN_VERSION) - darwin_AR:=$(shell xcrun -f ar) - darwin_RANLIB:=$(shell xcrun -f ranlib) - darwin_STRIP:=$(shell xcrun -f strip) diff --git a/depends/builders/darwin.mk b/depends/builders/darwin.mk index cbbc5a667ab..6b877101327 100644 --- a/depends/builders/darwin.mk +++ b/depends/builders/darwin.mk @@ -1,5 +1,5 @@ -build_darwin_CC = gcc-8 -build_darwin_CXX = g++-8 +build_darwin_CC:=$(shell xcrun -f clang) --sysroot $(shell xcrun --show-sdk-path) +build_darwin_CXX:=$(shell xcrun -f clang++) --sysroot $(shell xcrun --show-sdk-path) build_darwin_AR: = $(shell xcrun -f ar) build_darwin_RANLIB: = $(shell xcrun -f ranlib) build_darwin_STRIP: = $(shell xcrun -f strip) @@ -7,11 +7,11 @@ build_darwin_OTOOL: = $(shell xcrun -f otool) build_darwin_NM: = $(shell xcrun -f nm) build_darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) build_darwin_SHA256SUM = shasum -a 256 -build_darwin_DOWNLOAD = curl --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -L -f -o +build_darwin_DOWNLOAD=curl --location --fail --connect-timeout $(DOWNLOAD_CONNECT_TIMEOUT) --retry $(DOWNLOAD_RETRIES) -o #darwin host on darwin builder. overrides darwin host preferences. -darwin_CC= gcc-8 -darwin_CXX= g++-8 +darwin_CC=$(shell xcrun -f clang) -mmacosx-version-min=$(OSX_MIN_VERSION) -fvisibility=hidden -fvisibility-inlines-hidden --sysroot $(shell xcrun --show-sdk-path) +darwin_CXX:=$(shell xcrun -f clang++) -mmacosx-version-min=$(OSX_MIN_VERSION) -fvisibility=hidden -fvisibility-inlines-hidden -stdlib=libc++ --sysroot $(shell xcrun --show-sdk-path) darwin_AR:=$(shell xcrun -f ar) darwin_RANLIB:=$(shell xcrun -f ranlib) darwin_STRIP:=$(shell xcrun -f strip) @@ -19,4 +19,5 @@ darwin_LIBTOOL:=$(shell xcrun -f libtool) darwin_OTOOL:=$(shell xcrun -f otool) darwin_NM:=$(shell xcrun -f nm) darwin_INSTALL_NAME_TOOL:=$(shell xcrun -f install_name_tool) +darwin_native_binutils= darwin_native_toolchain= diff --git a/depends/hosts/darwin.mk b/depends/hosts/darwin.mk index 7be744aebc0..2fafa535668 100644 --- a/depends/hosts/darwin.mk +++ b/depends/hosts/darwin.mk @@ -1,17 +1,50 @@ -OSX_MIN_VERSION=10.12 -OSX_SDK_VERSION=10.12 -OSX_SDK=$(SDK_PATH)/MacOSX$(OSX_SDK_VERSION).sdk -LD64_VERSION=253.9 -darwin_CC=gcc-8 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -darwin_CXX=g++-8 -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) +OSX_MIN_VERSION=10.15 +OSX_SDK_VERSION=10.15.6 +XCODE_VERSION=12.1 +XCODE_BUILD_ID=12A7403 +LD64_VERSION=609 + +OSX_SDK=$(SDK_PATH)/Xcode-$(XCODE_VERSION)-$(XCODE_BUILD_ID)-extracted-SDK-with-libcxx-headers + +# Flag explanations: +# +# -mlinker-version +# +# Ensures that modern linker features are enabled. See here for more +# details: https://github.com/bitcoin/bitcoin/pull/19407. +# +# -B$(build_prefix)/bin +# +# Explicitly point to our binaries (e.g. cctools) so that they are +# ensured to be found and preferred over other possibilities. +# +# -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1 +# +# Forces clang to use the libc++ headers from our SDK and completely +# forget about the libc++ headers from the standard directories +# +# TODO: Once we start requiring a clang version that has the +# -stdlib++-isystem flag first introduced here: +# https://reviews.llvm.org/D64089, we should use that instead. Read the +# differential summary there for more details. +# +darwin_CC=clang -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin +darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) --sysroot $(OSX_SDK) -stdlib=libc++ -mlinker-version=$(LD64_VERSION) -B$(build_prefix)/bin -nostdinc++ -isystem $(OSX_SDK)/usr/include/c++/v1 darwin_CFLAGS=-pipe darwin_CXXFLAGS=$(darwin_CFLAGS) -darwin_release_CFLAGS=-O1 +darwin_release_CFLAGS=-O2 darwin_release_CXXFLAGS=$(darwin_release_CFLAGS) -darwin_debug_CFLAGS=-O1 +darwin_debug_CFLAGS=-g -O0 darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS) +darwin_native_binutils=native_cctools +ifeq ($(strip $(FORCE_USE_SYSTEM_CLANG)),) darwin_native_toolchain=native_cctools +else +darwin_native_toolchain= +endif + +darwin_cmake_system=Darwin \ No newline at end of file diff --git a/depends/packages/bdb.mk b/depends/packages/bdb.mk index 404d94c5180..385e646b916 100644 --- a/depends/packages/bdb.mk +++ b/depends/packages/bdb.mk @@ -9,7 +9,7 @@ define $(package)_set_vars $(package)_config_opts=--disable-shared --enable-cxx --disable-replication $(package)_config_opts_mingw32=--enable-mingw $(package)_config_opts_linux=--with-pic -$(package)_cxxflags=-std=c++11 +$(package)_cxxflags+=-std=c++11 endef define $(package)_preprocess_cmds @@ -25,7 +25,9 @@ endef ifeq ($(build_os),darwin) define $(package)_preprocess_cmds - sed -i -e "s/WinIoCtl.h/winioctl.h/g" src/dbinc/win_db.h + sed -i -e "s/WinIoCtl.h/winioctl.h/g" src/dbinc/win_db.h && \ + sed -i.old 's/__atomic_compare_exchange\\(/__atomic_compare_exchange_db(/' src/dbinc/atomic.h && \ + sed -i.old 's/atomic_init/atomic_init_db/' src/dbinc/atomic.h src/mp/mp_region.c src/mp/mp_mvcc.c src/mp/mp_fget.c src/mutex/mut_method.c src/mutex/mut_tas.c endef else ifeq ($(host_os),mingw32) define $(package)_preprocess_cmds @@ -39,4 +41,4 @@ endef define $(package)_stage_cmds $(MAKE) DESTDIR=$($(package)_staging_dir) install_lib install_include -endef +endef \ No newline at end of file diff --git a/depends/packages/libcurl.mk b/depends/packages/libcurl.mk index d25f43e1705..1996ad3502f 100644 --- a/depends/packages/libcurl.mk +++ b/depends/packages/libcurl.mk @@ -7,6 +7,7 @@ $(package)_sha256_hash=816e41809c043ff285e8c0f06a75a1fa250211bbfb2dc0a037eeef39f $(package)_config_opts=--with-openssl --disable-shared --enable-static --prefix=$(host_prefix) $(package)_config_opts_linux=--host=x86_64-unknown-linux-gnu $(package)_config_opts_mingw32=--enable-mingw --host=x86_64-w64-mingw32 +$(package)_config_opts_darwin=--without-libidn2 --without-zstd --without-nghttp2 --without-librtmp --without-brotli $(package)_cflags_darwin=-mmacosx-version-min=$(OSX_MIN_VERSION) $(package)_conf_tool=./configure diff --git a/depends/packages/libsodium.mk b/depends/packages/libsodium.mk index 4974edc70d1..fe8b0a4e915 100644 --- a/depends/packages/libsodium.mk +++ b/depends/packages/libsodium.mk @@ -9,7 +9,7 @@ $(package)_config_opts= define $(package)_set_vars $(package)_build_env=DO_NOT_UPDATE_CONFIG_SCRIPTS=1 ifeq ($(build_os),darwin) - $(package)_build_env+=MACOSX_DEPLOYMENT_TARGET="10.11" + $(package)_build_env+=MACOSX_DEPLOYMENT_TARGET="$(OSX_MIN_VERSION)" $(package)_cc=clang $(package)_cxx=clang++ endif diff --git a/src/Makefile.am b/src/Makefile.am index cdb88f73f27..b63e8bf6a96 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,16 +31,17 @@ BITCOIN_INCLUDES += -I$(srcdir)/snark BITCOIN_INCLUDES += -I$(srcdir)/snark/libsnark BITCOIN_INCLUDES += -I$(srcdir)/univalue/include -if TARGET_WINDOWS -LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl -endif -if TARGET_DARWIN -LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl -endif -if TARGET_LINUX -LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl -endif - +# if TARGET_WINDOWS +# LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl +# endif +# if TARGET_DARWIN +# LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl +# endif +# if TARGET_LINUX +# LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl +# endif + +LIBBITCOIN_SERVER=libbitcoin_server.a LIBBITCOIN_WALLET=libbitcoin_wallet.a LIBBITCOIN_COMMON=libbitcoin_common.a LIBBITCOIN_CLI=libbitcoin_cli.a @@ -52,6 +53,7 @@ LIBSECP256K1=secp256k1/libsecp256k1.la LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la LIBSNARK=snark/libsnark.a LIBUNIVALUE=univalue/libunivalue.la +LIBCC=libcc.a LIBZCASH=libzcash.a if ENABLE_ZMQ @@ -95,13 +97,15 @@ $(LIBCRYPTOCONDITIONS): $(wildcard cryptoconditions/src/*) $(wildcard cryptocond # But to build the less dependent modules first, we manually select their order here: EXTRA_LIBRARIES += \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ +# $(LIBVERUS_CRYPTO) \ +# $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_CLI) \ - libzcash.a + $(LIBZCASH) \ + $(LIBCC) + if ENABLE_WALLET BITCOIN_INCLUDES += $(BDB_CPPFLAGS) EXTRA_LIBRARIES += $(LIBBITCOIN_WALLET) @@ -183,9 +187,9 @@ BITCOIN_CORE_H = \ consensus/validation.h \ core_io.h \ core_memusage.h \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ + crypto/haraka.h \ #does marmara use haraka check + crypto/haraka_portable.h \ # removed from komodo + crypto/verus_hash.h \ # removed from komodo, verus related deprecation.h \ hash.h \ httprpc.h \ @@ -290,17 +294,17 @@ libbitcoin_server_a_SOURCES = \ cc/import.cpp \ cc/importgateway.cpp \ cc/CCassetsCore.cpp \ - cc/old/CCassetsCore_v0.cpp \ - cc/CCassetstx.cpp \ - cc/old/CCassetstx_v0.cpp \ + cc/old/CCassetsCore_v0.cpp \ #removed from komodo + cc/CCassetstx.cpp \ #removed from komodo + cc/old/CCassetstx_v0.cpp \ #removed from komodo cc/CCcustom.cpp \ cc/CCtx.cpp \ cc/CCutils.cpp \ - cc/CCvalidation.cpp \ + cc/CCvalidation.cpp \ #removed from komodo cc/CCtokens.cpp \ - cc/old/CCtokens_v0.cpp \ + cc/old/CCtokens_v0.cpp \ #removed from komodo cc/assets.cpp \ - cc/old/assets_v0.cpp \ + cc/old/assets_v0.cpp \ #removed from komodo cc/faucet.cpp \ cc/rewards.cpp \ cc/dice.cpp \ @@ -308,8 +312,8 @@ libbitcoin_server_a_SOURCES = \ cc/fsm.cpp \ cc/heir.cpp \ cc/oracles.cpp \ - cc/prices.cpp \ - cc/pegs.cpp \ + cc/prices.cpp \ #removed from komodo + cc/pegs.cpp \ #removed from komodo cc/marmara.cpp \ cc/marmara_h0.cpp \ cc/payments.cpp \ @@ -317,17 +321,17 @@ libbitcoin_server_a_SOURCES = \ cc/channels.cpp \ cc/auction.cpp \ cc/betprotocol.cpp \ - cc/pricesfeed.cpp \ - cc/priceslibs/cjsonpointer.cpp \ - cc/kogs.cpp \ + cc/pricesfeed.cpp \ #removed from komodo + cc/priceslibs/cjsonpointer.cpp \ #removed from komodo + cc/kogs.cpp \ #removed from komodo chain.cpp \ checkpoints.cpp \ crosschain.cpp \ - crosschain_authority.cpp \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp \ + crosschain_authority.cpp \ #removed from komodo + crypto/haraka.h \ #removed from komodo + crypto/haraka_portable.h \ #removed from komodo + crypto/verus_hash.h \ #removed from komodo + crypto/verus_hash.cpp \ #removed from komodo deprecation.cpp \ httprpc.cpp \ httpserver.cpp \ @@ -353,8 +357,8 @@ libbitcoin_server_a_SOURCES = \ rpc/net.cpp \ rpc/rawtransaction.cpp \ rpc/server.cpp \ - rpc/tokensrpc.cpp \ - rpc/pricesrpc.cpp \ + rpc/tokensrpc.cpp \ #removed from komodo + rpc/pricesrpc.cpp \ #removed from komodo rpc/marmararpc.cpp \ script/serverchecker.cpp \ script/sigcache.cpp \ @@ -411,6 +415,11 @@ libbitcoin_wallet_a_SOURCES = \ $(BITCOIN_CORE_H) \ $(LIBZCASH_H) +# a static library for cryptoconditions +libcc_a_SOURCES = cc/cclib.cpp +libcc_a_CXXFLAGS = -DBUILD_CUSTOMCC -I../secp256k1/include -I../depends/$(shell echo `../depends/config.guess`/include) -I./univalue/include -I./cryptoconditions/include -I./cryptoconditions/src -I./cryptoconditions/src/asn -I. -I./cc +# libcc_a_LDFLAGS = -version-info 0:0:0 + # crypto primitives library crypto_libbitcoin_crypto_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_CONFIG_INCLUDES) crypto_libbitcoin_crypto_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -431,10 +440,10 @@ crypto_libbitcoin_crypto_a_SOURCES = \ crypto/sha256.h \ crypto/sha512.cpp \ crypto/sha512.h \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp + crypto/haraka.h \ # removed from komodo + crypto/haraka_portable.h \ # removed from komodo + crypto/verus_hash.h \ # removed from komodo + crypto/verus_hash.cpp # removed from komodo if EXPERIMENTAL_ASM crypto_libbitcoin_crypto_a_SOURCES += crypto/sha256_sse4.cpp @@ -480,10 +489,10 @@ libbitcoin_common_a_SOURCES = \ consensus/upgrades.cpp \ core_read.cpp \ core_write.cpp \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp \ + crypto/haraka.h \ # removed from komodo + crypto/haraka_portable.h \ # removed from komodo + crypto/verus_hash.h \ # removed from komodo + crypto/verus_hash.cpp \ # removed from komodo hash.cpp \ importcoin.cpp \ key.cpp \ @@ -506,7 +515,7 @@ libbitcoin_common_a_SOURCES = \ script/standard.cpp \ transaction_builder.cpp \ cc/CCtokenutils.cpp \ - cc/old/CCtokenutils_v0.cpp \ + cc/old/CCtokenutils_v0.cpp \ # removed from komodo cc/CCutilbits.cpp \ gmp_i64.c \ $(BITCOIN_CORE_H) \ @@ -570,8 +579,8 @@ marmarad_LDADD = \ $(LIBBITCOIN_ZMQ) \ $(LIBBITCOIN_PROTON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ + $(LIBVERUS_CRYPTO) \ #removed from komodo + $(LIBVERUS_PORTABLE_CRYPTO) \ #removed from komodo $(LIBZCASH) \ $(LIBSNARK) \ $(LIBLEVELDB) \ @@ -593,37 +602,33 @@ marmarad_LDADD += \ $(ZMQ_LIBS) \ $(PROTON_LIBS) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ + $(LIBVERUS_CRYPTO) \ #verus related, removed from komodo + $(LIBVERUS_PORTABLE_CRYPTO) \ #removed from komodo $(LIBZCASH_LIBS) - -if TARGET_DARWIN -marmarad_LDADD += libcc.dylib $(LIBSECP256K1) -endif -if TARGET_WINDOWS -marmarad_LDADD += libcc.dll $(LIBSECP256K1) -endif -if TARGET_LINUX -marmarad_LDADD += libcc.so $(LIBSECP256K1) -endif + $(LIBCC) \ + -lcurl + +# https://github.com/marmarachain/marmara/pull/47#issuecomment-2363865476 commented out explicit reference to libcc.dll +# if TARGET_DARWIN +# marmarad_LDADD += libcc.dylib $(LIBSECP256K1) +# endif +# if TARGET_WINDOWS +# marmarad_LDADD += libcc.dll $(LIBSECP256K1) +# endif +# if TARGET_LINUX +# marmarad_LDADD += libcc.so $(LIBSECP256K1) +# endif if ENABLE_PROTON marmarad_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) endif -# [+] Decker: use static linking for libstdc++.6.dylib, libgomp.1.dylib, libgcc_s.1.dylib -if TARGET_DARWIN -marmarad_LDFLAGS += -static-libgcc -endif - # bitcoin-cli binary # marmara_cli_SOURCES = bitcoin-cli.cpp marmara_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) marmara_cli_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) marmara_cli_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -if TARGET_DARWIN -marmara_cli_LDFLAGS += -static-libgcc -endif + # wallet-utility binary # if ENABLE_WALLET @@ -631,6 +636,10 @@ wallet_utility_SOURCES = wallet-utility.cpp wallet_utility_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) wallet_utility_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) wallet_utility_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) + +if TARGET_WINDOWS +wallet_utility_SOURCES += wallet-utility-res.rc +endif endif if TARGET_WINDOWS @@ -647,8 +656,8 @@ marmara_cli_LDADD = \ $(EVENT_LIBS) \ $(LIBZCASH) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ + $(LIBVERUS_CRYPTO) \ # verus related, removed from komodo + $(LIBVERUS_PORTABLE_CRYPTO) \ # verus related, removed from komodo $(LIBZCASH_LIBS) if ENABLE_WALLET @@ -656,8 +665,8 @@ wallet_utility_LDADD = \ libbitcoin_wallet.a \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ + $(LIBVERUS_CRYPTO) \ # verus related, removed from komodo + $(LIBVERUS_PORTABLE_CRYPTO) \ # verus related, removed from komodo $(LIBSECP256K1) \ $(LIBBITCOIN_UTIL) \ $(BOOST_LIBS) \ @@ -688,8 +697,8 @@ komodo_tx_LDADD = \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ + $(LIBVERUS_CRYPTO) \ # verus related, removed from komodo + $(LIBVERUS_PORTABLE_CRYPTO) \ # verus related, removed from komodo $(LIBZCASH_LIBS) \ $(LIBCRYPTOCONDITIONS) @@ -707,12 +716,12 @@ libzcash_a_SOURCES = \ zcash/prf.cpp \ zcash/util.cpp \ zcash/zip32.cpp \ - zcash/circuit/commitment.tcc \ - zcash/circuit/gadget.tcc \ - zcash/circuit/merkle.tcc \ - zcash/circuit/note.tcc \ - zcash/circuit/prfs.tcc \ - zcash/circuit/utils.tcc + zcash/circuit/commitment.tcc \ #removed from komodo + zcash/circuit/gadget.tcc \ #removed from komodo + zcash/circuit/merkle.tcc \ #removed from komodo + zcash/circuit/note.tcc \ #removed from komodo + zcash/circuit/prfs.tcc \ #removed from komodo + zcash/circuit/utils.tcc #removed from komodo libzcash_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) $(HARDENED_CXXFLAGS) $(HARDENED_LDFLAGS) -pipe $(SAN_LDFLAGS) -O1 -g -Wstack-protector $(SAN_CXXFLAGS) -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES) @@ -770,6 +779,12 @@ clean-local: -$(MAKE) -C cryptoconditions clean rm -f leveldb/*/*.gcno leveldb/helpers/memenv/*.gcno -rm -f config.h + -$(RM) *.a + -$(RM) crypto/*.a + -$(RM) cryptoconditions/.libs/*.a + +clean-all: clean-local + -$(MAKE) -C univalue clean-all .rc.o: @test -f $(WINDRES) @@ -797,6 +812,6 @@ endif if ENABLE_TESTS include Makefile.ktest.include -#include Makefile.test.include -#include Makefile.gtest.include +#include Makefile.test.include #bitcoin tests +#include Makefile.gtest.include #zcash tests endif diff --git a/zcutil/build-mac-dtest.sh b/zcutil/build-mac-dtest.sh index b3cba3b8670..ebdf78e9c8a 100755 --- a/zcutil/build-mac-dtest.sh +++ b/zcutil/build-mac-dtest.sh @@ -1,13 +1,4 @@ #!/bin/bash -export CC=gcc-8 -export CXX=g++-8 -export LIBTOOL=libtool -export AR=ar -export RANLIB=ranlib -export STRIP=strip -export OTOOL=otool -export NM=nm - set -eu -o pipefail if [ "x$*" = 'x--help' ] @@ -18,11 +9,13 @@ Usage: $0 --help Show this help message and exit. -$0 [ --enable-lcov ] [ MAKEARGS... ] - Build Zcash and most of its transitive dependencies from - source. MAKEARGS are applied to both dependencies and Zcash itself. If - --enable-lcov is passed, Zcash is configured to add coverage +$0 [ --enable-lcov ] [ --enable-debug ] [ MAKEARGS... ] + Build Komodo and most of its transitive dependencies from + source. MAKEARGS are applied to both dependencies and Komodo itself. + If --enable-lcov is passed, Komodo is configured to add coverage instrumentation, thus enabling "make cov" to work. + If --enable-debug is passed, Komodo is built with debugging information. It + must be passed after the previous arguments, if present. EOF exit 0 fi @@ -37,22 +30,27 @@ then shift fi +# If --enable-debug is the next argument, enable debugging +DEBUGGING_ARG='' +if [ "x${1:-}" = 'x--enable-debug' ] +then + DEBUG=1 + export DEBUG + DEBUGGING_ARG='--enable-debug' + shift +fi + TRIPLET=`./depends/config.guess` PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 -#BUILD CCLIB - -WD=$PWD -cd src/cc -echo $PWD -./makecustom -cd $WD - ./autogen.sh + CPPFLAGS="-I$PREFIX/include -arch x86_64 -DTESTMODE" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ -CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.4.0_2/include/c++/8.4.0_2/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ -./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" +CXXFLAGS="-arch x86_64 -I$PREFIX/include -fwrapv -fno-strict-aliasing \ +-Wno-deprecated-declarations -Wno-deprecated-builtins -Wno-enum-constexpr-conversion \ +-Wno-unknown-warning-option -Werror -Wno-error=attributes -g" \ +./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" "$DEBUGGING_ARG" -make "$@" V=1 NO_GTEST=1 STATIC=1 +make "$@" NO_GTEST=1 STATIC=1 \ No newline at end of file diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index 4e51e63306a..fc789977dfc 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -1,13 +1,4 @@ #!/bin/bash -export CC=gcc-8 -export CXX=g++-8 -export LIBTOOL=libtool -export AR=ar -export RANLIB=ranlib -export STRIP=strip -export OTOOL=otool -export NM=nm - set -eu -o pipefail if [ "x$*" = 'x--help' ] @@ -18,11 +9,13 @@ Usage: $0 --help Show this help message and exit. -$0 [ --enable-lcov ] [ MAKEARGS... ] - Build Zcash and most of its transitive dependencies from - source. MAKEARGS are applied to both dependencies and Zcash itself. If - --enable-lcov is passed, Zcash is configured to add coverage +$0 [ --enable-lcov ] [ --enable-debug ] [ MAKEARGS... ] + Build Komodo and most of its transitive dependencies from + source. MAKEARGS are applied to both dependencies and Komodo itself. + If --enable-lcov is passed, Komodo is configured to add coverage instrumentation, thus enabling "make cov" to work. + If --enable-debug is passed, Komodo is built with debugging information. It + must be passed after the previous arguments, if present. EOF exit 0 fi @@ -37,29 +30,27 @@ then shift fi +# If --enable-debug is the next argument, enable debugging +DEBUGGING_ARG='' +if [ "x${1:-}" = 'x--enable-debug' ] +then + DEBUG=1 + export DEBUG + DEBUGGING_ARG='--enable-debug' + shift +fi + TRIPLET=`./depends/config.guess` PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 -#BUILD CCLIB - -WD=$PWD - -cd src/cc -echo $PWD -echo Making cclib... -./makecustom - -cd ./priceslibs -echo Making prices feeds custom libs... -make all - -cd $WD - ./autogen.sh + CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ -CXXFLAGS='-arch x86_64 -I/usr/local/Cellar/gcc\@8/8.3.0/include/c++/8.3.0/ -I$PREFIX/include -fwrapv -fno-strict-aliasing -Wno-builtin-declaration-mismatch -Werror -g -Wl,-undefined -Wl,dynamic_lookup' \ -./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" +CXXFLAGS="-arch x86_64 -I$PREFIX/include -fwrapv -fno-strict-aliasing \ +-Wno-deprecated-declarations -Wno-deprecated-builtins -Wno-enum-constexpr-conversion \ +-Wno-unknown-warning-option -Werror -Wno-error=attributes -g" \ +./configure --prefix="${PREFIX}" --with-gui=no "$HARDENING_ARG" "$LCOV_ARG" "$DEBUGGING_ARG" -make "$@" V=1 NO_GTEST=1 STATIC=1 +make "$@" NO_GTEST=1 STATIC=1 \ No newline at end of file From 5f2945891e4989758730a8b70b080c2b3206922b Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Wed, 25 Sep 2024 10:56:55 +0300 Subject: [PATCH 2/7] removed comments --- src/Makefile.am | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b63e8bf6a96..6cbac3c69a8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -97,8 +97,8 @@ $(LIBCRYPTOCONDITIONS): $(wildcard cryptoconditions/src/*) $(wildcard cryptocond # But to build the less dependent modules first, we manually select their order here: EXTRA_LIBRARIES += \ $(LIBBITCOIN_CRYPTO) \ -# $(LIBVERUS_CRYPTO) \ -# $(LIBVERUS_PORTABLE_CRYPTO) \ + $(LIBVERUS_CRYPTO) \ + $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_SERVER) \ From 1b1548605a13a013e0b70f98fc9f6d6be6256d51 Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Wed, 25 Sep 2024 11:00:01 +0300 Subject: [PATCH 3/7] fix typo in library name in .github/workflows/marmara_mac_ci.yml --- .github/workflows/marmara_mac_ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/marmara_mac_ci.yml b/.github/workflows/marmara_mac_ci.yml index e2c04770bae..c754611136c 100644 --- a/.github/workflows/marmara_mac_ci.yml +++ b/.github/workflows/marmara_mac_ci.yml @@ -187,7 +187,7 @@ jobs: # run: | # brew install python3 curl # python3 -m pip install setuptools wheel - # python3 -m pip install slick-bitcoinrpc pytest wget jsonschemaa + # python3 -m pip install slick-bitcoinrpc pytest wget jsonschema # - name: Download komodo-macos.tar.gz # uses: actions/download-artifact@v4 # with: From 7cc1dccb0d87c74cc52e302c9c2f43d1fd58b065 Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Wed, 25 Sep 2024 18:14:11 +0300 Subject: [PATCH 4/7] reverted changes for static linking of libcc in src/Makefile.am --- src/Makefile.am | 164 +++++++++++++++++++++--------------------------- 1 file changed, 72 insertions(+), 92 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index 6cbac3c69a8..e694ca7810d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,17 +31,16 @@ BITCOIN_INCLUDES += -I$(srcdir)/snark BITCOIN_INCLUDES += -I$(srcdir)/snark/libsnark BITCOIN_INCLUDES += -I$(srcdir)/univalue/include -# if TARGET_WINDOWS -# LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl -# endif -# if TARGET_DARWIN -# LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl -# endif -# if TARGET_LINUX -# LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl -# endif - -LIBBITCOIN_SERVER=libbitcoin_server.a +if TARGET_WINDOWS +LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl +endif +if TARGET_DARWIN +LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl +endif +if TARGET_LINUX +LIBBITCOIN_SERVER=libbitcoin_server.a -lcurl +endif + LIBBITCOIN_WALLET=libbitcoin_wallet.a LIBBITCOIN_COMMON=libbitcoin_common.a LIBBITCOIN_CLI=libbitcoin_cli.a @@ -53,7 +52,6 @@ LIBSECP256K1=secp256k1/libsecp256k1.la LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la LIBSNARK=snark/libsnark.a LIBUNIVALUE=univalue/libunivalue.la -LIBCC=libcc.a LIBZCASH=libzcash.a if ENABLE_ZMQ @@ -103,9 +101,7 @@ EXTRA_LIBRARIES += \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_SERVER) \ $(LIBBITCOIN_CLI) \ - $(LIBZCASH) \ - $(LIBCC) - + libzcash.a if ENABLE_WALLET BITCOIN_INCLUDES += $(BDB_CPPFLAGS) EXTRA_LIBRARIES += $(LIBBITCOIN_WALLET) @@ -187,9 +183,9 @@ BITCOIN_CORE_H = \ consensus/validation.h \ core_io.h \ core_memusage.h \ - crypto/haraka.h \ #does marmara use haraka check - crypto/haraka_portable.h \ # removed from komodo - crypto/verus_hash.h \ # removed from komodo, verus related + crypto/haraka.h \ + crypto/haraka_portable.h \ + crypto/verus_hash.h \ deprecation.h \ hash.h \ httprpc.h \ @@ -294,17 +290,17 @@ libbitcoin_server_a_SOURCES = \ cc/import.cpp \ cc/importgateway.cpp \ cc/CCassetsCore.cpp \ - cc/old/CCassetsCore_v0.cpp \ #removed from komodo - cc/CCassetstx.cpp \ #removed from komodo - cc/old/CCassetstx_v0.cpp \ #removed from komodo + cc/old/CCassetsCore_v0.cpp \ + cc/CCassetstx.cpp \ + cc/old/CCassetstx_v0.cpp \ cc/CCcustom.cpp \ cc/CCtx.cpp \ cc/CCutils.cpp \ - cc/CCvalidation.cpp \ #removed from komodo + cc/CCvalidation.cpp \ cc/CCtokens.cpp \ - cc/old/CCtokens_v0.cpp \ #removed from komodo + cc/old/CCtokens_v0.cpp \ cc/assets.cpp \ - cc/old/assets_v0.cpp \ #removed from komodo + cc/old/assets_v0.cpp \ cc/faucet.cpp \ cc/rewards.cpp \ cc/dice.cpp \ @@ -312,8 +308,8 @@ libbitcoin_server_a_SOURCES = \ cc/fsm.cpp \ cc/heir.cpp \ cc/oracles.cpp \ - cc/prices.cpp \ #removed from komodo - cc/pegs.cpp \ #removed from komodo + cc/prices.cpp \ + cc/pegs.cpp \ cc/marmara.cpp \ cc/marmara_h0.cpp \ cc/payments.cpp \ @@ -321,17 +317,17 @@ libbitcoin_server_a_SOURCES = \ cc/channels.cpp \ cc/auction.cpp \ cc/betprotocol.cpp \ - cc/pricesfeed.cpp \ #removed from komodo - cc/priceslibs/cjsonpointer.cpp \ #removed from komodo - cc/kogs.cpp \ #removed from komodo + cc/pricesfeed.cpp \ + cc/priceslibs/cjsonpointer.cpp \ + cc/kogs.cpp \ chain.cpp \ checkpoints.cpp \ crosschain.cpp \ - crosschain_authority.cpp \ #removed from komodo - crypto/haraka.h \ #removed from komodo - crypto/haraka_portable.h \ #removed from komodo - crypto/verus_hash.h \ #removed from komodo - crypto/verus_hash.cpp \ #removed from komodo + crosschain_authority.cpp \ + crypto/haraka.h \ + crypto/haraka_portable.h \ + crypto/verus_hash.h \ + crypto/verus_hash.cpp \ deprecation.cpp \ httprpc.cpp \ httpserver.cpp \ @@ -357,8 +353,8 @@ libbitcoin_server_a_SOURCES = \ rpc/net.cpp \ rpc/rawtransaction.cpp \ rpc/server.cpp \ - rpc/tokensrpc.cpp \ #removed from komodo - rpc/pricesrpc.cpp \ #removed from komodo + rpc/tokensrpc.cpp \ + rpc/pricesrpc.cpp \ rpc/marmararpc.cpp \ script/serverchecker.cpp \ script/sigcache.cpp \ @@ -415,11 +411,6 @@ libbitcoin_wallet_a_SOURCES = \ $(BITCOIN_CORE_H) \ $(LIBZCASH_H) -# a static library for cryptoconditions -libcc_a_SOURCES = cc/cclib.cpp -libcc_a_CXXFLAGS = -DBUILD_CUSTOMCC -I../secp256k1/include -I../depends/$(shell echo `../depends/config.guess`/include) -I./univalue/include -I./cryptoconditions/include -I./cryptoconditions/src -I./cryptoconditions/src/asn -I. -I./cc -# libcc_a_LDFLAGS = -version-info 0:0:0 - # crypto primitives library crypto_libbitcoin_crypto_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_CONFIG_INCLUDES) crypto_libbitcoin_crypto_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -440,10 +431,10 @@ crypto_libbitcoin_crypto_a_SOURCES = \ crypto/sha256.h \ crypto/sha512.cpp \ crypto/sha512.h \ - crypto/haraka.h \ # removed from komodo - crypto/haraka_portable.h \ # removed from komodo - crypto/verus_hash.h \ # removed from komodo - crypto/verus_hash.cpp # removed from komodo + crypto/haraka.h \ + crypto/haraka_portable.h \ + crypto/verus_hash.h \ + crypto/verus_hash.cpp if EXPERIMENTAL_ASM crypto_libbitcoin_crypto_a_SOURCES += crypto/sha256_sse4.cpp @@ -489,10 +480,10 @@ libbitcoin_common_a_SOURCES = \ consensus/upgrades.cpp \ core_read.cpp \ core_write.cpp \ - crypto/haraka.h \ # removed from komodo - crypto/haraka_portable.h \ # removed from komodo - crypto/verus_hash.h \ # removed from komodo - crypto/verus_hash.cpp \ # removed from komodo + crypto/haraka.h \ + crypto/haraka_portable.h \ + crypto/verus_hash.h \ + crypto/verus_hash.cpp \ hash.cpp \ importcoin.cpp \ key.cpp \ @@ -515,7 +506,7 @@ libbitcoin_common_a_SOURCES = \ script/standard.cpp \ transaction_builder.cpp \ cc/CCtokenutils.cpp \ - cc/old/CCtokenutils_v0.cpp \ # removed from komodo + cc/old/CCtokenutils_v0.cpp \ cc/CCutilbits.cpp \ gmp_i64.c \ $(BITCOIN_CORE_H) \ @@ -579,8 +570,8 @@ marmarad_LDADD = \ $(LIBBITCOIN_ZMQ) \ $(LIBBITCOIN_PROTON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ #removed from komodo - $(LIBVERUS_PORTABLE_CRYPTO) \ #removed from komodo + $(LIBVERUS_CRYPTO) \ + $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBLEVELDB) \ @@ -602,27 +593,26 @@ marmarad_LDADD += \ $(ZMQ_LIBS) \ $(PROTON_LIBS) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ #verus related, removed from komodo - $(LIBVERUS_PORTABLE_CRYPTO) \ #removed from komodo + $(LIBVERUS_CRYPTO) \ + $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) - $(LIBCC) \ - -lcurl - -# https://github.com/marmarachain/marmara/pull/47#issuecomment-2363865476 commented out explicit reference to libcc.dll -# if TARGET_DARWIN -# marmarad_LDADD += libcc.dylib $(LIBSECP256K1) -# endif -# if TARGET_WINDOWS -# marmarad_LDADD += libcc.dll $(LIBSECP256K1) -# endif -# if TARGET_LINUX -# marmarad_LDADD += libcc.so $(LIBSECP256K1) -# endif + +if TARGET_DARWIN +marmarad_LDADD += libcc.dylib $(LIBSECP256K1) +endif +if TARGET_WINDOWS +marmarad_LDADD += libcc.dll $(LIBSECP256K1) +endif +if TARGET_LINUX +marmarad_LDADD += libcc.so $(LIBSECP256K1) +endif if ENABLE_PROTON marmarad_LDADD += $(LIBBITCOIN_PROTON) $(PROTON_LIBS) endif +# [+] Decker: use static linking for libstdc++.6.dylib, libgomp.1.dylib, libgcc_s.1.dylib + # bitcoin-cli binary # marmara_cli_SOURCES = bitcoin-cli.cpp marmara_cli_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CFLAGS) @@ -636,10 +626,6 @@ wallet_utility_SOURCES = wallet-utility.cpp wallet_utility_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) wallet_utility_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) wallet_utility_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) - -if TARGET_WINDOWS -wallet_utility_SOURCES += wallet-utility-res.rc -endif endif if TARGET_WINDOWS @@ -656,8 +642,8 @@ marmara_cli_LDADD = \ $(EVENT_LIBS) \ $(LIBZCASH) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ # verus related, removed from komodo - $(LIBVERUS_PORTABLE_CRYPTO) \ # verus related, removed from komodo + $(LIBVERUS_CRYPTO) \ + $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) if ENABLE_WALLET @@ -665,8 +651,8 @@ wallet_utility_LDADD = \ libbitcoin_wallet.a \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ # verus related, removed from komodo - $(LIBVERUS_PORTABLE_CRYPTO) \ # verus related, removed from komodo + $(LIBVERUS_CRYPTO) \ + $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBSECP256K1) \ $(LIBBITCOIN_UTIL) \ $(BOOST_LIBS) \ @@ -697,8 +683,8 @@ komodo_tx_LDADD = \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ # verus related, removed from komodo - $(LIBVERUS_PORTABLE_CRYPTO) \ # verus related, removed from komodo + $(LIBVERUS_CRYPTO) \ + $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ $(LIBCRYPTOCONDITIONS) @@ -716,12 +702,12 @@ libzcash_a_SOURCES = \ zcash/prf.cpp \ zcash/util.cpp \ zcash/zip32.cpp \ - zcash/circuit/commitment.tcc \ #removed from komodo - zcash/circuit/gadget.tcc \ #removed from komodo - zcash/circuit/merkle.tcc \ #removed from komodo - zcash/circuit/note.tcc \ #removed from komodo - zcash/circuit/prfs.tcc \ #removed from komodo - zcash/circuit/utils.tcc #removed from komodo + zcash/circuit/commitment.tcc \ + zcash/circuit/gadget.tcc \ + zcash/circuit/merkle.tcc \ + zcash/circuit/note.tcc \ + zcash/circuit/prfs.tcc \ + zcash/circuit/utils.tcc libzcash_a_CPPFLAGS = -DMULTICORE -fopenmp -fPIC -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DBOOST_SPIRIT_THREADSAFE -DHAVE_BUILD_INFO -D__STDC_FORMAT_MACROS $(HARDENED_CPPFLAGS) $(HARDENED_CXXFLAGS) $(HARDENED_LDFLAGS) -pipe $(SAN_LDFLAGS) -O1 -g -Wstack-protector $(SAN_CXXFLAGS) -fstack-protector-all -fPIE -fvisibility=hidden -DSTATIC $(BITCOIN_INCLUDES) @@ -779,12 +765,6 @@ clean-local: -$(MAKE) -C cryptoconditions clean rm -f leveldb/*/*.gcno leveldb/helpers/memenv/*.gcno -rm -f config.h - -$(RM) *.a - -$(RM) crypto/*.a - -$(RM) cryptoconditions/.libs/*.a - -clean-all: clean-local - -$(MAKE) -C univalue clean-all .rc.o: @test -f $(WINDRES) @@ -812,6 +792,6 @@ endif if ENABLE_TESTS include Makefile.ktest.include -#include Makefile.test.include #bitcoin tests -#include Makefile.gtest.include #zcash tests -endif +#include Makefile.test.include +#include Makefile.gtest.include +endif \ No newline at end of file From 94788917079c7f95c35c53cb7d3325e4585c9aef Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Thu, 26 Sep 2024 16:06:40 +0300 Subject: [PATCH 5/7] add build cclib steps in zcutil/build-mac-dtest.sh and zcutil/build-mac.sh --- zcutil/build-mac-dtest.sh | 8 ++++++++ zcutil/build-mac.sh | 15 +++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/zcutil/build-mac-dtest.sh b/zcutil/build-mac-dtest.sh index ebdf78e9c8a..866c51f0702 100755 --- a/zcutil/build-mac-dtest.sh +++ b/zcutil/build-mac-dtest.sh @@ -45,6 +45,14 @@ PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 +#BUILD CCLIB + +WD=$PWD +cd src/cc +echo $PWD +./makecustom +cd $WD + ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64 -DTESTMODE" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ diff --git a/zcutil/build-mac.sh b/zcutil/build-mac.sh index fc789977dfc..0954d060b0e 100755 --- a/zcutil/build-mac.sh +++ b/zcutil/build-mac.sh @@ -45,6 +45,21 @@ PREFIX="$(pwd)/depends/$TRIPLET" make "$@" -C ./depends/ V=1 NO_QT=1 NO_PROTON=1 +#BUILD CCLIB + +WD=$PWD + +cd src/cc +echo $PWD +echo Making cclib... +./makecustom + +cd ./priceslibs +echo Making prices feeds custom libs... +make all + +cd $WD + ./autogen.sh CPPFLAGS="-I$PREFIX/include -arch x86_64" LDFLAGS="-L$PREFIX/lib -arch x86_64 -Wl,-no_pie" \ From ac30079fbf1df7e85b2914f27d8ad0f0c2200e05 Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Tue, 1 Oct 2024 15:05:16 +0300 Subject: [PATCH 6/7] [REF] physically remove haraka and verus files from code [IMP] remove cron scheduler for ci workflows --- .github/workflows/marmara_linux_ci.yml | 2 - .github/workflows/marmara_mac_ci.yml | 2 - .github/workflows/marmara_win_ci.yml | 2 - doc/man/verus-cli/linux/README.txt | 13 - doc/man/verus-cli/mac/README.txt | 17 - doc/man/verus-cli/windows/README.txt | 21 - qa/verus-cli-tests/verus-cli-tester.py | 39 -- src/Makefile.am | 49 +- src/Makefile.gtest.include | 2 +- src/Makefile.qt.include | 2 +- src/Makefile.qttest.include | 2 +- src/Makefile.test.include | 2 +- src/Makefile.zcash.include | 1 - src/crypto/haraka.c | 606 ------------------------- src/crypto/haraka.h | 126 ----- src/crypto/haraka_portable.c | 375 --------------- src/crypto/haraka_portable.h | 33 -- src/crypto/verus_hash.cpp | 180 -------- src/crypto/verus_hash.h | 134 ------ src/fiat/verus.bat | 14 - src/hush-cli | 11 - src/hushd | 52 --- src/verusd | 5 - src/verusd.bat | 10 - zcutil/VerusCoin.xml | 432 ------------------ 25 files changed, 7 insertions(+), 2125 deletions(-) delete mode 100644 doc/man/verus-cli/linux/README.txt delete mode 100644 doc/man/verus-cli/mac/README.txt delete mode 100644 doc/man/verus-cli/windows/README.txt delete mode 100644 qa/verus-cli-tests/verus-cli-tester.py delete mode 100644 src/crypto/haraka.c delete mode 100644 src/crypto/haraka.h delete mode 100644 src/crypto/haraka_portable.c delete mode 100644 src/crypto/haraka_portable.h delete mode 100644 src/crypto/verus_hash.cpp delete mode 100644 src/crypto/verus_hash.h delete mode 100644 src/fiat/verus.bat delete mode 100755 src/hush-cli delete mode 100755 src/hushd delete mode 100755 src/verusd delete mode 100644 src/verusd.bat delete mode 100644 zcutil/VerusCoin.xml diff --git a/.github/workflows/marmara_linux_ci.yml b/.github/workflows/marmara_linux_ci.yml index 5df0747894d..66d60aae393 100644 --- a/.github/workflows/marmara_linux_ci.yml +++ b/.github/workflows/marmara_linux_ci.yml @@ -3,8 +3,6 @@ name: Marmara Linux CI on: pull_request: types: [opened, synchronize, reopened] - schedule: - - cron: '0 0 * * 1' jobs: diff --git a/.github/workflows/marmara_mac_ci.yml b/.github/workflows/marmara_mac_ci.yml index c754611136c..02e82dff3c7 100644 --- a/.github/workflows/marmara_mac_ci.yml +++ b/.github/workflows/marmara_mac_ci.yml @@ -3,8 +3,6 @@ name: Marmara MacOS CI on: pull_request: types: [opened, synchronize, reopened] - schedule: - - cron: '0 0 * * 1' jobs: diff --git a/.github/workflows/marmara_win_ci.yml b/.github/workflows/marmara_win_ci.yml index 7d657b8de8b..182cd514703 100644 --- a/.github/workflows/marmara_win_ci.yml +++ b/.github/workflows/marmara_win_ci.yml @@ -3,8 +3,6 @@ name: Marmara Win CI on: pull_request: types: [opened, synchronize, reopened] - schedule: - - cron: '0 0 * * 1' jobs: diff --git a/doc/man/verus-cli/linux/README.txt b/doc/man/verus-cli/linux/README.txt deleted file mode 100644 index cb2c10f0fbb..00000000000 --- a/doc/man/verus-cli/linux/README.txt +++ /dev/null @@ -1,13 +0,0 @@ -VerusCoin Command Line Tools v0.4.0c - -Contents: -komodod - VerusCoin's enhanced Komodo daemon -komodo-cli - VerusCoin's Komodo command line utility -verus - wrapper for komodo-cli that applies the command to the VRSC coin -verusd - wrapper for komodod that sets the VerusCoin parameters to defaults properly - -The first time on a new system you will need to run ./fetch-params before using komodod or verusd. - -Run ./verusd to launch komodod, and use verus to run commands such as: -./verus stop -Which signals komodod (if it is running) to stop running. diff --git a/doc/man/verus-cli/mac/README.txt b/doc/man/verus-cli/mac/README.txt deleted file mode 100644 index 367e52fce00..00000000000 --- a/doc/man/verus-cli/mac/README.txt +++ /dev/null @@ -1,17 +0,0 @@ -VerusCoin Command Line Tools v0.4.0c -Contents: -komodod - VerusCoin's enhanced Komodo daemon. -komodo-cli - VerusCoin's enhanced Komodo command line utility. -verus - wrapper for komodo-cli that applies the command to the VRSC coin -verusd - wrapper for komodod that sets the VerusCoin parameters to defaults properly -fetch_params.sh - utility to download the zcash parameters needed to start the VerusCoin command line tools and scripts -lib*.dylib - assorted dynamic libraries, dependencies needed by fetch-params.sh, komodod and/or komodo-cli - -Command line tools are run from the terminal. You can launch the terminal on a Mac by using the Finder, selecting Applications and from that select Utilities, finally selecting Terminal from the Utilities folder. -You will need to switch to the directory you extracted the verus-cl into. If you extracted it in the Download folder then the change directory command is -cd ~/Downloads/verus-cli -The first time on a new system you will need to run ./fetch-params before using komodod or verusd. - -Run ./verusd to launch komodod, and use verus to run commands such as: -./verus stop -Which signals komodod (if it is running) to stop running. diff --git a/doc/man/verus-cli/windows/README.txt b/doc/man/verus-cli/windows/README.txt deleted file mode 100644 index aa71d8c3f05..00000000000 --- a/doc/man/verus-cli/windows/README.txt +++ /dev/null @@ -1,21 +0,0 @@ -VerusCoin Command Line Tools v0.4.0c -Contents: -komodod.exe - VerusCoin's enhanced Komodo daemon -komodo-cli.exe - VerusCoin's Komodo command line utility -verus.bat - wrapper for komodo-cli that applies the command to the VRSC coin -verusd.bat - wrapper for komodod that sets the VerusCoin parameters to defaults properly - -You need to run a command prompt, for example hit and type cmd -From the command prompt change to the directory where you installed verus-cli. If you downloaded the file to your Downloads directory and extracted it there then the change directory command is -cd \Users\MyName\Downloads\verus-cli -From this directory you can run the Verus command line utilities. -The first time on a new system you will need to run fetch-params before using komodod.exe or verusd. -Many anti-virus products interfere with the VerusCoin tool's ability to open ports and will need to be configured to allow what the scanner says is unsafe behavior. -Extreme cases can result in the virus scanner deleting Agama.exe or moving it to "protect" the system. You will to add the executables to a whitelist and re-extract the verus-cli-windows.zip file if that happens. -Run verusd.bat to launch komodod, and use verus.bat to run commands such as: -verus.bat stop -Which signals komodod.exe (if it is running) to stop running. - -Note that if you pass in command line options to verus.bat or verusd.bat that include an = like -ac_veruspos=50 you must surround it with double quotes like this: -verusd.bat "-ac_veruspos=50" -Otherwise Windows will drop the = and pass the two values in as separate command line options. diff --git a/qa/verus-cli-tests/verus-cli-tester.py b/qa/verus-cli-tests/verus-cli-tester.py deleted file mode 100644 index 1476861101b..00000000000 --- a/qa/verus-cli-tests/verus-cli-tester.py +++ /dev/null @@ -1,39 +0,0 @@ -from subprocess import Popen, check_output, call -from time import sleep -from os import environ, path - -daemon_wrapper = "verusd" -cli_wrapper = "verus" -daemon_runtime_seconds = 600 -cli_commands = ["getblockchaininfo", "getmininginfo", "getwalletinfo", "stop"] - - -def start_daemon(daemon_wrapper): - try: - Popen(daemon_wrapper, shell=True, close_fds=True) - except: - exit(1) - - -def fetch_zcash_params(): - try: - call("fetch-params", shell=True) - except: - exit(1) - - -def run_cli_commands(cli_wrapper, commands): - for command in commands: - command = "%(cli_wrapper)s %(command)s" % locals() - try: - with open(path.join(environ["CI_PROJECT_DIR"], "log.txt"), "a") as log: - command_output = check_output(command, shell=True) - log.write("%(command_output)s\n" % locals()) - except: - exit(1) - - -fetch_zcash_params() -start_daemon(daemon_wrapper) -sleep(daemon_runtime_seconds) -run_cli_commands(cli_wrapper, cli_commands) diff --git a/src/Makefile.am b/src/Makefile.am index e694ca7810d..0c488fb004f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -46,8 +46,6 @@ LIBBITCOIN_COMMON=libbitcoin_common.a LIBBITCOIN_CLI=libbitcoin_cli.a LIBBITCOIN_UTIL=libbitcoin_util.a LIBBITCOIN_CRYPTO=crypto/libbitcoin_crypto.a -LIBVERUS_CRYPTO=crypto/libverus_crypto.a -LIBVERUS_PORTABLE_CRYPTO=crypto/libverus_portable_crypto.a LIBSECP256K1=secp256k1/libsecp256k1.la LIBCRYPTOCONDITIONS=cryptoconditions/libcryptoconditions_core.la LIBSNARK=snark/libsnark.a @@ -95,8 +93,6 @@ $(LIBCRYPTOCONDITIONS): $(wildcard cryptoconditions/src/*) $(wildcard cryptocond # But to build the less dependent modules first, we manually select their order here: EXTRA_LIBRARIES += \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_SERVER) \ @@ -183,9 +179,6 @@ BITCOIN_CORE_H = \ consensus/validation.h \ core_io.h \ core_memusage.h \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ deprecation.h \ hash.h \ httprpc.h \ @@ -324,10 +317,6 @@ libbitcoin_server_a_SOURCES = \ checkpoints.cpp \ crosschain.cpp \ crosschain_authority.cpp \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp \ deprecation.cpp \ httprpc.cpp \ httpserver.cpp \ @@ -430,11 +419,7 @@ crypto_libbitcoin_crypto_a_SOURCES = \ crypto/sha256.cpp \ crypto/sha256.h \ crypto/sha512.cpp \ - crypto/sha512.h \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp + crypto/sha512.h if EXPERIMENTAL_ASM crypto_libbitcoin_crypto_a_SOURCES += crypto/sha256_sse4.cpp @@ -452,20 +437,6 @@ crypto_libbitcoin_crypto_a_SOURCES += \ ${EQUIHASH_TROMP_SOURCES} endif -# Verus hash specific library - optimized -crypto_libverus_crypto_a_CPPFLAGS = -O3 -Wint-conversion -march=x86-64 -msse4 -msse4.1 -msse4.2 -mssse3 -mavx -maes -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CPPFLAGS) -crypto_libverus_crypto_a_CXXFLAGS = -O3 -Wint-conversion -march=x86-64 -msse4 -msse4.1 -msse4.2 -mssse3 -mavx -maes -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CXXFLAGS) -crypto_libverus_crypto_a_SOURCES = \ - crypto/haraka.h \ - crypto/haraka.c - -# Verus hash specific library - portable -crypto_libverus_portable_crypto_a_CPPFLAGS = -O3 -Wint-conversion -march=x86-64 -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CPPFLAGS) -crypto_libverus_portable_crypto_a_CXXFLAGS = -O3 -Wint-conversion -march=x86-64 -g -funroll-loops -fomit-frame-pointer -fPIC $(AM_CXXFLAGS) -crypto_libverus_portable_crypto_a_SOURCES = \ - crypto/haraka_portable.h \ - crypto/haraka_portable.c - # common: shared between zcashd and non-server tools libbitcoin_common_a_CPPFLAGS = -fPIC $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) libbitcoin_common_a_CXXFLAGS = -fPIC $(AM_CXXFLAGS) $(PIE_FLAGS) @@ -480,10 +451,6 @@ libbitcoin_common_a_SOURCES = \ consensus/upgrades.cpp \ core_read.cpp \ core_write.cpp \ - crypto/haraka.h \ - crypto/haraka_portable.h \ - crypto/verus_hash.h \ - crypto/verus_hash.cpp \ hash.cpp \ importcoin.cpp \ key.cpp \ @@ -570,8 +537,6 @@ marmarad_LDADD = \ $(LIBBITCOIN_ZMQ) \ $(LIBBITCOIN_PROTON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBLEVELDB) \ @@ -593,8 +558,6 @@ marmarad_LDADD += \ $(ZMQ_LIBS) \ $(PROTON_LIBS) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) if TARGET_DARWIN @@ -642,8 +605,6 @@ marmara_cli_LDADD = \ $(EVENT_LIBS) \ $(LIBZCASH) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) if ENABLE_WALLET @@ -651,8 +612,6 @@ wallet_utility_LDADD = \ libbitcoin_wallet.a \ $(LIBBITCOIN_COMMON) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBSECP256K1) \ $(LIBBITCOIN_UTIL) \ $(BOOST_LIBS) \ @@ -661,7 +620,7 @@ wallet_utility_LDADD = \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBZCASH_LIBS)\ - $(LIBCRYPTOCONDITIONS) + $(LIBCRYPTOCONDITIONS) endif # zcash-tx binary # @@ -683,8 +642,6 @@ komodo_tx_LDADD = \ $(LIBZCASH) \ $(LIBSNARK) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ - $(LIBVERUS_PORTABLE_CRYPTO) \ $(LIBZCASH_LIBS) \ $(LIBCRYPTOCONDITIONS) @@ -701,7 +658,7 @@ libzcash_a_SOURCES = \ zcash/Note.cpp \ zcash/prf.cpp \ zcash/util.cpp \ - zcash/zip32.cpp \ + zcash/zip32.cpp \ zcash/circuit/commitment.tcc \ zcash/circuit/gadget.tcc \ zcash/circuit/merkle.tcc \ diff --git a/src/Makefile.gtest.include b/src/Makefile.gtest.include index ec3a4a12e29..cb9aa844a04 100644 --- a/src/Makefile.gtest.include +++ b/src/Makefile.gtest.include @@ -54,7 +54,7 @@ endif komodo_gtest_CPPFLAGS = $(AM_CPPFLAGS) -DMULTICORE -fopenmp -DBINARY_OUTPUT -DCURVE_ALT_BN128 -DSTATIC $(BITCOIN_INCLUDES) komodo_gtest_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) -komodo_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +komodo_gtest_LDADD = -lgtest -lgmock $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) if ENABLE_ZMQ zcash_gtest_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS) diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index 6afc3a7075a..c2101673749 100644 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -361,7 +361,7 @@ qt_komodo_qt_LDADD = qt/libbitcoinqt.a $(LIBBITCOIN_SERVER) if ENABLE_WALLET qt_komodo_qt_LDADD += $(LIBBITCOIN_WALLET) endif -qt_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +qt_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(QT_LIBS) $(QT_DBUS_LIBS) $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) $(LIBZCASH_LIBS) qt_komodo_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) qt_komodo_qt_LIBTOOLFLAGS = --tag CXX diff --git a/src/Makefile.qttest.include b/src/Makefile.qttest.include index 2d56d07e381..3e57a89266a 100644 --- a/src/Makefile.qttest.include +++ b/src/Makefile.qttest.include @@ -30,7 +30,7 @@ qt_test_test_komodo_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER) if ENABLE_WALLET qt_test_test_komodo_qt_LDADD += $(LIBBITCOIN_WALLET) endif -qt_test_test_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) \ +qt_test_test_komodo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBBITCOIN_UNIVALUE) $(LIBLEVELDB) \ $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \ $(QR_LIBS) $(PROTOBUF_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) $(LIBZCASH_LIBS) qt_test_test_komodo_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) diff --git a/src/Makefile.test.include b/src/Makefile.test.include index 1f9f9ac1e7f..59c66ad43f2 100644 --- a/src/Makefile.test.include +++ b/src/Makefile.test.include @@ -113,7 +113,7 @@ endif test_test_bitcoin_SOURCES = $(BITCOIN_TESTS) $(JSON_TEST_FILES) $(RAW_TEST_FILES) test_test_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) -fopenmp $(BITCOIN_INCLUDES) -I$(builddir)/test/ $(TESTDEFS) $(EVENT_CFLAGS) -test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBVERUS_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ +test_test_bitcoin_LDADD = $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) \ $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) test_test_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS) if ENABLE_WALLET diff --git a/src/Makefile.zcash.include b/src/Makefile.zcash.include index 4302b2e0da5..da5b4344da7 100644 --- a/src/Makefile.zcash.include +++ b/src/Makefile.zcash.include @@ -24,7 +24,6 @@ zcash_CreateJoinSplit_LDADD = \ $(LIBSNARK) \ $(LIBBITCOIN_UTIL) \ $(LIBBITCOIN_CRYPTO) \ - $(LIBVERUS_CRYPTO) \ $(BOOST_LIBS) \ $(LIBZCASH_LIBS) \ $(LIBCRYPTOCONDITIONS) \ diff --git a/src/crypto/haraka.c b/src/crypto/haraka.c deleted file mode 100644 index d611b9af566..00000000000 --- a/src/crypto/haraka.c +++ /dev/null @@ -1,606 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2016 kste - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -Optimized Implementations for Haraka256 and Haraka512 -*/ - -#include -#include "crypto/haraka.h" - -u128 rc[40]; -u128 rc0[40] = {0}; - -void load_constants() { - rc[0] = _mm_set_epi32(0x0684704c,0xe620c00a,0xb2c5fef0,0x75817b9d); - rc[1] = _mm_set_epi32(0x8b66b4e1,0x88f3a06b,0x640f6ba4,0x2f08f717); - rc[2] = _mm_set_epi32(0x3402de2d,0x53f28498,0xcf029d60,0x9f029114); - rc[3] = _mm_set_epi32(0x0ed6eae6,0x2e7b4f08,0xbbf3bcaf,0xfd5b4f79); - rc[4] = _mm_set_epi32(0xcbcfb0cb,0x4872448b,0x79eecd1c,0xbe397044); - rc[5] = _mm_set_epi32(0x7eeacdee,0x6e9032b7,0x8d5335ed,0x2b8a057b); - rc[6] = _mm_set_epi32(0x67c28f43,0x5e2e7cd0,0xe2412761,0xda4fef1b); - rc[7] = _mm_set_epi32(0x2924d9b0,0xafcacc07,0x675ffde2,0x1fc70b3b); - rc[8] = _mm_set_epi32(0xab4d63f1,0xe6867fe9,0xecdb8fca,0xb9d465ee); - rc[9] = _mm_set_epi32(0x1c30bf84,0xd4b7cd64,0x5b2a404f,0xad037e33); - rc[10] = _mm_set_epi32(0xb2cc0bb9,0x941723bf,0x69028b2e,0x8df69800); - rc[11] = _mm_set_epi32(0xfa0478a6,0xde6f5572,0x4aaa9ec8,0x5c9d2d8a); - rc[12] = _mm_set_epi32(0xdfb49f2b,0x6b772a12,0x0efa4f2e,0x29129fd4); - rc[13] = _mm_set_epi32(0x1ea10344,0xf449a236,0x32d611ae,0xbb6a12ee); - rc[14] = _mm_set_epi32(0xaf044988,0x4b050084,0x5f9600c9,0x9ca8eca6); - rc[15] = _mm_set_epi32(0x21025ed8,0x9d199c4f,0x78a2c7e3,0x27e593ec); - rc[16] = _mm_set_epi32(0xbf3aaaf8,0xa759c9b7,0xb9282ecd,0x82d40173); - rc[17] = _mm_set_epi32(0x6260700d,0x6186b017,0x37f2efd9,0x10307d6b); - rc[18] = _mm_set_epi32(0x5aca45c2,0x21300443,0x81c29153,0xf6fc9ac6); - rc[19] = _mm_set_epi32(0x9223973c,0x226b68bb,0x2caf92e8,0x36d1943a); - rc[20] = _mm_set_epi32(0xd3bf9238,0x225886eb,0x6cbab958,0xe51071b4); - rc[21] = _mm_set_epi32(0xdb863ce5,0xaef0c677,0x933dfddd,0x24e1128d); - rc[22] = _mm_set_epi32(0xbb606268,0xffeba09c,0x83e48de3,0xcb2212b1); - rc[23] = _mm_set_epi32(0x734bd3dc,0xe2e4d19c,0x2db91a4e,0xc72bf77d); - rc[24] = _mm_set_epi32(0x43bb47c3,0x61301b43,0x4b1415c4,0x2cb3924e); - rc[25] = _mm_set_epi32(0xdba775a8,0xe707eff6,0x03b231dd,0x16eb6899); - rc[26] = _mm_set_epi32(0x6df3614b,0x3c755977,0x8e5e2302,0x7eca472c); - rc[27] = _mm_set_epi32(0xcda75a17,0xd6de7d77,0x6d1be5b9,0xb88617f9); - rc[28] = _mm_set_epi32(0xec6b43f0,0x6ba8e9aa,0x9d6c069d,0xa946ee5d); - rc[29] = _mm_set_epi32(0xcb1e6950,0xf957332b,0xa2531159,0x3bf327c1); - rc[30] = _mm_set_epi32(0x2cee0c75,0x00da619c,0xe4ed0353,0x600ed0d9); - rc[31] = _mm_set_epi32(0xf0b1a5a1,0x96e90cab,0x80bbbabc,0x63a4a350); - rc[32] = _mm_set_epi32(0xae3db102,0x5e962988,0xab0dde30,0x938dca39); - rc[33] = _mm_set_epi32(0x17bb8f38,0xd554a40b,0x8814f3a8,0x2e75b442); - rc[34] = _mm_set_epi32(0x34bb8a5b,0x5f427fd7,0xaeb6b779,0x360a16f6); - rc[35] = _mm_set_epi32(0x26f65241,0xcbe55438,0x43ce5918,0xffbaafde); - rc[36] = _mm_set_epi32(0x4ce99a54,0xb9f3026a,0xa2ca9cf7,0x839ec978); - rc[37] = _mm_set_epi32(0xae51a51a,0x1bdff7be,0x40c06e28,0x22901235); - rc[38] = _mm_set_epi32(0xa0c1613c,0xba7ed22b,0xc173bc0f,0x48a659cf); - rc[39] = _mm_set_epi32(0x756acc03,0x02288288,0x4ad6bdfd,0xe9c59da1); -} - -void test_implementations() { - unsigned char *in = (unsigned char *)calloc(64*8, sizeof(unsigned char)); - unsigned char *out256 = (unsigned char *)calloc(32*8, sizeof(unsigned char)); - unsigned char *out512 = (unsigned char *)calloc(32*8, sizeof(unsigned char)); - unsigned char testvector256[32] = {0x80, 0x27, 0xcc, 0xb8, 0x79, 0x49, 0x77, 0x4b, - 0x78, 0xd0, 0x54, 0x5f, 0xb7, 0x2b, 0xf7, 0x0c, - 0x69, 0x5c, 0x2a, 0x09, 0x23, 0xcb, 0xd4, 0x7b, - 0xba, 0x11, 0x59, 0xef, 0xbf, 0x2b, 0x2c, 0x1c}; - - unsigned char testvector512[32] = {0xbe, 0x7f, 0x72, 0x3b, 0x4e, 0x80, 0xa9, 0x98, - 0x13, 0xb2, 0x92, 0x28, 0x7f, 0x30, 0x6f, 0x62, - 0x5a, 0x6d, 0x57, 0x33, 0x1c, 0xae, 0x5f, 0x34, - 0xdd, 0x92, 0x77, 0xb0, 0x94, 0x5b, 0xe2, 0xaa}; - - - - int i; - - // Input for testvector - for(i = 0; i < 512; i++) { - in[i] = i % 64; - } - - load_constants(); - haraka512_8x(out512, in); - - // Verify output - for(i = 0; i < 32; i++) { - if (out512[i % 32] != testvector512[i]) { - printf("Error: testvector incorrect.\n"); - return; - } - } - - free(in); - free(out256); - free(out512); -} - -void haraka256(unsigned char *out, const unsigned char *in) { - __m128i s[2], tmp; - - s[0] = LOAD(in); - s[1] = LOAD(in + 16); - - AES2(s[0], s[1], 0); - MIX2(s[0], s[1]); - - AES2(s[0], s[1], 4); - MIX2(s[0], s[1]); - - AES2(s[0], s[1], 8); - MIX2(s[0], s[1]); - - AES2(s[0], s[1], 12); - MIX2(s[0], s[1]); - - AES2(s[0], s[1], 16); - MIX2(s[0], s[1]); - - s[0] = _mm_xor_si128(s[0], LOAD(in)); - s[1] = _mm_xor_si128(s[1], LOAD(in + 16)); - - STORE(out, s[0]); - STORE(out + 16, s[1]); -} - -void haraka256_4x(unsigned char *out, const unsigned char *in) { - __m128i s[4][2], tmp; - - s[0][0] = LOAD(in); - s[0][1] = LOAD(in + 16); - s[1][0] = LOAD(in + 32); - s[1][1] = LOAD(in + 48); - s[2][0] = LOAD(in + 64); - s[2][1] = LOAD(in + 80); - s[3][0] = LOAD(in + 96); - s[3][1] = LOAD(in + 112); - - // Round 1 - AES2_4x(s[0], s[1], s[2], s[3], 0); - - MIX2(s[0][0], s[0][1]); - MIX2(s[1][0], s[1][1]); - MIX2(s[2][0], s[2][1]); - MIX2(s[3][0], s[3][1]); - - // Round 2 - AES2_4x(s[0], s[1], s[2], s[3], 4); - - MIX2(s[0][0], s[0][1]); - MIX2(s[1][0], s[1][1]); - MIX2(s[2][0], s[2][1]); - MIX2(s[3][0], s[3][1]); - - // Round 3 - AES2_4x(s[0], s[1], s[2], s[3], 8); - - MIX2(s[0][0], s[0][1]); - MIX2(s[1][0], s[1][1]); - MIX2(s[2][0], s[2][1]); - MIX2(s[3][0], s[3][1]); - - // Round 4 - AES2_4x(s[0], s[1], s[2], s[3], 12); - - MIX2(s[0][0], s[0][1]); - MIX2(s[1][0], s[1][1]); - MIX2(s[2][0], s[2][1]); - MIX2(s[3][0], s[3][1]); - - // Round 5 - AES2_4x(s[0], s[1], s[2], s[3], 16); - - MIX2(s[0][0], s[0][1]); - MIX2(s[1][0], s[1][1]); - MIX2(s[2][0], s[2][1]); - MIX2(s[3][0], s[3][1]); - - // Feed Forward - s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); - s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); - s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 32)); - s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 48)); - s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 64)); - s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 80)); - s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 96)); - s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 112)); - - STORE(out, s[0][0]); - STORE(out + 16, s[0][1]); - STORE(out + 32, s[1][0]); - STORE(out + 48, s[1][1]); - STORE(out + 64, s[2][0]); - STORE(out + 80, s[2][1]); - STORE(out + 96, s[3][0]); - STORE(out + 112, s[3][1]); -} - -void haraka256_8x(unsigned char *out, const unsigned char *in) { - // This is faster on Skylake, the code below is faster on Haswell. - haraka256_4x(out, in); - haraka256_4x(out + 128, in + 128); - return; - // __m128i s[8][2], tmp; - // - // int i; - // - // s[0][0] = LOAD(in); - // s[0][1] = LOAD(in + 16); - // s[1][0] = LOAD(in + 32); - // s[1][1] = LOAD(in + 48); - // s[2][0] = LOAD(in + 64); - // s[2][1] = LOAD(in + 80); - // s[3][0] = LOAD(in + 96); - // s[3][1] = LOAD(in + 112); - // s[4][0] = LOAD(in + 128); - // s[4][1] = LOAD(in + 144); - // s[5][0] = LOAD(in + 160); - // s[5][1] = LOAD(in + 176); - // s[6][0] = LOAD(in + 192); - // s[6][1] = LOAD(in + 208); - // s[7][0] = LOAD(in + 224); - // s[7][1] = LOAD(in + 240); - // - // // Round 1 - // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 0); - // - // MIX2(s[0][0], s[0][1]); - // MIX2(s[1][0], s[1][1]); - // MIX2(s[2][0], s[2][1]); - // MIX2(s[3][0], s[3][1]); - // MIX2(s[4][0], s[4][1]); - // MIX2(s[5][0], s[5][1]); - // MIX2(s[6][0], s[6][1]); - // MIX2(s[7][0], s[7][1]); - // - // - // // Round 2 - // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 4); - // - // MIX2(s[0][0], s[0][1]); - // MIX2(s[1][0], s[1][1]); - // MIX2(s[2][0], s[2][1]); - // MIX2(s[3][0], s[3][1]); - // MIX2(s[4][0], s[4][1]); - // MIX2(s[5][0], s[5][1]); - // MIX2(s[6][0], s[6][1]); - // MIX2(s[7][0], s[7][1]); - // - // // Round 3 - // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 8); - // - // MIX2(s[0][0], s[0][1]); - // MIX2(s[1][0], s[1][1]); - // MIX2(s[2][0], s[2][1]); - // MIX2(s[3][0], s[3][1]); - // MIX2(s[4][0], s[4][1]); - // MIX2(s[5][0], s[5][1]); - // MIX2(s[6][0], s[6][1]); - // MIX2(s[7][0], s[7][1]); - // - // // Round 4 - // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 12); - // - // MIX2(s[0][0], s[0][1]); - // MIX2(s[1][0], s[1][1]); - // MIX2(s[2][0], s[2][1]); - // MIX2(s[3][0], s[3][1]); - // MIX2(s[4][0], s[4][1]); - // MIX2(s[5][0], s[5][1]); - // MIX2(s[6][0], s[6][1]); - // MIX2(s[7][0], s[7][1]); - // - // // Round 5 - // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 16); - // - // MIX2(s[0][0], s[0][1]); - // MIX2(s[1][0], s[1][1]); - // MIX2(s[2][0], s[2][1]); - // MIX2(s[3][0], s[3][1]); - // MIX2(s[4][0], s[4][1]); - // MIX2(s[5][0], s[5][1]); - // MIX2(s[6][0], s[6][1]); - // MIX2(s[7][0], s[7][1]); - // - // // Feed Forward - // s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); - // s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); - // s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 32)); - // s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 48)); - // s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 64)); - // s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 80)); - // s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 96)); - // s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 112)); - // s[4][0] = _mm_xor_si128(s[4][0], LOAD(in + 128)); - // s[4][1] = _mm_xor_si128(s[4][1], LOAD(in + 144)); - // s[5][0] = _mm_xor_si128(s[5][0], LOAD(in + 160)); - // s[5][1] = _mm_xor_si128(s[5][1], LOAD(in + 176)); - // s[6][0] = _mm_xor_si128(s[6][0], LOAD(in + 192)); - // s[6][1] = _mm_xor_si128(s[6][1], LOAD(in + 208)); - // s[7][0] = _mm_xor_si128(s[7][0], LOAD(in + 224)); - // s[7][1] = _mm_xor_si128(s[7][1], LOAD(in + 240)); - // - // STORE(out, s[0][0]); - // STORE(out + 16, s[0][1]); - // STORE(out + 32, s[1][0]); - // STORE(out + 48, s[1][1]); - // STORE(out + 64, s[2][0]); - // STORE(out + 80, s[2][1]); - // STORE(out + 96, s[3][0]); - // STORE(out + 112, s[3][1]); - // STORE(out + 128, s[4][0]); - // STORE(out + 144, s[4][1]); - // STORE(out + 160, s[5][0]); - // STORE(out + 176, s[5][1]); - // STORE(out + 192, s[6][0]); - // STORE(out + 208, s[6][1]); - // STORE(out + 224, s[7][0]); - // STORE(out + 240, s[7][1]); -} - -void haraka512(unsigned char *out, const unsigned char *in) { - u128 s[4], tmp; - - s[0] = LOAD(in); - s[1] = LOAD(in + 16); - s[2] = LOAD(in + 32); - s[3] = LOAD(in + 48); - - AES4(s[0], s[1], s[2], s[3], 0); - MIX4(s[0], s[1], s[2], s[3]); - - AES4(s[0], s[1], s[2], s[3], 8); - MIX4(s[0], s[1], s[2], s[3]); - - AES4(s[0], s[1], s[2], s[3], 16); - MIX4(s[0], s[1], s[2], s[3]); - - AES4(s[0], s[1], s[2], s[3], 24); - MIX4(s[0], s[1], s[2], s[3]); - - AES4(s[0], s[1], s[2], s[3], 32); - MIX4(s[0], s[1], s[2], s[3]); - - s[0] = _mm_xor_si128(s[0], LOAD(in)); - s[1] = _mm_xor_si128(s[1], LOAD(in + 16)); - s[2] = _mm_xor_si128(s[2], LOAD(in + 32)); - s[3] = _mm_xor_si128(s[3], LOAD(in + 48)); - - TRUNCSTORE(out, s[0], s[1], s[2], s[3]); -} - -void haraka512_zero(unsigned char *out, const unsigned char *in) { - u128 s[4], tmp; - - s[0] = LOAD(in); - s[1] = LOAD(in + 16); - s[2] = LOAD(in + 32); - s[3] = LOAD(in + 48); - - AES4_zero(s[0], s[1], s[2], s[3], 0); - MIX4(s[0], s[1], s[2], s[3]); - - AES4_zero(s[0], s[1], s[2], s[3], 8); - MIX4(s[0], s[1], s[2], s[3]); - - AES4_zero(s[0], s[1], s[2], s[3], 16); - MIX4(s[0], s[1], s[2], s[3]); - - AES4_zero(s[0], s[1], s[2], s[3], 24); - MIX4(s[0], s[1], s[2], s[3]); - - AES4_zero(s[0], s[1], s[2], s[3], 32); - MIX4(s[0], s[1], s[2], s[3]); - - s[0] = _mm_xor_si128(s[0], LOAD(in)); - s[1] = _mm_xor_si128(s[1], LOAD(in + 16)); - s[2] = _mm_xor_si128(s[2], LOAD(in + 32)); - s[3] = _mm_xor_si128(s[3], LOAD(in + 48)); - - TRUNCSTORE(out, s[0], s[1], s[2], s[3]); -} - -void haraka512_4x(unsigned char *out, const unsigned char *in) { - u128 s[4][4], tmp; - - s[0][0] = LOAD(in); - s[0][1] = LOAD(in + 16); - s[0][2] = LOAD(in + 32); - s[0][3] = LOAD(in + 48); - s[1][0] = LOAD(in + 64); - s[1][1] = LOAD(in + 80); - s[1][2] = LOAD(in + 96); - s[1][3] = LOAD(in + 112); - s[2][0] = LOAD(in + 128); - s[2][1] = LOAD(in + 144); - s[2][2] = LOAD(in + 160); - s[2][3] = LOAD(in + 176); - s[3][0] = LOAD(in + 192); - s[3][1] = LOAD(in + 208); - s[3][2] = LOAD(in + 224); - s[3][3] = LOAD(in + 240); - - AES4_4x(s[0], s[1], s[2], s[3], 0); - MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - - AES4_4x(s[0], s[1], s[2], s[3], 8); - MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - - AES4_4x(s[0], s[1], s[2], s[3], 16); - MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - - AES4_4x(s[0], s[1], s[2], s[3], 24); - MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - - AES4_4x(s[0], s[1], s[2], s[3], 32); - MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - - - s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); - s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); - s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32)); - s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48)); - s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64)); - s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80)); - s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96)); - s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112)); - s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128)); - s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144)); - s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160)); - s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176)); - s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192)); - s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208)); - s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224)); - s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240)); - - TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]); - TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]); - TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]); - TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]); -} - -void haraka512_8x(unsigned char *out, const unsigned char *in) { - // This is faster on Skylake, the code below is faster on Haswell. - haraka512_4x(out, in); - haraka512_4x(out + 128, in + 256); - - // u128 s[8][4], tmp; - // - // s[0][0] = LOAD(in); - // s[0][1] = LOAD(in + 16); - // s[0][2] = LOAD(in + 32); - // s[0][3] = LOAD(in + 48); - // s[1][0] = LOAD(in + 64); - // s[1][1] = LOAD(in + 80); - // s[1][2] = LOAD(in + 96); - // s[1][3] = LOAD(in + 112); - // s[2][0] = LOAD(in + 128); - // s[2][1] = LOAD(in + 144); - // s[2][2] = LOAD(in + 160); - // s[2][3] = LOAD(in + 176); - // s[3][0] = LOAD(in + 192); - // s[3][1] = LOAD(in + 208); - // s[3][2] = LOAD(in + 224); - // s[3][3] = LOAD(in + 240); - // s[4][0] = LOAD(in + 256); - // s[4][1] = LOAD(in + 272); - // s[4][2] = LOAD(in + 288); - // s[4][3] = LOAD(in + 304); - // s[5][0] = LOAD(in + 320); - // s[5][1] = LOAD(in + 336); - // s[5][2] = LOAD(in + 352); - // s[5][3] = LOAD(in + 368); - // s[6][0] = LOAD(in + 384); - // s[6][1] = LOAD(in + 400); - // s[6][2] = LOAD(in + 416); - // s[6][3] = LOAD(in + 432); - // s[7][0] = LOAD(in + 448); - // s[7][1] = LOAD(in + 464); - // s[7][2] = LOAD(in + 480); - // s[7][3] = LOAD(in + 496); - // - // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 0); - // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); - // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); - // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); - // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); - // - // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 8); - // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); - // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); - // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); - // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); - // - // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 16); - // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); - // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); - // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); - // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); - // - // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 24); - // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); - // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); - // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); - // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); - // - // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 32); - // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); - // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); - // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); - // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); - // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); - // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); - // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); - // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); - // - // - // s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); - // s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); - // s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32)); - // s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48)); - // s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64)); - // s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80)); - // s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96)); - // s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112)); - // s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128)); - // s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144)); - // s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160)); - // s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176)); - // s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192)); - // s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208)); - // s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224)); - // s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240)); - // s[4][0] = _mm_xor_si128(s[4][0], LOAD(in + 256)); - // s[4][1] = _mm_xor_si128(s[4][1], LOAD(in + 272)); - // s[4][2] = _mm_xor_si128(s[4][2], LOAD(in + 288)); - // s[4][3] = _mm_xor_si128(s[4][3], LOAD(in + 304)); - // s[5][0] = _mm_xor_si128(s[5][0], LOAD(in + 320)); - // s[5][1] = _mm_xor_si128(s[5][1], LOAD(in + 336)); - // s[5][2] = _mm_xor_si128(s[5][2], LOAD(in + 352)); - // s[5][3] = _mm_xor_si128(s[5][3], LOAD(in + 368)); - // s[6][0] = _mm_xor_si128(s[6][0], LOAD(in + 384)); - // s[6][1] = _mm_xor_si128(s[6][1], LOAD(in + 400)); - // s[6][2] = _mm_xor_si128(s[6][2], LOAD(in + 416)); - // s[6][3] = _mm_xor_si128(s[6][3], LOAD(in + 432)); - // s[7][0] = _mm_xor_si128(s[7][0], LOAD(in + 448)); - // s[7][1] = _mm_xor_si128(s[7][1], LOAD(in + 464)); - // s[7][2] = _mm_xor_si128(s[7][2], LOAD(in + 480)); - // s[7][3] = _mm_xor_si128(s[7][3], LOAD(in + 496)); - // - // TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]); - // TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]); - // TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]); - // TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]); - // TRUNCSTORE(out + 128, s[4][0], s[4][1], s[4][2], s[4][3]); - // TRUNCSTORE(out + 160, s[5][0], s[5][1], s[5][2], s[5][3]); - // TRUNCSTORE(out + 192, s[6][0], s[6][1], s[6][2], s[6][3]); - // TRUNCSTORE(out + 224, s[7][0], s[7][1], s[7][2], s[7][3]); -} diff --git a/src/crypto/haraka.h b/src/crypto/haraka.h deleted file mode 100644 index daf657184fe..00000000000 --- a/src/crypto/haraka.h +++ /dev/null @@ -1,126 +0,0 @@ -/* -The MIT License (MIT) - -Copyright (c) 2016 kste - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - -Optimized Implementations for Haraka256 and Haraka512 -*/ -#ifndef HARAKA_H_ -#define HARAKA_H_ - -#include "immintrin.h" - -#define NUMROUNDS 5 - -#ifdef _WIN32 -typedef unsigned long long u64; -#else -typedef unsigned long u64; -#endif -typedef __m128i u128; - -extern u128 rc[40]; - -#define LOAD(src) _mm_load_si128((u128 *)(src)) -#define STORE(dest,src) _mm_storeu_si128((u128 *)(dest),src) - -#define AES2(s0, s1, rci) \ - s0 = _mm_aesenc_si128(s0, rc[rci]); \ - s1 = _mm_aesenc_si128(s1, rc[rci + 1]); \ - s0 = _mm_aesenc_si128(s0, rc[rci + 2]); \ - s1 = _mm_aesenc_si128(s1, rc[rci + 3]); - -#define AES2_4x(s0, s1, s2, s3, rci) \ - AES2(s0[0], s0[1], rci); \ - AES2(s1[0], s1[1], rci); \ - AES2(s2[0], s2[1], rci); \ - AES2(s3[0], s3[1], rci); - -#define AES2_8x(s0, s1, s2, s3, s4, s5, s6, s7, rci) \ - AES2_4x(s0, s1, s2, s3, rci); \ - AES2_4x(s4, s5, s6, s7, rci); - -#define AES4(s0, s1, s2, s3, rci) \ - s0 = _mm_aesenc_si128(s0, rc[rci]); \ - s1 = _mm_aesenc_si128(s1, rc[rci + 1]); \ - s2 = _mm_aesenc_si128(s2, rc[rci + 2]); \ - s3 = _mm_aesenc_si128(s3, rc[rci + 3]); \ - s0 = _mm_aesenc_si128(s0, rc[rci + 4]); \ - s1 = _mm_aesenc_si128(s1, rc[rci + 5]); \ - s2 = _mm_aesenc_si128(s2, rc[rci + 6]); \ - s3 = _mm_aesenc_si128(s3, rc[rci + 7]); \ - -#define AES4_zero(s0, s1, s2, s3, rci) \ - s0 = _mm_aesenc_si128(s0, rc0[rci]); \ - s1 = _mm_aesenc_si128(s1, rc0[rci + 1]); \ - s2 = _mm_aesenc_si128(s2, rc0[rci + 2]); \ - s3 = _mm_aesenc_si128(s3, rc0[rci + 3]); \ - s0 = _mm_aesenc_si128(s0, rc0[rci + 4]); \ - s1 = _mm_aesenc_si128(s1, rc0[rci + 5]); \ - s2 = _mm_aesenc_si128(s2, rc0[rci + 6]); \ - s3 = _mm_aesenc_si128(s3, rc0[rci + 7]); \ - -#define AES4_4x(s0, s1, s2, s3, rci) \ - AES4(s0[0], s0[1], s0[2], s0[3], rci); \ - AES4(s1[0], s1[1], s1[2], s1[3], rci); \ - AES4(s2[0], s2[1], s2[2], s2[3], rci); \ - AES4(s3[0], s3[1], s3[2], s3[3], rci); - -#define AES4_8x(s0, s1, s2, s3, s4, s5, s6, s7, rci) \ - AES4_4x(s0, s1, s2, s3, rci); \ - AES4_4x(s4, s5, s6, s7, rci); - -#define MIX2(s0, s1) \ - tmp = _mm_unpacklo_epi32(s0, s1); \ - s1 = _mm_unpackhi_epi32(s0, s1); \ - s0 = tmp; - -#define MIX4(s0, s1, s2, s3) \ - tmp = _mm_unpacklo_epi32(s0, s1); \ - s0 = _mm_unpackhi_epi32(s0, s1); \ - s1 = _mm_unpacklo_epi32(s2, s3); \ - s2 = _mm_unpackhi_epi32(s2, s3); \ - s3 = _mm_unpacklo_epi32(s0, s2); \ - s0 = _mm_unpackhi_epi32(s0, s2); \ - s2 = _mm_unpackhi_epi32(s1, tmp); \ - s1 = _mm_unpacklo_epi32(s1, tmp); - -#define TRUNCSTORE(out, s0, s1, s2, s3) \ - *(u64*)(out) = (u64*)(s0)[1]; \ - *(u64*)(out + 8) = (u64*)(s1)[1]; \ - *(u64*)(out + 16) = (u64*)(s2)[0]; \ - *(u64*)(out + 24) = (u64*)(s3)[0]; - -void load_constants(); -void test_implementations(); - -void load_constants(); - -void haraka256(unsigned char *out, const unsigned char *in); -void haraka256_4x(unsigned char *out, const unsigned char *in); -void haraka256_8x(unsigned char *out, const unsigned char *in); - -void haraka512(unsigned char *out, const unsigned char *in); -void haraka512_zero(unsigned char *out, const unsigned char *in); -void haraka512_4x(unsigned char *out, const unsigned char *in); -void haraka512_8x(unsigned char *out, const unsigned char *in); - -#endif diff --git a/src/crypto/haraka_portable.c b/src/crypto/haraka_portable.c deleted file mode 100644 index 0792f8b2f7d..00000000000 --- a/src/crypto/haraka_portable.c +++ /dev/null @@ -1,375 +0,0 @@ -/* -Plain C implementation of the Haraka256 and Haraka512 permutations. -*/ -#include -#include -#include - -#include "haraka_portable.h" - -#define HARAKAS_RATE 32 - -static const unsigned char haraka_rc[40][16] = { - {0x9d, 0x7b, 0x81, 0x75, 0xf0, 0xfe, 0xc5, 0xb2, 0x0a, 0xc0, 0x20, 0xe6, 0x4c, 0x70, 0x84, 0x06}, - {0x17, 0xf7, 0x08, 0x2f, 0xa4, 0x6b, 0x0f, 0x64, 0x6b, 0xa0, 0xf3, 0x88, 0xe1, 0xb4, 0x66, 0x8b}, - {0x14, 0x91, 0x02, 0x9f, 0x60, 0x9d, 0x02, 0xcf, 0x98, 0x84, 0xf2, 0x53, 0x2d, 0xde, 0x02, 0x34}, - {0x79, 0x4f, 0x5b, 0xfd, 0xaf, 0xbc, 0xf3, 0xbb, 0x08, 0x4f, 0x7b, 0x2e, 0xe6, 0xea, 0xd6, 0x0e}, - {0x44, 0x70, 0x39, 0xbe, 0x1c, 0xcd, 0xee, 0x79, 0x8b, 0x44, 0x72, 0x48, 0xcb, 0xb0, 0xcf, 0xcb}, - {0x7b, 0x05, 0x8a, 0x2b, 0xed, 0x35, 0x53, 0x8d, 0xb7, 0x32, 0x90, 0x6e, 0xee, 0xcd, 0xea, 0x7e}, - {0x1b, 0xef, 0x4f, 0xda, 0x61, 0x27, 0x41, 0xe2, 0xd0, 0x7c, 0x2e, 0x5e, 0x43, 0x8f, 0xc2, 0x67}, - {0x3b, 0x0b, 0xc7, 0x1f, 0xe2, 0xfd, 0x5f, 0x67, 0x07, 0xcc, 0xca, 0xaf, 0xb0, 0xd9, 0x24, 0x29}, - {0xee, 0x65, 0xd4, 0xb9, 0xca, 0x8f, 0xdb, 0xec, 0xe9, 0x7f, 0x86, 0xe6, 0xf1, 0x63, 0x4d, 0xab}, - {0x33, 0x7e, 0x03, 0xad, 0x4f, 0x40, 0x2a, 0x5b, 0x64, 0xcd, 0xb7, 0xd4, 0x84, 0xbf, 0x30, 0x1c}, - {0x00, 0x98, 0xf6, 0x8d, 0x2e, 0x8b, 0x02, 0x69, 0xbf, 0x23, 0x17, 0x94, 0xb9, 0x0b, 0xcc, 0xb2}, - {0x8a, 0x2d, 0x9d, 0x5c, 0xc8, 0x9e, 0xaa, 0x4a, 0x72, 0x55, 0x6f, 0xde, 0xa6, 0x78, 0x04, 0xfa}, - {0xd4, 0x9f, 0x12, 0x29, 0x2e, 0x4f, 0xfa, 0x0e, 0x12, 0x2a, 0x77, 0x6b, 0x2b, 0x9f, 0xb4, 0xdf}, - {0xee, 0x12, 0x6a, 0xbb, 0xae, 0x11, 0xd6, 0x32, 0x36, 0xa2, 0x49, 0xf4, 0x44, 0x03, 0xa1, 0x1e}, - {0xa6, 0xec, 0xa8, 0x9c, 0xc9, 0x00, 0x96, 0x5f, 0x84, 0x00, 0x05, 0x4b, 0x88, 0x49, 0x04, 0xaf}, - {0xec, 0x93, 0xe5, 0x27, 0xe3, 0xc7, 0xa2, 0x78, 0x4f, 0x9c, 0x19, 0x9d, 0xd8, 0x5e, 0x02, 0x21}, - {0x73, 0x01, 0xd4, 0x82, 0xcd, 0x2e, 0x28, 0xb9, 0xb7, 0xc9, 0x59, 0xa7, 0xf8, 0xaa, 0x3a, 0xbf}, - {0x6b, 0x7d, 0x30, 0x10, 0xd9, 0xef, 0xf2, 0x37, 0x17, 0xb0, 0x86, 0x61, 0x0d, 0x70, 0x60, 0x62}, - {0xc6, 0x9a, 0xfc, 0xf6, 0x53, 0x91, 0xc2, 0x81, 0x43, 0x04, 0x30, 0x21, 0xc2, 0x45, 0xca, 0x5a}, - {0x3a, 0x94, 0xd1, 0x36, 0xe8, 0x92, 0xaf, 0x2c, 0xbb, 0x68, 0x6b, 0x22, 0x3c, 0x97, 0x23, 0x92}, - {0xb4, 0x71, 0x10, 0xe5, 0x58, 0xb9, 0xba, 0x6c, 0xeb, 0x86, 0x58, 0x22, 0x38, 0x92, 0xbf, 0xd3}, - {0x8d, 0x12, 0xe1, 0x24, 0xdd, 0xfd, 0x3d, 0x93, 0x77, 0xc6, 0xf0, 0xae, 0xe5, 0x3c, 0x86, 0xdb}, - {0xb1, 0x12, 0x22, 0xcb, 0xe3, 0x8d, 0xe4, 0x83, 0x9c, 0xa0, 0xeb, 0xff, 0x68, 0x62, 0x60, 0xbb}, - {0x7d, 0xf7, 0x2b, 0xc7, 0x4e, 0x1a, 0xb9, 0x2d, 0x9c, 0xd1, 0xe4, 0xe2, 0xdc, 0xd3, 0x4b, 0x73}, - {0x4e, 0x92, 0xb3, 0x2c, 0xc4, 0x15, 0x14, 0x4b, 0x43, 0x1b, 0x30, 0x61, 0xc3, 0x47, 0xbb, 0x43}, - {0x99, 0x68, 0xeb, 0x16, 0xdd, 0x31, 0xb2, 0x03, 0xf6, 0xef, 0x07, 0xe7, 0xa8, 0x75, 0xa7, 0xdb}, - {0x2c, 0x47, 0xca, 0x7e, 0x02, 0x23, 0x5e, 0x8e, 0x77, 0x59, 0x75, 0x3c, 0x4b, 0x61, 0xf3, 0x6d}, - {0xf9, 0x17, 0x86, 0xb8, 0xb9, 0xe5, 0x1b, 0x6d, 0x77, 0x7d, 0xde, 0xd6, 0x17, 0x5a, 0xa7, 0xcd}, - {0x5d, 0xee, 0x46, 0xa9, 0x9d, 0x06, 0x6c, 0x9d, 0xaa, 0xe9, 0xa8, 0x6b, 0xf0, 0x43, 0x6b, 0xec}, - {0xc1, 0x27, 0xf3, 0x3b, 0x59, 0x11, 0x53, 0xa2, 0x2b, 0x33, 0x57, 0xf9, 0x50, 0x69, 0x1e, 0xcb}, - {0xd9, 0xd0, 0x0e, 0x60, 0x53, 0x03, 0xed, 0xe4, 0x9c, 0x61, 0xda, 0x00, 0x75, 0x0c, 0xee, 0x2c}, - {0x50, 0xa3, 0xa4, 0x63, 0xbc, 0xba, 0xbb, 0x80, 0xab, 0x0c, 0xe9, 0x96, 0xa1, 0xa5, 0xb1, 0xf0}, - {0x39, 0xca, 0x8d, 0x93, 0x30, 0xde, 0x0d, 0xab, 0x88, 0x29, 0x96, 0x5e, 0x02, 0xb1, 0x3d, 0xae}, - {0x42, 0xb4, 0x75, 0x2e, 0xa8, 0xf3, 0x14, 0x88, 0x0b, 0xa4, 0x54, 0xd5, 0x38, 0x8f, 0xbb, 0x17}, - {0xf6, 0x16, 0x0a, 0x36, 0x79, 0xb7, 0xb6, 0xae, 0xd7, 0x7f, 0x42, 0x5f, 0x5b, 0x8a, 0xbb, 0x34}, - {0xde, 0xaf, 0xba, 0xff, 0x18, 0x59, 0xce, 0x43, 0x38, 0x54, 0xe5, 0xcb, 0x41, 0x52, 0xf6, 0x26}, - {0x78, 0xc9, 0x9e, 0x83, 0xf7, 0x9c, 0xca, 0xa2, 0x6a, 0x02, 0xf3, 0xb9, 0x54, 0x9a, 0xe9, 0x4c}, - {0x35, 0x12, 0x90, 0x22, 0x28, 0x6e, 0xc0, 0x40, 0xbe, 0xf7, 0xdf, 0x1b, 0x1a, 0xa5, 0x51, 0xae}, - {0xcf, 0x59, 0xa6, 0x48, 0x0f, 0xbc, 0x73, 0xc1, 0x2b, 0xd2, 0x7e, 0xba, 0x3c, 0x61, 0xc1, 0xa0}, - {0xa1, 0x9d, 0xc5, 0xe9, 0xfd, 0xbd, 0xd6, 0x4a, 0x88, 0x82, 0x28, 0x02, 0x03, 0xcc, 0x6a, 0x75} -}; - -static unsigned char rc[40][16]; -static unsigned char rc0[40][16]; -static unsigned char rc_sseed[40][16]; - -static const unsigned char sbox[256] = -{ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, - 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, - 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, - 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, - 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, - 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, - 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, - 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, - 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, - 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, - 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, - 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, - 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, - 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, - 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, - 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, - 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, - 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, - 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, - 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; - -#define XT(x) (((x) << 1) ^ ((((x) >> 7) & 1) * 0x1b)) - -// Simulate _mm_aesenc_si128 instructions from AESNI -void aesenc(unsigned char *s, const unsigned char *rk) -{ - unsigned char i, t, u, v[4][4]; - for (i = 0; i < 16; ++i) { - v[((i / 4) + 4 - (i%4) ) % 4][i % 4] = sbox[s[i]]; - } - for (i = 0; i < 4; ++i) { - t = v[i][0]; - u = v[i][0] ^ v[i][1] ^ v[i][2] ^ v[i][3]; - v[i][0] ^= u ^ XT(v[i][0] ^ v[i][1]); - v[i][1] ^= u ^ XT(v[i][1] ^ v[i][2]); - v[i][2] ^= u ^ XT(v[i][2] ^ v[i][3]); - v[i][3] ^= u ^ XT(v[i][3] ^ t); - } - for (i = 0; i < 16; ++i) { - s[i] = v[i / 4][i % 4] ^ rk[i]; - } -} - -// Simulate _mm_unpacklo_epi32 -void unpacklo32(unsigned char *t, unsigned char *a, unsigned char *b) -{ - unsigned char tmp[16]; - memcpy(tmp, a, 4); - memcpy(tmp + 4, b, 4); - memcpy(tmp + 8, a + 4, 4); - memcpy(tmp + 12, b + 4, 4); - memcpy(t, tmp, 16); -} - -// Simulate _mm_unpackhi_epi32 -void unpackhi32(unsigned char *t, unsigned char *a, unsigned char *b) -{ - unsigned char tmp[16]; - memcpy(tmp, a + 8, 4); - memcpy(tmp + 4, b + 8, 4); - memcpy(tmp + 8, a + 12, 4); - memcpy(tmp + 12, b + 12, 4); - memcpy(t, tmp, 16); -} - -void load_constants_port() -{ - /* Use the standard constants to generate tweaked ones. */ - memcpy(rc, haraka_rc, 40*16); -} - -void tweak_constants(const unsigned char *pk_seed, const unsigned char *sk_seed, - unsigned long long seed_length) -{ - unsigned char buf[40*16]; - - /* Use the standard constants to generate tweaked ones. */ - memcpy(rc, haraka_rc, 40*16); - - /* Constants for sk.seed */ - if (sk_seed != NULL) { - haraka_S(buf, 40*16, sk_seed, seed_length); - memcpy(rc_sseed, buf, 40*16); - } - - /* Constants for pk.seed */ - haraka_S(buf, 40*16, pk_seed, seed_length); - memcpy(rc, buf, 40*16); -} - -static void haraka_S_absorb(unsigned char *s, unsigned int r, - const unsigned char *m, unsigned long long mlen, - unsigned char p) -{ - unsigned long long i; - unsigned char t[r]; - - while (mlen >= r) { - // XOR block to state - for (i = 0; i < r; ++i) { - s[i] ^= m[i]; - } - haraka512_perm(s, s); - mlen -= r; - m += r; - } - - for (i = 0; i < r; ++i) { - t[i] = 0; - } - for (i = 0; i < mlen; ++i) { - t[i] = m[i]; - } - t[i] = p; - t[r - 1] |= 128; - for (i = 0; i < r; ++i) { - s[i] ^= t[i]; - } -} - -static void haraka_S_squeezeblocks(unsigned char *h, unsigned long long nblocks, - unsigned char *s, unsigned int r) -{ - while (nblocks > 0) { - haraka512_perm(s, s); - memcpy(h, s, HARAKAS_RATE); - h += r; - nblocks--; - } -} - - -void haraka_S(unsigned char *out, unsigned long long outlen, - const unsigned char *in, unsigned long long inlen) -{ - unsigned long long i; - unsigned char s[64]; - unsigned char d[32]; - - for (i = 0; i < 64; i++) { - s[i] = 0; - } - haraka_S_absorb(s, 32, in, inlen, 0x1F); - - haraka_S_squeezeblocks(out, outlen / 32, s, 32); - out += (outlen / 32) * 32; - - if (outlen % 32) { - haraka_S_squeezeblocks(d, 1, s, 32); - for (i = 0; i < outlen % 32; i++) { - out[i] = d[i]; - } - } -} - -void haraka512_perm(unsigned char *out, const unsigned char *in) -{ - int i, j; - - unsigned char s[64], tmp[16]; - - memcpy(s, in, 16); - memcpy(s + 16, in + 16, 16); - memcpy(s + 32, in + 32, 16); - memcpy(s + 48, in + 48, 16); - - for (i = 0; i < 5; ++i) { - // aes round(s) - for (j = 0; j < 2; ++j) { - aesenc(s, rc[4*2*i + 4*j]); - aesenc(s + 16, rc[4*2*i + 4*j + 1]); - aesenc(s + 32, rc[4*2*i + 4*j + 2]); - aesenc(s + 48, rc[4*2*i + 4*j + 3]); - } - - // mixing - unpacklo32(tmp, s, s + 16); - unpackhi32(s, s, s + 16); - unpacklo32(s + 16, s + 32, s + 48); - unpackhi32(s + 32, s + 32, s + 48); - unpacklo32(s + 48, s, s + 32); - unpackhi32(s, s, s + 32); - unpackhi32(s + 32, s + 16, tmp); - unpacklo32(s + 16, s + 16, tmp); - } - - memcpy(out, s, 64); -} - -void haraka512_port(unsigned char *out, const unsigned char *in) -{ - int i; - - unsigned char buf[64]; - - haraka512_perm(buf, in); - /* Feed-forward */ - for (i = 0; i < 64; i++) { - buf[i] = buf[i] ^ in[i]; - } - - /* Truncated */ - memcpy(out, buf + 8, 8); - memcpy(out + 8, buf + 24, 8); - memcpy(out + 16, buf + 32, 8); - memcpy(out + 24, buf + 48, 8); -} - -void haraka512_perm_zero(unsigned char *out, const unsigned char *in) -{ - int i, j; - - unsigned char s[64], tmp[16]; - - memcpy(s, in, 16); - memcpy(s + 16, in + 16, 16); - memcpy(s + 32, in + 32, 16); - memcpy(s + 48, in + 48, 16); - - for (i = 0; i < 5; ++i) { - // aes round(s) - for (j = 0; j < 2; ++j) { - aesenc(s, rc0[4*2*i + 4*j]); - aesenc(s + 16, rc0[4*2*i + 4*j + 1]); - aesenc(s + 32, rc0[4*2*i + 4*j + 2]); - aesenc(s + 48, rc0[4*2*i + 4*j + 3]); - } - - // mixing - unpacklo32(tmp, s, s + 16); - unpackhi32(s, s, s + 16); - unpacklo32(s + 16, s + 32, s + 48); - unpackhi32(s + 32, s + 32, s + 48); - unpacklo32(s + 48, s, s + 32); - unpackhi32(s, s, s + 32); - unpackhi32(s + 32, s + 16, tmp); - unpacklo32(s + 16, s + 16, tmp); - } - - memcpy(out, s, 64); -} - -void haraka512_port_zero(unsigned char *out, const unsigned char *in) -{ - int i; - - unsigned char buf[64]; - - haraka512_perm_zero(buf, in); - /* Feed-forward */ - for (i = 0; i < 64; i++) { - buf[i] = buf[i] ^ in[i]; - } - - /* Truncated */ - memcpy(out, buf + 8, 8); - memcpy(out + 8, buf + 24, 8); - memcpy(out + 16, buf + 32, 8); - memcpy(out + 24, buf + 48, 8); -} - -void haraka256_port(unsigned char *out, const unsigned char *in) -{ - int i, j; - - unsigned char s[32], tmp[16]; - - memcpy(s, in, 16); - memcpy(s + 16, in + 16, 16); - - for (i = 0; i < 5; ++i) { - // aes round(s) - for (j = 0; j < 2; ++j) { - aesenc(s, rc[2*2*i + 2*j]); - aesenc(s + 16, rc[2*2*i + 2*j + 1]); - } - - // mixing - unpacklo32(tmp, s, s + 16); - unpackhi32(s + 16, s, s + 16); - memcpy(s, tmp, 16); - } - - /* Feed-forward */ - for (i = 0; i < 32; i++) { - out[i] = in[i] ^ s[i]; - } -} - -void haraka256_sk(unsigned char *out, const unsigned char *in) -{ - int i, j; - - unsigned char s[32], tmp[16]; - - memcpy(s, in, 16); - memcpy(s + 16, in + 16, 16); - - for (i = 0; i < 5; ++i) { - // aes round(s) - for (j = 0; j < 2; ++j) { - aesenc(s, rc_sseed[2*2*i + 2*j]); - aesenc(s + 16, rc_sseed[2*2*i + 2*j + 1]); - } - - // mixing - unpacklo32(tmp, s, s + 16); - unpackhi32(s + 16, s, s + 16); - memcpy(s, tmp, 16); - } - - /* Feed-forward */ - for (i = 0; i < 32; i++) { - out[i] = in[i] ^ s[i]; - } -} diff --git a/src/crypto/haraka_portable.h b/src/crypto/haraka_portable.h deleted file mode 100644 index dcc4f65aef4..00000000000 --- a/src/crypto/haraka_portable.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef SPX_HARAKA_H -#define SPX_HARAKA_H - -/* load constants */ -void load_constants_port(); - -/* Tweak constants with seed */ -void tweak_constants(const unsigned char *pk_seed, const unsigned char *sk_seed, - unsigned long long seed_length); - -/* Haraka Sponge */ -void haraka_S(unsigned char *out, unsigned long long outlen, - const unsigned char *in, unsigned long long inlen); - -/* Applies the 512-bit Haraka permutation to in. */ -void haraka512_perm(unsigned char *out, const unsigned char *in); - -/* Implementation of Haraka-512 */ -void haraka512_port(unsigned char *out, const unsigned char *in); - -/* Applies the 512-bit Haraka permutation to in, using zero key. */ -void haraka512_perm_zero(unsigned char *out, const unsigned char *in); - -/* Implementation of Haraka-512, using zero key */ -void haraka512_port_zero(unsigned char *out, const unsigned char *in); - -/* Implementation of Haraka-256 */ -void haraka256_port(unsigned char *out, const unsigned char *in); - -/* Implementation of Haraka-256 using sk.seed constants */ -void haraka256_sk(unsigned char *out, const unsigned char *in); - -#endif diff --git a/src/crypto/verus_hash.cpp b/src/crypto/verus_hash.cpp deleted file mode 100644 index f5cb1c9f3db..00000000000 --- a/src/crypto/verus_hash.cpp +++ /dev/null @@ -1,180 +0,0 @@ -// (C) 2018 The Verus Developers -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -/* -This provides the PoW hash function for Verus, a CPU-optimized hash -function with a Haraka V2 core. Unlike Haraka, which is made for short -inputs only, Verus Hash takes any length of input and produces a 256 -bit output. -*/ -#include -#include "crypto/common.h" -#include "crypto/verus_hash.h" - -void (*CVerusHash::haraka512Function)(unsigned char *out, const unsigned char *in); - -void CVerusHash::Hash(void *result, const void *data, size_t _len) -{ - unsigned char buf[128]; - unsigned char *bufPtr = buf; - int nextOffset = 64; - uint32_t pos = 0, len = _len; - unsigned char *bufPtr2 = bufPtr + nextOffset; - unsigned char *ptr = (unsigned char *)data; - - // put our last result or zero at beginning of buffer each time - memset(bufPtr, 0, 32); - - // digest up to 32 bytes at a time - for ( ; pos < len; pos += 32) - { - if (len - pos >= 32) - { - memcpy(bufPtr + 32, ptr + pos, 32); - } - else - { - int i = (int)(len - pos); - memcpy(bufPtr + 32, ptr + pos, i); - memset(bufPtr + 32 + i, 0, 32 - i); - } - (*haraka512Function)(bufPtr2, bufPtr); - bufPtr2 = bufPtr; - bufPtr += nextOffset; - nextOffset *= -1; - } - memcpy(result, bufPtr, 32); -}; - -void CVerusHash::init() -{ - if (IsCPUVerusOptimized()) - { - haraka512Function = &haraka512_zero; - } - else - { - haraka512Function = &haraka512_port_zero; - } -} - -CVerusHash &CVerusHash::Write(const unsigned char *data, size_t _len) -{ - unsigned char *tmp; - uint32_t pos, len = _len; - - // digest up to 32 bytes at a time - for ( pos = 0; pos < len; ) - { - uint32_t room = 32 - curPos; - - if (len - pos >= room) - { - memcpy(curBuf + 32 + curPos, data + pos, room); - (*haraka512Function)(result, curBuf); - tmp = curBuf; - curBuf = result; - result = tmp; - pos += room; - curPos = 0; - } - else - { - memcpy(curBuf + 32 + curPos, data + pos, len - pos); - curPos += len - pos; - pos = len; - } - } - return *this; -} - -// to be declared and accessed from C -void verus_hash(void *result, const void *data, size_t len) -{ - return CVerusHash::Hash(result, data, len); -} - -void (*CVerusHashV2::haraka512Function)(unsigned char *out, const unsigned char *in); - -void CVerusHashV2::init() -{ - if (IsCPUVerusOptimized()) - { - load_constants(); - haraka512Function = &haraka512; - } - else - { - // load and tweak the haraka constants - load_constants_port(); - haraka512Function = &haraka512_port; - } -} - -void CVerusHashV2::Hash(void *result, const void *data, size_t len) -{ - unsigned char buf[128]; - unsigned char *bufPtr = buf; - int pos = 0, nextOffset = 64; - unsigned char *bufPtr2 = bufPtr + nextOffset; - unsigned char *ptr = (unsigned char *)data; - - // put our last result or zero at beginning of buffer each time - memset(bufPtr, 0, 32); - - // digest up to 32 bytes at a time - for ( ; pos < len; pos += 32) - { - if (len - pos >= 32) - { - memcpy(bufPtr + 32, ptr + pos, 32); - } - else - { - int i = (int)(len - pos); - memcpy(bufPtr + 32, ptr + pos, i); - memset(bufPtr + 32 + i, 0, 32 - i); - } - (*haraka512Function)(bufPtr2, bufPtr); - bufPtr2 = bufPtr; - bufPtr += nextOffset; - nextOffset *= -1; - } - memcpy(result, bufPtr, 32); -}; - -CVerusHashV2 &CVerusHashV2::Write(const unsigned char *data, size_t len) -{ - unsigned char *tmp; - - // digest up to 32 bytes at a time - for ( int pos = 0; pos < len; ) - { - int room = 32 - curPos; - - if (len - pos >= room) - { - memcpy(curBuf + 32 + curPos, data + pos, room); - (*haraka512Function)(result, curBuf); - tmp = curBuf; - curBuf = result; - result = tmp; - pos += room; - curPos = 0; - } - else - { - memcpy(curBuf + 32 + curPos, data + pos, len - pos); - curPos += len - pos; - pos = len; - } - } - return *this; -} - -// to be declared and accessed from C -void verus_hash_v2(void *result, const void *data, size_t len) -{ - return CVerusHashV2::Hash(result, data, len); -} diff --git a/src/crypto/verus_hash.h b/src/crypto/verus_hash.h deleted file mode 100644 index 63ff1aaaa27..00000000000 --- a/src/crypto/verus_hash.h +++ /dev/null @@ -1,134 +0,0 @@ -// (C) 2018 Michael Toutonghi -// Distributed under the MIT software license, see the accompanying -// file COPYING or http://www.opensource.org/licenses/mit-license.php. - -/* -This provides the PoW hash function for Verus, enabling CPU mining. -*/ -#ifndef VERUS_HASH_H_ -#define VERUS_HASH_H_ - -#include -#include - -#include - -extern "C" -{ -#include "crypto/haraka.h" -#include "crypto/haraka_portable.h" -} - -class CVerusHash -{ - public: - static void Hash(void *result, const void *data, size_t len); - static void (*haraka512Function)(unsigned char *out, const unsigned char *in); - - static void init(); - - CVerusHash() { } - - CVerusHash &Write(const unsigned char *data, size_t len); - - CVerusHash &Reset() - { - curBuf = buf1; - result = buf2; - curPos = 0; - std::fill(buf1, buf1 + sizeof(buf1), 0); - return *this; - } - - int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } - void ClearExtra() - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - } - } - void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } - - void Finalize(unsigned char hash[32]) - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - (*haraka512Function)(hash, curBuf); - } - else - std::memcpy(hash, curBuf, 32); - } - - private: - // only buf1, the first source, needs to be zero initialized - unsigned char buf1[64] = {0}, buf2[64]; - unsigned char *curBuf = buf1, *result = buf2; - size_t curPos = 0; -}; - -class CVerusHashV2 -{ - public: - static void Hash(void *result, const void *data, size_t len); - static void (*haraka512Function)(unsigned char *out, const unsigned char *in); - - static void init(); - - CVerusHashV2() {} - - CVerusHashV2 &Write(const unsigned char *data, size_t len); - - CVerusHashV2 &Reset() - { - curBuf = buf1; - result = buf2; - curPos = 0; - std::fill(buf1, buf1 + sizeof(buf1), 0); - return *this; - } - - int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } - void ClearExtra() - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - } - } - void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } - - void Finalize(unsigned char hash[32]) - { - if (curPos) - { - std::fill(curBuf + 32 + curPos, curBuf + 64, 0); - (*haraka512Function)(hash, curBuf); - } - else - std::memcpy(hash, curBuf, 32); - } - - private: - // only buf1, the first source, needs to be zero initialized - unsigned char buf1[64] = {0}, buf2[64]; - unsigned char *curBuf = buf1, *result = buf2; - size_t curPos = 0; -}; - -extern void verus_hash(void *result, const void *data, size_t len); -extern void verus_hash_v2(void *result, const void *data, size_t len); - -inline bool IsCPUVerusOptimized() -{ - unsigned int eax,ebx,ecx,edx; - - if (!__get_cpuid(1,&eax,&ebx,&ecx,&edx)) - { - return false; - } - return ((ecx & (bit_AVX | bit_AES)) == (bit_AVX | bit_AES)); -}; - -#endif diff --git a/src/fiat/verus.bat b/src/fiat/verus.bat deleted file mode 100644 index 0bf87d33bed..00000000000 --- a/src/fiat/verus.bat +++ /dev/null @@ -1,14 +0,0 @@ -@call :GET_CURRENT_DIR -@cd %THIS_DIR% -komodo-cli.exe -ac_name=VRSC %1 %2 %3 %4 %5 %6 %7 %8 %9 -@goto :EOF - -:GET_CURRENT_DIR -@pushd %~dp0 -@set THIS_DIR=%CD% -@popd -@goto :EOF - - - - diff --git a/src/hush-cli b/src/hush-cli deleted file mode 100755 index efa1840a6fc..00000000000 --- a/src/hush-cli +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/bash -# Copyright (c) 2019 Hush developers - -# set working directory to the location of this script -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR - -NAME=HUSH3 - -CLI=${KOMODOCLI:-./komodo-cli} -$CLI -ac_name=$NAME "$@" diff --git a/src/hushd b/src/hushd deleted file mode 100755 index 949779a90c1..00000000000 --- a/src/hushd +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/bash -# Copyright (c) 2019 Hush developers - -# set working directory to the location of this script -DIR="$( cd "$( dirname "$( readlink -f "${BASH_SOURCE[0]}" )" )" && pwd )" -cd $DIR - -NAME=HUSH3 -# this corresponds to FR address RHushEyeDm7XwtaTWtyCbjGQumYyV8vMjn -SCRIPT=76a9145eb10cf64f2bab1b457f1f25e658526155928fac88ac - -# Chain parameters -ERAS=3 -BLOCKTIME=150 -# 6250000 - (sprout pool at block 500,000) -SUPPLY=6178674 -FOUNDERS=1 -REWARD=0,1125000000,562500000 -PERC=11111111 -HALVING=129,340000,840000 -# NOTE: keep in sync with komodo_bitcoind.h -END=128,340000,5422111 -CLIENTNAME=GoldenSandtrout -SEEDNODE1=188.165.212.101 -SEEDNODE2=136.243.227.142 -SEEDNODE3=5.9.224.250 -CCLIB=hush3 - -# CryptoConditions/Custom Consensus params -FAUCET=228 -HEIR=234 -CHANNEL=235 -ORACLE=236 -GATEWAY=241 -CCENABLE=$FAUCET,$HEIR,$CHANNEL,$ORACLE,$GATEWAY - -KMD=${KOMODOD:-./komodod} -$KMD -ac_name=$NAME -ac_sapling=1 \ - -ac_reward=$REWARD \ - -ac_halving=$HALVING \ - -ac_end=$END \ - -ac_eras=$ERAS \ - -ac_blocktime=$BLOCKTIME \ - -ac_cc=2 -ac_ccenable=$CCENABLE \ - -ac_founders=$FOUNDERS -ac_supply=$SUPPLY \ - -ac_perc=$PERC \ - -clientname=$CLIENTNAME \ - -addnode=$SEEDNODE1 \ - -addnode=$SEEDNODE2 \ - -addnode=$SEEDNODE3 \ - -ac_cclib=$CCLIB \ - -ac_script=$SCRIPT "$@" diff --git a/src/verusd b/src/verusd deleted file mode 100755 index 17958551933..00000000000 --- a/src/verusd +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash -#set working directory to the location of this script -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -cd $DIR -./komodod -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -ac_veruspos=50 "$@" diff --git a/src/verusd.bat b/src/verusd.bat deleted file mode 100644 index b921ed4527c..00000000000 --- a/src/verusd.bat +++ /dev/null @@ -1,10 +0,0 @@ -@call :GET_CURRENT_DIR -@cd %THIS_DIR% -komodod.exe -ac_name=VRSC -ac_algo=verushash -ac_cc=1 -ac_supply=0 -ac_eras=3 -ac_reward=0,38400000000,2400000000 -ac_halving=1,43200,1051920 -ac_decay=100000000,0,0 -ac_end=10080,226080,0 -ac_timelockgte=19200000000 -ac_timeunlockfrom=129600 -ac_timeunlockto=1180800 -ac_veruspos=50 %1 %2 %3 %4 %5 %6 %7 %8 %9 -@goto :EOF - -:GET_CURRENT_DIR -@pushd %~dp0 -@set THIS_DIR=%CD% -@popd -@goto :EOF diff --git a/zcutil/VerusCoin.xml b/zcutil/VerusCoin.xml deleted file mode 100644 index 914e2f14b2d..00000000000 --- a/zcutil/VerusCoin.xml +++ /dev/null @@ -1,432 +0,0 @@ - - VerusCoin - VerusCoin - 0.3.12 - ${product_shortname}-v${product_version}-${platform_name}-installer.${platform_exec_suffix} - ../COPYING - ../assets/imgs/VRSC_256x256.png - ../assets/imgs/VRSC_256x256.png - ../assets/imgs/VRSC_256x256.png - 1 - - - VerusCoin - VerusCoin CLI - 1 - 1 - 1 - 1 - - - Agama - Verus-Enhanced Agama Wallet - 1 - 1 - 1 - 1 - - - Start Agama App - - ../assets/icons/agama_icons/256x256.png - Agama App - - all - 0 - 0 - ${installdir}/Agama/Agama-win32-x64/Agama.exe - - - ${windows_folder_common_programs}/ - - - - - Verus-Enhanced Agama Wallet - ${installdir}/Agama - Agama - all - - - ../Agama-win32-x64 - - - - - - - - - Program Files - ${installdir} - programfiles - all - - - Uninstall - ${installdir}/${uninstallerName} - - Uninstall ${product_fullname} - ${installdir} - all - 0 - 0 - ${installdir}/${uninstallerName}.exe - - - ${installdir} - - - - - VerusCoin - ${installdir}/ - VerusCoin - all - - - ../verus-cli - - - - - - - - - HKEY_LOCAL_MACHINE\SOFTWARE\${project.shortname} - uninstaller_path - uninstaller_path - - - previous_installation_exists - 1 - - - - - - - - ${uninstaller_path} - - - - equals - ${previous_installation_exists} - 1 - - - - - Deleting user data - ${windows_folder_appdata}/Agama - Deleting user data - - - equals - ${previous_installation_exists} - 1 - - - equals - ${installation_type} - uninstall - - - equals - ${delete_user_data} - 1 - - - - - Deleting iguana config json - ${windows_folder_appdata}/Iguana/config.json - Deleting iguana config - - - equals - ${previous_installation_exists} - 1 - - - equals - ${installation_type} - uninstall - - - equals - ${delete_config_data} - 1 - - - - - Uninstalled - Uninstalled - - - equals - ${previous_installation_exists} - 1 - - - equals - ${installation_type} - uninstall - - - - - Downloading files - - - 0 - Visual C++ Redistributable for Visual Studio 2015 library files are needed for Agama daemon - ${system_temp_directory}/vc_redist.x64.exe - Downloading Visual C++ Redistributable for Visual Studio 2015 - 0 - https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe - - - - - 1 - ${system_temp_directory}/vc_redist.x64.exe - - - - - 0 - Visual C++ Redistributable for Visual Studio 2015 library files are needed for Agama daemon - ${system_temp_directory}/vc_redist.x64.exe - /install /passive - Downloading Visual C++ Redistributable for Visual Studio 2015 - 0 - - - Downloading files - - - 0 - Visual C++ Redistributable for Visual Studio 2015 library files are needed for Agama daemon - ${system_temp_directory}/vc_redist.x86.exe - Downloading Visual C++ Redistributable for Visual Studio 2015 - 0 - https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe - - - - - 1 - ${system_temp_directory}/vc_redist.x86.exe - - - - - 0 - Visual C++ Redistributable for Visual Studio 2015 library files are needed for Agama daemon - ${system_temp_directory}/vc_redist.x86.exe - /install /passive - Downloading Visual C++ Redistributable for Visual Studio 2015 - 0 - - - 0 - Creating ZcashParam directory - ${windows_folder_appdata}/ZcashParams/ - Creating ZcashParam directory - 0 - - - 0 - Zcash Params file: sprout-proving.key - Zcash Params file: sprout-proving.key - 0 - Downloading Zcash Params file - - - 0 - Zcash Params file: sprout-proving.key - ${windows_folder_appdata}/ZcashParams/sprout-proving.key - Zcash Params file: sprout-proving.key - 0 - https://z.cash/downloads/sprout-proving.key - - - - - 1 - ${windows_folder_appdata}/ZcashParams/sprout-proving.key - - - - - 0 - Zcash Params file: sprout-verifying.key - Zcash Params file: sprout-verifying.key - Downloading Zcash Params files - - - 0 - Zcash Params file: sprout-verifying.key - ${windows_folder_appdata}/ZcashParams/sprout-verifying.key - Zcash Params file: sprout-verifying.key - 0 - https://z.cash/downloads/sprout-verifying.key - - - - - 1 - ${windows_folder_appdata}/ZcashParams/sprout-verifying.key - - - - - - - VERUS_HOME - system - ${installdir}/verus-cli/ - - - HKEY_LOCAL_MACHINE\SOFTWARE\${project.shortname} - uninstaller_path - REG_SZ - ${installdir}/${uninstallerName}.exe - - - - - C:\Windows\System32\ - Copying ReqCopying Required DLL filesuired DLL files - ${installdir}/resources/app/windeps/x86/vcruntime140d.dll - Copying ReqCopying Required DLL filesuired DLL files - - - - - - - - - - C:\Windows\System32\ - Copying ReqCopying Required DLL filesuired DLL files - ${installdir}/resources/app/windeps/x64/ucrtbased.dll - Copying ReqCopying Required DLL filesuired DLL files - - - C:\Windows\System32\ - Copying ReqCopying Required DLL filesuired DLL files - ${installdir}/resources/app/windeps/x64/vcruntime140d.dll - Copying ReqCopying Required DLL filesuired DLL files - - - C:\Windows\SysWOW64\ - Copying ReqCopying Required DLL filesuired DLL files - ${installdir}/resources/app/windeps/x86/ucrtbased.dll - Copying ReqCopying Required DLL filesuired DLL files - - - C:\Windows\SysWOW64\ - Copying ReqCopying Required DLL filesuired DLL files - ${installdir}/resources/app/windeps/x86/vcruntime140d.dll - Copying ReqCopying Required DLL filesuired DLL files - - - - - - - - - - HKEY_LOCAL_MACHINE\SOFTWARE\${project.shortname} - uninstaller_path - - - 1 - 1 - 1 - 1 - 1 - ../builds - 1 - ${windows_folder_appdata} - 1 - 1 - VerusCoin - 1 - - - installdir - Installer.Parameter.installdir.description - Installer.Parameter.installdir.explanation - - ${platform_install_prefix}/${product_shortname} - 0 - prefix - 1 - 0 - 30 - - - You don't have enough disk space to install the application, - please select another installation directory - - - less - ${installdir} - ${required_diskspace} - - - - - - - installation_type - Instalation type - Existing instalation is detected - Existing instalation is detected - uninstall - uninstall - - - uninstall - Uninstall - Uninstall - - - - - - 0 - 0 - - - - 0 - 0 - - - - - Upgrade - - - - - - - equals - ${previous_installation_exists} - 1 - - - - - - From 66c7fe487f4cb7afde025407ba5343dad81a4fd2 Mon Sep 17 00:00:00 2001 From: rumeysayilmaz Date: Tue, 1 Oct 2024 15:48:02 +0300 Subject: [PATCH 7/7] revert changes for physical removal of verus and haraka files --- src/crypto/haraka.c | 606 +++++++++++++++++++++++++++++++++++ src/crypto/haraka.h | 126 ++++++++ src/crypto/haraka_portable.c | 375 ++++++++++++++++++++++ src/crypto/haraka_portable.h | 33 ++ src/crypto/verus_hash.cpp | 180 +++++++++++ src/crypto/verus_hash.h | 134 ++++++++ 6 files changed, 1454 insertions(+) create mode 100644 src/crypto/haraka.c create mode 100644 src/crypto/haraka.h create mode 100644 src/crypto/haraka_portable.c create mode 100644 src/crypto/haraka_portable.h create mode 100644 src/crypto/verus_hash.cpp create mode 100644 src/crypto/verus_hash.h diff --git a/src/crypto/haraka.c b/src/crypto/haraka.c new file mode 100644 index 00000000000..d611b9af566 --- /dev/null +++ b/src/crypto/haraka.c @@ -0,0 +1,606 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 kste + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Optimized Implementations for Haraka256 and Haraka512 +*/ + +#include +#include "crypto/haraka.h" + +u128 rc[40]; +u128 rc0[40] = {0}; + +void load_constants() { + rc[0] = _mm_set_epi32(0x0684704c,0xe620c00a,0xb2c5fef0,0x75817b9d); + rc[1] = _mm_set_epi32(0x8b66b4e1,0x88f3a06b,0x640f6ba4,0x2f08f717); + rc[2] = _mm_set_epi32(0x3402de2d,0x53f28498,0xcf029d60,0x9f029114); + rc[3] = _mm_set_epi32(0x0ed6eae6,0x2e7b4f08,0xbbf3bcaf,0xfd5b4f79); + rc[4] = _mm_set_epi32(0xcbcfb0cb,0x4872448b,0x79eecd1c,0xbe397044); + rc[5] = _mm_set_epi32(0x7eeacdee,0x6e9032b7,0x8d5335ed,0x2b8a057b); + rc[6] = _mm_set_epi32(0x67c28f43,0x5e2e7cd0,0xe2412761,0xda4fef1b); + rc[7] = _mm_set_epi32(0x2924d9b0,0xafcacc07,0x675ffde2,0x1fc70b3b); + rc[8] = _mm_set_epi32(0xab4d63f1,0xe6867fe9,0xecdb8fca,0xb9d465ee); + rc[9] = _mm_set_epi32(0x1c30bf84,0xd4b7cd64,0x5b2a404f,0xad037e33); + rc[10] = _mm_set_epi32(0xb2cc0bb9,0x941723bf,0x69028b2e,0x8df69800); + rc[11] = _mm_set_epi32(0xfa0478a6,0xde6f5572,0x4aaa9ec8,0x5c9d2d8a); + rc[12] = _mm_set_epi32(0xdfb49f2b,0x6b772a12,0x0efa4f2e,0x29129fd4); + rc[13] = _mm_set_epi32(0x1ea10344,0xf449a236,0x32d611ae,0xbb6a12ee); + rc[14] = _mm_set_epi32(0xaf044988,0x4b050084,0x5f9600c9,0x9ca8eca6); + rc[15] = _mm_set_epi32(0x21025ed8,0x9d199c4f,0x78a2c7e3,0x27e593ec); + rc[16] = _mm_set_epi32(0xbf3aaaf8,0xa759c9b7,0xb9282ecd,0x82d40173); + rc[17] = _mm_set_epi32(0x6260700d,0x6186b017,0x37f2efd9,0x10307d6b); + rc[18] = _mm_set_epi32(0x5aca45c2,0x21300443,0x81c29153,0xf6fc9ac6); + rc[19] = _mm_set_epi32(0x9223973c,0x226b68bb,0x2caf92e8,0x36d1943a); + rc[20] = _mm_set_epi32(0xd3bf9238,0x225886eb,0x6cbab958,0xe51071b4); + rc[21] = _mm_set_epi32(0xdb863ce5,0xaef0c677,0x933dfddd,0x24e1128d); + rc[22] = _mm_set_epi32(0xbb606268,0xffeba09c,0x83e48de3,0xcb2212b1); + rc[23] = _mm_set_epi32(0x734bd3dc,0xe2e4d19c,0x2db91a4e,0xc72bf77d); + rc[24] = _mm_set_epi32(0x43bb47c3,0x61301b43,0x4b1415c4,0x2cb3924e); + rc[25] = _mm_set_epi32(0xdba775a8,0xe707eff6,0x03b231dd,0x16eb6899); + rc[26] = _mm_set_epi32(0x6df3614b,0x3c755977,0x8e5e2302,0x7eca472c); + rc[27] = _mm_set_epi32(0xcda75a17,0xd6de7d77,0x6d1be5b9,0xb88617f9); + rc[28] = _mm_set_epi32(0xec6b43f0,0x6ba8e9aa,0x9d6c069d,0xa946ee5d); + rc[29] = _mm_set_epi32(0xcb1e6950,0xf957332b,0xa2531159,0x3bf327c1); + rc[30] = _mm_set_epi32(0x2cee0c75,0x00da619c,0xe4ed0353,0x600ed0d9); + rc[31] = _mm_set_epi32(0xf0b1a5a1,0x96e90cab,0x80bbbabc,0x63a4a350); + rc[32] = _mm_set_epi32(0xae3db102,0x5e962988,0xab0dde30,0x938dca39); + rc[33] = _mm_set_epi32(0x17bb8f38,0xd554a40b,0x8814f3a8,0x2e75b442); + rc[34] = _mm_set_epi32(0x34bb8a5b,0x5f427fd7,0xaeb6b779,0x360a16f6); + rc[35] = _mm_set_epi32(0x26f65241,0xcbe55438,0x43ce5918,0xffbaafde); + rc[36] = _mm_set_epi32(0x4ce99a54,0xb9f3026a,0xa2ca9cf7,0x839ec978); + rc[37] = _mm_set_epi32(0xae51a51a,0x1bdff7be,0x40c06e28,0x22901235); + rc[38] = _mm_set_epi32(0xa0c1613c,0xba7ed22b,0xc173bc0f,0x48a659cf); + rc[39] = _mm_set_epi32(0x756acc03,0x02288288,0x4ad6bdfd,0xe9c59da1); +} + +void test_implementations() { + unsigned char *in = (unsigned char *)calloc(64*8, sizeof(unsigned char)); + unsigned char *out256 = (unsigned char *)calloc(32*8, sizeof(unsigned char)); + unsigned char *out512 = (unsigned char *)calloc(32*8, sizeof(unsigned char)); + unsigned char testvector256[32] = {0x80, 0x27, 0xcc, 0xb8, 0x79, 0x49, 0x77, 0x4b, + 0x78, 0xd0, 0x54, 0x5f, 0xb7, 0x2b, 0xf7, 0x0c, + 0x69, 0x5c, 0x2a, 0x09, 0x23, 0xcb, 0xd4, 0x7b, + 0xba, 0x11, 0x59, 0xef, 0xbf, 0x2b, 0x2c, 0x1c}; + + unsigned char testvector512[32] = {0xbe, 0x7f, 0x72, 0x3b, 0x4e, 0x80, 0xa9, 0x98, + 0x13, 0xb2, 0x92, 0x28, 0x7f, 0x30, 0x6f, 0x62, + 0x5a, 0x6d, 0x57, 0x33, 0x1c, 0xae, 0x5f, 0x34, + 0xdd, 0x92, 0x77, 0xb0, 0x94, 0x5b, 0xe2, 0xaa}; + + + + int i; + + // Input for testvector + for(i = 0; i < 512; i++) { + in[i] = i % 64; + } + + load_constants(); + haraka512_8x(out512, in); + + // Verify output + for(i = 0; i < 32; i++) { + if (out512[i % 32] != testvector512[i]) { + printf("Error: testvector incorrect.\n"); + return; + } + } + + free(in); + free(out256); + free(out512); +} + +void haraka256(unsigned char *out, const unsigned char *in) { + __m128i s[2], tmp; + + s[0] = LOAD(in); + s[1] = LOAD(in + 16); + + AES2(s[0], s[1], 0); + MIX2(s[0], s[1]); + + AES2(s[0], s[1], 4); + MIX2(s[0], s[1]); + + AES2(s[0], s[1], 8); + MIX2(s[0], s[1]); + + AES2(s[0], s[1], 12); + MIX2(s[0], s[1]); + + AES2(s[0], s[1], 16); + MIX2(s[0], s[1]); + + s[0] = _mm_xor_si128(s[0], LOAD(in)); + s[1] = _mm_xor_si128(s[1], LOAD(in + 16)); + + STORE(out, s[0]); + STORE(out + 16, s[1]); +} + +void haraka256_4x(unsigned char *out, const unsigned char *in) { + __m128i s[4][2], tmp; + + s[0][0] = LOAD(in); + s[0][1] = LOAD(in + 16); + s[1][0] = LOAD(in + 32); + s[1][1] = LOAD(in + 48); + s[2][0] = LOAD(in + 64); + s[2][1] = LOAD(in + 80); + s[3][0] = LOAD(in + 96); + s[3][1] = LOAD(in + 112); + + // Round 1 + AES2_4x(s[0], s[1], s[2], s[3], 0); + + MIX2(s[0][0], s[0][1]); + MIX2(s[1][0], s[1][1]); + MIX2(s[2][0], s[2][1]); + MIX2(s[3][0], s[3][1]); + + // Round 2 + AES2_4x(s[0], s[1], s[2], s[3], 4); + + MIX2(s[0][0], s[0][1]); + MIX2(s[1][0], s[1][1]); + MIX2(s[2][0], s[2][1]); + MIX2(s[3][0], s[3][1]); + + // Round 3 + AES2_4x(s[0], s[1], s[2], s[3], 8); + + MIX2(s[0][0], s[0][1]); + MIX2(s[1][0], s[1][1]); + MIX2(s[2][0], s[2][1]); + MIX2(s[3][0], s[3][1]); + + // Round 4 + AES2_4x(s[0], s[1], s[2], s[3], 12); + + MIX2(s[0][0], s[0][1]); + MIX2(s[1][0], s[1][1]); + MIX2(s[2][0], s[2][1]); + MIX2(s[3][0], s[3][1]); + + // Round 5 + AES2_4x(s[0], s[1], s[2], s[3], 16); + + MIX2(s[0][0], s[0][1]); + MIX2(s[1][0], s[1][1]); + MIX2(s[2][0], s[2][1]); + MIX2(s[3][0], s[3][1]); + + // Feed Forward + s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); + s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); + s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 32)); + s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 48)); + s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 64)); + s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 80)); + s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 96)); + s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 112)); + + STORE(out, s[0][0]); + STORE(out + 16, s[0][1]); + STORE(out + 32, s[1][0]); + STORE(out + 48, s[1][1]); + STORE(out + 64, s[2][0]); + STORE(out + 80, s[2][1]); + STORE(out + 96, s[3][0]); + STORE(out + 112, s[3][1]); +} + +void haraka256_8x(unsigned char *out, const unsigned char *in) { + // This is faster on Skylake, the code below is faster on Haswell. + haraka256_4x(out, in); + haraka256_4x(out + 128, in + 128); + return; + // __m128i s[8][2], tmp; + // + // int i; + // + // s[0][0] = LOAD(in); + // s[0][1] = LOAD(in + 16); + // s[1][0] = LOAD(in + 32); + // s[1][1] = LOAD(in + 48); + // s[2][0] = LOAD(in + 64); + // s[2][1] = LOAD(in + 80); + // s[3][0] = LOAD(in + 96); + // s[3][1] = LOAD(in + 112); + // s[4][0] = LOAD(in + 128); + // s[4][1] = LOAD(in + 144); + // s[5][0] = LOAD(in + 160); + // s[5][1] = LOAD(in + 176); + // s[6][0] = LOAD(in + 192); + // s[6][1] = LOAD(in + 208); + // s[7][0] = LOAD(in + 224); + // s[7][1] = LOAD(in + 240); + // + // // Round 1 + // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 0); + // + // MIX2(s[0][0], s[0][1]); + // MIX2(s[1][0], s[1][1]); + // MIX2(s[2][0], s[2][1]); + // MIX2(s[3][0], s[3][1]); + // MIX2(s[4][0], s[4][1]); + // MIX2(s[5][0], s[5][1]); + // MIX2(s[6][0], s[6][1]); + // MIX2(s[7][0], s[7][1]); + // + // + // // Round 2 + // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 4); + // + // MIX2(s[0][0], s[0][1]); + // MIX2(s[1][0], s[1][1]); + // MIX2(s[2][0], s[2][1]); + // MIX2(s[3][0], s[3][1]); + // MIX2(s[4][0], s[4][1]); + // MIX2(s[5][0], s[5][1]); + // MIX2(s[6][0], s[6][1]); + // MIX2(s[7][0], s[7][1]); + // + // // Round 3 + // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 8); + // + // MIX2(s[0][0], s[0][1]); + // MIX2(s[1][0], s[1][1]); + // MIX2(s[2][0], s[2][1]); + // MIX2(s[3][0], s[3][1]); + // MIX2(s[4][0], s[4][1]); + // MIX2(s[5][0], s[5][1]); + // MIX2(s[6][0], s[6][1]); + // MIX2(s[7][0], s[7][1]); + // + // // Round 4 + // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 12); + // + // MIX2(s[0][0], s[0][1]); + // MIX2(s[1][0], s[1][1]); + // MIX2(s[2][0], s[2][1]); + // MIX2(s[3][0], s[3][1]); + // MIX2(s[4][0], s[4][1]); + // MIX2(s[5][0], s[5][1]); + // MIX2(s[6][0], s[6][1]); + // MIX2(s[7][0], s[7][1]); + // + // // Round 5 + // AES2_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 16); + // + // MIX2(s[0][0], s[0][1]); + // MIX2(s[1][0], s[1][1]); + // MIX2(s[2][0], s[2][1]); + // MIX2(s[3][0], s[3][1]); + // MIX2(s[4][0], s[4][1]); + // MIX2(s[5][0], s[5][1]); + // MIX2(s[6][0], s[6][1]); + // MIX2(s[7][0], s[7][1]); + // + // // Feed Forward + // s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); + // s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); + // s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 32)); + // s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 48)); + // s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 64)); + // s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 80)); + // s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 96)); + // s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 112)); + // s[4][0] = _mm_xor_si128(s[4][0], LOAD(in + 128)); + // s[4][1] = _mm_xor_si128(s[4][1], LOAD(in + 144)); + // s[5][0] = _mm_xor_si128(s[5][0], LOAD(in + 160)); + // s[5][1] = _mm_xor_si128(s[5][1], LOAD(in + 176)); + // s[6][0] = _mm_xor_si128(s[6][0], LOAD(in + 192)); + // s[6][1] = _mm_xor_si128(s[6][1], LOAD(in + 208)); + // s[7][0] = _mm_xor_si128(s[7][0], LOAD(in + 224)); + // s[7][1] = _mm_xor_si128(s[7][1], LOAD(in + 240)); + // + // STORE(out, s[0][0]); + // STORE(out + 16, s[0][1]); + // STORE(out + 32, s[1][0]); + // STORE(out + 48, s[1][1]); + // STORE(out + 64, s[2][0]); + // STORE(out + 80, s[2][1]); + // STORE(out + 96, s[3][0]); + // STORE(out + 112, s[3][1]); + // STORE(out + 128, s[4][0]); + // STORE(out + 144, s[4][1]); + // STORE(out + 160, s[5][0]); + // STORE(out + 176, s[5][1]); + // STORE(out + 192, s[6][0]); + // STORE(out + 208, s[6][1]); + // STORE(out + 224, s[7][0]); + // STORE(out + 240, s[7][1]); +} + +void haraka512(unsigned char *out, const unsigned char *in) { + u128 s[4], tmp; + + s[0] = LOAD(in); + s[1] = LOAD(in + 16); + s[2] = LOAD(in + 32); + s[3] = LOAD(in + 48); + + AES4(s[0], s[1], s[2], s[3], 0); + MIX4(s[0], s[1], s[2], s[3]); + + AES4(s[0], s[1], s[2], s[3], 8); + MIX4(s[0], s[1], s[2], s[3]); + + AES4(s[0], s[1], s[2], s[3], 16); + MIX4(s[0], s[1], s[2], s[3]); + + AES4(s[0], s[1], s[2], s[3], 24); + MIX4(s[0], s[1], s[2], s[3]); + + AES4(s[0], s[1], s[2], s[3], 32); + MIX4(s[0], s[1], s[2], s[3]); + + s[0] = _mm_xor_si128(s[0], LOAD(in)); + s[1] = _mm_xor_si128(s[1], LOAD(in + 16)); + s[2] = _mm_xor_si128(s[2], LOAD(in + 32)); + s[3] = _mm_xor_si128(s[3], LOAD(in + 48)); + + TRUNCSTORE(out, s[0], s[1], s[2], s[3]); +} + +void haraka512_zero(unsigned char *out, const unsigned char *in) { + u128 s[4], tmp; + + s[0] = LOAD(in); + s[1] = LOAD(in + 16); + s[2] = LOAD(in + 32); + s[3] = LOAD(in + 48); + + AES4_zero(s[0], s[1], s[2], s[3], 0); + MIX4(s[0], s[1], s[2], s[3]); + + AES4_zero(s[0], s[1], s[2], s[3], 8); + MIX4(s[0], s[1], s[2], s[3]); + + AES4_zero(s[0], s[1], s[2], s[3], 16); + MIX4(s[0], s[1], s[2], s[3]); + + AES4_zero(s[0], s[1], s[2], s[3], 24); + MIX4(s[0], s[1], s[2], s[3]); + + AES4_zero(s[0], s[1], s[2], s[3], 32); + MIX4(s[0], s[1], s[2], s[3]); + + s[0] = _mm_xor_si128(s[0], LOAD(in)); + s[1] = _mm_xor_si128(s[1], LOAD(in + 16)); + s[2] = _mm_xor_si128(s[2], LOAD(in + 32)); + s[3] = _mm_xor_si128(s[3], LOAD(in + 48)); + + TRUNCSTORE(out, s[0], s[1], s[2], s[3]); +} + +void haraka512_4x(unsigned char *out, const unsigned char *in) { + u128 s[4][4], tmp; + + s[0][0] = LOAD(in); + s[0][1] = LOAD(in + 16); + s[0][2] = LOAD(in + 32); + s[0][3] = LOAD(in + 48); + s[1][0] = LOAD(in + 64); + s[1][1] = LOAD(in + 80); + s[1][2] = LOAD(in + 96); + s[1][3] = LOAD(in + 112); + s[2][0] = LOAD(in + 128); + s[2][1] = LOAD(in + 144); + s[2][2] = LOAD(in + 160); + s[2][3] = LOAD(in + 176); + s[3][0] = LOAD(in + 192); + s[3][1] = LOAD(in + 208); + s[3][2] = LOAD(in + 224); + s[3][3] = LOAD(in + 240); + + AES4_4x(s[0], s[1], s[2], s[3], 0); + MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + + AES4_4x(s[0], s[1], s[2], s[3], 8); + MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + + AES4_4x(s[0], s[1], s[2], s[3], 16); + MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + + AES4_4x(s[0], s[1], s[2], s[3], 24); + MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + + AES4_4x(s[0], s[1], s[2], s[3], 32); + MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + + + s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); + s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); + s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32)); + s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48)); + s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64)); + s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80)); + s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96)); + s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112)); + s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128)); + s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144)); + s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160)); + s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176)); + s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192)); + s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208)); + s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224)); + s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240)); + + TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]); + TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]); + TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]); + TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]); +} + +void haraka512_8x(unsigned char *out, const unsigned char *in) { + // This is faster on Skylake, the code below is faster on Haswell. + haraka512_4x(out, in); + haraka512_4x(out + 128, in + 256); + + // u128 s[8][4], tmp; + // + // s[0][0] = LOAD(in); + // s[0][1] = LOAD(in + 16); + // s[0][2] = LOAD(in + 32); + // s[0][3] = LOAD(in + 48); + // s[1][0] = LOAD(in + 64); + // s[1][1] = LOAD(in + 80); + // s[1][2] = LOAD(in + 96); + // s[1][3] = LOAD(in + 112); + // s[2][0] = LOAD(in + 128); + // s[2][1] = LOAD(in + 144); + // s[2][2] = LOAD(in + 160); + // s[2][3] = LOAD(in + 176); + // s[3][0] = LOAD(in + 192); + // s[3][1] = LOAD(in + 208); + // s[3][2] = LOAD(in + 224); + // s[3][3] = LOAD(in + 240); + // s[4][0] = LOAD(in + 256); + // s[4][1] = LOAD(in + 272); + // s[4][2] = LOAD(in + 288); + // s[4][3] = LOAD(in + 304); + // s[5][0] = LOAD(in + 320); + // s[5][1] = LOAD(in + 336); + // s[5][2] = LOAD(in + 352); + // s[5][3] = LOAD(in + 368); + // s[6][0] = LOAD(in + 384); + // s[6][1] = LOAD(in + 400); + // s[6][2] = LOAD(in + 416); + // s[6][3] = LOAD(in + 432); + // s[7][0] = LOAD(in + 448); + // s[7][1] = LOAD(in + 464); + // s[7][2] = LOAD(in + 480); + // s[7][3] = LOAD(in + 496); + // + // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 0); + // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); + // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); + // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); + // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); + // + // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 8); + // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); + // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); + // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); + // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); + // + // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 16); + // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); + // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); + // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); + // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); + // + // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 24); + // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); + // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); + // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); + // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); + // + // AES4_8x(s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], 32); + // MIX4(s[0][0], s[0][1], s[0][2], s[0][3]); + // MIX4(s[1][0], s[1][1], s[1][2], s[1][3]); + // MIX4(s[2][0], s[2][1], s[2][2], s[2][3]); + // MIX4(s[3][0], s[3][1], s[3][2], s[3][3]); + // MIX4(s[4][0], s[4][1], s[4][2], s[4][3]); + // MIX4(s[5][0], s[5][1], s[5][2], s[5][3]); + // MIX4(s[6][0], s[6][1], s[6][2], s[6][3]); + // MIX4(s[7][0], s[7][1], s[7][2], s[7][3]); + // + // + // s[0][0] = _mm_xor_si128(s[0][0], LOAD(in)); + // s[0][1] = _mm_xor_si128(s[0][1], LOAD(in + 16)); + // s[0][2] = _mm_xor_si128(s[0][2], LOAD(in + 32)); + // s[0][3] = _mm_xor_si128(s[0][3], LOAD(in + 48)); + // s[1][0] = _mm_xor_si128(s[1][0], LOAD(in + 64)); + // s[1][1] = _mm_xor_si128(s[1][1], LOAD(in + 80)); + // s[1][2] = _mm_xor_si128(s[1][2], LOAD(in + 96)); + // s[1][3] = _mm_xor_si128(s[1][3], LOAD(in + 112)); + // s[2][0] = _mm_xor_si128(s[2][0], LOAD(in + 128)); + // s[2][1] = _mm_xor_si128(s[2][1], LOAD(in + 144)); + // s[2][2] = _mm_xor_si128(s[2][2], LOAD(in + 160)); + // s[2][3] = _mm_xor_si128(s[2][3], LOAD(in + 176)); + // s[3][0] = _mm_xor_si128(s[3][0], LOAD(in + 192)); + // s[3][1] = _mm_xor_si128(s[3][1], LOAD(in + 208)); + // s[3][2] = _mm_xor_si128(s[3][2], LOAD(in + 224)); + // s[3][3] = _mm_xor_si128(s[3][3], LOAD(in + 240)); + // s[4][0] = _mm_xor_si128(s[4][0], LOAD(in + 256)); + // s[4][1] = _mm_xor_si128(s[4][1], LOAD(in + 272)); + // s[4][2] = _mm_xor_si128(s[4][2], LOAD(in + 288)); + // s[4][3] = _mm_xor_si128(s[4][3], LOAD(in + 304)); + // s[5][0] = _mm_xor_si128(s[5][0], LOAD(in + 320)); + // s[5][1] = _mm_xor_si128(s[5][1], LOAD(in + 336)); + // s[5][2] = _mm_xor_si128(s[5][2], LOAD(in + 352)); + // s[5][3] = _mm_xor_si128(s[5][3], LOAD(in + 368)); + // s[6][0] = _mm_xor_si128(s[6][0], LOAD(in + 384)); + // s[6][1] = _mm_xor_si128(s[6][1], LOAD(in + 400)); + // s[6][2] = _mm_xor_si128(s[6][2], LOAD(in + 416)); + // s[6][3] = _mm_xor_si128(s[6][3], LOAD(in + 432)); + // s[7][0] = _mm_xor_si128(s[7][0], LOAD(in + 448)); + // s[7][1] = _mm_xor_si128(s[7][1], LOAD(in + 464)); + // s[7][2] = _mm_xor_si128(s[7][2], LOAD(in + 480)); + // s[7][3] = _mm_xor_si128(s[7][3], LOAD(in + 496)); + // + // TRUNCSTORE(out, s[0][0], s[0][1], s[0][2], s[0][3]); + // TRUNCSTORE(out + 32, s[1][0], s[1][1], s[1][2], s[1][3]); + // TRUNCSTORE(out + 64, s[2][0], s[2][1], s[2][2], s[2][3]); + // TRUNCSTORE(out + 96, s[3][0], s[3][1], s[3][2], s[3][3]); + // TRUNCSTORE(out + 128, s[4][0], s[4][1], s[4][2], s[4][3]); + // TRUNCSTORE(out + 160, s[5][0], s[5][1], s[5][2], s[5][3]); + // TRUNCSTORE(out + 192, s[6][0], s[6][1], s[6][2], s[6][3]); + // TRUNCSTORE(out + 224, s[7][0], s[7][1], s[7][2], s[7][3]); +} diff --git a/src/crypto/haraka.h b/src/crypto/haraka.h new file mode 100644 index 00000000000..daf657184fe --- /dev/null +++ b/src/crypto/haraka.h @@ -0,0 +1,126 @@ +/* +The MIT License (MIT) + +Copyright (c) 2016 kste + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + +Optimized Implementations for Haraka256 and Haraka512 +*/ +#ifndef HARAKA_H_ +#define HARAKA_H_ + +#include "immintrin.h" + +#define NUMROUNDS 5 + +#ifdef _WIN32 +typedef unsigned long long u64; +#else +typedef unsigned long u64; +#endif +typedef __m128i u128; + +extern u128 rc[40]; + +#define LOAD(src) _mm_load_si128((u128 *)(src)) +#define STORE(dest,src) _mm_storeu_si128((u128 *)(dest),src) + +#define AES2(s0, s1, rci) \ + s0 = _mm_aesenc_si128(s0, rc[rci]); \ + s1 = _mm_aesenc_si128(s1, rc[rci + 1]); \ + s0 = _mm_aesenc_si128(s0, rc[rci + 2]); \ + s1 = _mm_aesenc_si128(s1, rc[rci + 3]); + +#define AES2_4x(s0, s1, s2, s3, rci) \ + AES2(s0[0], s0[1], rci); \ + AES2(s1[0], s1[1], rci); \ + AES2(s2[0], s2[1], rci); \ + AES2(s3[0], s3[1], rci); + +#define AES2_8x(s0, s1, s2, s3, s4, s5, s6, s7, rci) \ + AES2_4x(s0, s1, s2, s3, rci); \ + AES2_4x(s4, s5, s6, s7, rci); + +#define AES4(s0, s1, s2, s3, rci) \ + s0 = _mm_aesenc_si128(s0, rc[rci]); \ + s1 = _mm_aesenc_si128(s1, rc[rci + 1]); \ + s2 = _mm_aesenc_si128(s2, rc[rci + 2]); \ + s3 = _mm_aesenc_si128(s3, rc[rci + 3]); \ + s0 = _mm_aesenc_si128(s0, rc[rci + 4]); \ + s1 = _mm_aesenc_si128(s1, rc[rci + 5]); \ + s2 = _mm_aesenc_si128(s2, rc[rci + 6]); \ + s3 = _mm_aesenc_si128(s3, rc[rci + 7]); \ + +#define AES4_zero(s0, s1, s2, s3, rci) \ + s0 = _mm_aesenc_si128(s0, rc0[rci]); \ + s1 = _mm_aesenc_si128(s1, rc0[rci + 1]); \ + s2 = _mm_aesenc_si128(s2, rc0[rci + 2]); \ + s3 = _mm_aesenc_si128(s3, rc0[rci + 3]); \ + s0 = _mm_aesenc_si128(s0, rc0[rci + 4]); \ + s1 = _mm_aesenc_si128(s1, rc0[rci + 5]); \ + s2 = _mm_aesenc_si128(s2, rc0[rci + 6]); \ + s3 = _mm_aesenc_si128(s3, rc0[rci + 7]); \ + +#define AES4_4x(s0, s1, s2, s3, rci) \ + AES4(s0[0], s0[1], s0[2], s0[3], rci); \ + AES4(s1[0], s1[1], s1[2], s1[3], rci); \ + AES4(s2[0], s2[1], s2[2], s2[3], rci); \ + AES4(s3[0], s3[1], s3[2], s3[3], rci); + +#define AES4_8x(s0, s1, s2, s3, s4, s5, s6, s7, rci) \ + AES4_4x(s0, s1, s2, s3, rci); \ + AES4_4x(s4, s5, s6, s7, rci); + +#define MIX2(s0, s1) \ + tmp = _mm_unpacklo_epi32(s0, s1); \ + s1 = _mm_unpackhi_epi32(s0, s1); \ + s0 = tmp; + +#define MIX4(s0, s1, s2, s3) \ + tmp = _mm_unpacklo_epi32(s0, s1); \ + s0 = _mm_unpackhi_epi32(s0, s1); \ + s1 = _mm_unpacklo_epi32(s2, s3); \ + s2 = _mm_unpackhi_epi32(s2, s3); \ + s3 = _mm_unpacklo_epi32(s0, s2); \ + s0 = _mm_unpackhi_epi32(s0, s2); \ + s2 = _mm_unpackhi_epi32(s1, tmp); \ + s1 = _mm_unpacklo_epi32(s1, tmp); + +#define TRUNCSTORE(out, s0, s1, s2, s3) \ + *(u64*)(out) = (u64*)(s0)[1]; \ + *(u64*)(out + 8) = (u64*)(s1)[1]; \ + *(u64*)(out + 16) = (u64*)(s2)[0]; \ + *(u64*)(out + 24) = (u64*)(s3)[0]; + +void load_constants(); +void test_implementations(); + +void load_constants(); + +void haraka256(unsigned char *out, const unsigned char *in); +void haraka256_4x(unsigned char *out, const unsigned char *in); +void haraka256_8x(unsigned char *out, const unsigned char *in); + +void haraka512(unsigned char *out, const unsigned char *in); +void haraka512_zero(unsigned char *out, const unsigned char *in); +void haraka512_4x(unsigned char *out, const unsigned char *in); +void haraka512_8x(unsigned char *out, const unsigned char *in); + +#endif diff --git a/src/crypto/haraka_portable.c b/src/crypto/haraka_portable.c new file mode 100644 index 00000000000..0792f8b2f7d --- /dev/null +++ b/src/crypto/haraka_portable.c @@ -0,0 +1,375 @@ +/* +Plain C implementation of the Haraka256 and Haraka512 permutations. +*/ +#include +#include +#include + +#include "haraka_portable.h" + +#define HARAKAS_RATE 32 + +static const unsigned char haraka_rc[40][16] = { + {0x9d, 0x7b, 0x81, 0x75, 0xf0, 0xfe, 0xc5, 0xb2, 0x0a, 0xc0, 0x20, 0xe6, 0x4c, 0x70, 0x84, 0x06}, + {0x17, 0xf7, 0x08, 0x2f, 0xa4, 0x6b, 0x0f, 0x64, 0x6b, 0xa0, 0xf3, 0x88, 0xe1, 0xb4, 0x66, 0x8b}, + {0x14, 0x91, 0x02, 0x9f, 0x60, 0x9d, 0x02, 0xcf, 0x98, 0x84, 0xf2, 0x53, 0x2d, 0xde, 0x02, 0x34}, + {0x79, 0x4f, 0x5b, 0xfd, 0xaf, 0xbc, 0xf3, 0xbb, 0x08, 0x4f, 0x7b, 0x2e, 0xe6, 0xea, 0xd6, 0x0e}, + {0x44, 0x70, 0x39, 0xbe, 0x1c, 0xcd, 0xee, 0x79, 0x8b, 0x44, 0x72, 0x48, 0xcb, 0xb0, 0xcf, 0xcb}, + {0x7b, 0x05, 0x8a, 0x2b, 0xed, 0x35, 0x53, 0x8d, 0xb7, 0x32, 0x90, 0x6e, 0xee, 0xcd, 0xea, 0x7e}, + {0x1b, 0xef, 0x4f, 0xda, 0x61, 0x27, 0x41, 0xe2, 0xd0, 0x7c, 0x2e, 0x5e, 0x43, 0x8f, 0xc2, 0x67}, + {0x3b, 0x0b, 0xc7, 0x1f, 0xe2, 0xfd, 0x5f, 0x67, 0x07, 0xcc, 0xca, 0xaf, 0xb0, 0xd9, 0x24, 0x29}, + {0xee, 0x65, 0xd4, 0xb9, 0xca, 0x8f, 0xdb, 0xec, 0xe9, 0x7f, 0x86, 0xe6, 0xf1, 0x63, 0x4d, 0xab}, + {0x33, 0x7e, 0x03, 0xad, 0x4f, 0x40, 0x2a, 0x5b, 0x64, 0xcd, 0xb7, 0xd4, 0x84, 0xbf, 0x30, 0x1c}, + {0x00, 0x98, 0xf6, 0x8d, 0x2e, 0x8b, 0x02, 0x69, 0xbf, 0x23, 0x17, 0x94, 0xb9, 0x0b, 0xcc, 0xb2}, + {0x8a, 0x2d, 0x9d, 0x5c, 0xc8, 0x9e, 0xaa, 0x4a, 0x72, 0x55, 0x6f, 0xde, 0xa6, 0x78, 0x04, 0xfa}, + {0xd4, 0x9f, 0x12, 0x29, 0x2e, 0x4f, 0xfa, 0x0e, 0x12, 0x2a, 0x77, 0x6b, 0x2b, 0x9f, 0xb4, 0xdf}, + {0xee, 0x12, 0x6a, 0xbb, 0xae, 0x11, 0xd6, 0x32, 0x36, 0xa2, 0x49, 0xf4, 0x44, 0x03, 0xa1, 0x1e}, + {0xa6, 0xec, 0xa8, 0x9c, 0xc9, 0x00, 0x96, 0x5f, 0x84, 0x00, 0x05, 0x4b, 0x88, 0x49, 0x04, 0xaf}, + {0xec, 0x93, 0xe5, 0x27, 0xe3, 0xc7, 0xa2, 0x78, 0x4f, 0x9c, 0x19, 0x9d, 0xd8, 0x5e, 0x02, 0x21}, + {0x73, 0x01, 0xd4, 0x82, 0xcd, 0x2e, 0x28, 0xb9, 0xb7, 0xc9, 0x59, 0xa7, 0xf8, 0xaa, 0x3a, 0xbf}, + {0x6b, 0x7d, 0x30, 0x10, 0xd9, 0xef, 0xf2, 0x37, 0x17, 0xb0, 0x86, 0x61, 0x0d, 0x70, 0x60, 0x62}, + {0xc6, 0x9a, 0xfc, 0xf6, 0x53, 0x91, 0xc2, 0x81, 0x43, 0x04, 0x30, 0x21, 0xc2, 0x45, 0xca, 0x5a}, + {0x3a, 0x94, 0xd1, 0x36, 0xe8, 0x92, 0xaf, 0x2c, 0xbb, 0x68, 0x6b, 0x22, 0x3c, 0x97, 0x23, 0x92}, + {0xb4, 0x71, 0x10, 0xe5, 0x58, 0xb9, 0xba, 0x6c, 0xeb, 0x86, 0x58, 0x22, 0x38, 0x92, 0xbf, 0xd3}, + {0x8d, 0x12, 0xe1, 0x24, 0xdd, 0xfd, 0x3d, 0x93, 0x77, 0xc6, 0xf0, 0xae, 0xe5, 0x3c, 0x86, 0xdb}, + {0xb1, 0x12, 0x22, 0xcb, 0xe3, 0x8d, 0xe4, 0x83, 0x9c, 0xa0, 0xeb, 0xff, 0x68, 0x62, 0x60, 0xbb}, + {0x7d, 0xf7, 0x2b, 0xc7, 0x4e, 0x1a, 0xb9, 0x2d, 0x9c, 0xd1, 0xe4, 0xe2, 0xdc, 0xd3, 0x4b, 0x73}, + {0x4e, 0x92, 0xb3, 0x2c, 0xc4, 0x15, 0x14, 0x4b, 0x43, 0x1b, 0x30, 0x61, 0xc3, 0x47, 0xbb, 0x43}, + {0x99, 0x68, 0xeb, 0x16, 0xdd, 0x31, 0xb2, 0x03, 0xf6, 0xef, 0x07, 0xe7, 0xa8, 0x75, 0xa7, 0xdb}, + {0x2c, 0x47, 0xca, 0x7e, 0x02, 0x23, 0x5e, 0x8e, 0x77, 0x59, 0x75, 0x3c, 0x4b, 0x61, 0xf3, 0x6d}, + {0xf9, 0x17, 0x86, 0xb8, 0xb9, 0xe5, 0x1b, 0x6d, 0x77, 0x7d, 0xde, 0xd6, 0x17, 0x5a, 0xa7, 0xcd}, + {0x5d, 0xee, 0x46, 0xa9, 0x9d, 0x06, 0x6c, 0x9d, 0xaa, 0xe9, 0xa8, 0x6b, 0xf0, 0x43, 0x6b, 0xec}, + {0xc1, 0x27, 0xf3, 0x3b, 0x59, 0x11, 0x53, 0xa2, 0x2b, 0x33, 0x57, 0xf9, 0x50, 0x69, 0x1e, 0xcb}, + {0xd9, 0xd0, 0x0e, 0x60, 0x53, 0x03, 0xed, 0xe4, 0x9c, 0x61, 0xda, 0x00, 0x75, 0x0c, 0xee, 0x2c}, + {0x50, 0xa3, 0xa4, 0x63, 0xbc, 0xba, 0xbb, 0x80, 0xab, 0x0c, 0xe9, 0x96, 0xa1, 0xa5, 0xb1, 0xf0}, + {0x39, 0xca, 0x8d, 0x93, 0x30, 0xde, 0x0d, 0xab, 0x88, 0x29, 0x96, 0x5e, 0x02, 0xb1, 0x3d, 0xae}, + {0x42, 0xb4, 0x75, 0x2e, 0xa8, 0xf3, 0x14, 0x88, 0x0b, 0xa4, 0x54, 0xd5, 0x38, 0x8f, 0xbb, 0x17}, + {0xf6, 0x16, 0x0a, 0x36, 0x79, 0xb7, 0xb6, 0xae, 0xd7, 0x7f, 0x42, 0x5f, 0x5b, 0x8a, 0xbb, 0x34}, + {0xde, 0xaf, 0xba, 0xff, 0x18, 0x59, 0xce, 0x43, 0x38, 0x54, 0xe5, 0xcb, 0x41, 0x52, 0xf6, 0x26}, + {0x78, 0xc9, 0x9e, 0x83, 0xf7, 0x9c, 0xca, 0xa2, 0x6a, 0x02, 0xf3, 0xb9, 0x54, 0x9a, 0xe9, 0x4c}, + {0x35, 0x12, 0x90, 0x22, 0x28, 0x6e, 0xc0, 0x40, 0xbe, 0xf7, 0xdf, 0x1b, 0x1a, 0xa5, 0x51, 0xae}, + {0xcf, 0x59, 0xa6, 0x48, 0x0f, 0xbc, 0x73, 0xc1, 0x2b, 0xd2, 0x7e, 0xba, 0x3c, 0x61, 0xc1, 0xa0}, + {0xa1, 0x9d, 0xc5, 0xe9, 0xfd, 0xbd, 0xd6, 0x4a, 0x88, 0x82, 0x28, 0x02, 0x03, 0xcc, 0x6a, 0x75} +}; + +static unsigned char rc[40][16]; +static unsigned char rc0[40][16]; +static unsigned char rc_sseed[40][16]; + +static const unsigned char sbox[256] = +{ 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, + 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, 0xad, 0xd4, + 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, 0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, + 0xcc, 0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, 0x04, 0xc7, 0x23, 0xc3, + 0x18, 0x96, 0x05, 0x9a, 0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, 0x09, + 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, 0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, + 0x2f, 0x84, 0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, 0x6a, 0xcb, 0xbe, + 0x39, 0x4a, 0x4c, 0x58, 0xcf, 0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, + 0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, 0x51, 0xa3, 0x40, 0x8f, 0x92, + 0x9d, 0x38, 0xf5, 0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, 0xcd, 0x0c, + 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, 0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, + 0x73, 0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, 0x46, 0xee, 0xb8, 0x14, + 0xde, 0x5e, 0x0b, 0xdb, 0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, 0xc2, + 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, 0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, + 0x4e, 0xa9, 0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, 0xba, 0x78, 0x25, + 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, 0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, + 0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, 0x61, 0x35, 0x57, 0xb9, 0x86, + 0xc1, 0x1d, 0x9e, 0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, 0x9b, 0x1e, + 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, 0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, + 0x68, 0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16 }; + +#define XT(x) (((x) << 1) ^ ((((x) >> 7) & 1) * 0x1b)) + +// Simulate _mm_aesenc_si128 instructions from AESNI +void aesenc(unsigned char *s, const unsigned char *rk) +{ + unsigned char i, t, u, v[4][4]; + for (i = 0; i < 16; ++i) { + v[((i / 4) + 4 - (i%4) ) % 4][i % 4] = sbox[s[i]]; + } + for (i = 0; i < 4; ++i) { + t = v[i][0]; + u = v[i][0] ^ v[i][1] ^ v[i][2] ^ v[i][3]; + v[i][0] ^= u ^ XT(v[i][0] ^ v[i][1]); + v[i][1] ^= u ^ XT(v[i][1] ^ v[i][2]); + v[i][2] ^= u ^ XT(v[i][2] ^ v[i][3]); + v[i][3] ^= u ^ XT(v[i][3] ^ t); + } + for (i = 0; i < 16; ++i) { + s[i] = v[i / 4][i % 4] ^ rk[i]; + } +} + +// Simulate _mm_unpacklo_epi32 +void unpacklo32(unsigned char *t, unsigned char *a, unsigned char *b) +{ + unsigned char tmp[16]; + memcpy(tmp, a, 4); + memcpy(tmp + 4, b, 4); + memcpy(tmp + 8, a + 4, 4); + memcpy(tmp + 12, b + 4, 4); + memcpy(t, tmp, 16); +} + +// Simulate _mm_unpackhi_epi32 +void unpackhi32(unsigned char *t, unsigned char *a, unsigned char *b) +{ + unsigned char tmp[16]; + memcpy(tmp, a + 8, 4); + memcpy(tmp + 4, b + 8, 4); + memcpy(tmp + 8, a + 12, 4); + memcpy(tmp + 12, b + 12, 4); + memcpy(t, tmp, 16); +} + +void load_constants_port() +{ + /* Use the standard constants to generate tweaked ones. */ + memcpy(rc, haraka_rc, 40*16); +} + +void tweak_constants(const unsigned char *pk_seed, const unsigned char *sk_seed, + unsigned long long seed_length) +{ + unsigned char buf[40*16]; + + /* Use the standard constants to generate tweaked ones. */ + memcpy(rc, haraka_rc, 40*16); + + /* Constants for sk.seed */ + if (sk_seed != NULL) { + haraka_S(buf, 40*16, sk_seed, seed_length); + memcpy(rc_sseed, buf, 40*16); + } + + /* Constants for pk.seed */ + haraka_S(buf, 40*16, pk_seed, seed_length); + memcpy(rc, buf, 40*16); +} + +static void haraka_S_absorb(unsigned char *s, unsigned int r, + const unsigned char *m, unsigned long long mlen, + unsigned char p) +{ + unsigned long long i; + unsigned char t[r]; + + while (mlen >= r) { + // XOR block to state + for (i = 0; i < r; ++i) { + s[i] ^= m[i]; + } + haraka512_perm(s, s); + mlen -= r; + m += r; + } + + for (i = 0; i < r; ++i) { + t[i] = 0; + } + for (i = 0; i < mlen; ++i) { + t[i] = m[i]; + } + t[i] = p; + t[r - 1] |= 128; + for (i = 0; i < r; ++i) { + s[i] ^= t[i]; + } +} + +static void haraka_S_squeezeblocks(unsigned char *h, unsigned long long nblocks, + unsigned char *s, unsigned int r) +{ + while (nblocks > 0) { + haraka512_perm(s, s); + memcpy(h, s, HARAKAS_RATE); + h += r; + nblocks--; + } +} + + +void haraka_S(unsigned char *out, unsigned long long outlen, + const unsigned char *in, unsigned long long inlen) +{ + unsigned long long i; + unsigned char s[64]; + unsigned char d[32]; + + for (i = 0; i < 64; i++) { + s[i] = 0; + } + haraka_S_absorb(s, 32, in, inlen, 0x1F); + + haraka_S_squeezeblocks(out, outlen / 32, s, 32); + out += (outlen / 32) * 32; + + if (outlen % 32) { + haraka_S_squeezeblocks(d, 1, s, 32); + for (i = 0; i < outlen % 32; i++) { + out[i] = d[i]; + } + } +} + +void haraka512_perm(unsigned char *out, const unsigned char *in) +{ + int i, j; + + unsigned char s[64], tmp[16]; + + memcpy(s, in, 16); + memcpy(s + 16, in + 16, 16); + memcpy(s + 32, in + 32, 16); + memcpy(s + 48, in + 48, 16); + + for (i = 0; i < 5; ++i) { + // aes round(s) + for (j = 0; j < 2; ++j) { + aesenc(s, rc[4*2*i + 4*j]); + aesenc(s + 16, rc[4*2*i + 4*j + 1]); + aesenc(s + 32, rc[4*2*i + 4*j + 2]); + aesenc(s + 48, rc[4*2*i + 4*j + 3]); + } + + // mixing + unpacklo32(tmp, s, s + 16); + unpackhi32(s, s, s + 16); + unpacklo32(s + 16, s + 32, s + 48); + unpackhi32(s + 32, s + 32, s + 48); + unpacklo32(s + 48, s, s + 32); + unpackhi32(s, s, s + 32); + unpackhi32(s + 32, s + 16, tmp); + unpacklo32(s + 16, s + 16, tmp); + } + + memcpy(out, s, 64); +} + +void haraka512_port(unsigned char *out, const unsigned char *in) +{ + int i; + + unsigned char buf[64]; + + haraka512_perm(buf, in); + /* Feed-forward */ + for (i = 0; i < 64; i++) { + buf[i] = buf[i] ^ in[i]; + } + + /* Truncated */ + memcpy(out, buf + 8, 8); + memcpy(out + 8, buf + 24, 8); + memcpy(out + 16, buf + 32, 8); + memcpy(out + 24, buf + 48, 8); +} + +void haraka512_perm_zero(unsigned char *out, const unsigned char *in) +{ + int i, j; + + unsigned char s[64], tmp[16]; + + memcpy(s, in, 16); + memcpy(s + 16, in + 16, 16); + memcpy(s + 32, in + 32, 16); + memcpy(s + 48, in + 48, 16); + + for (i = 0; i < 5; ++i) { + // aes round(s) + for (j = 0; j < 2; ++j) { + aesenc(s, rc0[4*2*i + 4*j]); + aesenc(s + 16, rc0[4*2*i + 4*j + 1]); + aesenc(s + 32, rc0[4*2*i + 4*j + 2]); + aesenc(s + 48, rc0[4*2*i + 4*j + 3]); + } + + // mixing + unpacklo32(tmp, s, s + 16); + unpackhi32(s, s, s + 16); + unpacklo32(s + 16, s + 32, s + 48); + unpackhi32(s + 32, s + 32, s + 48); + unpacklo32(s + 48, s, s + 32); + unpackhi32(s, s, s + 32); + unpackhi32(s + 32, s + 16, tmp); + unpacklo32(s + 16, s + 16, tmp); + } + + memcpy(out, s, 64); +} + +void haraka512_port_zero(unsigned char *out, const unsigned char *in) +{ + int i; + + unsigned char buf[64]; + + haraka512_perm_zero(buf, in); + /* Feed-forward */ + for (i = 0; i < 64; i++) { + buf[i] = buf[i] ^ in[i]; + } + + /* Truncated */ + memcpy(out, buf + 8, 8); + memcpy(out + 8, buf + 24, 8); + memcpy(out + 16, buf + 32, 8); + memcpy(out + 24, buf + 48, 8); +} + +void haraka256_port(unsigned char *out, const unsigned char *in) +{ + int i, j; + + unsigned char s[32], tmp[16]; + + memcpy(s, in, 16); + memcpy(s + 16, in + 16, 16); + + for (i = 0; i < 5; ++i) { + // aes round(s) + for (j = 0; j < 2; ++j) { + aesenc(s, rc[2*2*i + 2*j]); + aesenc(s + 16, rc[2*2*i + 2*j + 1]); + } + + // mixing + unpacklo32(tmp, s, s + 16); + unpackhi32(s + 16, s, s + 16); + memcpy(s, tmp, 16); + } + + /* Feed-forward */ + for (i = 0; i < 32; i++) { + out[i] = in[i] ^ s[i]; + } +} + +void haraka256_sk(unsigned char *out, const unsigned char *in) +{ + int i, j; + + unsigned char s[32], tmp[16]; + + memcpy(s, in, 16); + memcpy(s + 16, in + 16, 16); + + for (i = 0; i < 5; ++i) { + // aes round(s) + for (j = 0; j < 2; ++j) { + aesenc(s, rc_sseed[2*2*i + 2*j]); + aesenc(s + 16, rc_sseed[2*2*i + 2*j + 1]); + } + + // mixing + unpacklo32(tmp, s, s + 16); + unpackhi32(s + 16, s, s + 16); + memcpy(s, tmp, 16); + } + + /* Feed-forward */ + for (i = 0; i < 32; i++) { + out[i] = in[i] ^ s[i]; + } +} diff --git a/src/crypto/haraka_portable.h b/src/crypto/haraka_portable.h new file mode 100644 index 00000000000..dcc4f65aef4 --- /dev/null +++ b/src/crypto/haraka_portable.h @@ -0,0 +1,33 @@ +#ifndef SPX_HARAKA_H +#define SPX_HARAKA_H + +/* load constants */ +void load_constants_port(); + +/* Tweak constants with seed */ +void tweak_constants(const unsigned char *pk_seed, const unsigned char *sk_seed, + unsigned long long seed_length); + +/* Haraka Sponge */ +void haraka_S(unsigned char *out, unsigned long long outlen, + const unsigned char *in, unsigned long long inlen); + +/* Applies the 512-bit Haraka permutation to in. */ +void haraka512_perm(unsigned char *out, const unsigned char *in); + +/* Implementation of Haraka-512 */ +void haraka512_port(unsigned char *out, const unsigned char *in); + +/* Applies the 512-bit Haraka permutation to in, using zero key. */ +void haraka512_perm_zero(unsigned char *out, const unsigned char *in); + +/* Implementation of Haraka-512, using zero key */ +void haraka512_port_zero(unsigned char *out, const unsigned char *in); + +/* Implementation of Haraka-256 */ +void haraka256_port(unsigned char *out, const unsigned char *in); + +/* Implementation of Haraka-256 using sk.seed constants */ +void haraka256_sk(unsigned char *out, const unsigned char *in); + +#endif diff --git a/src/crypto/verus_hash.cpp b/src/crypto/verus_hash.cpp new file mode 100644 index 00000000000..f5cb1c9f3db --- /dev/null +++ b/src/crypto/verus_hash.cpp @@ -0,0 +1,180 @@ +// (C) 2018 The Verus Developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +/* +This provides the PoW hash function for Verus, a CPU-optimized hash +function with a Haraka V2 core. Unlike Haraka, which is made for short +inputs only, Verus Hash takes any length of input and produces a 256 +bit output. +*/ +#include +#include "crypto/common.h" +#include "crypto/verus_hash.h" + +void (*CVerusHash::haraka512Function)(unsigned char *out, const unsigned char *in); + +void CVerusHash::Hash(void *result, const void *data, size_t _len) +{ + unsigned char buf[128]; + unsigned char *bufPtr = buf; + int nextOffset = 64; + uint32_t pos = 0, len = _len; + unsigned char *bufPtr2 = bufPtr + nextOffset; + unsigned char *ptr = (unsigned char *)data; + + // put our last result or zero at beginning of buffer each time + memset(bufPtr, 0, 32); + + // digest up to 32 bytes at a time + for ( ; pos < len; pos += 32) + { + if (len - pos >= 32) + { + memcpy(bufPtr + 32, ptr + pos, 32); + } + else + { + int i = (int)(len - pos); + memcpy(bufPtr + 32, ptr + pos, i); + memset(bufPtr + 32 + i, 0, 32 - i); + } + (*haraka512Function)(bufPtr2, bufPtr); + bufPtr2 = bufPtr; + bufPtr += nextOffset; + nextOffset *= -1; + } + memcpy(result, bufPtr, 32); +}; + +void CVerusHash::init() +{ + if (IsCPUVerusOptimized()) + { + haraka512Function = &haraka512_zero; + } + else + { + haraka512Function = &haraka512_port_zero; + } +} + +CVerusHash &CVerusHash::Write(const unsigned char *data, size_t _len) +{ + unsigned char *tmp; + uint32_t pos, len = _len; + + // digest up to 32 bytes at a time + for ( pos = 0; pos < len; ) + { + uint32_t room = 32 - curPos; + + if (len - pos >= room) + { + memcpy(curBuf + 32 + curPos, data + pos, room); + (*haraka512Function)(result, curBuf); + tmp = curBuf; + curBuf = result; + result = tmp; + pos += room; + curPos = 0; + } + else + { + memcpy(curBuf + 32 + curPos, data + pos, len - pos); + curPos += len - pos; + pos = len; + } + } + return *this; +} + +// to be declared and accessed from C +void verus_hash(void *result, const void *data, size_t len) +{ + return CVerusHash::Hash(result, data, len); +} + +void (*CVerusHashV2::haraka512Function)(unsigned char *out, const unsigned char *in); + +void CVerusHashV2::init() +{ + if (IsCPUVerusOptimized()) + { + load_constants(); + haraka512Function = &haraka512; + } + else + { + // load and tweak the haraka constants + load_constants_port(); + haraka512Function = &haraka512_port; + } +} + +void CVerusHashV2::Hash(void *result, const void *data, size_t len) +{ + unsigned char buf[128]; + unsigned char *bufPtr = buf; + int pos = 0, nextOffset = 64; + unsigned char *bufPtr2 = bufPtr + nextOffset; + unsigned char *ptr = (unsigned char *)data; + + // put our last result or zero at beginning of buffer each time + memset(bufPtr, 0, 32); + + // digest up to 32 bytes at a time + for ( ; pos < len; pos += 32) + { + if (len - pos >= 32) + { + memcpy(bufPtr + 32, ptr + pos, 32); + } + else + { + int i = (int)(len - pos); + memcpy(bufPtr + 32, ptr + pos, i); + memset(bufPtr + 32 + i, 0, 32 - i); + } + (*haraka512Function)(bufPtr2, bufPtr); + bufPtr2 = bufPtr; + bufPtr += nextOffset; + nextOffset *= -1; + } + memcpy(result, bufPtr, 32); +}; + +CVerusHashV2 &CVerusHashV2::Write(const unsigned char *data, size_t len) +{ + unsigned char *tmp; + + // digest up to 32 bytes at a time + for ( int pos = 0; pos < len; ) + { + int room = 32 - curPos; + + if (len - pos >= room) + { + memcpy(curBuf + 32 + curPos, data + pos, room); + (*haraka512Function)(result, curBuf); + tmp = curBuf; + curBuf = result; + result = tmp; + pos += room; + curPos = 0; + } + else + { + memcpy(curBuf + 32 + curPos, data + pos, len - pos); + curPos += len - pos; + pos = len; + } + } + return *this; +} + +// to be declared and accessed from C +void verus_hash_v2(void *result, const void *data, size_t len) +{ + return CVerusHashV2::Hash(result, data, len); +} diff --git a/src/crypto/verus_hash.h b/src/crypto/verus_hash.h new file mode 100644 index 00000000000..63ff1aaaa27 --- /dev/null +++ b/src/crypto/verus_hash.h @@ -0,0 +1,134 @@ +// (C) 2018 Michael Toutonghi +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +/* +This provides the PoW hash function for Verus, enabling CPU mining. +*/ +#ifndef VERUS_HASH_H_ +#define VERUS_HASH_H_ + +#include +#include + +#include + +extern "C" +{ +#include "crypto/haraka.h" +#include "crypto/haraka_portable.h" +} + +class CVerusHash +{ + public: + static void Hash(void *result, const void *data, size_t len); + static void (*haraka512Function)(unsigned char *out, const unsigned char *in); + + static void init(); + + CVerusHash() { } + + CVerusHash &Write(const unsigned char *data, size_t len); + + CVerusHash &Reset() + { + curBuf = buf1; + result = buf2; + curPos = 0; + std::fill(buf1, buf1 + sizeof(buf1), 0); + return *this; + } + + int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } + void ClearExtra() + { + if (curPos) + { + std::fill(curBuf + 32 + curPos, curBuf + 64, 0); + } + } + void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } + + void Finalize(unsigned char hash[32]) + { + if (curPos) + { + std::fill(curBuf + 32 + curPos, curBuf + 64, 0); + (*haraka512Function)(hash, curBuf); + } + else + std::memcpy(hash, curBuf, 32); + } + + private: + // only buf1, the first source, needs to be zero initialized + unsigned char buf1[64] = {0}, buf2[64]; + unsigned char *curBuf = buf1, *result = buf2; + size_t curPos = 0; +}; + +class CVerusHashV2 +{ + public: + static void Hash(void *result, const void *data, size_t len); + static void (*haraka512Function)(unsigned char *out, const unsigned char *in); + + static void init(); + + CVerusHashV2() {} + + CVerusHashV2 &Write(const unsigned char *data, size_t len); + + CVerusHashV2 &Reset() + { + curBuf = buf1; + result = buf2; + curPos = 0; + std::fill(buf1, buf1 + sizeof(buf1), 0); + return *this; + } + + int64_t *ExtraI64Ptr() { return (int64_t *)(curBuf + 32); } + void ClearExtra() + { + if (curPos) + { + std::fill(curBuf + 32 + curPos, curBuf + 64, 0); + } + } + void ExtraHash(unsigned char hash[32]) { (*haraka512Function)(hash, curBuf); } + + void Finalize(unsigned char hash[32]) + { + if (curPos) + { + std::fill(curBuf + 32 + curPos, curBuf + 64, 0); + (*haraka512Function)(hash, curBuf); + } + else + std::memcpy(hash, curBuf, 32); + } + + private: + // only buf1, the first source, needs to be zero initialized + unsigned char buf1[64] = {0}, buf2[64]; + unsigned char *curBuf = buf1, *result = buf2; + size_t curPos = 0; +}; + +extern void verus_hash(void *result, const void *data, size_t len); +extern void verus_hash_v2(void *result, const void *data, size_t len); + +inline bool IsCPUVerusOptimized() +{ + unsigned int eax,ebx,ecx,edx; + + if (!__get_cpuid(1,&eax,&ebx,&ecx,&edx)) + { + return false; + } + return ((ecx & (bit_AVX | bit_AES)) == (bit_AVX | bit_AES)); +}; + +#endif