@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,87 @@
1
+ /*
2
+ Public domain by Andrew M. <liquidsun@gmail.com>
3
+ */
4
+
5
+ #ifdef __cplusplus
6
+ extern "C" {
7
+ #endif
8
+
9
+ /*
10
+ Arithmetic modulo the group order n = 2^252 + 27742317777372353535851937790883648493 = 7237005577332262213973186563042994240857116359379907606001950938285454250989
11
+
12
+ k = 32
13
+ b = 1 << 8 = 256
14
+ m = 2^252 + 27742317777372353535851937790883648493 = 0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed
15
+ mu = floor( b^(k*2) / m ) = 0xfffffffffffffffffffffffffffffffeb2106215d086329a7ed9ce5a30a2c131b
16
+ */
17
+
18
+ #define bignum256modm_bits_per_limb 30
19
+ #define bignum256modm_limb_size 9
20
+
21
+ typedef uint32_t bignum256modm_element_t;
22
+ typedef bignum256modm_element_t bignum256modm[9];
23
+
24
+ /* see HAC, Alg. 14.42 Step 4 */
25
+ void reduce256_modm(bignum256modm r);
26
+
27
+ /*
28
+ Barrett reduction, see HAC, Alg. 14.42
29
+
30
+ Instead of passing in x, pre-process in to q1 and r1 for efficiency
31
+ */
32
+ void barrett_reduce256_modm(bignum256modm r, const bignum256modm q1, const bignum256modm r1);
33
+
34
+ /* addition modulo m */
35
+ void add256_modm(bignum256modm r, const bignum256modm x, const bignum256modm y);
36
+
37
+ /* -x modulo m */
38
+ void neg256_modm(bignum256modm r, const bignum256modm x);
39
+
40
+ /* subtraction x-y modulo m */
41
+ void sub256_modm(bignum256modm r, const bignum256modm x, const bignum256modm y);
42
+
43
+ /* multiplication modulo m */
44
+ void mul256_modm(bignum256modm r, const bignum256modm x, const bignum256modm y);
45
+
46
+ void expand256_modm(bignum256modm out, const unsigned char *in, size_t len);
47
+
48
+ void expand_raw256_modm(bignum256modm out, const unsigned char in[32]);
49
+
50
+ int is_reduced256_modm(const bignum256modm in);
51
+
52
+ void contract256_modm(unsigned char out[32], const bignum256modm in);
53
+
54
+ void contract256_window4_modm(signed char r[64], const bignum256modm in);
55
+
56
+ void contract256_slidingwindow_modm(signed char r[256], const bignum256modm s, int windowsize);
57
+
58
+ /* 64bit uint to scalar value */
59
+ void set256_modm(bignum256modm r, uint64_t v);
60
+
61
+ /* scalar value to 64bit uint */
62
+ int get256_modm(uint64_t * v, const bignum256modm r);
63
+
64
+ /* equality test on two reduced scalar values */
65
+ int eq256_modm(const bignum256modm x, const bignum256modm y);
66
+
67
+ /* comparison of two reduced scalar values */
68
+ int cmp256_modm(const bignum256modm x, const bignum256modm y);
69
+
70
+ /* scalar null check, has to be reduced */
71
+ int iszero256_modm(const bignum256modm x);
72
+
73
+ /* simple copy, no reduction */
74
+ void copy256_modm(bignum256modm r, const bignum256modm x);
75
+
76
+ /* check if nonzero && same after reduction */
77
+ int check256_modm(const bignum256modm x);
78
+
79
+ /* (cc - aa * bb) % l */
80
+ void mulsub256_modm(bignum256modm r, const bignum256modm a, const bignum256modm b, const bignum256modm c);
81
+
82
+ /* (cc + aa * bb) % l */
83
+ void muladd256_modm(bignum256modm r, const bignum256modm a, const bignum256modm b, const bignum256modm c);
84
+
85
+ #ifdef __cplusplus
86
+ } /* extern "C" */
87
+ #endif
@@ -0,0 +1,60 @@
1
+ /*
2
+ Public domain by Andrew M. <liquidsun@gmail.com>
3
+ Modified from the amd64-51-30k implementation by
4
+ Daniel J. Bernstein
5
+ Niels Duif
6
+ Tanja Lange
7
+ Peter Schwabe
8
+ Bo-Yin Yang
9
+ */
10
+
11
+ #ifndef ED25519_DONNA_H
12
+ #define ED25519_DONNA_H
13
+
14
+ #include "ed25519-donna/ed25519-donna-portable.h"
15
+
16
+ #include "ed25519-donna/curve25519-donna-32bit.h"
17
+
18
+ #include "ed25519-donna/curve25519-donna-helpers.h"
19
+
20
+ #include "ed25519-donna/modm-donna-32bit.h"
21
+
22
+ #ifdef __cplusplus
23
+ extern "C" {
24
+ #endif
25
+
26
+ typedef unsigned char hash_512bits[64];
27
+
28
+ /*
29
+ * Arithmetic on the twisted Edwards curve -x^2 + y^2 = 1 + dx^2y^2
30
+ * with d = -(121665/121666) = 37095705934669439343138083508754565189542113879843219016388785533085940283555
31
+ * Base point: (15112221349535400772501151409588531511454012693041857206046113283949847762202,46316835694926478169428394003475163141307993866256225615783033603165251855960);
32
+ */
33
+
34
+ typedef struct ge25519_t {
35
+ bignum25519 x, y, z, t;
36
+ } ge25519;
37
+
38
+ typedef struct ge25519_p1p1_t {
39
+ bignum25519 x, y, z, t;
40
+ } ge25519_p1p1;
41
+
42
+ typedef struct ge25519_niels_t {
43
+ bignum25519 ysubx, xaddy, t2d;
44
+ } ge25519_niels;
45
+
46
+ typedef struct ge25519_pniels_t {
47
+ bignum25519 ysubx, xaddy, z, t2d;
48
+ } ge25519_pniels;
49
+
50
+ #include "ed25519-donna/ed25519-donna-basepoint-table.h"
51
+
52
+ #include "ed25519-donna/ed25519-donna-32bit-tables.h"
53
+
54
+ #include "ed25519-donna/ed25519-donna-impl-base.h"
55
+
56
+ #ifdef __cplusplus
57
+ } /* extern "C" */
58
+ #endif
59
+
60
+ #endif
@@ -0,0 +1,42 @@
1
+ #ifndef ED25519_H
2
+ #define ED25519_H
3
+
4
+ #if defined(__cplusplus)
5
+ extern "C" {
6
+ #endif
7
+
8
+ typedef unsigned char ed25519_signature[64];
9
+ typedef unsigned char ed25519_public_key[32];
10
+ typedef unsigned char ed25519_secret_key[32];
11
+
12
+ typedef unsigned char curve25519_key[32];
13
+
14
+ typedef unsigned char ed25519_cosi_signature[32];
15
+
16
+ void ed25519_publickey(const ed25519_secret_key sk, ed25519_public_key pk);
17
+ void ed25519_publickey_ext(const ed25519_secret_key sk, const ed25519_secret_key skext, ed25519_public_key pk);
18
+
19
+ int ed25519_sign_open(const unsigned char *m, size_t mlen, const ed25519_public_key pk, const ed25519_signature RS);
20
+ void ed25519_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_public_key pk, ed25519_signature RS);
21
+ void ed25519_sign_ext(const unsigned char *m, size_t mlen, const ed25519_secret_key sk, const ed25519_secret_key skext, const ed25519_public_key pk, ed25519_signature RS);
22
+
23
+ int ed25519_scalarmult(ed25519_public_key res, const ed25519_secret_key sk, const ed25519_public_key pk);
24
+
25
+ void curve25519_scalarmult(curve25519_key mypublic, const curve25519_key secret, const curve25519_key basepoint);
26
+ void curve25519_scalarmult_basepoint(curve25519_key mypublic, const curve25519_key secret);
27
+
28
+ #if !defined(__GNUC__) || __GNUC__ > 4
29
+ #define CONST const
30
+ #else
31
+ #define CONST
32
+ #endif
33
+
34
+ int ed25519_cosi_combine_publickeys(ed25519_public_key res, CONST ed25519_public_key *pks, size_t n);
35
+ void ed25519_cosi_combine_signatures(ed25519_signature res, const ed25519_public_key R, CONST ed25519_cosi_signature *sigs, size_t n);
36
+ void ed25519_cosi_sign(const unsigned char *m, size_t mlen, const ed25519_secret_key key, const ed25519_secret_key nonce, const ed25519_public_key R, const ed25519_public_key pk, ed25519_cosi_signature sig);
37
+
38
+ #ifdef __cplusplus
39
+ } /* extern "C" */
40
+ #endif
41
+
42
+ #endif // ED25519_H
@@ -0,0 +1,132 @@
1
+ /*-
2
+ * Copyright 2007-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
+ #ifndef _ENDIAN_H_
30
+ #define _ENDIAN_H_
31
+
32
+
33
+ #include <stdint.h>
34
+ #ifdef _MSC_VER
35
+ #define INLINE __inline
36
+ #else
37
+ #define INLINE inline
38
+ #endif
39
+
40
+ static INLINE uint32_t
41
+ be32dec(const void *pp)
42
+ {
43
+ const uint8_t *p = (uint8_t const *)pp;
44
+
45
+ return ((uint32_t)(p[3]) + ((uint32_t)(p[2]) << 8) +
46
+ ((uint32_t)(p[1]) << 16) + ((uint32_t)(p[0]) << 24));
47
+ }
48
+
49
+ static INLINE void
50
+ be32enc(void *pp, uint32_t x)
51
+ {
52
+ uint8_t * p = (uint8_t *)pp;
53
+
54
+ p[3] = x & 0xff;
55
+ p[2] = (x >> 8) & 0xff;
56
+ p[1] = (x >> 16) & 0xff;
57
+ p[0] = (x >> 24) & 0xff;
58
+ }
59
+
60
+ static INLINE uint64_t
61
+ be64dec(const void *pp)
62
+ {
63
+ const uint8_t *p = (uint8_t const *)pp;
64
+
65
+ return ((uint64_t)(p[7]) + ((uint64_t)(p[6]) << 8) +
66
+ ((uint64_t)(p[5]) << 16) + ((uint64_t)(p[4]) << 24) +
67
+ ((uint64_t)(p[3]) << 32) + ((uint64_t)(p[2]) << 40) +
68
+ ((uint64_t)(p[1]) << 48) + ((uint64_t)(p[0]) << 56));
69
+ }
70
+
71
+ static INLINE void
72
+ be64enc(void *pp, uint64_t x)
73
+ {
74
+ uint8_t * p = (uint8_t *)pp;
75
+
76
+ p[7] = x & 0xff;
77
+ p[6] = (x >> 8) & 0xff;
78
+ p[5] = (x >> 16) & 0xff;
79
+ p[4] = (x >> 24) & 0xff;
80
+ p[3] = (x >> 32) & 0xff;
81
+ p[2] = (x >> 40) & 0xff;
82
+ p[1] = (x >> 48) & 0xff;
83
+ p[0] = (x >> 56) & 0xff;
84
+ }
85
+
86
+ static INLINE uint32_t
87
+ le32dec(const void *pp)
88
+ {
89
+ const uint8_t *p = (uint8_t const *)pp;
90
+
91
+ return ((uint32_t)(p[0]) + ((uint32_t)(p[1]) << 8) +
92
+ ((uint32_t)(p[2]) << 16) + ((uint32_t)(p[3]) << 24));
93
+ }
94
+
95
+ static INLINE void
96
+ le32enc(void *pp, uint32_t x)
97
+ {
98
+ uint8_t * p = (uint8_t *)pp;
99
+
100
+ p[0] = x & 0xff;
101
+ p[1] = (x >> 8) & 0xff;
102
+ p[2] = (x >> 16) & 0xff;
103
+ p[3] = (x >> 24) & 0xff;
104
+ }
105
+
106
+ static INLINE uint64_t
107
+ le64dec(const void *pp)
108
+ {
109
+ const uint8_t *p = (uint8_t const *)pp;
110
+
111
+ return ((uint64_t)(p[0]) + ((uint64_t)(p[1]) << 8) +
112
+ ((uint64_t)(p[2]) << 16) + ((uint64_t)(p[3]) << 24) +
113
+ ((uint64_t)(p[4]) << 32) + ((uint64_t)(p[5]) << 40) +
114
+ ((uint64_t)(p[6]) << 48) + ((uint64_t)(p[7]) << 56));
115
+ }
116
+
117
+ static INLINE void
118
+ le64enc(void *pp, uint64_t x)
119
+ {
120
+ uint8_t * p = (uint8_t *)pp;
121
+
122
+ p[0] = x & 0xff;
123
+ p[1] = (x >> 8) & 0xff;
124
+ p[2] = (x >> 16) & 0xff;
125
+ p[3] = (x >> 24) & 0xff;
126
+ p[4] = (x >> 32) & 0xff;
127
+ p[5] = (x >> 40) & 0xff;
128
+ p[6] = (x >> 48) & 0xff;
129
+ p[7] = (x >> 56) & 0xff;
130
+ }
131
+
132
+ #endif /* !_ENDIAN_H_ */
@@ -0,0 +1,104 @@
1
+ /* Groestl hash from https://github.com/Groestlcoin/vanitygen
2
+ * Trezor adaptation by Yura Pakhuchiy <pakhuchiy@gmail.com>. */
3
+ /**
4
+ * Groestl interface. This code implements Groestl with the recommended
5
+ * parameters for SHA-3, with outputs of 224, 256, 384 and 512 bits.
6
+ *
7
+ * ==========================(LICENSE BEGIN)============================
8
+ *
9
+ * Copyright (c) 2007-2010 Projet RNRT SAPHIR
10
+ *
11
+ * Permission is hereby granted, free of charge, to any person obtaining
12
+ * a copy of this software and associated documentation files (the
13
+ * "Software"), to deal in the Software without restriction, including
14
+ * without limitation the rights to use, copy, modify, merge, publish,
15
+ * distribute, sublicense, and/or sell copies of the Software, and to
16
+ * permit persons to whom the Software is furnished to do so, subject to
17
+ * the following conditions:
18
+ *
19
+ * The above copyright notice and this permission notice shall be
20
+ * included in all copies or substantial portions of the Software.
21
+ *
22
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
25
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
26
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
+ *
30
+ * ===========================(LICENSE END)=============================
31
+ *
32
+ * @file sph_groestl.h
33
+ * @author Thomas Pornin <thomas.pornin@cryptolog.com>
34
+ */
35
+
36
+ #ifndef GROESTL_H__
37
+ #define GROESTL_H__
38
+
39
+ #include <stddef.h>
40
+
41
+ #if defined(__cplusplus)
42
+ extern "C"
43
+ {
44
+ #endif
45
+
46
+ /**
47
+ * This structure is a context for Groestl-384 and Groestl-512 computations:
48
+ * it contains the intermediate values and some data from the last
49
+ * entered block. Once a Groestl computation has been performed, the
50
+ * context can be reused for another computation.
51
+ *
52
+ * The contents of this structure are private. A running Groestl
53
+ * computation can be cloned by copying the context (e.g. with a simple
54
+ * <code>memcpy()</code>).
55
+ */
56
+ typedef struct {
57
+ unsigned char buf[128]; /* first field, for alignment */
58
+ size_t ptr;
59
+ union {
60
+ uint64_t wide[16];
61
+ uint32_t narrow[32];
62
+ } state;
63
+ uint64_t count;
64
+ } sph_groestl_big_context;
65
+
66
+ typedef sph_groestl_big_context GROESTL512_CTX;
67
+
68
+ /**
69
+ * Initialize a Groestl-512 context. This process performs no memory allocation.
70
+ *
71
+ * @param cc the Groestl-512 context (pointer to a
72
+ * <code>GROESTL512_CTX</code>)
73
+ */
74
+ void groestl512_Init(void *cc);
75
+
76
+ /**
77
+ * Process some data bytes. It is acceptable that <code>len</code> is zero
78
+ * (in which case this function does nothing).
79
+ *
80
+ * @param cc the Groestl-512 context
81
+ * @param data the input data
82
+ * @param len the input data length (in bytes)
83
+ */
84
+ void groestl512_Update(void *cc, const void *data, size_t len);
85
+
86
+ /**
87
+ * Terminate the current Groestl-512 computation and output the result into
88
+ * the provided buffer. The destination buffer must be wide enough to
89
+ * accomodate the result (64 bytes). The context is automatically
90
+ * reinitialized.
91
+ *
92
+ * @param cc the Groestl-512 context
93
+ * @param dst the destination buffer
94
+ */
95
+ void groestl512_Final(void *cc, void *dst);
96
+
97
+ /* Calculate double Groestl-512 hash and truncate it to 256-bits. */
98
+ void groestl512_DoubleTrunc(void *cc, void *dst);
99
+
100
+ #ifdef __cplusplus
101
+ } /* extern "C" */
102
+ #endif
103
+
104
+ #endif
@@ -0,0 +1,90 @@
1
+ /**
2
+ * Copyright (c) 2017 Saleem Rashid
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the "Software"),
6
+ * to deal in the Software without restriction, including without limitation
7
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the
9
+ * Software is furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included
12
+ * in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
18
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
+ * OTHER DEALINGS IN THE SOFTWARE.
21
+ */
22
+
23
+ #ifndef __HASHER_H__
24
+ #define __HASHER_H__
25
+
26
+ #include <stddef.h>
27
+ #include <stdint.h>
28
+
29
+ #include <TrezorCrypto/sha2.h>
30
+ #include <TrezorCrypto/sha3.h>
31
+ #include <TrezorCrypto/blake256.h>
32
+ #include <TrezorCrypto/groestl.h>
33
+ #include <TrezorCrypto/blake2b.h>
34
+
35
+ #define HASHER_DIGEST_LENGTH 32
36
+
37
+ typedef enum {
38
+ HASHER_SHA2,
39
+ HASHER_SHA2D,
40
+ HASHER_SHA2_RIPEMD,
41
+
42
+ HASHER_SHA3,
43
+ HASHER_SHA3K,
44
+
45
+ HASHER_BLAKE,
46
+ HASHER_BLAKED,
47
+ HASHER_BLAKE_RIPEMD,
48
+
49
+ HASHER_GROESTLD_TRUNC, /* Double Groestl512 hasher truncated to 256 bits */
50
+
51
+ HASHER_BLAKE2B,
52
+ HASHER_BLAKE2B_PERSONAL,
53
+
54
+ // JuBiter-defined
55
+ HASHER_SHA2_KECCAK,
56
+ HASHER_SHA3_KECCAK,
57
+ } HasherType;
58
+
59
+ typedef struct {
60
+ HasherType type;
61
+
62
+ union {
63
+ SHA256_CTX sha2; // for HASHER_SHA2{,D}
64
+ SHA3_CTX sha3; // for HASHER_SHA3{,K}
65
+ BLAKE256_CTX blake; // for HASHER_BLAKE{,D}
66
+ GROESTL512_CTX groestl; // for HASHER_GROESTLD_TRUNC
67
+ BLAKE2B_CTX blake2b; // for HASHER_BLAKE2B{,_PERSONAL}
68
+ } ctx;
69
+
70
+ const void *param;
71
+ uint32_t param_size;
72
+ } Hasher;
73
+
74
+ // JuBiter-modified
75
+ int hasher_InitParam(Hasher *hasher, HasherType type, const void *param, uint32_t param_size);
76
+ // JuBiter-modified
77
+ int hasher_Init(Hasher *hasher, HasherType type);
78
+ // JuBiter-modified
79
+ int hasher_Reset(Hasher *hasher);
80
+ // JuBiter-modified
81
+ int hasher_Update(Hasher *hasher, const uint8_t *data, size_t length);
82
+ // JuBiter-modified
83
+ int hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]);
84
+
85
+ // JuBiter-modified
86
+ int hasher_Raw(HasherType type, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]);
87
+ // JuBiter-defined
88
+ int hasher_InitParam_Raw(Hasher *hasher, const uint8_t *data, size_t length, uint8_t hash[HASHER_DIGEST_LENGTH]);
89
+
90
+ #endif
@@ -0,0 +1,60 @@
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 HMAC_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 __HMAC_H__
25
+ #define __HMAC_H__
26
+
27
+ #include <stdint.h>
28
+ #include <TrezorCrypto/sha2.h>
29
+
30
+ #ifdef __cplusplus
31
+ extern "C" {
32
+ #endif
33
+
34
+ typedef struct _HMAC_SHA256_CTX {
35
+ uint8_t o_key_pad[SHA256_BLOCK_LENGTH];
36
+ SHA256_CTX ctx;
37
+ } HMAC_SHA256_CTX;
38
+
39
+ typedef struct _HMAC_SHA512_CTX {
40
+ uint8_t o_key_pad[SHA512_BLOCK_LENGTH];
41
+ SHA512_CTX ctx;
42
+ } HMAC_SHA512_CTX;
43
+
44
+ void hmac_sha256_Init(HMAC_SHA256_CTX *hctx, const uint8_t *key, const uint32_t keylen);
45
+ void hmac_sha256_Update(HMAC_SHA256_CTX *hctx, const uint8_t *msg, const uint32_t msglen);
46
+ void hmac_sha256_Final(HMAC_SHA256_CTX *hctx, uint8_t *hmac);
47
+ void hmac_sha256(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac);
48
+ void hmac_sha256_prepare(const uint8_t *key, const uint32_t keylen, uint32_t *opad_digest, uint32_t *ipad_digest);
49
+
50
+ void hmac_sha512_Init(HMAC_SHA512_CTX *hctx, const uint8_t *key, const uint32_t keylen);
51
+ void hmac_sha512_Update(HMAC_SHA512_CTX *hctx, const uint8_t *msg, const uint32_t msglen);
52
+ void hmac_sha512_Final(HMAC_SHA512_CTX *hctx, uint8_t *hmac);
53
+ void hmac_sha512(const uint8_t *key, const uint32_t keylen, const uint8_t *msg, const uint32_t msglen, uint8_t *hmac);
54
+ void hmac_sha512_prepare(const uint8_t *key, const uint32_t keylen, uint64_t *opad_digest, uint64_t *ipad_digest);
55
+
56
+ #ifdef __cplusplus
57
+ } /* extern "C" */
58
+ #endif
59
+
60
+ #endif
@@ -0,0 +1,16 @@
1
+ #ifndef __MEMZERO_H__
2
+ #define __MEMZERO_H__
3
+
4
+ #include <stddef.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ void memzero(void *s, size_t n);
11
+
12
+ #ifdef __cplusplus
13
+ } /* extern "C" */
14
+ #endif
15
+
16
+ #endif
@@ -0,0 +1,42 @@
1
+ // Copyright (c) 2014-2018, The Monero Project
2
+ //
3
+ // All rights reserved.
4
+ //
5
+ // Redistribution and use in source and binary forms, with or without modification, are
6
+ // permitted provided that the following conditions are met:
7
+ //
8
+ // 1. Redistributions of source code must retain the above copyright notice, this list of
9
+ // conditions and the following disclaimer.
10
+ //
11
+ // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12
+ // of conditions and the following disclaimer in the documentation and/or other
13
+ // materials provided with the distribution.
14
+ //
15
+ // 3. Neither the name of the copyright holder nor the names of its contributors may be
16
+ // used to endorse or promote products derived from this software without specific
17
+ // prior written permission.
18
+ //
19
+ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20
+ // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21
+ // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22
+ // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23
+ // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24
+ // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
+ // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26
+ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27
+ // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+ //
29
+ // Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
30
+
31
+ #ifndef __XMR_BASE58_H__
32
+ #define __XMR_BASE58_H__
33
+
34
+ #include <stdbool.h>
35
+ #include <TrezorCrypto/hasher.h>
36
+
37
+ int xmr_base58_addr_encode_check(uint64_t tag, const uint8_t *data, size_t binsz, char *b58, size_t b58sz);
38
+ int xmr_base58_addr_decode_check(const char *addr, size_t sz, uint64_t *tag, void *data, size_t datalen);
39
+ bool xmr_base58_encode(char *b58, size_t *b58sz, const void *data, size_t binsz);
40
+ bool xmr_base58_decode(const char *b58, size_t b58sz, void *data, size_t *binsz);
41
+
42
+ #endif
@@ -0,0 +1,13 @@
1
+ //
2
+ // Created by Dusan Klinec on 10/05/2018.
3
+ //
4
+
5
+ #ifndef TREZOR_CRYPTO_MONERO_H
6
+ #define TREZOR_CRYPTO_MONERO_H
7
+
8
+ #include "base58.h"
9
+ #include "serialize.h"
10
+ #include "xmr.h"
11
+ #include "range_proof.h"
12
+
13
+ #endif //TREZOR_CRYPTO_MONERO_H
@@ -0,0 +1,30 @@
1
+ //
2
+ // Created by Dusan Klinec on 10/05/2018.
3
+ //
4
+
5
+ #ifndef TREZOR_CRYPTO_RANGE_PROOF_H
6
+ #define TREZOR_CRYPTO_RANGE_PROOF_H
7
+
8
+ #include "xmr.h"
9
+ #define XMR_ATOMS 64
10
+
11
+ typedef uint64_t xmr_amount;
12
+ typedef xmr_key_t xmr_key64_t[64];
13
+
14
+ typedef struct xmr_boro_sig {
15
+ xmr_key64_t s0;
16
+ xmr_key64_t s1;
17
+ xmr_key_t ee;
18
+ } xmr_boro_sig_t;
19
+
20
+ typedef struct range_sig {
21
+ xmr_boro_sig_t asig;
22
+ xmr_key64_t Ci;
23
+ } xmr_range_sig_t;
24
+
25
+
26
+ void xmr_gen_range_sig(xmr_range_sig_t * sig, ge25519 * C, bignum256modm mask, xmr_amount amount, bignum256modm * last_mask);
27
+ void xmr_gen_range_sig_ex(xmr_range_sig_t * sig, ge25519 * C, bignum256modm mask, xmr_amount amount, bignum256modm * last_mask,
28
+ bignum256modm ai[64], bignum256modm alpha[64]);
29
+
30
+ #endif //TREZOR_CRYPTO_RANGE_PROOF_H