@onekeyfe/react-native-lite-card 6.7.0-4 → 6.7.0-41

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 (237) hide show
  1. package/README.md +12 -2
  2. package/ReactNativeLiteCard.podspec +31 -2
  3. package/android/build.gradle +8 -0
  4. package/android/consumer-rules.pro +4 -0
  5. package/android/src/main/cpp/CMakeLists.txt +6 -2
  6. package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +60 -49
  7. package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
  8. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +117 -39
  9. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/entitys/SendResponse.kt +6 -3
  10. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +24 -2
  11. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +46 -19
  12. package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
  13. package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +38 -1
  14. package/ios/Classes/OKNFCBridge.mm +24 -1
  15. package/ios/Classes/OKNFTLite/OKLiteV1.m +20 -10
  16. package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
  17. package/ios/Classes/OKNFTLite/OKNFCManager.h +2 -2
  18. package/ios/Classes/OKNFTLite/OKNFCManager.m +110 -18
  19. package/ios/ReactNativeLiteCard.mm +23 -11
  20. package/lib/module/index.js +4 -4
  21. package/lib/typescript/src/NativeReactNativeLiteCard.d.ts +4 -4
  22. package/lib/typescript/src/index.d.ts +2 -2
  23. package/package.json +8 -8
  24. package/sdk/CMakeLists.txt +121 -0
  25. package/sdk/README.md +190 -0
  26. package/sdk/android/implJni.cpp +216 -0
  27. package/sdk/deps/jsoncpp/LICENSE +55 -0
  28. package/sdk/deps/jsoncpp/include/CMakeLists.txt +2 -0
  29. package/sdk/deps/jsoncpp/include/json/allocator.h +98 -0
  30. package/sdk/deps/jsoncpp/include/json/assertions.h +54 -0
  31. package/sdk/deps/jsoncpp/include/json/autolink.h +25 -0
  32. package/sdk/deps/jsoncpp/include/json/config.h +187 -0
  33. package/sdk/deps/jsoncpp/include/json/features.h +61 -0
  34. package/sdk/deps/jsoncpp/include/json/forwards.h +37 -0
  35. package/sdk/deps/jsoncpp/include/json/json.h +15 -0
  36. package/sdk/deps/jsoncpp/include/json/reader.h +411 -0
  37. package/sdk/deps/jsoncpp/include/json/value.h +888 -0
  38. package/sdk/deps/jsoncpp/include/json/version.h +20 -0
  39. package/sdk/deps/jsoncpp/include/json/writer.h +357 -0
  40. package/sdk/deps/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
  41. package/sdk/deps/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
  42. package/sdk/deps/jsoncpp/src/lib_json/json_tool.h +114 -0
  43. package/sdk/deps/jsoncpp/src/lib_json/json_value.cpp +1661 -0
  44. package/sdk/deps/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
  45. package/sdk/deps/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
  46. package/sdk/deps/jsoncpp/src/lib_json/version.h.in +20 -0
  47. package/sdk/deps/trezor-crypto/AUTHORS +2 -0
  48. package/sdk/deps/trezor-crypto/LICENSE +22 -0
  49. package/sdk/deps/trezor-crypto/include/TrezorCrypto/TrezorCrypto.h +29 -0
  50. package/sdk/deps/trezor-crypto/include/TrezorCrypto/address.h +44 -0
  51. package/sdk/deps/trezor-crypto/include/TrezorCrypto/aes.h +224 -0
  52. package/sdk/deps/trezor-crypto/include/TrezorCrypto/base32.h +49 -0
  53. package/sdk/deps/trezor-crypto/include/TrezorCrypto/base58.h +58 -0
  54. package/sdk/deps/trezor-crypto/include/TrezorCrypto/bignum.h +169 -0
  55. package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip32.h +114 -0
  56. package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip39.h +66 -0
  57. package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake256.h +61 -0
  58. package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2b.h +50 -0
  59. package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2s.h +49 -0
  60. package/sdk/deps/trezor-crypto/include/TrezorCrypto/cash_addr.h +109 -0
  61. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-config.h +316 -0
  62. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-sync.h +289 -0
  63. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-types.h +53 -0
  64. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/poly1305-donna.h +28 -0
  65. package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305.h +27 -0
  66. package/sdk/deps/trezor-crypto/include/TrezorCrypto/cmac.h +44 -0
  67. package/sdk/deps/trezor-crypto/include/TrezorCrypto/curves.h +60 -0
  68. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ecdsa.h +112 -0
  69. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-32bit.h +87 -0
  70. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-helpers.h +30 -0
  71. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-blake2b.h +21 -0
  72. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-32bit-tables.h +25 -0
  73. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-basepoint-table.h +10 -0
  74. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-impl-base.h +110 -0
  75. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-portable.h +32 -0
  76. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna.h +60 -0
  77. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-keccak.h +21 -0
  78. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-sha3.h +21 -0
  79. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/modm-donna-32bit.h +87 -0
  80. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna.h +60 -0
  81. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519.h +42 -0
  82. package/sdk/deps/trezor-crypto/include/TrezorCrypto/endian.h +132 -0
  83. package/sdk/deps/trezor-crypto/include/TrezorCrypto/groestl.h +104 -0
  84. package/sdk/deps/trezor-crypto/include/TrezorCrypto/hasher.h +90 -0
  85. package/sdk/deps/trezor-crypto/include/TrezorCrypto/hmac.h +60 -0
  86. package/sdk/deps/trezor-crypto/include/TrezorCrypto/memzero.h +16 -0
  87. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/base58.h +42 -0
  88. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/monero.h +13 -0
  89. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/range_proof.h +30 -0
  90. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/serialize.h +15 -0
  91. package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/xmr.h +67 -0
  92. package/sdk/deps/trezor-crypto/include/TrezorCrypto/nano.h +56 -0
  93. package/sdk/deps/trezor-crypto/include/TrezorCrypto/nem.h +199 -0
  94. package/sdk/deps/trezor-crypto/include/TrezorCrypto/nist256p1.h +35 -0
  95. package/sdk/deps/trezor-crypto/include/TrezorCrypto/pbkdf2.h +64 -0
  96. package/sdk/deps/trezor-crypto/include/TrezorCrypto/rand.h +44 -0
  97. package/sdk/deps/trezor-crypto/include/TrezorCrypto/rc4.h +37 -0
  98. package/sdk/deps/trezor-crypto/include/TrezorCrypto/rfc6979.h +40 -0
  99. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripemd160.h +28 -0
  100. package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripple/base58.h +45 -0
  101. package/sdk/deps/trezor-crypto/include/TrezorCrypto/schnorr.h +48 -0
  102. package/sdk/deps/trezor-crypto/include/TrezorCrypto/script.h +30 -0
  103. package/sdk/deps/trezor-crypto/include/TrezorCrypto/scrypt.h +68 -0
  104. package/sdk/deps/trezor-crypto/include/TrezorCrypto/secp256k1.h +59 -0
  105. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha2.h +125 -0
  106. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha3.h +86 -0
  107. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/keypair.h +20 -0
  108. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10.h +85 -0
  109. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10_fe_25_5.h +43 -0
  110. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/constants.h +29 -0
  111. package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/fe.h +25 -0
  112. package/sdk/deps/trezor-crypto/src/address.c +87 -0
  113. package/sdk/deps/trezor-crypto/src/aes/aes_modes.c +959 -0
  114. package/sdk/deps/trezor-crypto/src/aes/aescrypt.c +307 -0
  115. package/sdk/deps/trezor-crypto/src/aes/aeskey.c +560 -0
  116. package/sdk/deps/trezor-crypto/src/aes/aesopt.h +784 -0
  117. package/sdk/deps/trezor-crypto/src/aes/aestab.c +418 -0
  118. package/sdk/deps/trezor-crypto/src/aes/aestab.h +173 -0
  119. package/sdk/deps/trezor-crypto/src/base32.c +233 -0
  120. package/sdk/deps/trezor-crypto/src/base58.c +298 -0
  121. package/sdk/deps/trezor-crypto/src/bignum.c +808 -0
  122. package/sdk/deps/trezor-crypto/src/bip32.c +852 -0
  123. package/sdk/deps/trezor-crypto/src/bip39.c +266 -0
  124. package/sdk/deps/trezor-crypto/src/bip39_english.h +2074 -0
  125. package/sdk/deps/trezor-crypto/src/blake256.c +235 -0
  126. package/sdk/deps/trezor-crypto/src/blake2_common.h +39 -0
  127. package/sdk/deps/trezor-crypto/src/blake2b.c +333 -0
  128. package/sdk/deps/trezor-crypto/src/blake2s.c +318 -0
  129. package/sdk/deps/trezor-crypto/src/cash_addr.c +195 -0
  130. package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c +60 -0
  131. package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c +246 -0
  132. package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-machine.h +49 -0
  133. package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-portable.h +275 -0
  134. package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna-32.h +219 -0
  135. package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c +179 -0
  136. package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.c +48 -0
  137. package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.h +10 -0
  138. package/sdk/deps/trezor-crypto/src/check_mem.h +30 -0
  139. package/sdk/deps/trezor-crypto/src/cmac.c +342 -0
  140. package/sdk/deps/trezor-crypto/src/curves.c +48 -0
  141. package/sdk/deps/trezor-crypto/src/ecdsa.c +1355 -0
  142. package/sdk/deps/trezor-crypto/src/ed25519-donna/README.md +183 -0
  143. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c +681 -0
  144. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c +66 -0
  145. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c +67 -0
  146. package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.h +8 -0
  147. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c +8 -0
  148. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c +63 -0
  149. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c +261 -0
  150. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c +722 -0
  151. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-blake2b.h +23 -0
  152. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-keccak.h +23 -0
  153. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-sha3.h +23 -0
  154. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom.h +23 -0
  155. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c +8 -0
  156. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c +8 -0
  157. package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519.c +311 -0
  158. package/sdk/deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c +517 -0
  159. package/sdk/deps/trezor-crypto/src/groestl.c +783 -0
  160. package/sdk/deps/trezor-crypto/src/groestl_internal.h +419 -0
  161. package/sdk/deps/trezor-crypto/src/hasher.c +186 -0
  162. package/sdk/deps/trezor-crypto/src/hmac.c +179 -0
  163. package/sdk/deps/trezor-crypto/src/memzero.c +6 -0
  164. package/sdk/deps/trezor-crypto/src/monero/base58.c +245 -0
  165. package/sdk/deps/trezor-crypto/src/monero/int-util.h +77 -0
  166. package/sdk/deps/trezor-crypto/src/monero/range_proof.c +115 -0
  167. package/sdk/deps/trezor-crypto/src/monero/serialize.c +54 -0
  168. package/sdk/deps/trezor-crypto/src/monero/xmr.c +136 -0
  169. package/sdk/deps/trezor-crypto/src/nano.c +151 -0
  170. package/sdk/deps/trezor-crypto/src/nem.c +569 -0
  171. package/sdk/deps/trezor-crypto/src/nist256p1.c +63 -0
  172. package/sdk/deps/trezor-crypto/src/nist256p1.table +1664 -0
  173. package/sdk/deps/trezor-crypto/src/options.h +43 -0
  174. package/sdk/deps/trezor-crypto/src/pbkdf2.c +177 -0
  175. package/sdk/deps/trezor-crypto/src/rand.c +51 -0
  176. package/sdk/deps/trezor-crypto/src/rc4.c +56 -0
  177. package/sdk/deps/trezor-crypto/src/ripemd160.c +343 -0
  178. package/sdk/deps/trezor-crypto/src/ripple/base58.c +76 -0
  179. package/sdk/deps/trezor-crypto/src/schnorr.c +208 -0
  180. package/sdk/deps/trezor-crypto/src/script.c +64 -0
  181. package/sdk/deps/trezor-crypto/src/scrypt.c +343 -0
  182. package/sdk/deps/trezor-crypto/src/secp256k1.c +160 -0
  183. package/sdk/deps/trezor-crypto/src/secp256k1.table +1664 -0
  184. package/sdk/deps/trezor-crypto/src/setup.py +38 -0
  185. package/sdk/deps/trezor-crypto/src/sha2.c +1314 -0
  186. package/sdk/deps/trezor-crypto/src/sha3.c +395 -0
  187. package/sdk/deps/trezor-crypto/src/shell.nix +6 -0
  188. package/sdk/deps/trezor-crypto/src/sodium/keypair.c +63 -0
  189. package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10.c +481 -0
  190. package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c +885 -0
  191. package/sdk/deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c +237 -0
  192. package/sdk/gpc/include/scp03/scp03.hpp +80 -0
  193. package/sdk/gpc/include/scp11/scp11.hpp +492 -0
  194. package/sdk/gpc/include/scp11/scp11c.hpp +58 -0
  195. package/sdk/gpc/include/tag.h +68 -0
  196. package/sdk/gpc/include/tlv.hpp +94 -0
  197. package/sdk/gpc/include/tlvparse.hpp +24 -0
  198. package/sdk/gpc/src/scp03.cpp +243 -0
  199. package/sdk/gpc/src/scp11.cpp +798 -0
  200. package/sdk/gpc/src/scp11c.cpp +136 -0
  201. package/sdk/gpc/src/tlv.cpp +159 -0
  202. package/sdk/gpc/src/tlvparse.c +174 -0
  203. package/{framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers → sdk/include}/GPChannelSDK.h +0 -0
  204. package/sdk/include/GPChannelSDKCore.h +10 -0
  205. package/sdk/include/context/BaseContext.h +56 -0
  206. package/sdk/include/device/ApduBuilder.hpp +72 -0
  207. package/sdk/include/mSIGNA/stdutils/uchar_vector.h +36 -0
  208. package/sdk/include/utility/Apdu.hpp +172 -0
  209. package/sdk/include/utility/Debug.hpp +3 -0
  210. package/sdk/include/utility/util.h +104 -0
  211. package/sdk/scripts/generate-source-id.rb +22 -0
  212. package/sdk/source-id-manifest.txt +19 -0
  213. package/sdk/source-id.cmake +31 -0
  214. package/sdk/src/ApduBuilder.cpp +332 -0
  215. package/sdk/src/GPChannelSDK.cpp +258 -0
  216. package/sdk/src/random.c +25 -0
  217. package/sdk/src/version.c +3 -0
  218. package/sdk/tests/android/GPChannelProxy.java +55 -0
  219. package/sdk/tests/android_verify.py +124 -0
  220. package/sdk/tests/safety.cpp +757 -0
  221. package/sdk/tests/verify.py +284 -0
  222. package/src/NativeReactNativeLiteCard.ts +4 -2
  223. package/src/index.tsx +14 -3
  224. package/android/src/main/jniLibs/arm64-v8a/libgpchannelNDK.so +0 -0
  225. package/android/src/main/jniLibs/armeabi-v7a/libgpchannelNDK.so +0 -0
  226. package/framework/GPChannelSDKCore.xcframework/Info.plist +0 -52
  227. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
  228. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
  229. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Info.plist +0 -0
  230. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
  231. package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
  232. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
  233. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDK.h +0 -315
  234. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
  235. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Info.plist +0 -0
  236. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
  237. package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
