@onekeyfe/react-native-lite-card 6.7.0-6 → 6.7.0-60
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 +134 -43
- package/ReactNativeLiteCard.podspec +31 -2
- package/android/build.gradle +8 -0
- package/android/consumer-rules.pro +4 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +60 -49
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +117 -39
- 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 +24 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +46 -19
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +38 -1
- package/ios/Classes/OKNFCBridge.mm +24 -1
- package/ios/Classes/OKNFTLite/OKLiteV1.m +20 -10
- package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
- package/ios/Classes/OKNFTLite/OKNFCManager.h +2 -2
- package/ios/Classes/OKNFTLite/OKNFCManager.m +110 -18
- package/ios/ReactNativeLiteCard.mm +23 -11
- package/lib/module/index.js +4 -4
- package/lib/typescript/src/NativeReactNativeLiteCard.d.ts +4 -4
- package/lib/typescript/src/index.d.ts +2 -2
- package/package.json +9 -8
- package/sdk/CMakeLists.txt +121 -0
- package/sdk/README.md +190 -0
- package/sdk/android/implJni.cpp +216 -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/scripts/generate-source-id.rb +22 -0
- package/sdk/source-id-manifest.txt +19 -0
- package/sdk/source-id.cmake +31 -0
- package/sdk/src/ApduBuilder.cpp +332 -0
- package/sdk/src/GPChannelSDK.cpp +258 -0
- package/sdk/src/random.c +25 -0
- package/sdk/src/version.c +3 -0
- package/sdk/tests/android/GPChannelProxy.java +55 -0
- package/sdk/tests/android_verify.py +124 -0
- package/sdk/tests/safety.cpp +757 -0
- package/sdk/tests/verify.py +284 -0
- package/src/NativeReactNativeLiteCard.ts +4 -2
- package/src/index.tsx +14 -3
- 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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016 Pavol Rusnak
|
|
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
|
+
#ifndef __SCRIPT_H__
|
|
24
|
+
#define __SCRIPT_H__
|
|
25
|
+
|
|
26
|
+
#include <stdint.h>
|
|
27
|
+
|
|
28
|
+
int script_output_to_address(const uint8_t *script, int scriptlen, char *addr, int addrsize);
|
|
29
|
+
|
|
30
|
+
#endif
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/*-
|
|
2
|
+
* Copyright 2009 Colin Percival
|
|
3
|
+
* All rights reserved.
|
|
4
|
+
*
|
|
5
|
+
* Redistribution and use in source and binary forms, with or without
|
|
6
|
+
* modification, are permitted provided that the following conditions
|
|
7
|
+
* are met:
|
|
8
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
9
|
+
* notice, this list of conditions and the following disclaimer.
|
|
10
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
11
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
12
|
+
* documentation and/or other materials provided with the distribution.
|
|
13
|
+
*
|
|
14
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
15
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
16
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
17
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
18
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
19
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
20
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
21
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
22
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
23
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
24
|
+
* SUCH DAMAGE.
|
|
25
|
+
*
|
|
26
|
+
* This file was originally written by Colin Percival as part of the Tarsnap
|
|
27
|
+
* online backup system.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
#ifndef _SCRYPT_H_
|
|
31
|
+
#define _SCRYPT_H_
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
#include <stdint.h>
|
|
35
|
+
#include <stddef.h>
|
|
36
|
+
#ifdef __cplusplus
|
|
37
|
+
extern "C"{
|
|
38
|
+
#endif
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
|
42
|
+
* Compute scrypt(passwd[0 .. passwdlen - 1], salt[0 .. saltlen - 1], N, r,
|
|
43
|
+
* p, buflen) and write the result into buf. The parameters r, p, and buflen
|
|
44
|
+
* must satisfy r * p < 2^30 and buflen <= (2^32 - 1) * 32. The parameter N
|
|
45
|
+
* must be a power of 2 greater than 1.
|
|
46
|
+
*
|
|
47
|
+
* scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen):
|
|
48
|
+
* password; duh
|
|
49
|
+
* N: CPU AND RAM cost (first modifier)
|
|
50
|
+
* r: RAM Cost
|
|
51
|
+
* p: CPU cost (parallelisation)
|
|
52
|
+
* In short, N is your main performance modifier. Values of r = 8, p = 1 are
|
|
53
|
+
* standard unless you want to modify the CPU/RAM ratio.
|
|
54
|
+
* Return 0 on success; or -1 on error.
|
|
55
|
+
*/
|
|
56
|
+
int scrypt(const uint8_t *, size_t, const uint8_t *, size_t, uint64_t,
|
|
57
|
+
uint32_t, uint32_t, /*@out@*/ uint8_t *, size_t);
|
|
58
|
+
|
|
59
|
+
#ifdef __cplusplus
|
|
60
|
+
}
|
|
61
|
+
#endif
|
|
62
|
+
|
|
63
|
+
/* Sane default values */
|
|
64
|
+
#define SCRYPT_N 16384
|
|
65
|
+
#define SCRYPT_r 8
|
|
66
|
+
#define SCRYPT_p 16
|
|
67
|
+
|
|
68
|
+
#endif /* !_SCRYPT_H_ */
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2013-2014 Tomas Dzetkulic
|
|
3
|
+
* Copyright (c) 2013-2014 Pavol Rusnak
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
7
|
+
* to deal in the Software without restriction, including without limitation
|
|
8
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
10
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included
|
|
13
|
+
* in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
19
|
+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
20
|
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
21
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#ifndef __SECP256K1_H__
|
|
25
|
+
#define __SECP256K1_H__
|
|
26
|
+
|
|
27
|
+
#include <stdint.h>
|
|
28
|
+
|
|
29
|
+
#include <TrezorCrypto/ecdsa.h>
|
|
30
|
+
#include <TrezorCrypto/bip32.h>
|
|
31
|
+
|
|
32
|
+
#ifdef __cplusplus
|
|
33
|
+
extern "C" {
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
extern const ecdsa_curve secp256k1;
|
|
37
|
+
extern const curve_info secp256k1_info;
|
|
38
|
+
// JuBiter-defined
|
|
39
|
+
extern const curve_info secp256k1_ethereum_info;
|
|
40
|
+
// JuBiter-defined
|
|
41
|
+
extern const curve_info secp256k1_ripple_info;
|
|
42
|
+
// JuBiter-defined
|
|
43
|
+
extern const curve_info secp256k1_hcash_info;
|
|
44
|
+
// JuBiter-defined
|
|
45
|
+
extern const curve_info secp256k1_eos_info;
|
|
46
|
+
// JuBiter-defined
|
|
47
|
+
extern const curve_info secp256k1_trx_info;
|
|
48
|
+
// JuBiter-defined
|
|
49
|
+
extern const curve_info secp256k1_fil_info;
|
|
50
|
+
// JuBiter-defined
|
|
51
|
+
extern const curve_info secp256k1_ckb_info;
|
|
52
|
+
extern const curve_info secp256k1_decred_info;
|
|
53
|
+
extern const curve_info secp256k1_smart_info;
|
|
54
|
+
|
|
55
|
+
#ifdef __cplusplus
|
|
56
|
+
} /* extern "C" */
|
|
57
|
+
#endif
|
|
58
|
+
|
|
59
|
+
#endif
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2000-2001 Aaron D. Gifford
|
|
3
|
+
* Copyright (c) 2013-2014 Pavol Rusnak
|
|
4
|
+
* All rights reserved.
|
|
5
|
+
*
|
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
|
7
|
+
* modification, are permitted provided that the following conditions
|
|
8
|
+
* are met:
|
|
9
|
+
* 1. Redistributions of source code must retain the above copyright
|
|
10
|
+
* notice, this list of conditions and the following disclaimer.
|
|
11
|
+
* 2. Redistributions in binary form must reproduce the above copyright
|
|
12
|
+
* notice, this list of conditions and the following disclaimer in the
|
|
13
|
+
* documentation and/or other materials provided with the distribution.
|
|
14
|
+
* 3. Neither the name of the copyright holder nor the names of contributors
|
|
15
|
+
* may be used to endorse or promote products derived from this software
|
|
16
|
+
* without specific prior written permission.
|
|
17
|
+
*
|
|
18
|
+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTOR(S) ``AS IS'' AND
|
|
19
|
+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
20
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
21
|
+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTOR(S) BE LIABLE
|
|
22
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
23
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
24
|
+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
25
|
+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
26
|
+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
27
|
+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
28
|
+
* SUCH DAMAGE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
#ifndef __SHA2_H__
|
|
32
|
+
#define __SHA2_H__
|
|
33
|
+
|
|
34
|
+
#include <stdint.h>
|
|
35
|
+
#include <stddef.h>
|
|
36
|
+
|
|
37
|
+
#ifdef __cplusplus
|
|
38
|
+
extern "C" {
|
|
39
|
+
#endif
|
|
40
|
+
|
|
41
|
+
#define SHA1_BLOCK_LENGTH 64
|
|
42
|
+
#define SHA1_DIGEST_LENGTH 20
|
|
43
|
+
#define SHA1_DIGEST_STRING_LENGTH (SHA1_DIGEST_LENGTH * 2 + 1)
|
|
44
|
+
#define SHA256_BLOCK_LENGTH 64
|
|
45
|
+
#define SHA256_DIGEST_LENGTH 32
|
|
46
|
+
#define SHA256_DIGEST_STRING_LENGTH (SHA256_DIGEST_LENGTH * 2 + 1)
|
|
47
|
+
#define SHA512_BLOCK_LENGTH 128
|
|
48
|
+
#define SHA512_DIGEST_LENGTH 64
|
|
49
|
+
#define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1)
|
|
50
|
+
|
|
51
|
+
typedef struct _SHA1_CTX {
|
|
52
|
+
uint32_t state[5];
|
|
53
|
+
uint64_t bitcount;
|
|
54
|
+
uint32_t buffer[SHA1_BLOCK_LENGTH/sizeof(uint32_t)];
|
|
55
|
+
} SHA1_CTX;
|
|
56
|
+
typedef struct _SHA256_CTX {
|
|
57
|
+
uint32_t state[8];
|
|
58
|
+
uint64_t bitcount;
|
|
59
|
+
uint32_t buffer[SHA256_BLOCK_LENGTH/sizeof(uint32_t)];
|
|
60
|
+
} SHA256_CTX;
|
|
61
|
+
typedef struct _SHA512_CTX {
|
|
62
|
+
uint64_t state[8];
|
|
63
|
+
uint64_t bitcount[2];
|
|
64
|
+
uint64_t buffer[SHA512_BLOCK_LENGTH/sizeof(uint64_t)];
|
|
65
|
+
} SHA512_CTX;
|
|
66
|
+
|
|
67
|
+
/*** ENDIAN REVERSAL MACROS *******************************************/
|
|
68
|
+
#ifndef LITTLE_ENDIAN
|
|
69
|
+
#define LITTLE_ENDIAN 1234
|
|
70
|
+
#define BIG_ENDIAN 4321
|
|
71
|
+
#endif
|
|
72
|
+
|
|
73
|
+
#ifndef BYTE_ORDER
|
|
74
|
+
#define BYTE_ORDER LITTLE_ENDIAN
|
|
75
|
+
#endif
|
|
76
|
+
|
|
77
|
+
#if BYTE_ORDER == LITTLE_ENDIAN
|
|
78
|
+
#define REVERSE32(w,x) { \
|
|
79
|
+
uint32_t tmp = (w); \
|
|
80
|
+
tmp = (tmp >> 16) | (tmp << 16); \
|
|
81
|
+
(x) = ((tmp & 0xff00ff00UL) >> 8) | ((tmp & 0x00ff00ffUL) << 8); \
|
|
82
|
+
}
|
|
83
|
+
#define REVERSE64(w,x) { \
|
|
84
|
+
uint64_t tmp = (w); \
|
|
85
|
+
tmp = (tmp >> 32) | (tmp << 32); \
|
|
86
|
+
tmp = ((tmp & 0xff00ff00ff00ff00ULL) >> 8) | \
|
|
87
|
+
((tmp & 0x00ff00ff00ff00ffULL) << 8); \
|
|
88
|
+
(x) = ((tmp & 0xffff0000ffff0000ULL) >> 16) | \
|
|
89
|
+
((tmp & 0x0000ffff0000ffffULL) << 16); \
|
|
90
|
+
}
|
|
91
|
+
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
|
|
92
|
+
|
|
93
|
+
extern const uint32_t sha256_initial_hash_value[8];
|
|
94
|
+
extern const uint64_t sha512_initial_hash_value[8];
|
|
95
|
+
|
|
96
|
+
void sha1_Transform(const uint32_t* state_in, const uint32_t* data, uint32_t* state_out);
|
|
97
|
+
void sha1_Init(SHA1_CTX *);
|
|
98
|
+
void sha1_Update(SHA1_CTX*, const uint8_t*, size_t);
|
|
99
|
+
void sha1_Final(SHA1_CTX*, uint8_t[SHA1_DIGEST_LENGTH]);
|
|
100
|
+
char* sha1_End(SHA1_CTX*, char[SHA1_DIGEST_STRING_LENGTH]);
|
|
101
|
+
void sha1_Raw(const uint8_t*, size_t, uint8_t[SHA1_DIGEST_LENGTH]);
|
|
102
|
+
char* sha1_Data(const uint8_t*, size_t, char[SHA1_DIGEST_STRING_LENGTH]);
|
|
103
|
+
|
|
104
|
+
void sha256_Transform(const uint32_t* state_in, const uint32_t* data, uint32_t* state_out);
|
|
105
|
+
void sha256_Init(SHA256_CTX *);
|
|
106
|
+
void sha256_Update(SHA256_CTX*, const uint8_t*, size_t);
|
|
107
|
+
void sha256_Final(SHA256_CTX*, uint8_t[SHA256_DIGEST_LENGTH]);
|
|
108
|
+
char* sha256_End(SHA256_CTX*, char[SHA256_DIGEST_STRING_LENGTH]);
|
|
109
|
+
void sha256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]);
|
|
110
|
+
char* sha256_Data(const uint8_t*, size_t, char[SHA256_DIGEST_STRING_LENGTH]);
|
|
111
|
+
|
|
112
|
+
void sha512_Transform(const uint64_t* state_in, const uint64_t* data, uint64_t* state_out);
|
|
113
|
+
void sha512_Init(SHA512_CTX*);
|
|
114
|
+
void sha512_Update(SHA512_CTX*, const uint8_t*, size_t);
|
|
115
|
+
void sha512_Final(SHA512_CTX*, uint8_t[SHA512_DIGEST_LENGTH]);
|
|
116
|
+
char* sha512_End(SHA512_CTX*, char[SHA512_DIGEST_STRING_LENGTH]);
|
|
117
|
+
void sha512_Raw(const uint8_t*, size_t, uint8_t[SHA512_DIGEST_LENGTH]);
|
|
118
|
+
void sha512_256_Raw(const uint8_t*, size_t, uint8_t[SHA256_DIGEST_LENGTH]);
|
|
119
|
+
char* sha512_Data(const uint8_t*, size_t, char[SHA512_DIGEST_STRING_LENGTH]);
|
|
120
|
+
|
|
121
|
+
#ifdef __cplusplus
|
|
122
|
+
} /* extern "C" */
|
|
123
|
+
#endif
|
|
124
|
+
|
|
125
|
+
#endif
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/* sha3.h - an implementation of Secure Hash Algorithm 3 (Keccak).
|
|
2
|
+
* based on the
|
|
3
|
+
* The Keccak SHA-3 submission. Submission to NIST (Round 3), 2011
|
|
4
|
+
* by Guido Bertoni, Joan Daemen, Michaël Peeters and Gilles Van Assche
|
|
5
|
+
*
|
|
6
|
+
* Copyright: 2013 Aleksey Kravchenko <rhash.admin@gmail.com>
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
9
|
+
* copy of this software and associated documentation files (the "Software"),
|
|
10
|
+
* to deal in the Software without restriction, including without limitation
|
|
11
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
12
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
13
|
+
* Software is furnished to do so.
|
|
14
|
+
*
|
|
15
|
+
* This program is distributed in the hope that it will be useful, but
|
|
16
|
+
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
17
|
+
* or FITNESS FOR A PARTICULAR PURPOSE. Use this program at your own risk!
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
#ifndef __SHA3_H__
|
|
21
|
+
#define __SHA3_H__
|
|
22
|
+
|
|
23
|
+
#include <stdint.h>
|
|
24
|
+
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#define sha3_224_hash_size 28
|
|
30
|
+
#define sha3_256_hash_size 32
|
|
31
|
+
#define sha3_384_hash_size 48
|
|
32
|
+
#define sha3_512_hash_size 64
|
|
33
|
+
#define sha3_max_permutation_size 25
|
|
34
|
+
#define sha3_max_rate_in_qwords 24
|
|
35
|
+
|
|
36
|
+
#define SHA3_224_BLOCK_LENGTH 144
|
|
37
|
+
#define SHA3_256_BLOCK_LENGTH 136
|
|
38
|
+
#define SHA3_384_BLOCK_LENGTH 104
|
|
39
|
+
#define SHA3_512_BLOCK_LENGTH 72
|
|
40
|
+
|
|
41
|
+
#define SHA3_224_DIGEST_LENGTH sha3_224_hash_size
|
|
42
|
+
#define SHA3_256_DIGEST_LENGTH sha3_256_hash_size
|
|
43
|
+
#define SHA3_384_DIGEST_LENGTH sha3_384_hash_size
|
|
44
|
+
#define SHA3_512_DIGEST_LENGTH sha3_512_hash_size
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* SHA3 Algorithm context.
|
|
48
|
+
*/
|
|
49
|
+
typedef struct SHA3_CTX
|
|
50
|
+
{
|
|
51
|
+
/* 1600 bits algorithm hashing state */
|
|
52
|
+
uint64_t hash[sha3_max_permutation_size];
|
|
53
|
+
/* 1536-bit buffer for leftovers */
|
|
54
|
+
uint64_t message[sha3_max_rate_in_qwords];
|
|
55
|
+
/* count of bytes in the message[] buffer */
|
|
56
|
+
unsigned rest;
|
|
57
|
+
/* size of a message block processed at once */
|
|
58
|
+
unsigned block_size;
|
|
59
|
+
} SHA3_CTX;
|
|
60
|
+
|
|
61
|
+
/* methods for calculating the hash function */
|
|
62
|
+
|
|
63
|
+
void sha3_224_Init(SHA3_CTX *ctx);
|
|
64
|
+
void sha3_256_Init(SHA3_CTX *ctx);
|
|
65
|
+
void sha3_384_Init(SHA3_CTX *ctx);
|
|
66
|
+
void sha3_512_Init(SHA3_CTX *ctx);
|
|
67
|
+
void sha3_Update(SHA3_CTX *ctx, const unsigned char* msg, size_t size);
|
|
68
|
+
void sha3_Final(SHA3_CTX *ctx, unsigned char* result);
|
|
69
|
+
|
|
70
|
+
#define keccak_224_Init sha3_224_Init
|
|
71
|
+
#define keccak_256_Init sha3_256_Init
|
|
72
|
+
#define keccak_384_Init sha3_384_Init
|
|
73
|
+
#define keccak_512_Init sha3_512_Init
|
|
74
|
+
#define keccak_Update sha3_Update
|
|
75
|
+
void keccak_Final(SHA3_CTX *ctx, unsigned char* result);
|
|
76
|
+
void keccak_256(const unsigned char* data, size_t len, unsigned char* digest);
|
|
77
|
+
void keccak_512(const unsigned char* data, size_t len, unsigned char* digest);
|
|
78
|
+
|
|
79
|
+
void sha3_256(const unsigned char* data, size_t len, unsigned char* digest);
|
|
80
|
+
void sha3_512(const unsigned char* data, size_t len, unsigned char* digest);
|
|
81
|
+
|
|
82
|
+
#ifdef __cplusplus
|
|
83
|
+
} /* extern "C" */
|
|
84
|
+
#endif
|
|
85
|
+
|
|
86
|
+
#endif /* __SHA3_H__ */
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#ifndef __KEYPAIR_H__
|
|
2
|
+
#define __KEYPAIR_H__
|
|
3
|
+
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
#include "private/ed25519_ref10.h"
|
|
7
|
+
|
|
8
|
+
#ifdef __cplusplus
|
|
9
|
+
extern "C" {
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
int ed25519_pk_to_curve25519(unsigned char *curve25519_pk, const unsigned char *ed25519_pk);
|
|
13
|
+
|
|
14
|
+
int curve25519_pk_to_ed25519(unsigned char *ed25519_pk, const unsigned char *curve25519_pk);
|
|
15
|
+
|
|
16
|
+
#ifdef __cplusplus
|
|
17
|
+
} /* extern "C" */
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#endif
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
#ifndef __ED25519_REF10_H__
|
|
2
|
+
#define __ED25519_REF10_H__
|
|
3
|
+
|
|
4
|
+
#include <stddef.h>
|
|
5
|
+
#include <stdint.h>
|
|
6
|
+
|
|
7
|
+
#include "ed25519_ref10_fe_25_5.h"
|
|
8
|
+
#include "fe_25_5/fe.h"
|
|
9
|
+
|
|
10
|
+
#ifdef __cplusplus
|
|
11
|
+
extern "C" {
|
|
12
|
+
#endif
|
|
13
|
+
|
|
14
|
+
void fe25519_invert(fe25519 out, const fe25519 z);
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
ge means group element.
|
|
18
|
+
|
|
19
|
+
Here the group is the set of pairs (x,y) of field elements
|
|
20
|
+
satisfying -x^2 + y^2 = 1 + d x^2y^2
|
|
21
|
+
where d = -121665/121666.
|
|
22
|
+
|
|
23
|
+
Representations:
|
|
24
|
+
ge25519_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
|
|
25
|
+
ge25519_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
|
|
26
|
+
ge25519_p1p1_1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
|
|
27
|
+
ge25519_precomp (Duif): (y+x,y-x,2dxy)
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
typedef struct {
|
|
31
|
+
fe25519 X;
|
|
32
|
+
fe25519 Y;
|
|
33
|
+
fe25519 Z;
|
|
34
|
+
} ge25519_p2;
|
|
35
|
+
|
|
36
|
+
typedef struct {
|
|
37
|
+
fe25519 X;
|
|
38
|
+
fe25519 Y;
|
|
39
|
+
fe25519 Z;
|
|
40
|
+
fe25519 T;
|
|
41
|
+
} ge25519_p3;
|
|
42
|
+
|
|
43
|
+
typedef struct {
|
|
44
|
+
fe25519 X;
|
|
45
|
+
fe25519 Y;
|
|
46
|
+
fe25519 Z;
|
|
47
|
+
fe25519 T;
|
|
48
|
+
} ge25519_p1p1_1;
|
|
49
|
+
|
|
50
|
+
typedef struct {
|
|
51
|
+
fe25519 yplusx;
|
|
52
|
+
fe25519 yminusx;
|
|
53
|
+
fe25519 xy2d;
|
|
54
|
+
} ge25519_precomp;
|
|
55
|
+
|
|
56
|
+
typedef struct {
|
|
57
|
+
fe25519 YplusX;
|
|
58
|
+
fe25519 YminusX;
|
|
59
|
+
fe25519 Z;
|
|
60
|
+
fe25519 T2d;
|
|
61
|
+
} ge25519_cached;
|
|
62
|
+
|
|
63
|
+
void ge25519_tobytes(unsigned char *s, const ge25519_p2 *h);
|
|
64
|
+
|
|
65
|
+
void ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h);
|
|
66
|
+
|
|
67
|
+
int ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s);
|
|
68
|
+
|
|
69
|
+
void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p);
|
|
70
|
+
|
|
71
|
+
void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1_1 *p);
|
|
72
|
+
|
|
73
|
+
void ge25519_add2(ge25519_p1p1_1 *r, const ge25519_p3 *p, const ge25519_cached *q);
|
|
74
|
+
|
|
75
|
+
void ge25519_sub(ge25519_p1p1_1 *r, const ge25519_p3 *p, const ge25519_cached *q);
|
|
76
|
+
|
|
77
|
+
int ge25519_is_on_main_subgroup(const ge25519_p3 *p);
|
|
78
|
+
|
|
79
|
+
int ge25519_has_small_order(const unsigned char s[32]);
|
|
80
|
+
|
|
81
|
+
#ifdef __cplusplus
|
|
82
|
+
} /* extern "C" */
|
|
83
|
+
#endif
|
|
84
|
+
|
|
85
|
+
#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#ifndef __ED25519_REF10_FE_25_H__
|
|
2
|
+
#define __ED25519_REF10_FE_25_H__
|
|
3
|
+
|
|
4
|
+
#include <string.h>
|
|
5
|
+
|
|
6
|
+
#include "ed25519_ref10.h"
|
|
7
|
+
#include "fe_25_5/fe.h"
|
|
8
|
+
|
|
9
|
+
#ifdef __cplusplus
|
|
10
|
+
extern "C" {
|
|
11
|
+
#endif
|
|
12
|
+
|
|
13
|
+
void fe25519_0(fe25519 h);
|
|
14
|
+
|
|
15
|
+
void fe25519_1(fe25519 h);
|
|
16
|
+
|
|
17
|
+
void fe25519_add(fe25519 h, const fe25519 f, const fe25519 g);
|
|
18
|
+
|
|
19
|
+
void fe25519_sub(fe25519 h, const fe25519 f, const fe25519 g);
|
|
20
|
+
|
|
21
|
+
void fe25519_neg(fe25519 h, const fe25519 f);
|
|
22
|
+
|
|
23
|
+
void fe25519_cmov(fe25519 f, const fe25519 g, unsigned int b);
|
|
24
|
+
|
|
25
|
+
void fe25519_copy(fe25519 h, const fe25519 f);
|
|
26
|
+
|
|
27
|
+
int fe25519_isnegative(const fe25519 f);
|
|
28
|
+
|
|
29
|
+
int sodium_is_zero(const unsigned char *n, const size_t nlen);
|
|
30
|
+
|
|
31
|
+
int fe25519_iszero(const fe25519 f);
|
|
32
|
+
|
|
33
|
+
void fe25519_mul(fe25519 h, const fe25519 f, const fe25519 g);
|
|
34
|
+
|
|
35
|
+
void fe25519_sq(fe25519 h, const fe25519 f);
|
|
36
|
+
|
|
37
|
+
void fe25519_sq2(fe25519 h, const fe25519 f);
|
|
38
|
+
|
|
39
|
+
#ifdef __cplusplus
|
|
40
|
+
} /* extern "C" */
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
#endif
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#ifndef __CONSTANTS_H__
|
|
2
|
+
#define __CONSTANTS_H__
|
|
3
|
+
|
|
4
|
+
#ifdef __cplusplus
|
|
5
|
+
extern "C" {
|
|
6
|
+
#endif
|
|
7
|
+
|
|
8
|
+
/* 37095705934669439343138083508754565189542113879843219016388785533085940283555 */
|
|
9
|
+
static const fe25519 d = {-10913610, 13857413, -15372611, 6949391, 114729,
|
|
10
|
+
-8787816, -6275908, -3247719, -18696448, -12055116};
|
|
11
|
+
|
|
12
|
+
/* 2 * d =
|
|
13
|
+
* 16295367250680780974490674513165176452449235426866156013048779062215315747161
|
|
14
|
+
*/
|
|
15
|
+
static const fe25519 d2 = {-21827239, -5839606, -30745221, 13898782, 229458,
|
|
16
|
+
15978800, -12551817, -6495438, 29715968, 9444199};
|
|
17
|
+
|
|
18
|
+
/* sqrt(-1) */
|
|
19
|
+
static const fe25519 sqrtm1 = {-32595792, -7943725, 9377950, 3500415, 12389472,
|
|
20
|
+
-272473, -25146209, -2005654, 326686, 11406482};
|
|
21
|
+
|
|
22
|
+
/* A = 486662 */
|
|
23
|
+
static const fe25519 curve25519_A = {486662, 0, 0, 0, 0, 0, 0, 0, 0, 0};
|
|
24
|
+
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
} /* extern "C" */
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
#endif
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#ifndef __FE_H__
|
|
2
|
+
#define __FE_H__
|
|
3
|
+
|
|
4
|
+
#include <stdint.h>
|
|
5
|
+
|
|
6
|
+
#ifdef __cplusplus
|
|
7
|
+
extern "C" {
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
/*
|
|
11
|
+
fe means field element.
|
|
12
|
+
Here the field is \Z/(2^255-19).
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
typedef int32_t fe25519[10];
|
|
16
|
+
|
|
17
|
+
void fe25519_frombytes(fe25519 h, const unsigned char *s);
|
|
18
|
+
|
|
19
|
+
void fe25519_tobytes(unsigned char *s, const fe25519 h);
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
} /* extern "C" */
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
#endif
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016 Daira Hopwood
|
|
3
|
+
* Copyright (c) 2016 Pavol Rusnak
|
|
4
|
+
*
|
|
5
|
+
* Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
* a copy of this software and associated documentation files (the "Software"),
|
|
7
|
+
* to deal in the Software without restriction, including without limitation
|
|
8
|
+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
9
|
+
* and/or sell copies of the Software, and to permit persons to whom the
|
|
10
|
+
* Software is furnished to do so, subject to the following conditions:
|
|
11
|
+
*
|
|
12
|
+
* The above copyright notice and this permission notice shall be included
|
|
13
|
+
* in all copies or substantial portions of the Software.
|
|
14
|
+
*
|
|
15
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
16
|
+
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
18
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
|
|
19
|
+
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
20
|
+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
21
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
#include <TrezorCrypto/address.h>
|
|
25
|
+
#include <TrezorCrypto/bignum.h>
|
|
26
|
+
|
|
27
|
+
size_t address_prefix_bytes_len(uint32_t address_type)
|
|
28
|
+
{
|
|
29
|
+
if (address_type <= 0xFF) return 1;
|
|
30
|
+
if (address_type <= 0xFFFF) return 2;
|
|
31
|
+
if (address_type <= 0xFFFFFF) return 3;
|
|
32
|
+
return 4;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
void address_write_prefix_bytes(uint32_t address_type, uint8_t *out)
|
|
36
|
+
{
|
|
37
|
+
if (address_type > 0xFFFFFF) *(out++) = address_type >> 24;
|
|
38
|
+
if (address_type > 0xFFFF) *(out++) = (address_type >> 16) & 0xFF;
|
|
39
|
+
if (address_type > 0xFF) *(out++) = (address_type >> 8) & 0xFF;
|
|
40
|
+
*(out++) = address_type & 0xFF;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
bool address_check_prefix(const uint8_t *addr, uint32_t address_type)
|
|
44
|
+
{
|
|
45
|
+
if (address_type <= 0xFF) {
|
|
46
|
+
return address_type == (uint32_t)(addr[0]);
|
|
47
|
+
}
|
|
48
|
+
if (address_type <= 0xFFFF) {
|
|
49
|
+
return address_type == (((uint32_t) addr[0] << 8) | ((uint32_t) addr[1]));
|
|
50
|
+
}
|
|
51
|
+
if (address_type <= 0xFFFFFF) {
|
|
52
|
+
return address_type == (((uint32_t) addr[0] << 16) | ((uint32_t) addr[1] << 8) | ((uint32_t) addr[2]));
|
|
53
|
+
}
|
|
54
|
+
return address_type == (((uint32_t) addr[0] << 24) | ((uint32_t) addr[1] << 16) | ((uint32_t) addr[2] << 8) | ((uint32_t) addr[3]));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#include <TrezorCrypto/sha3.h>
|
|
58
|
+
|
|
59
|
+
void ethereum_address_checksum(const uint8_t *addr, char *address, bool rskip60, uint32_t chain_id)
|
|
60
|
+
{
|
|
61
|
+
const char *hex = "0123456789abcdef";
|
|
62
|
+
for (int i = 0; i < 20; i++) {
|
|
63
|
+
address[i * 2] = hex[(addr[i] >> 4) & 0xF];
|
|
64
|
+
address[i * 2 + 1] = hex[addr[i] & 0xF];
|
|
65
|
+
}
|
|
66
|
+
address[40] = 0;
|
|
67
|
+
|
|
68
|
+
SHA3_CTX ctx;
|
|
69
|
+
uint8_t hash[32];
|
|
70
|
+
keccak_256_Init(&ctx);
|
|
71
|
+
if (rskip60) {
|
|
72
|
+
char prefix[16];
|
|
73
|
+
int prefix_size = bn_format_uint64(chain_id, NULL, "0x", 0, 0, false, prefix, sizeof(prefix));
|
|
74
|
+
keccak_Update(&ctx, (const uint8_t *)prefix, prefix_size);
|
|
75
|
+
}
|
|
76
|
+
keccak_Update(&ctx, (const uint8_t *)address, 40);
|
|
77
|
+
keccak_Final(&ctx, hash);
|
|
78
|
+
|
|
79
|
+
for (int i = 0; i < 20; i++) {
|
|
80
|
+
if (hash[i] & 0x80 && address[i * 2 ] >= 'a' && address[i * 2 ] <= 'f') {
|
|
81
|
+
address[i * 2] -= 0x20;
|
|
82
|
+
}
|
|
83
|
+
if (hash[i] & 0x08 && address[i * 2 + 1] >= 'a' && address[i * 2 + 1] <= 'f') {
|
|
84
|
+
address[i * 2 + 1] -= 0x20;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|