@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/crypto/aesb.c
ADDED
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/*
|
|
2
|
+
---------------------------------------------------------------------------
|
|
3
|
+
Copyright (c) 1998-2013, Brian Gladman, Worcester, UK. All rights reserved.
|
|
4
|
+
|
|
5
|
+
The redistribution and use of this software (with or without changes)
|
|
6
|
+
is allowed without the payment of fees or royalties provided that:
|
|
7
|
+
|
|
8
|
+
source code distributions include the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer;
|
|
10
|
+
|
|
11
|
+
binary distributions include the above copyright notice, this list
|
|
12
|
+
of conditions and the following disclaimer in their documentation.
|
|
13
|
+
|
|
14
|
+
This software is provided 'as is' with no explicit or implied warranties
|
|
15
|
+
in respect of its operation, including, but not limited to, correctness
|
|
16
|
+
and fitness for purpose.
|
|
17
|
+
---------------------------------------------------------------------------
|
|
18
|
+
Issue Date: 20/12/2007
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#include <stdint.h>
|
|
22
|
+
|
|
23
|
+
#if defined(__cplusplus)
|
|
24
|
+
extern "C"
|
|
25
|
+
{
|
|
26
|
+
#endif
|
|
27
|
+
|
|
28
|
+
#define TABLE_ALIGN 32
|
|
29
|
+
#define WPOLY 0x011b
|
|
30
|
+
#define N_COLS 4
|
|
31
|
+
#define AES_BLOCK_SIZE 16
|
|
32
|
+
#define RC_LENGTH (5 * (AES_BLOCK_SIZE / 4 - 2))
|
|
33
|
+
|
|
34
|
+
#if defined(_MSC_VER)
|
|
35
|
+
#define ALIGN __declspec(align(TABLE_ALIGN))
|
|
36
|
+
#elif defined(__GNUC__)
|
|
37
|
+
#define ALIGN __attribute__ ((aligned(16)))
|
|
38
|
+
#else
|
|
39
|
+
#define ALIGN
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#define rf1(r,c) (r)
|
|
43
|
+
#define word_in(x,c) (*((uint32_t*)(x)+(c)))
|
|
44
|
+
#define word_out(x,c,v) (*((uint32_t*)(x)+(c)) = (v))
|
|
45
|
+
|
|
46
|
+
#define s(x,c) x[c]
|
|
47
|
+
#define si(y,x,c) (s(y,c) = word_in(x, c))
|
|
48
|
+
#define so(y,x,c) word_out(y, c, s(x,c))
|
|
49
|
+
#define state_in(y,x) si(y,x,0); si(y,x,1); si(y,x,2); si(y,x,3)
|
|
50
|
+
#define state_out(y,x) so(y,x,0); so(y,x,1); so(y,x,2); so(y,x,3)
|
|
51
|
+
#define round(rm,y,x,k) rm(y,x,k,0); rm(y,x,k,1); rm(y,x,k,2); rm(y,x,k,3)
|
|
52
|
+
#define to_byte(x) ((x) & 0xff)
|
|
53
|
+
#define bval(x,n) to_byte((x) >> (8 * (n)))
|
|
54
|
+
|
|
55
|
+
#define fwd_var(x,r,c)\
|
|
56
|
+
( r == 0 ? ( c == 0 ? s(x,0) : c == 1 ? s(x,1) : c == 2 ? s(x,2) : s(x,3))\
|
|
57
|
+
: r == 1 ? ( c == 0 ? s(x,1) : c == 1 ? s(x,2) : c == 2 ? s(x,3) : s(x,0))\
|
|
58
|
+
: r == 2 ? ( c == 0 ? s(x,2) : c == 1 ? s(x,3) : c == 2 ? s(x,0) : s(x,1))\
|
|
59
|
+
: ( c == 0 ? s(x,3) : c == 1 ? s(x,0) : c == 2 ? s(x,1) : s(x,2)))
|
|
60
|
+
|
|
61
|
+
#define fwd_rnd(y,x,k,c) (s(y,c) = (k)[c] ^ four_tables(x,t_use(f,n),fwd_var,rf1,c))
|
|
62
|
+
|
|
63
|
+
#define sb_data(w) {\
|
|
64
|
+
w(0x63), w(0x7c), w(0x77), w(0x7b), w(0xf2), w(0x6b), w(0x6f), w(0xc5),\
|
|
65
|
+
w(0x30), w(0x01), w(0x67), w(0x2b), w(0xfe), w(0xd7), w(0xab), w(0x76),\
|
|
66
|
+
w(0xca), w(0x82), w(0xc9), w(0x7d), w(0xfa), w(0x59), w(0x47), w(0xf0),\
|
|
67
|
+
w(0xad), w(0xd4), w(0xa2), w(0xaf), w(0x9c), w(0xa4), w(0x72), w(0xc0),\
|
|
68
|
+
w(0xb7), w(0xfd), w(0x93), w(0x26), w(0x36), w(0x3f), w(0xf7), w(0xcc),\
|
|
69
|
+
w(0x34), w(0xa5), w(0xe5), w(0xf1), w(0x71), w(0xd8), w(0x31), w(0x15),\
|
|
70
|
+
w(0x04), w(0xc7), w(0x23), w(0xc3), w(0x18), w(0x96), w(0x05), w(0x9a),\
|
|
71
|
+
w(0x07), w(0x12), w(0x80), w(0xe2), w(0xeb), w(0x27), w(0xb2), w(0x75),\
|
|
72
|
+
w(0x09), w(0x83), w(0x2c), w(0x1a), w(0x1b), w(0x6e), w(0x5a), w(0xa0),\
|
|
73
|
+
w(0x52), w(0x3b), w(0xd6), w(0xb3), w(0x29), w(0xe3), w(0x2f), w(0x84),\
|
|
74
|
+
w(0x53), w(0xd1), w(0x00), w(0xed), w(0x20), w(0xfc), w(0xb1), w(0x5b),\
|
|
75
|
+
w(0x6a), w(0xcb), w(0xbe), w(0x39), w(0x4a), w(0x4c), w(0x58), w(0xcf),\
|
|
76
|
+
w(0xd0), w(0xef), w(0xaa), w(0xfb), w(0x43), w(0x4d), w(0x33), w(0x85),\
|
|
77
|
+
w(0x45), w(0xf9), w(0x02), w(0x7f), w(0x50), w(0x3c), w(0x9f), w(0xa8),\
|
|
78
|
+
w(0x51), w(0xa3), w(0x40), w(0x8f), w(0x92), w(0x9d), w(0x38), w(0xf5),\
|
|
79
|
+
w(0xbc), w(0xb6), w(0xda), w(0x21), w(0x10), w(0xff), w(0xf3), w(0xd2),\
|
|
80
|
+
w(0xcd), w(0x0c), w(0x13), w(0xec), w(0x5f), w(0x97), w(0x44), w(0x17),\
|
|
81
|
+
w(0xc4), w(0xa7), w(0x7e), w(0x3d), w(0x64), w(0x5d), w(0x19), w(0x73),\
|
|
82
|
+
w(0x60), w(0x81), w(0x4f), w(0xdc), w(0x22), w(0x2a), w(0x90), w(0x88),\
|
|
83
|
+
w(0x46), w(0xee), w(0xb8), w(0x14), w(0xde), w(0x5e), w(0x0b), w(0xdb),\
|
|
84
|
+
w(0xe0), w(0x32), w(0x3a), w(0x0a), w(0x49), w(0x06), w(0x24), w(0x5c),\
|
|
85
|
+
w(0xc2), w(0xd3), w(0xac), w(0x62), w(0x91), w(0x95), w(0xe4), w(0x79),\
|
|
86
|
+
w(0xe7), w(0xc8), w(0x37), w(0x6d), w(0x8d), w(0xd5), w(0x4e), w(0xa9),\
|
|
87
|
+
w(0x6c), w(0x56), w(0xf4), w(0xea), w(0x65), w(0x7a), w(0xae), w(0x08),\
|
|
88
|
+
w(0xba), w(0x78), w(0x25), w(0x2e), w(0x1c), w(0xa6), w(0xb4), w(0xc6),\
|
|
89
|
+
w(0xe8), w(0xdd), w(0x74), w(0x1f), w(0x4b), w(0xbd), w(0x8b), w(0x8a),\
|
|
90
|
+
w(0x70), w(0x3e), w(0xb5), w(0x66), w(0x48), w(0x03), w(0xf6), w(0x0e),\
|
|
91
|
+
w(0x61), w(0x35), w(0x57), w(0xb9), w(0x86), w(0xc1), w(0x1d), w(0x9e),\
|
|
92
|
+
w(0xe1), w(0xf8), w(0x98), w(0x11), w(0x69), w(0xd9), w(0x8e), w(0x94),\
|
|
93
|
+
w(0x9b), w(0x1e), w(0x87), w(0xe9), w(0xce), w(0x55), w(0x28), w(0xdf),\
|
|
94
|
+
w(0x8c), w(0xa1), w(0x89), w(0x0d), w(0xbf), w(0xe6), w(0x42), w(0x68),\
|
|
95
|
+
w(0x41), w(0x99), w(0x2d), w(0x0f), w(0xb0), w(0x54), w(0xbb), w(0x16) }
|
|
96
|
+
|
|
97
|
+
#define rc_data(w) {\
|
|
98
|
+
w(0x01), w(0x02), w(0x04), w(0x08), w(0x10),w(0x20), w(0x40), w(0x80),\
|
|
99
|
+
w(0x1b), w(0x36) }
|
|
100
|
+
|
|
101
|
+
#define bytes2word(b0, b1, b2, b3) (((uint32_t)(b3) << 24) | \
|
|
102
|
+
((uint32_t)(b2) << 16) | ((uint32_t)(b1) << 8) | (b0))
|
|
103
|
+
|
|
104
|
+
#define h0(x) (x)
|
|
105
|
+
#define w0(p) bytes2word(p, 0, 0, 0)
|
|
106
|
+
#define w1(p) bytes2word(0, p, 0, 0)
|
|
107
|
+
#define w2(p) bytes2word(0, 0, p, 0)
|
|
108
|
+
#define w3(p) bytes2word(0, 0, 0, p)
|
|
109
|
+
|
|
110
|
+
#define u0(p) bytes2word(f2(p), p, p, f3(p))
|
|
111
|
+
#define u1(p) bytes2word(f3(p), f2(p), p, p)
|
|
112
|
+
#define u2(p) bytes2word(p, f3(p), f2(p), p)
|
|
113
|
+
#define u3(p) bytes2word(p, p, f3(p), f2(p))
|
|
114
|
+
|
|
115
|
+
#define v0(p) bytes2word(fe(p), f9(p), fd(p), fb(p))
|
|
116
|
+
#define v1(p) bytes2word(fb(p), fe(p), f9(p), fd(p))
|
|
117
|
+
#define v2(p) bytes2word(fd(p), fb(p), fe(p), f9(p))
|
|
118
|
+
#define v3(p) bytes2word(f9(p), fd(p), fb(p), fe(p))
|
|
119
|
+
|
|
120
|
+
#define f2(x) ((x<<1) ^ (((x>>7) & 1) * WPOLY))
|
|
121
|
+
#define f4(x) ((x<<2) ^ (((x>>6) & 1) * WPOLY) ^ (((x>>6) & 2) * WPOLY))
|
|
122
|
+
#define f8(x) ((x<<3) ^ (((x>>5) & 1) * WPOLY) ^ (((x>>5) & 2) * WPOLY) ^ (((x>>5) & 4) * WPOLY))
|
|
123
|
+
#define f3(x) (f2(x) ^ x)
|
|
124
|
+
#define f9(x) (f8(x) ^ x)
|
|
125
|
+
#define fb(x) (f8(x) ^ f2(x) ^ x)
|
|
126
|
+
#define fd(x) (f8(x) ^ f4(x) ^ x)
|
|
127
|
+
#define fe(x) (f8(x) ^ f4(x) ^ f2(x))
|
|
128
|
+
|
|
129
|
+
#define t_dec(m,n) t_##m##n
|
|
130
|
+
#define t_set(m,n) t_##m##n
|
|
131
|
+
#define t_use(m,n) t_##m##n
|
|
132
|
+
|
|
133
|
+
#define d_4(t,n,b,e,f,g,h) ALIGN const t n[4][256] = { b(e), b(f), b(g), b(h) }
|
|
134
|
+
|
|
135
|
+
#define four_tables(x,tab,vf,rf,c) \
|
|
136
|
+
(tab[0][bval(vf(x,0,c),rf(0,c))] \
|
|
137
|
+
^ tab[1][bval(vf(x,1,c),rf(1,c))] \
|
|
138
|
+
^ tab[2][bval(vf(x,2,c),rf(2,c))] \
|
|
139
|
+
^ tab[3][bval(vf(x,3,c),rf(3,c))])
|
|
140
|
+
|
|
141
|
+
d_4(uint32_t, t_dec(f,n), sb_data, u0, u1, u2, u3);
|
|
142
|
+
|
|
143
|
+
void aesb_single_round(const uint8_t *in, uint8_t *out, uint8_t *expandedKey)
|
|
144
|
+
{
|
|
145
|
+
uint32_t b0[4], b1[4];
|
|
146
|
+
const uint32_t *kp = (uint32_t *) expandedKey;
|
|
147
|
+
state_in(b0, in);
|
|
148
|
+
|
|
149
|
+
round(fwd_rnd, b1, b0, kp);
|
|
150
|
+
|
|
151
|
+
state_out(out, b1);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
void aesb_pseudo_round(const uint8_t *in, uint8_t *out, uint8_t *expandedKey)
|
|
155
|
+
{
|
|
156
|
+
uint32_t b0[4], b1[4];
|
|
157
|
+
const uint32_t *kp = (uint32_t *) expandedKey;
|
|
158
|
+
state_in(b0, in);
|
|
159
|
+
|
|
160
|
+
round(fwd_rnd, b1, b0, kp);
|
|
161
|
+
round(fwd_rnd, b0, b1, kp + 1 * N_COLS);
|
|
162
|
+
round(fwd_rnd, b1, b0, kp + 2 * N_COLS);
|
|
163
|
+
round(fwd_rnd, b0, b1, kp + 3 * N_COLS);
|
|
164
|
+
round(fwd_rnd, b1, b0, kp + 4 * N_COLS);
|
|
165
|
+
round(fwd_rnd, b0, b1, kp + 5 * N_COLS);
|
|
166
|
+
round(fwd_rnd, b1, b0, kp + 6 * N_COLS);
|
|
167
|
+
round(fwd_rnd, b0, b1, kp + 7 * N_COLS);
|
|
168
|
+
round(fwd_rnd, b1, b0, kp + 8 * N_COLS);
|
|
169
|
+
round(fwd_rnd, b0, b1, kp + 9 * N_COLS);
|
|
170
|
+
|
|
171
|
+
state_out(out, b0);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
#if defined(__cplusplus)
|
|
176
|
+
}
|
|
177
|
+
#endif
|
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The blake256_* and blake224_* functions are largely copied from
|
|
3
|
+
* blake256_light.c and blake224_light.c from the BLAKE website:
|
|
4
|
+
*
|
|
5
|
+
* http://131002.net/blake/
|
|
6
|
+
*
|
|
7
|
+
* The hmac_* functions implement HMAC-BLAKE-256 and HMAC-BLAKE-224.
|
|
8
|
+
* HMAC is specified by RFC 2104.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
#include <string.h>
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <stdint.h>
|
|
14
|
+
#include "c_blake256.h"
|
|
15
|
+
|
|
16
|
+
#define U8TO32(p) \
|
|
17
|
+
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
|
|
18
|
+
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
|
|
19
|
+
#define U32TO8(p, v) \
|
|
20
|
+
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
|
|
21
|
+
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
|
|
22
|
+
|
|
23
|
+
const uint8_t sigma[][16] = {
|
|
24
|
+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
|
|
25
|
+
{14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
|
|
26
|
+
{11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
|
|
27
|
+
{ 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8},
|
|
28
|
+
{ 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13},
|
|
29
|
+
{ 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9},
|
|
30
|
+
{12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11},
|
|
31
|
+
{13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10},
|
|
32
|
+
{ 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5},
|
|
33
|
+
{10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0},
|
|
34
|
+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15},
|
|
35
|
+
{14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3},
|
|
36
|
+
{11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4},
|
|
37
|
+
{ 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const uint32_t cst[16] = {
|
|
41
|
+
0x243F6A88, 0x85A308D3, 0x13198A2E, 0x03707344,
|
|
42
|
+
0xA4093822, 0x299F31D0, 0x082EFA98, 0xEC4E6C89,
|
|
43
|
+
0x452821E6, 0x38D01377, 0xBE5466CF, 0x34E90C6C,
|
|
44
|
+
0xC0AC29B7, 0xC97C50DD, 0x3F84D5B5, 0xB5470917
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
static const uint8_t padding[] = {
|
|
48
|
+
0x80,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
|
49
|
+
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
void blake256_compress(state *S, const uint8_t *block) {
|
|
54
|
+
uint32_t v[16], m[16], i;
|
|
55
|
+
|
|
56
|
+
#define ROT(x,n) (((x)<<(32-n))|((x)>>(n)))
|
|
57
|
+
#define G(a,b,c,d,e) \
|
|
58
|
+
v[a] += (m[sigma[i][e]] ^ cst[sigma[i][e+1]]) + v[b]; \
|
|
59
|
+
v[d] = ROT(v[d] ^ v[a],16); \
|
|
60
|
+
v[c] += v[d]; \
|
|
61
|
+
v[b] = ROT(v[b] ^ v[c],12); \
|
|
62
|
+
v[a] += (m[sigma[i][e+1]] ^ cst[sigma[i][e]])+v[b]; \
|
|
63
|
+
v[d] = ROT(v[d] ^ v[a], 8); \
|
|
64
|
+
v[c] += v[d]; \
|
|
65
|
+
v[b] = ROT(v[b] ^ v[c], 7);
|
|
66
|
+
|
|
67
|
+
for (i = 0; i < 16; ++i) m[i] = U8TO32(block + i * 4);
|
|
68
|
+
for (i = 0; i < 8; ++i) v[i] = S->h[i];
|
|
69
|
+
v[ 8] = S->s[0] ^ 0x243F6A88;
|
|
70
|
+
v[ 9] = S->s[1] ^ 0x85A308D3;
|
|
71
|
+
v[10] = S->s[2] ^ 0x13198A2E;
|
|
72
|
+
v[11] = S->s[3] ^ 0x03707344;
|
|
73
|
+
v[12] = 0xA4093822;
|
|
74
|
+
v[13] = 0x299F31D0;
|
|
75
|
+
v[14] = 0x082EFA98;
|
|
76
|
+
v[15] = 0xEC4E6C89;
|
|
77
|
+
|
|
78
|
+
if (S->nullt == 0) {
|
|
79
|
+
v[12] ^= S->t[0];
|
|
80
|
+
v[13] ^= S->t[0];
|
|
81
|
+
v[14] ^= S->t[1];
|
|
82
|
+
v[15] ^= S->t[1];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
for (i = 0; i < 14; ++i) {
|
|
86
|
+
G(0, 4, 8, 12, 0);
|
|
87
|
+
G(1, 5, 9, 13, 2);
|
|
88
|
+
G(2, 6, 10, 14, 4);
|
|
89
|
+
G(3, 7, 11, 15, 6);
|
|
90
|
+
G(3, 4, 9, 14, 14);
|
|
91
|
+
G(2, 7, 8, 13, 12);
|
|
92
|
+
G(0, 5, 10, 15, 8);
|
|
93
|
+
G(1, 6, 11, 12, 10);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
for (i = 0; i < 16; ++i) S->h[i % 8] ^= v[i];
|
|
97
|
+
for (i = 0; i < 8; ++i) S->h[i] ^= S->s[i % 4];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
void blake256_init(state *S) {
|
|
101
|
+
S->h[0] = 0x6A09E667;
|
|
102
|
+
S->h[1] = 0xBB67AE85;
|
|
103
|
+
S->h[2] = 0x3C6EF372;
|
|
104
|
+
S->h[3] = 0xA54FF53A;
|
|
105
|
+
S->h[4] = 0x510E527F;
|
|
106
|
+
S->h[5] = 0x9B05688C;
|
|
107
|
+
S->h[6] = 0x1F83D9AB;
|
|
108
|
+
S->h[7] = 0x5BE0CD19;
|
|
109
|
+
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
|
|
110
|
+
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
void blake224_init(state *S) {
|
|
114
|
+
S->h[0] = 0xC1059ED8;
|
|
115
|
+
S->h[1] = 0x367CD507;
|
|
116
|
+
S->h[2] = 0x3070DD17;
|
|
117
|
+
S->h[3] = 0xF70E5939;
|
|
118
|
+
S->h[4] = 0xFFC00B31;
|
|
119
|
+
S->h[5] = 0x68581511;
|
|
120
|
+
S->h[6] = 0x64F98FA7;
|
|
121
|
+
S->h[7] = 0xBEFA4FA4;
|
|
122
|
+
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
|
|
123
|
+
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// datalen = number of bits
|
|
127
|
+
void blake256_update(state *S, const uint8_t *data, uint64_t datalen) {
|
|
128
|
+
int left = S->buflen >> 3;
|
|
129
|
+
int fill = 64 - left;
|
|
130
|
+
|
|
131
|
+
if (left && (((datalen >> 3) & 0x3F) >= (unsigned) fill)) {
|
|
132
|
+
memcpy((void *) (S->buf + left), (void *) data, fill);
|
|
133
|
+
S->t[0] += 512;
|
|
134
|
+
if (S->t[0] == 0) S->t[1]++;
|
|
135
|
+
blake256_compress(S, S->buf);
|
|
136
|
+
data += fill;
|
|
137
|
+
datalen -= (fill << 3);
|
|
138
|
+
left = 0;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
while (datalen >= 512) {
|
|
142
|
+
S->t[0] += 512;
|
|
143
|
+
if (S->t[0] == 0) S->t[1]++;
|
|
144
|
+
blake256_compress(S, data);
|
|
145
|
+
data += 64;
|
|
146
|
+
datalen -= 512;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (datalen > 0) {
|
|
150
|
+
memcpy((void *) (S->buf + left), (void *) data, datalen >> 3);
|
|
151
|
+
S->buflen = (left << 3) + (int)datalen;
|
|
152
|
+
} else {
|
|
153
|
+
S->buflen = 0;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// datalen = number of bits
|
|
158
|
+
void blake224_update(state *S, const uint8_t *data, uint64_t datalen) {
|
|
159
|
+
blake256_update(S, data, datalen);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
void blake256_final_h(state *S, uint8_t *digest, uint8_t pa, uint8_t pb) {
|
|
163
|
+
uint8_t msglen[8];
|
|
164
|
+
uint32_t lo = S->t[0] + S->buflen, hi = S->t[1];
|
|
165
|
+
if (lo < (unsigned) S->buflen) hi++;
|
|
166
|
+
U32TO8(msglen + 0, hi);
|
|
167
|
+
U32TO8(msglen + 4, lo);
|
|
168
|
+
|
|
169
|
+
if (S->buflen == 440) { /* one padding byte */
|
|
170
|
+
S->t[0] -= 8;
|
|
171
|
+
blake256_update(S, &pa, 8);
|
|
172
|
+
} else {
|
|
173
|
+
if (S->buflen < 440) { /* enough space to fill the block */
|
|
174
|
+
if (S->buflen == 0) S->nullt = 1;
|
|
175
|
+
S->t[0] -= 440 - S->buflen;
|
|
176
|
+
blake256_update(S, padding, 440 - S->buflen);
|
|
177
|
+
} else { /* need 2 compressions */
|
|
178
|
+
S->t[0] -= 512 - S->buflen;
|
|
179
|
+
blake256_update(S, padding, 512 - S->buflen);
|
|
180
|
+
S->t[0] -= 440;
|
|
181
|
+
blake256_update(S, padding + 1, 440);
|
|
182
|
+
S->nullt = 1;
|
|
183
|
+
}
|
|
184
|
+
blake256_update(S, &pb, 8);
|
|
185
|
+
S->t[0] -= 8;
|
|
186
|
+
}
|
|
187
|
+
S->t[0] -= 64;
|
|
188
|
+
blake256_update(S, msglen, 64);
|
|
189
|
+
|
|
190
|
+
U32TO8(digest + 0, S->h[0]);
|
|
191
|
+
U32TO8(digest + 4, S->h[1]);
|
|
192
|
+
U32TO8(digest + 8, S->h[2]);
|
|
193
|
+
U32TO8(digest + 12, S->h[3]);
|
|
194
|
+
U32TO8(digest + 16, S->h[4]);
|
|
195
|
+
U32TO8(digest + 20, S->h[5]);
|
|
196
|
+
U32TO8(digest + 24, S->h[6]);
|
|
197
|
+
U32TO8(digest + 28, S->h[7]);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
void blake256_final(state *S, uint8_t *digest) {
|
|
201
|
+
blake256_final_h(S, digest, 0x81, 0x01);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
void blake224_final(state *S, uint8_t *digest) {
|
|
205
|
+
blake256_final_h(S, digest, 0x80, 0x00);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// inlen = number of bytes
|
|
209
|
+
void blake256_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) {
|
|
210
|
+
state S;
|
|
211
|
+
blake256_init(&S);
|
|
212
|
+
blake256_update(&S, in, inlen * 8);
|
|
213
|
+
blake256_final(&S, out);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// inlen = number of bytes
|
|
217
|
+
void blake224_hash(uint8_t *out, const uint8_t *in, uint64_t inlen) {
|
|
218
|
+
state S;
|
|
219
|
+
blake224_init(&S);
|
|
220
|
+
blake224_update(&S, in, inlen * 8);
|
|
221
|
+
blake224_final(&S, out);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// keylen = number of bytes
|
|
225
|
+
void hmac_blake256_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) {
|
|
226
|
+
const uint8_t *key = _key;
|
|
227
|
+
uint8_t keyhash[32];
|
|
228
|
+
uint8_t pad[64];
|
|
229
|
+
uint64_t i;
|
|
230
|
+
|
|
231
|
+
if (keylen > 64) {
|
|
232
|
+
blake256_hash(keyhash, key, keylen);
|
|
233
|
+
key = keyhash;
|
|
234
|
+
keylen = 32;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
blake256_init(&S->inner);
|
|
238
|
+
memset(pad, 0x36, 64);
|
|
239
|
+
for (i = 0; i < keylen; ++i) {
|
|
240
|
+
pad[i] ^= key[i];
|
|
241
|
+
}
|
|
242
|
+
blake256_update(&S->inner, pad, 512);
|
|
243
|
+
|
|
244
|
+
blake256_init(&S->outer);
|
|
245
|
+
memset(pad, 0x5c, 64);
|
|
246
|
+
for (i = 0; i < keylen; ++i) {
|
|
247
|
+
pad[i] ^= key[i];
|
|
248
|
+
}
|
|
249
|
+
blake256_update(&S->outer, pad, 512);
|
|
250
|
+
|
|
251
|
+
memset(keyhash, 0, 32);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// keylen = number of bytes
|
|
255
|
+
void hmac_blake224_init(hmac_state *S, const uint8_t *_key, uint64_t keylen) {
|
|
256
|
+
const uint8_t *key = _key;
|
|
257
|
+
uint8_t keyhash[32];
|
|
258
|
+
uint8_t pad[64];
|
|
259
|
+
uint64_t i;
|
|
260
|
+
|
|
261
|
+
if (keylen > 64) {
|
|
262
|
+
blake256_hash(keyhash, key, keylen);
|
|
263
|
+
key = keyhash;
|
|
264
|
+
keylen = 28;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
blake224_init(&S->inner);
|
|
268
|
+
memset(pad, 0x36, 64);
|
|
269
|
+
for (i = 0; i < keylen; ++i) {
|
|
270
|
+
pad[i] ^= key[i];
|
|
271
|
+
}
|
|
272
|
+
blake224_update(&S->inner, pad, 512);
|
|
273
|
+
|
|
274
|
+
blake224_init(&S->outer);
|
|
275
|
+
memset(pad, 0x5c, 64);
|
|
276
|
+
for (i = 0; i < keylen; ++i) {
|
|
277
|
+
pad[i] ^= key[i];
|
|
278
|
+
}
|
|
279
|
+
blake224_update(&S->outer, pad, 512);
|
|
280
|
+
|
|
281
|
+
memset(keyhash, 0, 32);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// datalen = number of bits
|
|
285
|
+
void hmac_blake256_update(hmac_state *S, const uint8_t *data, uint64_t datalen) {
|
|
286
|
+
// update the inner state
|
|
287
|
+
blake256_update(&S->inner, data, datalen);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// datalen = number of bits
|
|
291
|
+
void hmac_blake224_update(hmac_state *S, const uint8_t *data, uint64_t datalen) {
|
|
292
|
+
// update the inner state
|
|
293
|
+
blake224_update(&S->inner, data, datalen);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
void hmac_blake256_final(hmac_state *S, uint8_t *digest) {
|
|
297
|
+
uint8_t ihash[32];
|
|
298
|
+
blake256_final(&S->inner, ihash);
|
|
299
|
+
blake256_update(&S->outer, ihash, 256);
|
|
300
|
+
blake256_final(&S->outer, digest);
|
|
301
|
+
memset(ihash, 0, 32);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
void hmac_blake224_final(hmac_state *S, uint8_t *digest) {
|
|
305
|
+
uint8_t ihash[32];
|
|
306
|
+
blake224_final(&S->inner, ihash);
|
|
307
|
+
blake224_update(&S->outer, ihash, 224);
|
|
308
|
+
blake224_final(&S->outer, digest);
|
|
309
|
+
memset(ihash, 0, 32);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// keylen = number of bytes; inlen = number of bytes
|
|
313
|
+
void hmac_blake256_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) {
|
|
314
|
+
hmac_state S;
|
|
315
|
+
hmac_blake256_init(&S, key, keylen);
|
|
316
|
+
hmac_blake256_update(&S, in, inlen * 8);
|
|
317
|
+
hmac_blake256_final(&S, out);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// keylen = number of bytes; inlen = number of bytes
|
|
321
|
+
void hmac_blake224_hash(uint8_t *out, const uint8_t *key, uint64_t keylen, const uint8_t *in, uint64_t inlen) {
|
|
322
|
+
hmac_state S;
|
|
323
|
+
hmac_blake224_init(&S, key, keylen);
|
|
324
|
+
hmac_blake224_update(&S, in, inlen * 8);
|
|
325
|
+
hmac_blake224_final(&S, out);
|
|
326
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#ifndef _BLAKE256_H_
|
|
2
|
+
#define _BLAKE256_H_
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
typedef struct {
|
|
7
|
+
uint32_t h[8], s[4], t[2];
|
|
8
|
+
int buflen, nullt;
|
|
9
|
+
uint8_t buf[64];
|
|
10
|
+
} state;
|
|
11
|
+
|
|
12
|
+
typedef struct {
|
|
13
|
+
state inner;
|
|
14
|
+
state outer;
|
|
15
|
+
} hmac_state;
|
|
16
|
+
|
|
17
|
+
void blake256_init(state *);
|
|
18
|
+
void blake224_init(state *);
|
|
19
|
+
|
|
20
|
+
void blake256_update(state *, const uint8_t *, uint64_t);
|
|
21
|
+
void blake224_update(state *, const uint8_t *, uint64_t);
|
|
22
|
+
|
|
23
|
+
void blake256_final(state *, uint8_t *);
|
|
24
|
+
void blake224_final(state *, uint8_t *);
|
|
25
|
+
|
|
26
|
+
void blake256_hash(uint8_t *, const uint8_t *, uint64_t);
|
|
27
|
+
void blake224_hash(uint8_t *, const uint8_t *, uint64_t);
|
|
28
|
+
|
|
29
|
+
/* HMAC functions: */
|
|
30
|
+
|
|
31
|
+
void hmac_blake256_init(hmac_state *, const uint8_t *, uint64_t);
|
|
32
|
+
void hmac_blake224_init(hmac_state *, const uint8_t *, uint64_t);
|
|
33
|
+
|
|
34
|
+
void hmac_blake256_update(hmac_state *, const uint8_t *, uint64_t);
|
|
35
|
+
void hmac_blake224_update(hmac_state *, const uint8_t *, uint64_t);
|
|
36
|
+
|
|
37
|
+
void hmac_blake256_final(hmac_state *, uint8_t *);
|
|
38
|
+
void hmac_blake224_final(hmac_state *, uint8_t *);
|
|
39
|
+
|
|
40
|
+
void hmac_blake256_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t);
|
|
41
|
+
void hmac_blake224_hash(uint8_t *, const uint8_t *, uint64_t, const uint8_t *, uint64_t);
|
|
42
|
+
|
|
43
|
+
#endif /* _BLAKE256_H_ */
|