@leocuvee/wrkzcoin-multi-hashing 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.travis.yml +5 -0
- package/LICENSE +674 -0
- package/README.md +87 -0
- package/appveyor.yml +12 -0
- package/argon2/.gitattributes +10 -0
- package/argon2/.travis.yml +25 -0
- package/argon2/Argon2.sln +160 -0
- package/argon2/CHANGELOG.md +32 -0
- package/argon2/CMakeLists.txt +87 -0
- package/argon2/LICENSE +314 -0
- package/argon2/Makefile +196 -0
- package/argon2/README.md +297 -0
- package/argon2/appveyor.yml +40 -0
- package/argon2/argon2-specs.pdf +0 -0
- package/argon2/export.sh +7 -0
- package/argon2/include/argon2.h +427 -0
- package/argon2/latex/CMakeLists.txt +34 -0
- package/argon2/latex/IEEEtran.cls +6347 -0
- package/argon2/latex/Makefile +18 -0
- package/argon2/latex/argon2-specs.tex +920 -0
- package/argon2/latex/pics/argon2-par.pdf +0 -0
- package/argon2/latex/pics/compression.pdf +0 -0
- package/argon2/latex/pics/generic.pdf +0 -0
- package/argon2/latex/pics/power-distribution.jpg +0 -0
- package/argon2/latex/tradeoff.bib +822 -0
- package/argon2/libargon2.pc +16 -0
- package/argon2/man/CMakeLists.txt +8 -0
- package/argon2/man/argon2.1 +57 -0
- package/argon2/meson.build +16 -0
- package/argon2/meson_options.txt +1 -0
- package/argon2/src/CMakeLists.txt +147 -0
- package/argon2/src/argon2.c +452 -0
- package/argon2/src/argon2.pc.in +11 -0
- package/argon2/src/blake2/blake2-impl.h +156 -0
- package/argon2/src/blake2/blake2.h +89 -0
- package/argon2/src/blake2/blake2b.c +390 -0
- package/argon2/src/blake2/blamka-round-opt.h +471 -0
- package/argon2/src/blake2/blamka-round-ref.h +56 -0
- package/argon2/src/core.c +634 -0
- package/argon2/src/core.h +228 -0
- package/argon2/src/encoding.c +467 -0
- package/argon2/src/encoding.h +57 -0
- package/argon2/src/genkat.h +51 -0
- package/argon2/src/meson.build +68 -0
- package/argon2/src/opt.c +283 -0
- package/argon2/src/optimization/CMakeLists.txt +10 -0
- package/argon2/src/ref.c +194 -0
- package/argon2/src/thread.c +57 -0
- package/argon2/src/thread.h +67 -0
- package/argon2/tests/CMakeLists.txt +43 -0
- package/argon2/tests/bench.c +111 -0
- package/argon2/tests/genkat.c +207 -0
- package/argon2/tests/kats/argon2d +12304 -0
- package/argon2/tests/kats/argon2d.shasum +1 -0
- package/argon2/tests/kats/argon2d_v16 +12304 -0
- package/argon2/tests/kats/argon2d_v16.shasum +1 -0
- package/argon2/tests/kats/argon2i +12304 -0
- package/argon2/tests/kats/argon2i.shasum +1 -0
- package/argon2/tests/kats/argon2i_v16 +12304 -0
- package/argon2/tests/kats/argon2i_v16.shasum +1 -0
- package/argon2/tests/kats/argon2id +12304 -0
- package/argon2/tests/kats/argon2id.shasum +1 -0
- package/argon2/tests/kats/argon2id_v16 +12304 -0
- package/argon2/tests/kats/argon2id_v16.shasum +1 -0
- package/argon2/tests/kats/check-sums.ps1 +48 -0
- package/argon2/tests/kats/check-sums.sh +16 -0
- package/argon2/tests/kats/test.ps1 +132 -0
- package/argon2/tests/kats/test.sh +117 -0
- package/argon2/tests/meson.build +34 -0
- package/argon2/tests/test.c +289 -0
- package/argon2/tool/CMakeLists.txt +7 -0
- package/argon2/tool/main.c +339 -0
- package/argon2/tool/meson.build +8 -0
- package/argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj +226 -0
- package/argon2/vs2015/Argon2Opt/Argon2Opt.vcxproj.filters +69 -0
- package/argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj +226 -0
- package/argon2/vs2015/Argon2OptBench/Argon2OptBench.vcxproj.filters +69 -0
- package/argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj +225 -0
- package/argon2/vs2015/Argon2OptDll/Argon2OptDll.vcxproj.filters +66 -0
- package/argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj +239 -0
- package/argon2/vs2015/Argon2OptGenKAT/Argon2OptGenKAT.vcxproj.filters +72 -0
- package/argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj +227 -0
- package/argon2/vs2015/Argon2OptTestCI/Argon2OptTestCI.vcxproj.filters +69 -0
- package/argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj +226 -0
- package/argon2/vs2015/Argon2Ref/Argon2Ref.vcxproj.filters +69 -0
- package/argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj +226 -0
- package/argon2/vs2015/Argon2RefBench/Argon2RefBench.vcxproj.filters +69 -0
- package/argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj +225 -0
- package/argon2/vs2015/Argon2RefDll/Argon2RefDll.vcxproj.filters +66 -0
- package/argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj +227 -0
- package/argon2/vs2015/Argon2RefGenKAT/Argon2RefGenKAT.vcxproj.filters +72 -0
- package/argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj +226 -0
- package/argon2/vs2015/Argon2RefTestCI/Argon2RefTestCI.vcxproj.filters +69 -0
- package/bcrypt.c +566 -0
- package/bcrypt.h +14 -0
- package/binding.gyp +93 -0
- package/blake.c +17 -0
- package/blake.h +16 -0
- package/boolberry.cc +11 -0
- package/boolberry.h +6 -0
- package/build/Makefile +354 -0
- package/build/Release/.deps/Release/multihashing.node.d +1 -0
- package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/argon2.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/blake2/blake2b.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/core.o.d +10 -0
- package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/encoding.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/ref.o.d +14 -0
- package/build/Release/.deps/Release/obj.target/multihashing/argon2/src/thread.o.d +5 -0
- package/build/Release/.deps/Release/obj.target/multihashing/bcrypt.o.d +4 -0
- package/build/Release/.deps/Release/obj.target/multihashing/blake.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/boolberry.o.d +12 -0
- package/build/Release/.deps/Release/obj.target/multihashing/c11.o.d +20 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/aesb.o.d +3 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_blake256.o.d +5 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_groestl.o.d +10 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_jh.o.d +9 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_keccak.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/c_skein.o.d +10 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/hash.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/oaes_lib.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/crypto/wild_keccak.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_dark.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_dark_lite.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_fast.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_lite.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_soft_shell.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_turtle.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/cryptonight_turtle_lite.o.d +18 -0
- package/build/Release/.deps/Release/obj.target/multihashing/fresh.o.d +10 -0
- package/build/Release/.deps/Release/obj.target/multihashing/fugue.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/groestl.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/hefty1.o.d +12 -0
- package/build/Release/.deps/Release/obj.target/multihashing/keccak.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/multihashing.o.d +155 -0
- package/build/Release/.deps/Release/obj.target/multihashing/nist5.o.d +12 -0
- package/build/Release/.deps/Release/obj.target/multihashing/quark.o.d +14 -0
- package/build/Release/.deps/Release/obj.target/multihashing/qubit.o.d +12 -0
- package/build/Release/.deps/Release/obj.target/multihashing/scryptjane.o.d +30 -0
- package/build/Release/.deps/Release/obj.target/multihashing/scryptn.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha1.o.d +24 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/aes_helper.o.d +5 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/hamsi.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_blake.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_bmw.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_cubehash.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_echo.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_fugue.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_groestl.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_hefty1.o.d +5 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_jh.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_keccak.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_luffa.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_shabal.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_shavite.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_simd.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_skein.o.d +6 -0
- package/build/Release/.deps/Release/obj.target/multihashing/sha3/sph_whirlpool.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/shavite3.o.d +7 -0
- package/build/Release/.deps/Release/obj.target/multihashing/skein.o.d +8 -0
- package/build/Release/.deps/Release/obj.target/multihashing/x11.o.d +20 -0
- package/build/Release/.deps/Release/obj.target/multihashing/x13.o.d +23 -0
- package/build/Release/.deps/Release/obj.target/multihashing/x15.o.d +26 -0
- package/build/Release/.deps/Release/obj.target/multihashing.node.d +1 -0
- package/build/Release/multihashing.node +0 -0
- package/build/binding.Makefile +6 -0
- package/build/multihashing.target.mk +255 -0
- package/c11.c +85 -0
- package/c11.h +17 -0
- package/crypto/aesb.c +177 -0
- package/crypto/c_blake256.c +326 -0
- package/crypto/c_blake256.h +43 -0
- package/crypto/c_groestl.c +360 -0
- package/crypto/c_groestl.h +56 -0
- package/crypto/c_jh.c +367 -0
- package/crypto/c_jh.h +20 -0
- package/crypto/c_keccak.c +112 -0
- package/crypto/c_keccak.h +26 -0
- package/crypto/c_skein.c +2036 -0
- package/crypto/c_skein.h +45 -0
- package/crypto/crypto.h +186 -0
- package/crypto/cryptonote_core/account.cpp +50 -0
- package/crypto/cryptonote_core/account.h +61 -0
- package/crypto/cryptonote_core/cryptonote_basic_impl.cpp +186 -0
- package/crypto/cryptonote_core/cryptonote_basic_impl.h +65 -0
- package/crypto/cryptonote_core/cryptonote_format_utils.cpp +766 -0
- package/crypto/cryptonote_core/cryptonote_format_utils.h +30 -0
- package/crypto/cryptonote_protocol/cryptonote_protocol_defs.h +152 -0
- package/crypto/groestl_tables.h +38 -0
- package/crypto/hash-ops.h +57 -0
- package/crypto/hash.c +24 -0
- package/crypto/hash.h +22 -0
- package/crypto/int-util.h +230 -0
- package/crypto/oaes_config.h +50 -0
- package/crypto/oaes_lib.c +1468 -0
- package/crypto/oaes_lib.h +215 -0
- package/crypto/skein_port.h +190 -0
- package/crypto/variant2_int_sqrt.h +168 -0
- package/crypto/wild_keccak.cpp +119 -0
- package/crypto/wild_keccak.h +168 -0
- package/cryptonight.c +300 -0
- package/cryptonight.h +17 -0
- package/cryptonight_dark.c +300 -0
- package/cryptonight_dark.h +17 -0
- package/cryptonight_dark_lite.c +300 -0
- package/cryptonight_dark_lite.h +17 -0
- package/cryptonight_fast.c +300 -0
- package/cryptonight_fast.h +17 -0
- package/cryptonight_lite.c +300 -0
- package/cryptonight_lite.h +17 -0
- package/cryptonight_soft_shell.c +298 -0
- package/cryptonight_soft_shell.h +17 -0
- package/cryptonight_turtle.c +300 -0
- package/cryptonight_turtle.h +17 -0
- package/cryptonight_turtle_lite.c +300 -0
- package/cryptonight_turtle_lite.h +17 -0
- package/fresh.c +42 -0
- package/fresh.h +16 -0
- package/fugue.c +12 -0
- package/fugue.h +16 -0
- package/groestl.c +40 -0
- package/groestl.h +17 -0
- package/hefty1.c +63 -0
- package/hefty1.h +16 -0
- package/index.js +1 -0
- package/keccak.c +14 -0
- package/keccak.h +16 -0
- package/leocuvee-wrkzcoin-multi-hashing-0.0.20.tgz +0 -0
- package/multihashing.cc +699 -0
- package/nist5.c +46 -0
- package/nist5.h +16 -0
- package/package.json +56 -0
- package/quark.c +210 -0
- package/quark.h +16 -0
- package/qubit.c +45 -0
- package/qubit.h +16 -0
- package/scryptjane/scrypt-jane-chacha.h +132 -0
- package/scryptjane/scrypt-jane-hash.h +48 -0
- package/scryptjane/scrypt-jane-hash_keccak.h +168 -0
- package/scryptjane/scrypt-jane-hash_sha256.h +135 -0
- package/scryptjane/scrypt-jane-mix_chacha-avx.h +340 -0
- package/scryptjane/scrypt-jane-mix_chacha-sse2.h +371 -0
- package/scryptjane/scrypt-jane-mix_chacha-ssse3.h +348 -0
- package/scryptjane/scrypt-jane-mix_chacha.h +69 -0
- package/scryptjane/scrypt-jane-mix_salsa-avx.h +381 -0
- package/scryptjane/scrypt-jane-mix_salsa-sse2.h +443 -0
- package/scryptjane/scrypt-jane-mix_salsa.h +70 -0
- package/scryptjane/scrypt-jane-pbkdf2.h +112 -0
- package/scryptjane/scrypt-jane-portable-x86.h +364 -0
- package/scryptjane/scrypt-jane-portable.h +281 -0
- package/scryptjane/scrypt-jane-romix-basic.h +67 -0
- package/scryptjane/scrypt-jane-romix-template.h +118 -0
- package/scryptjane/scrypt-jane-romix.h +27 -0
- package/scryptjane/scrypt-jane-salsa.h +106 -0
- package/scryptjane/scrypt-jane-test-vectors.h +261 -0
- package/scryptjane.c +223 -0
- package/scryptjane.h +36 -0
- package/scryptn.c +258 -0
- package/scryptn.h +16 -0
- package/sha1.c +65 -0
- package/sha1.h +16 -0
- package/sha256.h +440 -0
- package/sha3/aes_helper.c +392 -0
- package/sha3/hamsi.c +867 -0
- package/sha3/hamsi_helper.c +39648 -0
- package/sha3/md_helper.c +347 -0
- package/sha3/sph_blake.c +1114 -0
- package/sha3/sph_blake.h +327 -0
- package/sha3/sph_bmw.c +965 -0
- package/sha3/sph_bmw.h +328 -0
- package/sha3/sph_cubehash.c +723 -0
- package/sha3/sph_cubehash.h +292 -0
- package/sha3/sph_echo.c +1031 -0
- package/sha3/sph_echo.h +320 -0
- package/sha3/sph_fugue.c +1208 -0
- package/sha3/sph_fugue.h +81 -0
- package/sha3/sph_groestl.c +3119 -0
- package/sha3/sph_groestl.h +329 -0
- package/sha3/sph_hamsi.h +321 -0
- package/sha3/sph_hefty1.c +378 -0
- package/sha3/sph_hefty1.h +66 -0
- package/sha3/sph_jh.c +1116 -0
- package/sha3/sph_jh.h +298 -0
- package/sha3/sph_keccak.c +1824 -0
- package/sha3/sph_keccak.h +293 -0
- package/sha3/sph_luffa.c +1426 -0
- package/sha3/sph_luffa.h +296 -0
- package/sha3/sph_shabal.c +806 -0
- package/sha3/sph_shabal.h +344 -0
- package/sha3/sph_shavite.c +1764 -0
- package/sha3/sph_shavite.h +314 -0
- package/sha3/sph_simd.c +1799 -0
- package/sha3/sph_simd.h +309 -0
- package/sha3/sph_skein.c +1254 -0
- package/sha3/sph_skein.h +298 -0
- package/sha3/sph_types.h +1976 -0
- package/sha3/sph_whirlpool.c +3480 -0
- package/sha3/sph_whirlpool.h +209 -0
- package/shavite3.c +24 -0
- package/shavite3.h +16 -0
- package/skein.c +26 -0
- package/skein.h +16 -0
- package/stdint.h +259 -0
- package/tests/argon2-tests.js +16 -0
- package/tests/benchmark.js +36 -0
- package/tests/cryptonight-tests.js +189 -0
- package/tests/cryptonight_monero.js +53 -0
- package/tests/test.js +16 -0
- package/x11.c +85 -0
- package/x11.h +16 -0
- package/x13.c +97 -0
- package/x13.h +5 -0
- package/x15.c +106 -0
- package/x15.h +16 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* ---------------------------------------------------------------------------
|
|
3
|
+
* OpenAES License
|
|
4
|
+
* ---------------------------------------------------------------------------
|
|
5
|
+
* Copyright (c) 2012, Nabil S. Al Ramli, www.nalramli.com
|
|
6
|
+
* All rights reserved.
|
|
7
|
+
*
|
|
8
|
+
* Redistribution and use in source and binary forms, with or without
|
|
9
|
+
* modification, are permitted provided that the following conditions are met:
|
|
10
|
+
*
|
|
11
|
+
* - Redistributions of source code must retain the above copyright notice,
|
|
12
|
+
* this list of conditions and the following disclaimer.
|
|
13
|
+
* - Redistributions in binary form must reproduce the above copyright
|
|
14
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
15
|
+
* documentation and/or other materials provided with the distribution.
|
|
16
|
+
*
|
|
17
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
18
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
19
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
20
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
21
|
+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
22
|
+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
23
|
+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
24
|
+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
25
|
+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
26
|
+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
27
|
+
* POSSIBILITY OF SUCH DAMAGE.
|
|
28
|
+
* ---------------------------------------------------------------------------
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
#ifndef _OAES_LIB_H
|
|
32
|
+
#define _OAES_LIB_H
|
|
33
|
+
|
|
34
|
+
#include <stdint.h>
|
|
35
|
+
#include <stdlib.h>
|
|
36
|
+
|
|
37
|
+
#ifdef __cplusplus
|
|
38
|
+
extern "C" {
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#ifdef _WIN32
|
|
42
|
+
# ifdef OAES_SHARED
|
|
43
|
+
# ifdef oaes_lib_EXPORTS
|
|
44
|
+
# define OAES_API __declspec(dllexport)
|
|
45
|
+
# else
|
|
46
|
+
# define OAES_API __declspec(dllimport)
|
|
47
|
+
# endif
|
|
48
|
+
# else
|
|
49
|
+
# define OAES_API
|
|
50
|
+
# endif
|
|
51
|
+
#else
|
|
52
|
+
# define OAES_API
|
|
53
|
+
#endif // WIN32
|
|
54
|
+
|
|
55
|
+
#define OAES_VERSION "0.8.1"
|
|
56
|
+
#define OAES_BLOCK_SIZE 16
|
|
57
|
+
|
|
58
|
+
typedef void OAES_CTX;
|
|
59
|
+
|
|
60
|
+
typedef enum
|
|
61
|
+
{
|
|
62
|
+
OAES_RET_FIRST = 0,
|
|
63
|
+
OAES_RET_SUCCESS = 0,
|
|
64
|
+
OAES_RET_UNKNOWN,
|
|
65
|
+
OAES_RET_ARG1,
|
|
66
|
+
OAES_RET_ARG2,
|
|
67
|
+
OAES_RET_ARG3,
|
|
68
|
+
OAES_RET_ARG4,
|
|
69
|
+
OAES_RET_ARG5,
|
|
70
|
+
OAES_RET_NOKEY,
|
|
71
|
+
OAES_RET_MEM,
|
|
72
|
+
OAES_RET_BUF,
|
|
73
|
+
OAES_RET_HEADER,
|
|
74
|
+
OAES_RET_COUNT
|
|
75
|
+
} OAES_RET;
|
|
76
|
+
|
|
77
|
+
/*
|
|
78
|
+
* oaes_set_option() takes one of these values for its [option] parameter
|
|
79
|
+
* some options accept either an optional or a required [value] parameter
|
|
80
|
+
*/
|
|
81
|
+
// no option
|
|
82
|
+
#define OAES_OPTION_NONE 0
|
|
83
|
+
// enable ECB mode, disable CBC mode
|
|
84
|
+
#define OAES_OPTION_ECB 1
|
|
85
|
+
// enable CBC mode, disable ECB mode
|
|
86
|
+
// value is optional, may pass uint8_t iv[OAES_BLOCK_SIZE] to specify
|
|
87
|
+
// the value of the initialization vector, iv
|
|
88
|
+
#define OAES_OPTION_CBC 2
|
|
89
|
+
|
|
90
|
+
#ifdef OAES_DEBUG
|
|
91
|
+
typedef int ( * oaes_step_cb ) (
|
|
92
|
+
const uint8_t state[OAES_BLOCK_SIZE],
|
|
93
|
+
const char * step_name,
|
|
94
|
+
int step_count,
|
|
95
|
+
void * user_data );
|
|
96
|
+
// enable state stepping mode
|
|
97
|
+
// value is required, must pass oaes_step_cb to receive the state at each step
|
|
98
|
+
#define OAES_OPTION_STEP_ON 4
|
|
99
|
+
// disable state stepping mode
|
|
100
|
+
#define OAES_OPTION_STEP_OFF 8
|
|
101
|
+
#endif // OAES_DEBUG
|
|
102
|
+
|
|
103
|
+
typedef uint16_t OAES_OPTION;
|
|
104
|
+
|
|
105
|
+
typedef struct _oaes_key
|
|
106
|
+
{
|
|
107
|
+
size_t data_len;
|
|
108
|
+
uint8_t *data;
|
|
109
|
+
size_t exp_data_len;
|
|
110
|
+
uint8_t *exp_data;
|
|
111
|
+
size_t num_keys;
|
|
112
|
+
size_t key_base;
|
|
113
|
+
} oaes_key;
|
|
114
|
+
|
|
115
|
+
typedef struct _oaes_ctx
|
|
116
|
+
{
|
|
117
|
+
#ifdef OAES_HAVE_ISAAC
|
|
118
|
+
randctx * rctx;
|
|
119
|
+
#endif // OAES_HAVE_ISAAC
|
|
120
|
+
|
|
121
|
+
#ifdef OAES_DEBUG
|
|
122
|
+
oaes_step_cb step_cb;
|
|
123
|
+
#endif // OAES_DEBUG
|
|
124
|
+
|
|
125
|
+
oaes_key * key;
|
|
126
|
+
OAES_OPTION options;
|
|
127
|
+
uint8_t iv[OAES_BLOCK_SIZE];
|
|
128
|
+
} oaes_ctx;
|
|
129
|
+
/*
|
|
130
|
+
* // usage:
|
|
131
|
+
*
|
|
132
|
+
* OAES_CTX * ctx = oaes_alloc();
|
|
133
|
+
* .
|
|
134
|
+
* .
|
|
135
|
+
* .
|
|
136
|
+
* {
|
|
137
|
+
* oaes_gen_key_xxx( ctx );
|
|
138
|
+
* {
|
|
139
|
+
* oaes_key_export( ctx, _buf, &_buf_len );
|
|
140
|
+
* // or
|
|
141
|
+
* oaes_key_export_data( ctx, _buf, &_buf_len );\
|
|
142
|
+
* }
|
|
143
|
+
* }
|
|
144
|
+
* // or
|
|
145
|
+
* {
|
|
146
|
+
* oaes_key_import( ctx, _buf, _buf_len );
|
|
147
|
+
* // or
|
|
148
|
+
* oaes_key_import_data( ctx, _buf, _buf_len );
|
|
149
|
+
* }
|
|
150
|
+
* .
|
|
151
|
+
* .
|
|
152
|
+
* .
|
|
153
|
+
* oaes_encrypt( ctx, m, m_len, c, &c_len );
|
|
154
|
+
* .
|
|
155
|
+
* .
|
|
156
|
+
* .
|
|
157
|
+
* oaes_decrypt( ctx, c, c_len, m, &m_len );
|
|
158
|
+
* .
|
|
159
|
+
* .
|
|
160
|
+
* .
|
|
161
|
+
* oaes_free( &ctx );
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
OAES_API OAES_CTX * oaes_alloc(void);
|
|
165
|
+
|
|
166
|
+
OAES_API OAES_RET oaes_free( OAES_CTX ** ctx );
|
|
167
|
+
|
|
168
|
+
OAES_API OAES_RET oaes_set_option( OAES_CTX * ctx,
|
|
169
|
+
OAES_OPTION option, const void * value );
|
|
170
|
+
|
|
171
|
+
OAES_API OAES_RET oaes_key_gen_128( OAES_CTX * ctx );
|
|
172
|
+
|
|
173
|
+
OAES_API OAES_RET oaes_key_gen_192( OAES_CTX * ctx );
|
|
174
|
+
|
|
175
|
+
OAES_API OAES_RET oaes_key_gen_256( OAES_CTX * ctx );
|
|
176
|
+
|
|
177
|
+
// export key with header information
|
|
178
|
+
// set data == NULL to get the required data_len
|
|
179
|
+
OAES_API OAES_RET oaes_key_export( OAES_CTX * ctx,
|
|
180
|
+
uint8_t * data, size_t * data_len );
|
|
181
|
+
|
|
182
|
+
// directly export the data from key
|
|
183
|
+
// set data == NULL to get the required data_len
|
|
184
|
+
OAES_API OAES_RET oaes_key_export_data( OAES_CTX * ctx,
|
|
185
|
+
uint8_t * data, size_t * data_len );
|
|
186
|
+
|
|
187
|
+
// import key with header information
|
|
188
|
+
OAES_API OAES_RET oaes_key_import( OAES_CTX * ctx,
|
|
189
|
+
const uint8_t * data, size_t data_len );
|
|
190
|
+
|
|
191
|
+
// directly import data into key
|
|
192
|
+
OAES_API OAES_RET oaes_key_import_data( OAES_CTX * ctx,
|
|
193
|
+
const uint8_t * data, size_t data_len );
|
|
194
|
+
|
|
195
|
+
// set c == NULL to get the required c_len
|
|
196
|
+
OAES_API OAES_RET oaes_encrypt( OAES_CTX * ctx,
|
|
197
|
+
const uint8_t * m, size_t m_len, uint8_t * c, size_t * c_len );
|
|
198
|
+
|
|
199
|
+
// set m == NULL to get the required m_len
|
|
200
|
+
OAES_API OAES_RET oaes_decrypt( OAES_CTX * ctx,
|
|
201
|
+
const uint8_t * c, size_t c_len, uint8_t * m, size_t * m_len );
|
|
202
|
+
|
|
203
|
+
// set buf == NULL to get the required buf_len
|
|
204
|
+
OAES_API OAES_RET oaes_sprintf(
|
|
205
|
+
char * buf, size_t * buf_len, const uint8_t * data, size_t data_len );
|
|
206
|
+
|
|
207
|
+
OAES_API OAES_RET oaes_encryption_round( const uint8_t * key, uint8_t * c );
|
|
208
|
+
|
|
209
|
+
OAES_API OAES_RET oaes_pseudo_encrypt_ecb( OAES_CTX * ctx, uint8_t * c );
|
|
210
|
+
|
|
211
|
+
#ifdef __cplusplus
|
|
212
|
+
}
|
|
213
|
+
#endif
|
|
214
|
+
|
|
215
|
+
#endif // _OAES_LIB_H
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#ifndef _SKEIN_PORT_H_
|
|
2
|
+
#define _SKEIN_PORT_H_
|
|
3
|
+
|
|
4
|
+
#include <limits.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
#ifndef RETURN_VALUES
|
|
8
|
+
# define RETURN_VALUES
|
|
9
|
+
# if defined( DLL_EXPORT )
|
|
10
|
+
# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
|
|
11
|
+
# define VOID_RETURN __declspec( dllexport ) void __stdcall
|
|
12
|
+
# define INT_RETURN __declspec( dllexport ) int __stdcall
|
|
13
|
+
# elif defined( __GNUC__ )
|
|
14
|
+
# define VOID_RETURN __declspec( __dllexport__ ) void
|
|
15
|
+
# define INT_RETURN __declspec( __dllexport__ ) int
|
|
16
|
+
# else
|
|
17
|
+
# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
|
|
18
|
+
# endif
|
|
19
|
+
# elif defined( DLL_IMPORT )
|
|
20
|
+
# if defined( _MSC_VER ) || defined ( __INTEL_COMPILER )
|
|
21
|
+
# define VOID_RETURN __declspec( dllimport ) void __stdcall
|
|
22
|
+
# define INT_RETURN __declspec( dllimport ) int __stdcall
|
|
23
|
+
# elif defined( __GNUC__ )
|
|
24
|
+
# define VOID_RETURN __declspec( __dllimport__ ) void
|
|
25
|
+
# define INT_RETURN __declspec( __dllimport__ ) int
|
|
26
|
+
# else
|
|
27
|
+
# error Use of the DLL is only available on the Microsoft, Intel and GCC compilers
|
|
28
|
+
# endif
|
|
29
|
+
# elif defined( __WATCOMC__ )
|
|
30
|
+
# define VOID_RETURN void __cdecl
|
|
31
|
+
# define INT_RETURN int __cdecl
|
|
32
|
+
# else
|
|
33
|
+
# define VOID_RETURN void
|
|
34
|
+
# define INT_RETURN int
|
|
35
|
+
# endif
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
/* These defines are used to declare buffers in a way that allows
|
|
39
|
+
faster operations on longer variables to be used. In all these
|
|
40
|
+
defines 'size' must be a power of 2 and >= 8
|
|
41
|
+
|
|
42
|
+
dec_unit_type(size,x) declares a variable 'x' of length
|
|
43
|
+
'size' bits
|
|
44
|
+
|
|
45
|
+
dec_bufr_type(size,bsize,x) declares a buffer 'x' of length 'bsize'
|
|
46
|
+
bytes defined as an array of variables
|
|
47
|
+
each of 'size' bits (bsize must be a
|
|
48
|
+
multiple of size / 8)
|
|
49
|
+
|
|
50
|
+
ptr_cast(x,size) casts a pointer to a pointer to a
|
|
51
|
+
varaiable of length 'size' bits
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
#define ui_type(size) uint##size##_t
|
|
55
|
+
#define dec_unit_type(size,x) typedef ui_type(size) x
|
|
56
|
+
#define dec_bufr_type(size,bsize,x) typedef ui_type(size) x[bsize / (size >> 3)]
|
|
57
|
+
#define ptr_cast(x,size) ((ui_type(size)*)(x))
|
|
58
|
+
|
|
59
|
+
typedef unsigned int uint_t; /* native unsigned integer */
|
|
60
|
+
typedef uint8_t u08b_t; /* 8-bit unsigned integer */
|
|
61
|
+
typedef uint64_t u64b_t; /* 64-bit unsigned integer */
|
|
62
|
+
|
|
63
|
+
#ifndef RotL_64
|
|
64
|
+
#define RotL_64(x,N) (((x) << (N)) | ((x) >> (64-(N))))
|
|
65
|
+
#endif
|
|
66
|
+
|
|
67
|
+
/*
|
|
68
|
+
* Skein is "natively" little-endian (unlike SHA-xxx), for optimal
|
|
69
|
+
* performance on x86 CPUs. The Skein code requires the following
|
|
70
|
+
* definitions for dealing with endianness:
|
|
71
|
+
*
|
|
72
|
+
* SKEIN_NEED_SWAP: 0 for little-endian, 1 for big-endian
|
|
73
|
+
* Skein_Put64_LSB_First
|
|
74
|
+
* Skein_Get64_LSB_First
|
|
75
|
+
* Skein_Swap64
|
|
76
|
+
*
|
|
77
|
+
* If SKEIN_NEED_SWAP is defined at compile time, it is used here
|
|
78
|
+
* along with the portable versions of Put64/Get64/Swap64, which
|
|
79
|
+
* are slow in general.
|
|
80
|
+
*
|
|
81
|
+
* Otherwise, an "auto-detect" of endianness is attempted below.
|
|
82
|
+
* If the default handling doesn't work well, the user may insert
|
|
83
|
+
* platform-specific code instead (e.g., for big-endian CPUs).
|
|
84
|
+
*
|
|
85
|
+
*/
|
|
86
|
+
#ifndef SKEIN_NEED_SWAP /* compile-time "override" for endianness? */
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
#include "int-util.h"
|
|
90
|
+
|
|
91
|
+
#define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */
|
|
92
|
+
#define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */
|
|
93
|
+
|
|
94
|
+
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
95
|
+
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
|
96
|
+
#endif
|
|
97
|
+
|
|
98
|
+
#if BYTE_ORDER == BIG_ENDIAN
|
|
99
|
+
# define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN
|
|
100
|
+
#endif
|
|
101
|
+
|
|
102
|
+
/* special handler for IA64, which may be either endianness (?) */
|
|
103
|
+
/* here we assume little-endian, but this may need to be changed */
|
|
104
|
+
#if defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
|
|
105
|
+
# define PLATFORM_MUST_ALIGN (1)
|
|
106
|
+
#ifndef PLATFORM_BYTE_ORDER
|
|
107
|
+
# define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN
|
|
108
|
+
#endif
|
|
109
|
+
#endif
|
|
110
|
+
|
|
111
|
+
#ifndef PLATFORM_MUST_ALIGN
|
|
112
|
+
# define PLATFORM_MUST_ALIGN (0)
|
|
113
|
+
#endif
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
#if PLATFORM_BYTE_ORDER == IS_BIG_ENDIAN
|
|
117
|
+
/* here for big-endian CPUs */
|
|
118
|
+
#define SKEIN_NEED_SWAP (1)
|
|
119
|
+
#elif PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN
|
|
120
|
+
/* here for x86 and x86-64 CPUs (and other detected little-endian CPUs) */
|
|
121
|
+
#define SKEIN_NEED_SWAP (0)
|
|
122
|
+
#if PLATFORM_MUST_ALIGN == 0 /* ok to use "fast" versions? */
|
|
123
|
+
#define Skein_Put64_LSB_First(dst08,src64,bCnt) memcpy(dst08,src64,bCnt)
|
|
124
|
+
#define Skein_Get64_LSB_First(dst64,src08,wCnt) memcpy(dst64,src08,8*(wCnt))
|
|
125
|
+
#endif
|
|
126
|
+
#else
|
|
127
|
+
#error "Skein needs endianness setting!"
|
|
128
|
+
#endif
|
|
129
|
+
|
|
130
|
+
#endif /* ifndef SKEIN_NEED_SWAP */
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
******************************************************************
|
|
134
|
+
* Provide any definitions still needed.
|
|
135
|
+
******************************************************************
|
|
136
|
+
*/
|
|
137
|
+
#ifndef Skein_Swap64 /* swap for big-endian, nop for little-endian */
|
|
138
|
+
#if SKEIN_NEED_SWAP
|
|
139
|
+
#define Skein_Swap64(w64) \
|
|
140
|
+
( (( ((u64b_t)(w64)) & 0xFF) << 56) | \
|
|
141
|
+
(((((u64b_t)(w64)) >> 8) & 0xFF) << 48) | \
|
|
142
|
+
(((((u64b_t)(w64)) >>16) & 0xFF) << 40) | \
|
|
143
|
+
(((((u64b_t)(w64)) >>24) & 0xFF) << 32) | \
|
|
144
|
+
(((((u64b_t)(w64)) >>32) & 0xFF) << 24) | \
|
|
145
|
+
(((((u64b_t)(w64)) >>40) & 0xFF) << 16) | \
|
|
146
|
+
(((((u64b_t)(w64)) >>48) & 0xFF) << 8) | \
|
|
147
|
+
(((((u64b_t)(w64)) >>56) & 0xFF) ) )
|
|
148
|
+
#else
|
|
149
|
+
#define Skein_Swap64(w64) (w64)
|
|
150
|
+
#endif
|
|
151
|
+
#endif /* ifndef Skein_Swap64 */
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
#ifndef Skein_Put64_LSB_First
|
|
155
|
+
void Skein_Put64_LSB_First(u08b_t *dst,const u64b_t *src,size_t bCnt)
|
|
156
|
+
#ifdef SKEIN_PORT_CODE /* instantiate the function code here? */
|
|
157
|
+
{ /* this version is fully portable (big-endian or little-endian), but slow */
|
|
158
|
+
size_t n;
|
|
159
|
+
|
|
160
|
+
for (n=0;n<bCnt;n++)
|
|
161
|
+
dst[n] = (u08b_t) (src[n>>3] >> (8*(n&7)));
|
|
162
|
+
}
|
|
163
|
+
#else
|
|
164
|
+
; /* output only the function prototype */
|
|
165
|
+
#endif
|
|
166
|
+
#endif /* ifndef Skein_Put64_LSB_First */
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
#ifndef Skein_Get64_LSB_First
|
|
170
|
+
void Skein_Get64_LSB_First(u64b_t *dst,const u08b_t *src,size_t wCnt)
|
|
171
|
+
#ifdef SKEIN_PORT_CODE /* instantiate the function code here? */
|
|
172
|
+
{ /* this version is fully portable (big-endian or little-endian), but slow */
|
|
173
|
+
size_t n;
|
|
174
|
+
|
|
175
|
+
for (n=0;n<8*wCnt;n+=8)
|
|
176
|
+
dst[n/8] = (((u64b_t) src[n ]) ) +
|
|
177
|
+
(((u64b_t) src[n+1]) << 8) +
|
|
178
|
+
(((u64b_t) src[n+2]) << 16) +
|
|
179
|
+
(((u64b_t) src[n+3]) << 24) +
|
|
180
|
+
(((u64b_t) src[n+4]) << 32) +
|
|
181
|
+
(((u64b_t) src[n+5]) << 40) +
|
|
182
|
+
(((u64b_t) src[n+6]) << 48) +
|
|
183
|
+
(((u64b_t) src[n+7]) << 56) ;
|
|
184
|
+
}
|
|
185
|
+
#else
|
|
186
|
+
; /* output only the function prototype */
|
|
187
|
+
#endif
|
|
188
|
+
#endif /* ifndef Skein_Get64_LSB_First */
|
|
189
|
+
|
|
190
|
+
#endif /* ifndef _SKEIN_PORT_H_ */
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
#ifndef VARIANT2_INT_SQRT_H
|
|
2
|
+
#define VARIANT2_INT_SQRT_H
|
|
3
|
+
|
|
4
|
+
#include <math.h>
|
|
5
|
+
#include <float.h>
|
|
6
|
+
|
|
7
|
+
#define VARIANT2_INTEGER_MATH_SQRT_STEP_SSE2() \
|
|
8
|
+
do { \
|
|
9
|
+
const __m128i exp_double_bias = _mm_set_epi64x(0, 1023ULL << 52); \
|
|
10
|
+
__m128d x = _mm_castsi128_pd(_mm_add_epi64(_mm_cvtsi64_si128(sqrt_input >> 12), exp_double_bias)); \
|
|
11
|
+
x = _mm_sqrt_sd(_mm_setzero_pd(), x); \
|
|
12
|
+
sqrt_result = (uint64_t)(_mm_cvtsi128_si64(_mm_sub_epi64(_mm_castpd_si128(x), exp_double_bias))) >> 19; \
|
|
13
|
+
} while(0)
|
|
14
|
+
|
|
15
|
+
#define VARIANT2_INTEGER_MATH_SQRT_STEP_FP64() \
|
|
16
|
+
do { \
|
|
17
|
+
sqrt_result = sqrt(sqrt_input + 18446744073709551616.0) * 2.0 - 8589934592.0; \
|
|
18
|
+
} while(0)
|
|
19
|
+
|
|
20
|
+
//#define VARIANT2_INTEGER_MATH_SQRT_STEP_REF() \
|
|
21
|
+
// sqrt_result = integer_square_root_v2(sqrt_input)
|
|
22
|
+
|
|
23
|
+
// Reference implementation of the integer square root for Cryptonight variant 2
|
|
24
|
+
// Computes integer part of "sqrt(2^64 + n) * 2 - 2^33"
|
|
25
|
+
//
|
|
26
|
+
// In other words, given 64-bit unsigned integer n:
|
|
27
|
+
// 1) Write it as x = 1.NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN000... in binary (1 <= x < 2, all 64 bits of n are used)
|
|
28
|
+
// 2) Calculate sqrt(x) = 1.0RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR... (1 <= sqrt(x) < sqrt(2), so it will always start with "1.0" in binary)
|
|
29
|
+
// 3) Take 32 bits that come after "1.0" and return them as a 32-bit unsigned integer, discard all remaining bits
|
|
30
|
+
//
|
|
31
|
+
// Some sample inputs and outputs:
|
|
32
|
+
//
|
|
33
|
+
// Input | Output | Exact value of "sqrt(2^64 + n) * 2 - 2^33"
|
|
34
|
+
// -----------------|------------|-------------------------------------------
|
|
35
|
+
// 0 | 0 | 0
|
|
36
|
+
// 2^32 | 0 | 0.99999999994179233909330885695244...
|
|
37
|
+
// 2^32 + 1 | 1 | 1.0000000001746229827200734316305...
|
|
38
|
+
// 2^50 | 262140 | 262140.00012206565608606978175873...
|
|
39
|
+
// 2^55 + 20963331 | 8384515 | 8384515.9999999997673963974959744...
|
|
40
|
+
// 2^55 + 20963332 | 8384516 | 8384516
|
|
41
|
+
// 2^62 + 26599786 | 1013904242 | 1013904242.9999999999479374853545...
|
|
42
|
+
// 2^62 + 26599787 | 1013904243 | 1013904243.0000000001561875439364...
|
|
43
|
+
// 2^64 - 1 | 3558067407 | 3558067407.9041987696409179931096...
|
|
44
|
+
|
|
45
|
+
// The reference implementation as it is now uses only unsigned int64 arithmetic, so it can't have undefined behavior
|
|
46
|
+
// It was tested once for all edge cases and confirmed correct
|
|
47
|
+
//
|
|
48
|
+
// !!! Note: if you're modifying this code, uncomment the test in monero/tests/hash/main.cpp !!!
|
|
49
|
+
//
|
|
50
|
+
/*
|
|
51
|
+
static inline uint64_t integer_square_root_v2(uint64_t n)
|
|
52
|
+
{
|
|
53
|
+
uint64_t r = 1ULL << 63;
|
|
54
|
+
|
|
55
|
+
for (uint64_t bit = 1ULL << 60; bit; bit >>= 2)
|
|
56
|
+
{
|
|
57
|
+
const bool b = (n < r + bit);
|
|
58
|
+
const uint64_t n_next = n - (r + bit);
|
|
59
|
+
const uint64_t r_next = r + bit * 2;
|
|
60
|
+
n = b ? n : n_next;
|
|
61
|
+
r = b ? r : r_next;
|
|
62
|
+
r >>= 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return r * 2 + ((n > r) ? 1 : 0);
|
|
66
|
+
}
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
VARIANT2_INTEGER_MATH_SQRT_FIXUP checks that "r" is an integer part of "sqrt(2^64 + sqrt_input) * 2 - 2^33" and adds or subtracts 1 if needed
|
|
71
|
+
It's hard to understand how it works, so here is a full calculation of formulas used in VARIANT2_INTEGER_MATH_SQRT_FIXUP
|
|
72
|
+
|
|
73
|
+
The following inequalities must hold for r if it's an integer part of "sqrt(2^64 + sqrt_input) * 2 - 2^33":
|
|
74
|
+
1) r <= sqrt(2^64 + sqrt_input) * 2 - 2^33
|
|
75
|
+
2) r + 1 > sqrt(2^64 + sqrt_input) * 2 - 2^33
|
|
76
|
+
|
|
77
|
+
We need to check them using only unsigned integer arithmetic to avoid rounding errors and undefined behavior
|
|
78
|
+
|
|
79
|
+
First inequality: r <= sqrt(2^64 + sqrt_input) * 2 - 2^33
|
|
80
|
+
-----------------------------------------------------------------------------------
|
|
81
|
+
r <= sqrt(2^64 + sqrt_input) * 2 - 2^33
|
|
82
|
+
r + 2^33 <= sqrt(2^64 + sqrt_input) * 2
|
|
83
|
+
r/2 + 2^32 <= sqrt(2^64 + sqrt_input)
|
|
84
|
+
(r/2 + 2^32)^2 <= 2^64 + sqrt_input
|
|
85
|
+
|
|
86
|
+
Rewrite r as r = s * 2 + b (s = trunc(r/2), b is 0 or 1)
|
|
87
|
+
|
|
88
|
+
((s*2+b)/2 + 2^32)^2 <= 2^64 + sqrt_input
|
|
89
|
+
(s*2+b)^2/4 + 2*2^32*(s*2+b)/2 + 2^64 <= 2^64 + sqrt_input
|
|
90
|
+
(s*2+b)^2/4 + 2*2^32*(s*2+b)/2 <= sqrt_input
|
|
91
|
+
(s*2+b)^2/4 + 2^32*r <= sqrt_input
|
|
92
|
+
(s^2*4+2*s*2*b+b^2)/4 + 2^32*r <= sqrt_input
|
|
93
|
+
s^2+s*b+b^2/4 + 2^32*r <= sqrt_input
|
|
94
|
+
s*(s+b) + b^2/4 + 2^32*r <= sqrt_input
|
|
95
|
+
|
|
96
|
+
Let r2 = s*(s+b) + r*2^32
|
|
97
|
+
r2 + b^2/4 <= sqrt_input
|
|
98
|
+
|
|
99
|
+
If this inequality doesn't hold, then we must decrement r: IF "r2 + b^2/4 > sqrt_input" THEN r = r - 1
|
|
100
|
+
|
|
101
|
+
b can be 0 or 1
|
|
102
|
+
If b is 0 then we need to compare "r2 > sqrt_input"
|
|
103
|
+
If b is 1 then b^2/4 = 0.25, so we need to compare "r2 + 0.25 > sqrt_input"
|
|
104
|
+
Since both r2 and sqrt_input are integers, we can safely replace it with "r2 + 1 > sqrt_input"
|
|
105
|
+
-----------------------------------------------------------------------------------
|
|
106
|
+
Both cases can be merged to a single expression "r2 + b > sqrt_input"
|
|
107
|
+
-----------------------------------------------------------------------------------
|
|
108
|
+
There will be no overflow when calculating "r2 + b", so it's safe to compare with sqrt_input:
|
|
109
|
+
r2 + b = s*(s+b) + r*2^32 + b
|
|
110
|
+
The largest value s, b and r can have is s = 1779033703, b = 1, r = 3558067407 when sqrt_input = 2^64 - 1
|
|
111
|
+
r2 + b <= 1779033703*1779033704 + 3558067407*2^32 + 1 = 18446744068217447385 < 2^64
|
|
112
|
+
|
|
113
|
+
Second inequality: r + 1 > sqrt(2^64 + sqrt_input) * 2 - 2^33
|
|
114
|
+
-----------------------------------------------------------------------------------
|
|
115
|
+
r + 1 > sqrt(2^64 + sqrt_input) * 2 - 2^33
|
|
116
|
+
r + 1 + 2^33 > sqrt(2^64 + sqrt_input) * 2
|
|
117
|
+
((r+1)/2 + 2^32)^2 > 2^64 + sqrt_input
|
|
118
|
+
|
|
119
|
+
Rewrite r as r = s * 2 + b (s = trunc(r/2), b is 0 or 1)
|
|
120
|
+
|
|
121
|
+
((s*2+b+1)/2 + 2^32)^2 > 2^64 + sqrt_input
|
|
122
|
+
(s*2+b+1)^2/4 + 2*(s*2+b+1)/2*2^32 + 2^64 > 2^64 + sqrt_input
|
|
123
|
+
(s*2+b+1)^2/4 + (s*2+b+1)*2^32 > sqrt_input
|
|
124
|
+
(s*2+b+1)^2/4 + (r+1)*2^32 > sqrt_input
|
|
125
|
+
(s*2+(b+1))^2/4 + r*2^32 + 2^32 > sqrt_input
|
|
126
|
+
(s^2*4+2*s*2*(b+1)+(b+1)^2)/4 + r*2^32 + 2^32 > sqrt_input
|
|
127
|
+
s^2+s*(b+1)+(b+1)^2/4 + r*2^32 + 2^32 > sqrt_input
|
|
128
|
+
s*(s+b) + s + (b+1)^2/4 + r*2^32 + 2^32 > sqrt_input
|
|
129
|
+
|
|
130
|
+
Let r2 = s*(s+b) + r*2^32
|
|
131
|
+
|
|
132
|
+
r2 + s + (b+1)^2/4 + 2^32 > sqrt_input
|
|
133
|
+
r2 + 2^32 + (b+1)^2/4 > sqrt_input - s
|
|
134
|
+
|
|
135
|
+
If this inequality doesn't hold, then we must decrement r: IF "r2 + 2^32 + (b+1)^2/4 <= sqrt_input - s" THEN r = r - 1
|
|
136
|
+
b can be 0 or 1
|
|
137
|
+
If b is 0 then we need to compare "r2 + 2^32 + 1/4 <= sqrt_input - s" which is equal to "r2 + 2^32 < sqrt_input - s" because all numbers here are integers
|
|
138
|
+
If b is 1 then (b+1)^2/4 = 1, so we need to compare "r2 + 2^32 + 1 <= sqrt_input - s" which is also equal to "r2 + 2^32 < sqrt_input - s"
|
|
139
|
+
-----------------------------------------------------------------------------------
|
|
140
|
+
Both cases can be merged to a single expression "r2 + 2^32 < sqrt_input - s"
|
|
141
|
+
-----------------------------------------------------------------------------------
|
|
142
|
+
There will be no overflow when calculating "r2 + 2^32":
|
|
143
|
+
r2 + 2^32 = s*(s+b) + r*2^32 + 2^32 = s*(s+b) + (r+1)*2^32
|
|
144
|
+
The largest value s, b and r can have is s = 1779033703, b = 1, r = 3558067407 when sqrt_input = 2^64 - 1
|
|
145
|
+
r2 + b <= 1779033703*1779033704 + 3558067408*2^32 = 18446744072512414680 < 2^64
|
|
146
|
+
|
|
147
|
+
There will be no integer overflow when calculating "sqrt_input - s", i.e. "sqrt_input >= s" at all times:
|
|
148
|
+
s = trunc(r/2) = trunc(sqrt(2^64 + sqrt_input) - 2^32) < sqrt(2^64 + sqrt_input) - 2^32 + 1
|
|
149
|
+
sqrt_input > sqrt(2^64 + sqrt_input) - 2^32 + 1
|
|
150
|
+
sqrt_input + 2^32 - 1 > sqrt(2^64 + sqrt_input)
|
|
151
|
+
(sqrt_input + 2^32 - 1)^2 > sqrt_input + 2^64
|
|
152
|
+
sqrt_input^2 + 2*sqrt_input*(2^32 - 1) + (2^32-1)^2 > sqrt_input + 2^64
|
|
153
|
+
sqrt_input^2 + sqrt_input*(2^33 - 2) + (2^32-1)^2 > sqrt_input + 2^64
|
|
154
|
+
sqrt_input^2 + sqrt_input*(2^33 - 3) + (2^32-1)^2 > 2^64
|
|
155
|
+
sqrt_input^2 + sqrt_input*(2^33 - 3) + 2^64-2^33+1 > 2^64
|
|
156
|
+
sqrt_input^2 + sqrt_input*(2^33 - 3) - 2^33 + 1 > 0
|
|
157
|
+
This inequality is true if sqrt_input > 1 and it's easy to check that s = 0 if sqrt_input is 0 or 1, so there will be no integer overflow
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
#define VARIANT2_INTEGER_MATH_SQRT_FIXUP(r) \
|
|
161
|
+
do { \
|
|
162
|
+
const uint64_t s = r >> 1; \
|
|
163
|
+
const uint64_t b = r & 1; \
|
|
164
|
+
const uint64_t r2 = (uint64_t)(s) * (s + b) + (r << 32); \
|
|
165
|
+
r += ((r2 + b > sqrt_input) ? -1 : 0) + ((r2 + (1ULL << 32) < sqrt_input - s) ? 1 : 0); \
|
|
166
|
+
} while(0)
|
|
167
|
+
|
|
168
|
+
#endif
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// keccak.c
|
|
2
|
+
// 19-Nov-11 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
|
3
|
+
// A baseline Keccak (3rd round) implementation.
|
|
4
|
+
|
|
5
|
+
// Memory-hard extension of keccak for PoW
|
|
6
|
+
// Copyright (c) 2014 The Boolberry developers
|
|
7
|
+
// Distributed under the MIT/X11 software license, see the accompanying
|
|
8
|
+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
#include "wild_keccak.h"
|
|
12
|
+
namespace crypto
|
|
13
|
+
{
|
|
14
|
+
|
|
15
|
+
const uint64_t keccakf_rndc[24] =
|
|
16
|
+
{
|
|
17
|
+
0x0000000000000001, 0x0000000000008082, 0x800000000000808a,
|
|
18
|
+
0x8000000080008000, 0x000000000000808b, 0x0000000080000001,
|
|
19
|
+
0x8000000080008081, 0x8000000000008009, 0x000000000000008a,
|
|
20
|
+
0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
|
|
21
|
+
0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
|
|
22
|
+
0x8000000000008003, 0x8000000000008002, 0x8000000000000080,
|
|
23
|
+
0x000000000000800a, 0x800000008000000a, 0x8000000080008081,
|
|
24
|
+
0x8000000000008080, 0x0000000080000001, 0x8000000080008008
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const int keccakf_rotc[24] =
|
|
28
|
+
{
|
|
29
|
+
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14,
|
|
30
|
+
27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const int keccakf_piln[24] =
|
|
34
|
+
{
|
|
35
|
+
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4,
|
|
36
|
+
15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// update the state with given number of rounds
|
|
40
|
+
void regular_f::keccakf(uint64_t st[25], int rounds)
|
|
41
|
+
{
|
|
42
|
+
int i, j, round;
|
|
43
|
+
uint64_t t, bc[5];
|
|
44
|
+
|
|
45
|
+
for (round = 0; round < rounds; round++) {
|
|
46
|
+
|
|
47
|
+
// Theta
|
|
48
|
+
for (i = 0; i < 5; i++)
|
|
49
|
+
bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] ^ st[i + 15] ^ st[i + 20];
|
|
50
|
+
|
|
51
|
+
for (i = 0; i < 5; i++) {
|
|
52
|
+
t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1);
|
|
53
|
+
for (j = 0; j < 25; j += 5)
|
|
54
|
+
st[j + i] ^= t;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Rho Pi
|
|
58
|
+
t = st[1];
|
|
59
|
+
for (i = 0; i < 24; i++) {
|
|
60
|
+
j = keccakf_piln[i];
|
|
61
|
+
bc[0] = st[j];
|
|
62
|
+
st[j] = ROTL64(t, keccakf_rotc[i]);
|
|
63
|
+
t = bc[0];
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Chi
|
|
67
|
+
for (j = 0; j < 25; j += 5) {
|
|
68
|
+
for (i = 0; i < 5; i++)
|
|
69
|
+
bc[i] = st[j + i];
|
|
70
|
+
for (i = 0; i < 5; i++)
|
|
71
|
+
st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Iota
|
|
75
|
+
st[0] ^= keccakf_rndc[round];
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
void mul_f::keccakf(uint64_t st[25], int rounds)
|
|
80
|
+
{
|
|
81
|
+
int i, j, round;
|
|
82
|
+
uint64_t t, bc[5];
|
|
83
|
+
|
|
84
|
+
for (round = 0; round < rounds; round++) {
|
|
85
|
+
|
|
86
|
+
// Theta
|
|
87
|
+
for (i = 0; i < 5; i++)
|
|
88
|
+
{
|
|
89
|
+
bc[i] = st[i] ^ st[i + 5] ^ st[i + 10] * st[i + 15] * st[i + 20];//surprise
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
for (i = 0; i < 5; i++) {
|
|
93
|
+
t = bc[(i + 4) % 5] ^ ROTL64(bc[(i + 1) % 5], 1);
|
|
94
|
+
for (j = 0; j < 25; j += 5)
|
|
95
|
+
st[j + i] ^= t;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Rho Pi
|
|
99
|
+
t = st[1];
|
|
100
|
+
for (i = 0; i < 24; i++) {
|
|
101
|
+
j = keccakf_piln[i];
|
|
102
|
+
bc[0] = st[j];
|
|
103
|
+
st[j] = ROTL64(t, keccakf_rotc[i]);
|
|
104
|
+
t = bc[0];
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Chi
|
|
108
|
+
for (j = 0; j < 25; j += 5) {
|
|
109
|
+
for (i = 0; i < 5; i++)
|
|
110
|
+
bc[i] = st[j + i];
|
|
111
|
+
for (i = 0; i < 5; i++)
|
|
112
|
+
st[j + i] ^= (~bc[(i + 1) % 5]) & bc[(i + 2) % 5];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Iota
|
|
116
|
+
st[0] ^= keccakf_rndc[round];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|