@onekeyfe/react-native-lite-card 6.7.0-alpha.409 → 6.7.0-alpha.412
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/README.md +9 -1
- package/ReactNativeLiteCard.podspec +25 -2
- package/android/build.gradle +7 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/entitys/SendResponse.kt +6 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +5 -1
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +21 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +4 -1
- package/ios/Classes/OKNFCBridge.mm +1 -1
- package/ios/Classes/OKNFTLite/OKLiteV1.m +6 -3
- package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
- package/package.json +2 -2
- package/sdk/CMakeLists.txt +120 -0
- package/sdk/README.md +175 -0
- package/sdk/android/implJni.cpp +177 -0
- package/sdk/deps/jsoncpp/LICENSE +55 -0
- package/sdk/deps/jsoncpp/include/CMakeLists.txt +2 -0
- package/sdk/deps/jsoncpp/include/json/allocator.h +98 -0
- package/sdk/deps/jsoncpp/include/json/assertions.h +54 -0
- package/sdk/deps/jsoncpp/include/json/autolink.h +25 -0
- package/sdk/deps/jsoncpp/include/json/config.h +187 -0
- package/sdk/deps/jsoncpp/include/json/features.h +61 -0
- package/sdk/deps/jsoncpp/include/json/forwards.h +37 -0
- package/sdk/deps/jsoncpp/include/json/json.h +15 -0
- package/sdk/deps/jsoncpp/include/json/reader.h +411 -0
- package/sdk/deps/jsoncpp/include/json/value.h +888 -0
- package/sdk/deps/jsoncpp/include/json/version.h +20 -0
- package/sdk/deps/jsoncpp/include/json/writer.h +357 -0
- package/sdk/deps/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/sdk/deps/jsoncpp/src/lib_json/version.h.in +20 -0
- package/sdk/deps/trezor-crypto/AUTHORS +2 -0
- package/sdk/deps/trezor-crypto/LICENSE +22 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/TrezorCrypto.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/address.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/aes.h +224 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base32.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base58.h +58 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bignum.h +169 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip32.h +114 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip39.h +66 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake256.h +61 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2b.h +50 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2s.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cash_addr.h +109 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-config.h +316 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-sync.h +289 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-types.h +53 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/poly1305-donna.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305.h +27 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cmac.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/curves.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ecdsa.h +112 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-helpers.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-blake2b.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-32bit-tables.h +25 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-basepoint-table.h +10 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-impl-base.h +110 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-portable.h +32 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-keccak.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-sha3.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/modm-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/endian.h +132 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/groestl.h +104 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hasher.h +90 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hmac.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/memzero.h +16 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/base58.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/monero.h +13 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/range_proof.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/serialize.h +15 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/xmr.h +67 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nano.h +56 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nem.h +199 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nist256p1.h +35 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/pbkdf2.h +64 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rand.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rc4.h +37 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rfc6979.h +40 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripemd160.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripple/base58.h +45 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/schnorr.h +48 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/script.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/scrypt.h +68 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/secp256k1.h +59 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha2.h +125 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha3.h +86 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/keypair.h +20 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10.h +85 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10_fe_25_5.h +43 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/constants.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/fe.h +25 -0
- package/sdk/deps/trezor-crypto/src/address.c +87 -0
- package/sdk/deps/trezor-crypto/src/aes/aes_modes.c +959 -0
- package/sdk/deps/trezor-crypto/src/aes/aescrypt.c +307 -0
- package/sdk/deps/trezor-crypto/src/aes/aeskey.c +560 -0
- package/sdk/deps/trezor-crypto/src/aes/aesopt.h +784 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.c +418 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.h +173 -0
- package/sdk/deps/trezor-crypto/src/base32.c +233 -0
- package/sdk/deps/trezor-crypto/src/base58.c +298 -0
- package/sdk/deps/trezor-crypto/src/bignum.c +808 -0
- package/sdk/deps/trezor-crypto/src/bip32.c +852 -0
- package/sdk/deps/trezor-crypto/src/bip39.c +266 -0
- package/sdk/deps/trezor-crypto/src/bip39_english.h +2074 -0
- package/sdk/deps/trezor-crypto/src/blake256.c +235 -0
- package/sdk/deps/trezor-crypto/src/blake2_common.h +39 -0
- package/sdk/deps/trezor-crypto/src/blake2b.c +333 -0
- package/sdk/deps/trezor-crypto/src/blake2s.c +318 -0
- package/sdk/deps/trezor-crypto/src/cash_addr.c +195 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c +60 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c +246 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-machine.h +49 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-portable.h +275 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna-32.h +219 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c +179 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.c +48 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.h +10 -0
- package/sdk/deps/trezor-crypto/src/check_mem.h +30 -0
- package/sdk/deps/trezor-crypto/src/cmac.c +342 -0
- package/sdk/deps/trezor-crypto/src/curves.c +48 -0
- package/sdk/deps/trezor-crypto/src/ecdsa.c +1355 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/README.md +183 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c +681 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c +66 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c +67 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.h +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c +63 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c +261 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c +722 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-blake2b.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-keccak.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-sha3.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519.c +311 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c +517 -0
- package/sdk/deps/trezor-crypto/src/groestl.c +783 -0
- package/sdk/deps/trezor-crypto/src/groestl_internal.h +419 -0
- package/sdk/deps/trezor-crypto/src/hasher.c +186 -0
- package/sdk/deps/trezor-crypto/src/hmac.c +179 -0
- package/sdk/deps/trezor-crypto/src/memzero.c +6 -0
- package/sdk/deps/trezor-crypto/src/monero/base58.c +245 -0
- package/sdk/deps/trezor-crypto/src/monero/int-util.h +77 -0
- package/sdk/deps/trezor-crypto/src/monero/range_proof.c +115 -0
- package/sdk/deps/trezor-crypto/src/monero/serialize.c +54 -0
- package/sdk/deps/trezor-crypto/src/monero/xmr.c +136 -0
- package/sdk/deps/trezor-crypto/src/nano.c +151 -0
- package/sdk/deps/trezor-crypto/src/nem.c +569 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.c +63 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/options.h +43 -0
- package/sdk/deps/trezor-crypto/src/pbkdf2.c +177 -0
- package/sdk/deps/trezor-crypto/src/rand.c +51 -0
- package/sdk/deps/trezor-crypto/src/rc4.c +56 -0
- package/sdk/deps/trezor-crypto/src/ripemd160.c +343 -0
- package/sdk/deps/trezor-crypto/src/ripple/base58.c +76 -0
- package/sdk/deps/trezor-crypto/src/schnorr.c +208 -0
- package/sdk/deps/trezor-crypto/src/script.c +64 -0
- package/sdk/deps/trezor-crypto/src/scrypt.c +343 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.c +160 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/setup.py +38 -0
- package/sdk/deps/trezor-crypto/src/sha2.c +1314 -0
- package/sdk/deps/trezor-crypto/src/sha3.c +395 -0
- package/sdk/deps/trezor-crypto/src/shell.nix +6 -0
- package/sdk/deps/trezor-crypto/src/sodium/keypair.c +63 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10.c +481 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c +885 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c +237 -0
- package/sdk/gpc/include/scp03/scp03.hpp +80 -0
- package/sdk/gpc/include/scp11/scp11.hpp +492 -0
- package/sdk/gpc/include/scp11/scp11c.hpp +58 -0
- package/sdk/gpc/include/tag.h +68 -0
- package/sdk/gpc/include/tlv.hpp +94 -0
- package/sdk/gpc/include/tlvparse.hpp +24 -0
- package/sdk/gpc/src/scp03.cpp +243 -0
- package/sdk/gpc/src/scp11.cpp +798 -0
- package/sdk/gpc/src/scp11c.cpp +136 -0
- package/sdk/gpc/src/tlv.cpp +159 -0
- package/sdk/gpc/src/tlvparse.c +174 -0
- package/{framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers → sdk/include}/GPChannelSDK.h +0 -0
- package/sdk/include/GPChannelSDKCore.h +10 -0
- package/sdk/include/context/BaseContext.h +56 -0
- package/sdk/include/device/ApduBuilder.hpp +72 -0
- package/sdk/include/mSIGNA/stdutils/uchar_vector.h +36 -0
- package/sdk/include/utility/Apdu.hpp +172 -0
- package/sdk/include/utility/Debug.hpp +3 -0
- package/sdk/include/utility/util.h +104 -0
- package/sdk/src/ApduBuilder.cpp +332 -0
- package/sdk/src/GPChannelSDK.cpp +252 -0
- package/sdk/src/random.c +25 -0
- package/sdk/src/version.c +2 -0
- package/sdk/tests/android/GPChannelProxy.java +55 -0
- package/sdk/tests/android_verify.py +121 -0
- package/sdk/tests/safety.cpp +603 -0
- package/sdk/tests/verify.py +267 -0
- package/android/src/main/jniLibs/arm64-v8a/libgpchannelNDK.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libgpchannelNDK.so +0 -0
- package/framework/GPChannelSDKCore.xcframework/Info.plist +0 -52
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDK.h +0 -315
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*
|
|
2
|
+
BLAKE reference C implementation
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2012 Jean-Philippe Aumasson <jeanphilippe.aumasson@gmail.com>
|
|
5
|
+
|
|
6
|
+
To the extent possible under law, the author(s) have dedicated all copyright
|
|
7
|
+
and related and neighboring rights to this software to the public domain
|
|
8
|
+
worldwide. This software is distributed without any warranty.
|
|
9
|
+
|
|
10
|
+
You should have received a copy of the CC0 Public Domain Dedication along with
|
|
11
|
+
this software. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
|
|
12
|
+
*/
|
|
13
|
+
#include <TrezorCrypto/blake256.h>
|
|
14
|
+
|
|
15
|
+
#include <string.h>
|
|
16
|
+
|
|
17
|
+
#define U8TO32_BIG(p) \
|
|
18
|
+
(((uint32_t)((p)[0]) << 24) | ((uint32_t)((p)[1]) << 16) | \
|
|
19
|
+
((uint32_t)((p)[2]) << 8) | ((uint32_t)((p)[3]) ))
|
|
20
|
+
|
|
21
|
+
#define U32TO8_BIG(p, v) \
|
|
22
|
+
(p)[0] = (uint8_t)((v) >> 24); (p)[1] = (uint8_t)((v) >> 16); \
|
|
23
|
+
(p)[2] = (uint8_t)((v) >> 8); (p)[3] = (uint8_t)((v) );
|
|
24
|
+
|
|
25
|
+
static const uint8_t sigma[][16] =
|
|
26
|
+
{
|
|
27
|
+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
|
28
|
+
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
|
29
|
+
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
|
30
|
+
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
|
31
|
+
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
|
32
|
+
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 },
|
|
33
|
+
{12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 },
|
|
34
|
+
{13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 },
|
|
35
|
+
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 },
|
|
36
|
+
{10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
|
|
37
|
+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
|
|
38
|
+
{14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
|
|
39
|
+
{11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 },
|
|
40
|
+
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 },
|
|
41
|
+
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 },
|
|
42
|
+
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 }
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
static const uint32_t u256[16] =
|
|
46
|
+
{
|
|
47
|
+
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
|
|
48
|
+
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
|
|
49
|
+
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
|
50
|
+
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
static const uint8_t padding[129] =
|
|
54
|
+
{
|
|
55
|
+
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
56
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
57
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
58
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
59
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
60
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
61
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
62
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
static void blake256_compress( BLAKE256_CTX *S, const uint8_t *block )
|
|
66
|
+
{
|
|
67
|
+
uint32_t v[16], m[16], i;
|
|
68
|
+
#define ROT(x,n) (((x)<<(32-n))|( (x)>>(n)))
|
|
69
|
+
#define G(a,b,c,d,e) \
|
|
70
|
+
v[a] += (m[sigma[i][e]] ^ u256[sigma[i][e+1]]) + v[b]; \
|
|
71
|
+
v[d] = ROT( v[d] ^ v[a],16); \
|
|
72
|
+
v[c] += v[d]; \
|
|
73
|
+
v[b] = ROT( v[b] ^ v[c],12); \
|
|
74
|
+
v[a] += (m[sigma[i][e+1]] ^ u256[sigma[i][e]])+v[b]; \
|
|
75
|
+
v[d] = ROT( v[d] ^ v[a], 8); \
|
|
76
|
+
v[c] += v[d]; \
|
|
77
|
+
v[b] = ROT( v[b] ^ v[c], 7);
|
|
78
|
+
|
|
79
|
+
for( i = 0; i < 16; ++i ) m[i] = U8TO32_BIG( block + i * 4 );
|
|
80
|
+
|
|
81
|
+
for( i = 0; i < 8; ++i ) v[i] = S->h[i];
|
|
82
|
+
|
|
83
|
+
v[ 8] = S->s[0] ^ u256[0];
|
|
84
|
+
v[ 9] = S->s[1] ^ u256[1];
|
|
85
|
+
v[10] = S->s[2] ^ u256[2];
|
|
86
|
+
v[11] = S->s[3] ^ u256[3];
|
|
87
|
+
v[12] = u256[4];
|
|
88
|
+
v[13] = u256[5];
|
|
89
|
+
v[14] = u256[6];
|
|
90
|
+
v[15] = u256[7];
|
|
91
|
+
|
|
92
|
+
/* don't xor t when the block is only padding */
|
|
93
|
+
if ( !S->nullt )
|
|
94
|
+
{
|
|
95
|
+
v[12] ^= S->t[0];
|
|
96
|
+
v[13] ^= S->t[0];
|
|
97
|
+
v[14] ^= S->t[1];
|
|
98
|
+
v[15] ^= S->t[1];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
for( i = 0; i < 14; ++i )
|
|
102
|
+
{
|
|
103
|
+
/* column step */
|
|
104
|
+
G( 0, 4, 8, 12, 0 );
|
|
105
|
+
G( 1, 5, 9, 13, 2 );
|
|
106
|
+
G( 2, 6, 10, 14, 4 );
|
|
107
|
+
G( 3, 7, 11, 15, 6 );
|
|
108
|
+
/* diagonal step */
|
|
109
|
+
G( 0, 5, 10, 15, 8 );
|
|
110
|
+
G( 1, 6, 11, 12, 10 );
|
|
111
|
+
G( 2, 7, 8, 13, 12 );
|
|
112
|
+
G( 3, 4, 9, 14, 14 );
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
for( i = 0; i < 16; ++i ) S->h[i % 8] ^= v[i];
|
|
116
|
+
|
|
117
|
+
for( i = 0; i < 8 ; ++i ) S->h[i] ^= S->s[i % 4];
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
void blake256_Init( BLAKE256_CTX *S )
|
|
122
|
+
{
|
|
123
|
+
S->h[0] = 0x6a09e667;
|
|
124
|
+
S->h[1] = 0xbb67ae85;
|
|
125
|
+
S->h[2] = 0x3c6ef372;
|
|
126
|
+
S->h[3] = 0xa54ff53a;
|
|
127
|
+
S->h[4] = 0x510e527f;
|
|
128
|
+
S->h[5] = 0x9b05688c;
|
|
129
|
+
S->h[6] = 0x1f83d9ab;
|
|
130
|
+
S->h[7] = 0x5be0cd19;
|
|
131
|
+
S->t[0] = S->t[1] = S->buflen = S->nullt = 0;
|
|
132
|
+
S->s[0] = S->s[1] = S->s[2] = S->s[3] = 0;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
void blake256_Update( BLAKE256_CTX *S, const uint8_t *in, size_t inlen )
|
|
137
|
+
{
|
|
138
|
+
size_t left = S->buflen;
|
|
139
|
+
size_t fill = 64 - left;
|
|
140
|
+
|
|
141
|
+
/* data left and data received fill a block */
|
|
142
|
+
if( left && ( inlen >= fill ) )
|
|
143
|
+
{
|
|
144
|
+
memcpy( ( void * ) ( S->buf + left ), ( void * ) in, fill );
|
|
145
|
+
S->t[0] += 512;
|
|
146
|
+
|
|
147
|
+
if ( S->t[0] == 0 ) S->t[1]++;
|
|
148
|
+
|
|
149
|
+
blake256_compress( S, S->buf );
|
|
150
|
+
in += fill;
|
|
151
|
+
inlen -= fill;
|
|
152
|
+
left = 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* compress blocks of data received */
|
|
156
|
+
while( inlen >= 64 )
|
|
157
|
+
{
|
|
158
|
+
S->t[0] += 512;
|
|
159
|
+
|
|
160
|
+
if ( S->t[0] == 0 ) S->t[1]++;
|
|
161
|
+
|
|
162
|
+
blake256_compress( S, in );
|
|
163
|
+
in += 64;
|
|
164
|
+
inlen -= 64;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/* store any data left */
|
|
168
|
+
if( inlen > 0 )
|
|
169
|
+
{
|
|
170
|
+
memcpy( ( void * ) ( S->buf + left ), \
|
|
171
|
+
( void * ) in, ( size_t ) inlen );
|
|
172
|
+
S->buflen = left + ( int )inlen;
|
|
173
|
+
}
|
|
174
|
+
else S->buflen = 0;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
void blake256_Final( BLAKE256_CTX *S, uint8_t *out )
|
|
179
|
+
{
|
|
180
|
+
uint8_t msglen[8], zo = 0x01, oo = 0x81;
|
|
181
|
+
uint32_t lo = S->t[0] + ( S->buflen << 3 ), hi = S->t[1];
|
|
182
|
+
|
|
183
|
+
/* support for hashing more than 2^32 bits */
|
|
184
|
+
if ( lo < ( S->buflen << 3 ) ) hi++;
|
|
185
|
+
|
|
186
|
+
U32TO8_BIG( msglen + 0, hi );
|
|
187
|
+
U32TO8_BIG( msglen + 4, lo );
|
|
188
|
+
|
|
189
|
+
if ( S->buflen == 55 ) /* one padding byte */
|
|
190
|
+
{
|
|
191
|
+
S->t[0] -= 8;
|
|
192
|
+
blake256_Update( S, &oo, 1 );
|
|
193
|
+
}
|
|
194
|
+
else
|
|
195
|
+
{
|
|
196
|
+
if ( S->buflen < 55 ) /* enough space to fill the block */
|
|
197
|
+
{
|
|
198
|
+
if ( !S->buflen ) S->nullt = 1;
|
|
199
|
+
|
|
200
|
+
S->t[0] -= 440 - ( S->buflen << 3 );
|
|
201
|
+
blake256_Update( S, padding, 55 - S->buflen );
|
|
202
|
+
}
|
|
203
|
+
else /* need 2 compressions */
|
|
204
|
+
{
|
|
205
|
+
S->t[0] -= 512 - ( S->buflen << 3 );
|
|
206
|
+
blake256_Update( S, padding, 64 - S->buflen );
|
|
207
|
+
S->t[0] -= 440;
|
|
208
|
+
blake256_Update( S, padding + 1, 55 );
|
|
209
|
+
S->nullt = 1;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
blake256_Update( S, &zo, 1 );
|
|
213
|
+
S->t[0] -= 8;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
S->t[0] -= 64;
|
|
217
|
+
blake256_Update( S, msglen, 8 );
|
|
218
|
+
U32TO8_BIG( out + 0, S->h[0] );
|
|
219
|
+
U32TO8_BIG( out + 4, S->h[1] );
|
|
220
|
+
U32TO8_BIG( out + 8, S->h[2] );
|
|
221
|
+
U32TO8_BIG( out + 12, S->h[3] );
|
|
222
|
+
U32TO8_BIG( out + 16, S->h[4] );
|
|
223
|
+
U32TO8_BIG( out + 20, S->h[5] );
|
|
224
|
+
U32TO8_BIG( out + 24, S->h[6] );
|
|
225
|
+
U32TO8_BIG( out + 28, S->h[7] );
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
void blake256( const uint8_t *in, size_t inlen, uint8_t *out )
|
|
230
|
+
{
|
|
231
|
+
BLAKE256_CTX S;
|
|
232
|
+
blake256_Init( &S );
|
|
233
|
+
blake256_Update( &S, in, inlen );
|
|
234
|
+
blake256_Final( &S, out );
|
|
235
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
static inline uint32_t load32( const void *src )
|
|
2
|
+
{
|
|
3
|
+
uint32_t w;
|
|
4
|
+
memcpy(&w, src, sizeof w);
|
|
5
|
+
return w;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
static inline uint64_t load64( const void *src )
|
|
9
|
+
{
|
|
10
|
+
uint64_t w;
|
|
11
|
+
memcpy(&w, src, sizeof w);
|
|
12
|
+
return w;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static inline void store16( void *dst, uint16_t w )
|
|
16
|
+
{
|
|
17
|
+
memcpy(dst, &w, sizeof w);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static inline void store32( void *dst, uint32_t w )
|
|
21
|
+
{
|
|
22
|
+
memcpy(dst, &w, sizeof w);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static inline void store64( void *dst, uint64_t w )
|
|
26
|
+
{
|
|
27
|
+
memcpy(dst, &w, sizeof w);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
static inline uint32_t rotr32( const uint32_t w, const unsigned c )
|
|
31
|
+
{
|
|
32
|
+
return ( w >> c ) | ( w << ( 32 - c ) );
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
static inline uint64_t rotr64( const uint64_t w, const unsigned c )
|
|
36
|
+
{
|
|
37
|
+
return ( w >> c ) | ( w << ( 64 - c ) );
|
|
38
|
+
}
|
|
39
|
+
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/*
|
|
2
|
+
BLAKE2 reference source code package - reference C implementations
|
|
3
|
+
|
|
4
|
+
Copyright 2012, Samuel Neves <sneves@dei.uc.pt>. You may use this under the
|
|
5
|
+
terms of the CC0, the OpenSSL Licence, or the Apache Public License 2.0, at
|
|
6
|
+
your option. The terms of these licenses can be found at:
|
|
7
|
+
|
|
8
|
+
- CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
|
9
|
+
- OpenSSL license : https://www.openssl.org/source/license.html
|
|
10
|
+
- Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
|
|
12
|
+
More information about the BLAKE2 hash function can be found at
|
|
13
|
+
https://blake2.net.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include <string.h>
|
|
17
|
+
|
|
18
|
+
#include <TrezorCrypto/blake2b.h>
|
|
19
|
+
#include "blake2_common.h"
|
|
20
|
+
#include <TrezorCrypto/memzero.h>
|
|
21
|
+
|
|
22
|
+
typedef struct blake2b_param__
|
|
23
|
+
{
|
|
24
|
+
uint8_t digest_length; /* 1 */
|
|
25
|
+
uint8_t key_length; /* 2 */
|
|
26
|
+
uint8_t fanout; /* 3 */
|
|
27
|
+
uint8_t depth; /* 4 */
|
|
28
|
+
uint32_t leaf_length; /* 8 */
|
|
29
|
+
uint32_t node_offset; /* 12 */
|
|
30
|
+
uint32_t xof_length; /* 16 */
|
|
31
|
+
uint8_t node_depth; /* 17 */
|
|
32
|
+
uint8_t inner_length; /* 18 */
|
|
33
|
+
uint8_t reserved[14]; /* 32 */
|
|
34
|
+
uint8_t salt[BLAKE2B_SALTBYTES]; /* 48 */
|
|
35
|
+
uint8_t personal[BLAKE2B_PERSONALBYTES]; /* 64 */
|
|
36
|
+
} __attribute__((packed)) blake2b_param;
|
|
37
|
+
|
|
38
|
+
static const uint64_t blake2b_IV[8] =
|
|
39
|
+
{
|
|
40
|
+
0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL,
|
|
41
|
+
0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL,
|
|
42
|
+
0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL,
|
|
43
|
+
0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
static const uint8_t blake2b_sigma[12][16] =
|
|
47
|
+
{
|
|
48
|
+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
|
49
|
+
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 } ,
|
|
50
|
+
{ 11, 8, 12, 0, 5, 2, 15, 13, 10, 14, 3, 6, 7, 1, 9, 4 } ,
|
|
51
|
+
{ 7, 9, 3, 1, 13, 12, 11, 14, 2, 6, 5, 10, 4, 0, 15, 8 } ,
|
|
52
|
+
{ 9, 0, 5, 7, 2, 4, 10, 15, 14, 1, 11, 12, 6, 8, 3, 13 } ,
|
|
53
|
+
{ 2, 12, 6, 10, 0, 11, 8, 3, 4, 13, 7, 5, 15, 14, 1, 9 } ,
|
|
54
|
+
{ 12, 5, 1, 15, 14, 13, 4, 10, 0, 7, 6, 3, 9, 2, 8, 11 } ,
|
|
55
|
+
{ 13, 11, 7, 14, 12, 1, 3, 9, 5, 0, 15, 4, 8, 6, 2, 10 } ,
|
|
56
|
+
{ 6, 15, 14, 9, 11, 3, 0, 8, 12, 2, 13, 7, 1, 4, 10, 5 } ,
|
|
57
|
+
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 } ,
|
|
58
|
+
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } ,
|
|
59
|
+
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 }
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
static void blake2b_set_lastnode( blake2b_state *S )
|
|
64
|
+
{
|
|
65
|
+
S->f[1] = (uint64_t)-1;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/* Some helper functions, not necessarily useful */
|
|
69
|
+
static int blake2b_is_lastblock( const blake2b_state *S )
|
|
70
|
+
{
|
|
71
|
+
return S->f[0] != 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static void blake2b_set_lastblock( blake2b_state *S )
|
|
75
|
+
{
|
|
76
|
+
if( S->last_node ) blake2b_set_lastnode( S );
|
|
77
|
+
|
|
78
|
+
S->f[0] = (uint64_t)-1;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
static void blake2b_increment_counter( blake2b_state *S, const uint64_t inc )
|
|
82
|
+
{
|
|
83
|
+
S->t[0] += inc;
|
|
84
|
+
S->t[1] += ( S->t[0] < inc );
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
static void blake2b_init0( blake2b_state *S )
|
|
88
|
+
{
|
|
89
|
+
size_t i;
|
|
90
|
+
memset( S, 0, sizeof( blake2b_state ) );
|
|
91
|
+
|
|
92
|
+
for( i = 0; i < 8; ++i ) S->h[i] = blake2b_IV[i];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* init xors IV with input parameter block */
|
|
96
|
+
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
|
|
97
|
+
{
|
|
98
|
+
const uint8_t *p = ( const uint8_t * )( P );
|
|
99
|
+
size_t i;
|
|
100
|
+
|
|
101
|
+
blake2b_init0( S );
|
|
102
|
+
|
|
103
|
+
/* IV XOR ParamBlock */
|
|
104
|
+
for( i = 0; i < 8; ++i )
|
|
105
|
+
S->h[i] ^= load64( p + sizeof( S->h[i] ) * i );
|
|
106
|
+
|
|
107
|
+
S->outlen = P->digest_length;
|
|
108
|
+
return 0;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
/* Sequential blake2b initialization */
|
|
113
|
+
int blake2b_Init( blake2b_state *S, size_t outlen )
|
|
114
|
+
{
|
|
115
|
+
blake2b_param P[1];
|
|
116
|
+
|
|
117
|
+
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
|
|
118
|
+
|
|
119
|
+
P->digest_length = (uint8_t)outlen;
|
|
120
|
+
P->key_length = 0;
|
|
121
|
+
P->fanout = 1;
|
|
122
|
+
P->depth = 1;
|
|
123
|
+
store32( &P->leaf_length, 0 );
|
|
124
|
+
store32( &P->node_offset, 0 );
|
|
125
|
+
store32( &P->xof_length, 0 );
|
|
126
|
+
P->node_depth = 0;
|
|
127
|
+
P->inner_length = 0;
|
|
128
|
+
memset( P->reserved, 0, sizeof( P->reserved ) );
|
|
129
|
+
memset( P->salt, 0, sizeof( P->salt ) );
|
|
130
|
+
memset( P->personal, 0, sizeof( P->personal ) );
|
|
131
|
+
return blake2b_init_param( S, P );
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
int blake2b_InitPersonal( blake2b_state *S, size_t outlen, const void *personal, size_t personal_len)
|
|
135
|
+
{
|
|
136
|
+
blake2b_param P[1];
|
|
137
|
+
|
|
138
|
+
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
|
|
139
|
+
if ( ( !personal ) || ( personal_len != BLAKE2B_PERSONALBYTES ) ) return -1;
|
|
140
|
+
|
|
141
|
+
P->digest_length = (uint8_t)outlen;
|
|
142
|
+
P->key_length = 0;
|
|
143
|
+
P->fanout = 1;
|
|
144
|
+
P->depth = 1;
|
|
145
|
+
store32( &P->leaf_length, 0 );
|
|
146
|
+
store32( &P->node_offset, 0 );
|
|
147
|
+
store32( &P->xof_length, 0 );
|
|
148
|
+
P->node_depth = 0;
|
|
149
|
+
P->inner_length = 0;
|
|
150
|
+
memset( P->reserved, 0, sizeof( P->reserved ) );
|
|
151
|
+
memset( P->salt, 0, sizeof( P->salt ) );
|
|
152
|
+
memcpy( P->personal, personal, BLAKE2B_PERSONALBYTES );
|
|
153
|
+
return blake2b_init_param( S, P );
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
int blake2b_InitKey( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
|
|
157
|
+
{
|
|
158
|
+
blake2b_param P[1];
|
|
159
|
+
|
|
160
|
+
if ( ( !outlen ) || ( outlen > BLAKE2B_OUTBYTES ) ) return -1;
|
|
161
|
+
|
|
162
|
+
if ( !key || !keylen || keylen > BLAKE2B_KEYBYTES ) return -1;
|
|
163
|
+
|
|
164
|
+
P->digest_length = (uint8_t)outlen;
|
|
165
|
+
P->key_length = (uint8_t)keylen;
|
|
166
|
+
P->fanout = 1;
|
|
167
|
+
P->depth = 1;
|
|
168
|
+
store32( &P->leaf_length, 0 );
|
|
169
|
+
store32( &P->node_offset, 0 );
|
|
170
|
+
store32( &P->xof_length, 0 );
|
|
171
|
+
P->node_depth = 0;
|
|
172
|
+
P->inner_length = 0;
|
|
173
|
+
memset( P->reserved, 0, sizeof( P->reserved ) );
|
|
174
|
+
memset( P->salt, 0, sizeof( P->salt ) );
|
|
175
|
+
memset( P->personal, 0, sizeof( P->personal ) );
|
|
176
|
+
|
|
177
|
+
if( blake2b_init_param( S, P ) < 0 ) return -1;
|
|
178
|
+
|
|
179
|
+
{
|
|
180
|
+
uint8_t block[BLAKE2B_BLOCKBYTES];
|
|
181
|
+
memset( block, 0, BLAKE2B_BLOCKBYTES );
|
|
182
|
+
memcpy( block, key, keylen );
|
|
183
|
+
blake2b_Update( S, block, BLAKE2B_BLOCKBYTES );
|
|
184
|
+
memzero( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
|
|
185
|
+
}
|
|
186
|
+
return 0;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
#define G(r,i,a,b,c,d) \
|
|
190
|
+
do { \
|
|
191
|
+
a = a + b + m[blake2b_sigma[r][2*i+0]]; \
|
|
192
|
+
d = rotr64(d ^ a, 32); \
|
|
193
|
+
c = c + d; \
|
|
194
|
+
b = rotr64(b ^ c, 24); \
|
|
195
|
+
a = a + b + m[blake2b_sigma[r][2*i+1]]; \
|
|
196
|
+
d = rotr64(d ^ a, 16); \
|
|
197
|
+
c = c + d; \
|
|
198
|
+
b = rotr64(b ^ c, 63); \
|
|
199
|
+
} while(0)
|
|
200
|
+
|
|
201
|
+
#define ROUND(r) \
|
|
202
|
+
do { \
|
|
203
|
+
G(r,0,v[ 0],v[ 4],v[ 8],v[12]); \
|
|
204
|
+
G(r,1,v[ 1],v[ 5],v[ 9],v[13]); \
|
|
205
|
+
G(r,2,v[ 2],v[ 6],v[10],v[14]); \
|
|
206
|
+
G(r,3,v[ 3],v[ 7],v[11],v[15]); \
|
|
207
|
+
G(r,4,v[ 0],v[ 5],v[10],v[15]); \
|
|
208
|
+
G(r,5,v[ 1],v[ 6],v[11],v[12]); \
|
|
209
|
+
G(r,6,v[ 2],v[ 7],v[ 8],v[13]); \
|
|
210
|
+
G(r,7,v[ 3],v[ 4],v[ 9],v[14]); \
|
|
211
|
+
} while(0)
|
|
212
|
+
|
|
213
|
+
static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOCKBYTES] )
|
|
214
|
+
{
|
|
215
|
+
uint64_t m[16];
|
|
216
|
+
uint64_t v[16];
|
|
217
|
+
size_t i;
|
|
218
|
+
|
|
219
|
+
for( i = 0; i < 16; ++i ) {
|
|
220
|
+
m[i] = load64( block + i * sizeof( m[i] ) );
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
for( i = 0; i < 8; ++i ) {
|
|
224
|
+
v[i] = S->h[i];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
v[ 8] = blake2b_IV[0];
|
|
228
|
+
v[ 9] = blake2b_IV[1];
|
|
229
|
+
v[10] = blake2b_IV[2];
|
|
230
|
+
v[11] = blake2b_IV[3];
|
|
231
|
+
v[12] = blake2b_IV[4] ^ S->t[0];
|
|
232
|
+
v[13] = blake2b_IV[5] ^ S->t[1];
|
|
233
|
+
v[14] = blake2b_IV[6] ^ S->f[0];
|
|
234
|
+
v[15] = blake2b_IV[7] ^ S->f[1];
|
|
235
|
+
|
|
236
|
+
ROUND( 0 );
|
|
237
|
+
ROUND( 1 );
|
|
238
|
+
ROUND( 2 );
|
|
239
|
+
ROUND( 3 );
|
|
240
|
+
ROUND( 4 );
|
|
241
|
+
ROUND( 5 );
|
|
242
|
+
ROUND( 6 );
|
|
243
|
+
ROUND( 7 );
|
|
244
|
+
ROUND( 8 );
|
|
245
|
+
ROUND( 9 );
|
|
246
|
+
ROUND( 10 );
|
|
247
|
+
ROUND( 11 );
|
|
248
|
+
|
|
249
|
+
for( i = 0; i < 8; ++i ) {
|
|
250
|
+
S->h[i] = S->h[i] ^ v[i] ^ v[i + 8];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#undef G
|
|
255
|
+
#undef ROUND
|
|
256
|
+
|
|
257
|
+
int blake2b_Update( blake2b_state *S, const void *pin, size_t inlen )
|
|
258
|
+
{
|
|
259
|
+
const unsigned char * in = (const unsigned char *)pin;
|
|
260
|
+
if( inlen > 0 )
|
|
261
|
+
{
|
|
262
|
+
size_t left = S->buflen;
|
|
263
|
+
size_t fill = BLAKE2B_BLOCKBYTES - left;
|
|
264
|
+
if( inlen > fill )
|
|
265
|
+
{
|
|
266
|
+
S->buflen = 0;
|
|
267
|
+
memcpy( S->buf + left, in, fill ); /* Fill buffer */
|
|
268
|
+
blake2b_increment_counter( S, BLAKE2B_BLOCKBYTES );
|
|
269
|
+
blake2b_compress( S, S->buf ); /* Compress */
|
|
270
|
+
in += fill; inlen -= fill;
|
|
271
|
+
while(inlen > BLAKE2B_BLOCKBYTES) {
|
|
272
|
+
blake2b_increment_counter(S, BLAKE2B_BLOCKBYTES);
|
|
273
|
+
blake2b_compress( S, in );
|
|
274
|
+
in += BLAKE2B_BLOCKBYTES;
|
|
275
|
+
inlen -= BLAKE2B_BLOCKBYTES;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
memcpy( S->buf + S->buflen, in, inlen );
|
|
279
|
+
S->buflen += inlen;
|
|
280
|
+
}
|
|
281
|
+
return 0;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
int blake2b_Final( blake2b_state *S, void *out, size_t outlen )
|
|
285
|
+
{
|
|
286
|
+
uint8_t buffer[BLAKE2B_OUTBYTES] = {0};
|
|
287
|
+
size_t i;
|
|
288
|
+
|
|
289
|
+
if( out == NULL || outlen < S->outlen )
|
|
290
|
+
return -1;
|
|
291
|
+
|
|
292
|
+
if( blake2b_is_lastblock( S ) )
|
|
293
|
+
return -1;
|
|
294
|
+
|
|
295
|
+
blake2b_increment_counter( S, S->buflen );
|
|
296
|
+
blake2b_set_lastblock( S );
|
|
297
|
+
memset( S->buf + S->buflen, 0, BLAKE2B_BLOCKBYTES - S->buflen ); /* Padding */
|
|
298
|
+
blake2b_compress( S, S->buf );
|
|
299
|
+
|
|
300
|
+
for( i = 0; i < 8; ++i ) /* Output full hash to temp buffer */
|
|
301
|
+
store64( buffer + sizeof( S->h[i] ) * i, S->h[i] );
|
|
302
|
+
|
|
303
|
+
memcpy( out, buffer, S->outlen );
|
|
304
|
+
memzero(buffer, sizeof(buffer));
|
|
305
|
+
return 0;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
int blake2b(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen)
|
|
309
|
+
{
|
|
310
|
+
BLAKE2B_CTX ctx;
|
|
311
|
+
if (0 != blake2b_Init(&ctx, outlen)) return -1;
|
|
312
|
+
if (0 != blake2b_Update(&ctx, msg, msg_len)) return -1;
|
|
313
|
+
if (0 != blake2b_Final(&ctx, out, outlen)) return -1;
|
|
314
|
+
return 0;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
int blake2b_Personal(const uint8_t *msg, uint32_t msg_len, const void *personal, size_t personal_len, void *out, size_t outlen)
|
|
318
|
+
{
|
|
319
|
+
BLAKE2B_CTX ctx;
|
|
320
|
+
if (0 != blake2b_InitPersonal(&ctx, outlen, personal, personal_len)) return -1;
|
|
321
|
+
if (0 != blake2b_Update(&ctx, msg, msg_len)) return -1;
|
|
322
|
+
if (0 != blake2b_Final(&ctx, out, outlen)) return -1;
|
|
323
|
+
return 0;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
int blake2b_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen)
|
|
327
|
+
{
|
|
328
|
+
BLAKE2B_CTX ctx;
|
|
329
|
+
if (0 != blake2b_InitKey(&ctx, outlen, key, keylen)) return -1;
|
|
330
|
+
if (0 != blake2b_Update(&ctx, msg, msg_len)) return -1;
|
|
331
|
+
if (0 != blake2b_Final(&ctx, out, outlen)) return -1;
|
|
332
|
+
return 0;
|
|
333
|
+
}
|