@onekeyfe/react-native-lite-card 6.7.0-alpha.409 → 6.7.0-alpha.411
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,419 @@
|
|
|
1
|
+
/* Groestl hash from https://github.com/Groestlcoin/vanitygen
|
|
2
|
+
* Trezor adaptation by Yura Pakhuchiy <pakhuchiy@gmail.com>. */
|
|
3
|
+
/**
|
|
4
|
+
* Basic type definitions.
|
|
5
|
+
*
|
|
6
|
+
* This header file defines the generic integer types that will be used
|
|
7
|
+
* for the implementation of hash functions; it also contains helper
|
|
8
|
+
* functions which encode and decode multi-byte integer values, using
|
|
9
|
+
* either little-endian or big-endian conventions.
|
|
10
|
+
*
|
|
11
|
+
* This file contains a compile-time test on the size of a byte
|
|
12
|
+
* (the <code>unsigned char</code> C type). If bytes are not octets,
|
|
13
|
+
* i.e. if they do not have a size of exactly 8 bits, then compilation
|
|
14
|
+
* is aborted. Architectures where bytes are not octets are relatively
|
|
15
|
+
* rare, even in the embedded devices market. We forbid non-octet bytes
|
|
16
|
+
* because there is no clear convention on how octet streams are encoded
|
|
17
|
+
* on such systems.
|
|
18
|
+
*
|
|
19
|
+
* ==========================(LICENSE BEGIN)============================
|
|
20
|
+
*
|
|
21
|
+
* Copyright (c) 2007-2010 Projet RNRT SAPHIR
|
|
22
|
+
*
|
|
23
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
24
|
+
* a copy of this software and associated documentation files (the
|
|
25
|
+
* "Software"), to deal in the Software without restriction, including
|
|
26
|
+
* without limitation the rights to use, copy, modify, merge, publish,
|
|
27
|
+
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
28
|
+
* permit persons to whom the Software is furnished to do so, subject to
|
|
29
|
+
* the following conditions:
|
|
30
|
+
*
|
|
31
|
+
* The above copyright notice and this permission notice shall be
|
|
32
|
+
* included in all copies or substantial portions of the Software.
|
|
33
|
+
*
|
|
34
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
35
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
36
|
+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
37
|
+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
38
|
+
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
39
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
40
|
+
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
41
|
+
*
|
|
42
|
+
* ===========================(LICENSE END)=============================
|
|
43
|
+
*
|
|
44
|
+
* @file sph_types.h
|
|
45
|
+
* @author Thomas Pornin <thomas.pornin@cryptolog.com>
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
#ifndef GROESTL_INTERNAL_H__
|
|
49
|
+
#define GROESTL_INTERNAL_H__
|
|
50
|
+
|
|
51
|
+
#include <limits.h>
|
|
52
|
+
|
|
53
|
+
/*
|
|
54
|
+
* All our I/O functions are defined over octet streams. We do not know
|
|
55
|
+
* how to handle input data if bytes are not octets.
|
|
56
|
+
*/
|
|
57
|
+
#if CHAR_BIT != 8
|
|
58
|
+
#error This code requires 8-bit bytes
|
|
59
|
+
#endif
|
|
60
|
+
|
|
61
|
+
#if defined __STDC__ && __STDC_VERSION__ >= 199901L
|
|
62
|
+
|
|
63
|
+
#include <stdint.h>
|
|
64
|
+
|
|
65
|
+
typedef uint32_t sph_u32;
|
|
66
|
+
typedef int32_t sph_s32;
|
|
67
|
+
typedef uint64_t sph_u64;
|
|
68
|
+
typedef int64_t sph_s64;
|
|
69
|
+
|
|
70
|
+
#define SPH_C32(x) ((sph_u32)(x))
|
|
71
|
+
#define SPH_C64(x) ((sph_u64)(x))
|
|
72
|
+
|
|
73
|
+
#else
|
|
74
|
+
#error We need at least C99 compiler
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
#define SPH_T32(x) ((x) & SPH_C32(0xFFFFFFFF))
|
|
78
|
+
#define SPH_ROTL32(x, n) SPH_T32(((x) << (n)) | ((x) >> (32 - (n))))
|
|
79
|
+
#define SPH_ROTR32(x, n) SPH_ROTL32(x, (32 - (n)))
|
|
80
|
+
|
|
81
|
+
#define SPH_T64(x) ((x) & SPH_C64(0xFFFFFFFFFFFFFFFF))
|
|
82
|
+
#define SPH_ROTL64(x, n) SPH_T64(((x) << (n)) | ((x) >> (64 - (n))))
|
|
83
|
+
#define SPH_ROTR64(x, n) SPH_ROTL64(x, (64 - (n)))
|
|
84
|
+
|
|
85
|
+
static inline sph_u32
|
|
86
|
+
sph_bswap32(sph_u32 x)
|
|
87
|
+
{
|
|
88
|
+
x = SPH_T32((x << 16) | (x >> 16));
|
|
89
|
+
x = ((x & SPH_C32(0xFF00FF00)) >> 8)
|
|
90
|
+
| ((x & SPH_C32(0x00FF00FF)) << 8);
|
|
91
|
+
return x;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Byte-swap a 64-bit value.
|
|
96
|
+
*
|
|
97
|
+
* @param x the input value
|
|
98
|
+
* @return the byte-swapped value
|
|
99
|
+
*/
|
|
100
|
+
static inline sph_u64
|
|
101
|
+
sph_bswap64(sph_u64 x)
|
|
102
|
+
{
|
|
103
|
+
x = SPH_T64((x << 32) | (x >> 32));
|
|
104
|
+
x = ((x & SPH_C64(0xFFFF0000FFFF0000)) >> 16)
|
|
105
|
+
| ((x & SPH_C64(0x0000FFFF0000FFFF)) << 16);
|
|
106
|
+
x = ((x & SPH_C64(0xFF00FF00FF00FF00)) >> 8)
|
|
107
|
+
| ((x & SPH_C64(0x00FF00FF00FF00FF)) << 8);
|
|
108
|
+
return x;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
static inline void
|
|
112
|
+
sph_enc16be(void *dst, unsigned val)
|
|
113
|
+
{
|
|
114
|
+
((unsigned char *)dst)[0] = (val >> 8);
|
|
115
|
+
((unsigned char *)dst)[1] = val;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
static inline unsigned
|
|
119
|
+
sph_dec16be(const void *src)
|
|
120
|
+
{
|
|
121
|
+
return ((unsigned)(((const unsigned char *)src)[0]) << 8)
|
|
122
|
+
| (unsigned)(((const unsigned char *)src)[1]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static inline void
|
|
126
|
+
sph_enc16le(void *dst, unsigned val)
|
|
127
|
+
{
|
|
128
|
+
((unsigned char *)dst)[0] = val;
|
|
129
|
+
((unsigned char *)dst)[1] = val >> 8;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static inline unsigned
|
|
133
|
+
sph_dec16le(const void *src)
|
|
134
|
+
{
|
|
135
|
+
return (unsigned)(((const unsigned char *)src)[0])
|
|
136
|
+
| ((unsigned)(((const unsigned char *)src)[1]) << 8);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Encode a 32-bit value into the provided buffer (big endian convention).
|
|
141
|
+
*
|
|
142
|
+
* @param dst the destination buffer
|
|
143
|
+
* @param val the 32-bit value to encode
|
|
144
|
+
*/
|
|
145
|
+
static inline void
|
|
146
|
+
sph_enc32be(void *dst, sph_u32 val)
|
|
147
|
+
{
|
|
148
|
+
((unsigned char *)dst)[0] = (val >> 24);
|
|
149
|
+
((unsigned char *)dst)[1] = (val >> 16);
|
|
150
|
+
((unsigned char *)dst)[2] = (val >> 8);
|
|
151
|
+
((unsigned char *)dst)[3] = val;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Encode a 32-bit value into the provided buffer (big endian convention).
|
|
156
|
+
* The destination buffer must be properly aligned.
|
|
157
|
+
*
|
|
158
|
+
* @param dst the destination buffer (32-bit aligned)
|
|
159
|
+
* @param val the value to encode
|
|
160
|
+
*/
|
|
161
|
+
static inline void
|
|
162
|
+
sph_enc32be_aligned(void *dst, sph_u32 val)
|
|
163
|
+
{
|
|
164
|
+
((unsigned char *)dst)[0] = (val >> 24);
|
|
165
|
+
((unsigned char *)dst)[1] = (val >> 16);
|
|
166
|
+
((unsigned char *)dst)[2] = (val >> 8);
|
|
167
|
+
((unsigned char *)dst)[3] = val;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Decode a 32-bit value from the provided buffer (big endian convention).
|
|
172
|
+
*
|
|
173
|
+
* @param src the source buffer
|
|
174
|
+
* @return the decoded value
|
|
175
|
+
*/
|
|
176
|
+
static inline sph_u32
|
|
177
|
+
sph_dec32be(const void *src)
|
|
178
|
+
{
|
|
179
|
+
return ((sph_u32)(((const unsigned char *)src)[0]) << 24)
|
|
180
|
+
| ((sph_u32)(((const unsigned char *)src)[1]) << 16)
|
|
181
|
+
| ((sph_u32)(((const unsigned char *)src)[2]) << 8)
|
|
182
|
+
| (sph_u32)(((const unsigned char *)src)[3]);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Decode a 32-bit value from the provided buffer (big endian convention).
|
|
187
|
+
* The source buffer must be properly aligned.
|
|
188
|
+
*
|
|
189
|
+
* @param src the source buffer (32-bit aligned)
|
|
190
|
+
* @return the decoded value
|
|
191
|
+
*/
|
|
192
|
+
static inline sph_u32
|
|
193
|
+
sph_dec32be_aligned(const void *src)
|
|
194
|
+
{
|
|
195
|
+
return ((sph_u32)(((const unsigned char *)src)[0]) << 24)
|
|
196
|
+
| ((sph_u32)(((const unsigned char *)src)[1]) << 16)
|
|
197
|
+
| ((sph_u32)(((const unsigned char *)src)[2]) << 8)
|
|
198
|
+
| (sph_u32)(((const unsigned char *)src)[3]);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Encode a 32-bit value into the provided buffer (little endian convention).
|
|
203
|
+
*
|
|
204
|
+
* @param dst the destination buffer
|
|
205
|
+
* @param val the 32-bit value to encode
|
|
206
|
+
*/
|
|
207
|
+
static inline void
|
|
208
|
+
sph_enc32le(void *dst, sph_u32 val)
|
|
209
|
+
{
|
|
210
|
+
((unsigned char *)dst)[0] = val;
|
|
211
|
+
((unsigned char *)dst)[1] = (val >> 8);
|
|
212
|
+
((unsigned char *)dst)[2] = (val >> 16);
|
|
213
|
+
((unsigned char *)dst)[3] = (val >> 24);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Encode a 32-bit value into the provided buffer (little endian convention).
|
|
218
|
+
* The destination buffer must be properly aligned.
|
|
219
|
+
*
|
|
220
|
+
* @param dst the destination buffer (32-bit aligned)
|
|
221
|
+
* @param val the value to encode
|
|
222
|
+
*/
|
|
223
|
+
static inline void
|
|
224
|
+
sph_enc32le_aligned(void *dst, sph_u32 val)
|
|
225
|
+
{
|
|
226
|
+
((unsigned char *)dst)[0] = val;
|
|
227
|
+
((unsigned char *)dst)[1] = (val >> 8);
|
|
228
|
+
((unsigned char *)dst)[2] = (val >> 16);
|
|
229
|
+
((unsigned char *)dst)[3] = (val >> 24);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Decode a 32-bit value from the provided buffer (little endian convention).
|
|
234
|
+
*
|
|
235
|
+
* @param src the source buffer
|
|
236
|
+
* @return the decoded value
|
|
237
|
+
*/
|
|
238
|
+
static inline sph_u32
|
|
239
|
+
sph_dec32le(const void *src)
|
|
240
|
+
{
|
|
241
|
+
return (sph_u32)(((const unsigned char *)src)[0])
|
|
242
|
+
| ((sph_u32)(((const unsigned char *)src)[1]) << 8)
|
|
243
|
+
| ((sph_u32)(((const unsigned char *)src)[2]) << 16)
|
|
244
|
+
| ((sph_u32)(((const unsigned char *)src)[3]) << 24);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Decode a 32-bit value from the provided buffer (little endian convention).
|
|
249
|
+
* The source buffer must be properly aligned.
|
|
250
|
+
*
|
|
251
|
+
* @param src the source buffer (32-bit aligned)
|
|
252
|
+
* @return the decoded value
|
|
253
|
+
*/
|
|
254
|
+
static inline sph_u32
|
|
255
|
+
sph_dec32le_aligned(const void *src)
|
|
256
|
+
{
|
|
257
|
+
return (sph_u32)(((const unsigned char *)src)[0])
|
|
258
|
+
| ((sph_u32)(((const unsigned char *)src)[1]) << 8)
|
|
259
|
+
| ((sph_u32)(((const unsigned char *)src)[2]) << 16)
|
|
260
|
+
| ((sph_u32)(((const unsigned char *)src)[3]) << 24);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Encode a 64-bit value into the provided buffer (big endian convention).
|
|
265
|
+
*
|
|
266
|
+
* @param dst the destination buffer
|
|
267
|
+
* @param val the 64-bit value to encode
|
|
268
|
+
*/
|
|
269
|
+
static inline void
|
|
270
|
+
sph_enc64be(void *dst, sph_u64 val)
|
|
271
|
+
{
|
|
272
|
+
((unsigned char *)dst)[0] = (val >> 56);
|
|
273
|
+
((unsigned char *)dst)[1] = (val >> 48);
|
|
274
|
+
((unsigned char *)dst)[2] = (val >> 40);
|
|
275
|
+
((unsigned char *)dst)[3] = (val >> 32);
|
|
276
|
+
((unsigned char *)dst)[4] = (val >> 24);
|
|
277
|
+
((unsigned char *)dst)[5] = (val >> 16);
|
|
278
|
+
((unsigned char *)dst)[6] = (val >> 8);
|
|
279
|
+
((unsigned char *)dst)[7] = val;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Encode a 64-bit value into the provided buffer (big endian convention).
|
|
284
|
+
* The destination buffer must be properly aligned.
|
|
285
|
+
*
|
|
286
|
+
* @param dst the destination buffer (64-bit aligned)
|
|
287
|
+
* @param val the value to encode
|
|
288
|
+
*/
|
|
289
|
+
static inline void
|
|
290
|
+
sph_enc64be_aligned(void *dst, sph_u64 val)
|
|
291
|
+
{
|
|
292
|
+
((unsigned char *)dst)[0] = (val >> 56);
|
|
293
|
+
((unsigned char *)dst)[1] = (val >> 48);
|
|
294
|
+
((unsigned char *)dst)[2] = (val >> 40);
|
|
295
|
+
((unsigned char *)dst)[3] = (val >> 32);
|
|
296
|
+
((unsigned char *)dst)[4] = (val >> 24);
|
|
297
|
+
((unsigned char *)dst)[5] = (val >> 16);
|
|
298
|
+
((unsigned char *)dst)[6] = (val >> 8);
|
|
299
|
+
((unsigned char *)dst)[7] = val;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Decode a 64-bit value from the provided buffer (big endian convention).
|
|
304
|
+
*
|
|
305
|
+
* @param src the source buffer
|
|
306
|
+
* @return the decoded value
|
|
307
|
+
*/
|
|
308
|
+
static inline sph_u64
|
|
309
|
+
sph_dec64be(const void *src)
|
|
310
|
+
{
|
|
311
|
+
return ((sph_u64)(((const unsigned char *)src)[0]) << 56)
|
|
312
|
+
| ((sph_u64)(((const unsigned char *)src)[1]) << 48)
|
|
313
|
+
| ((sph_u64)(((const unsigned char *)src)[2]) << 40)
|
|
314
|
+
| ((sph_u64)(((const unsigned char *)src)[3]) << 32)
|
|
315
|
+
| ((sph_u64)(((const unsigned char *)src)[4]) << 24)
|
|
316
|
+
| ((sph_u64)(((const unsigned char *)src)[5]) << 16)
|
|
317
|
+
| ((sph_u64)(((const unsigned char *)src)[6]) << 8)
|
|
318
|
+
| (sph_u64)(((const unsigned char *)src)[7]);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Decode a 64-bit value from the provided buffer (big endian convention).
|
|
323
|
+
* The source buffer must be properly aligned.
|
|
324
|
+
*
|
|
325
|
+
* @param src the source buffer (64-bit aligned)
|
|
326
|
+
* @return the decoded value
|
|
327
|
+
*/
|
|
328
|
+
static inline sph_u64
|
|
329
|
+
sph_dec64be_aligned(const void *src)
|
|
330
|
+
{
|
|
331
|
+
return ((sph_u64)(((const unsigned char *)src)[0]) << 56)
|
|
332
|
+
| ((sph_u64)(((const unsigned char *)src)[1]) << 48)
|
|
333
|
+
| ((sph_u64)(((const unsigned char *)src)[2]) << 40)
|
|
334
|
+
| ((sph_u64)(((const unsigned char *)src)[3]) << 32)
|
|
335
|
+
| ((sph_u64)(((const unsigned char *)src)[4]) << 24)
|
|
336
|
+
| ((sph_u64)(((const unsigned char *)src)[5]) << 16)
|
|
337
|
+
| ((sph_u64)(((const unsigned char *)src)[6]) << 8)
|
|
338
|
+
| (sph_u64)(((const unsigned char *)src)[7]);
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Encode a 64-bit value into the provided buffer (little endian convention).
|
|
343
|
+
*
|
|
344
|
+
* @param dst the destination buffer
|
|
345
|
+
* @param val the 64-bit value to encode
|
|
346
|
+
*/
|
|
347
|
+
static inline void
|
|
348
|
+
sph_enc64le(void *dst, sph_u64 val)
|
|
349
|
+
{
|
|
350
|
+
((unsigned char *)dst)[0] = val;
|
|
351
|
+
((unsigned char *)dst)[1] = (val >> 8);
|
|
352
|
+
((unsigned char *)dst)[2] = (val >> 16);
|
|
353
|
+
((unsigned char *)dst)[3] = (val >> 24);
|
|
354
|
+
((unsigned char *)dst)[4] = (val >> 32);
|
|
355
|
+
((unsigned char *)dst)[5] = (val >> 40);
|
|
356
|
+
((unsigned char *)dst)[6] = (val >> 48);
|
|
357
|
+
((unsigned char *)dst)[7] = (val >> 56);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/**
|
|
361
|
+
* Encode a 64-bit value into the provided buffer (little endian convention).
|
|
362
|
+
* The destination buffer must be properly aligned.
|
|
363
|
+
*
|
|
364
|
+
* @param dst the destination buffer (64-bit aligned)
|
|
365
|
+
* @param val the value to encode
|
|
366
|
+
*/
|
|
367
|
+
static inline void
|
|
368
|
+
sph_enc64le_aligned(void *dst, sph_u64 val)
|
|
369
|
+
{
|
|
370
|
+
((unsigned char *)dst)[0] = val;
|
|
371
|
+
((unsigned char *)dst)[1] = (val >> 8);
|
|
372
|
+
((unsigned char *)dst)[2] = (val >> 16);
|
|
373
|
+
((unsigned char *)dst)[3] = (val >> 24);
|
|
374
|
+
((unsigned char *)dst)[4] = (val >> 32);
|
|
375
|
+
((unsigned char *)dst)[5] = (val >> 40);
|
|
376
|
+
((unsigned char *)dst)[6] = (val >> 48);
|
|
377
|
+
((unsigned char *)dst)[7] = (val >> 56);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Decode a 64-bit value from the provided buffer (little endian convention).
|
|
382
|
+
*
|
|
383
|
+
* @param src the source buffer
|
|
384
|
+
* @return the decoded value
|
|
385
|
+
*/
|
|
386
|
+
static inline sph_u64
|
|
387
|
+
sph_dec64le(const void *src)
|
|
388
|
+
{
|
|
389
|
+
return (sph_u64)(((const unsigned char *)src)[0])
|
|
390
|
+
| ((sph_u64)(((const unsigned char *)src)[1]) << 8)
|
|
391
|
+
| ((sph_u64)(((const unsigned char *)src)[2]) << 16)
|
|
392
|
+
| ((sph_u64)(((const unsigned char *)src)[3]) << 24)
|
|
393
|
+
| ((sph_u64)(((const unsigned char *)src)[4]) << 32)
|
|
394
|
+
| ((sph_u64)(((const unsigned char *)src)[5]) << 40)
|
|
395
|
+
| ((sph_u64)(((const unsigned char *)src)[6]) << 48)
|
|
396
|
+
| ((sph_u64)(((const unsigned char *)src)[7]) << 56);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Decode a 64-bit value from the provided buffer (little endian convention).
|
|
401
|
+
* The source buffer must be properly aligned.
|
|
402
|
+
*
|
|
403
|
+
* @param src the source buffer (64-bit aligned)
|
|
404
|
+
* @return the decoded value
|
|
405
|
+
*/
|
|
406
|
+
static inline sph_u64
|
|
407
|
+
sph_dec64le_aligned(const void *src)
|
|
408
|
+
{
|
|
409
|
+
return (sph_u64)(((const unsigned char *)src)[0])
|
|
410
|
+
| ((sph_u64)(((const unsigned char *)src)[1]) << 8)
|
|
411
|
+
| ((sph_u64)(((const unsigned char *)src)[2]) << 16)
|
|
412
|
+
| ((sph_u64)(((const unsigned char *)src)[3]) << 24)
|
|
413
|
+
| ((sph_u64)(((const unsigned char *)src)[4]) << 32)
|
|
414
|
+
| ((sph_u64)(((const unsigned char *)src)[5]) << 40)
|
|
415
|
+
| ((sph_u64)(((const unsigned char *)src)[6]) << 48)
|
|
416
|
+
| ((sph_u64)(((const unsigned char *)src)[7]) << 56);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
#endif
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2017 Saleem Rashid
|
|
3
|
+
*
|
|
4
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
5
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
6
|
+
* to deal in the Software without restriction, including without limitation
|
|
7
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
8
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
9
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
10
|
+
*
|
|
11
|
+
* The above copyright notice and this permission notice shall be included
|
|
12
|
+
* in all copies or substantial portions of the Software.
|
|
13
|
+
*
|
|
14
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
17
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
18
|
+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
19
|
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
20
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#include <TrezorCrypto/hasher.h>
|
|
24
|
+
#include <TrezorCrypto/ripemd160.h>
|
|
25
|
+
|
|
26
|
+
// JuBiter-modified
|
|
27
|
+
int hasher_InitParam(Hasher *hasher, HasherType type, const void *param, uint32_t param_size) {
|
|
28
|
+
int ret = 0;
|
|
29
|
+
|
|
30
|
+
hasher->type = type;
|
|
31
|
+
hasher->param = param;
|
|
32
|
+
hasher->param_size = param_size;
|
|
33
|
+
|
|
34
|
+
switch (hasher->type) {
|
|
35
|
+
case HASHER_SHA2:
|
|
36
|
+
case HASHER_SHA2D:
|
|
37
|
+
case HASHER_SHA2_RIPEMD:
|
|
38
|
+
sha256_Init(&hasher->ctx.sha2);
|
|
39
|
+
break;
|
|
40
|
+
case HASHER_SHA3:
|
|
41
|
+
case HASHER_SHA3K:
|
|
42
|
+
sha3_256_Init(&hasher->ctx.sha3);
|
|
43
|
+
break;
|
|
44
|
+
case HASHER_BLAKE:
|
|
45
|
+
case HASHER_BLAKED:
|
|
46
|
+
case HASHER_BLAKE_RIPEMD:
|
|
47
|
+
blake256_Init(&hasher->ctx.blake);
|
|
48
|
+
break;
|
|
49
|
+
case HASHER_GROESTLD_TRUNC:
|
|
50
|
+
groestl512_Init(&hasher->ctx.groestl);
|
|
51
|
+
break;
|
|
52
|
+
case HASHER_BLAKE2B:
|
|
53
|
+
ret = blake2b_Init(&hasher->ctx.blake2b, 32);
|
|
54
|
+
break;
|
|
55
|
+
case HASHER_BLAKE2B_PERSONAL:
|
|
56
|
+
ret = blake2b_InitPersonal(&hasher->ctx.blake2b, 32, hasher->param, hasher->param_size);
|
|
57
|
+
break;
|
|
58
|
+
case HASHER_SHA2_KECCAK:
|
|
59
|
+
keccak_256_Init(&hasher->ctx.sha3);
|
|
60
|
+
break;
|
|
61
|
+
case HASHER_SHA3_KECCAK:
|
|
62
|
+
keccak_512_Init(&hasher->ctx.sha3);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
return ret;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// JuBiter-modified
|
|
69
|
+
int hasher_Init(Hasher *hasher, HasherType type) {
|
|
70
|
+
return hasher_InitParam(hasher, type, NULL, 0);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// JuBiter-modified
|
|
74
|
+
int hasher_Reset(Hasher *hasher) {
|
|
75
|
+
return hasher_InitParam(hasher, hasher->type, hasher->param, hasher->param_size);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// JuBiter-modified
|
|
79
|
+
int hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) {
|
|
80
|
+
int ret = 0;
|
|
81
|
+
switch (hasher->type) {
|
|
82
|
+
case HASHER_SHA2:
|
|
83
|
+
case HASHER_SHA2D:
|
|
84
|
+
case HASHER_SHA2_RIPEMD:
|
|
85
|
+
sha256_Update(&hasher->ctx.sha2, data, length);
|
|
86
|
+
break;
|
|
87
|
+
case HASHER_SHA3:
|
|
88
|
+
case HASHER_SHA3K:
|
|
89
|
+
sha3_Update(&hasher->ctx.sha3, data, length);
|
|
90
|
+
break;
|
|
91
|
+
case HASHER_BLAKE:
|
|
92
|
+
case HASHER_BLAKED:
|
|
93
|
+
case HASHER_BLAKE_RIPEMD:
|
|
94
|
+
blake256_Update(&hasher->ctx.blake, data, length);
|
|
95
|
+
break;
|
|
96
|
+
case HASHER_GROESTLD_TRUNC:
|
|
97
|
+
groestl512_Update(&hasher->ctx.groestl, data, length);
|
|
98
|
+
break;
|
|
99
|
+
case HASHER_BLAKE2B:
|
|
100
|
+
case HASHER_BLAKE2B_PERSONAL:
|
|
101
|
+
ret = blake2b_Update(&hasher->ctx.blake2b, data, length);
|
|
102
|
+
break;
|
|
103
|
+
case HASHER_SHA2_KECCAK:
|
|
104
|
+
case HASHER_SHA3_KECCAK:
|
|
105
|
+
keccak_Update(&hasher->ctx.sha3, data, length);
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
return ret;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// JuBiter-modified
|
|
112
|
+
int hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) {
|
|
113
|
+
int ret = 0;
|
|
114
|
+
switch (hasher->type) {
|
|
115
|
+
case HASHER_SHA2:
|
|
116
|
+
sha256_Final(&hasher->ctx.sha2, hash);
|
|
117
|
+
break;
|
|
118
|
+
case HASHER_SHA2D:
|
|
119
|
+
sha256_Final(&hasher->ctx.sha2, hash);
|
|
120
|
+
hasher_Raw(HASHER_SHA2, hash, HASHER_DIGEST_LENGTH, hash);
|
|
121
|
+
break;
|
|
122
|
+
case HASHER_SHA2_RIPEMD:
|
|
123
|
+
sha256_Final(&hasher->ctx.sha2, hash);
|
|
124
|
+
ripemd160(hash, HASHER_DIGEST_LENGTH, hash);
|
|
125
|
+
break;
|
|
126
|
+
case HASHER_SHA3:
|
|
127
|
+
sha3_Final(&hasher->ctx.sha3, hash);
|
|
128
|
+
break;
|
|
129
|
+
case HASHER_SHA3K:
|
|
130
|
+
keccak_Final(&hasher->ctx.sha3, hash);
|
|
131
|
+
break;
|
|
132
|
+
case HASHER_BLAKE:
|
|
133
|
+
blake256_Final(&hasher->ctx.blake, hash);
|
|
134
|
+
break;
|
|
135
|
+
case HASHER_BLAKED:
|
|
136
|
+
blake256_Final(&hasher->ctx.blake, hash);
|
|
137
|
+
hasher_Raw(HASHER_BLAKE, hash, HASHER_DIGEST_LENGTH, hash);
|
|
138
|
+
break;
|
|
139
|
+
case HASHER_BLAKE_RIPEMD:
|
|
140
|
+
blake256_Final(&hasher->ctx.blake, hash);
|
|
141
|
+
ripemd160(hash, HASHER_DIGEST_LENGTH, hash);
|
|
142
|
+
break;
|
|
143
|
+
case HASHER_GROESTLD_TRUNC:
|
|
144
|
+
groestl512_DoubleTrunc(&hasher->ctx.groestl, hash);
|
|
145
|
+
break;
|
|
146
|
+
case HASHER_BLAKE2B:
|
|
147
|
+
case HASHER_BLAKE2B_PERSONAL:
|
|
148
|
+
ret = blake2b_Final(&hasher->ctx.blake2b, hash, 32);
|
|
149
|
+
break;
|
|
150
|
+
case HASHER_SHA2_KECCAK:
|
|
151
|
+
case HASHER_SHA3_KECCAK:
|
|
152
|
+
keccak_Final(&hasher->ctx.sha3, hash);
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
return ret;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// JuBiter-modified
|
|
159
|
+
int hasher_Raw(HasherType type, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]) {
|
|
160
|
+
int ret = 0;
|
|
161
|
+
Hasher hasher;
|
|
162
|
+
ret = hasher_Init(&hasher, type);
|
|
163
|
+
if (0 != ret) {
|
|
164
|
+
return ret;
|
|
165
|
+
}
|
|
166
|
+
ret = hasher_Update(&hasher, data, length);
|
|
167
|
+
if (0 != ret) {
|
|
168
|
+
return ret;
|
|
169
|
+
}
|
|
170
|
+
return hasher_Final(&hasher, hash);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// JuBiter-modified
|
|
174
|
+
int hasher_InitParam_Raw(Hasher *phasher, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]) {
|
|
175
|
+
int ret = 0;
|
|
176
|
+
Hasher hasher;
|
|
177
|
+
ret = hasher_InitParam(&hasher, phasher->type, phasher->param, phasher->param_size);
|
|
178
|
+
if (0 != ret) {
|
|
179
|
+
return ret;
|
|
180
|
+
}
|
|
181
|
+
ret = hasher_Update(&hasher, data, length);
|
|
182
|
+
if (0 != ret) {
|
|
183
|
+
return ret;
|
|
184
|
+
}
|
|
185
|
+
return hasher_Final(&hasher, hash);
|
|
186
|
+
}
|