@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.
Files changed (223) hide show
  1. package/README.md +9 -1
  2. package/ReactNativeLiteCard.podspec +25 -2
  3. package/android/build.gradle +7 -0
  4. package/android/src/main/cpp/CMakeLists.txt +6 -2
  5. package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
  6. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/entitys/SendResponse.kt +6 -3
  7. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +5 -1
  8. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +21 -7
  9. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
  10. package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +4 -1
  11. package/ios/Classes/OKNFCBridge.mm +1 -1
  12. package/ios/Classes/OKNFTLite/OKLiteV1.m +6 -3
  13. package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
  14. package/package.json +2 -2
  15. package/sdk/CMakeLists.txt +120 -0
  16. package/sdk/README.md +175 -0
  17. package/sdk/android/implJni.cpp +177 -0
  18. package/sdk/deps/jsoncpp/LICENSE +55 -0
  19. package/sdk/deps/jsoncpp/include/CMakeLists.txt +2 -0
  20. package/sdk/deps/jsoncpp/include/json/allocator.h +98 -0
  21. package/sdk/deps/jsoncpp/include/json/assertions.h +54 -0
  22. package/sdk/deps/jsoncpp/include/json/autolink.h +25 -0
  23. package/sdk/deps/jsoncpp/include/json/config.h +187 -0
  24. package/sdk/deps/jsoncpp/include/json/features.h +61 -0
  25. package/sdk/deps/jsoncpp/include/json/forwards.h +37 -0
  26. package/sdk/deps/jsoncpp/include/json/json.h +15 -0
  27. package/sdk/deps/jsoncpp/include/json/reader.h +411 -0
  28. package/sdk/deps/jsoncpp/include/json/value.h +888 -0
  29. package/sdk/deps/jsoncpp/include/json/version.h +20 -0
  30. package/sdk/deps/jsoncpp/include/json/writer.h +357 -0
  31. package/sdk/deps/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
  32. package/sdk/deps/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
  33. package/sdk/deps/jsoncpp/src/lib_json/json_tool.h +114 -0
  34. package/sdk/deps/jsoncpp/src/lib_json/json_value.cpp +1661 -0
  35. package/sdk/deps/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
  36. package/sdk/deps/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
  37. package/sdk/deps/jsoncpp/src/lib_json/version.h.in +20 -0
  38. package/sdk/deps/trezor-crypto/AUTHORS +2 -0
  39. package/sdk/deps/trezor-crypto/LICENSE +22 -0
  40. package/sdk/deps/trezor-crypto/include/TrezorCrypto/TrezorCrypto.h +29 -0
  41. package/sdk/deps/trezor-crypto/include/TrezorCrypto/address.h +44 -0
  42. package/sdk/deps/trezor-crypto/include/TrezorCrypto/aes.h +224 -0
  43. package/sdk/deps/trezor-crypto/include/TrezorCrypto/base32.h +49 -0
  44. package/sdk/deps/trezor-crypto/include/TrezorCrypto/base58.h +58 -0
  45. package/sdk/deps/trezor-crypto/include/TrezorCrypto/bignum.h +169 -0
  46. package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip32.h +114 -0
  47. package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip39.h +66 -0
  48. package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake256.h +61 -0
  49. package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2b.h +50 -0
  50. package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2s.h +49 -0
  51. package/sdk/deps/trezor-crypto/include/TrezorCrypto/cash_addr.h +109 -0
  52. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-config.h +316 -0
  53. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-sync.h +289 -0
  54. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-types.h +53 -0
  55. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/poly1305-donna.h +28 -0
  56. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305.h +27 -0
  57. package/sdk/deps/trezor-crypto/include/TrezorCrypto/cmac.h +44 -0
  58. package/sdk/deps/trezor-crypto/include/TrezorCrypto/curves.h +60 -0
  59. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ecdsa.h +112 -0
  60. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-32bit.h +87 -0
  61. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-helpers.h +30 -0
  62. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-blake2b.h +21 -0
  63. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-32bit-tables.h +25 -0
  64. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-basepoint-table.h +10 -0
  65. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-impl-base.h +110 -0
  66. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-portable.h +32 -0
  67. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna.h +60 -0
  68. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-keccak.h +21 -0
  69. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-sha3.h +21 -0
  70. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/modm-donna-32bit.h +87 -0
  71. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna.h +60 -0
  72. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519.h +42 -0
  73. package/sdk/deps/trezor-crypto/include/TrezorCrypto/endian.h +132 -0
  74. package/sdk/deps/trezor-crypto/include/TrezorCrypto/groestl.h +104 -0
  75. package/sdk/deps/trezor-crypto/include/TrezorCrypto/hasher.h +90 -0
  76. package/sdk/deps/trezor-crypto/include/TrezorCrypto/hmac.h +60 -0
  77. package/sdk/deps/trezor-crypto/include/TrezorCrypto/memzero.h +16 -0
  78. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/base58.h +42 -0
  79. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/monero.h +13 -0
  80. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/range_proof.h +30 -0
  81. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/serialize.h +15 -0
  82. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/xmr.h +67 -0
  83. package/sdk/deps/trezor-crypto/include/TrezorCrypto/nano.h +56 -0
  84. package/sdk/deps/trezor-crypto/include/TrezorCrypto/nem.h +199 -0
  85. package/sdk/deps/trezor-crypto/include/TrezorCrypto/nist256p1.h +35 -0
  86. package/sdk/deps/trezor-crypto/include/TrezorCrypto/pbkdf2.h +64 -0
  87. package/sdk/deps/trezor-crypto/include/TrezorCrypto/rand.h +44 -0
  88. package/sdk/deps/trezor-crypto/include/TrezorCrypto/rc4.h +37 -0
  89. package/sdk/deps/trezor-crypto/include/TrezorCrypto/rfc6979.h +40 -0
  90. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripemd160.h +28 -0
  91. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripple/base58.h +45 -0
  92. package/sdk/deps/trezor-crypto/include/TrezorCrypto/schnorr.h +48 -0
  93. package/sdk/deps/trezor-crypto/include/TrezorCrypto/script.h +30 -0
  94. package/sdk/deps/trezor-crypto/include/TrezorCrypto/scrypt.h +68 -0
  95. package/sdk/deps/trezor-crypto/include/TrezorCrypto/secp256k1.h +59 -0
  96. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha2.h +125 -0
  97. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha3.h +86 -0
  98. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/keypair.h +20 -0
  99. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10.h +85 -0
  100. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10_fe_25_5.h +43 -0
  101. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/constants.h +29 -0
  102. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/fe.h +25 -0
  103. package/sdk/deps/trezor-crypto/src/address.c +87 -0
  104. package/sdk/deps/trezor-crypto/src/aes/aes_modes.c +959 -0
  105. package/sdk/deps/trezor-crypto/src/aes/aescrypt.c +307 -0
  106. package/sdk/deps/trezor-crypto/src/aes/aeskey.c +560 -0
  107. package/sdk/deps/trezor-crypto/src/aes/aesopt.h +784 -0
  108. package/sdk/deps/trezor-crypto/src/aes/aestab.c +418 -0
  109. package/sdk/deps/trezor-crypto/src/aes/aestab.h +173 -0
  110. package/sdk/deps/trezor-crypto/src/base32.c +233 -0
  111. package/sdk/deps/trezor-crypto/src/base58.c +298 -0
  112. package/sdk/deps/trezor-crypto/src/bignum.c +808 -0
  113. package/sdk/deps/trezor-crypto/src/bip32.c +852 -0
  114. package/sdk/deps/trezor-crypto/src/bip39.c +266 -0
  115. package/sdk/deps/trezor-crypto/src/bip39_english.h +2074 -0
  116. package/sdk/deps/trezor-crypto/src/blake256.c +235 -0
  117. package/sdk/deps/trezor-crypto/src/blake2_common.h +39 -0
  118. package/sdk/deps/trezor-crypto/src/blake2b.c +333 -0
  119. package/sdk/deps/trezor-crypto/src/blake2s.c +318 -0
  120. package/sdk/deps/trezor-crypto/src/cash_addr.c +195 -0
  121. package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c +60 -0
  122. package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c +246 -0
  123. package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-machine.h +49 -0
  124. package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-portable.h +275 -0
  125. package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna-32.h +219 -0
  126. package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c +179 -0
  127. package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.c +48 -0
  128. package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.h +10 -0
  129. package/sdk/deps/trezor-crypto/src/check_mem.h +30 -0
  130. package/sdk/deps/trezor-crypto/src/cmac.c +342 -0
  131. package/sdk/deps/trezor-crypto/src/curves.c +48 -0
  132. package/sdk/deps/trezor-crypto/src/ecdsa.c +1355 -0
  133. package/sdk/deps/trezor-crypto/src/ed25519-donna/README.md +183 -0
  134. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c +681 -0
  135. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c +66 -0
  136. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c +67 -0
  137. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.h +8 -0
  138. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c +8 -0
  139. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c +63 -0
  140. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c +261 -0
  141. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c +722 -0
  142. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-blake2b.h +23 -0
  143. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-keccak.h +23 -0
  144. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-sha3.h +23 -0
  145. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom.h +23 -0
  146. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c +8 -0
  147. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c +8 -0
  148. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519.c +311 -0
  149. package/sdk/deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c +517 -0
  150. package/sdk/deps/trezor-crypto/src/groestl.c +783 -0
  151. package/sdk/deps/trezor-crypto/src/groestl_internal.h +419 -0
  152. package/sdk/deps/trezor-crypto/src/hasher.c +186 -0
  153. package/sdk/deps/trezor-crypto/src/hmac.c +179 -0
  154. package/sdk/deps/trezor-crypto/src/memzero.c +6 -0
  155. package/sdk/deps/trezor-crypto/src/monero/base58.c +245 -0
  156. package/sdk/deps/trezor-crypto/src/monero/int-util.h +77 -0
  157. package/sdk/deps/trezor-crypto/src/monero/range_proof.c +115 -0
  158. package/sdk/deps/trezor-crypto/src/monero/serialize.c +54 -0
  159. package/sdk/deps/trezor-crypto/src/monero/xmr.c +136 -0
  160. package/sdk/deps/trezor-crypto/src/nano.c +151 -0
  161. package/sdk/deps/trezor-crypto/src/nem.c +569 -0
  162. package/sdk/deps/trezor-crypto/src/nist256p1.c +63 -0
  163. package/sdk/deps/trezor-crypto/src/nist256p1.table +1664 -0
  164. package/sdk/deps/trezor-crypto/src/options.h +43 -0
  165. package/sdk/deps/trezor-crypto/src/pbkdf2.c +177 -0
  166. package/sdk/deps/trezor-crypto/src/rand.c +51 -0
  167. package/sdk/deps/trezor-crypto/src/rc4.c +56 -0
  168. package/sdk/deps/trezor-crypto/src/ripemd160.c +343 -0
  169. package/sdk/deps/trezor-crypto/src/ripple/base58.c +76 -0
  170. package/sdk/deps/trezor-crypto/src/schnorr.c +208 -0
  171. package/sdk/deps/trezor-crypto/src/script.c +64 -0
  172. package/sdk/deps/trezor-crypto/src/scrypt.c +343 -0
  173. package/sdk/deps/trezor-crypto/src/secp256k1.c +160 -0
  174. package/sdk/deps/trezor-crypto/src/secp256k1.table +1664 -0
  175. package/sdk/deps/trezor-crypto/src/setup.py +38 -0
  176. package/sdk/deps/trezor-crypto/src/sha2.c +1314 -0
  177. package/sdk/deps/trezor-crypto/src/sha3.c +395 -0
  178. package/sdk/deps/trezor-crypto/src/shell.nix +6 -0
  179. package/sdk/deps/trezor-crypto/src/sodium/keypair.c +63 -0
  180. package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10.c +481 -0
  181. package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c +885 -0
  182. package/sdk/deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c +237 -0
  183. package/sdk/gpc/include/scp03/scp03.hpp +80 -0
  184. package/sdk/gpc/include/scp11/scp11.hpp +492 -0
  185. package/sdk/gpc/include/scp11/scp11c.hpp +58 -0
  186. package/sdk/gpc/include/tag.h +68 -0
  187. package/sdk/gpc/include/tlv.hpp +94 -0
  188. package/sdk/gpc/include/tlvparse.hpp +24 -0
  189. package/sdk/gpc/src/scp03.cpp +243 -0
  190. package/sdk/gpc/src/scp11.cpp +798 -0
  191. package/sdk/gpc/src/scp11c.cpp +136 -0
  192. package/sdk/gpc/src/tlv.cpp +159 -0
  193. package/sdk/gpc/src/tlvparse.c +174 -0
  194. package/{framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers → sdk/include}/GPChannelSDK.h +0 -0
  195. package/sdk/include/GPChannelSDKCore.h +10 -0
  196. package/sdk/include/context/BaseContext.h +56 -0
  197. package/sdk/include/device/ApduBuilder.hpp +72 -0
  198. package/sdk/include/mSIGNA/stdutils/uchar_vector.h +36 -0
  199. package/sdk/include/utility/Apdu.hpp +172 -0
  200. package/sdk/include/utility/Debug.hpp +3 -0
  201. package/sdk/include/utility/util.h +104 -0
  202. package/sdk/src/ApduBuilder.cpp +332 -0
  203. package/sdk/src/GPChannelSDK.cpp +252 -0
  204. package/sdk/src/random.c +25 -0
  205. package/sdk/src/version.c +2 -0
  206. package/sdk/tests/android/GPChannelProxy.java +55 -0
  207. package/sdk/tests/android_verify.py +121 -0
  208. package/sdk/tests/safety.cpp +603 -0
  209. package/sdk/tests/verify.py +267 -0
  210. package/android/src/main/jniLibs/arm64-v8a/libgpchannelNDK.so +0 -0
  211. package/android/src/main/jniLibs/armeabi-v7a/libgpchannelNDK.so +0 -0
  212. package/framework/GPChannelSDKCore.xcframework/Info.plist +0 -52
  213. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
  214. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
  215. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Info.plist +0 -0
  216. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
  217. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
  218. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
  219. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDK.h +0 -315
  220. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
  221. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Info.plist +0 -0
  222. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
  223. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