@@ -0,0 +1,246 @@
1
+ /*
2
+ chacha-merged.c version 20080118
3
+ D. J. Bernstein
4
+ Public domain.
5
+ */
6
+
7
+ #include <TrezorCrypto/chacha20poly1305/ecrypt-sync.h>
8
+ #include "ecrypt-portable.h"
9
+
10
+ #define ROTATE(v,c) (ROTL32(v,c))
11
+ #define XOR(v,w) ((v) ^ (w))
12
+ #define PLUS(v,w) (U32V((v) + (w)))
13
+ #define PLUSONE(v) (PLUS((v),1))
14
+
15
+ #define QUARTERROUND(a,b,c,d) \
16
+ a = PLUS(a,b); d = ROTATE(XOR(d,a),16); \
17
+ c = PLUS(c,d); b = ROTATE(XOR(b,c),12); \
18
+ a = PLUS(a,b); d = ROTATE(XOR(d,a), 8); \
19
+ c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
20
+
21
+ void ECRYPT_init(void)
22
+ {
23
+ return;
24
+ }
25
+
26
+ static const char sigma[16] = "expand 32-byte k";
27
+ static const char tau[16] = "expand 16-byte k";
28
+
29
+ void ECRYPT_keysetup(ECRYPT_ctx *x,const u8 *k,u32 kbits,u32 ivbits)
30
+ {
31
+ (void)ivbits;
32
+ const char *constants;
33
+
34
+ x->input[4] = U8TO32_LITTLE(k + 0);
35
+ x->input[5] = U8TO32_LITTLE(k + 4);
36
+ x->input[6] = U8TO32_LITTLE(k + 8);
37
+ x->input[7] = U8TO32_LITTLE(k + 12);
38
+ if (kbits == 256) { /* recommended */
39
+ k += 16;
40
+ constants = sigma;
41
+ } else { /* kbits == 128 */
42
+ constants = tau;
43
+ }
44
+ x->input[8] = U8TO32_LITTLE(k + 0);
45
+ x->input[9] = U8TO32_LITTLE(k + 4);
46
+ x->input[10] = U8TO32_LITTLE(k + 8);
47
+ x->input[11] = U8TO32_LITTLE(k + 12);
48
+ x->input[0] = U8TO32_LITTLE(constants + 0);
49
+ x->input[1] = U8TO32_LITTLE(constants + 4);
50
+ x->input[2] = U8TO32_LITTLE(constants + 8);
51
+ x->input[3] = U8TO32_LITTLE(constants + 12);
52
+ }
53
+
54
+ void ECRYPT_ivsetup(ECRYPT_ctx *x,const u8 *iv)
55
+ {
56
+ x->input[12] = 0;
57
+ x->input[13] = 0;
58
+ x->input[14] = U8TO32_LITTLE(iv + 0);
59
+ x->input[15] = U8TO32_LITTLE(iv + 4);
60
+ }
61
+
62
+ void ECRYPT_encrypt_bytes(ECRYPT_ctx *x,const u8 *m,u8 *c,u32 bytes)
63
+ {
64
+ u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
65
+ u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
66
+ u8 *ctarget = 0;
67
+ u8 tmp[64];
68
+ int i;
69
+
70
+ if (!bytes) return;
71
+
72
+ j0 = x->input[0];
73
+ j1 = x->input[1];
74
+ j2 = x->input[2];
75
+ j3 = x->input[3];
76
+ j4 = x->input[4];
77
+ j5 = x->input[5];
78
+ j6 = x->input[6];
79
+ j7 = x->input[7];
80
+ j8 = x->input[8];
81
+ j9 = x->input[9];
82
+ j10 = x->input[10];
83
+ j11 = x->input[11];
84
+ j12 = x->input[12];
85
+ j13 = x->input[13];
86
+ j14 = x->input[14];
87
+ j15 = x->input[15];
88
+
89
+ for (;;) {
90
+ if (bytes < 64) {
91
+ for (i = 0;i < (int)bytes;++i) tmp[i] = m[i];
92
+ m = tmp;
93
+ ctarget = c;
94
+ c = tmp;
95
+ }
96
+ x0 = j0;
97
+ x1 = j1;
98
+ x2 = j2;
99
+ x3 = j3;
100
+ x4 = j4;
101
+ x5 = j5;
102
+ x6 = j6;
103
+ x7 = j7;
104
+ x8 = j8;
105
+ x9 = j9;
106
+ x10 = j10;
107
+ x11 = j11;
108
+ x12 = j12;
109
+ x13 = j13;
110
+ x14 = j14;
111
+ x15 = j15;
112
+ for (i = 20;i > 0;i -= 2) {
113
+ QUARTERROUND( x0, x4, x8,x12)
114
+ QUARTERROUND( x1, x5, x9,x13)
115
+ QUARTERROUND( x2, x6,x10,x14)
116
+ QUARTERROUND( x3, x7,x11,x15)
117
+ QUARTERROUND( x0, x5,x10,x15)
118
+ QUARTERROUND( x1, x6,x11,x12)
119
+ QUARTERROUND( x2, x7, x8,x13)
120
+ QUARTERROUND( x3, x4, x9,x14)
121
+ }
122
+ x0 = PLUS(x0,j0);
123
+ x1 = PLUS(x1,j1);
124
+ x2 = PLUS(x2,j2);
125
+ x3 = PLUS(x3,j3);
126
+ x4 = PLUS(x4,j4);
127
+ x5 = PLUS(x5,j5);
128
+ x6 = PLUS(x6,j6);
129
+ x7 = PLUS(x7,j7);
130
+ x8 = PLUS(x8,j8);
131
+ x9 = PLUS(x9,j9);
132
+ x10 = PLUS(x10,j10);
133
+ x11 = PLUS(x11,j11);
134
+ x12 = PLUS(x12,j12);
135
+ x13 = PLUS(x13,j13);
136
+ x14 = PLUS(x14,j14);
137
+ x15 = PLUS(x15,j15);
138
+
139
+ x0 = XOR(x0,U8TO32_LITTLE(m + 0));
140
+ x1 = XOR(x1,U8TO32_LITTLE(m + 4));
141
+ x2 = XOR(x2,U8TO32_LITTLE(m + 8));
142
+ x3 = XOR(x3,U8TO32_LITTLE(m + 12));
143
+ x4 = XOR(x4,U8TO32_LITTLE(m + 16));
144
+ x5 = XOR(x5,U8TO32_LITTLE(m + 20));
145
+ x6 = XOR(x6,U8TO32_LITTLE(m + 24));
146
+ x7 = XOR(x7,U8TO32_LITTLE(m + 28));
147
+ x8 = XOR(x8,U8TO32_LITTLE(m + 32));
148
+ x9 = XOR(x9,U8TO32_LITTLE(m + 36));
149
+ x10 = XOR(x10,U8TO32_LITTLE(m + 40));
150
+ x11 = XOR(x11,U8TO32_LITTLE(m + 44));
151
+ x12 = XOR(x12,U8TO32_LITTLE(m + 48));
152
+ x13 = XOR(x13,U8TO32_LITTLE(m + 52));
153
+ x14 = XOR(x14,U8TO32_LITTLE(m + 56));
154
+ x15 = XOR(x15,U8TO32_LITTLE(m + 60));
155
+
156
+ j12 = PLUSONE(j12);
157
+ if (!j12) {
158
+ j13 = PLUSONE(j13);
159
+ /* stopping at 2^70 bytes per nonce is user's responsibility */
160
+ }
161
+
162
+ U32TO8_LITTLE(c + 0,x0);
163
+ U32TO8_LITTLE(c + 4,x1);
164
+ U32TO8_LITTLE(c + 8,x2);
165
+ U32TO8_LITTLE(c + 12,x3);
166
+ U32TO8_LITTLE(c + 16,x4);
167
+ U32TO8_LITTLE(c + 20,x5);
168
+ U32TO8_LITTLE(c + 24,x6);
169
+ U32TO8_LITTLE(c + 28,x7);
170
+ U32TO8_LITTLE(c + 32,x8);
171
+ U32TO8_LITTLE(c + 36,x9);
172
+ U32TO8_LITTLE(c + 40,x10);
173
+ U32TO8_LITTLE(c + 44,x11);
174
+ U32TO8_LITTLE(c + 48,x12);
175
+ U32TO8_LITTLE(c + 52,x13);
176
+ U32TO8_LITTLE(c + 56,x14);
177
+ U32TO8_LITTLE(c + 60,x15);
178
+
179
+ if (bytes <= 64) {
180
+ if (bytes < 64) {
181
+ for (i = 0;i < (int)bytes;++i) ctarget[i] = c[i];
182
+ }
183
+ x->input[12] = j12;
184
+ x->input[13] = j13;
185
+ return;
186
+ }
187
+ bytes -= 64;
188
+ c += 64;
189
+ m += 64;
190
+ }
191
+ }
192
+
193
+ void ECRYPT_decrypt_bytes(ECRYPT_ctx *x,const u8 *c,u8 *m,u32 bytes)
194
+ {
195
+ ECRYPT_encrypt_bytes(x,c,m,bytes);
196
+ }
197
+
198
+ void ECRYPT_keystream_bytes(ECRYPT_ctx *x,u8 *stream,u32 bytes)
199
+ {
200
+ u32 i;
201
+ for (i = 0;i < bytes;++i) stream[i] = 0;
202
+ ECRYPT_encrypt_bytes(x,stream,stream,bytes);
203
+ }
204
+
205
+ void hchacha20(ECRYPT_ctx *x,u8 *c)
206
+ {
207
+ u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
208
+ int i;
209
+
210
+ x0 = x->input[0];
211
+ x1 = x->input[1];
212
+ x2 = x->input[2];
213
+ x3 = x->input[3];
214
+ x4 = x->input[4];
215
+ x5 = x->input[5];
216
+ x6 = x->input[6];
217
+ x7 = x->input[7];
218
+ x8 = x->input[8];
219
+ x9 = x->input[9];
220
+ x10 = x->input[10];
221
+ x11 = x->input[11];
222
+ x12 = x->input[12];
223
+ x13 = x->input[13];
224
+ x14 = x->input[14];
225
+ x15 = x->input[15];
226
+
227
+ for (i = 20;i > 0;i -= 2) {
228
+ QUARTERROUND( x0, x4, x8,x12)
229
+ QUARTERROUND( x1, x5, x9,x13)
230
+ QUARTERROUND( x2, x6,x10,x14)
231
+ QUARTERROUND( x3, x7,x11,x15)
232
+ QUARTERROUND( x0, x5,x10,x15)
233
+ QUARTERROUND( x1, x6,x11,x12)
234
+ QUARTERROUND( x2, x7, x8,x13)
235
+ QUARTERROUND( x3, x4, x9,x14)
236
+ }
237
+
238
+ U32TO8_LITTLE(c + 0,x0);
239
+ U32TO8_LITTLE(c + 4,x1);
240
+ U32TO8_LITTLE(c + 8,x2);
241
+ U32TO8_LITTLE(c + 12,x3);
242
+ U32TO8_LITTLE(c + 16,x12);
243
+ U32TO8_LITTLE(c + 20,x13);
244
+ U32TO8_LITTLE(c + 24,x14);
245
+ U32TO8_LITTLE(c + 28,x15);
246
+ }
@@ -0,0 +1,49 @@
1
+ /* ecrypt-machine.h */
2
+
3
+ /*
4
+ * This file is included by 'ecrypt-portable.h'. It allows to override
5
+ * the default macros for specific platforms. Please carefully check
6
+ * the machine code generated by your compiler (with optimisations
7
+ * turned on) before deciding to edit this file.
8
+ */
9
+
10
+ /* ------------------------------------------------------------------------- */
11
+
12
+ #if (defined(ECRYPT_DEFAULT_ROT) && !defined(ECRYPT_MACHINE_ROT))
13
+
14
+ #define ECRYPT_MACHINE_ROT
15
+
16
+ #if (defined(WIN32) && defined(_MSC_VER))
17
+
18
+ #undef ROTL32
19
+ #undef ROTR32
20
+ #undef ROTL64
21
+ #undef ROTR64
22
+
23
+ #include <stdlib.h>
24
+
25
+ #pragma intrinsic(_lrotl) /* compile rotations "inline" */
26
+ #pragma intrinsic(_lrotr)
27
+
28
+ #define ROTL32(v, n) _lrotl(v, n)
29
+ #define ROTR32(v, n) _lrotr(v, n)
30
+ #define ROTL64(v, n) _rotl64(v, n)
31
+ #define ROTR64(v, n) _rotr64(v, n)
32
+
33
+ #endif
34
+
35
+ #endif
36
+
37
+ /* ------------------------------------------------------------------------- */
38
+
39
+ #if (defined(ECRYPT_DEFAULT_SWAP) && !defined(ECRYPT_MACHINE_SWAP))
40
+
41
+ #define ECRYPT_MACHINE_SWAP
42
+
43
+ /*
44
+ * If you want to overwrite the default swap macros, put it here. And so on.
45
+ */
46
+
47
+ #endif
48
+
49
+ /* ------------------------------------------------------------------------- */
@@ -0,0 +1,275 @@
1
+ /* ecrypt-portable.h */
2
+
3
+ /*
4
+ * WARNING: the conversions defined below are implemented as macros,
5
+ * and should be used carefully. They should NOT be used with
6
+ * parameters which perform some action. E.g., the following two lines
7
+ * are not equivalent:
8
+ *
9
+ * 1) ++x; y = ROTL32(x, n);
10
+ * 2) y = ROTL32(++x, n);
11
+ */
12
+
13
+ /*
14
+ * *** Please do not edit this file. ***
15
+ *
16
+ * The default macros can be overridden for specific architectures by
17
+ * editing 'ecrypt-machine.h'.
18
+ */
19
+
20
+ #ifndef ECRYPT_PORTABLE
21
+ #define ECRYPT_PORTABLE
22
+
23
+ #include <TrezorCrypto/chacha20poly1305/ecrypt-config.h>
24
+ #include <TrezorCrypto/chacha20poly1305/ecrypt-types.h>
25
+
26
+ /* ------------------------------------------------------------------------- */
27
+
28
+ /*
29
+ * The following macros are used to obtain exact-width results.
30
+ */
31
+
32
+ #define U8V(v) ((u8)(v) & U8C(0xFF))
33
+ #define U16V(v) ((u16)(v) & U16C(0xFFFF))
34
+ #define U32V(v) ((u32)(v) & U32C(0xFFFFFFFF))
35
+ #define U64V(v) ((u64)(v) & U64C(0xFFFFFFFFFFFFFFFF))
36
+
37
+ /* ------------------------------------------------------------------------- */
38
+
39
+ /*
40
+ * The following macros return words with their bits rotated over n
41
+ * positions to the left/right.
42
+ */
43
+
44
+ #define ECRYPT_DEFAULT_ROT
45
+
46
+ #define ROTL8(v, n) \
47
+ (U8V((v) << (n)) | ((v) >> (8 - (n))))
48
+
49
+ #define ROTL16(v, n) \
50
+ (U16V((v) << (n)) | ((v) >> (16 - (n))))
51
+
52
+ #define ROTL32(v, n) \
53
+ (U32V((v) << (n)) | ((v) >> (32 - (n))))
54
+
55
+ #define ROTL64(v, n) \
56
+ (U64V((v) << (n)) | ((v) >> (64 - (n))))
57
+
58
+ #define ROTR8(v, n) ROTL8(v, 8 - (n))
59
+ #define ROTR16(v, n) ROTL16(v, 16 - (n))
60
+ #define ROTR32(v, n) ROTL32(v, 32 - (n))
61
+ #define ROTR64(v, n) ROTL64(v, 64 - (n))
62
+
63
+ #include "ecrypt-machine.h"
64
+
65
+ /* ------------------------------------------------------------------------- */
66
+
67
+ /*
68
+ * The following macros return a word with bytes in reverse order.
69
+ */
70
+
71
+ #define ECRYPT_DEFAULT_SWAP
72
+
73
+ #define SWAP16(v) \
74
+ ROTL16(v, 8)
75
+
76
+ #define SWAP32(v) \
77
+ ((ROTL32(v, 8) & U32C(0x00FF00FF)) | \
78
+ (ROTL32(v, 24) & U32C(0xFF00FF00)))
79
+
80
+ #ifdef ECRYPT_NATIVE64
81
+ #define SWAP64(v) \
82
+ ((ROTL64(v, 8) & U64C(0x000000FF000000FF)) | \
83
+ (ROTL64(v, 24) & U64C(0x0000FF000000FF00)) | \
84
+ (ROTL64(v, 40) & U64C(0x00FF000000FF0000)) | \
85
+ (ROTL64(v, 56) & U64C(0xFF000000FF000000)))
86
+ #else
87
+ #define SWAP64(v) \
88
+ (((u64)SWAP32(U32V(v)) << 32) | (u64)SWAP32(U32V(v >> 32)))
89
+ #endif
90
+
91
+ #include "ecrypt-machine.h"
92
+
93
+ #define ECRYPT_DEFAULT_WTOW
94
+
95
+ #ifdef ECRYPT_LITTLE_ENDIAN
96
+ #define U16TO16_LITTLE(v) (v)
97
+ #define U32TO32_LITTLE(v) (v)
98
+ #define U64TO64_LITTLE(v) (v)
99
+
100
+ #define U16TO16_BIG(v) SWAP16(v)
101
+ #define U32TO32_BIG(v) SWAP32(v)
102
+ #define U64TO64_BIG(v) SWAP64(v)
103
+ #endif
104
+
105
+ #ifdef ECRYPT_BIG_ENDIAN
106
+ #define U16TO16_LITTLE(v) SWAP16(v)
107
+ #define U32TO32_LITTLE(v) SWAP32(v)
108
+ #define U64TO64_LITTLE(v) SWAP64(v)
109
+
110
+ #define U16TO16_BIG(v) (v)
111
+ #define U32TO32_BIG(v) (v)
112
+ #define U64TO64_BIG(v) (v)
113
+ #endif
114
+
115
+ #include "ecrypt-machine.h"
116
+
117
+ /*
118
+ * The following macros load words from an array of bytes with
119
+ * different types of endianness, and vice versa.
120
+ */
121
+
122
+ #define ECRYPT_DEFAULT_BTOW
123
+
124
+ #if (!defined(ECRYPT_UNKNOWN) && defined(ECRYPT_I8T_IS_BYTE))
125
+
126
+ #define U8TO16_LITTLE(p) U16TO16_LITTLE(((u16*)(p))[0])
127
+ #define U8TO32_LITTLE(p) U32TO32_LITTLE(((u32*)(p))[0])
128
+ #define U8TO64_LITTLE(p) U64TO64_LITTLE(((u64*)(p))[0])
129
+
130
+ #define U8TO16_BIG(p) U16TO16_BIG(((u16*)(p))[0])
131
+ #define U8TO32_BIG(p) U32TO32_BIG(((u32*)(p))[0])
132
+ #define U8TO64_BIG(p) U64TO64_BIG(((u64*)(p))[0])
133
+
134
+ #define U16TO8_LITTLE(p, v) (((u16*)(p))[0] = U16TO16_LITTLE(v))
135
+ #define U32TO8_LITTLE(p, v) (((u32*)(p))[0] = U32TO32_LITTLE(v))
136
+ #define U64TO8_LITTLE(p, v) (((u64*)(p))[0] = U64TO64_LITTLE(v))
137
+
138
+ #define U16TO8_BIG(p, v) (((u16*)(p))[0] = U16TO16_BIG(v))
139
+ #define U32TO8_BIG(p, v) (((u32*)(p))[0] = U32TO32_BIG(v))
140
+ #define U64TO8_BIG(p, v) (((u64*)(p))[0] = U64TO64_BIG(v))
141
+
142
+ #else
143
+
144
+ #define U8TO16_LITTLE(p) \
145
+ (((u16)((p)[0]) ) | \
146
+ ((u16)((p)[1]) << 8))
147
+
148
+ #define U8TO32_LITTLE(p) \
149
+ (((u32)((p)[0]) ) | \
150
+ ((u32)((p)[1]) << 8) | \
151
+ ((u32)((p)[2]) << 16) | \
152
+ ((u32)((p)[3]) << 24))
153
+
154
+ #ifdef ECRYPT_NATIVE64
155
+ #define U8TO64_LITTLE(p) \
156
+ (((u64)((p)[0]) ) | \
157
+ ((u64)((p)[1]) << 8) | \
158
+ ((u64)((p)[2]) << 16) | \
159
+ ((u64)((p)[3]) << 24) | \
160
+ ((u64)((p)[4]) << 32) | \
161
+ ((u64)((p)[5]) << 40) | \
162
+ ((u64)((p)[6]) << 48) | \
163
+ ((u64)((p)[7]) << 56))
164
+ #else
165
+ #define U8TO64_LITTLE(p) \
166
+ ((u64)U8TO32_LITTLE(p) | ((u64)U8TO32_LITTLE((p) + 4) << 32))
167
+ #endif
168
+
169
+ #define U8TO16_BIG(p) \
170
+ (((u16)((p)[0]) << 8) | \
171
+ ((u16)((p)[1]) ))
172
+
173
+ #define U8TO32_BIG(p) \
174
+ (((u32)((p)[0]) << 24) | \
175
+ ((u32)((p)[1]) << 16) | \
176
+ ((u32)((p)[2]) << 8) | \
177
+ ((u32)((p)[3]) ))
178
+
179
+ #ifdef ECRYPT_NATIVE64
180
+ #define U8TO64_BIG(p) \
181
+ (((u64)((p)[0]) << 56) | \
182
+ ((u64)((p)[1]) << 48) | \
183
+ ((u64)((p)[2]) << 40) | \
184
+ ((u64)((p)[3]) << 32) | \
185
+ ((u64)((p)[4]) << 24) | \
186
+ ((u64)((p)[5]) << 16) | \
187
+ ((u64)((p)[6]) << 8) | \
188
+ ((u64)((p)[7]) ))
189
+ #else
190
+ #define U8TO64_BIG(p) \
191
+ (((u64)U8TO32_BIG(p) << 32) | (u64)U8TO32_BIG((p) + 4))
192
+ #endif
193
+
194
+ #define U16TO8_LITTLE(p, v) \
195
+ do { \
196
+ (p)[0] = U8V((v) ); \
197
+ (p)[1] = U8V((v) >> 8); \
198
+ } while (0)
199
+
200
+ #define U32TO8_LITTLE(p, v) \
201
+ do { \
202
+ (p)[0] = U8V((v) ); \
203
+ (p)[1] = U8V((v) >> 8); \
204
+ (p)[2] = U8V((v) >> 16); \
205
+ (p)[3] = U8V((v) >> 24); \
206
+ } while (0)
207
+
208
+ #ifdef ECRYPT_NATIVE64
209
+ #define U64TO8_LITTLE(p, v) \
210
+ do { \
211
+ (p)[0] = U8V((v) ); \
212
+ (p)[1] = U8V((v) >> 8); \
213
+ (p)[2] = U8V((v) >> 16); \
214
+ (p)[3] = U8V((v) >> 24); \
215
+ (p)[4] = U8V((v) >> 32); \
216
+ (p)[5] = U8V((v) >> 40); \
217
+ (p)[6] = U8V((v) >> 48); \
218
+ (p)[7] = U8V((v) >> 56); \
219
+ } while (0)
220
+ #else
221
+ #define U64TO8_LITTLE(p, v) \
222
+ do { \
223
+ U32TO8_LITTLE((p), U32V((v) )); \
224
+ U32TO8_LITTLE((p) + 4, U32V((v) >> 32)); \
225
+ } while (0)
226
+ #endif
227
+
228
+ #define U16TO8_BIG(p, v) \
229
+ do { \
230
+ (p)[0] = U8V((v) ); \
231
+ (p)[1] = U8V((v) >> 8); \
232
+ } while (0)
233
+
234
+ #define U32TO8_BIG(p, v) \
235
+ do { \
236
+ (p)[0] = U8V((v) >> 24); \
237
+ (p)[1] = U8V((v) >> 16); \
238
+ (p)[2] = U8V((v) >> 8); \
239
+ (p)[3] = U8V((v) ); \
240
+ } while (0)
241
+
242
+ #ifdef ECRYPT_NATIVE64
243
+ #define U64TO8_BIG(p, v) \
244
+ do { \
245
+ (p)[0] = U8V((v) >> 56); \
246
+ (p)[1] = U8V((v) >> 48); \
247
+ (p)[2] = U8V((v) >> 40); \
248
+ (p)[3] = U8V((v) >> 32); \
249
+ (p)[4] = U8V((v) >> 24); \
250
+ (p)[5] = U8V((v) >> 16); \
251
+ (p)[6] = U8V((v) >> 8); \
252
+ (p)[7] = U8V((v) ); \
253
+ } while (0)
254
+ #else
255
+ #define U64TO8_BIG(p, v) \
256
+ do { \
257
+ U32TO8_BIG((p), U32V((v) >> 32)); \
258
+ U32TO8_BIG((p) + 4, U32V((v) )); \
259
+ } while (0)
260
+ #endif
261
+
262
+ #endif
263
+
264
+ #include "ecrypt-machine.h"
265
+
266
+ /* ------------------------------------------------------------------------- */
267
+
268
+ #define AT_LEAST_ONE(n) (((n) < 1) ? 1 : (n))
269
+
270
+ #define ALIGN(t, v, n) \
271
+ union { t b[n]; MAXT l[AT_LEAST_ONE(n * sizeof(t) / sizeof(MAXT))]; } v
272
+
273
+ /* ------------------------------------------------------------------------- */
274
+
275
+ #endif