@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,364 @@
|
|
|
1
|
+
#if defined(CPU_X86) && (defined(COMPILER_MSVC) || defined(COMPILER_GCC))
|
|
2
|
+
#define X86ASM
|
|
3
|
+
/* gcc 2.95 royally screws up stack alignments on variables */
|
|
4
|
+
#if (defined(COMPILER_MSVC6PP_AND_LATER) || (defined(COMPILER_GCC) && (COMPILER_GCC >= 30000)))
|
|
5
|
+
#define X86ASM_SSE
|
|
6
|
+
#define X86ASM_SSE2
|
|
7
|
+
#endif
|
|
8
|
+
#if ((defined(COMPILER_MSVC) && (COMPILER_MSVC >= 1400)) || (defined(COMPILER_GCC) && (COMPILER_GCC >= 40102)))
|
|
9
|
+
#define X86ASM_SSSE3
|
|
10
|
+
#endif
|
|
11
|
+
#if ((defined(COMPILER_GCC) && (COMPILER_GCC >= 40400)))
|
|
12
|
+
#define X86ASM_AVX
|
|
13
|
+
#endif
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#if defined(CPU_X86_64) && defined(COMPILER_GCC)
|
|
17
|
+
#define X86_64ASM
|
|
18
|
+
#define X86_64ASM_SSE2
|
|
19
|
+
#if (COMPILER_GCC >= 40102)
|
|
20
|
+
#define X86_64ASM_SSSE3
|
|
21
|
+
#endif
|
|
22
|
+
#if (COMPILER_GCC >= 40400)
|
|
23
|
+
#define X86_64ASM_AVX
|
|
24
|
+
#endif
|
|
25
|
+
#endif
|
|
26
|
+
|
|
27
|
+
#if defined(COMPILER_MSVC)
|
|
28
|
+
#define X86_INTRINSIC
|
|
29
|
+
#if defined(CPU_X86_64) || defined(X86ASM_SSE)
|
|
30
|
+
#define X86_INTRINSIC_SSE
|
|
31
|
+
#endif
|
|
32
|
+
#if defined(CPU_X86_64) || defined(X86ASM_SSE2)
|
|
33
|
+
#define X86_INTRINSIC_SSE2
|
|
34
|
+
#endif
|
|
35
|
+
#if (COMPILER_MSVC >= 1400)
|
|
36
|
+
#define X86_INTRINSIC_SSSE3
|
|
37
|
+
#endif
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
#if defined(COMPILER_MSVC) && defined(CPU_X86_64)
|
|
41
|
+
#define X86_64USE_INTRINSIC
|
|
42
|
+
#endif
|
|
43
|
+
|
|
44
|
+
#if defined(COMPILER_MSVC) && defined(CPU_X86_64)
|
|
45
|
+
#define X86_64USE_INTRINSIC
|
|
46
|
+
#endif
|
|
47
|
+
|
|
48
|
+
#if defined(COMPILER_GCC) && defined(CPU_X86_FORCE_INTRINSICS)
|
|
49
|
+
#define X86_INTRINSIC
|
|
50
|
+
#if defined(__SSE__)
|
|
51
|
+
#define X86_INTRINSIC_SSE
|
|
52
|
+
#endif
|
|
53
|
+
#if defined(__SSE2__)
|
|
54
|
+
#define X86_INTRINSIC_SSE2
|
|
55
|
+
#endif
|
|
56
|
+
#if defined(__SSSE3__)
|
|
57
|
+
#define X86_INTRINSIC_SSSE3
|
|
58
|
+
#endif
|
|
59
|
+
#if defined(__AVX__)
|
|
60
|
+
#define X86_INTRINSIC_AVX
|
|
61
|
+
#endif
|
|
62
|
+
#endif
|
|
63
|
+
|
|
64
|
+
/* only use simd on windows (or SSE2 on gcc)! */
|
|
65
|
+
#if defined(CPU_X86_FORCE_INTRINSICS) || defined(X86_INTRINSIC)
|
|
66
|
+
#if defined(X86_INTRINSIC_SSE)
|
|
67
|
+
#define X86_INTRINSIC
|
|
68
|
+
#include <mmintrin.h>
|
|
69
|
+
#include <xmmintrin.h>
|
|
70
|
+
typedef __m64 qmm;
|
|
71
|
+
typedef __m128 xmm;
|
|
72
|
+
typedef __m128d xmmd;
|
|
73
|
+
#endif
|
|
74
|
+
#if defined(X86_INTRINSIC_SSE2)
|
|
75
|
+
#define X86_INTRINSIC_SSE2
|
|
76
|
+
#include <emmintrin.h>
|
|
77
|
+
typedef __m128i xmmi;
|
|
78
|
+
#endif
|
|
79
|
+
#if defined(X86_INTRINSIC_SSSE3)
|
|
80
|
+
#define X86_INTRINSIC_SSSE3
|
|
81
|
+
#include <tmmintrin.h>
|
|
82
|
+
#endif
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
#if defined(X86_INTRINSIC_SSE2)
|
|
87
|
+
typedef union packedelem8_t {
|
|
88
|
+
uint8_t u[16];
|
|
89
|
+
xmmi v;
|
|
90
|
+
} packedelem8;
|
|
91
|
+
|
|
92
|
+
typedef union packedelem32_t {
|
|
93
|
+
uint32_t u[4];
|
|
94
|
+
xmmi v;
|
|
95
|
+
} packedelem32;
|
|
96
|
+
|
|
97
|
+
typedef union packedelem64_t {
|
|
98
|
+
uint64_t u[2];
|
|
99
|
+
xmmi v;
|
|
100
|
+
} packedelem64;
|
|
101
|
+
#else
|
|
102
|
+
typedef union packedelem8_t {
|
|
103
|
+
uint8_t u[16];
|
|
104
|
+
uint32_t dw[4];
|
|
105
|
+
} packedelem8;
|
|
106
|
+
|
|
107
|
+
typedef union packedelem32_t {
|
|
108
|
+
uint32_t u[4];
|
|
109
|
+
uint8_t b[16];
|
|
110
|
+
} packedelem32;
|
|
111
|
+
|
|
112
|
+
typedef union packedelem64_t {
|
|
113
|
+
uint64_t u[2];
|
|
114
|
+
uint8_t b[16];
|
|
115
|
+
} packedelem64;
|
|
116
|
+
#endif
|
|
117
|
+
|
|
118
|
+
#if defined(X86_INTRINSIC_SSSE3) || defined(X86ASM_SSSE3) || defined(X86_64ASM_SSSE3)
|
|
119
|
+
const packedelem8 MM16 ssse3_rotr16_64bit = {{2,3,4,5,6,7,0,1,10,11,12,13,14,15,8,9}};
|
|
120
|
+
const packedelem8 MM16 ssse3_rotl16_32bit = {{2,3,0,1,6,7,4,5,10,11,8,9,14,15,12,13}};
|
|
121
|
+
const packedelem8 MM16 ssse3_rotl8_32bit = {{3,0,1,2,7,4,5,6,11,8,9,10,15,12,13,14}};
|
|
122
|
+
const packedelem8 MM16 ssse3_endian_swap_64bit = {{7,6,5,4,3,2,1,0,15,14,13,12,11,10,9,8}};
|
|
123
|
+
#endif
|
|
124
|
+
|
|
125
|
+
/*
|
|
126
|
+
x86 inline asm for gcc/msvc. usage:
|
|
127
|
+
|
|
128
|
+
asm_naked_fn_proto(return_type, name) (type parm1, type parm2..)
|
|
129
|
+
asm_naked_fn(name)
|
|
130
|
+
a1(..)
|
|
131
|
+
a2(.., ..)
|
|
132
|
+
a3(.., .., ..)
|
|
133
|
+
a1(ret)
|
|
134
|
+
asm_naked_fn_end(name)
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
#if defined(X86ASM) || defined(X86_64ASM)
|
|
138
|
+
|
|
139
|
+
#if defined(COMPILER_MSVC)
|
|
140
|
+
#pragma warning(disable : 4731) /* frame pointer modified by inline assembly */
|
|
141
|
+
#define a1(x) __asm {x}
|
|
142
|
+
#define a2(x, y) __asm {x, y}
|
|
143
|
+
#define a3(x, y, z) __asm {x, y, z}
|
|
144
|
+
#define a4(x, y, z, w) __asm {x, y, z, w}
|
|
145
|
+
#define al(x) __asm {label##x:}
|
|
146
|
+
#define aj(x, y, z) __asm {x label##y}
|
|
147
|
+
#define asm_align8 a1(ALIGN 8)
|
|
148
|
+
#define asm_align16 a1(ALIGN 16)
|
|
149
|
+
|
|
150
|
+
#define asm_naked_fn_proto(type, fn) static NAKED type STDCALL fn
|
|
151
|
+
#define asm_naked_fn(fn) {
|
|
152
|
+
#define asm_naked_fn_end(fn) }
|
|
153
|
+
#elif defined(COMPILER_GCC)
|
|
154
|
+
#define GNU_AS1(x) #x ";\n"
|
|
155
|
+
#define GNU_AS2(x, y) #x ", " #y ";\n"
|
|
156
|
+
#define GNU_AS3(x, y, z) #x ", " #y ", " #z ";\n"
|
|
157
|
+
#define GNU_AS4(x, y, z, w) #x ", " #y ", " #z ", " #w ";\n"
|
|
158
|
+
#define GNU_ASL(x) "\n" #x ":\n"
|
|
159
|
+
#define GNU_ASJ(x, y, z) #x " " #y #z ";"
|
|
160
|
+
|
|
161
|
+
#define a1(x) GNU_AS1(x)
|
|
162
|
+
#define a2(x, y) GNU_AS2(x, y)
|
|
163
|
+
#define a3(x, y, z) GNU_AS3(x, y, z)
|
|
164
|
+
#define a4(x, y, z, w) GNU_AS4(x, y, z, w)
|
|
165
|
+
#define al(x) GNU_ASL(x)
|
|
166
|
+
#define aj(x, y, z) GNU_ASJ(x, y, z)
|
|
167
|
+
#define asm_align8 a1(.align 8)
|
|
168
|
+
#define asm_align16 a1(.align 16)
|
|
169
|
+
|
|
170
|
+
#define asm_naked_fn_proto(type, fn) extern type STDCALL fn
|
|
171
|
+
#define asm_naked_fn(fn) ; __asm__ (".intel_syntax noprefix;\n.text\n" asm_align16 GNU_ASL(fn)
|
|
172
|
+
#define asm_naked_fn_end(fn) ".att_syntax prefix;\n.type " #fn ",@function\n.size " #fn ",.-" #fn "\n" );
|
|
173
|
+
#define asm_gcc() __asm__ __volatile__(".intel_syntax noprefix;\n"
|
|
174
|
+
#define asm_gcc_parms() ".att_syntax prefix;"
|
|
175
|
+
#define asm_gcc_trashed() __asm__ __volatile__("" :::
|
|
176
|
+
#define asm_gcc_end() );
|
|
177
|
+
#else
|
|
178
|
+
need x86 asm
|
|
179
|
+
#endif
|
|
180
|
+
|
|
181
|
+
#endif /* X86ASM || X86_64ASM */
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
#if defined(CPU_X86) || defined(CPU_X86_64)
|
|
185
|
+
|
|
186
|
+
typedef enum cpu_flags_x86_t {
|
|
187
|
+
cpu_mmx = 1 << 0,
|
|
188
|
+
cpu_sse = 1 << 1,
|
|
189
|
+
cpu_sse2 = 1 << 2,
|
|
190
|
+
cpu_sse3 = 1 << 3,
|
|
191
|
+
cpu_ssse3 = 1 << 4,
|
|
192
|
+
cpu_sse4_1 = 1 << 5,
|
|
193
|
+
cpu_sse4_2 = 1 << 6,
|
|
194
|
+
cpu_avx = 1 << 7
|
|
195
|
+
} cpu_flags_x86;
|
|
196
|
+
|
|
197
|
+
typedef enum cpu_vendors_x86_t {
|
|
198
|
+
cpu_nobody,
|
|
199
|
+
cpu_intel,
|
|
200
|
+
cpu_amd
|
|
201
|
+
} cpu_vendors_x86;
|
|
202
|
+
|
|
203
|
+
typedef struct x86_regs_t {
|
|
204
|
+
uint32_t eax, ebx, ecx, edx;
|
|
205
|
+
} x86_regs;
|
|
206
|
+
|
|
207
|
+
#if defined(X86ASM)
|
|
208
|
+
asm_naked_fn_proto(int, has_cpuid)(void)
|
|
209
|
+
asm_naked_fn(has_cpuid)
|
|
210
|
+
a1(pushfd)
|
|
211
|
+
a1(pop eax)
|
|
212
|
+
a2(mov ecx, eax)
|
|
213
|
+
a2(xor eax, 0x200000)
|
|
214
|
+
a1(push eax)
|
|
215
|
+
a1(popfd)
|
|
216
|
+
a1(pushfd)
|
|
217
|
+
a1(pop eax)
|
|
218
|
+
a2(xor eax, ecx)
|
|
219
|
+
a2(shr eax, 21)
|
|
220
|
+
a2(and eax, 1)
|
|
221
|
+
a1(push ecx)
|
|
222
|
+
a1(popfd)
|
|
223
|
+
a1(ret)
|
|
224
|
+
asm_naked_fn_end(has_cpuid)
|
|
225
|
+
#endif /* X86ASM */
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
static void NOINLINE
|
|
229
|
+
get_cpuid(x86_regs *regs, uint32_t flags) {
|
|
230
|
+
#if defined(COMPILER_MSVC)
|
|
231
|
+
__cpuid((int *)regs, (int)flags);
|
|
232
|
+
#else
|
|
233
|
+
#if defined(CPU_X86_64)
|
|
234
|
+
#define cpuid_bx rbx
|
|
235
|
+
#else
|
|
236
|
+
#define cpuid_bx ebx
|
|
237
|
+
#endif
|
|
238
|
+
|
|
239
|
+
asm_gcc()
|
|
240
|
+
a1(push cpuid_bx)
|
|
241
|
+
a1(cpuid)
|
|
242
|
+
a2(mov [%1 + 0], eax)
|
|
243
|
+
a2(mov [%1 + 4], ebx)
|
|
244
|
+
a2(mov [%1 + 8], ecx)
|
|
245
|
+
a2(mov [%1 + 12], edx)
|
|
246
|
+
a1(pop cpuid_bx)
|
|
247
|
+
asm_gcc_parms() : "+a"(flags) : "S"(regs) : "%ecx", "%edx", "cc"
|
|
248
|
+
asm_gcc_end()
|
|
249
|
+
#endif
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#if defined(X86ASM_AVX) || defined(X86_64ASM_AVX)
|
|
253
|
+
static uint64_t NOINLINE
|
|
254
|
+
get_xgetbv(uint32_t flags) {
|
|
255
|
+
#if defined(COMPILER_MSVC)
|
|
256
|
+
return _xgetbv(flags);
|
|
257
|
+
#else
|
|
258
|
+
uint32_t lo, hi;
|
|
259
|
+
asm_gcc()
|
|
260
|
+
a1(xgetbv)
|
|
261
|
+
asm_gcc_parms() : "+c"(flags), "=a" (lo), "=d" (hi)
|
|
262
|
+
asm_gcc_end()
|
|
263
|
+
return ((uint64_t)lo | ((uint64_t)hi << 32));
|
|
264
|
+
#endif
|
|
265
|
+
}
|
|
266
|
+
#endif // AVX support
|
|
267
|
+
|
|
268
|
+
#if defined(SCRYPT_TEST_SPEED)
|
|
269
|
+
size_t cpu_detect_mask = (size_t)-1;
|
|
270
|
+
#endif
|
|
271
|
+
|
|
272
|
+
static size_t
|
|
273
|
+
detect_cpu(void) {
|
|
274
|
+
union { uint8_t s[12]; uint32_t i[3]; } vendor_string;
|
|
275
|
+
cpu_vendors_x86 vendor = cpu_nobody;
|
|
276
|
+
x86_regs regs;
|
|
277
|
+
uint32_t max_level;
|
|
278
|
+
size_t cpu_flags = 0;
|
|
279
|
+
#if defined(X86ASM_AVX) || defined(X86_64ASM_AVX)
|
|
280
|
+
uint64_t xgetbv_flags;
|
|
281
|
+
#endif
|
|
282
|
+
|
|
283
|
+
#if defined(CPU_X86)
|
|
284
|
+
if (!has_cpuid())
|
|
285
|
+
return cpu_flags;
|
|
286
|
+
#endif
|
|
287
|
+
|
|
288
|
+
get_cpuid(®s, 0);
|
|
289
|
+
max_level = regs.eax;
|
|
290
|
+
vendor_string.i[0] = regs.ebx;
|
|
291
|
+
vendor_string.i[1] = regs.edx;
|
|
292
|
+
vendor_string.i[2] = regs.ecx;
|
|
293
|
+
|
|
294
|
+
if (scrypt_verify(vendor_string.s, (const uint8_t *)"GenuineIntel", 12))
|
|
295
|
+
vendor = cpu_intel;
|
|
296
|
+
else if (scrypt_verify(vendor_string.s, (const uint8_t *)"AuthenticAMD", 12))
|
|
297
|
+
vendor = cpu_amd;
|
|
298
|
+
|
|
299
|
+
if (max_level & 0x00000500) {
|
|
300
|
+
/* "Intel P5 pre-B0" */
|
|
301
|
+
cpu_flags |= cpu_mmx;
|
|
302
|
+
return cpu_flags;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
if (max_level < 1)
|
|
306
|
+
return cpu_flags;
|
|
307
|
+
|
|
308
|
+
get_cpuid(®s, 1);
|
|
309
|
+
#if defined(X86ASM_AVX) || defined(X86_64ASM_AVX)
|
|
310
|
+
/* xsave/xrestore */
|
|
311
|
+
if (regs.ecx & (1 << 27)) {
|
|
312
|
+
xgetbv_flags = get_xgetbv(0);
|
|
313
|
+
if ((regs.ecx & (1 << 28)) && (xgetbv_flags & 0x6)) cpu_flags |= cpu_avx;
|
|
314
|
+
}
|
|
315
|
+
#endif
|
|
316
|
+
if (regs.ecx & (1 << 20)) cpu_flags |= cpu_sse4_2;
|
|
317
|
+
if (regs.ecx & (1 << 19)) cpu_flags |= cpu_sse4_2;
|
|
318
|
+
if (regs.ecx & (1 << 9)) cpu_flags |= cpu_ssse3;
|
|
319
|
+
if (regs.ecx & (1 )) cpu_flags |= cpu_sse3;
|
|
320
|
+
if (regs.edx & (1 << 26)) cpu_flags |= cpu_sse2;
|
|
321
|
+
if (regs.edx & (1 << 25)) cpu_flags |= cpu_sse;
|
|
322
|
+
if (regs.edx & (1 << 23)) cpu_flags |= cpu_mmx;
|
|
323
|
+
|
|
324
|
+
#if defined(SCRYPT_TEST_SPEED)
|
|
325
|
+
cpu_flags &= cpu_detect_mask;
|
|
326
|
+
#endif
|
|
327
|
+
|
|
328
|
+
return cpu_flags;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
#if defined(SCRYPT_TEST_SPEED)
|
|
332
|
+
static const char *
|
|
333
|
+
get_top_cpuflag_desc(size_t flag) {
|
|
334
|
+
if (flag & cpu_avx) return "AVX";
|
|
335
|
+
else if (flag & cpu_sse4_2) return "SSE4.2";
|
|
336
|
+
else if (flag & cpu_sse4_1) return "SSE4.1";
|
|
337
|
+
else if (flag & cpu_ssse3) return "SSSE3";
|
|
338
|
+
else if (flag & cpu_sse2) return "SSE2";
|
|
339
|
+
else if (flag & cpu_sse) return "SSE";
|
|
340
|
+
else if (flag & cpu_mmx) return "MMX";
|
|
341
|
+
else return "Basic";
|
|
342
|
+
}
|
|
343
|
+
#endif
|
|
344
|
+
|
|
345
|
+
/* enable the highest system-wide option */
|
|
346
|
+
#if defined(SCRYPT_CHOOSE_COMPILETIME)
|
|
347
|
+
#if !defined(__AVX__)
|
|
348
|
+
#undef X86_64ASM_AVX
|
|
349
|
+
#undef X86ASM_AVX
|
|
350
|
+
#undef X86_INTRINSIC_AVX
|
|
351
|
+
#endif
|
|
352
|
+
#if !defined(__SSSE3__)
|
|
353
|
+
#undef X86_64ASM_SSSE3
|
|
354
|
+
#undef X86ASM_SSSE3
|
|
355
|
+
#undef X86_INTRINSIC_SSSE3
|
|
356
|
+
#endif
|
|
357
|
+
#if !defined(__SSE2__)
|
|
358
|
+
#undef X86_64ASM_SSE2
|
|
359
|
+
#undef X86ASM_SSE2
|
|
360
|
+
#undef X86_INTRINSIC_SSE2
|
|
361
|
+
#endif
|
|
362
|
+
#endif
|
|
363
|
+
|
|
364
|
+
#endif /* defined(CPU_X86) || defined(CPU_X86_64) */
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
/* determine os */
|
|
2
|
+
#if defined(_WIN32) || defined(_WIN64) || defined(__TOS_WIN__) || defined(__WINDOWS__)
|
|
3
|
+
#include <windows.h>
|
|
4
|
+
#include <wincrypt.h>
|
|
5
|
+
#define OS_WINDOWS
|
|
6
|
+
#elif defined(sun) || defined(__sun) || defined(__SVR4) || defined(__svr4__)
|
|
7
|
+
#include <sys/mman.h>
|
|
8
|
+
#include <sys/time.h>
|
|
9
|
+
#include <fcntl.h>
|
|
10
|
+
|
|
11
|
+
#define OS_SOLARIS
|
|
12
|
+
#else
|
|
13
|
+
#include <sys/mman.h>
|
|
14
|
+
#include <sys/time.h>
|
|
15
|
+
#include <sys/param.h> /* need this to define BSD */
|
|
16
|
+
#include <unistd.h>
|
|
17
|
+
#include <fcntl.h>
|
|
18
|
+
|
|
19
|
+
#define OS_NIX
|
|
20
|
+
#if defined(__linux__)
|
|
21
|
+
#include <endian.h>
|
|
22
|
+
#define OS_LINUX
|
|
23
|
+
#elif defined(BSD)
|
|
24
|
+
#define OS_BSD
|
|
25
|
+
|
|
26
|
+
#if defined(MACOS_X) || (defined(__APPLE__) & defined(__MACH__))
|
|
27
|
+
#define OS_OSX
|
|
28
|
+
#elif defined(macintosh) || defined(Macintosh)
|
|
29
|
+
#define OS_MAC
|
|
30
|
+
#elif defined(__OpenBSD__)
|
|
31
|
+
#define OS_OPENBSD
|
|
32
|
+
#endif
|
|
33
|
+
#endif
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
/* determine compiler */
|
|
38
|
+
#if defined(_MSC_VER)
|
|
39
|
+
#define COMPILER_MSVC _MSC_VER
|
|
40
|
+
#if ((COMPILER_MSVC > 1200) || defined(_mm_free))
|
|
41
|
+
#define COMPILER_MSVC6PP_AND_LATER
|
|
42
|
+
#endif
|
|
43
|
+
#if (COMPILER_MSVC >= 1500)
|
|
44
|
+
#define COMPILER_HAS_TMMINTRIN
|
|
45
|
+
#endif
|
|
46
|
+
|
|
47
|
+
#pragma warning(disable : 4127) /* conditional expression is constant */
|
|
48
|
+
#pragma warning(disable : 4100) /* unreferenced formal parameter */
|
|
49
|
+
|
|
50
|
+
#define _CRT_SECURE_NO_WARNINGS
|
|
51
|
+
#include <float.h>
|
|
52
|
+
#include <stdlib.h> /* _rotl */
|
|
53
|
+
#include <intrin.h>
|
|
54
|
+
|
|
55
|
+
typedef unsigned char uint8_t;
|
|
56
|
+
typedef unsigned short uint16_t;
|
|
57
|
+
typedef unsigned int uint32_t;
|
|
58
|
+
typedef signed int int32_t;
|
|
59
|
+
typedef unsigned __int64 uint64_t;
|
|
60
|
+
typedef signed __int64 int64_t;
|
|
61
|
+
|
|
62
|
+
#define ROTL32(a,b) _rotl(a,b)
|
|
63
|
+
#define ROTR32(a,b) _rotr(a,b)
|
|
64
|
+
#define ROTL64(a,b) _rotl64(a,b)
|
|
65
|
+
#define ROTR64(a,b) _rotr64(a,b)
|
|
66
|
+
#undef NOINLINE
|
|
67
|
+
#define NOINLINE __declspec(noinline)
|
|
68
|
+
#undef INLINE
|
|
69
|
+
#define INLINE __forceinline
|
|
70
|
+
#undef FASTCALL
|
|
71
|
+
#define FASTCALL __fastcall
|
|
72
|
+
#undef CDECL
|
|
73
|
+
#define CDECL __cdecl
|
|
74
|
+
#undef STDCALL
|
|
75
|
+
#define STDCALL __stdcall
|
|
76
|
+
#undef NAKED
|
|
77
|
+
#define NAKED __declspec(naked)
|
|
78
|
+
#define MM16 __declspec(align(16))
|
|
79
|
+
#endif
|
|
80
|
+
#if defined(__ICC)
|
|
81
|
+
#define COMPILER_INTEL
|
|
82
|
+
#endif
|
|
83
|
+
#if defined(__GNUC__)
|
|
84
|
+
#if (__GNUC__ >= 3)
|
|
85
|
+
#define COMPILER_GCC_PATCHLEVEL __GNUC_PATCHLEVEL__
|
|
86
|
+
#else
|
|
87
|
+
#define COMPILER_GCC_PATCHLEVEL 0
|
|
88
|
+
#endif
|
|
89
|
+
#define COMPILER_GCC (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + COMPILER_GCC_PATCHLEVEL)
|
|
90
|
+
#define ROTL32(a,b) (((a) << (b)) | ((a) >> (32 - b)))
|
|
91
|
+
#define ROTR32(a,b) (((a) >> (b)) | ((a) << (32 - b)))
|
|
92
|
+
#define ROTL64(a,b) (((a) << (b)) | ((a) >> (64 - b)))
|
|
93
|
+
#define ROTR64(a,b) (((a) >> (b)) | ((a) << (64 - b)))
|
|
94
|
+
#undef NOINLINE
|
|
95
|
+
#if (COMPILER_GCC >= 30000)
|
|
96
|
+
#define NOINLINE __attribute__((noinline))
|
|
97
|
+
#else
|
|
98
|
+
#define NOINLINE
|
|
99
|
+
#endif
|
|
100
|
+
#undef INLINE
|
|
101
|
+
#if (COMPILER_GCC >= 30000)
|
|
102
|
+
#define INLINE __attribute__((always_inline))
|
|
103
|
+
#else
|
|
104
|
+
#define INLINE inline
|
|
105
|
+
#endif
|
|
106
|
+
#undef FASTCALL
|
|
107
|
+
#if (COMPILER_GCC >= 30400)
|
|
108
|
+
#define FASTCALL __attribute__((fastcall))
|
|
109
|
+
#else
|
|
110
|
+
#define FASTCALL
|
|
111
|
+
#endif
|
|
112
|
+
#undef CDECL
|
|
113
|
+
#define CDECL __attribute__((cdecl))
|
|
114
|
+
#undef STDCALL
|
|
115
|
+
#define STDCALL __attribute__((stdcall))
|
|
116
|
+
#define MM16 __attribute__((aligned(16)))
|
|
117
|
+
#include <stdint.h>
|
|
118
|
+
#endif
|
|
119
|
+
#if defined(__MINGW32__) || defined(__MINGW64__)
|
|
120
|
+
#define COMPILER_MINGW
|
|
121
|
+
#endif
|
|
122
|
+
#if defined(__PATHCC__)
|
|
123
|
+
#define COMPILER_PATHCC
|
|
124
|
+
#endif
|
|
125
|
+
|
|
126
|
+
#define OPTIONAL_INLINE
|
|
127
|
+
#if defined(OPTIONAL_INLINE)
|
|
128
|
+
#undef OPTIONAL_INLINE
|
|
129
|
+
#define OPTIONAL_INLINE INLINE
|
|
130
|
+
#else
|
|
131
|
+
#define OPTIONAL_INLINE
|
|
132
|
+
#endif
|
|
133
|
+
|
|
134
|
+
#define CRYPTO_FN NOINLINE STDCALL
|
|
135
|
+
|
|
136
|
+
/* determine cpu */
|
|
137
|
+
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__ ) || defined(_M_X64)
|
|
138
|
+
#define CPU_X86_64
|
|
139
|
+
#elif defined(__i586__) || defined(__i686__) || (defined(_M_IX86) && (_M_IX86 >= 500))
|
|
140
|
+
#define CPU_X86 500
|
|
141
|
+
#elif defined(__i486__) || (defined(_M_IX86) && (_M_IX86 >= 400))
|
|
142
|
+
#define CPU_X86 400
|
|
143
|
+
#elif defined(__i386__) || (defined(_M_IX86) && (_M_IX86 >= 300)) || defined(__X86__) || defined(_X86_) || defined(__I86__)
|
|
144
|
+
#define CPU_X86 300
|
|
145
|
+
#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64) || defined(__ia64)
|
|
146
|
+
#define CPU_IA64
|
|
147
|
+
#endif
|
|
148
|
+
|
|
149
|
+
#if defined(__sparc__) || defined(__sparc) || defined(__sparcv9)
|
|
150
|
+
#define CPU_SPARC
|
|
151
|
+
#if defined(__sparcv9)
|
|
152
|
+
#define CPU_SPARC64
|
|
153
|
+
#endif
|
|
154
|
+
#endif
|
|
155
|
+
|
|
156
|
+
#if defined(CPU_X86_64) || defined(CPU_IA64) || defined(CPU_SPARC64) || defined(__64BIT__) || defined(__LP64__) || defined(_LP64) || (defined(_MIPS_SZLONG) && (_MIPS_SZLONG == 64))
|
|
157
|
+
#define CPU_64BITS
|
|
158
|
+
#undef FASTCALL
|
|
159
|
+
#define FASTCALL
|
|
160
|
+
#undef CDECL
|
|
161
|
+
#define CDECL
|
|
162
|
+
#undef STDCALL
|
|
163
|
+
#define STDCALL
|
|
164
|
+
#endif
|
|
165
|
+
|
|
166
|
+
#if defined(powerpc) || defined(__PPC__) || defined(__ppc__) || defined(_ARCH_PPC) || defined(__powerpc__) || defined(__powerpc) || defined(POWERPC) || defined(_M_PPC)
|
|
167
|
+
#define CPU_PPC
|
|
168
|
+
#if defined(_ARCH_PWR7)
|
|
169
|
+
#define CPU_POWER7
|
|
170
|
+
#elif defined(__64BIT__)
|
|
171
|
+
#define CPU_PPC64
|
|
172
|
+
#else
|
|
173
|
+
#define CPU_PPC32
|
|
174
|
+
#endif
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
#if defined(__hppa__) || defined(__hppa)
|
|
178
|
+
#define CPU_HPPA
|
|
179
|
+
#endif
|
|
180
|
+
|
|
181
|
+
#if defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA)
|
|
182
|
+
#define CPU_ALPHA
|
|
183
|
+
#endif
|
|
184
|
+
|
|
185
|
+
/* endian */
|
|
186
|
+
|
|
187
|
+
#if ((defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN)) || \
|
|
188
|
+
(defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && (BYTE_ORDER == LITTLE_ENDIAN)) || \
|
|
189
|
+
(defined(CPU_X86) || defined(CPU_X86_64)) || \
|
|
190
|
+
(defined(vax) || defined(MIPSEL) || defined(_MIPSEL)))
|
|
191
|
+
#define CPU_LE
|
|
192
|
+
#elif ((defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN)) || \
|
|
193
|
+
(defined(BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN)) || \
|
|
194
|
+
(defined(CPU_SPARC) || defined(CPU_PPC) || defined(mc68000) || defined(sel)) || defined(_MIPSEB))
|
|
195
|
+
#define CPU_BE
|
|
196
|
+
#else
|
|
197
|
+
/* unknown endian! */
|
|
198
|
+
#endif
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
#define U8TO32_BE(p) \
|
|
202
|
+
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
|
|
203
|
+
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
|
|
204
|
+
|
|
205
|
+
#define U8TO32_LE(p) \
|
|
206
|
+
(((uint32_t)((p)[0]) ) | ((uint32_t)((p)[1]) << 8) | \
|
|
207
|
+
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24))
|
|
208
|
+
|
|
209
|
+
#define U32TO8_BE(p, v) \
|
|
210
|
+
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
|
|
211
|
+
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
|
|
212
|
+
|
|
213
|
+
#define U32TO8_LE(p, v) \
|
|
214
|
+
(p)[0] = (uint8_t)((v) ); (p)[1] = (uint8_t)((v) >> 8); \
|
|
215
|
+
(p)[2] = (uint8_t)((v) >> 16); (p)[3] = (uint8_t)((v) >> 24);
|
|
216
|
+
|
|
217
|
+
#define U8TO64_BE(p) \
|
|
218
|
+
(((uint64_t)U8TO32_BE(p) << 32) | (uint64_t)U8TO32_BE((p) + 4))
|
|
219
|
+
|
|
220
|
+
#define U8TO64_LE(p) \
|
|
221
|
+
(((uint64_t)U8TO32_LE(p)) | ((uint64_t)U8TO32_LE((p) + 4) << 32))
|
|
222
|
+
|
|
223
|
+
#define U64TO8_BE(p, v) \
|
|
224
|
+
U32TO8_BE((p), (uint32_t)((v) >> 32)); \
|
|
225
|
+
U32TO8_BE((p) + 4, (uint32_t)((v) ));
|
|
226
|
+
|
|
227
|
+
#define U64TO8_LE(p, v) \
|
|
228
|
+
U32TO8_LE((p), (uint32_t)((v) )); \
|
|
229
|
+
U32TO8_LE((p) + 4, (uint32_t)((v) >> 32));
|
|
230
|
+
|
|
231
|
+
#define U32_SWAP(v) { \
|
|
232
|
+
(v) = (((v) << 8) & 0xFF00FF00 ) | (((v) >> 8) & 0xFF00FF ); \
|
|
233
|
+
(v) = ((v) << 16) | ((v) >> 16); \
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
#define U64_SWAP(v) { \
|
|
237
|
+
(v) = (((v) << 8) & 0xFF00FF00FF00FF00ull ) | (((v) >> 8) & 0x00FF00FF00FF00FFull ); \
|
|
238
|
+
(v) = (((v) << 16) & 0xFFFF0000FFFF0000ull ) | (((v) >> 16) & 0x0000FFFF0000FFFFull ); \
|
|
239
|
+
(v) = ((v) << 32) | ((v) >> 32); \
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
static int
|
|
243
|
+
scrypt_verify(const uint8_t *x, const uint8_t *y, size_t len) {
|
|
244
|
+
uint32_t differentbits = 0;
|
|
245
|
+
while (len--)
|
|
246
|
+
differentbits |= (*x++ ^ *y++);
|
|
247
|
+
return (1 & ((differentbits - 1) >> 8));
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
void
|
|
251
|
+
scrypt_ensure_zero(void *p, size_t len) {
|
|
252
|
+
#if ((defined(CPU_X86) || defined(CPU_X86_64)) && defined(COMPILER_MSVC))
|
|
253
|
+
__stosb((unsigned char *)p, 0, len);
|
|
254
|
+
#elif (defined(CPU_X86) && defined(COMPILER_GCC))
|
|
255
|
+
__asm__ __volatile__(
|
|
256
|
+
"pushl %%edi;\n"
|
|
257
|
+
"pushl %%ecx;\n"
|
|
258
|
+
"rep stosb;\n"
|
|
259
|
+
"popl %%ecx;\n"
|
|
260
|
+
"popl %%edi;\n"
|
|
261
|
+
:: "a"(0), "D"(p), "c"(len) : "cc", "memory"
|
|
262
|
+
);
|
|
263
|
+
#elif (defined(CPU_X86_64) && defined(COMPILER_GCC))
|
|
264
|
+
__asm__ __volatile__(
|
|
265
|
+
"pushq %%rdi;\n"
|
|
266
|
+
"pushq %%rcx;\n"
|
|
267
|
+
"rep stosb;\n"
|
|
268
|
+
"popq %%rcx;\n"
|
|
269
|
+
"popq %%rdi;\n"
|
|
270
|
+
:: "a"(0), "D"(p), "c"(len) : "cc", "memory"
|
|
271
|
+
);
|
|
272
|
+
#else
|
|
273
|
+
volatile uint8_t *b = (volatile uint8_t *)p;
|
|
274
|
+
size_t i;
|
|
275
|
+
for (i = 0; i < len; i++)
|
|
276
|
+
b[i] = 0;
|
|
277
|
+
#endif
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
#include "scrypt-jane-portable-x86.h"
|
|
281
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
#if !defined(SCRYPT_CHOOSE_COMPILETIME)
|
|
2
|
+
/* function type returned by scrypt_getROMix, used with cpu detection */
|
|
3
|
+
typedef void (FASTCALL *scrypt_ROMixfn)(scrypt_mix_word_t *X/*[chunkWords]*/, scrypt_mix_word_t *Y/*[chunkWords]*/, scrypt_mix_word_t *V/*[chunkWords * N]*/, uint32_t N, uint32_t r);
|
|
4
|
+
#endif
|
|
5
|
+
|
|
6
|
+
/* romix pre/post nop function */
|
|
7
|
+
static void STDCALL
|
|
8
|
+
scrypt_romix_nop(scrypt_mix_word_t *blocks, size_t nblocks) {
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* romix pre/post endian conversion function */
|
|
12
|
+
static void STDCALL
|
|
13
|
+
scrypt_romix_convert_endian(scrypt_mix_word_t *blocks, size_t nblocks) {
|
|
14
|
+
#if !defined(CPU_LE)
|
|
15
|
+
static const union { uint8_t b[2]; uint16_t w; } endian_test = {{1,0}};
|
|
16
|
+
size_t i;
|
|
17
|
+
if (endian_test.w == 0x100) {
|
|
18
|
+
nblocks *= SCRYPT_BLOCK_WORDS;
|
|
19
|
+
for (i = 0; i < nblocks; i++) {
|
|
20
|
+
SCRYPT_WORD_ENDIAN_SWAP(blocks[i]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
#endif
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/* chunkmix test function */
|
|
27
|
+
typedef void (STDCALL *chunkmixfn)(scrypt_mix_word_t *Bout/*[chunkWords]*/, scrypt_mix_word_t *Bin/*[chunkWords]*/, scrypt_mix_word_t *Bxor/*[chunkWords]*/, uint32_t r);
|
|
28
|
+
typedef void (STDCALL *blockfixfn)(scrypt_mix_word_t *blocks, size_t nblocks);
|
|
29
|
+
|
|
30
|
+
static int
|
|
31
|
+
scrypt_test_mix_instance(chunkmixfn mixfn, blockfixfn prefn, blockfixfn postfn, const uint8_t expected[16]) {
|
|
32
|
+
/* r = 2, (2 * r) = 4 blocks in a chunk, 4 * SCRYPT_BLOCK_WORDS total */
|
|
33
|
+
const uint32_t r = 2, blocks = 2 * r, words = blocks * SCRYPT_BLOCK_WORDS;
|
|
34
|
+
scrypt_mix_word_t MM16 chunk[2][4 * SCRYPT_BLOCK_WORDS], v;
|
|
35
|
+
uint8_t final[16];
|
|
36
|
+
size_t i;
|
|
37
|
+
|
|
38
|
+
for (i = 0; i < words; i++) {
|
|
39
|
+
v = (scrypt_mix_word_t)i;
|
|
40
|
+
v = (v << 8) | v;
|
|
41
|
+
v = (v << 16) | v;
|
|
42
|
+
chunk[0][i] = v;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
prefn(chunk[0], blocks);
|
|
46
|
+
mixfn(chunk[1], chunk[0], NULL, r);
|
|
47
|
+
postfn(chunk[1], blocks);
|
|
48
|
+
|
|
49
|
+
/* grab the last 16 bytes of the final block */
|
|
50
|
+
for (i = 0; i < 16; i += sizeof(scrypt_mix_word_t)) {
|
|
51
|
+
SCRYPT_WORDTO8_LE(final + i, chunk[1][words - (16 / sizeof(scrypt_mix_word_t)) + (i / sizeof(scrypt_mix_word_t))]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return scrypt_verify(expected, final, 16);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/* returns a pointer to item i, where item is len scrypt_mix_word_t's long */
|
|
58
|
+
static scrypt_mix_word_t *
|
|
59
|
+
scrypt_item(scrypt_mix_word_t *base, scrypt_mix_word_t i, scrypt_mix_word_t len) {
|
|
60
|
+
return base + (i * len);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* returns a pointer to block i */
|
|
64
|
+
static scrypt_mix_word_t *
|
|
65
|
+
scrypt_block(scrypt_mix_word_t *base, scrypt_mix_word_t i) {
|
|
66
|
+
return base + (i * SCRYPT_BLOCK_WORDS);
|
|
67
|
+
}
|