@@ -0,0 +1,395 @@
1
+ /* sha3.c - 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
+ #include <assert.h>
21
+ #include <string.h>
22
+
23
+ #include <TrezorCrypto/sha3.h>
24
+ #include <TrezorCrypto/memzero.h>
25
+
26
+ #define I64(x) x##LL
27
+ #define ROTL64(qword, n) ((qword) << (n) ^ ((qword) >> (64 - (n))))
28
+ #define le2me_64(x) (x)
29
+ #define IS_ALIGNED_64(p) (0 == (7 & ((const char*)(p) - (const char*)0)))
30
+ # define me64_to_le_str(to, from, length) memcpy((to), (from), (length))
31
+
32
+ /* constants */
33
+ #define NumberOfRounds 24
34
+
35
+ /* SHA3 (Keccak) constants for 24 rounds */
36
+ static uint64_t keccak_round_constants[NumberOfRounds] = {
37
+ I64(0x0000000000000001), I64(0x0000000000008082), I64(0x800000000000808A), I64(0x8000000080008000),
38
+ I64(0x000000000000808B), I64(0x0000000080000001), I64(0x8000000080008081), I64(0x8000000000008009),
39
+ I64(0x000000000000008A), I64(0x0000000000000088), I64(0x0000000080008009), I64(0x000000008000000A),
40
+ I64(0x000000008000808B), I64(0x800000000000008B), I64(0x8000000000008089), I64(0x8000000000008003),
41
+ I64(0x8000000000008002), I64(0x8000000000000080), I64(0x000000000000800A), I64(0x800000008000000A),
42
+ I64(0x8000000080008081), I64(0x8000000000008080), I64(0x0000000080000001), I64(0x8000000080008008)
43
+ };
44
+
45
+ /* Initializing a sha3 context for given number of output bits */
46
+ static void keccak_Init(SHA3_CTX *ctx, unsigned bits)
47
+ {
48
+ /* NB: The Keccak capacity parameter = bits * 2 */
49
+ unsigned rate = 1600 - bits * 2;
50
+
51
+ memset(ctx, 0, sizeof(SHA3_CTX));
52
+ ctx->block_size = rate / 8;
53
+ assert(rate <= 1600 && (rate % 64) == 0);
54
+ }
55
+
56
+ /**
57
+ * Initialize context before calculating hash.
58
+ *
59
+ * @param ctx context to initialize
60
+ */
61
+ void sha3_224_Init(SHA3_CTX *ctx)
62
+ {
63
+ keccak_Init(ctx, 224);
64
+ }
65
+
66
+ /**
67
+ * Initialize context before calculating hash.
68
+ *
69
+ * @param ctx context to initialize
70
+ */
71
+ void sha3_256_Init(SHA3_CTX *ctx)
72
+ {
73
+ keccak_Init(ctx, 256);
74
+ }
75
+
76
+ /**
77
+ * Initialize context before calculating hash.
78
+ *
79
+ * @param ctx context to initialize
80
+ */
81
+ void sha3_384_Init(SHA3_CTX *ctx)
82
+ {
83
+ keccak_Init(ctx, 384);
84
+ }
85
+
86
+ /**
87
+ * Initialize context before calculating hash.
88
+ *
89
+ * @param ctx context to initialize
90
+ */
91
+ void sha3_512_Init(SHA3_CTX *ctx)
92
+ {
93
+ keccak_Init(ctx, 512);
94
+ }
95
+
96
+ /* Keccak theta() transformation */
97
+ static void keccak_theta(uint64_t *A)
98
+ {
99
+ unsigned int x;
100
+ uint64_t C[5], D[5];
101
+
102
+ for (x = 0; x < 5; x++) {
103
+ C[x] = A[x] ^ A[x + 5] ^ A[x + 10] ^ A[x + 15] ^ A[x + 20];
104
+ }
105
+ D[0] = ROTL64(C[1], 1) ^ C[4];
106
+ D[1] = ROTL64(C[2], 1) ^ C[0];
107
+ D[2] = ROTL64(C[3], 1) ^ C[1];
108
+ D[3] = ROTL64(C[4], 1) ^ C[2];
109
+ D[4] = ROTL64(C[0], 1) ^ C[3];
110
+
111
+ for (x = 0; x < 5; x++) {
112
+ A[x] ^= D[x];
113
+ A[x + 5] ^= D[x];
114
+ A[x + 10] ^= D[x];
115
+ A[x + 15] ^= D[x];
116
+ A[x + 20] ^= D[x];
117
+ }
118
+ }
119
+
120
+ /* Keccak pi() transformation */
121
+ static void keccak_pi(uint64_t *A)
122
+ {
123
+ uint64_t A1;
124
+ A1 = A[1];
125
+ A[ 1] = A[ 6];
126
+ A[ 6] = A[ 9];
127
+ A[ 9] = A[22];
128
+ A[22] = A[14];
129
+ A[14] = A[20];
130
+ A[20] = A[ 2];
131
+ A[ 2] = A[12];
132
+ A[12] = A[13];
133
+ A[13] = A[19];
134
+ A[19] = A[23];
135
+ A[23] = A[15];
136
+ A[15] = A[ 4];
137
+ A[ 4] = A[24];
138
+ A[24] = A[21];
139
+ A[21] = A[ 8];
140
+ A[ 8] = A[16];
141
+ A[16] = A[ 5];
142
+ A[ 5] = A[ 3];
143
+ A[ 3] = A[18];
144
+ A[18] = A[17];
145
+ A[17] = A[11];
146
+ A[11] = A[ 7];
147
+ A[ 7] = A[10];
148
+ A[10] = A1;
149
+ /* note: A[ 0] is left as is */
150
+ }
151
+
152
+ /* Keccak chi() transformation */
153
+ static void keccak_chi(uint64_t *A)
154
+ {
155
+ int i;
156
+ for (i = 0; i < 25; i += 5) {
157
+ uint64_t A0 = A[0 + i], A1 = A[1 + i];
158
+ A[0 + i] ^= ~A1 & A[2 + i];
159
+ A[1 + i] ^= ~A[2 + i] & A[3 + i];
160
+ A[2 + i] ^= ~A[3 + i] & A[4 + i];
161
+ A[3 + i] ^= ~A[4 + i] & A0;
162
+ A[4 + i] ^= ~A0 & A1;
163
+ }
164
+ }
165
+
166
+ static void sha3_permutation(uint64_t *state)
167
+ {
168
+ int round;
169
+ for (round = 0; round < NumberOfRounds; round++)
170
+ {
171
+ keccak_theta(state);
172
+
173
+ /* apply Keccak rho() transformation */
174
+ state[ 1] = ROTL64(state[ 1], 1);
175
+ state[ 2] = ROTL64(state[ 2], 62);
176
+ state[ 3] = ROTL64(state[ 3], 28);
177
+ state[ 4] = ROTL64(state[ 4], 27);
178
+ state[ 5] = ROTL64(state[ 5], 36);
179
+ state[ 6] = ROTL64(state[ 6], 44);
180
+ state[ 7] = ROTL64(state[ 7], 6);
181
+ state[ 8] = ROTL64(state[ 8], 55);
182
+ state[ 9] = ROTL64(state[ 9], 20);
183
+ state[10] = ROTL64(state[10], 3);
184
+ state[11] = ROTL64(state[11], 10);
185
+ state[12] = ROTL64(state[12], 43);
186
+ state[13] = ROTL64(state[13], 25);
187
+ state[14] = ROTL64(state[14], 39);
188
+ state[15] = ROTL64(state[15], 41);
189
+ state[16] = ROTL64(state[16], 45);
190
+ state[17] = ROTL64(state[17], 15);
191
+ state[18] = ROTL64(state[18], 21);
192
+ state[19] = ROTL64(state[19], 8);
193
+ state[20] = ROTL64(state[20], 18);
194
+ state[21] = ROTL64(state[21], 2);
195
+ state[22] = ROTL64(state[22], 61);
196
+ state[23] = ROTL64(state[23], 56);
197
+ state[24] = ROTL64(state[24], 14);
198
+
199
+ keccak_pi(state);
200
+ keccak_chi(state);
201
+
202
+ /* apply iota(state, round) */
203
+ *state ^= keccak_round_constants[round];
204
+ }
205
+ }
206
+
207
+ /**
208
+ * The core transformation. Process the specified block of data.
209
+ *
210
+ * @param hash the algorithm state
211
+ * @param block the message block to process
212
+ * @param block_size the size of the processed block in bytes
213
+ */
214
+ static void sha3_process_block(uint64_t hash[25], const uint64_t *block, size_t block_size)
215
+ {
216
+ /* expanded loop */
217
+ hash[ 0] ^= le2me_64(block[ 0]);
218
+ hash[ 1] ^= le2me_64(block[ 1]);
219
+ hash[ 2] ^= le2me_64(block[ 2]);
220
+ hash[ 3] ^= le2me_64(block[ 3]);
221
+ hash[ 4] ^= le2me_64(block[ 4]);
222
+ hash[ 5] ^= le2me_64(block[ 5]);
223
+ hash[ 6] ^= le2me_64(block[ 6]);
224
+ hash[ 7] ^= le2me_64(block[ 7]);
225
+ hash[ 8] ^= le2me_64(block[ 8]);
226
+ /* if not sha3-512 */
227
+ if (block_size > 72) {
228
+ hash[ 9] ^= le2me_64(block[ 9]);
229
+ hash[10] ^= le2me_64(block[10]);
230
+ hash[11] ^= le2me_64(block[11]);
231
+ hash[12] ^= le2me_64(block[12]);
232
+ /* if not sha3-384 */
233
+ if (block_size > 104) {
234
+ hash[13] ^= le2me_64(block[13]);
235
+ hash[14] ^= le2me_64(block[14]);
236
+ hash[15] ^= le2me_64(block[15]);
237
+ hash[16] ^= le2me_64(block[16]);
238
+ /* if not sha3-256 */
239
+ if (block_size > 136) {
240
+ hash[17] ^= le2me_64(block[17]);
241
+ #ifdef FULL_SHA3_FAMILY_SUPPORT
242
+ /* if not sha3-224 */
243
+ if (block_size > 144) {
244
+ hash[18] ^= le2me_64(block[18]);
245
+ hash[19] ^= le2me_64(block[19]);
246
+ hash[20] ^= le2me_64(block[20]);
247
+ hash[21] ^= le2me_64(block[21]);
248
+ hash[22] ^= le2me_64(block[22]);
249
+ hash[23] ^= le2me_64(block[23]);
250
+ hash[24] ^= le2me_64(block[24]);
251
+ }
252
+ #endif
253
+ }
254
+ }
255
+ }
256
+ /* make a permutation of the hash */
257
+ sha3_permutation(hash);
258
+ }
259
+
260
+ #define SHA3_FINALIZED 0x80000000
261
+
262
+ /**
263
+ * Calculate message hash.
264
+ * Can be called repeatedly with chunks of the message to be hashed.
265
+ *
266
+ * @param ctx the algorithm context containing current hashing state
267
+ * @param msg message chunk
268
+ * @param size length of the message chunk
269
+ */
270
+ void sha3_Update(SHA3_CTX *ctx, const unsigned char *msg, size_t size)
271
+ {
272
+ size_t idx = (size_t)ctx->rest;
273
+ size_t block_size = (size_t)ctx->block_size;
274
+
275
+ if (ctx->rest & SHA3_FINALIZED) return; /* too late for additional input */
276
+ ctx->rest = (unsigned)((ctx->rest + size) % block_size);
277
+
278
+ /* fill partial block */
279
+ if (idx) {
280
+ size_t left = block_size - idx;
281
+ memcpy((char*)ctx->message + idx, msg, (size < left ? size : left));
282
+ if (size < left) return;
283
+
284
+ /* process partial block */
285
+ sha3_process_block(ctx->hash, ctx->message, block_size);
286
+ msg += left;
287
+ size -= left;
288
+ }
289
+ while (size >= block_size) {
290
+ uint64_t* aligned_message_block;
291
+ if (IS_ALIGNED_64(msg)) {
292
+ /* the most common case is processing of an already aligned message
293
+ without copying it */
294
+ aligned_message_block = (uint64_t*)(void*)msg;
295
+ } else {
296
+ memcpy(ctx->message, msg, block_size);
297
+ aligned_message_block = ctx->message;
298
+ }
299
+
300
+ sha3_process_block(ctx->hash, aligned_message_block, block_size);
301
+ msg += block_size;
302
+ size -= block_size;
303
+ }
304
+ if (size) {
305
+ memcpy(ctx->message, msg, size); /* save leftovers */
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Store calculated hash into the given array.
311
+ *
312
+ * @param ctx the algorithm context containing current hashing state
313
+ * @param result calculated hash in binary form
314
+ */
315
+ void sha3_Final(SHA3_CTX *ctx, unsigned char* result)
316
+ {
317
+ size_t digest_length = 100 - ctx->block_size / 2;
318
+ const size_t block_size = ctx->block_size;
319
+
320
+ if (!(ctx->rest & SHA3_FINALIZED))
321
+ {
322
+ /* clear the rest of the data queue */
323
+ memset((char*)ctx->message + ctx->rest, 0, block_size - ctx->rest);
324
+ ((char*)ctx->message)[ctx->rest] |= 0x06;
325
+ ((char*)ctx->message)[block_size - 1] |= 0x80;
326
+
327
+ /* process final block */
328
+ sha3_process_block(ctx->hash, ctx->message, block_size);
329
+ ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
330
+ }
331
+
332
+ assert(block_size > digest_length);
333
+ if (result) me64_to_le_str(result, ctx->hash, digest_length);
334
+ memzero(ctx, sizeof(SHA3_CTX));
335
+ }
336
+
337
+ /**
338
+ * Store calculated hash into the given array.
339
+ *
340
+ * @param ctx the algorithm context containing current hashing state
341
+ * @param result calculated hash in binary form
342
+ */
343
+ void keccak_Final(SHA3_CTX *ctx, unsigned char* result)
344
+ {
345
+ size_t digest_length = 100 - ctx->block_size / 2;
346
+ const size_t block_size = ctx->block_size;
347
+
348
+ if (!(ctx->rest & SHA3_FINALIZED))
349
+ {
350
+ /* clear the rest of the data queue */
351
+ memset((char*)ctx->message + ctx->rest, 0, block_size - ctx->rest);
352
+ ((char*)ctx->message)[ctx->rest] |= 0x01;
353
+ ((char*)ctx->message)[block_size - 1] |= 0x80;
354
+
355
+ /* process final block */
356
+ sha3_process_block(ctx->hash, ctx->message, block_size);
357
+ ctx->rest = SHA3_FINALIZED; /* mark context as finalized */
358
+ }
359
+
360
+ assert(block_size > digest_length);
361
+ if (result) me64_to_le_str(result, ctx->hash, digest_length);
362
+ memzero(ctx, sizeof(SHA3_CTX));
363
+ }
364
+
365
+ void keccak_256(const unsigned char* data, size_t len, unsigned char* digest)
366
+ {
367
+ SHA3_CTX ctx;
368
+ keccak_256_Init(&ctx);
369
+ keccak_Update(&ctx, data, len);
370
+ keccak_Final(&ctx, digest);
371
+ }
372
+
373
+ void keccak_512(const unsigned char* data, size_t len, unsigned char* digest)
374
+ {
375
+ SHA3_CTX ctx;
376
+ keccak_512_Init(&ctx);
377
+ keccak_Update(&ctx, data, len);
378
+ keccak_Final(&ctx, digest);
379
+ }
380
+
381
+ void sha3_256(const unsigned char* data, size_t len, unsigned char* digest)
382
+ {
383
+ SHA3_CTX ctx;
384
+ sha3_256_Init(&ctx);
385
+ sha3_Update(&ctx, data, len);
386
+ sha3_Final(&ctx, digest);
387
+ }
388
+
389
+ void sha3_512(const unsigned char* data, size_t len, unsigned char* digest)
390
+ {
391
+ SHA3_CTX ctx;
392
+ sha3_512_Init(&ctx);
393
+ sha3_Update(&ctx, data, len);
394
+ sha3_Final(&ctx, digest);
395
+ }
@@ -0,0 +1,6 @@
1
+ with import <nixpkgs> {};
2
+
3
+ stdenv.mkDerivation {
4
+ name = "trezor-crypto-dev";
5
+ buildInputs = [ gnumake gcc pkgconfig openssl check ];
6
+ }
@@ -0,0 +1,63 @@
1
+ #include <string.h>
2
+
3
+ #include <TrezorCrypto/sodium/keypair.h>
4
+
5
+ /* Perform a fixed-base multiplication of the Edwards base point,
6
+ (which is efficient due to precalculated tables), then convert
7
+ to the Curve25519 montgomery-format public key. In particular,
8
+ convert Curve25519's "montgomery" x-coordinate into an Ed25519
9
+ "edwards" y-coordinate:
10
+
11
+ mont_x = (ed_y + 1) / (1 - ed_y)
12
+
13
+ with projective coordinates:
14
+
15
+ mont_x = (ed_y + ed_z) / (ed_z - ed_y)
16
+
17
+ NOTE: ed_y=1 is converted to mont_x=0 since fe_invert is mod-exp
18
+ */
19
+ int ed25519_pk_to_curve25519(unsigned char *curve25519_pk, const unsigned char *ed25519_pk) {
20
+ ge25519_p3 A;
21
+ fe25519 x;
22
+ fe25519 one_minus_y;
23
+
24
+ if (ge25519_has_small_order(ed25519_pk) != 0 ||
25
+ ge25519_frombytes_negate_vartime(&A, ed25519_pk) != 0 ||
26
+ ge25519_is_on_main_subgroup(&A) == 0) {
27
+ return -1;
28
+ }
29
+ fe25519_1(one_minus_y);
30
+ fe25519_sub(one_minus_y, one_minus_y, A.Y);
31
+ fe25519_invert(one_minus_y, one_minus_y);
32
+ fe25519_1(x);
33
+ fe25519_add(x, x, A.Y);
34
+ fe25519_mul(x, x, one_minus_y);
35
+ fe25519_tobytes(curve25519_pk, x);
36
+
37
+ return 0;
38
+ }
39
+
40
+ /* Convert the Curve25519 public key into an Ed25519 public key. In
41
+ particular, convert Curve25519's "montgomery" x-coordinate into an
42
+ Ed25519 "edwards" y-coordinate:
43
+
44
+ ed_y = (mont_x - 1) / (mont_x + 1)
45
+
46
+ NOTE: mont_x=-1 is converted to ed_y=0 since fe_invert is mod-exp
47
+ */
48
+ int curve25519_pk_to_ed25519(unsigned char *ed25519_pk, const unsigned char *curve25519_pk) {
49
+ fe25519 x;
50
+ fe25519 tmp;
51
+ fe25519 one_minus_y;
52
+
53
+ fe25519_frombytes(x, curve25519_pk);
54
+ fe25519_1(one_minus_y);
55
+ fe25519_add(one_minus_y, x, one_minus_y);
56
+ fe25519_invert(one_minus_y, one_minus_y);
57
+ fe25519_1(tmp);
58
+ fe25519_sub(x, x, tmp);
59
+ fe25519_mul(x, x, one_minus_y);
60
+ fe25519_tobytes(ed25519_pk, x);
61
+
62
+ return 0;
63
+ }