@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
package/scryptjane.c
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
/*
|
|
2
|
+
scrypt-jane by Andrew M, https://github.com/floodyberry/scrypt-jane
|
|
3
|
+
|
|
4
|
+
Public Domain or MIT License, whichever is easier
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include <string.h>
|
|
8
|
+
|
|
9
|
+
#include "scryptjane.h"
|
|
10
|
+
#include "scryptjane/scrypt-jane-portable.h"
|
|
11
|
+
#include "scryptjane/scrypt-jane-hash.h"
|
|
12
|
+
#include "scryptjane/scrypt-jane-romix.h"
|
|
13
|
+
#include "scryptjane/scrypt-jane-test-vectors.h"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
#define scrypt_maxN 30 /* (1 << (30 + 1)) = ~2 billion */
|
|
17
|
+
#if (SCRYPT_BLOCK_BYTES == 64)
|
|
18
|
+
#define scrypt_r_32kb 8 /* (1 << 8) = 256 * 2 blocks in a chunk * 64 bytes = Max of 32kb in a chunk */
|
|
19
|
+
#elif (SCRYPT_BLOCK_BYTES == 128)
|
|
20
|
+
#define scrypt_r_32kb 7 /* (1 << 7) = 128 * 2 blocks in a chunk * 128 bytes = Max of 32kb in a chunk */
|
|
21
|
+
#elif (SCRYPT_BLOCK_BYTES == 256)
|
|
22
|
+
#define scrypt_r_32kb 6 /* (1 << 6) = 64 * 2 blocks in a chunk * 256 bytes = Max of 32kb in a chunk */
|
|
23
|
+
#elif (SCRYPT_BLOCK_BYTES == 512)
|
|
24
|
+
#define scrypt_r_32kb 5 /* (1 << 5) = 32 * 2 blocks in a chunk * 512 bytes = Max of 32kb in a chunk */
|
|
25
|
+
#endif
|
|
26
|
+
#define scrypt_maxr scrypt_r_32kb /* 32kb */
|
|
27
|
+
#define scrypt_maxp 25 /* (1 << 25) = ~33 million */
|
|
28
|
+
|
|
29
|
+
#include <stdio.h>
|
|
30
|
+
#include <stdlib.h>
|
|
31
|
+
|
|
32
|
+
static void
|
|
33
|
+
scrypt_fatal_error_default(const char *msg) {
|
|
34
|
+
fprintf(stderr, "%s\n", msg);
|
|
35
|
+
exit(1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
static scrypt_fatal_errorfn scrypt_fatal_error = scrypt_fatal_error_default;
|
|
39
|
+
|
|
40
|
+
void
|
|
41
|
+
scrypt_set_fatal_error_default(scrypt_fatal_errorfn fn) {
|
|
42
|
+
scrypt_fatal_error = fn;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static int
|
|
46
|
+
scrypt_power_on_self_test() {
|
|
47
|
+
const scrypt_test_setting *t;
|
|
48
|
+
uint8_t test_digest[64];
|
|
49
|
+
uint32_t i;
|
|
50
|
+
int res = 7, scrypt_valid;
|
|
51
|
+
|
|
52
|
+
if (!scrypt_test_mix()) {
|
|
53
|
+
#if !defined(SCRYPT_TEST)
|
|
54
|
+
scrypt_fatal_error("scrypt: mix function power-on-self-test failed");
|
|
55
|
+
#endif
|
|
56
|
+
res &= ~1;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!scrypt_test_hash()) {
|
|
60
|
+
#if !defined(SCRYPT_TEST)
|
|
61
|
+
scrypt_fatal_error("scrypt: hash function power-on-self-test failed");
|
|
62
|
+
#endif
|
|
63
|
+
res &= ~2;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (i = 0, scrypt_valid = 1; post_settings[i].pw; i++) {
|
|
67
|
+
t = post_settings + i;
|
|
68
|
+
scrypt((uint8_t *)t->pw, strlen(t->pw), (uint8_t *)t->salt, strlen(t->salt), t->Nfactor, t->rfactor, t->pfactor, test_digest, sizeof(test_digest));
|
|
69
|
+
scrypt_valid &= scrypt_verify(post_vectors[i], test_digest, sizeof(test_digest));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (!scrypt_valid) {
|
|
73
|
+
#if !defined(SCRYPT_TEST)
|
|
74
|
+
scrypt_fatal_error("scrypt: scrypt power-on-self-test failed");
|
|
75
|
+
#endif
|
|
76
|
+
res &= ~4;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return res;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
typedef struct scrypt_aligned_alloc_t {
|
|
83
|
+
uint8_t *mem, *ptr;
|
|
84
|
+
} scrypt_aligned_alloc;
|
|
85
|
+
|
|
86
|
+
#if defined(SCRYPT_TEST_SPEED)
|
|
87
|
+
static uint8_t *mem_base = (uint8_t *)0;
|
|
88
|
+
static size_t mem_bump = 0;
|
|
89
|
+
|
|
90
|
+
/* allocations are assumed to be multiples of 64 bytes and total allocations not to exceed ~1.01gb */
|
|
91
|
+
static scrypt_aligned_alloc
|
|
92
|
+
scrypt_alloc(uint64_t size) {
|
|
93
|
+
scrypt_aligned_alloc aa;
|
|
94
|
+
if (!mem_base) {
|
|
95
|
+
mem_base = (uint8_t *)malloc((1024 * 1024 * 1024) + (1024 * 1024) + (SCRYPT_BLOCK_BYTES - 1));
|
|
96
|
+
if (!mem_base)
|
|
97
|
+
scrypt_fatal_error("scrypt: out of memory");
|
|
98
|
+
mem_base = (uint8_t *)(((size_t)mem_base + (SCRYPT_BLOCK_BYTES - 1)) & ~(SCRYPT_BLOCK_BYTES - 1));
|
|
99
|
+
}
|
|
100
|
+
aa.mem = mem_base + mem_bump;
|
|
101
|
+
aa.ptr = aa.mem;
|
|
102
|
+
mem_bump += (size_t)size;
|
|
103
|
+
return aa;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static void
|
|
107
|
+
scrypt_free(scrypt_aligned_alloc *aa) {
|
|
108
|
+
mem_bump = 0;
|
|
109
|
+
}
|
|
110
|
+
#else
|
|
111
|
+
static scrypt_aligned_alloc
|
|
112
|
+
scrypt_alloc(uint64_t size) {
|
|
113
|
+
static const size_t max_alloc = (size_t)-1;
|
|
114
|
+
scrypt_aligned_alloc aa;
|
|
115
|
+
size += (SCRYPT_BLOCK_BYTES - 1);
|
|
116
|
+
if (size > max_alloc)
|
|
117
|
+
scrypt_fatal_error("scrypt: not enough address space on this CPU to allocate required memory");
|
|
118
|
+
aa.mem = (uint8_t *)malloc((size_t)size);
|
|
119
|
+
aa.ptr = (uint8_t *)(((size_t)aa.mem + (SCRYPT_BLOCK_BYTES - 1)) & ~(SCRYPT_BLOCK_BYTES - 1));
|
|
120
|
+
if (!aa.mem)
|
|
121
|
+
scrypt_fatal_error("scrypt: out of memory");
|
|
122
|
+
return aa;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static void
|
|
126
|
+
scrypt_free(scrypt_aligned_alloc *aa) {
|
|
127
|
+
free(aa->mem);
|
|
128
|
+
}
|
|
129
|
+
#endif
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
void
|
|
133
|
+
scrypt(const uint8_t *password, size_t password_len, const uint8_t *salt, size_t salt_len, uint8_t Nfactor, uint8_t rfactor, uint8_t pfactor, uint8_t *out, size_t bytes) {
|
|
134
|
+
scrypt_aligned_alloc YX, V;
|
|
135
|
+
uint8_t *X, *Y;
|
|
136
|
+
uint32_t N, r, p, chunk_bytes, i;
|
|
137
|
+
|
|
138
|
+
#if !defined(SCRYPT_CHOOSE_COMPILETIME)
|
|
139
|
+
scrypt_ROMixfn scrypt_ROMix = scrypt_getROMix();
|
|
140
|
+
#endif
|
|
141
|
+
|
|
142
|
+
#if !defined(SCRYPT_TEST)
|
|
143
|
+
static int power_on_self_test = 0;
|
|
144
|
+
if (!power_on_self_test) {
|
|
145
|
+
power_on_self_test = 1;
|
|
146
|
+
if (!scrypt_power_on_self_test())
|
|
147
|
+
scrypt_fatal_error("scrypt: power on self test failed");
|
|
148
|
+
}
|
|
149
|
+
#endif
|
|
150
|
+
|
|
151
|
+
if (Nfactor > scrypt_maxN)
|
|
152
|
+
scrypt_fatal_error("scrypt: N out of range");
|
|
153
|
+
if (rfactor > scrypt_maxr)
|
|
154
|
+
scrypt_fatal_error("scrypt: r out of range");
|
|
155
|
+
if (pfactor > scrypt_maxp)
|
|
156
|
+
scrypt_fatal_error("scrypt: p out of range");
|
|
157
|
+
|
|
158
|
+
N = (1 << (Nfactor + 1));
|
|
159
|
+
r = (1 << rfactor);
|
|
160
|
+
p = (1 << pfactor);
|
|
161
|
+
|
|
162
|
+
chunk_bytes = SCRYPT_BLOCK_BYTES * r * 2;
|
|
163
|
+
V = scrypt_alloc((uint64_t)N * chunk_bytes);
|
|
164
|
+
YX = scrypt_alloc((p + 1) * chunk_bytes);
|
|
165
|
+
|
|
166
|
+
/* 1: X = PBKDF2(password, salt) */
|
|
167
|
+
Y = YX.ptr;
|
|
168
|
+
X = Y + chunk_bytes;
|
|
169
|
+
scrypt_pbkdf2(password, password_len, salt, salt_len, 1, X, chunk_bytes * p);
|
|
170
|
+
|
|
171
|
+
/* 2: X = ROMix(X) */
|
|
172
|
+
for (i = 0; i < p; i++)
|
|
173
|
+
scrypt_ROMix((scrypt_mix_word_t *)(X + (chunk_bytes * i)), (scrypt_mix_word_t *)Y, (scrypt_mix_word_t *)V.ptr, N, r);
|
|
174
|
+
|
|
175
|
+
/* 3: Out = PBKDF2(password, X) */
|
|
176
|
+
scrypt_pbkdf2(password, password_len, X, chunk_bytes * p, 1, out, bytes);
|
|
177
|
+
|
|
178
|
+
scrypt_ensure_zero(YX.ptr, (p + 1) * chunk_bytes);
|
|
179
|
+
|
|
180
|
+
scrypt_free(&V);
|
|
181
|
+
scrypt_free(&YX);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
#define max(a,b) (((a) > (b)) ? (a) : (b))
|
|
185
|
+
#define min(a,b) (((a) < (b)) ? (a) : (b))
|
|
186
|
+
unsigned char GetNfactorJane(int nTimestamp, int nChainStartTime, int nMin, int nMax) {
|
|
187
|
+
|
|
188
|
+
const unsigned char minNfactor = nMin;//4;
|
|
189
|
+
const unsigned char maxNfactor = nMax;//30;
|
|
190
|
+
|
|
191
|
+
int l = 0, s, n;
|
|
192
|
+
unsigned char N;
|
|
193
|
+
|
|
194
|
+
if (nTimestamp <= nChainStartTime)
|
|
195
|
+
return 4;
|
|
196
|
+
|
|
197
|
+
s = nTimestamp - nChainStartTime;
|
|
198
|
+
while ((s >> 1) > 3) {
|
|
199
|
+
l += 1;
|
|
200
|
+
s >>= 1;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
s &= 3;
|
|
204
|
+
|
|
205
|
+
n = (l * 170 + s * 25 - 2320) / 100;
|
|
206
|
+
|
|
207
|
+
if (n < 0) n = 0;
|
|
208
|
+
|
|
209
|
+
if (n > 255)
|
|
210
|
+
printf("GetNfactor(%d) - something wrong(n == %d)\n", nTimestamp, n);
|
|
211
|
+
|
|
212
|
+
N = (unsigned char)n;
|
|
213
|
+
//printf("GetNfactor: %d -> %d %d : %d / %d\n", nTimestamp - nChainStartTime, l, s, n, min(max(N, minNfactor), maxNfactor));
|
|
214
|
+
|
|
215
|
+
return min(max(N, minNfactor), maxNfactor);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
void scryptjane_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char Nfactor)
|
|
219
|
+
{
|
|
220
|
+
scrypt((const unsigned char*)input, inputlen,
|
|
221
|
+
(const unsigned char*)input, inputlen,
|
|
222
|
+
Nfactor, 0, 0, (unsigned char*)res, 32);
|
|
223
|
+
}
|
package/scryptjane.h
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#ifndef SCRYPT_JANE_H
|
|
2
|
+
#define SCRYPT_JANE_H
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
#define SCRYPT_KECCAK512
|
|
7
|
+
#define SCRYPT_CHACHA
|
|
8
|
+
#define SCRYPT_CHOOSE_COMPILETIME
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
Nfactor: Increases CPU & Memory Hardness
|
|
12
|
+
N = (1 << (Nfactor + 1)): How many times to mix a chunk and how many temporary chunks are used
|
|
13
|
+
|
|
14
|
+
rfactor: Increases Memory Hardness
|
|
15
|
+
r = (1 << rfactor): How large a chunk is
|
|
16
|
+
|
|
17
|
+
pfactor: Increases CPU Hardness
|
|
18
|
+
p = (1 << pfactor): Number of times to mix the main chunk
|
|
19
|
+
|
|
20
|
+
A block is the basic mixing unit (salsa/chacha block = 64 bytes)
|
|
21
|
+
A chunk is (2 * r) blocks
|
|
22
|
+
|
|
23
|
+
~Memory used = (N + 2) * ((2 * r) * block size)
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
#include <stdlib.h>
|
|
27
|
+
|
|
28
|
+
typedef void (*scrypt_fatal_errorfn)(const char *msg);
|
|
29
|
+
void scrypt_set_fatal_error(scrypt_fatal_errorfn fn);
|
|
30
|
+
|
|
31
|
+
void scrypt(const unsigned char *password, size_t password_len, const unsigned char *salt, size_t salt_len, unsigned char Nfactor, unsigned char rfactor, unsigned char pfactor, unsigned char *out, size_t bytes);
|
|
32
|
+
|
|
33
|
+
unsigned char GetNfactorJane(int nTimestamp, int nChainStartTime, int nMin, int nMax);
|
|
34
|
+
void scryptjane_hash(const void* input, size_t inputlen, uint32_t *res, unsigned char Nfactor);
|
|
35
|
+
|
|
36
|
+
#endif /* SCRYPT_JANE_H */
|
package/scryptn.c
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright 2009 Colin Percival, 2011 ArtForz
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions
|
|
7
|
+
* are met:
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
|
13
|
+
*
|
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
15
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
18
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
20
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
21
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
22
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
23
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
24
|
+
* SUCH DAMAGE.
|
|
25
|
+
*
|
|
26
|
+
* This file was originally written by Colin Percival as part of the Tarsnap
|
|
27
|
+
* online backup system.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
#include <stdlib.h>
|
|
32
|
+
#include <string.h>
|
|
33
|
+
|
|
34
|
+
#include "scryptn.h"
|
|
35
|
+
#include "sha256.h"
|
|
36
|
+
|
|
37
|
+
static void blkcpy(void *, void *, size_t);
|
|
38
|
+
static void blkxor(void *, void *, size_t);
|
|
39
|
+
static void salsa20_8(uint32_t[16]);
|
|
40
|
+
static void blockmix_salsa8(uint32_t *, uint32_t *, uint32_t *, size_t);
|
|
41
|
+
static uint64_t integerify(void *, size_t);
|
|
42
|
+
static void smix(uint8_t *, size_t, uint64_t, uint32_t *, uint32_t *);
|
|
43
|
+
|
|
44
|
+
static void
|
|
45
|
+
blkcpy(void * dest, void * src, size_t len)
|
|
46
|
+
{
|
|
47
|
+
size_t * D = dest;
|
|
48
|
+
size_t * S = src;
|
|
49
|
+
size_t L = len / sizeof(size_t);
|
|
50
|
+
size_t i;
|
|
51
|
+
|
|
52
|
+
for (i = 0; i < L; i++)
|
|
53
|
+
D[i] = S[i];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static void
|
|
57
|
+
blkxor(void * dest, void * src, size_t len)
|
|
58
|
+
{
|
|
59
|
+
size_t * D = dest;
|
|
60
|
+
size_t * S = src;
|
|
61
|
+
size_t L = len / sizeof(size_t);
|
|
62
|
+
size_t i;
|
|
63
|
+
|
|
64
|
+
for (i = 0; i < L; i++)
|
|
65
|
+
D[i] ^= S[i];
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* salsa20_8(B):
|
|
70
|
+
* Apply the salsa20/8 core to the provided block.
|
|
71
|
+
*/
|
|
72
|
+
static void
|
|
73
|
+
salsa20_8(uint32_t B[16])
|
|
74
|
+
{
|
|
75
|
+
uint32_t x[16];
|
|
76
|
+
size_t i;
|
|
77
|
+
|
|
78
|
+
blkcpy(x, B, 64);
|
|
79
|
+
for (i = 0; i < 8; i += 2) {
|
|
80
|
+
#define R(a,b) (((a) << (b)) | ((a) >> (32 - (b))))
|
|
81
|
+
/* Operate on columns. */
|
|
82
|
+
x[ 4] ^= R(x[ 0]+x[12], 7); x[ 8] ^= R(x[ 4]+x[ 0], 9);
|
|
83
|
+
x[12] ^= R(x[ 8]+x[ 4],13); x[ 0] ^= R(x[12]+x[ 8],18);
|
|
84
|
+
|
|
85
|
+
x[ 9] ^= R(x[ 5]+x[ 1], 7); x[13] ^= R(x[ 9]+x[ 5], 9);
|
|
86
|
+
x[ 1] ^= R(x[13]+x[ 9],13); x[ 5] ^= R(x[ 1]+x[13],18);
|
|
87
|
+
|
|
88
|
+
x[14] ^= R(x[10]+x[ 6], 7); x[ 2] ^= R(x[14]+x[10], 9);
|
|
89
|
+
x[ 6] ^= R(x[ 2]+x[14],13); x[10] ^= R(x[ 6]+x[ 2],18);
|
|
90
|
+
|
|
91
|
+
x[ 3] ^= R(x[15]+x[11], 7); x[ 7] ^= R(x[ 3]+x[15], 9);
|
|
92
|
+
x[11] ^= R(x[ 7]+x[ 3],13); x[15] ^= R(x[11]+x[ 7],18);
|
|
93
|
+
|
|
94
|
+
/* Operate on rows. */
|
|
95
|
+
x[ 1] ^= R(x[ 0]+x[ 3], 7); x[ 2] ^= R(x[ 1]+x[ 0], 9);
|
|
96
|
+
x[ 3] ^= R(x[ 2]+x[ 1],13); x[ 0] ^= R(x[ 3]+x[ 2],18);
|
|
97
|
+
|
|
98
|
+
x[ 6] ^= R(x[ 5]+x[ 4], 7); x[ 7] ^= R(x[ 6]+x[ 5], 9);
|
|
99
|
+
x[ 4] ^= R(x[ 7]+x[ 6],13); x[ 5] ^= R(x[ 4]+x[ 7],18);
|
|
100
|
+
|
|
101
|
+
x[11] ^= R(x[10]+x[ 9], 7); x[ 8] ^= R(x[11]+x[10], 9);
|
|
102
|
+
x[ 9] ^= R(x[ 8]+x[11],13); x[10] ^= R(x[ 9]+x[ 8],18);
|
|
103
|
+
|
|
104
|
+
x[12] ^= R(x[15]+x[14], 7); x[13] ^= R(x[12]+x[15], 9);
|
|
105
|
+
x[14] ^= R(x[13]+x[12],13); x[15] ^= R(x[14]+x[13],18);
|
|
106
|
+
#undef R
|
|
107
|
+
}
|
|
108
|
+
for (i = 0; i < 16; i++)
|
|
109
|
+
B[i] += x[i];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* blockmix_salsa8(Bin, Bout, X, r):
|
|
114
|
+
* Compute Bout = BlockMix_{salsa20/8, r}(Bin). The input Bin must be 128r
|
|
115
|
+
* bytes in length; the output Bout must also be the same size. The
|
|
116
|
+
* temporary space X must be 64 bytes.
|
|
117
|
+
*/
|
|
118
|
+
static void
|
|
119
|
+
blockmix_salsa8(uint32_t * Bin, uint32_t * Bout, uint32_t * X, size_t r)
|
|
120
|
+
{
|
|
121
|
+
size_t i;
|
|
122
|
+
|
|
123
|
+
/* 1: X <-- B_{2r - 1} */
|
|
124
|
+
blkcpy(X, &Bin[(2 * r - 1) * 16], 64);
|
|
125
|
+
|
|
126
|
+
/* 2: for i = 0 to 2r - 1 do */
|
|
127
|
+
for (i = 0; i < 2 * r; i += 2) {
|
|
128
|
+
/* 3: X <-- H(X \xor B_i) */
|
|
129
|
+
blkxor(X, &Bin[i * 16], 64);
|
|
130
|
+
salsa20_8(X);
|
|
131
|
+
|
|
132
|
+
/* 4: Y_i <-- X */
|
|
133
|
+
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
|
134
|
+
blkcpy(&Bout[i * 8], X, 64);
|
|
135
|
+
|
|
136
|
+
/* 3: X <-- H(X \xor B_i) */
|
|
137
|
+
blkxor(X, &Bin[i * 16 + 16], 64);
|
|
138
|
+
salsa20_8(X);
|
|
139
|
+
|
|
140
|
+
/* 4: Y_i <-- X */
|
|
141
|
+
/* 6: B' <-- (Y_0, Y_2 ... Y_{2r-2}, Y_1, Y_3 ... Y_{2r-1}) */
|
|
142
|
+
blkcpy(&Bout[i * 8 + r * 16], X, 64);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* integerify(B, r):
|
|
148
|
+
* Return the result of parsing B_{2r-1} as a little-endian integer.
|
|
149
|
+
*/
|
|
150
|
+
static uint64_t
|
|
151
|
+
integerify(void * B, size_t r)
|
|
152
|
+
{
|
|
153
|
+
uint32_t * X = (void *)((uintptr_t)(B) + (2 * r - 1) * 64);
|
|
154
|
+
|
|
155
|
+
return (((uint64_t)(X[1]) << 32) + X[0]);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* smix(B, r, N, V, XY):
|
|
160
|
+
* Compute B = SMix_r(B, N). The input B must be 128r bytes in length;
|
|
161
|
+
* the temporary storage V must be 128rN bytes in length; the temporary
|
|
162
|
+
* storage XY must be 256r + 64 bytes in length. The value N must be a
|
|
163
|
+
* power of 2 greater than 1. The arrays B, V, and XY must be aligned to a
|
|
164
|
+
* multiple of 64 bytes.
|
|
165
|
+
*/
|
|
166
|
+
static void
|
|
167
|
+
smix(uint8_t * B, size_t r, uint64_t N, uint32_t * V, uint32_t * XY)
|
|
168
|
+
{
|
|
169
|
+
uint32_t * X = XY;
|
|
170
|
+
uint32_t * Y = &XY[32 * r];
|
|
171
|
+
uint32_t * Z = &XY[64 * r];
|
|
172
|
+
uint64_t i;
|
|
173
|
+
uint64_t j;
|
|
174
|
+
size_t k;
|
|
175
|
+
|
|
176
|
+
/* 1: X <-- B */
|
|
177
|
+
for (k = 0; k < 32 * r; k++)
|
|
178
|
+
X[k] = le32dec(&B[4 * k]);
|
|
179
|
+
|
|
180
|
+
/* 2: for i = 0 to N - 1 do */
|
|
181
|
+
for (i = 0; i < N; i += 2) {
|
|
182
|
+
/* 3: V_i <-- X */
|
|
183
|
+
blkcpy(&V[i * (32 * r)], X, 128 * r);
|
|
184
|
+
|
|
185
|
+
/* 4: X <-- H(X) */
|
|
186
|
+
blockmix_salsa8(X, Y, Z, r);
|
|
187
|
+
|
|
188
|
+
/* 3: V_i <-- X */
|
|
189
|
+
blkcpy(&V[(i + 1) * (32 * r)], Y, 128 * r);
|
|
190
|
+
|
|
191
|
+
/* 4: X <-- H(X) */
|
|
192
|
+
blockmix_salsa8(Y, X, Z, r);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/* 6: for i = 0 to N - 1 do */
|
|
196
|
+
for (i = 0; i < N; i += 2) {
|
|
197
|
+
/* 7: j <-- Integerify(X) mod N */
|
|
198
|
+
j = integerify(X, r) & (N - 1);
|
|
199
|
+
|
|
200
|
+
/* 8: X <-- H(X \xor V_j) */
|
|
201
|
+
blkxor(X, &V[j * (32 * r)], 128 * r);
|
|
202
|
+
blockmix_salsa8(X, Y, Z, r);
|
|
203
|
+
|
|
204
|
+
/* 7: j <-- Integerify(X) mod N */
|
|
205
|
+
j = integerify(Y, r) & (N - 1);
|
|
206
|
+
|
|
207
|
+
/* 8: X <-- H(X \xor V_j) */
|
|
208
|
+
blkxor(Y, &V[j * (32 * r)], 128 * r);
|
|
209
|
+
blockmix_salsa8(Y, X, Z, r);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/* 10: B' <-- X */
|
|
213
|
+
for (k = 0; k < 32 * r; k++)
|
|
214
|
+
le32enc(&B[4 * k], X[k]);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/* cpu and memory intensive function to transform a 80 byte buffer into a 32 byte output
|
|
218
|
+
scratchpad size needs to be at least 63 + (128 * r * p) + (256 * r + 64) + (128 * r * N) bytes
|
|
219
|
+
*/
|
|
220
|
+
void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len)
|
|
221
|
+
{
|
|
222
|
+
uint8_t * B;
|
|
223
|
+
uint32_t * V;
|
|
224
|
+
uint32_t * XY;
|
|
225
|
+
uint32_t i;
|
|
226
|
+
|
|
227
|
+
//const uint32_t N = 1024;
|
|
228
|
+
uint32_t r=R;
|
|
229
|
+
const uint32_t p = 1;
|
|
230
|
+
|
|
231
|
+
B = (uint8_t *)(((uintptr_t)(scratchpad) + 63) & ~ (uintptr_t)(63));
|
|
232
|
+
XY = (uint32_t *)(B + (128 * r * p));
|
|
233
|
+
V = (uint32_t *)(B + (128 * r * p) + (256 * r + 64));
|
|
234
|
+
|
|
235
|
+
/* 1: (B_0 ... B_{p-1}) <-- PBKDF2(P, S, 1, p * MFLen) */
|
|
236
|
+
PBKDF2_SHA256((const uint8_t*)input, len, (const uint8_t*)input, len, 1, B, p * 128 * r);
|
|
237
|
+
|
|
238
|
+
/* 2: for i = 0 to p - 1 do */
|
|
239
|
+
for (i = 0; i < p; i++) {
|
|
240
|
+
/* 3: B_i <-- MF(B_i, N) */
|
|
241
|
+
smix(&B[i * 128 * r], r, N, V, XY);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* 5: DK <-- PBKDF2(P, B, 1, dkLen) */
|
|
245
|
+
PBKDF2_SHA256((const uint8_t*)input, len, B, p * 128 * r, 1, (uint8_t*)output, 32);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len)
|
|
249
|
+
{
|
|
250
|
+
//char scratchpad[131583];
|
|
251
|
+
char *scratchpad;
|
|
252
|
+
|
|
253
|
+
// align on 4 byte boundary
|
|
254
|
+
scratchpad = (char*)malloc(128*N*R + (128*R)+(256*R)+64+64);
|
|
255
|
+
scrypt_N_R_1_256_sp(input, output, scratchpad, N, R, len);
|
|
256
|
+
free(scratchpad);
|
|
257
|
+
}
|
|
258
|
+
|
package/scryptn.h
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#ifndef SCRYPTN_H
|
|
2
|
+
#define SCRYPTN_H
|
|
3
|
+
#include <stdint.h>
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, uint32_t len);
|
|
9
|
+
void scrypt_N_R_1_256_sp(const char* input, char* output, char* scratchpad, uint32_t N, uint32_t R, uint32_t len);
|
|
10
|
+
//const int scrypt_scratchpad_size = 131583;
|
|
11
|
+
|
|
12
|
+
#ifdef __cplusplus
|
|
13
|
+
}
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#endif
|
package/sha1.c
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#include "sha1.h"
|
|
2
|
+
|
|
3
|
+
#include <string.h>
|
|
4
|
+
#include <openssl/sha.h>
|
|
5
|
+
|
|
6
|
+
#if defined(_MSC_VER)
|
|
7
|
+
#define __align(boundary, type) __declspec(align(boundary)) type
|
|
8
|
+
#else
|
|
9
|
+
#define __align(boundary, type) type __attribute__((aligned(boundary)))
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
inline void encodeb64(const unsigned char* pch, char* buff)
|
|
13
|
+
{
|
|
14
|
+
const char *pbase64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
15
|
+
int mode = 0, left = 0;
|
|
16
|
+
const int len = 20;
|
|
17
|
+
const unsigned char *pchEnd = pch + len;
|
|
18
|
+
while (pch < pchEnd) {
|
|
19
|
+
int enc = *(pch++);
|
|
20
|
+
if (mode == 0) {
|
|
21
|
+
*buff++ = pbase64[enc >> 2];
|
|
22
|
+
left = (enc & 3) << 4;
|
|
23
|
+
mode = 1;
|
|
24
|
+
}
|
|
25
|
+
else if (mode == 1) {
|
|
26
|
+
*buff++ = pbase64[left | (enc >> 4)];
|
|
27
|
+
left = (enc & 15) << 2;
|
|
28
|
+
mode = 2;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
*buff++ = pbase64[left | (enc >> 6)];
|
|
32
|
+
*buff++ = pbase64[enc & 63];
|
|
33
|
+
mode = 0;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
*buff = pbase64[left];
|
|
37
|
+
*(buff + 1) = 0;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
void sha1_hash(const char* input, char* output, uint32_t len)
|
|
41
|
+
{
|
|
42
|
+
__align(32, char str[38]); // 26 + 11 + 1
|
|
43
|
+
__align(32, uint32_t prehash[5]);
|
|
44
|
+
__align(32, uint32_t hash[5]) = { 0 };
|
|
45
|
+
int i = 0;
|
|
46
|
+
SHA_CTX ctx;
|
|
47
|
+
SHA1_Init(&ctx);
|
|
48
|
+
SHA1_Update(&ctx, (void *)input, len);
|
|
49
|
+
SHA1_Final((void *)prehash, &ctx);
|
|
50
|
+
encodeb64((const unsigned char *)prehash, str);
|
|
51
|
+
memcpy(&str[26], str, 11);
|
|
52
|
+
str[37] = 0;
|
|
53
|
+
for (i = 0; i < 26; i++) {
|
|
54
|
+
SHA1_Init(&ctx);
|
|
55
|
+
SHA1_Update(&ctx, (void *)&str[i], 12);
|
|
56
|
+
SHA1_Final((void *)prehash, &ctx);
|
|
57
|
+
hash[0] ^= prehash[0];
|
|
58
|
+
hash[1] ^= prehash[1];
|
|
59
|
+
hash[2] ^= prehash[2];
|
|
60
|
+
hash[3] ^= prehash[3];
|
|
61
|
+
hash[4] ^= prehash[4];
|
|
62
|
+
}
|
|
63
|
+
memset(output, 0, 32 - 20);
|
|
64
|
+
memcpy(&output[32 - 20], hash, 20);
|
|
65
|
+
}
|