diff --git a/AUTHORS b/AUTHORS
index 9cff06784e0c..936932dcc678 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -9,4 +9,6 @@ Genjix - Porting pro-mode functionality to lite-gui and worked on server
Slush - Work on the server. Designed the original Stratum spec.
Julian Toash (Tuxavant) - Various fixes to the client.
rdymac - Website and translations.
-kyuupichan - Miscellaneous.
\ No newline at end of file
+kyuupichan - Miscellaneous.
+pooler - Litecoin port.
+sn-ntu - Zcoin port.
diff --git a/Info.plist b/Info.plist
index a8f58f733958..22c46a94aa26 100644
--- a/Info.plist
+++ b/Info.plist
@@ -6,10 +6,10 @@
CFBundleURLName
- bitcoin
+ zcoin
CFBundleURLSchemes
- bitcoin
+ zcoin
diff --git a/MANIFEST.in b/MANIFEST.in
index 4fa5491a6d48..cb52871c28ff 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1,9 +1,9 @@
include LICENCE RELEASE-NOTES AUTHORS
include README.rst
-include electrum.conf.sample
-include electrum.desktop
+include electrum-xzc.conf.sample
+include electrum-xzc.desktop
include *.py
-include electrum
+include electrum-xzc
recursive-include lib *.py
recursive-include gui *.py
recursive-include plugins *.py
diff --git a/README.rst b/README.rst
index 9b183235477a..fbc11c3fe3a3 100644
--- a/README.rst
+++ b/README.rst
@@ -1,20 +1,13 @@
-Electrum - Lightweight Bitcoin client
-=====================================
+Electrum-XZC - Lightweight Zcoin client
+=======================================
::
Licence: MIT Licence
- Author: Thomas Voegtlin
+ Original Author: Thomas Voegtlin
+ Port Maintainer: Pooler, SN
Language: Python
- Homepage: https://electrum.org/
-
-
-.. image:: https://travis-ci.org/spesmilo/electrum.svg?branch=master
- :target: https://travis-ci.org/spesmilo/electrum
- :alt: Build Status
-.. image:: https://coveralls.io/repos/github/spesmilo/electrum/badge.svg?branch=master
- :target: https://coveralls.io/github/spesmilo/electrum?branch=master
- :alt: Test coverage statistics
+ Homepage: https://electrum.zcoin.io/
@@ -34,7 +27,7 @@ Electrum from its root directory, without installing it on your
system; all the python dependencies are included in the 'packages'
directory. To run Electrum from its root directory, just do::
- ./electrum
+ ./electrum-xzc
You can also install Electrum on your system, by running this command::
@@ -53,10 +46,32 @@ Version".
Development version
===================
+ElectrumX developer decided to use newer Python 3 which isn't installed on many operating systems by default. Let's install it manually::
+
+ sudo add-apt-repository ppa:jonathonf/python-3.6
+ sudo apt-get update && sudo apt-get install python3.6 python3.6-dev python3-pip python3-pyqt5
+
+To make python3 use the new installed python 3.6 instead of the default 3.5 release, run following 3 commands::
+
+ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.5 1
+ sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
+ sudo update-alternatives --config python3
+
+Install dependencies::
+
+ sudo apt-get install pyqt5-dev-tools protobuf-compiler python-requests gettext
+ pip3 install --upgrade pip setuptools wheel
+
Check out the code from Github::
- git clone git://github.com/spesmilo/electrum.git
- cd electrum
+ git clone git://github.com/sn-ntu/electrum-xzc.git
+ cd electrum-xzc
+
+Install lyra2z lib::
+
+ cd ./exlib/lyra2z-py/
+ sudo python3 setup.py install
+ cd ../../
Run install (this should install dependencies)::
@@ -64,17 +79,14 @@ Run install (this should install dependencies)::
Compile the icons file for Qt::
- sudo apt-get install pyqt5-dev-tools
pyrcc5 icons.qrc -o gui/qt/icons_rc.py
Compile the protobuf description file::
- sudo apt-get install protobuf-compiler
protoc --proto_path=lib/ --python_out=lib/ lib/paymentrequest.proto
Create translations (optional)::
- sudo apt-get install python-requests gettext
./contrib/make_locale
@@ -93,12 +105,13 @@ This directory contains the python dependencies used by Electrum.
Mac OS X / macOS
--------
-See `contrib/build-osx/`.
+See `contrib/build-osx/README`.
+
Windows
-------
-See `contrib/build-wine/`.
+See `contrib/build-wine/README` file.
Android
diff --git a/RELEASE-NOTES b/RELEASE-NOTES
index ddadee13d6b4..2a06061e836b 100644
--- a/RELEASE-NOTES
+++ b/RELEASE-NOTES
@@ -1,50 +1,3 @@
-# Release 3.1 - (to be released)
-
- * Mempory pool based fee estimates. If this option is activated,
- users can set transaction fees that target a desired depth in the
- memory pool. This feature might be controversial, because miners
- could conspire and fill the memory pool with expensive transactions
- that never get mined. However, our current time-based fee estimates
- results in sticky fees, which cause inexperienced users to overpay,
- while more advanced users visit (and trust) websites that display
- memorypool data, and set their fee accordingly.
- * Local transactions: Transactions that have not been broadcasted can
- be saved in the wallet file, and their outputs can be used in
- subsequent transactions. Transactions that disapear from the memory
- pool stay in the wallet, and can be rebroadcasted. This feature can
- be combined with cold storage, to create several transactions
- before broadcasting.
- * The initial headers download was replaced with hardcoded
- checkpoints, one per retargeting period. Past headers are
- downloaded when needed.
- * The two coin selection policies have been merged, and the policy
- choice was removed from preferences. Previously, the 'privacy'
- policy has been unusable because it was was not prioritizing
- confirmed coins.
- * The 'Send' tab of the Qt GUI displays how transaction fees are
- computed from transaction size.
- * RBF is enabled by default. This might cause some issues with
- merchants that use wallets that do not display RBF transactions
- until they are confirmed.
- * Watching-only wallets and hardware wallets can be encrypted.
- * Semi-automated crash reporting
- * The SSL checkbox option was removed from the GUI.
- * Capital gains: For each outgoing transaction, the difference
- between the acquisition and liquidation prices of outgoing coins is
- displayed in the wallet history. By default, historical exchange
- rates are used to compute acquisition and liquidation prices. These
- value can also be entered manually, in order to match the actual
- price realized by the user. The order of liquidation of coins is
- the natural order defined by the blockchain; this results in
- capital gain values that are invariant to changes in the set of
- addresses that are in the wallet. Any other ordering strategy (such
- as FIFO, LIFO) would result in capital gain values that depend on
- the set of addresses in the wallet.
-
-
-# Release 3.0.6 :
- * Fix transaction parsing bug #3788
-
# Release 3.0.5 : (Security update)
This is a follow-up to the 3.0.4 release, which did not completely fix
diff --git a/contrib/build-wine/build-electrum-git.sh b/contrib/build-wine/build-electrum-git.sh
index a8f743588f98..0878eaefc8f2 100755
--- a/contrib/build-wine/build-electrum-git.sh
+++ b/contrib/build-wine/build-electrum-git.sh
@@ -1,6 +1,6 @@
#!/bin/bash
-NAME_ROOT=electrum
+NAME_ROOT=electrum-xzc
PYTHON_VERSION=3.5.4
# These settings probably don't need any change
@@ -18,19 +18,19 @@ set -e
cd tmp
-for repo in electrum electrum-locale electrum-icons; do
+for repo in electrum-xzc electrum-xzc-locale electrum-xzc-icons; do
if [ -d $repo ]; then
cd $repo
git pull
git checkout master
cd ..
else
- URL=https://github.com/spesmilo/$repo.git
+ URL=https://github.com/sn-ntu/$repo.git
git clone -b master $URL $repo
fi
done
-pushd electrum-locale
+pushd electrum-xzc-locale
for i in ./locale/*; do
dir=$i/LC_MESSAGES
mkdir -p $dir
@@ -38,7 +38,7 @@ for i in ./locale/*; do
done
popd
-pushd electrum
+pushd electrum-xzc
if [ ! -z "$1" ]; then
git checkout $1
fi
@@ -48,17 +48,16 @@ echo "Last commit: $VERSION"
find -exec touch -d '2000-11-11T11:11:11+00:00' {} +
popd
-rm -rf $WINEPREFIX/drive_c/electrum
-cp -r electrum $WINEPREFIX/drive_c/electrum
-cp electrum/LICENCE .
-cp -r electrum-locale/locale $WINEPREFIX/drive_c/electrum/lib/
-cp electrum-icons/icons_rc.py $WINEPREFIX/drive_c/electrum/gui/qt/
+rm -rf $WINEPREFIX/drive_c/electrum-xzc
+cp -r electrum-xzc $WINEPREFIX/drive_c/electrum-xzc
+cp electrum-xzc/LICENCE .
+cp -r electrum-xzc-locale/locale $WINEPREFIX/drive_c/electrum-xzc/lib/
+cp electrum-xzc-icons/icons_rc.py $WINEPREFIX/drive_c/electrum-xzc/gui/qt/
# Install frozen dependencies
-$PYTHON -m pip install -r ../../deterministic-build/requirements.txt
-$PYTHON -m pip install -r ../../deterministic-build/requirements-hw.txt
+$PYTHON -m pip install -r ../../requirements.txt
-pushd $WINEPREFIX/drive_c/electrum
+pushd $WINEPREFIX/drive_c/electrum-xzc
$PYTHON setup.py install
popd
@@ -79,7 +78,7 @@ popd
wine "$WINEPREFIX/drive_c/Program Files (x86)/NSIS/makensis.exe" /DPRODUCT_VERSION=$VERSION electrum.nsi
cd dist
-mv electrum-setup.exe $NAME_ROOT-$VERSION-setup.exe
+mv electrum-xzc-setup.exe $NAME_ROOT-$VERSION-setup.exe
cd ..
echo "Done."
diff --git a/contrib/build-wine/build.sh b/contrib/build-wine/build.sh
index 8bf650626c9b..efd23bc17c0f 100755
--- a/contrib/build-wine/build.sh
+++ b/contrib/build-wine/build.sh
@@ -13,7 +13,9 @@ echo "Clearing $here/build and $here/dist..."
rm "$here"/build/* -rf
rm "$here"/dist/* -rf
-$here/prepare-wine.sh || exit 1
+$here/prepare-wine.sh && \
+$here/prepare-pyinstaller.sh && \
+$here/prepare-hw.sh || exit 1
echo "Resetting modification time in C:\Python..."
# (Because of some bugs in pyinstaller)
diff --git a/contrib/build-wine/deterministic.spec b/contrib/build-wine/deterministic.spec
index 3dc5953b537b..80f13e4586f4 100644
--- a/contrib/build-wine/deterministic.spec
+++ b/contrib/build-wine/deterministic.spec
@@ -11,36 +11,38 @@ else:
raise BaseException('no name')
-home = 'C:\\electrum\\'
+home = 'C:\\electrum-xzc\\'
# see https://github.com/pyinstaller/pyinstaller/issues/2005
hiddenimports = []
hiddenimports += collect_submodules('trezorlib')
hiddenimports += collect_submodules('btchip')
hiddenimports += collect_submodules('keepkeylib')
+hiddenimports += ['_scrypt']
datas = [
- (home+'lib/currencies.json', 'electrum'),
- (home+'lib/servers.json', 'electrum'),
- (home+'lib/checkpoints.json', 'electrum'),
- (home+'lib/servers_testnet.json', 'electrum'),
- (home+'lib/checkpoints_testnet.json', 'electrum'),
- (home+'lib/wordlist/english.txt', 'electrum/wordlist'),
- (home+'lib/locale', 'electrum/locale'),
- (home+'plugins', 'electrum_plugins'),
+ (home+'lib/currencies.json', 'electrum_xzc'),
+ (home+'lib/servers.json', 'electrum_xzc'),
+ (home+'lib/checkpoints.json', 'electrum_xzc'),
+ (home+'lib/servers_testnet.json', 'electrum_xzc'),
+ (home+'lib/checkpoints_testnet.json', 'electrum_xzc'),
+ (home+'lib/wordlist/english.txt', 'electrum_xzc/wordlist'),
+ (home+'lib/locale', 'electrum_xzc/locale'),
+ (home+'plugins', 'electrum_xzc_plugins'),
]
datas += collect_data_files('trezorlib')
datas += collect_data_files('btchip')
datas += collect_data_files('keepkeylib')
# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports
-a = Analysis([home+'electrum',
+a = Analysis([home+'electrum-xzc',
home+'gui/qt/main_window.py',
home+'gui/text.py',
home+'lib/util.py',
home+'lib/wallet.py',
home+'lib/simple_config.py',
home+'lib/bitcoin.py',
+ home+'lib/blockchain.py',
home+'lib/dnssec.py',
home+'lib/commands.py',
home+'plugins/cosigner_pool/qt.py',
@@ -77,7 +79,7 @@ exe_standalone = EXE(
a.scripts,
a.binaries,
a.datas,
- name=os.path.join('build\\pyi.win32\\electrum', cmdline_name + ".exe"),
+ name=os.path.join('build\\pyi.win32\\electrum-xzc', cmdline_name + ".exe"),
debug=False,
strip=None,
upx=False,
@@ -90,7 +92,7 @@ exe_portable = EXE(
a.scripts,
a.binaries,
a.datas + [ ('is_portable', 'README.md', 'DATA' ) ],
- name=os.path.join('build\\pyi.win32\\electrum', cmdline_name + "-portable.exe"),
+ name=os.path.join('build\\pyi.win32\\electrum-xzc', cmdline_name + "-portable.exe"),
debug=False,
strip=None,
upx=False,
@@ -104,7 +106,7 @@ exe_dependent = EXE(
pyz,
a.scripts,
exclude_binaries=True,
- name=os.path.join('build\\pyi.win32\\electrum', cmdline_name),
+ name=os.path.join('build\\pyi.win32\\electrum-xzc', cmdline_name),
debug=False,
strip=None,
upx=False,
@@ -121,4 +123,4 @@ coll = COLLECT(
debug=False,
icon=home+'icons/electrum.ico',
console=False,
- name=os.path.join('dist', 'electrum'))
+ name=os.path.join('dist', 'electrum-xzc'))
diff --git a/contrib/build-wine/electrum.nsi b/contrib/build-wine/electrum.nsi
index 0a30033257ea..d70747b2a304 100644
--- a/contrib/build-wine/electrum.nsi
+++ b/contrib/build-wine/electrum.nsi
@@ -6,8 +6,8 @@
;--------------------------------
;Variables
- !define PRODUCT_NAME "Electrum"
- !define PRODUCT_WEB_SITE "https://github.com/spesmilo/electrum"
+ !define PRODUCT_NAME "Electrum-XZC"
+ !define PRODUCT_WEB_SITE "https://github.com/sn-ntu/electrum-xzc"
!define PRODUCT_PUBLISHER "Electrum Technologies GmbH"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
@@ -16,7 +16,7 @@
;Name and file
Name "${PRODUCT_NAME}"
- OutFile "dist/electrum-setup.exe"
+ OutFile "dist/electrum-xzc-setup.exe"
;Default installation folder
InstallDir "$PROGRAMFILES\${PRODUCT_NAME}"
@@ -72,7 +72,7 @@
!define MUI_ABORTWARNING
!define MUI_ABORTWARNING_TEXT "Are you sure you wish to abort the installation of ${PRODUCT_NAME}?"
- !define MUI_ICON "tmp\electrum\icons\electrum.ico"
+ !define MUI_ICON "tmp\electrum-xzc\icons\electrum.ico"
;--------------------------------
;Pages
@@ -110,7 +110,7 @@ Section
Delete "$SMPROGRAMS\${PRODUCT_NAME}\*.*"
;Files to pack into the installer
- File /r "dist\electrum\*.*"
+ File /r "dist\electrum-xzc\*.*"
File "..\..\icons\electrum.ico"
;Store installation folder
@@ -122,21 +122,21 @@ Section
;Create desktop shortcut
DetailPrint "Creating desktop shortcut..."
- CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\electrum-${PRODUCT_VERSION}.exe" ""
+ CreateShortCut "$DESKTOP\${PRODUCT_NAME}.lnk" "$INSTDIR\electrum-xzc-${PRODUCT_VERSION}.exe" ""
;Create start-menu items
DetailPrint "Creating start-menu items..."
CreateDirectory "$SMPROGRAMS\${PRODUCT_NAME}"
CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\Uninstall.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
- CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\electrum-${PRODUCT_VERSION}.exe" "" "$INSTDIR\electrum-${PRODUCT_VERSION}.exe" 0
- CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME} Testnet.lnk" "$INSTDIR\electrum-${PRODUCT_VERSION}.exe" "--testnet" "$INSTDIR\electrum-${PRODUCT_VERSION}.exe" 0
+ CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME}.lnk" "$INSTDIR\electrum-xzc-${PRODUCT_VERSION}.exe" "" "$INSTDIR\electrum-xzc-${PRODUCT_VERSION}.exe" 0
+ CreateShortCut "$SMPROGRAMS\${PRODUCT_NAME}\${PRODUCT_NAME} Testnet.lnk" "$INSTDIR\electrum-xzc-${PRODUCT_VERSION}.exe" "--testnet" "$INSTDIR\electrum-xzc-${PRODUCT_VERSION}.exe" 0
;Links bitcoin: URI's to Electrum
- WriteRegStr HKCU "Software\Classes\bitcoin" "" "URL:bitcoin Protocol"
- WriteRegStr HKCU "Software\Classes\bitcoin" "URL Protocol" ""
- WriteRegStr HKCU "Software\Classes\bitcoin" "DefaultIcon" "$\"$INSTDIR\electrum.ico, 0$\""
- WriteRegStr HKCU "Software\Classes\bitcoin\shell\open\command" "" "$\"$INSTDIR\electrum-${PRODUCT_VERSION}.exe$\" $\"%1$\""
+ WriteRegStr HKCU "Software\Classes\zcoin" "" "URL:zcoin Protocol"
+ WriteRegStr HKCU "Software\Classes\zcoin" "URL Protocol" ""
+ WriteRegStr HKCU "Software\Classes\zcoin" "DefaultIcon" "$\"$INSTDIR\electrum.ico, 0$\""
+ WriteRegStr HKCU "Software\Classes\zcoin\shell\open\command" "" "$\"$INSTDIR\electrum-xzc-${PRODUCT_VERSION}.exe$\" $\"%1$\""
;Adds an uninstaller possibilty to Windows Uninstall or change a program section
WriteRegStr HKCU "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
@@ -167,7 +167,7 @@ Section "Uninstall"
Delete "$SMPROGRAMS\${PRODUCT_NAME}\*.*"
RMDir "$SMPROGRAMS\${PRODUCT_NAME}"
- DeleteRegKey HKCU "Software\Classes\bitcoin"
+ DeleteRegKey HKCU "Software\Classes\zcoin"
DeleteRegKey HKCU "Software\${PRODUCT_NAME}"
DeleteRegKey HKCU "${PRODUCT_UNINST_KEY}"
SectionEnd
diff --git a/contrib/build-wine/prepare-hw.sh b/contrib/build-wine/prepare-hw.sh
new file mode 100755
index 000000000000..1851b7b0ffd9
--- /dev/null
+++ b/contrib/build-wine/prepare-hw.sh
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+TREZOR_GIT_URL=https://github.com/trezor/python-trezor.git
+KEEPKEY_GIT_URL=https://github.com/keepkey/python-keepkey.git
+BTCHIP_GIT_URL=https://github.com/LedgerHQ/btchip-python.git
+
+BRANCH=master
+
+PYTHON_VERSION=3.5.4
+
+# These settings probably don't need any change
+export WINEPREFIX=/opt/wine64
+
+PYHOME=c:/python$PYTHON_VERSION
+PYTHON="wine $PYHOME/python.exe -OO -B"
+
+# Let's begin!
+cd `dirname $0`
+set -e
+
+cd tmp
+
+$PYTHON -m pip install setuptools --upgrade
+$PYTHON -m pip install cython --upgrade
+$PYTHON -m pip install trezor==0.7.16 --upgrade
+$PYTHON -m pip install keepkey==4.0.0 --upgrade
+$PYTHON -m pip install btchip-python==0.1.23 --upgrade
+
diff --git a/contrib/build-wine/prepare-pyinstaller.sh b/contrib/build-wine/prepare-pyinstaller.sh
new file mode 100755
index 000000000000..cf8a326cdf7f
--- /dev/null
+++ b/contrib/build-wine/prepare-pyinstaller.sh
@@ -0,0 +1,24 @@
+#!/bin/bash
+PYTHON_VERSION=3.5.4
+
+PYINSTALLER_GIT_URL=https://github.com/ecdsa/pyinstaller.git
+BRANCH=fix_2952
+
+export WINEPREFIX=/opt/wine64
+PYHOME=c:/python$PYTHON_VERSION
+PYTHON="wine $PYHOME/python.exe -OO -B"
+
+cd `dirname $0`
+set -e
+cd tmp
+if [ ! -d "pyinstaller" ]; then
+ git clone -b $BRANCH $PYINSTALLER_GIT_URL pyinstaller
+fi
+
+cd pyinstaller
+git pull
+git checkout $BRANCH
+$PYTHON setup.py install
+cd ..
+
+wine "C:/python$PYTHON_VERSION/scripts/pyinstaller.exe" -v
diff --git a/contrib/build-wine/prepare-wine.sh b/contrib/build-wine/prepare-wine.sh
index d62b4c63da7f..1282dc0bc870 100755
--- a/contrib/build-wine/prepare-wine.sh
+++ b/contrib/build-wine/prepare-wine.sh
@@ -72,22 +72,28 @@ done
# upgrade pip
$PYTHON -m pip install pip --upgrade
-# Install pywin32-ctypes (needed by pyinstaller)
-$PYTHON -m pip install pywin32-ctypes==0.1.2
+# Install PyWin32
+$PYTHON -m pip install pypiwin32
-# install PySocks
-$PYTHON -m pip install win_inet_pton==1.0.1
-
-$PYTHON -m pip install -r ../../deterministic-build/requirements-binaries.txt
+# Install PyQt
+$PYTHON -m pip install PyQt5
-# Install PyInstaller
+## Install pyinstaller
+#$PYTHON -m pip install pyinstaller==3.3
-$PYTHON -m pip install git+https://github.com/ecdsa/pyinstaller@fix_2952
# Install ZBar
#wget -q -O zbar.exe "https://sourceforge.net/projects/zbar/files/zbar/0.10/zbar-0.10-setup.exe/download"
#wine zbar.exe
+# install Cryptodome
+$PYTHON -m pip install pycryptodomex
+
+# install PySocks
+$PYTHON -m pip install win_inet_pton
+
+# install websocket (python2)
+$PYTHON -m pip install websocket-client
# Upgrade setuptools (so Electrum can be installed later)
$PYTHON -m pip install setuptools --upgrade
@@ -105,4 +111,21 @@ wine nsis.exe /S
# add dlls needed for pyinstaller:
cp $WINEPREFIX/drive_c/python$PYTHON_VERSION/Lib/site-packages/PyQt5/Qt/bin/* $WINEPREFIX/drive_c/python$PYTHON_VERSION/
+
+# Install MinGW
+wget http://downloads.sourceforge.net/project/mingw/Installer/mingw-get-setup.exe
+wine mingw-get-setup.exe
+
+echo "add c:\MinGW\bin to PATH using regedit"
+echo "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
+regedit
+
+wine mingw-get install gcc
+wine mingw-get install mingw-utils
+wine mingw-get install mingw32-libz
+
+printf "[build]\ncompiler=mingw32\n" > $WINEPREFIX/drive_c/python$PYTHON_VERSION/Lib/distutils/distutils.cfg
+
+$PYTHON -m pip install scrypt
+
echo "Wine is configured. Please run prepare-pyinstaller.sh"
diff --git a/contrib/freeze_packages.sh b/contrib/freeze_packages.sh
index 3471e528bff5..c8e4527b968f 100755
--- a/contrib/freeze_packages.sh
+++ b/contrib/freeze_packages.sh
@@ -6,17 +6,17 @@ contrib=$(dirname "$0")
which virtualenv > /dev/null 2>&1 || { echo "Please install virtualenv" && exit 1; }
-for i in '' '-hw' '-binaries'; do
- rm "$venv_dir" -rf
- virtualenv -p $(which python3) $venv_dir
+rm "$venv_dir" -rf
+virtualenv -p $(which python3) $venv_dir
- source $venv_dir/bin/activate
+source $venv_dir/bin/activate
- echo "Installing $i dependencies"
+echo "Installing dependencies"
- python -m pip install -r $contrib/requirements/requirements${i}.txt --upgrade
+pushd $contrib/..
+python setup.py install
+popd
- pip freeze | sed '/^Electrum/ d' > $contrib/deterministic-build/requirements${i}.txt
-done
+pip freeze | sed '/^Electrum/ d' > $contrib/requirements.txt
-echo "Done. Updated requirements"
+echo "Updated requirements"
diff --git a/contrib/make_download b/contrib/make_download
index 84e4ff21b6ca..cfc0812aa88b 100755
--- a/contrib/make_download
+++ b/contrib/make_download
@@ -15,17 +15,17 @@ string = string.replace("##VERSION_ANDROID##", version_android)
string = string.replace("##VERSION_APK##", version_apk)
files = {
- 'tgz': "Electrum-%s.tar.gz" % version,
- 'zip': "Electrum-%s.zip" % version,
- 'mac': "electrum-%s.dmg" % version_mac,
- 'win': "electrum-%s.exe" % version_win,
- 'win_setup': "electrum-%s-setup.exe" % version_win,
- 'win_portable': "electrum-%s-portable.exe" % version_win,
+ 'tgz': "Electrum-XZC-%s.tar.gz" % version,
+ 'zip': "Electrum-XZC-%s.zip" % version,
+ 'mac': "electrum-xzc-%s.dmg" % version_mac,
+ 'win': "electrum-xzc-%s.exe" % version_win,
+ 'win_setup': "electrum-xzc-%s-setup.exe" % version_win,
+ 'win_portable': "electrum-xzc-%s-portable.exe" % version_win,
}
for k, n in files.items():
path = "dist/%s"%n
- link = "https://download.electrum.org/%s/%s"%(version,n)
+ link = "https://download.electrum-xzc.org/%s"%n
if not os.path.exists(path):
os.system("wget -q %s -O %s" % (link, path))
if not os.path.getsize(path):
diff --git a/contrib/make_osx b/contrib/make_osx
new file mode 100755
index 000000000000..c634645f3dfc
--- /dev/null
+++ b/contrib/make_osx
@@ -0,0 +1,6 @@
+#!/bin/bash
+rm -rf dist
+export PYTHONHASHSEED=22
+VERSION=`git describe --tags`
+pyinstaller --noconfirm --ascii --name $VERSION contrib/osx.spec
+hdiutil create -fs HFS+ -volname "Electrum-XZC" -srcfolder dist/Electrum-XZC.app dist/electrum-xzc-$VERSION.dmg
diff --git a/contrib/make_packages b/contrib/make_packages
index 9cfd32bb24cc..b3a36049722e 100755
--- a/contrib/make_packages
+++ b/contrib/make_packages
@@ -9,5 +9,5 @@ if [ $? -ne 0 ] ; then echo "Install pip3" ; exit ; fi
rm "$contrib"/../packages/ -r
#Install pure python modules in electrum directory
-pip3 install -r $contrib/deterministic-build/requirements.txt -t $contrib/../packages
+pip3 install -r $contrib/requirements.txt -t $contrib/../packages
diff --git a/contrib/osx.spec b/contrib/osx.spec
new file mode 100644
index 000000000000..7864b08292b3
--- /dev/null
+++ b/contrib/osx.spec
@@ -0,0 +1,87 @@
+# -*- mode: python -*-
+
+from PyInstaller.utils.hooks import collect_data_files, collect_submodules
+
+import sys
+import os
+
+for i, x in enumerate(sys.argv):
+ if x == '--name':
+ VERSION = sys.argv[i+1]
+ break
+else:
+ raise BaseException('no version')
+
+electrum = "../"
+block_cipher=None
+
+# see https://github.com/pyinstaller/pyinstaller/issues/2005
+hiddenimports = []
+hiddenimports += collect_submodules('trezorlib')
+hiddenimports += collect_submodules('btchip')
+hiddenimports += collect_submodules('keepkeylib')
+hiddenimports += ['_scrypt']
+
+datas = [
+ (electrum+'lib/currencies.json', 'electrum_xzc'),
+ (electrum+'lib/servers.json', 'electrum_xzc'),
+ (electrum+'lib/checkpoints.json', 'electrum_xzc'),
+ (electrum+'lib/servers_testnet.json', 'electrum_xzc'),
+ (electrum+'lib/checkpoints_testnet.json', 'electrum_xzc'),
+ (electrum+'lib/wordlist/english.txt', 'electrum_xzc/wordlist'),
+ (electrum+'lib/locale', 'electrum_xzc/locale'),
+ (electrum+'plugins', 'electrum_xzc_plugins'),
+]
+datas += collect_data_files('trezorlib')
+datas += collect_data_files('btchip')
+datas += collect_data_files('keepkeylib')
+
+# We don't put these files in to actually include them in the script but to make the Analysis method scan them for imports
+a = Analysis([electrum+'electrum-xzc',
+ electrum+'gui/qt/main_window.py',
+ electrum+'gui/text.py',
+ electrum+'lib/util.py',
+ electrum+'lib/wallet.py',
+ electrum+'lib/simple_config.py',
+ electrum+'lib/bitcoin.py',
+ electrum+'lib/dnssec.py',
+ electrum+'lib/commands.py',
+ electrum+'plugins/cosigner_pool/qt.py',
+ electrum+'plugins/email_requests/qt.py',
+ electrum+'plugins/trezor/client.py',
+ electrum+'plugins/trezor/qt.py',
+ electrum+'plugins/keepkey/qt.py',
+ electrum+'plugins/ledger/qt.py',
+ ],
+ datas=datas,
+ hiddenimports=hiddenimports,
+ hookspath=[])
+
+# http://stackoverflow.com/questions/19055089/pyinstaller-onefile-warning-pyconfig-h-when-importing-scipy-or-scipy-signal
+for d in a.datas:
+ if 'pyconfig' in d[0]:
+ a.datas.remove(d)
+ break
+
+pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
+
+exe = EXE(pyz,
+ a.scripts,
+ a.binaries,
+ a.datas,
+ name='Electrum-XZC',
+ debug=False,
+ strip=False,
+ upx=True,
+ icon=electrum+'electrum.icns',
+ console=False)
+
+app = BUNDLE(exe,
+ version = VERSION,
+ name='Electrum-XZC.app',
+ icon=electrum+'electrum.icns',
+ bundle_identifier=None,
+ info_plist = {
+ 'NSHighResolutionCapable':'True'
+ }
+)
diff --git a/contrib/requirements.txt b/contrib/requirements.txt
new file mode 100644
index 000000000000..828818a6e5ef
--- /dev/null
+++ b/contrib/requirements.txt
@@ -0,0 +1,15 @@
+certifi==2017.11.5
+chardet==3.0.4
+dnspython==1.15.0
+ecdsa==0.13
+idna==2.6
+jsonrpclib-pelix==0.3.1
+pbkdf2==1.3
+protobuf==3.5.0.post1
+pyaes==1.6.1
+PySocks==1.6.7
+qrcode==5.3
+requests==2.18.4
+scrypt==0.8.0
+six==1.11.0
+urllib3==1.22
diff --git a/electrum b/electrum
index 25495f79e389..9df3e612af2c 100755
--- a/electrum
+++ b/electrum
@@ -193,8 +193,6 @@ def init_daemon(config_options):
print_msg("Type 'electrum create' to create a new wallet, or provide a path to a wallet with the -w option")
sys.exit(0)
if storage.is_encrypted():
- if storage.is_encrypted_with_hw_device():
- raise NotImplementedError("CLI functionality of encrypted hw wallets")
if config.get('password'):
password = config.get('password')
else:
@@ -239,8 +237,6 @@ def init_cmdline(config_options, server):
# commands needing password
if (cmd.requires_wallet and storage.is_encrypted() and server is None)\
or (cmd.requires_password and (storage.get('use_encryption') or storage.is_encrypted())):
- if storage.is_encrypted_with_hw_device():
- raise NotImplementedError("CLI functionality of encrypted hw wallets")
if config.get('password'):
password = config.get('password')
else:
@@ -267,14 +263,12 @@ def run_offline_command(config, config_options):
if cmd.requires_wallet:
storage = WalletStorage(config.get_wallet_path())
if storage.is_encrypted():
- if storage.is_encrypted_with_hw_device():
- raise NotImplementedError("CLI functionality of encrypted hw wallets")
storage.decrypt(password)
wallet = Wallet(storage)
else:
wallet = None
# check password
- if cmd.requires_password and wallet.has_password():
+ if cmd.requires_password and storage.get('use_encryption'):
try:
seed = wallet.check_password(password)
except InvalidPassword:
diff --git a/electrum-env b/electrum-env
index 42220edab67c..b44bd496b4e6 100755
--- a/electrum-env
+++ b/electrum-env
@@ -19,6 +19,6 @@ fi
export PYTHONPATH="/usr/local/lib/python3.5/site-packages:$PYTHONPATH"
-./electrum "$@"
+./electrum-xzc "$@"
deactivate
diff --git a/electrum-xzc b/electrum-xzc
new file mode 100755
index 000000000000..5bf33bd3be51
--- /dev/null
+++ b/electrum-xzc
@@ -0,0 +1,443 @@
+#!/usr/bin/env python3
+# -*- mode: python -*-
+#
+# Electrum - lightweight Bitcoin client
+# Copyright (C) 2011 thomasv@gitorious
+#
+# 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.
+import os
+import sys
+
+# from https://gist.github.com/tito/09c42fb4767721dc323d
+import threading
+try:
+ import jnius
+except:
+ jnius = None
+if jnius:
+ orig_thread_run = threading.Thread.run
+ def thread_check_run(*args, **kwargs):
+ try:
+ return orig_thread_run(*args, **kwargs)
+ finally:
+ jnius.detach()
+ threading.Thread.run = thread_check_run
+
+script_dir = os.path.dirname(os.path.realpath(__file__))
+is_bundle = getattr(sys, 'frozen', False)
+is_local = not is_bundle and os.path.exists(os.path.join(script_dir, "electrum-xzc.desktop"))
+is_android = 'ANDROID_DATA' in os.environ
+
+# move this back to gui/kivy/__init.py once plugins are moved
+os.environ['KIVY_DATA_DIR'] = os.path.abspath(os.path.dirname(__file__)) + '/gui/kivy/data/'
+
+if is_local or is_android:
+ sys.path.insert(0, os.path.join(script_dir, 'packages'))
+
+
+def check_imports():
+ # pure-python dependencies need to be imported here for pyinstaller
+ try:
+ import dns
+ import pyaes
+ import ecdsa
+ import requests
+ import qrcode
+ import pbkdf2
+ import google.protobuf
+ import jsonrpclib
+ except ImportError as e:
+ sys.exit("Error: %s. Try 'sudo pip install '"%str(e))
+ # the following imports are for pyinstaller
+ from google.protobuf import descriptor
+ from google.protobuf import message
+ from google.protobuf import reflection
+ from google.protobuf import descriptor_pb2
+ from jsonrpclib import SimpleJSONRPCServer
+ # make sure that certificates are here
+ assert os.path.exists(requests.utils.DEFAULT_CA_BUNDLE_PATH)
+
+
+if not is_android:
+ check_imports()
+
+# load local module as electrum
+if is_local or is_android:
+ import imp
+ imp.load_module('electrum_xzc', *imp.find_module('lib'))
+ imp.load_module('electrum_xzc_gui', *imp.find_module('gui'))
+ imp.load_module('electrum_xzc_plugins', *imp.find_module('plugins'))
+
+
+
+from electrum_xzc import bitcoin, util
+from electrum_xzc import SimpleConfig, Network
+from electrum_xzc.wallet import Wallet, Imported_Wallet
+from electrum_xzc.storage import WalletStorage
+from electrum_xzc.util import print_msg, print_stderr, json_encode, json_decode
+from electrum_xzc.util import set_verbosity, InvalidPassword
+from electrum_xzc.commands import get_parser, known_commands, Commands, config_variables
+from electrum_xzc import daemon
+from electrum_xzc import keystore
+from electrum_xzc.mnemonic import Mnemonic
+import electrum_xzc_plugins
+
+# get password routine
+def prompt_password(prompt, confirm=True):
+ import getpass
+ password = getpass.getpass(prompt, stream=None)
+ if password and confirm:
+ password2 = getpass.getpass("Confirm: ")
+ if password != password2:
+ sys.exit("Error: Passwords do not match.")
+ if not password:
+ password = None
+ return password
+
+
+
+def run_non_RPC(config):
+ cmdname = config.get('cmd')
+
+ storage = WalletStorage(config.get_wallet_path())
+ if storage.file_exists():
+ sys.exit("Error: Remove the existing wallet first!")
+
+ def password_dialog():
+ return prompt_password("Password (hit return if you do not wish to encrypt your wallet):")
+
+ if cmdname == 'restore':
+ text = config.get('text').strip()
+ passphrase = config.get('passphrase', '')
+ password = password_dialog() if keystore.is_private(text) else None
+ if keystore.is_address_list(text):
+ wallet = Imported_Wallet(storage)
+ for x in text.split():
+ wallet.import_address(x)
+ elif keystore.is_private_key_list(text):
+ k = keystore.Imported_KeyStore({})
+ storage.put('keystore', k.dump())
+ storage.put('use_encryption', bool(password))
+ wallet = Imported_Wallet(storage)
+ for x in text.split():
+ wallet.import_private_key(x, password)
+ storage.write()
+ else:
+ if keystore.is_seed(text):
+ k = keystore.from_seed(text, passphrase, False)
+ elif keystore.is_master_key(text):
+ k = keystore.from_master_key(text)
+ else:
+ sys.exit("Error: Seed or key not recognized")
+ if password:
+ k.update_password(None, password)
+ storage.put('keystore', k.dump())
+ storage.put('wallet_type', 'standard')
+ storage.put('use_encryption', bool(password))
+ storage.write()
+ wallet = Wallet(storage)
+ if not config.get('offline'):
+ network = Network(config)
+ network.start()
+ wallet.start_threads(network)
+ print_msg("Recovering wallet...")
+ wallet.synchronize()
+ wallet.wait_until_synchronized()
+ msg = "Recovery successful" if wallet.is_found() else "Found no history for this wallet"
+ else:
+ msg = "This wallet was restored offline. It may contain more addresses than displayed."
+ print_msg(msg)
+
+ elif cmdname == 'create':
+ password = password_dialog()
+ passphrase = config.get('passphrase', '')
+ seed_type = 'segwit' if config.get('segwit') else 'standard'
+ seed = Mnemonic('en').make_seed(seed_type)
+ k = keystore.from_seed(seed, passphrase, False)
+ storage.put('keystore', k.dump())
+ storage.put('wallet_type', 'standard')
+ wallet = Wallet(storage)
+ wallet.update_password(None, password, True)
+ wallet.synchronize()
+ print_msg("Your wallet generation seed is:\n\"%s\"" % seed)
+ print_msg("Please keep it in a safe place; if you lose it, you will not be able to restore your wallet.")
+
+ wallet.storage.write()
+ print_msg("Wallet saved in '%s'" % wallet.storage.path)
+ sys.exit(0)
+
+
+def init_daemon(config_options):
+ config = SimpleConfig(config_options)
+ storage = WalletStorage(config.get_wallet_path())
+ if not storage.file_exists():
+ print_msg("Error: Wallet file not found.")
+ print_msg("Type 'electrum-xzc create' to create a new wallet, or provide a path to a wallet with the -w option")
+ sys.exit(0)
+ if storage.is_encrypted():
+ if config.get('password'):
+ password = config.get('password')
+ else:
+ password = prompt_password('Password:', False)
+ if not password:
+ print_msg("Error: Password required")
+ sys.exit(1)
+ else:
+ password = None
+ config_options['password'] = password
+
+
+def init_cmdline(config_options, server):
+ config = SimpleConfig(config_options)
+ cmdname = config.get('cmd')
+ cmd = known_commands[cmdname]
+
+ if cmdname == 'signtransaction' and config.get('privkey'):
+ cmd.requires_wallet = False
+ cmd.requires_password = False
+
+ if cmdname in ['payto', 'paytomany'] and config.get('unsigned'):
+ cmd.requires_password = False
+
+ if cmdname in ['payto', 'paytomany'] and config.get('broadcast'):
+ cmd.requires_network = True
+
+ # instanciate wallet for command-line
+ storage = WalletStorage(config.get_wallet_path())
+
+ if cmd.requires_wallet and not storage.file_exists():
+ print_msg("Error: Wallet file not found.")
+ print_msg("Type 'electrum-xzc create' to create a new wallet, or provide a path to a wallet with the -w option")
+ sys.exit(0)
+
+ # important warning
+ if cmd.name in ['getprivatekeys']:
+ print_stderr("WARNING: ALL your private keys are secret.")
+ print_stderr("Exposing a single private key can compromise your entire wallet!")
+ print_stderr("In particular, DO NOT use 'redeem private key' services proposed by third parties.")
+
+ # commands needing password
+ if (cmd.requires_wallet and storage.is_encrypted() and server is None)\
+ or (cmd.requires_password and (storage.get('use_encryption') or storage.is_encrypted())):
+ if config.get('password'):
+ password = config.get('password')
+ else:
+ password = prompt_password('Password:', False)
+ if not password:
+ print_msg("Error: Password required")
+ sys.exit(1)
+ else:
+ password = None
+
+ config_options['password'] = password
+
+ if cmd.name == 'password':
+ new_password = prompt_password('New password:')
+ config_options['new_password'] = new_password
+
+ return cmd, password
+
+
+def run_offline_command(config, config_options):
+ cmdname = config.get('cmd')
+ cmd = known_commands[cmdname]
+ password = config_options.get('password')
+ if cmd.requires_wallet:
+ storage = WalletStorage(config.get_wallet_path())
+ if storage.is_encrypted():
+ storage.decrypt(password)
+ wallet = Wallet(storage)
+ else:
+ wallet = None
+ # check password
+ if cmd.requires_password and storage.get('use_encryption'):
+ try:
+ seed = wallet.check_password(password)
+ except InvalidPassword:
+ print_msg("Error: This password does not decode this wallet.")
+ sys.exit(1)
+ if cmd.requires_network:
+ print_msg("Warning: running command offline")
+ # arguments passed to function
+ args = [config.get(x) for x in cmd.params]
+ # decode json arguments
+ if cmdname not in ('setconfig',):
+ args = list(map(json_decode, args))
+ # options
+ kwargs = {}
+ for x in cmd.options:
+ kwargs[x] = (config_options.get(x) if x in ['password', 'new_password'] else config.get(x))
+ cmd_runner = Commands(config, wallet, None)
+ func = getattr(cmd_runner, cmd.name)
+ result = func(*args, **kwargs)
+ # save wallet
+ if wallet:
+ wallet.storage.write()
+ return result
+
+def init_plugins(config, gui_name):
+ from electrum_xzc.plugins import Plugins
+ return Plugins(config, is_local or is_android, gui_name)
+
+
+if __name__ == '__main__':
+ # The hook will only be used in the Qt GUI right now
+ util.setup_thread_excepthook()
+ # on osx, delete Process Serial Number arg generated for apps launched in Finder
+ sys.argv = list(filter(lambda x: not x.startswith('-psn'), sys.argv))
+
+ # old 'help' syntax
+ if len(sys.argv) > 1 and sys.argv[1] == 'help':
+ sys.argv.remove('help')
+ sys.argv.append('-h')
+
+ # read arguments from stdin pipe and prompt
+ for i, arg in enumerate(sys.argv):
+ if arg == '-':
+ if not sys.stdin.isatty():
+ sys.argv[i] = sys.stdin.read()
+ break
+ else:
+ raise BaseException('Cannot get argument from stdin')
+ elif arg == '?':
+ sys.argv[i] = input("Enter argument:")
+ elif arg == ':':
+ sys.argv[i] = prompt_password('Enter argument (will not echo):', False)
+
+ # parse command line
+ parser = get_parser()
+ args = parser.parse_args()
+
+ # config is an object passed to the various constructors (wallet, interface, gui)
+ if is_android:
+ config_options = {
+ 'verbose': True,
+ 'cmd': 'gui',
+ 'gui': 'kivy',
+ }
+ else:
+ config_options = args.__dict__
+ f = lambda key: config_options[key] is not None and key not in config_variables.get(args.cmd, {}).keys()
+ config_options = {key: config_options[key] for key in filter(f, config_options.keys())}
+ if config_options.get('server'):
+ config_options['auto_connect'] = False
+
+ config_options['cwd'] = os.getcwd()
+
+ # fixme: this can probably be achieved with a runtime hook (pyinstaller)
+ if is_bundle and os.path.exists(os.path.join(sys._MEIPASS, 'is_portable')):
+ config_options['portable'] = True
+
+ if config_options.get('portable'):
+ config_options['electrum_path'] = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'electrum-xzc_data')
+
+ # kivy sometimes freezes when we write to sys.stderr
+ set_verbosity(config_options.get('verbose') and config_options.get('gui')!='kivy')
+
+ # check uri
+ uri = config_options.get('url')
+ if uri:
+ if not uri.startswith('zcoin:'):
+ print_stderr('unknown command:', uri)
+ sys.exit(1)
+ config_options['url'] = uri
+
+ # todo: defer this to gui
+ config = SimpleConfig(config_options)
+ cmdname = config.get('cmd')
+
+ if config.get('testnet'):
+ bitcoin.NetworkConstants.set_testnet()
+
+ # run non-RPC commands separately
+ if cmdname in ['create', 'restore']:
+ run_non_RPC(config)
+ sys.exit(0)
+
+ if cmdname == 'gui':
+ fd, server = daemon.get_fd_or_server(config)
+ if fd is not None:
+ plugins = init_plugins(config, config.get('gui', 'qt'))
+ d = daemon.Daemon(config, fd, True)
+ d.start()
+ d.init_gui(config, plugins)
+ sys.exit(0)
+ else:
+ result = server.gui(config_options)
+
+ elif cmdname == 'daemon':
+ subcommand = config.get('subcommand')
+ if subcommand in ['load_wallet']:
+ init_daemon(config_options)
+
+ if subcommand in [None, 'start']:
+ fd, server = daemon.get_fd_or_server(config)
+ if fd is not None:
+ if subcommand == 'start':
+ pid = os.fork()
+ if pid:
+ print_stderr("starting daemon (PID %d)" % pid)
+ sys.exit(0)
+ init_plugins(config, 'cmdline')
+ d = daemon.Daemon(config, fd, False)
+ d.start()
+ if config.get('websocket_server'):
+ from electrum_xzc import websockets
+ websockets.WebSocketServer(config, d.network).start()
+ if config.get('requests_dir'):
+ path = os.path.join(config.get('requests_dir'), 'index.html')
+ if not os.path.exists(path):
+ print("Requests directory not configured.")
+ print("You can configure it using https://github.com/sn-ntu/electrum-xzc-merchant")
+ sys.exit(1)
+ d.join()
+ sys.exit(0)
+ else:
+ result = server.daemon(config_options)
+ else:
+ server = daemon.get_server(config)
+ if server is not None:
+ result = server.daemon(config_options)
+ else:
+ print_msg("Daemon not running")
+ sys.exit(1)
+ else:
+ # command line
+ server = daemon.get_server(config)
+ init_cmdline(config_options, server)
+ if server is not None:
+ result = server.run_cmdline(config_options)
+ else:
+ cmd = known_commands[cmdname]
+ if cmd.requires_network:
+ print_msg("Daemon not running; try 'electrum-xzc daemon start'")
+ sys.exit(1)
+ else:
+ init_plugins(config, 'cmdline')
+ result = run_offline_command(config, config_options)
+ # print result
+ if isinstance(result, str):
+ print_msg(result)
+ elif type(result) is dict and result.get('error'):
+ print_stderr(result.get('error'))
+ elif result is not None:
+ print_msg(json_encode(result))
+ sys.exit(0)
diff --git a/electrum-xzc.conf.sample b/electrum-xzc.conf.sample
new file mode 100644
index 000000000000..f2afaf5daf3e
--- /dev/null
+++ b/electrum-xzc.conf.sample
@@ -0,0 +1,16 @@
+# Configuration file for the electrum client
+# Settings defined here are shared across wallets
+#
+# copy this file to /etc/electrum-xzc.conf if you want read-only settings
+
+[client]
+server = 45.63.92.224:50001:t
+proxy = None
+gap_limit = 5
+# booleans use python syntax
+use_change = True
+gui = qt
+num_zeros = 2
+# default transaction fee is in Satoshis
+fee = 100000
+winpos-qt = [799, 226, 877, 435]
diff --git a/electrum-xzc.desktop b/electrum-xzc.desktop
new file mode 100644
index 000000000000..1706961438ef
--- /dev/null
+++ b/electrum-xzc.desktop
@@ -0,0 +1,17 @@
+# If you want electrum to appear in a linux app launcher ("start menu"), install this by doing:
+# sudo desktop-file-install electrum.desktop
+
+[Desktop Entry]
+Comment=Lightweight Zcoin Client
+Exec=electrum-xzc %u
+GenericName[en_US]=Zcoin Wallet
+GenericName=Zcoin Wallet
+Icon=electrum-xzc
+Name[en_US]=Electrum Zcoin Wallet
+Name=Electrum Zcoin Wallet
+Categories=Finance;Network;
+StartupNotify=false
+Terminal=false
+Type=Application
+MimeType=x-scheme-handler/zcoin;
+
diff --git a/electrum.icns b/electrum.icns
index 977b124d0d26..57efaa563ed3 100644
Binary files a/electrum.icns and b/electrum.icns differ
diff --git a/exlib/lyra2z-py/Lyra2.c b/exlib/lyra2z-py/Lyra2.c
new file mode 100644
index 000000000000..a1a07b2f5b43
--- /dev/null
+++ b/exlib/lyra2z-py/Lyra2.c
@@ -0,0 +1,197 @@
+/**
+ * Implementation of the Lyra2 Password Hashing Scheme (PHS).
+ *
+ * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014.
+ *
+ * This software is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include
+#ifndef _MSC_VER
+# include
+#endif
+#include
+#include "Lyra2.h"
+#include "Sponge.h"
+
+/**
+ * Executes Lyra2 based on the G function from Blake2b. This version supports salts and passwords
+ * whose combined length is smaller than the size of the memory matrix, (i.e., (nRows x nCols x b) bits,
+ * where "b" is the underlying sponge's bitrate). In this implementation, the "basil" is composed by all
+ * integer parameters (treated as type "unsigned int") in the order they are provided, plus the value
+ * of nCols, (i.e., basil = kLen || pwdlen || saltlen || timeCost || nRows || nCols).
+ *
+ * @param K The derived key to be output by the algorithm
+ * @param kLen Desired key length
+ * @param pwd User password
+ * @param pwdlen Password length
+ * @param salt Salt
+ * @param saltlen Salt length
+ * @param timeCost Parameter to determine the processing time (T)
+ * @param nRows Number or rows of the memory matrix (R)
+ * @param nCols Number of columns of the memory matrix (C)
+ *
+ * @return 0 if the key is generated correctly; -1 if there is an error (usually due to lack of memory for allocation)
+ */
+int LYRA2(uint64_t* wholeMatrix, void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols) {
+
+ //============================= Basic variables ============================//
+ int64_t row = 2; //index of row to be processed
+ int64_t prev = 1; //index of prev (last row ever computed/modified)
+ int64_t rowa = 0; //index of row* (a previous row, deterministically picked during Setup and randomly picked while Wandering)
+ int64_t tau; //Time Loop iterator
+ int64_t step = 1; //Visitation step (used during Setup and Wandering phases)
+ int64_t window = 2; //Visitation window (used to define which rows can be revisited during Setup)
+ int64_t gap = 1; //Modifier to the step, assuming the values 1 or -1
+ //==========================================================================/
+
+ //========== Initializing the Memory Matrix and pointers to it =============//
+ //Tries to allocate enough space for the whole memory matrix
+
+
+ const int64_t ROW_LEN_INT64 = BLOCK_LEN_INT64 * nCols;
+ const int64_t ROW_LEN_BYTES = ROW_LEN_INT64 * 8;
+
+ if (wholeMatrix == NULL) {
+ return -1;
+ }
+
+ //==========================================================================/
+
+ //============= Getting the password + salt + basil padded with 10*1 ===============//
+ //OBS.:The memory matrix will temporarily hold the password: not for saving memory,
+ //but this ensures that the password copied locally will be overwritten as soon as possible
+
+ //First, we clean enough blocks for the password, salt, basil and padding
+ uint64_t nBlocksInput = ((saltlen + pwdlen + 6 * sizeof (uint64_t)) / BLOCK_LEN_BLAKE2_SAFE_BYTES) + 1;
+ byte *ptrByte = (byte*) wholeMatrix;
+ memset(ptrByte, 0, nBlocksInput * BLOCK_LEN_BLAKE2_SAFE_BYTES);
+
+ //Prepends the password
+ memcpy(ptrByte, pwd, pwdlen);
+ ptrByte += pwdlen;
+
+ //Concatenates the salt
+ memcpy(ptrByte, salt, saltlen);
+ ptrByte += saltlen;
+
+ //Concatenates the basil: every integer passed as parameter, in the order they are provided by the interface
+ memcpy(ptrByte, &kLen, sizeof (uint64_t));
+ ptrByte += sizeof (uint64_t);
+ memcpy(ptrByte, &pwdlen, sizeof (uint64_t));
+ ptrByte += sizeof (uint64_t);
+ memcpy(ptrByte, &saltlen, sizeof (uint64_t));
+ ptrByte += sizeof (uint64_t);
+ memcpy(ptrByte, &timeCost, sizeof (uint64_t));
+ ptrByte += sizeof (uint64_t);
+ memcpy(ptrByte, &nRows, sizeof (uint64_t));
+ ptrByte += sizeof (uint64_t);
+ memcpy(ptrByte, &nCols, sizeof (uint64_t));
+ ptrByte += sizeof (uint64_t);
+
+ //Now comes the padding
+ *ptrByte = 0x80; //first byte of padding: right after the password
+ ptrByte = (byte*) wholeMatrix; //resets the pointer to the start of the memory matrix
+ ptrByte += nBlocksInput * BLOCK_LEN_BLAKE2_SAFE_BYTES - 1; //sets the pointer to the correct position: end of incomplete block
+ *ptrByte ^= 0x01; //last byte of padding: at the end of the last incomplete block
+ //==========================================================================/
+
+ //======================= Initializing the Sponge State ====================//
+ //Sponge state: 16 uint64_t, BLOCK_LEN_INT64 words of them for the bitrate (b) and the remainder for the capacity (c)
+ uint64_t *state = _mm_malloc(16 * sizeof (uint64_t), 32);
+ if (state == NULL) {
+ return -1;
+ }
+ initState(state);
+ //==========================================================================/
+
+ //================================ Setup Phase =============================//
+ //Absorbing salt, password and basil: this is the only place in which the block length is hard-coded to 512 bits
+ uint64_t *ptrWord = wholeMatrix;
+ for (int i = 0; i < nBlocksInput; i++) {
+ absorbBlockBlake2Safe(state, ptrWord); //absorbs each block of pad(pwd || salt || basil)
+ ptrWord += BLOCK_LEN_BLAKE2_SAFE_INT64; //goes to next block of pad(pwd || salt || basil)
+ }
+
+ //Initializes M[0] and M[1]
+ reducedSqueezeRow0(state, &wholeMatrix[0], nCols); //The locally copied password is most likely overwritten here
+ reducedDuplexRow1(state, &wholeMatrix[0], &wholeMatrix[ROW_LEN_INT64], nCols);
+
+ do {
+ //M[row] = rand; //M[row*] = M[row*] XOR rotW(rand)
+ reducedDuplexRowSetup(state, &wholeMatrix[prev*ROW_LEN_INT64], &wholeMatrix[rowa*ROW_LEN_INT64], &wholeMatrix[row*ROW_LEN_INT64], nCols);
+
+ //updates the value of row* (deterministically picked during Setup))
+ rowa = (rowa + step) & (window - 1);
+ //update prev: it now points to the last row ever computed
+ prev = row;
+ //updates row: goes to the next row to be computed
+ row++;
+
+ //Checks if all rows in the window where visited.
+ if (rowa == 0) {
+ step = window + gap; //changes the step: approximately doubles its value
+ window *= 2; //doubles the size of the re-visitation window
+ gap = -gap; //inverts the modifier to the step
+ }
+
+ } while (row < nRows);
+ //==========================================================================/
+
+ //============================ Wandering Phase =============================//
+ row = 0; //Resets the visitation to the first row of the memory matrix
+ for (tau = 1; tau <= timeCost; tau++) {
+ //Step is approximately half the number of all rows of the memory matrix for an odd tau; otherwise, it is -1
+ step = (tau % 2 == 0) ? -1 : nRows / 2 - 1;
+ do {
+ //Selects a pseudorandom index row*
+ //------------------------------------------------------------------------------------------
+ //rowa = ((unsigned int)state[0]) & (nRows-1); //(USE THIS IF nRows IS A POWER OF 2)
+ rowa = ((uint64_t) (state[0])) % nRows; //(USE THIS FOR THE "GENERIC" CASE)
+ //------------------------------------------------------------------------------------------
+
+ //Performs a reduced-round duplexing operation over M[row*] XOR M[prev], updating both M[row*] and M[row]
+ reducedDuplexRow(state, &wholeMatrix[prev*ROW_LEN_INT64], &wholeMatrix[rowa*ROW_LEN_INT64], &wholeMatrix[row*ROW_LEN_INT64], nCols);
+
+ //update prev: it now points to the last row ever computed
+ prev = row;
+
+ //updates row: goes to the next row to be computed
+ //------------------------------------------------------------------------------------------
+ //row = (row + step) & (nRows-1); //(USE THIS IF nRows IS A POWER OF 2)
+ row = (row + step) % nRows; //(USE THIS FOR THE "GENERIC" CASE)
+ //------------------------------------------------------------------------------------------
+
+ } while (row != 0);
+ }
+ //==========================================================================/
+
+ //============================ Wrap-up Phase ===============================//
+ //Absorbs the last block of the memory matrix
+ absorbBlock(state, &wholeMatrix[rowa*ROW_LEN_INT64]);
+
+ //Squeezes the key
+ squeeze(state, K, kLen);
+ //==========================================================================/
+
+ //========================= Freeing the memory =============================//
+ _mm_free(state);
+ //==========================================================================/
+
+ return 0;
+}
+
diff --git a/exlib/lyra2z-py/Lyra2.h b/exlib/lyra2z-py/Lyra2.h
new file mode 100644
index 000000000000..0e53680ca2e1
--- /dev/null
+++ b/exlib/lyra2z-py/Lyra2.h
@@ -0,0 +1,51 @@
+/**
+ * Header file for the Lyra2 Password Hashing Scheme (PHS).
+ *
+ * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014.
+ *
+ * This software is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef LYRA2_H_
+#define LYRA2_H_
+
+#include
+
+typedef unsigned char byte;
+
+//Block length required so Blake2's Initialization Vector (IV) is not overwritten (THIS SHOULD NOT BE MODIFIED)
+#define BLOCK_LEN_BLAKE2_SAFE_INT64 8 //512 bits (=64 bytes, =8 uint64_t)
+#define BLOCK_LEN_BLAKE2_SAFE_BYTES (BLOCK_LEN_BLAKE2_SAFE_INT64 * 8) //same as above, in bytes
+
+
+#ifdef BLOCK_LEN_BITS
+ #define BLOCK_LEN_INT64 (BLOCK_LEN_BITS/64) //Block length: 768 bits (=96 bytes, =12 uint64_t)
+ #define BLOCK_LEN_BYTES (BLOCK_LEN_BITS/8) //Block length, in bytes
+#else //default block lenght: 768 bits
+ #define BLOCK_LEN_INT64 12 //Block length: 768 bits (=96 bytes, =12 uint64_t)
+ #define BLOCK_LEN_BYTES (BLOCK_LEN_INT64 * 8) //Block length, in bytes
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ int LYRA2(uint64_t* matrix, void *K, uint64_t kLen, const void *pwd, uint64_t pwdlen, const void *salt, uint64_t saltlen, uint64_t timeCost, uint64_t nRows, uint64_t nCols);
+
+#ifdef __cplusplus
+}
+
+#endif
+
+#endif /* LYRA2_H_ */
diff --git a/exlib/lyra2z-py/README.md b/exlib/lyra2z-py/README.md
new file mode 100644
index 000000000000..08acbf44cff6
--- /dev/null
+++ b/exlib/lyra2z-py/README.md
@@ -0,0 +1,55 @@
+
+----------------------------------
+Python C module for lyra2z hashing
+----------------------------------
+
+Notes for Zcoin:
+----------------
+
+Module: lyra2z_hash
+
+Please see the "test.py" for a testcase
+
+From a previous readme from ocminer (updated):
+
+Requirements:
+-------------
+In order to run P2Pool and other Python based pools with the Zcoin network, you would need to build and install the
+lyra2z_hash module for Python that includes the lyra2z proof of work code that Zcoin uses for hashes.
+
+Linux:
+
+ sudo python setup.py install
+
+
+Windows (mingw):
+* Install MinGW: http://www.mingw.org/wiki/Getting_Started
+* Install Python 2.7: http://www.python.org/getit/
+
+In cmd type this:
+
+ C:\Python27\python.exe setup.py build --compile=mingw32 install
+
+ - untested
+
+
+Windows (microsoft visual c++)
+* Open visual studio console
+
+In cmd type this:
+
+ SET VS90COMNTOOLS=%VS140COMNTOOLS% # For visual c++ 2015
+ C:\Python27\python.exe setup.py install
+
+ Test the install:
+
+ C:\Python27\python.exe
+ ...
+ >>>import lyra2z_hash
+ >>>help('lyra2z_hash')
+ >>>quit()
+
+ - tested ok
+
+
+
diff --git a/exlib/lyra2z-py/Sponge.c b/exlib/lyra2z-py/Sponge.c
new file mode 100644
index 000000000000..c82f2ae54313
--- /dev/null
+++ b/exlib/lyra2z-py/Sponge.c
@@ -0,0 +1,832 @@
+/**
+ * A simple implementation of Blake2b's internal permutation
+ * in the form of a sponge.
+ *
+ * Author: The Lyra PHC team (http://www.lyra-kdf.net/) -- 2014.
+ *
+ * This software is hereby placed in the public domain.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#include
+#include
+#include
+#include "Sponge.h"
+#include "Lyra2.h"
+
+#include
+
+/**
+ * Initializes the Sponge State. The first 512 bits are set to zeros and the remainder
+ * receive Blake2b's IV as per Blake2b's specification. Note: Even though sponges
+ * typically have their internal state initialized with zeros, Blake2b's G function
+ * has a fixed point: if the internal state and message are both filled with zeros. the
+ * resulting permutation will always be a block filled with zeros; this happens because
+ * Blake2b does not use the constants originally employed in Blake2 inside its G function,
+ * relying on the IV for avoiding possible fixed points.
+ *
+ * @param state The 1024-bit array to be initialized
+ */
+inline void initState(uint64_t state[/*16*/]) {
+ //First 512 bis are zeros
+ memset(state, 0, 64);
+ //Remainder BLOCK_LEN_BLAKE2_SAFE_BYTES are reserved to the IV
+ state[8] = blake2b_IV[0];
+ state[9] = blake2b_IV[1];
+ state[10] = blake2b_IV[2];
+ state[11] = blake2b_IV[3];
+ state[12] = blake2b_IV[4];
+ state[13] = blake2b_IV[5];
+ state[14] = blake2b_IV[6];
+ state[15] = blake2b_IV[7];
+}
+
+/**
+ * Execute Blake2b's G function, with all 12 rounds.
+ *
+ * @param v A 1024-bit (16 uint64_t) array to be processed by Blake2b's G function
+ */
+inline static void blake2bLyra(uint64_t *v) {
+ ROUND_LYRA(0);
+ ROUND_LYRA(1);
+ ROUND_LYRA(2);
+ ROUND_LYRA(3);
+ ROUND_LYRA(4);
+ ROUND_LYRA(5);
+ ROUND_LYRA(6);
+ ROUND_LYRA(7);
+ ROUND_LYRA(8);
+ ROUND_LYRA(9);
+ ROUND_LYRA(10);
+ ROUND_LYRA(11);
+}
+
+/**
+ * Executes a reduced version of Blake2b's G function with only one round
+ * @param v A 1024-bit (16 uint64_t) array to be processed by Blake2b's G function
+ */
+inline static void reducedBlake2bLyra(uint64_t *v) {
+ ROUND_LYRA(0);
+}
+
+/**
+ * Performs a squeeze operation, using Blake2b's G function as the
+ * internal permutation
+ *
+ * @param state The current state of the sponge
+ * @param out Array that will receive the data squeezed
+ * @param len The number of bytes to be squeezed into the "out" array
+ */
+inline void squeeze(uint64_t *state, byte *out, unsigned int len) {
+ int fullBlocks = len / BLOCK_LEN_BYTES;
+ byte *ptr = out;
+ int i;
+ //Squeezes full blocks
+ for (i = 0; i < fullBlocks; i++) {
+ memcpy(ptr, state, BLOCK_LEN_BYTES);
+ blake2bLyra(state);
+ ptr += BLOCK_LEN_BYTES;
+ }
+
+ //Squeezes remaining bytes
+ memcpy(ptr, state, (len % BLOCK_LEN_BYTES));
+}
+
+/**
+ * Performs an absorb operation for a single block (BLOCK_LEN_INT64 words
+ * of type uint64_t), using Blake2b's G function as the internal permutation
+ *
+ * @param state The current state of the sponge
+ * @param in The block to be absorbed (BLOCK_LEN_INT64 words)
+ */
+inline void absorbBlock(uint64_t *state, const uint64_t *in) {
+ //XORs the first BLOCK_LEN_INT64 words of "in" with the current state
+ state[0] ^= in[0];
+ state[1] ^= in[1];
+ state[2] ^= in[2];
+ state[3] ^= in[3];
+ state[4] ^= in[4];
+ state[5] ^= in[5];
+ state[6] ^= in[6];
+ state[7] ^= in[7];
+ state[8] ^= in[8];
+ state[9] ^= in[9];
+ state[10] ^= in[10];
+ state[11] ^= in[11];
+
+ //Applies the transformation f to the sponge's state
+ blake2bLyra(state);
+}
+
+/**
+ * Performs an absorb operation for a single block (BLOCK_LEN_BLAKE2_SAFE_INT64
+ * words of type uint64_t), using Blake2b's G function as the internal permutation
+ *
+ * @param state The current state of the sponge
+ * @param in The block to be absorbed (BLOCK_LEN_BLAKE2_SAFE_INT64 words)
+ */
+inline void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in) {
+ //XORs the first BLOCK_LEN_BLAKE2_SAFE_INT64 words of "in" with the current state
+
+ state[0] ^= in[0];
+ state[1] ^= in[1];
+ state[2] ^= in[2];
+ state[3] ^= in[3];
+ state[4] ^= in[4];
+ state[5] ^= in[5];
+ state[6] ^= in[6];
+ state[7] ^= in[7];
+
+
+ //Applies the transformation f to the sponge's state
+ blake2bLyra(state);
+
+}
+
+/**
+ * Performs a reduced squeeze operation for a single row, from the highest to
+ * the lowest index, using the reduced-round Blake2b's G function as the
+ * internal permutation
+ *
+ * @param state The current state of the sponge
+ * @param rowOut Row to receive the data squeezed
+ */
+inline void reducedSqueezeRow0(uint64_t* state, uint64_t* rowOut, uint64_t nCols) {
+ uint64_t* ptrWord = rowOut + (nCols-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to M[0][C-1]
+ int i;
+ //M[row][C-1-col] = H.reduced_squeeze()
+ for (i = 0; i < nCols; i++) {
+ ptrWord[0] = state[0];
+ ptrWord[1] = state[1];
+ ptrWord[2] = state[2];
+ ptrWord[3] = state[3];
+ ptrWord[4] = state[4];
+ ptrWord[5] = state[5];
+ ptrWord[6] = state[6];
+ ptrWord[7] = state[7];
+ ptrWord[8] = state[8];
+ ptrWord[9] = state[9];
+ ptrWord[10] = state[10];
+ ptrWord[11] = state[11];
+
+ //Goes to next block (column) that will receive the squeezed data
+ ptrWord -= BLOCK_LEN_INT64;
+
+ //Applies the reduced-round transformation f to the sponge's state
+ reducedBlake2bLyra(state);
+ }
+}
+
+/**
+ * Performs a reduced duplex operation for a single row, from the highest to
+ * the lowest index, using the reduced-round Blake2b's G function as the
+ * internal permutation
+ *
+ * @param state The current state of the sponge
+ * @param rowIn Row to feed the sponge
+ * @param rowOut Row to receive the sponge's output
+ */
+inline void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut, uint64_t nCols) {
+ uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
+ uint64_t* ptrWordOut = rowOut + (nCols-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to row
+ int i;
+
+ for (i = 0; i < nCols; i++) {
+
+ //Absorbing "M[prev][col]"
+ state[0] ^= (ptrWordIn[0]);
+ state[1] ^= (ptrWordIn[1]);
+ state[2] ^= (ptrWordIn[2]);
+ state[3] ^= (ptrWordIn[3]);
+ state[4] ^= (ptrWordIn[4]);
+ state[5] ^= (ptrWordIn[5]);
+ state[6] ^= (ptrWordIn[6]);
+ state[7] ^= (ptrWordIn[7]);
+ state[8] ^= (ptrWordIn[8]);
+ state[9] ^= (ptrWordIn[9]);
+ state[10] ^= (ptrWordIn[10]);
+ state[11] ^= (ptrWordIn[11]);
+
+ //Applies the reduced-round transformation f to the sponge's state
+ reducedBlake2bLyra(state);
+
+ //M[row][C-1-col] = M[prev][col] XOR rand
+ ptrWordOut[0] = ptrWordIn[0] ^ state[0];
+ ptrWordOut[1] = ptrWordIn[1] ^ state[1];
+ ptrWordOut[2] = ptrWordIn[2] ^ state[2];
+ ptrWordOut[3] = ptrWordIn[3] ^ state[3];
+ ptrWordOut[4] = ptrWordIn[4] ^ state[4];
+ ptrWordOut[5] = ptrWordIn[5] ^ state[5];
+ ptrWordOut[6] = ptrWordIn[6] ^ state[6];
+ ptrWordOut[7] = ptrWordIn[7] ^ state[7];
+ ptrWordOut[8] = ptrWordIn[8] ^ state[8];
+ ptrWordOut[9] = ptrWordIn[9] ^ state[9];
+ ptrWordOut[10] = ptrWordIn[10] ^ state[10];
+ ptrWordOut[11] = ptrWordIn[11] ^ state[11];
+
+
+ //Input: next column (i.e., next block in sequence)
+ ptrWordIn += BLOCK_LEN_INT64;
+ //Output: goes to previous column
+ ptrWordOut -= BLOCK_LEN_INT64;
+ }
+}
+
+/**
+ * Performs a duplexing operation over "M[rowInOut][col] [+] M[rowIn][col]" (i.e.,
+ * the wordwise addition of two columns, ignoring carries between words). The
+ * output of this operation, "rand", is then used to make
+ * "M[rowOut][(N_COLS-1)-col] = M[rowIn][col] XOR rand" and
+ * "M[rowInOut][col] = M[rowInOut][col] XOR rotW(rand)", where rotW is a 64-bit
+ * rotation to the left and N_COLS is a system parameter.
+ *
+ * @param state The current state of the sponge
+ * @param rowIn Row used only as input
+ * @param rowInOut Row used as input and to receive output after rotation
+ * @param rowOut Row receiving the output
+ *
+ */
+inline void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, uint64_t nCols) {
+
+ uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
+ uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
+ uint64_t* ptrWordOut = rowOut + (nCols-1)*BLOCK_LEN_INT64; //In Lyra2: pointer to row
+
+#ifdef __AVX2__
+ __m256i* vstate = (__m256i*)state;
+ __m256i* vptrWordIn = (__m256i*)ptrWordIn; //In Lyra2: pointer to prev
+ __m256i* vptrWordInOut = (__m256i*)ptrWordInOut; //In Lyra2: pointer to row*
+ __m256i* vptrWordOut = (__m256i*)ptrWordOut; //In Lyra2: pointer to row
+
+ for (int i = 0; i < nCols; i++) {
+ //Absorbing "M[prev] [+] M[row*]"
+ vstate[0] = _mm256_xor_si256(vstate[0], _mm256_add_epi64(vptrWordIn[0], vptrWordInOut[0]));
+ vstate[1] = _mm256_xor_si256(vstate[1], _mm256_add_epi64(vptrWordIn[1], vptrWordInOut[1]));
+ vstate[2] = _mm256_xor_si256(vstate[2], _mm256_add_epi64(vptrWordIn[2], vptrWordInOut[2]));
+
+ //Applies the reduced-round transformation f to the sponge's state
+ reducedBlake2bLyra(state);
+
+ //M[row][col] = M[prev][col] XOR rand
+ vptrWordOut[0] = _mm256_xor_si256(vptrWordIn[0], vstate[0]);
+ vptrWordOut[1] = _mm256_xor_si256(vptrWordIn[1], vstate[1]);
+ vptrWordOut[2] = _mm256_xor_si256(vptrWordIn[2], vstate[2]);
+
+ //M[row*][col] = M[row*][col] XOR rotW(rand)
+ __m256i x1 = _mm256_permute4x64_epi64(vstate[0], 0x93);
+ __m256i x2 = _mm256_permute4x64_epi64(vstate[1], 0x93);
+ __m256i x3 = _mm256_permute4x64_epi64(vstate[2], 0x93);
+ vptrWordInOut[0] = _mm256_xor_si256(vptrWordInOut[0], _mm256_blend_epi32(x1, x3, 0x03));
+ vptrWordInOut[1] = _mm256_xor_si256(vptrWordInOut[1], _mm256_blend_epi32(x2, x1, 0x03));
+ vptrWordInOut[2] = _mm256_xor_si256(vptrWordInOut[2], _mm256_blend_epi32(x3, x2, 0x03));
+
+ //Inputs: next column (i.e., next block in sequence)
+ vptrWordInOut += (BLOCK_LEN_INT64 / 4);
+ vptrWordIn += (BLOCK_LEN_INT64 / 4);
+ //Output: goes to previous column
+ vptrWordOut -= (BLOCK_LEN_INT64 / 4);
+ }
+#else
+ for (int i = 0; i < nCols; i++) {
+ //Absorbing "M[prev] [+] M[row*]"
+ state[0] ^= (ptrWordIn[0] + ptrWordInOut[0]);
+ state[1] ^= (ptrWordIn[1] + ptrWordInOut[1]);
+ state[2] ^= (ptrWordIn[2] + ptrWordInOut[2]);
+ state[3] ^= (ptrWordIn[3] + ptrWordInOut[3]);
+ state[4] ^= (ptrWordIn[4] + ptrWordInOut[4]);
+ state[5] ^= (ptrWordIn[5] + ptrWordInOut[5]);
+ state[6] ^= (ptrWordIn[6] + ptrWordInOut[6]);
+ state[7] ^= (ptrWordIn[7] + ptrWordInOut[7]);
+ state[8] ^= (ptrWordIn[8] + ptrWordInOut[8]);
+ state[9] ^= (ptrWordIn[9] + ptrWordInOut[9]);
+ state[10] ^= (ptrWordIn[10] + ptrWordInOut[10]);
+ state[11] ^= (ptrWordIn[11] + ptrWordInOut[11]);
+
+ //Applies the reduced-round transformation f to the sponge's state
+ reducedBlake2bLyra(state);
+
+ //M[row][col] = M[prev][col] XOR rand
+ ptrWordOut[0] = ptrWordIn[0] ^ state[0];
+ ptrWordOut[1] = ptrWordIn[1] ^ state[1];
+ ptrWordOut[2] = ptrWordIn[2] ^ state[2];
+ ptrWordOut[3] = ptrWordIn[3] ^ state[3];
+ ptrWordOut[4] = ptrWordIn[4] ^ state[4];
+ ptrWordOut[5] = ptrWordIn[5] ^ state[5];
+ ptrWordOut[6] = ptrWordIn[6] ^ state[6];
+ ptrWordOut[7] = ptrWordIn[7] ^ state[7];
+ ptrWordOut[8] = ptrWordIn[8] ^ state[8];
+ ptrWordOut[9] = ptrWordIn[9] ^ state[9];
+ ptrWordOut[10] = ptrWordIn[10] ^ state[10];
+ ptrWordOut[11] = ptrWordIn[11] ^ state[11];
+
+ //M[row*][col] = M[row*][col] XOR rotW(rand)
+ ptrWordInOut[0] ^= state[11];
+ ptrWordInOut[1] ^= state[0];
+ ptrWordInOut[2] ^= state[1];
+ ptrWordInOut[3] ^= state[2];
+ ptrWordInOut[4] ^= state[3];
+ ptrWordInOut[5] ^= state[4];
+ ptrWordInOut[6] ^= state[5];
+ ptrWordInOut[7] ^= state[6];
+ ptrWordInOut[8] ^= state[7];
+ ptrWordInOut[9] ^= state[8];
+ ptrWordInOut[10] ^= state[9];
+ ptrWordInOut[11] ^= state[10];
+
+ //Inputs: next column (i.e., next block in sequence)
+ ptrWordInOut += BLOCK_LEN_INT64;
+ ptrWordIn += BLOCK_LEN_INT64;
+ //Output: goes to previous column
+ ptrWordOut -= BLOCK_LEN_INT64;
+ }
+#endif
+}
+
+/**
+ * Performs a duplexing operation over "M[rowInOut][col] [+] M[rowIn][col]" (i.e.,
+ * the wordwise addition of two columns, ignoring carries between words). The
+ * output of this operation, "rand", is then used to make
+ * "M[rowOut][col] = M[rowOut][col] XOR rand" and
+ * "M[rowInOut][col] = M[rowInOut][col] XOR rotW(rand)", where rotW is a 64-bit
+ * rotation to the left.
+ *
+ * @param state The current state of the sponge
+ * @param rowIn Row used only as input
+ * @param rowInOut Row used as input and to receive output after rotation
+ * @param rowOut Row receiving the output
+ *
+ */
+inline void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, uint64_t nCols) {
+ uint64_t* ptrWordInOut = rowInOut; //In Lyra2: pointer to row*
+ uint64_t* ptrWordIn = rowIn; //In Lyra2: pointer to prev
+ uint64_t* ptrWordOut = rowOut; //In Lyra2: pointer to row
+
+#ifdef __AVX2__
+ __m256i* vstate = (__m256i*)state;
+ __m256i* vptrWordIn = (__m256i*)ptrWordIn; //In Lyra2: pointer to prev
+ __m256i* vptrWordInOut = (__m256i*)ptrWordInOut; //In Lyra2: pointer to row*
+ __m256i* vptrWordOut = (__m256i*)ptrWordOut; //In Lyra2: pointer to row
+
+ int prefetch_distance = 3*3;
+#ifdef ROW_PREFETCH
+ for(int i=0; i
+
+#if defined(__GNUC__)
+#define ALIGN __attribute__ ((aligned(32)))
+#elif defined(_MSC_VER)
+#define ALIGN __declspec(align(32))
+#else
+#define ALIGN
+#endif
+
+
+/*Blake2b IV Array*/
+static const uint64_t blake2b_IV[8] =
+{
+ 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
+ 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
+ 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
+ 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
+};
+
+/*Blake2b's rotation*/
+static inline uint64_t rotr64( const uint64_t w, const unsigned c ){
+ return ( w >> c ) | ( w << ( 64 - c ) );
+}
+
+/*Blake2b's G function*/
+#define G(r,i,a,b,c,d) \
+ do { \
+ a = a + b; \
+ d = rotr64(d ^ a, 32); \
+ c = c + d; \
+ b = rotr64(b ^ c, 24); \
+ a = a + b; \
+ d = rotr64(d ^ a, 16); \
+ c = c + d; \
+ b = rotr64(b ^ c, 63); \
+ } while(0)
+
+
+/*One Round of the Blake2b's compression function*/
+#define ROUND_LYRA(r) \
+ G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
+ G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
+ G(r,2,v[ 2],v[ 6],v[10],v[14]); \
+ G(r,3,v[ 3],v[ 7],v[11],v[15]); \
+ G(r,4,v[ 0],v[ 5],v[10],v[15]); \
+ G(r,5,v[ 1],v[ 6],v[11],v[12]); \
+ G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
+ G(r,7,v[ 3],v[ 4],v[ 9],v[14]);
+
+//---- Housekeeping
+extern void initState(uint64_t state[/*16*/]);
+
+//---- Squeezes
+extern void squeeze(uint64_t *state, unsigned char *out, unsigned int len);
+extern void reducedSqueezeRow0(uint64_t* state, uint64_t* row, uint64_t nCols);
+
+//---- Absorbs
+extern void absorbBlock(uint64_t *state, const uint64_t *in);
+extern void absorbBlockBlake2Safe(uint64_t *state, const uint64_t *in);
+
+//---- Duplexes
+extern void reducedDuplexRow1(uint64_t *state, uint64_t *rowIn, uint64_t *rowOut, uint64_t nCols);
+extern void reducedDuplexRowSetup(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, uint64_t nCols);
+extern void reducedDuplexRow(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut, uint64_t nCols);
+
+//---- Misc
+void printArray(unsigned char *array, unsigned int size, char *name);
+
+////////////////////////////////////////////////////////////////////////////////////////////////
+
+
+////TESTS////
+//void reducedDuplexRowc(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
+//void reducedDuplexRowd(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
+//void reducedDuplexRowSetupv4(uint64_t *state, uint64_t *rowIn1, uint64_t *rowIn2, uint64_t *rowOut1, uint64_t *rowOut2);
+//void reducedDuplexRowSetupv5(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
+//void reducedDuplexRowSetupv5c(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
+//void reducedDuplexRowSetupv5d(uint64_t *state, uint64_t *rowIn, uint64_t *rowInOut, uint64_t *rowOut);
+/////////////
+
+
+#endif /* SPONGE_H_ */
diff --git a/exlib/lyra2z-py/blake.c b/exlib/lyra2z-py/blake.c
new file mode 100644
index 000000000000..28b32a71495a
--- /dev/null
+++ b/exlib/lyra2z-py/blake.c
@@ -0,0 +1,1121 @@
+/* $Id: blake.c 252 2011-06-07 17:55:14Z tp $ */
+/*
+ * BLAKE implementation.
+ *
+ * ==========================(LICENSE BEGIN)============================
+ *
+ * Copyright (c) 2007-2010 Projet RNRT SAPHIR
+ *
+ * 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.
+ *
+ * ===========================(LICENSE END)=============================
+ *
+ * @author Thomas Pornin
+ */
+
+#include
+#include
+#include
+#include
+
+#include "sph_blake.h"
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#if SPH_SMALL_FOOTPRINT && !defined SPH_SMALL_FOOTPRINT_BLAKE
+#define SPH_SMALL_FOOTPRINT_BLAKE 1
+#endif
+
+#if SPH_SMALL_FOOTPRINT_BLAKE
+#define SPH_COMPACT_BLAKE_32 1
+#endif
+
+#if SPH_64 && (SPH_SMALL_FOOTPRINT_BLAKE || !SPH_64_TRUE)
+#define SPH_COMPACT_BLAKE_64 1
+#endif
+
+#ifdef _MSC_VER
+#pragma warning (disable: 4146)
+#endif
+
+static const sph_u32 IV224[8] = {
+ SPH_C32(0xC1059ED8), SPH_C32(0x367CD507),
+ SPH_C32(0x3070DD17), SPH_C32(0xF70E5939),
+ SPH_C32(0xFFC00B31), SPH_C32(0x68581511),
+ SPH_C32(0x64F98FA7), SPH_C32(0xBEFA4FA4)
+};
+
+static const sph_u32 IV256[8] = {
+ SPH_C32(0x6A09E667), SPH_C32(0xBB67AE85),
+ SPH_C32(0x3C6EF372), SPH_C32(0xA54FF53A),
+ SPH_C32(0x510E527F), SPH_C32(0x9B05688C),
+ SPH_C32(0x1F83D9AB), SPH_C32(0x5BE0CD19)
+};
+
+#if SPH_64
+
+static const sph_u64 IV384[8] = {
+ SPH_C64(0xCBBB9D5DC1059ED8), SPH_C64(0x629A292A367CD507),
+ SPH_C64(0x9159015A3070DD17), SPH_C64(0x152FECD8F70E5939),
+ SPH_C64(0x67332667FFC00B31), SPH_C64(0x8EB44A8768581511),
+ SPH_C64(0xDB0C2E0D64F98FA7), SPH_C64(0x47B5481DBEFA4FA4)
+};
+
+static const sph_u64 IV512[8] = {
+ SPH_C64(0x6A09E667F3BCC908), SPH_C64(0xBB67AE8584CAA73B),
+ SPH_C64(0x3C6EF372FE94F82B), SPH_C64(0xA54FF53A5F1D36F1),
+ SPH_C64(0x510E527FADE682D1), SPH_C64(0x9B05688C2B3E6C1F),
+ SPH_C64(0x1F83D9ABFB41BD6B), SPH_C64(0x5BE0CD19137E2179)
+};
+
+#endif
+
+#if SPH_COMPACT_BLAKE_32 || SPH_COMPACT_BLAKE_64
+
+static const unsigned sigma[16][16] = {
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+ { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
+ { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
+ { 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
+ { 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
+ { 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
+ { 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13, 0 },
+ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
+ { 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
+ { 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
+ { 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
+ { 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
+ { 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
+};
+
+/*
+ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
+ 14 10 4 8 9 15 13 6 1 12 0 2 11 7 5 3
+ 11 8 12 0 5 2 15 13 10 14 3 6 7 1 9 4
+ 7 9 3 1 13 12 11 14 2 6 5 10 4 0 15 8
+ 9 0 5 7 2 4 10 15 14 1 11 12 6 8 3 13
+ 2 12 6 10 0 11 8 3 4 13 7 5 15 14 1 9
+ 12 5 1 15 14 13 4 10 0 7 6 3 9 2 8 11
+ 13 11 7 14 12 1 3 9 5 0 15 4 8 6 2 10
+ 6 15 14 9 11 3 0 8 12 2 13 7 1 4 10 5
+ 10 2 8 4 7 6 1 5 15 11 9 14 3 12 13 0
+*/
+#endif
+
+#define Z00 0
+#define Z01 1
+#define Z02 2
+#define Z03 3
+#define Z04 4
+#define Z05 5
+#define Z06 6
+#define Z07 7
+#define Z08 8
+#define Z09 9
+#define Z0A A
+#define Z0B B
+#define Z0C C
+#define Z0D D
+#define Z0E E
+#define Z0F F
+
+#define Z10 E
+#define Z11 A
+#define Z12 4
+#define Z13 8
+#define Z14 9
+#define Z15 F
+#define Z16 D
+#define Z17 6
+#define Z18 1
+#define Z19 C
+#define Z1A 0
+#define Z1B 2
+#define Z1C B
+#define Z1D 7
+#define Z1E 5
+#define Z1F 3
+
+#define Z20 B
+#define Z21 8
+#define Z22 C
+#define Z23 0
+#define Z24 5
+#define Z25 2
+#define Z26 F
+#define Z27 D
+#define Z28 A
+#define Z29 E
+#define Z2A 3
+#define Z2B 6
+#define Z2C 7
+#define Z2D 1
+#define Z2E 9
+#define Z2F 4
+
+#define Z30 7
+#define Z31 9
+#define Z32 3
+#define Z33 1
+#define Z34 D
+#define Z35 C
+#define Z36 B
+#define Z37 E
+#define Z38 2
+#define Z39 6
+#define Z3A 5
+#define Z3B A
+#define Z3C 4
+#define Z3D 0
+#define Z3E F
+#define Z3F 8
+
+#define Z40 9
+#define Z41 0
+#define Z42 5
+#define Z43 7
+#define Z44 2
+#define Z45 4
+#define Z46 A
+#define Z47 F
+#define Z48 E
+#define Z49 1
+#define Z4A B
+#define Z4B C
+#define Z4C 6
+#define Z4D 8
+#define Z4E 3
+#define Z4F D
+
+#define Z50 2
+#define Z51 C
+#define Z52 6
+#define Z53 A
+#define Z54 0
+#define Z55 B
+#define Z56 8
+#define Z57 3
+#define Z58 4
+#define Z59 D
+#define Z5A 7
+#define Z5B 5
+#define Z5C F
+#define Z5D E
+#define Z5E 1
+#define Z5F 9
+
+#define Z60 C
+#define Z61 5
+#define Z62 1
+#define Z63 F
+#define Z64 E
+#define Z65 D
+#define Z66 4
+#define Z67 A
+#define Z68 0
+#define Z69 7
+#define Z6A 6
+#define Z6B 3
+#define Z6C 9
+#define Z6D 2
+#define Z6E 8
+#define Z6F B
+
+#define Z70 D
+#define Z71 B
+#define Z72 7
+#define Z73 E
+#define Z74 C
+#define Z75 1
+#define Z76 3
+#define Z77 9
+#define Z78 5
+#define Z79 0
+#define Z7A F
+#define Z7B 4
+#define Z7C 8
+#define Z7D 6
+#define Z7E 2
+#define Z7F A
+
+#define Z80 6
+#define Z81 F
+#define Z82 E
+#define Z83 9
+#define Z84 B
+#define Z85 3
+#define Z86 0
+#define Z87 8
+#define Z88 C
+#define Z89 2
+#define Z8A D
+#define Z8B 7
+#define Z8C 1
+#define Z8D 4
+#define Z8E A
+#define Z8F 5
+
+#define Z90 A
+#define Z91 2
+#define Z92 8
+#define Z93 4
+#define Z94 7
+#define Z95 6
+#define Z96 1
+#define Z97 5
+#define Z98 F
+#define Z99 B
+#define Z9A 9
+#define Z9B E
+#define Z9C 3
+#define Z9D C
+#define Z9E D
+#define Z9F 0
+
+#define Mx(r, i) Mx_(Z ## r ## i)
+#define Mx_(n) Mx__(n)
+#define Mx__(n) M ## n
+
+#define CSx(r, i) CSx_(Z ## r ## i)
+#define CSx_(n) CSx__(n)
+#define CSx__(n) CS ## n
+
+#define CS0 SPH_C32(0x243F6A88)
+#define CS1 SPH_C32(0x85A308D3)
+#define CS2 SPH_C32(0x13198A2E)
+#define CS3 SPH_C32(0x03707344)
+#define CS4 SPH_C32(0xA4093822)
+#define CS5 SPH_C32(0x299F31D0)
+#define CS6 SPH_C32(0x082EFA98)
+#define CS7 SPH_C32(0xEC4E6C89)
+#define CS8 SPH_C32(0x452821E6)
+#define CS9 SPH_C32(0x38D01377)
+#define CSA SPH_C32(0xBE5466CF)
+#define CSB SPH_C32(0x34E90C6C)
+#define CSC SPH_C32(0xC0AC29B7)
+#define CSD SPH_C32(0xC97C50DD)
+#define CSE SPH_C32(0x3F84D5B5)
+#define CSF SPH_C32(0xB5470917)
+
+#if SPH_COMPACT_BLAKE_32
+
+static const sph_u32 CS[16] = {
+ SPH_C32(0x243F6A88), SPH_C32(0x85A308D3),
+ SPH_C32(0x13198A2E), SPH_C32(0x03707344),
+ SPH_C32(0xA4093822), SPH_C32(0x299F31D0),
+ SPH_C32(0x082EFA98), SPH_C32(0xEC4E6C89),
+ SPH_C32(0x452821E6), SPH_C32(0x38D01377),
+ SPH_C32(0xBE5466CF), SPH_C32(0x34E90C6C),
+ SPH_C32(0xC0AC29B7), SPH_C32(0xC97C50DD),
+ SPH_C32(0x3F84D5B5), SPH_C32(0xB5470917)
+};
+
+#endif
+
+#if SPH_64
+
+#define CBx(r, i) CBx_(Z ## r ## i)
+#define CBx_(n) CBx__(n)
+#define CBx__(n) CB ## n
+
+#define CB0 SPH_C64(0x243F6A8885A308D3)
+#define CB1 SPH_C64(0x13198A2E03707344)
+#define CB2 SPH_C64(0xA4093822299F31D0)
+#define CB3 SPH_C64(0x082EFA98EC4E6C89)
+#define CB4 SPH_C64(0x452821E638D01377)
+#define CB5 SPH_C64(0xBE5466CF34E90C6C)
+#define CB6 SPH_C64(0xC0AC29B7C97C50DD)
+#define CB7 SPH_C64(0x3F84D5B5B5470917)
+#define CB8 SPH_C64(0x9216D5D98979FB1B)
+#define CB9 SPH_C64(0xD1310BA698DFB5AC)
+#define CBA SPH_C64(0x2FFD72DBD01ADFB7)
+#define CBB SPH_C64(0xB8E1AFED6A267E96)
+#define CBC SPH_C64(0xBA7C9045F12C7F99)
+#define CBD SPH_C64(0x24A19947B3916CF7)
+#define CBE SPH_C64(0x0801F2E2858EFC16)
+#define CBF SPH_C64(0x636920D871574E69)
+
+#if SPH_COMPACT_BLAKE_64
+
+static const sph_u64 CB[16] = {
+ SPH_C64(0x243F6A8885A308D3), SPH_C64(0x13198A2E03707344),
+ SPH_C64(0xA4093822299F31D0), SPH_C64(0x082EFA98EC4E6C89),
+ SPH_C64(0x452821E638D01377), SPH_C64(0xBE5466CF34E90C6C),
+ SPH_C64(0xC0AC29B7C97C50DD), SPH_C64(0x3F84D5B5B5470917),
+ SPH_C64(0x9216D5D98979FB1B), SPH_C64(0xD1310BA698DFB5AC),
+ SPH_C64(0x2FFD72DBD01ADFB7), SPH_C64(0xB8E1AFED6A267E96),
+ SPH_C64(0xBA7C9045F12C7F99), SPH_C64(0x24A19947B3916CF7),
+ SPH_C64(0x0801F2E2858EFC16), SPH_C64(0x636920D871574E69)
+};
+
+#endif
+
+#endif
+
+#define GS(m0, m1, c0, c1, a, b, c, d) do { \
+ a = SPH_T32(a + b + (m0 ^ c1)); \
+ d = SPH_ROTR32(d ^ a, 16); \
+ c = SPH_T32(c + d); \
+ b = SPH_ROTR32(b ^ c, 12); \
+ a = SPH_T32(a + b + (m1 ^ c0)); \
+ d = SPH_ROTR32(d ^ a, 8); \
+ c = SPH_T32(c + d); \
+ b = SPH_ROTR32(b ^ c, 7); \
+ } while (0)
+
+#if SPH_COMPACT_BLAKE_32
+
+#define ROUND_S(r) do { \
+ GS(M[sigma[r][0x0]], M[sigma[r][0x1]], \
+ CS[sigma[r][0x0]], CS[sigma[r][0x1]], V0, V4, V8, VC); \
+ GS(M[sigma[r][0x2]], M[sigma[r][0x3]], \
+ CS[sigma[r][0x2]], CS[sigma[r][0x3]], V1, V5, V9, VD); \
+ GS(M[sigma[r][0x4]], M[sigma[r][0x5]], \
+ CS[sigma[r][0x4]], CS[sigma[r][0x5]], V2, V6, VA, VE); \
+ GS(M[sigma[r][0x6]], M[sigma[r][0x7]], \
+ CS[sigma[r][0x6]], CS[sigma[r][0x7]], V3, V7, VB, VF); \
+ GS(M[sigma[r][0x8]], M[sigma[r][0x9]], \
+ CS[sigma[r][0x8]], CS[sigma[r][0x9]], V0, V5, VA, VF); \
+ GS(M[sigma[r][0xA]], M[sigma[r][0xB]], \
+ CS[sigma[r][0xA]], CS[sigma[r][0xB]], V1, V6, VB, VC); \
+ GS(M[sigma[r][0xC]], M[sigma[r][0xD]], \
+ CS[sigma[r][0xC]], CS[sigma[r][0xD]], V2, V7, V8, VD); \
+ GS(M[sigma[r][0xE]], M[sigma[r][0xF]], \
+ CS[sigma[r][0xE]], CS[sigma[r][0xF]], V3, V4, V9, VE); \
+ } while (0)
+
+#else
+
+#define ROUND_S(r) do { \
+ GS(Mx(r, 0), Mx(r, 1), CSx(r, 0), CSx(r, 1), V0, V4, V8, VC); \
+ GS(Mx(r, 2), Mx(r, 3), CSx(r, 2), CSx(r, 3), V1, V5, V9, VD); \
+ GS(Mx(r, 4), Mx(r, 5), CSx(r, 4), CSx(r, 5), V2, V6, VA, VE); \
+ GS(Mx(r, 6), Mx(r, 7), CSx(r, 6), CSx(r, 7), V3, V7, VB, VF); \
+ GS(Mx(r, 8), Mx(r, 9), CSx(r, 8), CSx(r, 9), V0, V5, VA, VF); \
+ GS(Mx(r, A), Mx(r, B), CSx(r, A), CSx(r, B), V1, V6, VB, VC); \
+ GS(Mx(r, C), Mx(r, D), CSx(r, C), CSx(r, D), V2, V7, V8, VD); \
+ GS(Mx(r, E), Mx(r, F), CSx(r, E), CSx(r, F), V3, V4, V9, VE); \
+ } while (0)
+
+#endif
+
+#if SPH_64
+
+#define GB(m0, m1, c0, c1, a, b, c, d) do { \
+ a = SPH_T64(a + b + (m0 ^ c1)); \
+ d = SPH_ROTR64(d ^ a, 32); \
+ c = SPH_T64(c + d); \
+ b = SPH_ROTR64(b ^ c, 25); \
+ a = SPH_T64(a + b + (m1 ^ c0)); \
+ d = SPH_ROTR64(d ^ a, 16); \
+ c = SPH_T64(c + d); \
+ b = SPH_ROTR64(b ^ c, 11); \
+ } while (0)
+
+#if SPH_COMPACT_BLAKE_64
+
+#define ROUND_B(r) do { \
+ GB(M[sigma[r][0x0]], M[sigma[r][0x1]], \
+ CB[sigma[r][0x0]], CB[sigma[r][0x1]], V0, V4, V8, VC); \
+ GB(M[sigma[r][0x2]], M[sigma[r][0x3]], \
+ CB[sigma[r][0x2]], CB[sigma[r][0x3]], V1, V5, V9, VD); \
+ GB(M[sigma[r][0x4]], M[sigma[r][0x5]], \
+ CB[sigma[r][0x4]], CB[sigma[r][0x5]], V2, V6, VA, VE); \
+ GB(M[sigma[r][0x6]], M[sigma[r][0x7]], \
+ CB[sigma[r][0x6]], CB[sigma[r][0x7]], V3, V7, VB, VF); \
+ GB(M[sigma[r][0x8]], M[sigma[r][0x9]], \
+ CB[sigma[r][0x8]], CB[sigma[r][0x9]], V0, V5, VA, VF); \
+ GB(M[sigma[r][0xA]], M[sigma[r][0xB]], \
+ CB[sigma[r][0xA]], CB[sigma[r][0xB]], V1, V6, VB, VC); \
+ GB(M[sigma[r][0xC]], M[sigma[r][0xD]], \
+ CB[sigma[r][0xC]], CB[sigma[r][0xD]], V2, V7, V8, VD); \
+ GB(M[sigma[r][0xE]], M[sigma[r][0xF]], \
+ CB[sigma[r][0xE]], CB[sigma[r][0xF]], V3, V4, V9, VE); \
+ } while (0)
+
+#else
+
+#define ROUND_B(r) do { \
+ GB(Mx(r, 0), Mx(r, 1), CBx(r, 0), CBx(r, 1), V0, V4, V8, VC); \
+ GB(Mx(r, 2), Mx(r, 3), CBx(r, 2), CBx(r, 3), V1, V5, V9, VD); \
+ GB(Mx(r, 4), Mx(r, 5), CBx(r, 4), CBx(r, 5), V2, V6, VA, VE); \
+ GB(Mx(r, 6), Mx(r, 7), CBx(r, 6), CBx(r, 7), V3, V7, VB, VF); \
+ GB(Mx(r, 8), Mx(r, 9), CBx(r, 8), CBx(r, 9), V0, V5, VA, VF); \
+ GB(Mx(r, A), Mx(r, B), CBx(r, A), CBx(r, B), V1, V6, VB, VC); \
+ GB(Mx(r, C), Mx(r, D), CBx(r, C), CBx(r, D), V2, V7, V8, VD); \
+ GB(Mx(r, E), Mx(r, F), CBx(r, E), CBx(r, F), V3, V4, V9, VE); \
+ } while (0)
+
+#endif
+
+#endif
+
+#define DECL_STATE32 \
+ sph_u32 H0, H1, H2, H3, H4, H5, H6, H7; \
+ sph_u32 S0, S1, S2, S3, T0, T1;
+
+#define READ_STATE32(state) do { \
+ H0 = (state)->H[0]; \
+ H1 = (state)->H[1]; \
+ H2 = (state)->H[2]; \
+ H3 = (state)->H[3]; \
+ H4 = (state)->H[4]; \
+ H5 = (state)->H[5]; \
+ H6 = (state)->H[6]; \
+ H7 = (state)->H[7]; \
+ S0 = (state)->S[0]; \
+ S1 = (state)->S[1]; \
+ S2 = (state)->S[2]; \
+ S3 = (state)->S[3]; \
+ T0 = (state)->T0; \
+ T1 = (state)->T1; \
+ } while (0)
+
+#define WRITE_STATE32(state) do { \
+ (state)->H[0] = H0; \
+ (state)->H[1] = H1; \
+ (state)->H[2] = H2; \
+ (state)->H[3] = H3; \
+ (state)->H[4] = H4; \
+ (state)->H[5] = H5; \
+ (state)->H[6] = H6; \
+ (state)->H[7] = H7; \
+ (state)->S[0] = S0; \
+ (state)->S[1] = S1; \
+ (state)->S[2] = S2; \
+ (state)->S[3] = S3; \
+ (state)->T0 = T0; \
+ (state)->T1 = T1; \
+ } while (0)
+
+#if SPH_COMPACT_BLAKE_32
+
+#define COMPRESS32 do { \
+ sph_u32 M[16]; \
+ sph_u32 V0, V1, V2, V3, V4, V5, V6, V7; \
+ sph_u32 V8, V9, VA, VB, VC, VD, VE, VF; \
+ unsigned r; \
+ V0 = H0; \
+ V1 = H1; \
+ V2 = H2; \
+ V3 = H3; \
+ V4 = H4; \
+ V5 = H5; \
+ V6 = H6; \
+ V7 = H7; \
+ V8 = S0 ^ CS0; \
+ V9 = S1 ^ CS1; \
+ VA = S2 ^ CS2; \
+ VB = S3 ^ CS3; \
+ VC = T0 ^ CS4; \
+ VD = T0 ^ CS5; \
+ VE = T1 ^ CS6; \
+ VF = T1 ^ CS7; \
+ M[0x0] = sph_dec32be_aligned(buf + 0); \
+ M[0x1] = sph_dec32be_aligned(buf + 4); \
+ M[0x2] = sph_dec32be_aligned(buf + 8); \
+ M[0x3] = sph_dec32be_aligned(buf + 12); \
+ M[0x4] = sph_dec32be_aligned(buf + 16); \
+ M[0x5] = sph_dec32be_aligned(buf + 20); \
+ M[0x6] = sph_dec32be_aligned(buf + 24); \
+ M[0x7] = sph_dec32be_aligned(buf + 28); \
+ M[0x8] = sph_dec32be_aligned(buf + 32); \
+ M[0x9] = sph_dec32be_aligned(buf + 36); \
+ M[0xA] = sph_dec32be_aligned(buf + 40); \
+ M[0xB] = sph_dec32be_aligned(buf + 44); \
+ M[0xC] = sph_dec32be_aligned(buf + 48); \
+ M[0xD] = sph_dec32be_aligned(buf + 52); \
+ M[0xE] = sph_dec32be_aligned(buf + 56); \
+ M[0xF] = sph_dec32be_aligned(buf + 60); \
+ for (r = 0; r < 14; r ++) \
+ ROUND_S(r); \
+ H0 ^= S0 ^ V0 ^ V8; \
+ H1 ^= S1 ^ V1 ^ V9; \
+ H2 ^= S2 ^ V2 ^ VA; \
+ H3 ^= S3 ^ V3 ^ VB; \
+ H4 ^= S0 ^ V4 ^ VC; \
+ H5 ^= S1 ^ V5 ^ VD; \
+ H6 ^= S2 ^ V6 ^ VE; \
+ H7 ^= S3 ^ V7 ^ VF; \
+ } while (0)
+
+#else
+
+#define COMPRESS32 do { \
+ sph_u32 M0, M1, M2, M3, M4, M5, M6, M7; \
+ sph_u32 M8, M9, MA, MB, MC, MD, ME, MF; \
+ sph_u32 V0, V1, V2, V3, V4, V5, V6, V7; \
+ sph_u32 V8, V9, VA, VB, VC, VD, VE, VF; \
+ V0 = H0; \
+ V1 = H1; \
+ V2 = H2; \
+ V3 = H3; \
+ V4 = H4; \
+ V5 = H5; \
+ V6 = H6; \
+ V7 = H7; \
+ V8 = S0 ^ CS0; \
+ V9 = S1 ^ CS1; \
+ VA = S2 ^ CS2; \
+ VB = S3 ^ CS3; \
+ VC = T0 ^ CS4; \
+ VD = T0 ^ CS5; \
+ VE = T1 ^ CS6; \
+ VF = T1 ^ CS7; \
+ M0 = sph_dec32be_aligned(buf + 0); \
+ M1 = sph_dec32be_aligned(buf + 4); \
+ M2 = sph_dec32be_aligned(buf + 8); \
+ M3 = sph_dec32be_aligned(buf + 12); \
+ M4 = sph_dec32be_aligned(buf + 16); \
+ M5 = sph_dec32be_aligned(buf + 20); \
+ M6 = sph_dec32be_aligned(buf + 24); \
+ M7 = sph_dec32be_aligned(buf + 28); \
+ M8 = sph_dec32be_aligned(buf + 32); \
+ M9 = sph_dec32be_aligned(buf + 36); \
+ MA = sph_dec32be_aligned(buf + 40); \
+ MB = sph_dec32be_aligned(buf + 44); \
+ MC = sph_dec32be_aligned(buf + 48); \
+ MD = sph_dec32be_aligned(buf + 52); \
+ ME = sph_dec32be_aligned(buf + 56); \
+ MF = sph_dec32be_aligned(buf + 60); \
+ ROUND_S(0); \
+ ROUND_S(1); \
+ ROUND_S(2); \
+ ROUND_S(3); \
+ ROUND_S(4); \
+ ROUND_S(5); \
+ ROUND_S(6); \
+ ROUND_S(7); \
+ ROUND_S(8); \
+ ROUND_S(9); \
+ ROUND_S(0); \
+ ROUND_S(1); \
+ ROUND_S(2); \
+ ROUND_S(3); \
+ H0 ^= S0 ^ V0 ^ V8; \
+ H1 ^= S1 ^ V1 ^ V9; \
+ H2 ^= S2 ^ V2 ^ VA; \
+ H3 ^= S3 ^ V3 ^ VB; \
+ H4 ^= S0 ^ V4 ^ VC; \
+ H5 ^= S1 ^ V5 ^ VD; \
+ H6 ^= S2 ^ V6 ^ VE; \
+ H7 ^= S3 ^ V7 ^ VF; \
+ } while (0)
+
+#endif
+
+#if SPH_64
+
+#define DECL_STATE64 \
+ sph_u64 H0, H1, H2, H3, H4, H5, H6, H7; \
+ sph_u64 S0, S1, S2, S3, T0, T1;
+
+#define READ_STATE64(state) do { \
+ H0 = (state)->H[0]; \
+ H1 = (state)->H[1]; \
+ H2 = (state)->H[2]; \
+ H3 = (state)->H[3]; \
+ H4 = (state)->H[4]; \
+ H5 = (state)->H[5]; \
+ H6 = (state)->H[6]; \
+ H7 = (state)->H[7]; \
+ S0 = (state)->S[0]; \
+ S1 = (state)->S[1]; \
+ S2 = (state)->S[2]; \
+ S3 = (state)->S[3]; \
+ T0 = (state)->T0; \
+ T1 = (state)->T1; \
+ } while (0)
+
+#define WRITE_STATE64(state) do { \
+ (state)->H[0] = H0; \
+ (state)->H[1] = H1; \
+ (state)->H[2] = H2; \
+ (state)->H[3] = H3; \
+ (state)->H[4] = H4; \
+ (state)->H[5] = H5; \
+ (state)->H[6] = H6; \
+ (state)->H[7] = H7; \
+ (state)->S[0] = S0; \
+ (state)->S[1] = S1; \
+ (state)->S[2] = S2; \
+ (state)->S[3] = S3; \
+ (state)->T0 = T0; \
+ (state)->T1 = T1; \
+ } while (0)
+
+#if SPH_COMPACT_BLAKE_64
+
+#define COMPRESS64 do { \
+ sph_u64 M[16]; \
+ sph_u64 V0, V1, V2, V3, V4, V5, V6, V7; \
+ sph_u64 V8, V9, VA, VB, VC, VD, VE, VF; \
+ unsigned r; \
+ V0 = H0; \
+ V1 = H1; \
+ V2 = H2; \
+ V3 = H3; \
+ V4 = H4; \
+ V5 = H5; \
+ V6 = H6; \
+ V7 = H7; \
+ V8 = S0 ^ CB0; \
+ V9 = S1 ^ CB1; \
+ VA = S2 ^ CB2; \
+ VB = S3 ^ CB3; \
+ VC = T0 ^ CB4; \
+ VD = T0 ^ CB5; \
+ VE = T1 ^ CB6; \
+ VF = T1 ^ CB7; \
+ M[0x0] = sph_dec64be_aligned(buf + 0); \
+ M[0x1] = sph_dec64be_aligned(buf + 8); \
+ M[0x2] = sph_dec64be_aligned(buf + 16); \
+ M[0x3] = sph_dec64be_aligned(buf + 24); \
+ M[0x4] = sph_dec64be_aligned(buf + 32); \
+ M[0x5] = sph_dec64be_aligned(buf + 40); \
+ M[0x6] = sph_dec64be_aligned(buf + 48); \
+ M[0x7] = sph_dec64be_aligned(buf + 56); \
+ M[0x8] = sph_dec64be_aligned(buf + 64); \
+ M[0x9] = sph_dec64be_aligned(buf + 72); \
+ M[0xA] = sph_dec64be_aligned(buf + 80); \
+ M[0xB] = sph_dec64be_aligned(buf + 88); \
+ M[0xC] = sph_dec64be_aligned(buf + 96); \
+ M[0xD] = sph_dec64be_aligned(buf + 104); \
+ M[0xE] = sph_dec64be_aligned(buf + 112); \
+ M[0xF] = sph_dec64be_aligned(buf + 120); \
+ for (r = 0; r < 16; r ++) \
+ ROUND_B(r); \
+ H0 ^= S0 ^ V0 ^ V8; \
+ H1 ^= S1 ^ V1 ^ V9; \
+ H2 ^= S2 ^ V2 ^ VA; \
+ H3 ^= S3 ^ V3 ^ VB; \
+ H4 ^= S0 ^ V4 ^ VC; \
+ H5 ^= S1 ^ V5 ^ VD; \
+ H6 ^= S2 ^ V6 ^ VE; \
+ H7 ^= S3 ^ V7 ^ VF; \
+ } while (0)
+
+#else
+
+#define COMPRESS64 do { \
+ sph_u64 M0, M1, M2, M3, M4, M5, M6, M7; \
+ sph_u64 M8, M9, MA, MB, MC, MD, ME, MF; \
+ sph_u64 V0, V1, V2, V3, V4, V5, V6, V7; \
+ sph_u64 V8, V9, VA, VB, VC, VD, VE, VF; \
+ V0 = H0; \
+ V1 = H1; \
+ V2 = H2; \
+ V3 = H3; \
+ V4 = H4; \
+ V5 = H5; \
+ V6 = H6; \
+ V7 = H7; \
+ V8 = S0 ^ CB0; \
+ V9 = S1 ^ CB1; \
+ VA = S2 ^ CB2; \
+ VB = S3 ^ CB3; \
+ VC = T0 ^ CB4; \
+ VD = T0 ^ CB5; \
+ VE = T1 ^ CB6; \
+ VF = T1 ^ CB7; \
+ M0 = sph_dec64be_aligned(buf + 0); \
+ M1 = sph_dec64be_aligned(buf + 8); \
+ M2 = sph_dec64be_aligned(buf + 16); \
+ M3 = sph_dec64be_aligned(buf + 24); \
+ M4 = sph_dec64be_aligned(buf + 32); \
+ M5 = sph_dec64be_aligned(buf + 40); \
+ M6 = sph_dec64be_aligned(buf + 48); \
+ M7 = sph_dec64be_aligned(buf + 56); \
+ M8 = sph_dec64be_aligned(buf + 64); \
+ M9 = sph_dec64be_aligned(buf + 72); \
+ MA = sph_dec64be_aligned(buf + 80); \
+ MB = sph_dec64be_aligned(buf + 88); \
+ MC = sph_dec64be_aligned(buf + 96); \
+ MD = sph_dec64be_aligned(buf + 104); \
+ ME = sph_dec64be_aligned(buf + 112); \
+ MF = sph_dec64be_aligned(buf + 120); \
+ ROUND_B(0); \
+ ROUND_B(1); \
+ ROUND_B(2); \
+ ROUND_B(3); \
+ ROUND_B(4); \
+ ROUND_B(5); \
+ ROUND_B(6); \
+ ROUND_B(7); \
+ ROUND_B(8); \
+ ROUND_B(9); \
+ ROUND_B(0); \
+ ROUND_B(1); \
+ ROUND_B(2); \
+ ROUND_B(3); \
+ ROUND_B(4); \
+ ROUND_B(5); \
+ H0 ^= S0 ^ V0 ^ V8; \
+ H1 ^= S1 ^ V1 ^ V9; \
+ H2 ^= S2 ^ V2 ^ VA; \
+ H3 ^= S3 ^ V3 ^ VB; \
+ H4 ^= S0 ^ V4 ^ VC; \
+ H5 ^= S1 ^ V5 ^ VD; \
+ H6 ^= S2 ^ V6 ^ VE; \
+ H7 ^= S3 ^ V7 ^ VF; \
+ } while (0)
+
+#endif
+
+#endif
+
+static const sph_u32 salt_zero_small[4] = { 0, 0, 0, 0 };
+
+static void
+blake32_init(sph_blake_small_context *sc,
+ const sph_u32 *iv, const sph_u32 *salt)
+{
+ memcpy(sc->H, iv, 8 * sizeof(sph_u32));
+ memcpy(sc->S, salt, 4 * sizeof(sph_u32));
+ sc->T0 = sc->T1 = 0;
+ sc->ptr = 0;
+}
+
+static void
+blake32(sph_blake_small_context *sc, const void *data, size_t len)
+{
+ unsigned char *buf;
+ size_t ptr;
+ DECL_STATE32
+
+ buf = sc->buf;
+ ptr = sc->ptr;
+ if (len < (sizeof sc->buf) - ptr) {
+ memcpy(buf + ptr, data, len);
+ ptr += len;
+ sc->ptr = ptr;
+ return;
+ }
+
+ READ_STATE32(sc);
+ while (len > 0) {
+ size_t clen;
+
+ clen = (sizeof sc->buf) - ptr;
+ if (clen > len)
+ clen = len;
+ memcpy(buf + ptr, data, clen);
+ ptr += clen;
+ data = (const unsigned char *)data + clen;
+ len -= clen;
+ if (ptr == sizeof sc->buf) {
+ if ((T0 = SPH_T32(T0 + 512)) < 512)
+ T1 = SPH_T32(T1 + 1);
+ COMPRESS32;
+ ptr = 0;
+ }
+ }
+ WRITE_STATE32(sc);
+ sc->ptr = ptr;
+}
+
+static void
+blake32_close(sph_blake_small_context *sc,
+ unsigned ub, unsigned n, void *dst, size_t out_size_w32)
+{
+ union {
+ unsigned char buf[64];
+ sph_u32 dummy;
+ } u;
+ size_t ptr, k;
+ unsigned bit_len;
+ unsigned z;
+ sph_u32 th, tl;
+ unsigned char *out;
+
+ ptr = sc->ptr;
+ bit_len = ((unsigned)ptr << 3) + n;
+ z = 0x80 >> n;
+ u.buf[ptr] = ((ub & -z) | z) & 0xFF;
+ tl = sc->T0 + bit_len;
+ th = sc->T1;
+ if (ptr == 0 && n == 0) {
+ sc->T0 = SPH_C32(0xFFFFFE00);
+ sc->T1 = SPH_C32(0xFFFFFFFF);
+ } else if (sc->T0 == 0) {
+ sc->T0 = SPH_C32(0xFFFFFE00) + bit_len;
+ sc->T1 = SPH_T32(sc->T1 - 1);
+ } else {
+ sc->T0 -= 512 - bit_len;
+ }
+ if (bit_len <= 446) {
+ memset(u.buf + ptr + 1, 0, 55 - ptr);
+ if (out_size_w32 == 8)
+ u.buf[55] |= 1;
+ sph_enc32be_aligned(u.buf + 56, th);
+ sph_enc32be_aligned(u.buf + 60, tl);
+ blake32(sc, u.buf + ptr, 64 - ptr);
+ } else {
+ memset(u.buf + ptr + 1, 0, 63 - ptr);
+ blake32(sc, u.buf + ptr, 64 - ptr);
+ sc->T0 = SPH_C32(0xFFFFFE00);
+ sc->T1 = SPH_C32(0xFFFFFFFF);
+ memset(u.buf, 0, 56);
+ if (out_size_w32 == 8)
+ u.buf[55] = 1;
+ sph_enc32be_aligned(u.buf + 56, th);
+ sph_enc32be_aligned(u.buf + 60, tl);
+ blake32(sc, u.buf, 64);
+ }
+ out = dst;
+ for (k = 0; k < out_size_w32; k ++)
+ sph_enc32be(out + (k << 2), sc->H[k]);
+}
+
+#if SPH_64
+
+static const sph_u64 salt_zero_big[4] = { 0, 0, 0, 0 };
+
+static void
+blake64_init(sph_blake_big_context *sc,
+ const sph_u64 *iv, const sph_u64 *salt)
+{
+ memcpy(sc->H, iv, 8 * sizeof(sph_u64));
+ memcpy(sc->S, salt, 4 * sizeof(sph_u64));
+ sc->T0 = sc->T1 = 0;
+ sc->ptr = 0;
+}
+
+static void
+blake64(sph_blake_big_context *sc, const void *data, size_t len)
+{
+ unsigned char *buf;
+ size_t ptr;
+ DECL_STATE64
+
+ buf = sc->buf;
+ ptr = sc->ptr;
+ if (len < (sizeof sc->buf) - ptr) {
+ memcpy(buf + ptr, data, len);
+ ptr += len;
+ sc->ptr = ptr;
+ return;
+ }
+
+ READ_STATE64(sc);
+ while (len > 0) {
+ size_t clen;
+
+ clen = (sizeof sc->buf) - ptr;
+ if (clen > len)
+ clen = len;
+ memcpy(buf + ptr, data, clen);
+ ptr += clen;
+ data = (const unsigned char *)data + clen;
+ len -= clen;
+ if (ptr == sizeof sc->buf) {
+ if ((T0 = SPH_T64(T0 + 1024)) < 1024)
+ T1 = SPH_T64(T1 + 1);
+ COMPRESS64;
+ ptr = 0;
+ }
+ }
+ WRITE_STATE64(sc);
+ sc->ptr = ptr;
+}
+
+static void
+blake64_close(sph_blake_big_context *sc,
+ unsigned ub, unsigned n, void *dst, size_t out_size_w64)
+{
+ union {
+ unsigned char buf[128];
+ sph_u64 dummy;
+ } u;
+ size_t ptr, k;
+ unsigned bit_len;
+ unsigned z;
+ sph_u64 th, tl;
+ unsigned char *out;
+
+ ptr = sc->ptr;
+ bit_len = ((unsigned)ptr << 3) + n;
+ z = 0x80 >> n;
+ u.buf[ptr] = ((ub & -z) | z) & 0xFF;
+ tl = sc->T0 + bit_len;
+ th = sc->T1;
+ if (ptr == 0 && n == 0) {
+ sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00);
+ sc->T1 = SPH_C64(0xFFFFFFFFFFFFFFFF);
+ } else if (sc->T0 == 0) {
+ sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00) + bit_len;
+ sc->T1 = SPH_T64(sc->T1 - 1);
+ } else {
+ sc->T0 -= 1024 - bit_len;
+ }
+ if (bit_len <= 894) {
+ memset(u.buf + ptr + 1, 0, 111 - ptr);
+ if (out_size_w64 == 8)
+ u.buf[111] |= 1;
+ sph_enc64be_aligned(u.buf + 112, th);
+ sph_enc64be_aligned(u.buf + 120, tl);
+ blake64(sc, u.buf + ptr, 128 - ptr);
+ } else {
+ memset(u.buf + ptr + 1, 0, 127 - ptr);
+ blake64(sc, u.buf + ptr, 128 - ptr);
+ sc->T0 = SPH_C64(0xFFFFFFFFFFFFFC00);
+ sc->T1 = SPH_C64(0xFFFFFFFFFFFFFFFF);
+ memset(u.buf, 0, 112);
+ if (out_size_w64 == 8)
+ u.buf[111] = 1;
+ sph_enc64be_aligned(u.buf + 112, th);
+ sph_enc64be_aligned(u.buf + 120, tl);
+ blake64(sc, u.buf, 128);
+ }
+ out = dst;
+ for (k = 0; k < out_size_w64; k ++)
+ sph_enc64be(out + (k << 3), sc->H[k]);
+}
+
+#endif
+
+/* see sph_blake.h */
+void
+sph_blake224_init(void *cc)
+{
+ blake32_init(cc, IV224, salt_zero_small);
+}
+
+/* see sph_blake.h */
+void
+sph_blake224(void *cc, const void *data, size_t len)
+{
+ blake32(cc, data, len);
+}
+
+/* see sph_blake.h */
+void
+sph_blake224_close(void *cc, void *dst)
+{
+ sph_blake224_addbits_and_close(cc, 0, 0, dst);
+}
+
+/* see sph_blake.h */
+void
+sph_blake224_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
+{
+ blake32_close(cc, ub, n, dst, 7);
+ sph_blake224_init(cc);
+}
+
+/* see sph_blake.h */
+void
+sph_blake256_init(void *cc)
+{
+ blake32_init(cc, IV256, salt_zero_small);
+}
+
+/* see sph_blake.h */
+void
+sph_blake256(void *cc, const void *data, size_t len)
+{
+ blake32(cc, data, len);
+}
+
+/* see sph_blake.h */
+void
+sph_blake256_close(void *cc, void *dst)
+{
+ sph_blake256_addbits_and_close(cc, 0, 0, dst);
+}
+
+/* see sph_blake.h */
+void
+sph_blake256_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
+{
+ blake32_close(cc, ub, n, dst, 8);
+ sph_blake256_init(cc);
+}
+
+#if SPH_64
+
+/* see sph_blake.h */
+void
+sph_blake384_init(void *cc)
+{
+ blake64_init(cc, IV384, salt_zero_big);
+}
+
+/* see sph_blake.h */
+void
+sph_blake384(void *cc, const void *data, size_t len)
+{
+ blake64(cc, data, len);
+}
+
+/* see sph_blake.h */
+void
+sph_blake384_close(void *cc, void *dst)
+{
+ sph_blake384_addbits_and_close(cc, 0, 0, dst);
+}
+
+/* see sph_blake.h */
+void
+sph_blake384_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
+{
+ blake64_close(cc, ub, n, dst, 6);
+ sph_blake384_init(cc);
+}
+
+/* see sph_blake.h */
+void
+sph_blake512_init(void *cc)
+{
+ blake64_init(cc, IV512, salt_zero_big);
+}
+
+/* see sph_blake.h */
+void
+sph_blake512(void *cc, const void *data, size_t len)
+{
+ blake64(cc, data, len);
+}
+
+/* see sph_blake.h */
+void
+sph_blake512_close(void *cc, void *dst)
+{
+ sph_blake512_addbits_and_close(cc, 0, 0, dst);
+}
+
+/* see sph_blake.h */
+void
+sph_blake512_addbits_and_close(void *cc, unsigned ub, unsigned n, void *dst)
+{
+ blake64_close(cc, ub, n, dst, 8);
+ sph_blake512_init(cc);
+}
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/exlib/lyra2z-py/lyra2z-zcoin.c b/exlib/lyra2z-py/lyra2z-zcoin.c
new file mode 100644
index 000000000000..0959ff87b6ec
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z-zcoin.c
@@ -0,0 +1,44 @@
+//
+// lyra2z-zcoin.c : windows test harness for Lyra2z hashing
+//
+
+#include "lyra2z-zcoin.h"
+#include "Lyra2z.h"
+#include
+
+static const char test[] = {
+ 0x70, 0x00, 0x00, 0x00, 0x5d, 0x38, 0x5b, 0xa1,
+ 0x14, 0xd0, 0x79, 0x97, 0x1b, 0x29, 0xa9, 0x41,
+ 0x8f, 0xd0, 0x54, 0x9e, 0x7d, 0x68, 0xa9, 0x5c,
+ 0x7f, 0x16, 0x86, 0x21, 0xa3, 0x14, 0x20, 0x10,
+ 0x00, 0x00, 0x00, 0x00, 0x57, 0x85, 0x86, 0xd1,
+ 0x49, 0xfd, 0x07, 0xb2, 0x2f, 0x3a, 0x8a, 0x34,
+ 0x7c, 0x51, 0x6d, 0xe7, 0x05, 0x2f, 0x03, 0x4d,
+ 0x2b, 0x76, 0xff, 0x68, 0xe0, 0xd6, 0xec, 0xff,
+ 0x9b, 0x77, 0xa4, 0x54, 0x89, 0xe3, 0xfd, 0x51,
+ 0x17, 0x32, 0x01, 0x1d, 0xf0, 0x73, 0x10, 0x00
+};
+static const testlen = sizeof(test);
+
+#define OUTLEN 32
+static char out[OUTLEN];
+
+static void dump(char* d, int len) {
+ int i = 0;
+ if (d == NULL || len < 1) {
+ printf("do me a favor...\n");
+ return;
+ }
+ for (i = 0; i < len; i++) {
+ printf("%02x ", (unsigned char)d[i]);
+ }
+ printf("\n");
+}
+
+int main()
+{
+ lyra2z_hash(out, test);
+ dump(out, OUTLEN);
+ return 0;
+}
+
diff --git a/exlib/lyra2z-py/lyra2z-zcoin.h b/exlib/lyra2z-py/lyra2z-zcoin.h
new file mode 100644
index 000000000000..503f3e410ca5
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z-zcoin.h
@@ -0,0 +1,13 @@
+#pragma once
+//
+// Windows only stuff
+//
+
+// Including SDKDDKVer.h defines the highest available Windows platform.
+
+// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and
+// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h.
+#define _WIN32_WINNT _WIN32_WINNT_WIN7
+#include
+
+#include
diff --git a/exlib/lyra2z-py/lyra2z-zcoin.sln b/exlib/lyra2z-py/lyra2z-zcoin.sln
new file mode 100644
index 000000000000..ed0bdb0cc3c5
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z-zcoin.sln
@@ -0,0 +1,28 @@
+
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 14
+VisualStudioVersion = 14.0.25420.1
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lyra2z-zcoin", "lyra2z-zcoin.vcxproj", "{12DBC121-1B34-45B1-82BC-91F9EC4D1062}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Debug|x64.ActiveCfg = Debug|x64
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Debug|x64.Build.0 = Debug|x64
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Debug|x86.ActiveCfg = Debug|Win32
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Debug|x86.Build.0 = Debug|Win32
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Release|x64.ActiveCfg = Release|x64
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Release|x64.Build.0 = Release|x64
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Release|x86.ActiveCfg = Release|Win32
+ {12DBC121-1B34-45B1-82BC-91F9EC4D1062}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/exlib/lyra2z-py/lyra2z.c b/exlib/lyra2z-py/lyra2z.c
new file mode 100644
index 000000000000..cdd07b515f96
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z.c
@@ -0,0 +1,117 @@
+//
+// Hacked from cpuminer-xzc
+//
+
+#ifdef _MSC_VER
+# define _mm_malloc _aligned_malloc
+#else
+# include
+# include
+#endif
+
+#include
+#include "sph_blake.h"
+#include "Lyra2.h"
+
+static void get_lyra2z_hash(uint64_t* mtx, void *state, const void *input)
+{
+ sph_blake256_context ctx_blake;
+
+ uint32_t hashA[8], hashB[8];
+
+ sph_blake256_init(&ctx_blake);
+ sph_blake256(&ctx_blake, input, 80);
+ sph_blake256_close(&ctx_blake, hashA);
+
+ LYRA2(mtx, hashB, 32, hashA, 32, hashA, 32, 8, 8, 8);
+
+ memcpy(state, hashB, 32);
+}
+
+void lyra2z_hash(void *output, const void *input)
+{
+ size_t size = (int64_t)((int64_t)16 * 16 * 96); // from cpuminer-xzc
+ // Windows: _aligned_malloc(size,align)
+ uint64_t *mtx = _mm_malloc(size, 64); // freed in algo
+ get_lyra2z_hash(mtx, output, input);
+}
+
+
+// cpuminer
+//
+#if 0
+void lyra2z_hash(uint64_t* wholeMatrix, void *state, const void *input)
+{
+#ifdef VERBOSE_HASH_TIMING
+ struct timespec spec;
+ clock_gettime(CLOCK_REALTIME, &spec);
+ double start = spec.tv_sec + spec.tv_nsec / 1.0e9;
+#endif
+
+ sph_blake256_context ctx_blake;
+
+ uint32_t hashA[8], hashB[8];
+
+ sph_blake256_init(&ctx_blake);
+ sph_blake256(&ctx_blake, input, 80);
+ sph_blake256_close(&ctx_blake, hashA);
+
+// LYRA2(0, hashB, 32, hashA, 32, hashA, 32, 2, 8, 8);
+
+ LYRA2(wholeMatrix, hashB, 32, hashA, 32, hashA, 32, 8, 8, 8);
+
+#ifdef VERBOSE_HASH_TIMING
+ if (hash[0] % 32 == 0) {
+ clock_gettime(CLOCK_REALTIME, &spec);
+ double end = spec.tv_sec + spec.tv_nsec / 1.0e9;
+ printf("Hash time: %f ms\n", (end - start) * 1000);
+ }
+#endif
+
+ memcpy(state, hashB, 32);
+}
+
+int scanhash_lyra2z(int thr_id, struct work *work, uint32_t max_nonce, uint64_t *hashes_done)
+{
+
+ size_t size = (int64_t)((int64_t)16 * 16 * 96);
+ uint64_t *wholeMatrix = _mm_malloc(size, 64);
+
+ uint32_t _ALIGN(128) hash[8];
+ uint32_t _ALIGN(128) endiandata[20];
+ uint32_t *pdata = work->data;
+ uint32_t *ptarget = work->target;
+
+ const uint32_t Htarg = ptarget[7];
+ const uint32_t first_nonce = pdata[19];
+ uint32_t nonce = first_nonce;
+
+ if (opt_benchmark)
+ ptarget[7] = 0x0000ff;
+
+ for (int i = 0; i < 19; i++) {
+ be32enc(&endiandata[i], pdata[i]);
+ }
+
+ do {
+ be32enc(&endiandata[19], nonce);
+ lyra2z_hash(wholeMatrix, hash, endiandata);
+ // lyra2z_hash(0, hash, endiandata);
+
+ if (hash[7] <= Htarg && fulltest(hash, ptarget)) {
+ work_set_target_ratio(work, hash);
+ pdata[19] = nonce;
+ *hashes_done = pdata[19] - first_nonce;
+ _mm_free(wholeMatrix);
+ return 1;
+ }
+ nonce++;
+
+ } while (nonce < max_nonce && !work_restart[thr_id].restart);
+
+ pdata[19] = nonce;
+ *hashes_done = pdata[19] - first_nonce + 1;
+ _mm_free(wholeMatrix);
+ return 0;
+}
+#endif // 0
diff --git a/exlib/lyra2z-py/lyra2z.h b/exlib/lyra2z-py/lyra2z.h
new file mode 100644
index 000000000000..7b26dd9d9e9e
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z.h
@@ -0,0 +1,7 @@
+
+#ifndef _LYRA2Z_H
+# define _LYRA2Z_H
+
+void lyra2z_hash(void *output, const void *input);
+
+#endif // _LYRA2Z_H
diff --git a/exlib/lyra2z-py/lyra2z_hash.egg-info/PKG-INFO b/exlib/lyra2z-py/lyra2z_hash.egg-info/PKG-INFO
new file mode 100644
index 000000000000..9033864dc6df
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z_hash.egg-info/PKG-INFO
@@ -0,0 +1,11 @@
+Metadata-Version: 1.0
+Name: lyra2z-hash
+Version: 0.1.0
+Summary: Bindings for Lyra2Z proof of work used by Zcoin
+Home-page: https://github.com/devwarrior777/lyra2z-py
+Author: devwarrior
+Author-email: devwarrior.zcoin@gmail.com
+License: UNKNOWN
+Description-Content-Type: UNKNOWN
+Description: UNKNOWN
+Platform: UNKNOWN
diff --git a/exlib/lyra2z-py/lyra2z_hash.egg-info/SOURCES.txt b/exlib/lyra2z-py/lyra2z_hash.egg-info/SOURCES.txt
new file mode 100644
index 000000000000..69959bfb3f6b
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z_hash.egg-info/SOURCES.txt
@@ -0,0 +1,11 @@
+Lyra2.c
+README.md
+Sponge.c
+blake.c
+lyra2z.c
+lyra2zmodule.c
+setup.py
+lyra2z_hash.egg-info/PKG-INFO
+lyra2z_hash.egg-info/SOURCES.txt
+lyra2z_hash.egg-info/dependency_links.txt
+lyra2z_hash.egg-info/top_level.txt
\ No newline at end of file
diff --git a/exlib/lyra2z-py/lyra2z_hash.egg-info/dependency_links.txt b/exlib/lyra2z-py/lyra2z_hash.egg-info/dependency_links.txt
new file mode 100644
index 000000000000..8b137891791f
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z_hash.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/exlib/lyra2z-py/lyra2z_hash.egg-info/top_level.txt b/exlib/lyra2z-py/lyra2z_hash.egg-info/top_level.txt
new file mode 100644
index 000000000000..55f3839ca87d
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2z_hash.egg-info/top_level.txt
@@ -0,0 +1 @@
+lyra2z_hash
diff --git a/exlib/lyra2z-py/lyra2zmodule.c b/exlib/lyra2z-py/lyra2zmodule.c
new file mode 100644
index 000000000000..4bb430a46027
--- /dev/null
+++ b/exlib/lyra2z-py/lyra2zmodule.c
@@ -0,0 +1,57 @@
+#include
+
+#include "lyra2z.h"
+
+static PyObject *lyra2z_getpowhash(PyObject *self, PyObject *args)
+{
+ char *output;
+ PyObject *value;
+#if PY_MAJOR_VERSION >= 3
+ PyBytesObject *input;
+#else
+ PyStringObject *input;
+#endif
+ if (!PyArg_ParseTuple(args, "S", &input))
+ return NULL;
+ Py_INCREF(input);
+ output = PyMem_Malloc(32);
+
+#if PY_MAJOR_VERSION >= 3
+ lyra2z_hash((char *)PyBytes_AsString((PyObject*) input), output);
+#else
+ lyra2z_hash((char *)PyString_AsString((PyObject*) input), output);
+#endif
+ Py_DECREF(input);
+#if PY_MAJOR_VERSION >= 3
+ value = Py_BuildValue("y#", output, 32);
+#else
+ value = Py_BuildValue("s#", output, 32);
+#endif
+ PyMem_Free(output);
+ return value;
+}
+
+static PyMethodDef Lyra2ZMethods[] = {
+ { "getPoWHash", lyra2z_getpowhash, METH_VARARGS, "Returns the proof of work hash using lyra2z hash" },
+ { NULL, NULL, 0, NULL }
+};
+
+#if PY_MAJOR_VERSION >= 3
+static struct PyModuleDef Lyra2ZModule = {
+ PyModuleDef_HEAD_INIT,
+ "lyra2z_hash",
+ "...",
+ -1,
+ Lyra2ZMethods
+};
+
+PyMODINIT_FUNC PyInit_lyra2z_hash(void) {
+ return PyModule_Create(&Lyra2ZModule);
+}
+
+#else
+
+PyMODINIT_FUNC initlyra2z_hash(void) {
+ (void) Py_InitModule("lyra2z_hash", Lyra2ZMethods);
+}
+#endif
diff --git a/exlib/lyra2z-py/setup.py b/exlib/lyra2z-py/setup.py
new file mode 100644
index 000000000000..02b79dcdb185
--- /dev/null
+++ b/exlib/lyra2z-py/setup.py
@@ -0,0 +1,19 @@
+from setuptools import setup, Extension
+
+lyra2z_hash_module = Extension('lyra2z_hash',
+ sources = [
+ 'lyra2zmodule.c',
+ 'lyra2z.c',
+ 'Sponge.c',
+ 'Lyra2.c',
+ 'blake.c'],
+ include_dirs=['.'])
+
+setup (name = 'lyra2z_hash',
+ version = '0.1.0',
+ author_email = 'devwarrior.zcoin@gmail.com',
+ author = 'devwarrior',
+ url = 'https://github.com/devwarrior777/lyra2z-py',
+ description = 'Bindings for Lyra2Z proof of work used by Zcoin',
+ ext_modules = [lyra2z_hash_module])
+
diff --git a/exlib/lyra2z-py/sph_blake.h b/exlib/lyra2z-py/sph_blake.h
new file mode 100644
index 000000000000..d8d794399d00
--- /dev/null
+++ b/exlib/lyra2z-py/sph_blake.h
@@ -0,0 +1,327 @@
+/* $Id: sph_blake.h 252 2011-06-07 17:55:14Z tp $ */
+/**
+ * BLAKE interface. BLAKE is a family of functions which differ by their
+ * output size; this implementation defines BLAKE for output sizes 224,
+ * 256, 384 and 512 bits. This implementation conforms to the "third
+ * round" specification.
+ *
+ * ==========================(LICENSE BEGIN)============================
+ *
+ * Copyright (c) 2007-2010 Projet RNRT SAPHIR
+ *
+ * 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.
+ *
+ * ===========================(LICENSE END)=============================
+ *
+ * @file sph_blake.h
+ * @author Thomas Pornin
+ */
+
+#ifndef SPH_BLAKE_H__
+#define SPH_BLAKE_H__
+
+#ifdef __cplusplus
+extern "C"{
+#endif
+
+#include
+#include "sph_types.h"
+
+/**
+ * Output size (in bits) for BLAKE-224.
+ */
+#define SPH_SIZE_blake224 224
+
+/**
+ * Output size (in bits) for BLAKE-256.
+ */
+#define SPH_SIZE_blake256 256
+
+#if SPH_64
+
+/**
+ * Output size (in bits) for BLAKE-384.
+ */
+#define SPH_SIZE_blake384 384
+
+/**
+ * Output size (in bits) for BLAKE-512.
+ */
+#define SPH_SIZE_blake512 512
+
+#endif
+
+/**
+ * This structure is a context for BLAKE-224 and BLAKE-256 computations:
+ * it contains the intermediate values and some data from the last
+ * entered block. Once a BLAKE computation has been performed, the
+ * context can be reused for another computation.
+ *
+ * The contents of this structure are private. A running BLAKE
+ * computation can be cloned by copying the context (e.g. with a simple
+ * memcpy()
).
+ */
+typedef struct {
+#ifndef DOXYGEN_IGNORE
+ unsigned char buf[64]; /* first field, for alignment */
+ size_t ptr;
+ sph_u32 H[8];
+ sph_u32 S[4];
+ sph_u32 T0, T1;
+#endif
+} sph_blake_small_context;
+
+/**
+ * This structure is a context for BLAKE-224 computations. It is
+ * identical to the common sph_blake_small_context
.
+ */
+typedef sph_blake_small_context sph_blake224_context;
+
+/**
+ * This structure is a context for BLAKE-256 computations. It is
+ * identical to the common sph_blake_small_context
.
+ */
+typedef sph_blake_small_context sph_blake256_context;
+
+#if SPH_64
+
+/**
+ * This structure is a context for BLAKE-384 and BLAKE-512 computations:
+ * it contains the intermediate values and some data from the last
+ * entered block. Once a BLAKE computation has been performed, the
+ * context can be reused for another computation.
+ *
+ * The contents of this structure are private. A running BLAKE
+ * computation can be cloned by copying the context (e.g. with a simple
+ * memcpy()
).
+ */
+typedef struct {
+#ifndef DOXYGEN_IGNORE
+ unsigned char buf[128]; /* first field, for alignment */
+ size_t ptr;
+ sph_u64 H[8];
+ sph_u64 S[4];
+ sph_u64 T0, T1;
+#endif
+} sph_blake_big_context;
+
+/**
+ * This structure is a context for BLAKE-384 computations. It is
+ * identical to the common sph_blake_small_context
.
+ */
+typedef sph_blake_big_context sph_blake384_context;
+
+/**
+ * This structure is a context for BLAKE-512 computations. It is
+ * identical to the common sph_blake_small_context
.
+ */
+typedef sph_blake_big_context sph_blake512_context;
+
+#endif
+
+/**
+ * Initialize a BLAKE-224 context. This process performs no memory allocation.
+ *
+ * @param cc the BLAKE-224 context (pointer to a
+ * sph_blake224_context
)
+ */
+void sph_blake224_init(void *cc);
+
+/**
+ * Process some data bytes. It is acceptable that len
is zero
+ * (in which case this function does nothing).
+ *
+ * @param cc the BLAKE-224 context
+ * @param data the input data
+ * @param len the input data length (in bytes)
+ */
+void sph_blake224(void *cc, const void *data, size_t len);
+
+/**
+ * Terminate the current BLAKE-224 computation and output the result into
+ * the provided buffer. The destination buffer must be wide enough to
+ * accomodate the result (28 bytes). The context is automatically
+ * reinitialized.
+ *
+ * @param cc the BLAKE-224 context
+ * @param dst the destination buffer
+ */
+void sph_blake224_close(void *cc, void *dst);
+
+/**
+ * Add a few additional bits (0 to 7) to the current computation, then
+ * terminate it and output the result in the provided buffer, which must
+ * be wide enough to accomodate the result (28 bytes). If bit number i
+ * in ub
has value 2^i, then the extra bits are those
+ * numbered 7 downto 8-n (this is the big-endian convention at the byte
+ * level). The context is automatically reinitialized.
+ *
+ * @param cc the BLAKE-224 context
+ * @param ub the extra bits
+ * @param n the number of extra bits (0 to 7)
+ * @param dst the destination buffer
+ */
+void sph_blake224_addbits_and_close(
+ void *cc, unsigned ub, unsigned n, void *dst);
+
+/**
+ * Initialize a BLAKE-256 context. This process performs no memory allocation.
+ *
+ * @param cc the BLAKE-256 context (pointer to a
+ * sph_blake256_context
)
+ */
+void sph_blake256_init(void *cc);
+
+/**
+ * Process some data bytes. It is acceptable that len
is zero
+ * (in which case this function does nothing).
+ *
+ * @param cc the BLAKE-256 context
+ * @param data the input data
+ * @param len the input data length (in bytes)
+ */
+void sph_blake256(void *cc, const void *data, size_t len);
+
+/**
+ * Terminate the current BLAKE-256 computation and output the result into
+ * the provided buffer. The destination buffer must be wide enough to
+ * accomodate the result (32 bytes). The context is automatically
+ * reinitialized.
+ *
+ * @param cc the BLAKE-256 context
+ * @param dst the destination buffer
+ */
+void sph_blake256_close(void *cc, void *dst);
+
+/**
+ * Add a few additional bits (0 to 7) to the current computation, then
+ * terminate it and output the result in the provided buffer, which must
+ * be wide enough to accomodate the result (32 bytes). If bit number i
+ * in ub
has value 2^i, then the extra bits are those
+ * numbered 7 downto 8-n (this is the big-endian convention at the byte
+ * level). The context is automatically reinitialized.
+ *
+ * @param cc the BLAKE-256 context
+ * @param ub the extra bits
+ * @param n the number of extra bits (0 to 7)
+ * @param dst the destination buffer
+ */
+void sph_blake256_addbits_and_close(
+ void *cc, unsigned ub, unsigned n, void *dst);
+
+#if SPH_64
+
+/**
+ * Initialize a BLAKE-384 context. This process performs no memory allocation.
+ *
+ * @param cc the BLAKE-384 context (pointer to a
+ * sph_blake384_context
)
+ */
+void sph_blake384_init(void *cc);
+
+/**
+ * Process some data bytes. It is acceptable that len
is zero
+ * (in which case this function does nothing).
+ *
+ * @param cc the BLAKE-384 context
+ * @param data the input data
+ * @param len the input data length (in bytes)
+ */
+void sph_blake384(void *cc, const void *data, size_t len);
+
+/**
+ * Terminate the current BLAKE-384 computation and output the result into
+ * the provided buffer. The destination buffer must be wide enough to
+ * accomodate the result (48 bytes). The context is automatically
+ * reinitialized.
+ *
+ * @param cc the BLAKE-384 context
+ * @param dst the destination buffer
+ */
+void sph_blake384_close(void *cc, void *dst);
+
+/**
+ * Add a few additional bits (0 to 7) to the current computation, then
+ * terminate it and output the result in the provided buffer, which must
+ * be wide enough to accomodate the result (48 bytes). If bit number i
+ * in ub
has value 2^i, then the extra bits are those
+ * numbered 7 downto 8-n (this is the big-endian convention at the byte
+ * level). The context is automatically reinitialized.
+ *
+ * @param cc the BLAKE-384 context
+ * @param ub the extra bits
+ * @param n the number of extra bits (0 to 7)
+ * @param dst the destination buffer
+ */
+void sph_blake384_addbits_and_close(
+ void *cc, unsigned ub, unsigned n, void *dst);
+
+/**
+ * Initialize a BLAKE-512 context. This process performs no memory allocation.
+ *
+ * @param cc the BLAKE-512 context (pointer to a
+ * sph_blake512_context
)
+ */
+void sph_blake512_init(void *cc);
+
+/**
+ * Process some data bytes. It is acceptable that len
is zero
+ * (in which case this function does nothing).
+ *
+ * @param cc the BLAKE-512 context
+ * @param data the input data
+ * @param len the input data length (in bytes)
+ */
+void sph_blake512(void *cc, const void *data, size_t len);
+
+/**
+ * Terminate the current BLAKE-512 computation and output the result into
+ * the provided buffer. The destination buffer must be wide enough to
+ * accomodate the result (64 bytes). The context is automatically
+ * reinitialized.
+ *
+ * @param cc the BLAKE-512 context
+ * @param dst the destination buffer
+ */
+void sph_blake512_close(void *cc, void *dst);
+
+/**
+ * Add a few additional bits (0 to 7) to the current computation, then
+ * terminate it and output the result in the provided buffer, which must
+ * be wide enough to accomodate the result (64 bytes). If bit number i
+ * in ub
has value 2^i, then the extra bits are those
+ * numbered 7 downto 8-n (this is the big-endian convention at the byte
+ * level). The context is automatically reinitialized.
+ *
+ * @param cc the BLAKE-512 context
+ * @param ub the extra bits
+ * @param n the number of extra bits (0 to 7)
+ * @param dst the destination buffer
+ */
+void sph_blake512_addbits_and_close(
+ void *cc, unsigned ub, unsigned n, void *dst);
+
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/exlib/lyra2z-py/sph_types.h b/exlib/lyra2z-py/sph_types.h
new file mode 100644
index 000000000000..6c8ecf4b676f
--- /dev/null
+++ b/exlib/lyra2z-py/sph_types.h
@@ -0,0 +1,1986 @@
+/* $Id: sph_types.h 260 2011-07-21 01:02:38Z tp $ */
+/**
+ * Basic type definitions.
+ *
+ * This header file defines the generic integer types that will be used
+ * for the implementation of hash functions; it also contains helper
+ * functions which encode and decode multi-byte integer values, using
+ * either little-endian or big-endian conventions.
+ *
+ * This file contains a compile-time test on the size of a byte
+ * (the unsigned char
C type). If bytes are not octets,
+ * i.e. if they do not have a size of exactly 8 bits, then compilation
+ * is aborted. Architectures where bytes are not octets are relatively
+ * rare, even in the embedded devices market. We forbid non-octet bytes
+ * because there is no clear convention on how octet streams are encoded
+ * on such systems.
+ *
+ * ==========================(LICENSE BEGIN)============================
+ *
+ * Copyright (c) 2007-2010 Projet RNRT SAPHIR
+ *
+ * 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.
+ *
+ * ===========================(LICENSE END)=============================
+ *
+ * @file sph_types.h
+ * @author Thomas Pornin
+ */
+
+#ifndef SPH_TYPES_H__
+#define SPH_TYPES_H__
+
+#include
+
+/*
+ * All our I/O functions are defined over octet streams. We do not know
+ * how to handle input data if bytes are not octets.
+ */
+#if CHAR_BIT != 8
+#error This code requires 8-bit bytes
+#endif
+
+/* ============= BEGIN documentation block for Doxygen ============ */
+
+#ifdef DOXYGEN_IGNORE
+
+/** @mainpage sphlib C code documentation
+ *
+ * @section overview Overview
+ *
+ * sphlib
is a library which contains implementations of
+ * various cryptographic hash functions. These pages have been generated
+ * with doxygen and
+ * document the API for the C implementations.
+ *
+ * The API is described in appropriate header files, which are available
+ * in the "Files" section. Each hash function family has its own header,
+ * whose name begins with "sph_"
and contains the family
+ * name. For instance, the API for the RIPEMD hash functions is available
+ * in the header file sph_ripemd.h
.
+ *
+ * @section principles API structure and conventions
+ *
+ * @subsection io Input/output conventions
+ *
+ * In all generality, hash functions operate over strings of bits.
+ * Individual bits are rarely encountered in C programming or actual
+ * communication protocols; most protocols converge on the ubiquitous
+ * "octet" which is a group of eight bits. Data is thus expressed as a
+ * stream of octets. The C programming language contains the notion of a
+ * "byte", which is a data unit managed under the type "unsigned
+ * char"
. The C standard prescribes that a byte should hold at
+ * least eight bits, but possibly more. Most modern architectures, even
+ * in the embedded world, feature eight-bit bytes, i.e. map bytes to
+ * octets.
+ *
+ * Nevertheless, for some of the implemented hash functions, an extra
+ * API has been added, which allows the input of arbitrary sequences of
+ * bits: when the computation is about to be closed, 1 to 7 extra bits
+ * can be added. The functions for which this API is implemented include
+ * the SHA-2 functions and all SHA-3 candidates.
+ *
+ * sphlib
defines hash function which may hash octet streams,
+ * i.e. streams of bits where the number of bits is a multiple of eight.
+ * The data input functions in the sphlib
API expect data
+ * as anonymous pointers ("const void *"
) with a length
+ * (of type "size_t"
) which gives the input data chunk length
+ * in bytes. A byte is assumed to be an octet; the sph_types.h
+ * header contains a compile-time test which prevents compilation on
+ * architectures where this property is not met.
+ *
+ * The hash function output is also converted into bytes. All currently
+ * implemented hash functions have an output width which is a multiple of
+ * eight, and this is likely to remain true for new designs.
+ *
+ * Most hash functions internally convert input data into 32-bit of 64-bit
+ * words, using either little-endian or big-endian conversion. The hash
+ * output also often consists of such words, which are encoded into output
+ * bytes with a similar endianness convention. Some hash functions have
+ * been only loosely specified on that subject; when necessary,
+ * sphlib
has been tested against published "reference"
+ * implementations in order to use the same conventions.
+ *
+ * @subsection shortname Function short name
+ *
+ * Each implemented hash function has a "short name" which is used
+ * internally to derive the identifiers for the functions and context
+ * structures which the function uses. For instance, MD5 has the short
+ * name "md5"
. Short names are listed in the next section,
+ * for the implemented hash functions. In subsequent sections, the
+ * short name will be assumed to be "XXX"
: replace with the
+ * actual hash function name to get the C identifier.
+ *
+ * Note: some functions within the same family share the same core
+ * elements, such as update function or context structure. Correspondingly,
+ * some of the defined types or functions may actually be macros which
+ * transparently evaluate to another type or function name.
+ *
+ * @subsection context Context structure
+ *
+ * Each implemented hash fonction has its own context structure, available
+ * under the type name "sph_XXX_context"
for the hash function
+ * with short name "XXX"
. This structure holds all needed
+ * state for a running hash computation.
+ *
+ * The contents of these structures are meant to be opaque, and private
+ * to the implementation. However, these contents are specified in the
+ * header files so that application code which uses sphlib
+ * may access the size of those structures.
+ *
+ * The caller is responsible for allocating the context structure,
+ * whether by dynamic allocation (malloc()
or equivalent),
+ * static allocation (a global permanent variable), as an automatic
+ * variable ("on the stack"), or by any other mean which ensures proper
+ * structure alignment. sphlib
code performs no dynamic
+ * allocation by itself.
+ *
+ * The context must be initialized before use, using the
+ * sph_XXX_init()
function. This function sets the context
+ * state to proper initial values for hashing.
+ *
+ * Since all state data is contained within the context structure,
+ * sphlib
is thread-safe and reentrant: several hash
+ * computations may be performed in parallel, provided that they do not
+ * operate on the same context. Moreover, a running computation can be
+ * cloned by copying the context (with a simple memcpy()
):
+ * the context and its clone are then independant and may be updated
+ * with new data and/or closed without interfering with each other.
+ * Similarly, a context structure can be moved in memory at will:
+ * context structures contain no pointer, in particular no pointer to
+ * themselves.
+ *
+ * @subsection dataio Data input
+ *
+ * Hashed data is input with the sph_XXX()
fonction, which
+ * takes as parameters a pointer to the context, a pointer to the data
+ * to hash, and the number of data bytes to hash. The context is updated
+ * with the new data.
+ *
+ * Data can be input in one or several calls, with arbitrary input lengths.
+ * However, it is best, performance wise, to input data by relatively big
+ * chunks (say a few kilobytes), because this allows sphlib
to
+ * optimize things and avoid internal copying.
+ *
+ * When all data has been input, the context can be closed with
+ * sph_XXX_close()
. The hash output is computed and written
+ * into the provided buffer. The caller must take care to provide a
+ * buffer of appropriate length; e.g., when using SHA-1, the output is
+ * a 20-byte word, therefore the output buffer must be at least 20-byte
+ * long.
+ *
+ * For some hash functions, the sph_XXX_addbits_and_close()
+ * function can be used instead of sph_XXX_close()
. This
+ * function can take a few extra bits to be added at
+ * the end of the input message. This allows hashing messages with a
+ * bit length which is not a multiple of 8. The extra bits are provided
+ * as an unsigned integer value, and a bit count. The bit count must be
+ * between 0 and 7, inclusive. The extra bits are provided as bits 7 to
+ * 0 (bits of numerical value 128, 64, 32... downto 0), in that order.
+ * For instance, to add three bits of value 1, 1 and 0, the unsigned
+ * integer will have value 192 (1*128 + 1*64 + 0*32) and the bit count
+ * will be 3.
+ *
+ * The SPH_SIZE_XXX
macro is defined for each hash function;
+ * it evaluates to the function output size, expressed in bits. For instance,
+ * SPH_SIZE_sha1
evaluates to 160
.
+ *
+ * When closed, the context is automatically reinitialized and can be
+ * immediately used for another computation. It is not necessary to call
+ * sph_XXX_init()
after a close. Note that
+ * sph_XXX_init()
can still be called to "reset" a context,
+ * i.e. forget previously input data, and get back to the initial state.
+ *
+ * @subsection alignment Data alignment
+ *
+ * "Alignment" is a property of data, which is said to be "properly
+ * aligned" when its emplacement in memory is such that the data can
+ * be optimally read by full words. This depends on the type of access;
+ * basically, some hash functions will read data by 32-bit or 64-bit
+ * words. sphlib
does not mandate such alignment for input
+ * data, but using aligned data can substantially improve performance.
+ *
+ * As a rule, it is best to input data by chunks whose length (in bytes)
+ * is a multiple of eight, and which begins at "generally aligned"
+ * addresses, such as the base address returned by a call to
+ * malloc()
.
+ *
+ * @section functions Implemented functions
+ *
+ * We give here the list of implemented functions. They are grouped by
+ * family; to each family corresponds a specific header file. Each
+ * individual function has its associated "short name". Please refer to
+ * the documentation for that header file to get details on the hash
+ * function denomination and provenance.
+ *
+ * Note: the functions marked with a '(64)' in the list below are
+ * available only if the C compiler provides an integer type of length
+ * 64 bits or more. Such a type is mandatory in the latest C standard
+ * (ISO 9899:1999, aka "C99") and is present in several older compilers
+ * as well, so chances are that such a type is available.
+ *
+ * - HAVAL family: file sph_haval.h
+ * - HAVAL-128/3 (128-bit, 3 passes): short name: haval128_3
+ * - HAVAL-128/4 (128-bit, 4 passes): short name: haval128_4
+ * - HAVAL-128/5 (128-bit, 5 passes): short name: haval128_5
+ * - HAVAL-160/3 (160-bit, 3 passes): short name: haval160_3
+ * - HAVAL-160/4 (160-bit, 4 passes): short name: haval160_4
+ * - HAVAL-160/5 (160-bit, 5 passes): short name: haval160_5
+ * - HAVAL-192/3 (192-bit, 3 passes): short name: haval192_3
+ * - HAVAL-192/4 (192-bit, 4 passes): short name: haval192_4
+ * - HAVAL-192/5 (192-bit, 5 passes): short name: haval192_5
+ * - HAVAL-224/3 (224-bit, 3 passes): short name: haval224_3
+ * - HAVAL-224/4 (224-bit, 4 passes): short name: haval224_4
+ * - HAVAL-224/5 (224-bit, 5 passes): short name: haval224_5
+ * - HAVAL-256/3 (256-bit, 3 passes): short name: haval256_3
+ * - HAVAL-256/4 (256-bit, 4 passes): short name: haval256_4
+ * - HAVAL-256/5 (256-bit, 5 passes): short name: haval256_5
+ * - MD2: file sph_md2.h
, short name: md2
+ * - MD4: file sph_md4.h
, short name: md4
+ * - MD5: file sph_md5.h
, short name: md5
+ * - PANAMA: file sph_panama.h
, short name: panama
+ * - RadioGatun family: file sph_radiogatun.h
+ * - RadioGatun[32]: short name: radiogatun32
+ * - RadioGatun[64]: short name: radiogatun64
(64)
+ * - RIPEMD family: file sph_ripemd.h
+ * - RIPEMD: short name: ripemd
+ * - RIPEMD-128: short name: ripemd128
+ * - RIPEMD-160: short name: ripemd160
+ * - SHA-0: file sph_sha0.h
, short name: sha0
+ * - SHA-1: file sph_sha1.h
, short name: sha1
+ * - SHA-2 family, 32-bit hashes: file sph_sha2.h
+ * - SHA-224: short name: sha224
+ * - SHA-256: short name: sha256
+ * - SHA-384: short name: sha384
(64)
+ * - SHA-512: short name: sha512
(64)
+ * - Tiger family: file sph_tiger.h
+ * - Tiger: short name: tiger
(64)
+ * - Tiger2: short name: tiger2
(64)
+ * - WHIRLPOOL family: file sph_whirlpool.h
+ * - WHIRLPOOL-0: short name: whirlpool0
(64)
+ * - WHIRLPOOL-1: short name: whirlpool1
(64)
+ * - WHIRLPOOL: short name: whirlpool
(64)
+ *
+ * The fourteen second-round SHA-3 candidates are also implemented;
+ * when applicable, the implementations follow the "final" specifications
+ * as published for the third round of the SHA-3 competition (BLAKE,
+ * Groestl, JH, Keccak and Skein have been tweaked for third round).
+ *
+ * - BLAKE family: file sph_blake.h
+ * - BLAKE-224: short name: blake224
+ * - BLAKE-256: short name: blake256
+ * - BLAKE-384: short name: blake384
+ * - BLAKE-512: short name: blake512
+ * - BMW (Blue Midnight Wish) family: file sph_bmw.h
+ * - BMW-224: short name: bmw224
+ * - BMW-256: short name: bmw256
+ * - BMW-384: short name: bmw384
(64)
+ * - BMW-512: short name: bmw512
(64)
+ * - CubeHash family: file sph_cubehash.h
(specified as
+ * CubeHash16/32 in the CubeHash specification)
+ * - CubeHash-224: short name: cubehash224
+ * - CubeHash-256: short name: cubehash256
+ * - CubeHash-384: short name: cubehash384
+ * - CubeHash-512: short name: cubehash512
+ * - ECHO family: file sph_echo.h
+ * - ECHO-224: short name: echo224
+ * - ECHO-256: short name: echo256
+ * - ECHO-384: short name: echo384
+ * - ECHO-512: short name: echo512
+ * - Fugue family: file sph_fugue.h
+ * - Fugue-224: short name: fugue224
+ * - Fugue-256: short name: fugue256
+ * - Fugue-384: short name: fugue384
+ * - Fugue-512: short name: fugue512
+ * - Groestl family: file sph_groestl.h
+ * - Groestl-224: short name: groestl224
+ * - Groestl-256: short name: groestl256
+ * - Groestl-384: short name: groestl384
+ * - Groestl-512: short name: groestl512
+ * - Hamsi family: file sph_hamsi.h
+ * - Hamsi-224: short name: hamsi224
+ * - Hamsi-256: short name: hamsi256
+ * - Hamsi-384: short name: hamsi384
+ * - Hamsi-512: short name: hamsi512
+ * - JH family: file sph_jh.h
+ * - JH-224: short name: jh224
+ * - JH-256: short name: jh256
+ * - JH-384: short name: jh384
+ * - JH-512: short name: jh512
+ * - Keccak family: file sph_keccak.h
+ * - Keccak-224: short name: keccak224
+ * - Keccak-256: short name: keccak256
+ * - Keccak-384: short name: keccak384
+ * - Keccak-512: short name: keccak512
+ * - Luffa family: file sph_luffa.h
+ * - Luffa-224: short name: luffa224
+ * - Luffa-256: short name: luffa256
+ * - Luffa-384: short name: luffa384
+ * - Luffa-512: short name: luffa512
+ * - Shabal family: file sph_shabal.h
+ * - Shabal-192: short name: shabal192
+ * - Shabal-224: short name: shabal224
+ * - Shabal-256: short name: shabal256
+ * - Shabal-384: short name: shabal384
+ * - Shabal-512: short name: shabal512
+ * - SHAvite-3 family: file sph_shavite.h
+ * - SHAvite-224 (nominally "SHAvite-3 with 224-bit output"):
+ * short name: shabal224
+ * - SHAvite-256 (nominally "SHAvite-3 with 256-bit output"):
+ * short name: shabal256
+ * - SHAvite-384 (nominally "SHAvite-3 with 384-bit output"):
+ * short name: shabal384
+ * - SHAvite-512 (nominally "SHAvite-3 with 512-bit output"):
+ * short name: shabal512
+ * - SIMD family: file sph_simd.h
+ * - SIMD-224: short name: simd224
+ * - SIMD-256: short name: simd256
+ * - SIMD-384: short name: simd384
+ * - SIMD-512: short name: simd512
+ * - Skein family: file sph_skein.h
+ * - Skein-224 (nominally specified as Skein-512-224): short name:
+ * skein224
(64)
+ * - Skein-256 (nominally specified as Skein-512-256): short name:
+ * skein256
(64)
+ * - Skein-384 (nominally specified as Skein-512-384): short name:
+ * skein384
(64)
+ * - Skein-512 (nominally specified as Skein-512-512): short name:
+ * skein512
(64)
+ *
+ * For the second-round SHA-3 candidates, the functions are as specified
+ * for round 2, i.e. with the "tweaks" that some candidates added
+ * between round 1 and round 2. Also, some of the submitted packages for
+ * round 2 contained errors, in the specification, reference code, or
+ * both. sphlib
implements the corrected versions.
+ */
+
+/** @hideinitializer
+ * Unsigned integer type whose length is at least 32 bits; on most
+ * architectures, it will have a width of exactly 32 bits. Unsigned C
+ * types implement arithmetics modulo a power of 2; use the
+ * SPH_T32()
macro to ensure that the value is truncated
+ * to exactly 32 bits. Unless otherwise specified, all macros and
+ * functions which accept sph_u32
values assume that these
+ * values fit on 32 bits, i.e. do not exceed 2^32-1, even on architectures
+ * where sph_u32
is larger than that.
+ */
+typedef __arch_dependant__ sph_u32;
+
+/** @hideinitializer
+ * Signed integer type corresponding to sph_u32
; it has
+ * width 32 bits or more.
+ */
+typedef __arch_dependant__ sph_s32;
+
+/** @hideinitializer
+ * Unsigned integer type whose length is at least 64 bits; on most
+ * architectures which feature such a type, it will have a width of
+ * exactly 64 bits. C99-compliant platform will have this type; it
+ * is also defined when the GNU compiler (gcc) is used, and on
+ * platforms where unsigned long
is large enough. If this
+ * type is not available, then some hash functions which depends on
+ * a 64-bit type will not be available (most notably SHA-384, SHA-512,
+ * Tiger and WHIRLPOOL).
+ */
+typedef __arch_dependant__ sph_u64;
+
+/** @hideinitializer
+ * Signed integer type corresponding to sph_u64
; it has
+ * width 64 bits or more.
+ */
+typedef __arch_dependant__ sph_s64;
+
+/**
+ * This macro expands the token x
into a suitable
+ * constant expression of type sph_u32
. Depending on
+ * how this type is defined, a suffix such as UL
may
+ * be appended to the argument.
+ *
+ * @param x the token to expand into a suitable constant expression
+ */
+#define SPH_C32(x)
+
+/**
+ * Truncate a 32-bit value to exactly 32 bits. On most systems, this is
+ * a no-op, recognized as such by the compiler.
+ *
+ * @param x the value to truncate (of type sph_u32
)
+ */
+#define SPH_T32(x)
+
+/**
+ * Rotate a 32-bit value by a number of bits to the left. The rotate
+ * count must reside between 1 and 31. This macro assumes that its
+ * first argument fits in 32 bits (no extra bit allowed on machines where
+ * sph_u32
is wider); both arguments may be evaluated
+ * several times.
+ *
+ * @param x the value to rotate (of type sph_u32
)
+ * @param n the rotation count (between 1 and 31, inclusive)
+ */
+#define SPH_ROTL32(x, n)
+
+/**
+ * Rotate a 32-bit value by a number of bits to the left. The rotate
+ * count must reside between 1 and 31. This macro assumes that its
+ * first argument fits in 32 bits (no extra bit allowed on machines where
+ * sph_u32
is wider); both arguments may be evaluated
+ * several times.
+ *
+ * @param x the value to rotate (of type sph_u32
)
+ * @param n the rotation count (between 1 and 31, inclusive)
+ */
+#define SPH_ROTR32(x, n)
+
+/**
+ * This macro is defined on systems for which a 64-bit type has been
+ * detected, and is used for sph_u64
.
+ */
+#define SPH_64
+
+/**
+ * This macro is defined on systems for the "native" integer size is
+ * 64 bits (64-bit values fit in one register).
+ */
+#define SPH_64_TRUE
+
+/**
+ * This macro expands the token x
into a suitable
+ * constant expression of type sph_u64
. Depending on
+ * how this type is defined, a suffix such as ULL
may
+ * be appended to the argument. This macro is defined only if a
+ * 64-bit type was detected and used for sph_u64
.
+ *
+ * @param x the token to expand into a suitable constant expression
+ */
+#define SPH_C64(x)
+
+/**
+ * Truncate a 64-bit value to exactly 64 bits. On most systems, this is
+ * a no-op, recognized as such by the compiler. This macro is defined only
+ * if a 64-bit type was detected and used for sph_u64
.
+ *
+ * @param x the value to truncate (of type sph_u64
)
+ */
+#define SPH_T64(x)
+
+/**
+ * Rotate a 64-bit value by a number of bits to the left. The rotate
+ * count must reside between 1 and 63. This macro assumes that its
+ * first argument fits in 64 bits (no extra bit allowed on machines where
+ * sph_u64
is wider); both arguments may be evaluated
+ * several times. This macro is defined only if a 64-bit type was detected
+ * and used for sph_u64
.
+ *
+ * @param x the value to rotate (of type sph_u64
)
+ * @param n the rotation count (between 1 and 63, inclusive)
+ */
+#define SPH_ROTL64(x, n)
+
+/**
+ * Rotate a 64-bit value by a number of bits to the left. The rotate
+ * count must reside between 1 and 63. This macro assumes that its
+ * first argument fits in 64 bits (no extra bit allowed on machines where
+ * sph_u64
is wider); both arguments may be evaluated
+ * several times. This macro is defined only if a 64-bit type was detected
+ * and used for sph_u64
.
+ *
+ * @param x the value to rotate (of type sph_u64
)
+ * @param n the rotation count (between 1 and 63, inclusive)
+ */
+#define SPH_ROTR64(x, n)
+
+/**
+ * This macro evaluates to inline
or an equivalent construction,
+ * if available on the compilation platform, or to nothing otherwise. This
+ * is used to declare inline functions, for which the compiler should
+ * endeavour to include the code directly in the caller. Inline functions
+ * are typically defined in header files as replacement for macros.
+ */
+#define SPH_INLINE
+
+/**
+ * This macro is defined if the platform has been detected as using
+ * little-endian convention. This implies that the sph_u32
+ * type (and the sph_u64
type also, if it is defined) has
+ * an exact width (i.e. exactly 32-bit, respectively 64-bit).
+ */
+#define SPH_LITTLE_ENDIAN
+
+/**
+ * This macro is defined if the platform has been detected as using
+ * big-endian convention. This implies that the sph_u32
+ * type (and the sph_u64
type also, if it is defined) has
+ * an exact width (i.e. exactly 32-bit, respectively 64-bit).
+ */
+#define SPH_BIG_ENDIAN
+
+/**
+ * This macro is defined if 32-bit words (and 64-bit words, if defined)
+ * can be read from and written to memory efficiently in little-endian
+ * convention. This is the case for little-endian platforms, and also
+ * for the big-endian platforms which have special little-endian access
+ * opcodes (e.g. Ultrasparc).
+ */
+#define SPH_LITTLE_FAST
+
+/**
+ * This macro is defined if 32-bit words (and 64-bit words, if defined)
+ * can be read from and written to memory efficiently in big-endian
+ * convention. This is the case for little-endian platforms, and also
+ * for the little-endian platforms which have special big-endian access
+ * opcodes.
+ */
+#define SPH_BIG_FAST
+
+/**
+ * On some platforms, this macro is defined to an unsigned integer type
+ * into which pointer values may be cast. The resulting value can then
+ * be tested for being a multiple of 2, 4 or 8, indicating an aligned
+ * pointer for, respectively, 16-bit, 32-bit or 64-bit memory accesses.
+ */
+#define SPH_UPTR
+
+/**
+ * When defined, this macro indicates that unaligned memory accesses
+ * are possible with only a minor penalty, and thus should be prefered
+ * over strategies which first copy data to an aligned buffer.
+ */
+#define SPH_UNALIGNED
+
+/**
+ * Byte-swap a 32-bit word (i.e. 0x12345678
becomes
+ * 0x78563412
). This is an inline function which resorts
+ * to inline assembly on some platforms, for better performance.
+ *
+ * @param x the 32-bit value to byte-swap
+ * @return the byte-swapped value
+ */
+static inline sph_u32 sph_bswap32(sph_u32 x);
+
+/**
+ * Byte-swap a 64-bit word. This is an inline function which resorts
+ * to inline assembly on some platforms, for better performance. This
+ * function is defined only if a suitable 64-bit type was found for
+ * sph_u64
+ *
+ * @param x the 64-bit value to byte-swap
+ * @return the byte-swapped value
+ */
+static inline sph_u64 sph_bswap64(sph_u64 x);
+
+/**
+ * Decode a 16-bit unsigned value from memory, in little-endian convention
+ * (least significant byte comes first).
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline unsigned sph_dec16le(const void *src);
+
+/**
+ * Encode a 16-bit unsigned value into memory, in little-endian convention
+ * (least significant byte comes first).
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc16le(void *dst, unsigned val);
+
+/**
+ * Decode a 16-bit unsigned value from memory, in big-endian convention
+ * (most significant byte comes first).
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline unsigned sph_dec16be(const void *src);
+
+/**
+ * Encode a 16-bit unsigned value into memory, in big-endian convention
+ * (most significant byte comes first).
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc16be(void *dst, unsigned val);
+
+/**
+ * Decode a 32-bit unsigned value from memory, in little-endian convention
+ * (least significant byte comes first).
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u32 sph_dec32le(const void *src);
+
+/**
+ * Decode a 32-bit unsigned value from memory, in little-endian convention
+ * (least significant byte comes first). This function assumes that the
+ * source address is suitably aligned for a direct access, if the platform
+ * supports such things; it can thus be marginally faster than the generic
+ * sph_dec32le()
function.
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u32 sph_dec32le_aligned(const void *src);
+
+/**
+ * Encode a 32-bit unsigned value into memory, in little-endian convention
+ * (least significant byte comes first).
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc32le(void *dst, sph_u32 val);
+
+/**
+ * Encode a 32-bit unsigned value into memory, in little-endian convention
+ * (least significant byte comes first). This function assumes that the
+ * destination address is suitably aligned for a direct access, if the
+ * platform supports such things; it can thus be marginally faster than
+ * the generic sph_enc32le()
function.
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc32le_aligned(void *dst, sph_u32 val);
+
+/**
+ * Decode a 32-bit unsigned value from memory, in big-endian convention
+ * (most significant byte comes first).
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u32 sph_dec32be(const void *src);
+
+/**
+ * Decode a 32-bit unsigned value from memory, in big-endian convention
+ * (most significant byte comes first). This function assumes that the
+ * source address is suitably aligned for a direct access, if the platform
+ * supports such things; it can thus be marginally faster than the generic
+ * sph_dec32be()
function.
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u32 sph_dec32be_aligned(const void *src);
+
+/**
+ * Encode a 32-bit unsigned value into memory, in big-endian convention
+ * (most significant byte comes first).
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc32be(void *dst, sph_u32 val);
+
+/**
+ * Encode a 32-bit unsigned value into memory, in big-endian convention
+ * (most significant byte comes first). This function assumes that the
+ * destination address is suitably aligned for a direct access, if the
+ * platform supports such things; it can thus be marginally faster than
+ * the generic sph_enc32be()
function.
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc32be_aligned(void *dst, sph_u32 val);
+
+/**
+ * Decode a 64-bit unsigned value from memory, in little-endian convention
+ * (least significant byte comes first). This function is defined only
+ * if a suitable 64-bit type was detected and used for sph_u64
.
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u64 sph_dec64le(const void *src);
+
+/**
+ * Decode a 64-bit unsigned value from memory, in little-endian convention
+ * (least significant byte comes first). This function assumes that the
+ * source address is suitably aligned for a direct access, if the platform
+ * supports such things; it can thus be marginally faster than the generic
+ * sph_dec64le()
function. This function is defined only
+ * if a suitable 64-bit type was detected and used for sph_u64
.
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u64 sph_dec64le_aligned(const void *src);
+
+/**
+ * Encode a 64-bit unsigned value into memory, in little-endian convention
+ * (least significant byte comes first). This function is defined only
+ * if a suitable 64-bit type was detected and used for sph_u64
.
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc64le(void *dst, sph_u64 val);
+
+/**
+ * Encode a 64-bit unsigned value into memory, in little-endian convention
+ * (least significant byte comes first). This function assumes that the
+ * destination address is suitably aligned for a direct access, if the
+ * platform supports such things; it can thus be marginally faster than
+ * the generic sph_enc64le()
function. This function is defined
+ * only if a suitable 64-bit type was detected and used for
+ * sph_u64
.
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc64le_aligned(void *dst, sph_u64 val);
+
+/**
+ * Decode a 64-bit unsigned value from memory, in big-endian convention
+ * (most significant byte comes first). This function is defined only
+ * if a suitable 64-bit type was detected and used for sph_u64
.
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u64 sph_dec64be(const void *src);
+
+/**
+ * Decode a 64-bit unsigned value from memory, in big-endian convention
+ * (most significant byte comes first). This function assumes that the
+ * source address is suitably aligned for a direct access, if the platform
+ * supports such things; it can thus be marginally faster than the generic
+ * sph_dec64be()
function. This function is defined only
+ * if a suitable 64-bit type was detected and used for sph_u64
.
+ *
+ * @param src the source address
+ * @return the decoded value
+ */
+static inline sph_u64 sph_dec64be_aligned(const void *src);
+
+/**
+ * Encode a 64-bit unsigned value into memory, in big-endian convention
+ * (most significant byte comes first). This function is defined only
+ * if a suitable 64-bit type was detected and used for sph_u64
.
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc64be(void *dst, sph_u64 val);
+
+/**
+ * Encode a 64-bit unsigned value into memory, in big-endian convention
+ * (most significant byte comes first). This function assumes that the
+ * destination address is suitably aligned for a direct access, if the
+ * platform supports such things; it can thus be marginally faster than
+ * the generic sph_enc64be()
function. This function is defined
+ * only if a suitable 64-bit type was detected and used for
+ * sph_u64
.
+ *
+ * @param dst the destination buffer
+ * @param val the value to encode
+ */
+static inline void sph_enc64be_aligned(void *dst, sph_u64 val);
+
+#endif
+
+/* ============== END documentation block for Doxygen ============= */
+
+#ifndef DOXYGEN_IGNORE
+
+/*
+ * We want to define the types "sph_u32" and "sph_u64" which hold
+ * unsigned values of at least, respectively, 32 and 64 bits. These
+ * tests should select appropriate types for most platforms. The
+ * macro "SPH_64" is defined if the 64-bit is supported.
+ */
+
+#undef SPH_64
+#undef SPH_64_TRUE
+
+#if defined __STDC__ && __STDC_VERSION__ >= 199901L
+
+/*
+ * On C99 implementations, we can use to get an exact 64-bit
+ * type, if any, or otherwise use a wider type (which must exist, for
+ * C99 conformance).
+ */
+
+#include
+
+#ifdef UINT32_MAX
+typedef uint32_t sph_u32;
+typedef int32_t sph_s32;
+#else
+typedef uint_fast32_t sph_u32;
+typedef int_fast32_t sph_s32;
+#endif
+#if !SPH_NO_64
+#ifdef UINT64_MAX
+typedef uint64_t sph_u64;
+typedef int64_t sph_s64;
+#else
+typedef uint_fast64_t sph_u64;
+typedef int_fast64_t sph_s64;
+#endif
+#endif
+
+#define SPH_C32(x) ((sph_u32)(x))
+#if !SPH_NO_64
+#define SPH_C64(x) ((sph_u64)(x))
+#define SPH_64 1
+#endif
+
+#else
+
+/*
+ * On non-C99 systems, we use "unsigned int" if it is wide enough,
+ * "unsigned long" otherwise. This supports all "reasonable" architectures.
+ * We have to be cautious: pre-C99 preprocessors handle constants
+ * differently in '#if' expressions. Hence the shifts to test UINT_MAX.
+ */
+
+#if ((UINT_MAX >> 11) >> 11) >= 0x3FF
+
+typedef unsigned int sph_u32;
+typedef int sph_s32;
+
+#define SPH_C32(x) ((sph_u32)(x ## U))
+
+#else
+
+typedef unsigned long sph_u32;
+typedef long sph_s32;
+
+#define SPH_C32(x) ((sph_u32)(x ## UL))
+
+#endif
+
+#if !SPH_NO_64
+
+/*
+ * We want a 64-bit type. We use "unsigned long" if it is wide enough (as
+ * is common on 64-bit architectures such as AMD64, Alpha or Sparcv9),
+ * "unsigned long long" otherwise, if available. We use ULLONG_MAX to
+ * test whether "unsigned long long" is available; we also know that
+ * gcc features this type, even if the libc header do not know it.
+ */
+
+#if ((ULONG_MAX >> 31) >> 31) >= 3
+
+typedef unsigned long sph_u64;
+typedef long sph_s64;
+
+#define SPH_C64(x) ((sph_u64)(x ## UL))
+
+#define SPH_64 1
+
+#elif ((ULLONG_MAX >> 31) >> 31) >= 3 || defined __GNUC__
+
+typedef unsigned long long sph_u64;
+typedef long long sph_s64;
+
+#define SPH_C64(x) ((sph_u64)(x ## ULL))
+
+#define SPH_64 1
+
+#else
+
+/*
+ * No 64-bit type...
+ */
+
+#endif
+
+#endif
+
+#endif
+
+/*
+ * If the "unsigned long" type has length 64 bits or more, then this is
+ * a "true" 64-bit architectures. This is also true with Visual C on
+ * amd64, even though the "long" type is limited to 32 bits.
+ */
+#if SPH_64 && (((ULONG_MAX >> 31) >> 31) >= 3 || defined _M_X64)
+#define SPH_64_TRUE 1
+#endif
+
+/*
+ * Implementation note: some processors have specific opcodes to perform
+ * a rotation. Recent versions of gcc recognize the expression above and
+ * use the relevant opcodes, when appropriate.
+ */
+
+#define SPH_T32(x) ((x) & SPH_C32(0xFFFFFFFF))
+#ifdef _MSC_VER
+#define SPH_ROTL32(x, n) _rotl(x, n)
+#define SPH_ROTR32(x, n) _rotr(x, n)
+#else
+#define SPH_ROTL32(x, n) SPH_T32(((x) << (n)) | ((x) >> (32 - (n))))
+#define SPH_ROTR32(x, n) SPH_ROTL32(x, (32 - (n)))
+#endif
+
+#if SPH_64
+
+#define SPH_T64(x) ((x) & SPH_C64(0xFFFFFFFFFFFFFFFF))
+#ifdef _MSC_VER
+#define SPH_ROTL64(x, n) _rotl64(x, n)
+#define SPH_ROTR64(x, n) _rotr64(x, n)
+#else
+#define SPH_ROTL64(x, n) SPH_T64(((x) << (n)) | ((x) >> (64 - (n))))
+#define SPH_ROTR64(x, n) SPH_ROTL64(x, (64 - (n)))
+#endif
+
+#endif
+
+#ifndef DOXYGEN_IGNORE
+/*
+ * Define SPH_INLINE to be an "inline" qualifier, if available. We define
+ * some small macro-like functions which benefit greatly from being inlined.
+ */
+#if (defined __STDC__ && __STDC_VERSION__ >= 199901L) || defined __GNUC__
+#define SPH_INLINE inline
+#elif defined _MSC_VER
+#define SPH_INLINE __inline
+#else
+#define SPH_INLINE
+#endif
+#endif
+
+/*
+ * We define some macros which qualify the architecture. These macros
+ * may be explicit set externally (e.g. as compiler parameters). The
+ * code below sets those macros if they are not already defined.
+ *
+ * Most macros are boolean, thus evaluate to either zero or non-zero.
+ * The SPH_UPTR macro is special, in that it evaluates to a C type,
+ * or is not defined.
+ *
+ * SPH_UPTR if defined: unsigned type to cast pointers into
+ *
+ * SPH_UNALIGNED non-zero if unaligned accesses are efficient
+ * SPH_LITTLE_ENDIAN non-zero if architecture is known to be little-endian
+ * SPH_BIG_ENDIAN non-zero if architecture is known to be big-endian
+ * SPH_LITTLE_FAST non-zero if little-endian decoding is fast
+ * SPH_BIG_FAST non-zero if big-endian decoding is fast
+ *
+ * If SPH_UPTR is defined, then encoding and decoding of 32-bit and 64-bit
+ * values will try to be "smart". Either SPH_LITTLE_ENDIAN or SPH_BIG_ENDIAN
+ * _must_ be non-zero in those situations. The 32-bit and 64-bit types
+ * _must_ also have an exact width.
+ *
+ * SPH_SPARCV9_GCC_32 UltraSPARC-compatible with gcc, 32-bit mode
+ * SPH_SPARCV9_GCC_64 UltraSPARC-compatible with gcc, 64-bit mode
+ * SPH_SPARCV9_GCC UltraSPARC-compatible with gcc
+ * SPH_I386_GCC x86-compatible (32-bit) with gcc
+ * SPH_I386_MSVC x86-compatible (32-bit) with Microsoft Visual C
+ * SPH_AMD64_GCC x86-compatible (64-bit) with gcc
+ * SPH_AMD64_MSVC x86-compatible (64-bit) with Microsoft Visual C
+ * SPH_PPC32_GCC PowerPC, 32-bit, with gcc
+ * SPH_PPC64_GCC PowerPC, 64-bit, with gcc
+ *
+ * TODO: enhance automatic detection, for more architectures and compilers.
+ * Endianness is the most important. SPH_UNALIGNED and SPH_UPTR help with
+ * some very fast functions (e.g. MD4) when using unaligned input data.
+ * The CPU-specific-with-GCC macros are useful only for inline assembly,
+ * normally restrained to this header file.
+ */
+
+/*
+ * 32-bit x86, aka "i386 compatible".
+ */
+#if defined __i386__ || defined _M_IX86
+
+#define SPH_DETECT_UNALIGNED 1
+#define SPH_DETECT_LITTLE_ENDIAN 1
+#define SPH_DETECT_UPTR sph_u32
+#ifdef __GNUC__
+#define SPH_DETECT_I386_GCC 1
+#endif
+#ifdef _MSC_VER
+#define SPH_DETECT_I386_MSVC 1
+#endif
+
+/*
+ * 64-bit x86, hereafter known as "amd64".
+ */
+#elif defined __x86_64 || defined _M_X64
+
+#define SPH_DETECT_UNALIGNED 1
+#define SPH_DETECT_LITTLE_ENDIAN 1
+#define SPH_DETECT_UPTR sph_u64
+#ifdef __GNUC__
+#define SPH_DETECT_AMD64_GCC 1
+#endif
+#ifdef _MSC_VER
+#define SPH_DETECT_AMD64_MSVC 1
+#endif
+
+/*
+ * 64-bit Sparc architecture (implies v9).
+ */
+#elif ((defined __sparc__ || defined __sparc) && defined __arch64__) \
+ || defined __sparcv9
+
+#define SPH_DETECT_BIG_ENDIAN 1
+#define SPH_DETECT_UPTR sph_u64
+#ifdef __GNUC__
+#define SPH_DETECT_SPARCV9_GCC_64 1
+#define SPH_DETECT_LITTLE_FAST 1
+#endif
+
+/*
+ * 32-bit Sparc.
+ */
+#elif (defined __sparc__ || defined __sparc) \
+ && !(defined __sparcv9 || defined __arch64__)
+
+#define SPH_DETECT_BIG_ENDIAN 1
+#define SPH_DETECT_UPTR sph_u32
+#if defined __GNUC__ && defined __sparc_v9__
+#define SPH_DETECT_SPARCV9_GCC_32 1
+#define SPH_DETECT_LITTLE_FAST 1
+#endif
+
+/*
+ * ARM, little-endian.
+ */
+#elif defined __arm__ && __ARMEL__
+
+#define SPH_DETECT_LITTLE_ENDIAN 1
+
+/*
+ * MIPS, little-endian.
+ */
+#elif MIPSEL || _MIPSEL || __MIPSEL || __MIPSEL__
+
+#define SPH_DETECT_LITTLE_ENDIAN 1
+
+/*
+ * MIPS, big-endian.
+ */
+#elif MIPSEB || _MIPSEB || __MIPSEB || __MIPSEB__
+
+#define SPH_DETECT_BIG_ENDIAN 1
+
+/*
+ * PowerPC.
+ */
+#elif defined __powerpc__ || defined __POWERPC__ || defined __ppc__ \
+ || defined _ARCH_PPC
+
+/*
+ * Note: we do not declare cross-endian access to be "fast": even if
+ * using inline assembly, implementation should still assume that
+ * keeping the decoded word in a temporary is faster than decoding
+ * it again.
+ */
+#if defined __GNUC__
+#if SPH_64_TRUE
+#define SPH_DETECT_PPC64_GCC 1
+#else
+#define SPH_DETECT_PPC32_GCC 1
+#endif
+#endif
+
+#if defined __BIG_ENDIAN__ || defined _BIG_ENDIAN
+#define SPH_DETECT_BIG_ENDIAN 1
+#elif defined __LITTLE_ENDIAN__ || defined _LITTLE_ENDIAN
+#define SPH_DETECT_LITTLE_ENDIAN 1
+#endif
+
+/*
+ * Itanium, 64-bit.
+ */
+#elif defined __ia64 || defined __ia64__ \
+ || defined __itanium__ || defined _M_IA64
+
+#if defined __BIG_ENDIAN__ || defined _BIG_ENDIAN
+#define SPH_DETECT_BIG_ENDIAN 1
+#else
+#define SPH_DETECT_LITTLE_ENDIAN 1
+#endif
+#if defined __LP64__ || defined _LP64
+#define SPH_DETECT_UPTR sph_u64
+#else
+#define SPH_DETECT_UPTR sph_u32
+#endif
+
+#endif
+
+#if defined SPH_DETECT_SPARCV9_GCC_32 || defined SPH_DETECT_SPARCV9_GCC_64
+#define SPH_DETECT_SPARCV9_GCC 1
+#endif
+
+#if defined SPH_DETECT_UNALIGNED && !defined SPH_UNALIGNED
+#define SPH_UNALIGNED SPH_DETECT_UNALIGNED
+#endif
+#if defined SPH_DETECT_UPTR && !defined SPH_UPTR
+#define SPH_UPTR SPH_DETECT_UPTR
+#endif
+#if defined SPH_DETECT_LITTLE_ENDIAN && !defined SPH_LITTLE_ENDIAN
+#define SPH_LITTLE_ENDIAN SPH_DETECT_LITTLE_ENDIAN
+#endif
+#if defined SPH_DETECT_BIG_ENDIAN && !defined SPH_BIG_ENDIAN
+#define SPH_BIG_ENDIAN SPH_DETECT_BIG_ENDIAN
+#endif
+#if defined SPH_DETECT_LITTLE_FAST && !defined SPH_LITTLE_FAST
+#define SPH_LITTLE_FAST SPH_DETECT_LITTLE_FAST
+#endif
+#if defined SPH_DETECT_BIG_FAST && !defined SPH_BIG_FAST
+#define SPH_BIG_FAST SPH_DETECT_BIG_FAST
+#endif
+#if defined SPH_DETECT_SPARCV9_GCC_32 && !defined SPH_SPARCV9_GCC_32
+#define SPH_SPARCV9_GCC_32 SPH_DETECT_SPARCV9_GCC_32
+#endif
+#if defined SPH_DETECT_SPARCV9_GCC_64 && !defined SPH_SPARCV9_GCC_64
+#define SPH_SPARCV9_GCC_64 SPH_DETECT_SPARCV9_GCC_64
+#endif
+#if defined SPH_DETECT_SPARCV9_GCC && !defined SPH_SPARCV9_GCC
+#define SPH_SPARCV9_GCC SPH_DETECT_SPARCV9_GCC
+#endif
+#if defined SPH_DETECT_I386_GCC && !defined SPH_I386_GCC
+#define SPH_I386_GCC SPH_DETECT_I386_GCC
+#endif
+#if defined SPH_DETECT_I386_MSVC && !defined SPH_I386_MSVC
+#define SPH_I386_MSVC SPH_DETECT_I386_MSVC
+#endif
+#if defined SPH_DETECT_AMD64_GCC && !defined SPH_AMD64_GCC
+#define SPH_AMD64_GCC SPH_DETECT_AMD64_GCC
+#endif
+#if defined SPH_DETECT_AMD64_MSVC && !defined SPH_AMD64_MSVC
+#define SPH_AMD64_MSVC SPH_DETECT_AMD64_MSVC
+#endif
+#if defined SPH_DETECT_PPC32_GCC && !defined SPH_PPC32_GCC
+#define SPH_PPC32_GCC SPH_DETECT_PPC32_GCC
+#endif
+#if defined SPH_DETECT_PPC64_GCC && !defined SPH_PPC64_GCC
+#define SPH_PPC64_GCC SPH_DETECT_PPC64_GCC
+#endif
+
+#if SPH_LITTLE_ENDIAN && !defined SPH_LITTLE_FAST
+#define SPH_LITTLE_FAST 1
+#endif
+#if SPH_BIG_ENDIAN && !defined SPH_BIG_FAST
+#define SPH_BIG_FAST 1
+#endif
+
+#if defined SPH_UPTR && !(SPH_LITTLE_ENDIAN || SPH_BIG_ENDIAN)
+#error SPH_UPTR defined, but endianness is not known.
+#endif
+
+#if SPH_I386_GCC && !SPH_NO_ASM
+
+/*
+ * On x86 32-bit, with gcc, we use the bswapl opcode to byte-swap 32-bit
+ * values.
+ */
+
+static SPH_INLINE sph_u32
+sph_bswap32(sph_u32 x)
+{
+ __asm__ __volatile__ ("bswapl %0" : "=r" (x) : "0" (x));
+ return x;
+}
+
+#if SPH_64
+
+static SPH_INLINE sph_u64
+sph_bswap64(sph_u64 x)
+{
+ return ((sph_u64)sph_bswap32((sph_u32)x) << 32)
+ | (sph_u64)sph_bswap32((sph_u32)(x >> 32));
+}
+
+#endif
+
+#elif SPH_AMD64_GCC && !SPH_NO_ASM
+
+/*
+ * On x86 64-bit, with gcc, we use the bswapl opcode to byte-swap 32-bit
+ * and 64-bit values.
+ */
+
+static SPH_INLINE sph_u32
+sph_bswap32(sph_u32 x)
+{
+ __asm__ __volatile__ ("bswapl %0" : "=r" (x) : "0" (x));
+ return x;
+}
+
+#if SPH_64
+
+static SPH_INLINE sph_u64
+sph_bswap64(sph_u64 x)
+{
+ __asm__ __volatile__ ("bswapq %0" : "=r" (x) : "0" (x));
+ return x;
+}
+
+#endif
+
+/*
+ * Disabled code. Apparently, Microsoft Visual C 2005 is smart enough
+ * to generate proper opcodes for endianness swapping with the pure C
+ * implementation below.
+ *
+
+#elif SPH_I386_MSVC && !SPH_NO_ASM
+
+static __inline sph_u32 __declspec(naked) __fastcall
+sph_bswap32(sph_u32 x)
+{
+ __asm {
+ bswap ecx
+ mov eax,ecx
+ ret
+ }
+}
+
+#if SPH_64
+
+static SPH_INLINE sph_u64
+sph_bswap64(sph_u64 x)
+{
+ return ((sph_u64)sph_bswap32((sph_u32)x) << 32)
+ | (sph_u64)sph_bswap32((sph_u32)(x >> 32));
+}
+
+#endif
+
+ *
+ * [end of disabled code]
+ */
+
+#else
+
+static SPH_INLINE sph_u32
+sph_bswap32(sph_u32 x)
+{
+ x = SPH_T32((x << 16) | (x >> 16));
+ x = ((x & SPH_C32(0xFF00FF00)) >> 8)
+ | ((x & SPH_C32(0x00FF00FF)) << 8);
+ return x;
+}
+
+#if SPH_64
+
+/**
+ * Byte-swap a 64-bit value.
+ *
+ * @param x the input value
+ * @return the byte-swapped value
+ */
+static SPH_INLINE sph_u64
+sph_bswap64(sph_u64 x)
+{
+ x = SPH_T64((x << 32) | (x >> 32));
+ x = ((x & SPH_C64(0xFFFF0000FFFF0000)) >> 16)
+ | ((x & SPH_C64(0x0000FFFF0000FFFF)) << 16);
+ x = ((x & SPH_C64(0xFF00FF00FF00FF00)) >> 8)
+ | ((x & SPH_C64(0x00FF00FF00FF00FF)) << 8);
+ return x;
+}
+
+#endif
+
+#endif
+
+#if SPH_SPARCV9_GCC && !SPH_NO_ASM
+
+/*
+ * On UltraSPARC systems, native ordering is big-endian, but it is
+ * possible to perform little-endian read accesses by specifying the
+ * address space 0x88 (ASI_PRIMARY_LITTLE). Basically, either we use
+ * the opcode "lda [%reg]0x88,%dst", where %reg is the register which
+ * contains the source address and %dst is the destination register,
+ * or we use "lda [%reg+imm]%asi,%dst", which uses the %asi register
+ * to get the address space name. The latter format is better since it
+ * combines an addition and the actual access in a single opcode; but
+ * it requires the setting (and subsequent resetting) of %asi, which is
+ * slow. Some operations (i.e. MD5 compression function) combine many
+ * successive little-endian read accesses, which may share the same
+ * %asi setting. The macros below contain the appropriate inline
+ * assembly.
+ */
+
+#define SPH_SPARCV9_SET_ASI \
+ sph_u32 sph_sparcv9_asi; \
+ __asm__ __volatile__ ( \
+ "rd %%asi,%0\n\twr %%g0,0x88,%%asi" : "=r" (sph_sparcv9_asi));
+
+#define SPH_SPARCV9_RESET_ASI \
+ __asm__ __volatile__ ("wr %%g0,%0,%%asi" : : "r" (sph_sparcv9_asi));
+
+#define SPH_SPARCV9_DEC32LE(base, idx) ({ \
+ sph_u32 sph_sparcv9_tmp; \
+ __asm__ __volatile__ ("lda [%1+" #idx "*4]%%asi,%0" \
+ : "=r" (sph_sparcv9_tmp) : "r" (base)); \
+ sph_sparcv9_tmp; \
+ })
+
+#endif
+
+static SPH_INLINE void
+sph_enc16be(void *dst, unsigned val)
+{
+ ((unsigned char *)dst)[0] = (val >> 8);
+ ((unsigned char *)dst)[1] = val;
+}
+
+static SPH_INLINE unsigned
+sph_dec16be(const void *src)
+{
+ return ((unsigned)(((const unsigned char *)src)[0]) << 8)
+ | (unsigned)(((const unsigned char *)src)[1]);
+}
+
+static SPH_INLINE void
+sph_enc16le(void *dst, unsigned val)
+{
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = val >> 8;
+}
+
+static SPH_INLINE unsigned
+sph_dec16le(const void *src)
+{
+ return (unsigned)(((const unsigned char *)src)[0])
+ | ((unsigned)(((const unsigned char *)src)[1]) << 8);
+}
+
+/**
+ * Encode a 32-bit value into the provided buffer (big endian convention).
+ *
+ * @param dst the destination buffer
+ * @param val the 32-bit value to encode
+ */
+static SPH_INLINE void
+sph_enc32be(void *dst, sph_u32 val)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_LITTLE_ENDIAN
+ val = sph_bswap32(val);
+#endif
+ *(sph_u32 *)dst = val;
+#else
+ if (((SPH_UPTR)dst & 3) == 0) {
+#if SPH_LITTLE_ENDIAN
+ val = sph_bswap32(val);
+#endif
+ *(sph_u32 *)dst = val;
+ } else {
+ ((unsigned char *)dst)[0] = (val >> 24);
+ ((unsigned char *)dst)[1] = (val >> 16);
+ ((unsigned char *)dst)[2] = (val >> 8);
+ ((unsigned char *)dst)[3] = val;
+ }
+#endif
+#else
+ ((unsigned char *)dst)[0] = (val >> 24);
+ ((unsigned char *)dst)[1] = (val >> 16);
+ ((unsigned char *)dst)[2] = (val >> 8);
+ ((unsigned char *)dst)[3] = val;
+#endif
+}
+
+/**
+ * Encode a 32-bit value into the provided buffer (big endian convention).
+ * The destination buffer must be properly aligned.
+ *
+ * @param dst the destination buffer (32-bit aligned)
+ * @param val the value to encode
+ */
+static SPH_INLINE void
+sph_enc32be_aligned(void *dst, sph_u32 val)
+{
+#if SPH_LITTLE_ENDIAN
+ *(sph_u32 *)dst = sph_bswap32(val);
+#elif SPH_BIG_ENDIAN
+ *(sph_u32 *)dst = val;
+#else
+ ((unsigned char *)dst)[0] = (val >> 24);
+ ((unsigned char *)dst)[1] = (val >> 16);
+ ((unsigned char *)dst)[2] = (val >> 8);
+ ((unsigned char *)dst)[3] = val;
+#endif
+}
+
+/**
+ * Decode a 32-bit value from the provided buffer (big endian convention).
+ *
+ * @param src the source buffer
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u32
+sph_dec32be(const void *src)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_LITTLE_ENDIAN
+ return sph_bswap32(*(const sph_u32 *)src);
+#else
+ return *(const sph_u32 *)src;
+#endif
+#else
+ if (((SPH_UPTR)src & 3) == 0) {
+#if SPH_LITTLE_ENDIAN
+ return sph_bswap32(*(const sph_u32 *)src);
+#else
+ return *(const sph_u32 *)src;
+#endif
+ } else {
+ return ((sph_u32)(((const unsigned char *)src)[0]) << 24)
+ | ((sph_u32)(((const unsigned char *)src)[1]) << 16)
+ | ((sph_u32)(((const unsigned char *)src)[2]) << 8)
+ | (sph_u32)(((const unsigned char *)src)[3]);
+ }
+#endif
+#else
+ return ((sph_u32)(((const unsigned char *)src)[0]) << 24)
+ | ((sph_u32)(((const unsigned char *)src)[1]) << 16)
+ | ((sph_u32)(((const unsigned char *)src)[2]) << 8)
+ | (sph_u32)(((const unsigned char *)src)[3]);
+#endif
+}
+
+/**
+ * Decode a 32-bit value from the provided buffer (big endian convention).
+ * The source buffer must be properly aligned.
+ *
+ * @param src the source buffer (32-bit aligned)
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u32
+sph_dec32be_aligned(const void *src)
+{
+#if SPH_LITTLE_ENDIAN
+ return sph_bswap32(*(const sph_u32 *)src);
+#elif SPH_BIG_ENDIAN
+ return *(const sph_u32 *)src;
+#else
+ return ((sph_u32)(((const unsigned char *)src)[0]) << 24)
+ | ((sph_u32)(((const unsigned char *)src)[1]) << 16)
+ | ((sph_u32)(((const unsigned char *)src)[2]) << 8)
+ | (sph_u32)(((const unsigned char *)src)[3]);
+#endif
+}
+
+/**
+ * Encode a 32-bit value into the provided buffer (little endian convention).
+ *
+ * @param dst the destination buffer
+ * @param val the 32-bit value to encode
+ */
+static SPH_INLINE void
+sph_enc32le(void *dst, sph_u32 val)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_BIG_ENDIAN
+ val = sph_bswap32(val);
+#endif
+ *(sph_u32 *)dst = val;
+#else
+ if (((SPH_UPTR)dst & 3) == 0) {
+#if SPH_BIG_ENDIAN
+ val = sph_bswap32(val);
+#endif
+ *(sph_u32 *)dst = val;
+ } else {
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = (val >> 8);
+ ((unsigned char *)dst)[2] = (val >> 16);
+ ((unsigned char *)dst)[3] = (val >> 24);
+ }
+#endif
+#else
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = (val >> 8);
+ ((unsigned char *)dst)[2] = (val >> 16);
+ ((unsigned char *)dst)[3] = (val >> 24);
+#endif
+}
+
+/**
+ * Encode a 32-bit value into the provided buffer (little endian convention).
+ * The destination buffer must be properly aligned.
+ *
+ * @param dst the destination buffer (32-bit aligned)
+ * @param val the value to encode
+ */
+static SPH_INLINE void
+sph_enc32le_aligned(void *dst, sph_u32 val)
+{
+#if SPH_LITTLE_ENDIAN
+ *(sph_u32 *)dst = val;
+#elif SPH_BIG_ENDIAN
+ *(sph_u32 *)dst = sph_bswap32(val);
+#else
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = (val >> 8);
+ ((unsigned char *)dst)[2] = (val >> 16);
+ ((unsigned char *)dst)[3] = (val >> 24);
+#endif
+}
+
+/**
+ * Decode a 32-bit value from the provided buffer (little endian convention).
+ *
+ * @param src the source buffer
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u32
+sph_dec32le(const void *src)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_BIG_ENDIAN
+ return sph_bswap32(*(const sph_u32 *)src);
+#else
+ return *(const sph_u32 *)src;
+#endif
+#else
+ if (((SPH_UPTR)src & 3) == 0) {
+#if SPH_BIG_ENDIAN
+#if SPH_SPARCV9_GCC && !SPH_NO_ASM
+ sph_u32 tmp;
+
+ /*
+ * "__volatile__" is needed here because without it,
+ * gcc-3.4.3 miscompiles the code and performs the
+ * access before the test on the address, thus triggering
+ * a bus error...
+ */
+ __asm__ __volatile__ (
+ "lda [%1]0x88,%0" : "=r" (tmp) : "r" (src));
+ return tmp;
+/*
+ * On PowerPC, this turns out not to be worth the effort: the inline
+ * assembly makes GCC optimizer uncomfortable, which tends to nullify
+ * the decoding gains.
+ *
+ * For most hash functions, using this inline assembly trick changes
+ * hashing speed by less than 5% and often _reduces_ it. The biggest
+ * gains are for MD4 (+11%) and CubeHash (+30%). For all others, it is
+ * less then 10%. The speed gain on CubeHash is probably due to the
+ * chronic shortage of registers that CubeHash endures; for the other
+ * functions, the generic code appears to be efficient enough already.
+ *
+#elif (SPH_PPC32_GCC || SPH_PPC64_GCC) && !SPH_NO_ASM
+ sph_u32 tmp;
+
+ __asm__ __volatile__ (
+ "lwbrx %0,0,%1" : "=r" (tmp) : "r" (src));
+ return tmp;
+ */
+#else
+ return sph_bswap32(*(const sph_u32 *)src);
+#endif
+#else
+ return *(const sph_u32 *)src;
+#endif
+ } else {
+ return (sph_u32)(((const unsigned char *)src)[0])
+ | ((sph_u32)(((const unsigned char *)src)[1]) << 8)
+ | ((sph_u32)(((const unsigned char *)src)[2]) << 16)
+ | ((sph_u32)(((const unsigned char *)src)[3]) << 24);
+ }
+#endif
+#else
+ return (sph_u32)(((const unsigned char *)src)[0])
+ | ((sph_u32)(((const unsigned char *)src)[1]) << 8)
+ | ((sph_u32)(((const unsigned char *)src)[2]) << 16)
+ | ((sph_u32)(((const unsigned char *)src)[3]) << 24);
+#endif
+}
+
+/**
+ * Decode a 32-bit value from the provided buffer (little endian convention).
+ * The source buffer must be properly aligned.
+ *
+ * @param src the source buffer (32-bit aligned)
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u32
+sph_dec32le_aligned(const void *src)
+{
+#if SPH_LITTLE_ENDIAN
+ return *(const sph_u32 *)src;
+#elif SPH_BIG_ENDIAN
+#if SPH_SPARCV9_GCC && !SPH_NO_ASM
+ sph_u32 tmp;
+
+ __asm__ __volatile__ ("lda [%1]0x88,%0" : "=r" (tmp) : "r" (src));
+ return tmp;
+/*
+ * Not worth it generally.
+ *
+#elif (SPH_PPC32_GCC || SPH_PPC64_GCC) && !SPH_NO_ASM
+ sph_u32 tmp;
+
+ __asm__ __volatile__ ("lwbrx %0,0,%1" : "=r" (tmp) : "r" (src));
+ return tmp;
+ */
+#else
+ return sph_bswap32(*(const sph_u32 *)src);
+#endif
+#else
+ return (sph_u32)(((const unsigned char *)src)[0])
+ | ((sph_u32)(((const unsigned char *)src)[1]) << 8)
+ | ((sph_u32)(((const unsigned char *)src)[2]) << 16)
+ | ((sph_u32)(((const unsigned char *)src)[3]) << 24);
+#endif
+}
+
+#if SPH_64
+
+/**
+ * Encode a 64-bit value into the provided buffer (big endian convention).
+ *
+ * @param dst the destination buffer
+ * @param val the 64-bit value to encode
+ */
+static SPH_INLINE void
+sph_enc64be(void *dst, sph_u64 val)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_LITTLE_ENDIAN
+ val = sph_bswap64(val);
+#endif
+ *(sph_u64 *)dst = val;
+#else
+ if (((SPH_UPTR)dst & 7) == 0) {
+#if SPH_LITTLE_ENDIAN
+ val = sph_bswap64(val);
+#endif
+ *(sph_u64 *)dst = val;
+ } else {
+ ((unsigned char *)dst)[0] = (val >> 56);
+ ((unsigned char *)dst)[1] = (val >> 48);
+ ((unsigned char *)dst)[2] = (val >> 40);
+ ((unsigned char *)dst)[3] = (val >> 32);
+ ((unsigned char *)dst)[4] = (val >> 24);
+ ((unsigned char *)dst)[5] = (val >> 16);
+ ((unsigned char *)dst)[6] = (val >> 8);
+ ((unsigned char *)dst)[7] = val;
+ }
+#endif
+#else
+ ((unsigned char *)dst)[0] = (val >> 56);
+ ((unsigned char *)dst)[1] = (val >> 48);
+ ((unsigned char *)dst)[2] = (val >> 40);
+ ((unsigned char *)dst)[3] = (val >> 32);
+ ((unsigned char *)dst)[4] = (val >> 24);
+ ((unsigned char *)dst)[5] = (val >> 16);
+ ((unsigned char *)dst)[6] = (val >> 8);
+ ((unsigned char *)dst)[7] = val;
+#endif
+}
+
+/**
+ * Encode a 64-bit value into the provided buffer (big endian convention).
+ * The destination buffer must be properly aligned.
+ *
+ * @param dst the destination buffer (64-bit aligned)
+ * @param val the value to encode
+ */
+static SPH_INLINE void
+sph_enc64be_aligned(void *dst, sph_u64 val)
+{
+#if SPH_LITTLE_ENDIAN
+ *(sph_u64 *)dst = sph_bswap64(val);
+#elif SPH_BIG_ENDIAN
+ *(sph_u64 *)dst = val;
+#else
+ ((unsigned char *)dst)[0] = (val >> 56);
+ ((unsigned char *)dst)[1] = (val >> 48);
+ ((unsigned char *)dst)[2] = (val >> 40);
+ ((unsigned char *)dst)[3] = (val >> 32);
+ ((unsigned char *)dst)[4] = (val >> 24);
+ ((unsigned char *)dst)[5] = (val >> 16);
+ ((unsigned char *)dst)[6] = (val >> 8);
+ ((unsigned char *)dst)[7] = val;
+#endif
+}
+
+/**
+ * Decode a 64-bit value from the provided buffer (big endian convention).
+ *
+ * @param src the source buffer
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u64
+sph_dec64be(const void *src)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_LITTLE_ENDIAN
+ return sph_bswap64(*(const sph_u64 *)src);
+#else
+ return *(const sph_u64 *)src;
+#endif
+#else
+ if (((SPH_UPTR)src & 7) == 0) {
+#if SPH_LITTLE_ENDIAN
+ return sph_bswap64(*(const sph_u64 *)src);
+#else
+ return *(const sph_u64 *)src;
+#endif
+ } else {
+ return ((sph_u64)(((const unsigned char *)src)[0]) << 56)
+ | ((sph_u64)(((const unsigned char *)src)[1]) << 48)
+ | ((sph_u64)(((const unsigned char *)src)[2]) << 40)
+ | ((sph_u64)(((const unsigned char *)src)[3]) << 32)
+ | ((sph_u64)(((const unsigned char *)src)[4]) << 24)
+ | ((sph_u64)(((const unsigned char *)src)[5]) << 16)
+ | ((sph_u64)(((const unsigned char *)src)[6]) << 8)
+ | (sph_u64)(((const unsigned char *)src)[7]);
+ }
+#endif
+#else
+ return ((sph_u64)(((const unsigned char *)src)[0]) << 56)
+ | ((sph_u64)(((const unsigned char *)src)[1]) << 48)
+ | ((sph_u64)(((const unsigned char *)src)[2]) << 40)
+ | ((sph_u64)(((const unsigned char *)src)[3]) << 32)
+ | ((sph_u64)(((const unsigned char *)src)[4]) << 24)
+ | ((sph_u64)(((const unsigned char *)src)[5]) << 16)
+ | ((sph_u64)(((const unsigned char *)src)[6]) << 8)
+ | (sph_u64)(((const unsigned char *)src)[7]);
+#endif
+}
+
+/**
+ * Decode a 64-bit value from the provided buffer (big endian convention).
+ * The source buffer must be properly aligned.
+ *
+ * @param src the source buffer (64-bit aligned)
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u64
+sph_dec64be_aligned(const void *src)
+{
+#if SPH_LITTLE_ENDIAN
+ return sph_bswap64(*(const sph_u64 *)src);
+#elif SPH_BIG_ENDIAN
+ return *(const sph_u64 *)src;
+#else
+ return ((sph_u64)(((const unsigned char *)src)[0]) << 56)
+ | ((sph_u64)(((const unsigned char *)src)[1]) << 48)
+ | ((sph_u64)(((const unsigned char *)src)[2]) << 40)
+ | ((sph_u64)(((const unsigned char *)src)[3]) << 32)
+ | ((sph_u64)(((const unsigned char *)src)[4]) << 24)
+ | ((sph_u64)(((const unsigned char *)src)[5]) << 16)
+ | ((sph_u64)(((const unsigned char *)src)[6]) << 8)
+ | (sph_u64)(((const unsigned char *)src)[7]);
+#endif
+}
+
+/**
+ * Encode a 64-bit value into the provided buffer (little endian convention).
+ *
+ * @param dst the destination buffer
+ * @param val the 64-bit value to encode
+ */
+static SPH_INLINE void
+sph_enc64le(void *dst, sph_u64 val)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_BIG_ENDIAN
+ val = sph_bswap64(val);
+#endif
+ *(sph_u64 *)dst = val;
+#else
+ if (((SPH_UPTR)dst & 7) == 0) {
+#if SPH_BIG_ENDIAN
+ val = sph_bswap64(val);
+#endif
+ *(sph_u64 *)dst = val;
+ } else {
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = (val >> 8);
+ ((unsigned char *)dst)[2] = (val >> 16);
+ ((unsigned char *)dst)[3] = (val >> 24);
+ ((unsigned char *)dst)[4] = (val >> 32);
+ ((unsigned char *)dst)[5] = (val >> 40);
+ ((unsigned char *)dst)[6] = (val >> 48);
+ ((unsigned char *)dst)[7] = (val >> 56);
+ }
+#endif
+#else
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = (val >> 8);
+ ((unsigned char *)dst)[2] = (val >> 16);
+ ((unsigned char *)dst)[3] = (val >> 24);
+ ((unsigned char *)dst)[4] = (val >> 32);
+ ((unsigned char *)dst)[5] = (val >> 40);
+ ((unsigned char *)dst)[6] = (val >> 48);
+ ((unsigned char *)dst)[7] = (val >> 56);
+#endif
+}
+
+/**
+ * Encode a 64-bit value into the provided buffer (little endian convention).
+ * The destination buffer must be properly aligned.
+ *
+ * @param dst the destination buffer (64-bit aligned)
+ * @param val the value to encode
+ */
+static SPH_INLINE void
+sph_enc64le_aligned(void *dst, sph_u64 val)
+{
+#if SPH_LITTLE_ENDIAN
+ *(sph_u64 *)dst = val;
+#elif SPH_BIG_ENDIAN
+ *(sph_u64 *)dst = sph_bswap64(val);
+#else
+ ((unsigned char *)dst)[0] = val;
+ ((unsigned char *)dst)[1] = (val >> 8);
+ ((unsigned char *)dst)[2] = (val >> 16);
+ ((unsigned char *)dst)[3] = (val >> 24);
+ ((unsigned char *)dst)[4] = (val >> 32);
+ ((unsigned char *)dst)[5] = (val >> 40);
+ ((unsigned char *)dst)[6] = (val >> 48);
+ ((unsigned char *)dst)[7] = (val >> 56);
+#endif
+}
+
+/**
+ * Decode a 64-bit value from the provided buffer (little endian convention).
+ *
+ * @param src the source buffer
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u64
+sph_dec64le(const void *src)
+{
+#if defined SPH_UPTR
+#if SPH_UNALIGNED
+#if SPH_BIG_ENDIAN
+ return sph_bswap64(*(const sph_u64 *)src);
+#else
+ return *(const sph_u64 *)src;
+#endif
+#else
+ if (((SPH_UPTR)src & 7) == 0) {
+#if SPH_BIG_ENDIAN
+#if SPH_SPARCV9_GCC_64 && !SPH_NO_ASM
+ sph_u64 tmp;
+
+ __asm__ __volatile__ (
+ "ldxa [%1]0x88,%0" : "=r" (tmp) : "r" (src));
+ return tmp;
+/*
+ * Not worth it generally.
+ *
+#elif SPH_PPC32_GCC && !SPH_NO_ASM
+ return (sph_u64)sph_dec32le_aligned(src)
+ | ((sph_u64)sph_dec32le_aligned(
+ (const char *)src + 4) << 32);
+#elif SPH_PPC64_GCC && !SPH_NO_ASM
+ sph_u64 tmp;
+
+ __asm__ __volatile__ (
+ "ldbrx %0,0,%1" : "=r" (tmp) : "r" (src));
+ return tmp;
+ */
+#else
+ return sph_bswap64(*(const sph_u64 *)src);
+#endif
+#else
+ return *(const sph_u64 *)src;
+#endif
+ } else {
+ return (sph_u64)(((const unsigned char *)src)[0])
+ | ((sph_u64)(((const unsigned char *)src)[1]) << 8)
+ | ((sph_u64)(((const unsigned char *)src)[2]) << 16)
+ | ((sph_u64)(((const unsigned char *)src)[3]) << 24)
+ | ((sph_u64)(((const unsigned char *)src)[4]) << 32)
+ | ((sph_u64)(((const unsigned char *)src)[5]) << 40)
+ | ((sph_u64)(((const unsigned char *)src)[6]) << 48)
+ | ((sph_u64)(((const unsigned char *)src)[7]) << 56);
+ }
+#endif
+#else
+ return (sph_u64)(((const unsigned char *)src)[0])
+ | ((sph_u64)(((const unsigned char *)src)[1]) << 8)
+ | ((sph_u64)(((const unsigned char *)src)[2]) << 16)
+ | ((sph_u64)(((const unsigned char *)src)[3]) << 24)
+ | ((sph_u64)(((const unsigned char *)src)[4]) << 32)
+ | ((sph_u64)(((const unsigned char *)src)[5]) << 40)
+ | ((sph_u64)(((const unsigned char *)src)[6]) << 48)
+ | ((sph_u64)(((const unsigned char *)src)[7]) << 56);
+#endif
+}
+
+/**
+ * Decode a 64-bit value from the provided buffer (little endian convention).
+ * The source buffer must be properly aligned.
+ *
+ * @param src the source buffer (64-bit aligned)
+ * @return the decoded value
+ */
+static SPH_INLINE sph_u64
+sph_dec64le_aligned(const void *src)
+{
+#if SPH_LITTLE_ENDIAN
+ return *(const sph_u64 *)src;
+#elif SPH_BIG_ENDIAN
+#if SPH_SPARCV9_GCC_64 && !SPH_NO_ASM
+ sph_u64 tmp;
+
+ __asm__ __volatile__ ("ldxa [%1]0x88,%0" : "=r" (tmp) : "r" (src));
+ return tmp;
+/*
+ * Not worth it generally.
+ *
+#elif SPH_PPC32_GCC && !SPH_NO_ASM
+ return (sph_u64)sph_dec32le_aligned(src)
+ | ((sph_u64)sph_dec32le_aligned((const char *)src + 4) << 32);
+#elif SPH_PPC64_GCC && !SPH_NO_ASM
+ sph_u64 tmp;
+
+ __asm__ __volatile__ ("ldbrx %0,0,%1" : "=r" (tmp) : "r" (src));
+ return tmp;
+ */
+#else
+ return sph_bswap64(*(const sph_u64 *)src);
+#endif
+#else
+ return (sph_u64)(((const unsigned char *)src)[0])
+ | ((sph_u64)(((const unsigned char *)src)[1]) << 8)
+ | ((sph_u64)(((const unsigned char *)src)[2]) << 16)
+ | ((sph_u64)(((const unsigned char *)src)[3]) << 24)
+ | ((sph_u64)(((const unsigned char *)src)[4]) << 32)
+ | ((sph_u64)(((const unsigned char *)src)[5]) << 40)
+ | ((sph_u64)(((const unsigned char *)src)[6]) << 48)
+ | ((sph_u64)(((const unsigned char *)src)[7]) << 56);
+#endif
+}
+
+#endif
+
+#endif /* Doxygen excluded block */
+
+#endif
diff --git a/exlib/lyra2z-py/test.py b/exlib/lyra2z-py/test.py
new file mode 100644
index 000000000000..3d27ebeb727e
--- /dev/null
+++ b/exlib/lyra2z-py/test.py
@@ -0,0 +1,12 @@
+import lyra2z_hash
+import weakref
+import binascii
+import StringIO
+
+from binascii import unhexlify, hexlify
+
+teststart = '700000005d385ba114d079971b29a9418fd0549e7d68a95c7f168621a314201000000000578586d149fd07b22f3a8a347c516de7052f034d2b76ff68e0d6ecff9b77a45489e3fd511732011df0731000';
+testbin = unhexlify(teststart)
+hash_bin = lyra2z_hash.getPoWHash(testbin)
+
+print(hexlify(hash_bin))
diff --git a/gui/kivy/Makefile b/gui/kivy/Makefile
index e616f9d1a1ef..34bab6eeb483 100644
--- a/gui/kivy/Makefile
+++ b/gui/kivy/Makefile
@@ -10,7 +10,7 @@ prepare:
# running pre build setup
@cp tools/buildozer.spec ../../buildozer.spec
# copy electrum to main.py
- @cp ../../electrum ../../main.py
+ @cp ../../electrum-xzc ../../main.py
@-if [ ! -d "../../.buildozer" ];then \
cd ../..; buildozer android debug;\
cp -f gui/kivy/tools/blacklist.txt .buildozer/android/platform/python-for-android/src/blacklist.txt;\
diff --git a/gui/kivy/i18n.py b/gui/kivy/i18n.py
index e0be39082c8a..e1c09df4ac1a 100644
--- a/gui/kivy/i18n.py
+++ b/gui/kivy/i18n.py
@@ -35,7 +35,7 @@ def bind(label):
@staticmethod
def switch_lang(lang):
# get the right locales directory, and instanciate a gettext
- from electrum.i18n import LOCALE_DIR
+ from electrum_xzc.i18n import LOCALE_DIR
locales = gettext.translation('electrum', LOCALE_DIR, languages=[lang], fallback=True)
_.lang = locales.gettext
for label in _.observers:
diff --git a/gui/kivy/main.kv b/gui/kivy/main.kv
index 853ddd94e792..212f073e99a8 100644
--- a/gui/kivy/main.kv
+++ b/gui/kivy/main.kv
@@ -1,7 +1,7 @@
#:import Clock kivy.clock.Clock
#:import Window kivy.core.window.Window
#:import Factory kivy.factory.Factory
-#:import _ electrum_gui.kivy.i18n._
+#:import _ electrum_xzc_gui.kivy.i18n._
###########################
diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py
index 020388fadcd1..8c3ca3e3071c 100644
--- a/gui/kivy/main_window.py
+++ b/gui/kivy/main_window.py
@@ -7,15 +7,15 @@
from decimal import Decimal
import threading
-import electrum
-from electrum.bitcoin import TYPE_ADDRESS
-from electrum import WalletStorage, Wallet
-from electrum_gui.kivy.i18n import _
-from electrum.paymentrequest import InvoiceStore
-from electrum.util import profiler, InvalidPassword
-from electrum.plugins import run_hook
-from electrum.util import format_satoshis, format_satoshis_plain
-from electrum.paymentrequest import PR_UNPAID, PR_PAID, PR_UNKNOWN, PR_EXPIRED
+import electrum_xzc as electrum
+from electrum_xzc.bitcoin import TYPE_ADDRESS
+from electrum_xzc import WalletStorage, Wallet
+from electrum_xzc_gui.kivy.i18n import _
+from electrum_xzc.paymentrequest import InvoiceStore
+from electrum_xzc.util import profiler, InvalidPassword
+from electrum_xzc.plugins import run_hook
+from electrum_xzc.util import format_satoshis, format_satoshis_plain
+from electrum_xzc.paymentrequest import PR_UNPAID, PR_PAID, PR_UNKNOWN, PR_EXPIRED
from kivy.app import App
from kivy.core.window import Window
@@ -30,10 +30,10 @@
from kivy.lang import Builder
## lazy imports for factory so that widgets can be used in kv
-#Factory.register('InstallWizard', module='electrum_gui.kivy.uix.dialogs.installwizard')
-#Factory.register('InfoBubble', module='electrum_gui.kivy.uix.dialogs')
-#Factory.register('OutputList', module='electrum_gui.kivy.uix.dialogs')
-#Factory.register('OutputItem', module='electrum_gui.kivy.uix.dialogs')
+#Factory.register('InstallWizard', module='electrum_xzc_gui.kivy.uix.dialogs.installwizard')
+#Factory.register('InfoBubble', module='electrum_xzc_gui.kivy.uix.dialogs')
+#Factory.register('OutputList', module='electrum_xzc_gui.kivy.uix.dialogs')
+#Factory.register('OutputItem', module='electrum_xzc_gui.kivy.uix.dialogs')
from .uix.dialogs.installwizard import InstallWizard
from .uix.dialogs import InfoBubble
@@ -48,14 +48,14 @@
# register widget cache for keeping memory down timeout to forever to cache
# the data
-Cache.register('electrum_widgets', timeout=0)
+Cache.register('electrum_xzc_widgets', timeout=0)
from kivy.uix.screenmanager import Screen
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.label import Label
from kivy.core.clipboard import Clipboard
-Factory.register('TabbedCarousel', module='electrum_gui.kivy.uix.screens')
+Factory.register('TabbedCarousel', module='electrum_xzc_gui.kivy.uix.screens')
# Register fonts without this you won't be able to use bold/italic...
# inside markup.
@@ -67,7 +67,7 @@
'gui/kivy/data/fonts/Roboto-Bold.ttf')
-from electrum.util import base_units
+from electrum_xzc.util import base_units
class ElectrumWindow(App):
@@ -95,7 +95,7 @@ def choose_server_dialog(self, popup):
from .uix.dialogs.choice_dialog import ChoiceDialog
protocol = 's'
def cb2(host):
- from electrum.bitcoin import NetworkConstants
+ from electrum_xzc.bitcoin import NetworkConstants
pp = servers.get(host, NetworkConstants.DEFAULT_PORTS)
port = pp.get(protocol, '')
popup.ids.host.text = host
@@ -132,7 +132,7 @@ def set_URI(self, uri):
self.send_screen.set_URI(uri)
def on_new_intent(self, intent):
- if intent.getScheme() != 'bitcoin':
+ if intent.getScheme() != 'zcoin':
return
uri = intent.getDataString()
self.set_URI(uri)
@@ -154,7 +154,7 @@ def on_history(self, d):
self._trigger_update_history()
def _get_bu(self):
- return self.electrum_config.get('base_unit', 'mBTC')
+ return self.electrum_config.get('base_unit', 'XZC')
def _set_bu(self, value):
assert value in base_units.keys()
@@ -241,7 +241,7 @@ def __init__(self, **kwargs):
App.__init__(self)#, **kwargs)
- title = _('Electrum App')
+ title = _('Electrum-XZC App')
self.electrum_config = config = kwargs.get('config', None)
self.language = config.get('language', 'en')
self.network = network = kwargs.get('network', None)
@@ -295,17 +295,17 @@ def on_pr(self, pr):
self.send_screen.do_clear()
def on_qr(self, data):
- from electrum.bitcoin import base_decode, is_address
+ from electrum_xzc.bitcoin import base_decode, is_address
data = data.strip()
if is_address(data):
self.set_URI(data)
return
- if data.startswith('bitcoin:'):
+ if data.startswith('zcoin:'):
self.set_URI(data)
return
# try to decode transaction
- from electrum.transaction import Transaction
- from electrum.util import bh2u
+ from electrum_xzc.transaction import Transaction
+ from electrum_xzc.util import bh2u
try:
text = bh2u(base_decode(data, None, base=43))
tx = Transaction(text)
@@ -342,7 +342,7 @@ def show_request(self, addr):
self.receive_screen.screen.address = addr
def show_pr_details(self, req, status, is_invoice):
- from electrum.util import format_time
+ from electrum_xzc.util import format_time
requestor = req.get('requestor')
exp = req.get('exp')
memo = req.get('memo')
@@ -364,7 +364,7 @@ def show_pr_details(self, req, status, is_invoice):
popup.open()
def show_addr_details(self, req, status):
- from electrum.util import format_time
+ from electrum_xzc.util import format_time
fund = req.get('fund')
isaddr = 'y'
popup = Builder.load_file('gui/kivy/uix/ui_screens/invoice.kv')
@@ -563,13 +563,13 @@ def init_ui(self):
#setup lazy imports for mainscreen
Factory.register('AnimatedPopup',
- module='electrum_gui.kivy.uix.dialogs')
+ module='electrum_xzc_gui.kivy.uix.dialogs')
Factory.register('QRCodeWidget',
- module='electrum_gui.kivy.uix.qrcodewidget')
+ module='electrum_xzc_gui.kivy.uix.qrcodewidget')
# preload widgets. Remove this if you want to load the widgets on demand
- #Cache.append('electrum_widgets', 'AnimatedPopup', Factory.AnimatedPopup())
- #Cache.append('electrum_widgets', 'QRCodeWidget', Factory.QRCodeWidget())
+ #Cache.append('electrum_xzc_widgets', 'AnimatedPopup', Factory.AnimatedPopup())
+ #Cache.append('electrum_xzc_widgets', 'QRCodeWidget', Factory.QRCodeWidget())
# load and focus the ui
self.root.manager = self.root.ids['manager']
@@ -581,7 +581,7 @@ def init_ui(self):
self.receive_screen = None
self.requests_screen = None
self.address_screen = None
- self.icon = "icons/electrum.png"
+ self.icon = "icons/electrum-xzc.png"
self.tabs = self.root.ids['tabs']
def update_interfaces(self, dt):
@@ -631,7 +631,7 @@ def update_status(self, *dt):
if not self.wallet.up_to_date or server_height == 0:
status = _("Synchronizing...")
elif server_lag > 1:
- status = _("Server lagging ({} blocks)").format(server_lag)
+ status = _("Server lagging (%d blocks)"%server_lag)
else:
c, u, x = self.wallet.get_balance()
text = self.format_amount(c+x+u)
@@ -670,8 +670,8 @@ def notify(self, message):
from plyer import notification
icon = (os.path.dirname(os.path.realpath(__file__))
+ '/../../' + self.icon)
- notification.notify('Electrum', message,
- app_icon=icon, app_name='Electrum')
+ notification.notify('Electrum-XZC', message,
+ app_icon=icon, app_name='Electrum-XZC')
except ImportError:
Logger.Error('Notification: needs plyer; `sudo pip install plyer`')
@@ -846,7 +846,7 @@ def delete_wallet(self):
def _delete_wallet(self, b):
if b:
basename = os.path.basename(self.wallet.storage.path)
- self.protected(_("Enter your PIN code to confirm deletion of {}").format(basename), self.__delete_wallet, ())
+ self.protected(_("Enter your PIN code to confirm deletion of %s") % basename, self.__delete_wallet, ())
def __delete_wallet(self, pw):
wallet_path = self.get_wallet_path()
diff --git a/gui/kivy/nfc_scanner/__init__.py b/gui/kivy/nfc_scanner/__init__.py
index fd3d263a3fd4..e2b5deeb6a13 100644
--- a/gui/kivy/nfc_scanner/__init__.py
+++ b/gui/kivy/nfc_scanner/__init__.py
@@ -41,4 +41,4 @@ def nfc_disable_exchange(self):
NFCScanner = core_select_lib('nfc_manager', (
# keep the dummy implementtation as the last one to make it the fallback provider.NFCScanner = core_select_lib('nfc_scanner', (
('android', 'scanner_android', 'ScannerAndroid'),
- ('dummy', 'scanner_dummy', 'ScannerDummy')), True, 'electrum_gui.kivy')
+ ('dummy', 'scanner_dummy', 'ScannerDummy')), True, 'electrum_xzc_gui.kivy')
diff --git a/gui/kivy/nfc_scanner/scanner_android.py b/gui/kivy/nfc_scanner/scanner_android.py
index b8f860293238..db89dcd0930d 100644
--- a/gui/kivy/nfc_scanner/scanner_android.py
+++ b/gui/kivy/nfc_scanner/scanner_android.py
@@ -10,7 +10,7 @@
raise ImportError
import threading
-from electrum_gui.kivy.nfc_scanner import NFCBase
+from electrum_xzc_gui.kivy.nfc_scanner import NFCBase
from jnius import autoclass, cast
from android.runnable import run_on_ui_thread
from android import activity
@@ -165,20 +165,20 @@ def nfc_enable(self):
def create_AAR(self):
'''Create the record responsible for linking our application to the tag.
'''
- return NdefRecord.createApplicationRecord(JString("org.electrum.kivy"))
+ return NdefRecord.createApplicationRecord(JString("org.electrum_xzc.kivy"))
def create_TNF_EXTERNAL(self, data):
'''Create our actual payload record.
'''
if BUILDVERSION >= 14:
- domain = "org.electrum"
+ domain = "org.electrum_xzc"
stype = "externalType"
extRecord = NdefRecord.createExternal(domain, stype, data)
else:
# Creating the NdefRecord manually:
extRecord = NdefRecord(
NdefRecord.TNF_EXTERNAL_TYPE,
- "org.electrum:externalType",
+ "org.electrum_xzc:externalType",
'',
data)
return extRecord
@@ -213,7 +213,7 @@ def _nfc_enable_ndef_exchange(self, data):
# Create record
ndef_record = NdefRecord(
NdefRecord.TNF_MIME_MEDIA,
- 'org.electrum.kivy', '', data)
+ 'org.electrum_xzc.kivy', '', data)
# Create message
ndef_message = NdefMessage([ndef_record])
diff --git a/gui/kivy/nfc_scanner/scanner_dummy.py b/gui/kivy/nfc_scanner/scanner_dummy.py
index 1ad2c17a3b24..e1cfadb29aed 100644
--- a/gui/kivy/nfc_scanner/scanner_dummy.py
+++ b/gui/kivy/nfc_scanner/scanner_dummy.py
@@ -1,6 +1,6 @@
''' Dummy NFC Provider to be used on desktops in case no other provider is found
'''
-from electrum_gui.kivy.nfc_scanner import NFCBase
+from electrum_xzc_gui.kivy.nfc_scanner import NFCBase
from kivy.clock import Clock
from kivy.logger import Logger
diff --git a/gui/kivy/tools/bitcoin_intent.xml b/gui/kivy/tools/bitcoin_intent.xml
index f433f72c1ef8..b0e66c27628e 100644
--- a/gui/kivy/tools/bitcoin_intent.xml
+++ b/gui/kivy/tools/bitcoin_intent.xml
@@ -3,5 +3,5 @@
-
+
diff --git a/gui/kivy/tools/buildozer.spec b/gui/kivy/tools/buildozer.spec
index b3679889db6c..957a804fe0f2 100644
--- a/gui/kivy/tools/buildozer.spec
+++ b/gui/kivy/tools/buildozer.spec
@@ -1,13 +1,13 @@
[app]
# (str) Title of your application
-title = Electrum
+title = Electrum-XZC
# (str) Package name
-package.name = Electrum
+package.name = Electrum_XZC
# (str) Package domain (needed for android/ios packaging)
-package.domain = org.electrum
+package.domain = org.electrum_xzc
# (str) Source code where the main.py live
source.dir = .
diff --git a/gui/kivy/uix/context_menu.py b/gui/kivy/uix/context_menu.py
index dee0212af45d..fc4b3f3caac8 100644
--- a/gui/kivy/uix/context_menu.py
+++ b/gui/kivy/uix/context_menu.py
@@ -8,7 +8,7 @@
from kivy.factory import Factory
from kivy.clock import Clock
-from electrum_gui.kivy.i18n import _
+from electrum_xzc_gui.kivy.i18n import _
Builder.load_string('''