@onekeyfe/react-native-lite-card 6.7.0-alpha.409 → 6.7.0-alpha.411

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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,43 @@
1
+ /**
2
+ * Copyright (c) 2013-2014 Pavol Rusnak
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the "Software"),
6
+ * to deal in the Software without restriction, including without limitation
7
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
+ * and/or sell copies of the Software, and to permit persons to whom the
9
+ * Software is furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included
12
+ * in all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
18
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
+ * OTHER DEALINGS IN THE SOFTWARE.
21
+ */
22
+
23
+ #ifndef __OPTIONS_H__
24
+ #define __OPTIONS_H__
25
+
26
+ // implement BIP32 caching
27
+ #ifndef USE_BIP32_CACHE
28
+ #define USE_BIP32_CACHE 0
29
+ #define BIP32_CACHE_SIZE 10
30
+ #define BIP32_CACHE_MAXDEPTH 8
31
+ #endif
32
+
33
+ // support constructing BIP32 nodes from ed25519 and curve25519 curves.
34
+ #ifndef USE_BIP32_25519_CURVES
35
+ #define USE_BIP32_25519_CURVES 1
36
+ #endif
37
+
38
+ // add way how to mark confidential data
39
+ #ifndef CONFIDENTIAL
40
+ #define CONFIDENTIAL
41
+ #endif
42
+
43
+ #endif
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
3
+ * Copyright (c) 2013-2014 Pavol Rusnak
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation
8
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ * and/or sell copies of the Software, and to permit persons to whom the
10
+ * Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included
13
+ * in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
19
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
+ * OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ #include <string.h>
25
+ #include <TrezorCrypto/pbkdf2.h>
26
+ #include <TrezorCrypto/hmac.h>
27
+ #include <TrezorCrypto/sha2.h>
28
+ #include <TrezorCrypto/memzero.h>
29
+
30
+ void pbkdf2_hmac_sha256_Init(PBKDF2_HMAC_SHA256_CTX *pctx, const uint8_t *pass, size_t passlen, const uint8_t *salt, size_t saltlen, uint32_t blocknr)
31
+ {
32
+ SHA256_CTX ctx;
33
+ #if BYTE_ORDER == LITTLE_ENDIAN
34
+ REVERSE32(blocknr, blocknr);
35
+ #endif
36
+
37
+ hmac_sha256_prepare(pass, passlen, pctx->odig, pctx->idig);
38
+ memset(pctx->g, 0, sizeof(pctx->g));
39
+ pctx->g[8] = 0x80000000;
40
+ pctx->g[15] = (SHA256_BLOCK_LENGTH + SHA256_DIGEST_LENGTH) * 8;
41
+
42
+ memcpy (ctx.state, pctx->idig, sizeof(pctx->idig));
43
+ ctx.bitcount = SHA256_BLOCK_LENGTH * 8;
44
+ sha256_Update(&ctx, salt, saltlen);
45
+ sha256_Update(&ctx, (uint8_t*)&blocknr, sizeof(blocknr));
46
+ sha256_Final(&ctx, (uint8_t*)pctx->g);
47
+ #if BYTE_ORDER == LITTLE_ENDIAN
48
+ for (uint32_t k = 0; k < SHA256_DIGEST_LENGTH / sizeof(uint32_t); k++) {
49
+ REVERSE32(pctx->g[k], pctx->g[k]);
50
+ }
51
+ #endif
52
+ sha256_Transform(pctx->odig, pctx->g, pctx->g);
53
+ memcpy(pctx->f, pctx->g, SHA256_DIGEST_LENGTH);
54
+ pctx->first = 1;
55
+ }
56
+
57
+ void pbkdf2_hmac_sha256_Update(PBKDF2_HMAC_SHA256_CTX *pctx, uint32_t iterations)
58
+ {
59
+ for (uint32_t i = pctx->first; i < iterations; i++) {
60
+ sha256_Transform(pctx->idig, pctx->g, pctx->g);
61
+ sha256_Transform(pctx->odig, pctx->g, pctx->g);
62
+ for (uint32_t j = 0; j < SHA256_DIGEST_LENGTH/sizeof(uint32_t); j++) {
63
+ pctx->f[j] ^= pctx->g[j];
64
+ }
65
+ }
66
+ pctx->first = 0;
67
+ }
68
+
69
+ void pbkdf2_hmac_sha256_Final(PBKDF2_HMAC_SHA256_CTX *pctx, uint8_t *key)
70
+ {
71
+ #if BYTE_ORDER == LITTLE_ENDIAN
72
+ for (uint32_t k = 0; k < SHA256_DIGEST_LENGTH/sizeof(uint32_t); k++) {
73
+ REVERSE32(pctx->f[k], pctx->f[k]);
74
+ }
75
+ #endif
76
+ memcpy(key, pctx->f, SHA256_DIGEST_LENGTH);
77
+ memzero(pctx, sizeof(PBKDF2_HMAC_SHA256_CTX));
78
+ }
79
+
80
+ void pbkdf2_hmac_sha256(const uint8_t *pass, size_t passlen, const uint8_t *salt, size_t saltlen, uint32_t iterations, uint8_t *key, size_t keylen)
81
+ {
82
+ uint32_t last_block_size = keylen % SHA256_DIGEST_LENGTH;
83
+ uint32_t blocks_count = keylen / SHA256_DIGEST_LENGTH;
84
+ if (last_block_size) {
85
+ blocks_count++;
86
+ } else {
87
+ last_block_size = SHA256_DIGEST_LENGTH;
88
+ }
89
+ for (uint32_t blocknr = 1; blocknr <= blocks_count; blocknr++) {
90
+ PBKDF2_HMAC_SHA256_CTX pctx;
91
+ pbkdf2_hmac_sha256_Init(&pctx, pass, passlen, salt, saltlen, blocknr);
92
+ pbkdf2_hmac_sha256_Update(&pctx, iterations);
93
+ uint8_t digest[SHA256_DIGEST_LENGTH];
94
+ pbkdf2_hmac_sha256_Final(&pctx, digest);
95
+ uint32_t key_offset = (blocknr - 1) * SHA256_DIGEST_LENGTH;
96
+ if (blocknr < blocks_count) {
97
+ memcpy(key + key_offset, digest, SHA256_DIGEST_LENGTH);
98
+ } else {
99
+ memcpy(key + key_offset, digest, last_block_size);
100
+ }
101
+ }
102
+ }
103
+
104
+ void pbkdf2_hmac_sha512_Init(PBKDF2_HMAC_SHA512_CTX *pctx, const uint8_t *pass, size_t passlen, const uint8_t *salt, size_t saltlen, uint32_t blocknr)
105
+ {
106
+ SHA512_CTX ctx;
107
+ #if BYTE_ORDER == LITTLE_ENDIAN
108
+ REVERSE32(blocknr, blocknr);
109
+ #endif
110
+
111
+ hmac_sha512_prepare(pass, passlen, pctx->odig, pctx->idig);
112
+ memset(pctx->g, 0, sizeof(pctx->g));
113
+ pctx->g[8] = 0x8000000000000000;
114
+ pctx->g[15] = (SHA512_BLOCK_LENGTH + SHA512_DIGEST_LENGTH) * 8;
115
+
116
+ memcpy (ctx.state, pctx->idig, sizeof(pctx->idig));
117
+ ctx.bitcount[0] = SHA512_BLOCK_LENGTH * 8;
118
+ ctx.bitcount[1] = 0;
119
+ sha512_Update(&ctx, salt, saltlen);
120
+ sha512_Update(&ctx, (uint8_t*)&blocknr, sizeof(blocknr));
121
+ sha512_Final(&ctx, (uint8_t*)pctx->g);
122
+ #if BYTE_ORDER == LITTLE_ENDIAN
123
+ for (uint32_t k = 0; k < SHA512_DIGEST_LENGTH / sizeof(uint64_t); k++) {
124
+ REVERSE64(pctx->g[k], pctx->g[k]);
125
+ }
126
+ #endif
127
+ sha512_Transform(pctx->odig, pctx->g, pctx->g);
128
+ memcpy(pctx->f, pctx->g, SHA512_DIGEST_LENGTH);
129
+ pctx->first = 1;
130
+ }
131
+
132
+ void pbkdf2_hmac_sha512_Update(PBKDF2_HMAC_SHA512_CTX *pctx, uint32_t iterations)
133
+ {
134
+ for (uint32_t i = pctx->first; i < iterations; i++) {
135
+ sha512_Transform(pctx->idig, pctx->g, pctx->g);
136
+ sha512_Transform(pctx->odig, pctx->g, pctx->g);
137
+ for (uint32_t j = 0; j < SHA512_DIGEST_LENGTH / sizeof(uint64_t); j++) {
138
+ pctx->f[j] ^= pctx->g[j];
139
+ }
140
+ }
141
+ pctx->first = 0;
142
+ }
143
+
144
+ void pbkdf2_hmac_sha512_Final(PBKDF2_HMAC_SHA512_CTX *pctx, uint8_t *key)
145
+ {
146
+ #if BYTE_ORDER == LITTLE_ENDIAN
147
+ for (uint32_t k = 0; k < SHA512_DIGEST_LENGTH/sizeof(uint64_t); k++) {
148
+ REVERSE64(pctx->f[k], pctx->f[k]);
149
+ }
150
+ #endif
151
+ memcpy(key, pctx->f, SHA512_DIGEST_LENGTH);
152
+ memzero(pctx, sizeof(PBKDF2_HMAC_SHA512_CTX));
153
+ }
154
+
155
+ void pbkdf2_hmac_sha512(const uint8_t *pass, size_t passlen, const uint8_t *salt, size_t saltlen, uint32_t iterations, uint8_t *key, size_t keylen)
156
+ {
157
+ uint32_t last_block_size = keylen % SHA512_DIGEST_LENGTH;
158
+ uint32_t blocks_count = keylen / SHA512_DIGEST_LENGTH;
159
+ if (last_block_size) {
160
+ blocks_count++;
161
+ } else {
162
+ last_block_size = SHA512_DIGEST_LENGTH;
163
+ }
164
+ for (uint32_t blocknr = 1; blocknr <= blocks_count; blocknr++) {
165
+ PBKDF2_HMAC_SHA512_CTX pctx;
166
+ pbkdf2_hmac_sha512_Init(&pctx, pass, passlen, salt, saltlen, blocknr);
167
+ pbkdf2_hmac_sha512_Update(&pctx, iterations);
168
+ uint8_t digest[SHA512_DIGEST_LENGTH];
169
+ pbkdf2_hmac_sha512_Final(&pctx, digest);
170
+ uint32_t key_offset = (blocknr - 1) * SHA512_DIGEST_LENGTH;
171
+ if (blocknr < blocks_count) {
172
+ memcpy(key + key_offset, digest, SHA512_DIGEST_LENGTH);
173
+ } else {
174
+ memcpy(key + key_offset, digest, last_block_size);
175
+ }
176
+ }
177
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * Copyright (c) 2013-2014 Tomas Dzetkulic
3
+ * Copyright (c) 2013-2014 Pavol Rusnak
4
+ *
5
+ * Permission is hereby granted, free of charge, to any person obtaining
6
+ * a copy of this software and associated documentation files (the "Software"),
7
+ * to deal in the Software without restriction, including without limitation
8
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
+ * and/or sell copies of the Software, and to permit persons to whom the
10
+ * Software is furnished to do so, subject to the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be included
13
+ * in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
19
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21
+ * OTHER DEALINGS IN THE SOFTWARE.
22
+ */
23
+
24
+ #include <TrezorCrypto/rand.h>
25
+
26
+ #include <fcntl.h>
27
+ #include <sys/types.h>
28
+ #include <sys/uio.h>
29
+ #include <unistd.h>
30
+
31
+ uint32_t random32() {
32
+ int randomData = open("/dev/urandom", O_RDONLY);
33
+ if (randomData < 0) {
34
+ return 0;
35
+ }
36
+
37
+ uint32_t result;
38
+ if (read(randomData, &result, sizeof(result)) < 0) {
39
+ return 0;
40
+ }
41
+
42
+ close(randomData);
43
+
44
+ return result;
45
+ }
46
+
47
+ void random_buffer(uint8_t *buf, size_t len) {
48
+ int randomData = open("/dev/urandom", O_RDONLY);
49
+ read(randomData, buf, len);
50
+ close(randomData);
51
+ }
@@ -0,0 +1,56 @@
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, E1PRESS
15
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
18
+ * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20
+ * OTHER DEALINGS IN THE SOFTWARE.
21
+ */
22
+
23
+ #include <TrezorCrypto/rc4.h>
24
+
25
+ static inline void rc4_swap(RC4_CTX *ctx, uint8_t i, uint8_t j) {
26
+ uint8_t temp = ctx->S[i];
27
+ ctx->S[i] = ctx->S[j];
28
+ ctx->S[j] = temp;
29
+ }
30
+
31
+ void rc4_init(RC4_CTX *ctx, const uint8_t *key, size_t length) {
32
+ ctx->i = 0;
33
+ ctx->j = 0;
34
+
35
+ for (size_t i = 0; i < 256; i++) {
36
+ ctx->S[i] = i;
37
+ }
38
+
39
+ uint8_t j = 0;
40
+ for (size_t i = 0; i < 256; i++) {
41
+ j += ctx->S[i] + key[i % length];
42
+ rc4_swap(ctx, i, j);
43
+ }
44
+ }
45
+
46
+ void rc4_encrypt(RC4_CTX *ctx, uint8_t *buffer, size_t length) {
47
+ for (size_t idx = 0; idx < length; idx++) {
48
+ ctx->i++;
49
+ ctx->j += ctx->S[ctx->i];
50
+
51
+ rc4_swap(ctx, ctx->i, ctx->j);
52
+
53
+ uint8_t K = ctx->S[(ctx->S[ctx->i] + ctx->S[ctx->j]) % 256];
54
+ buffer[idx] ^= K;
55
+ }
56
+ }
@@ -0,0 +1,343 @@
1
+ /*
2
+ * RIPE MD-160 implementation
3
+ *
4
+ * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may
8
+ * not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * This file is part of mbed TLS (https://tls.mbed.org)
20
+ */
21
+
22
+ /*
23
+ * The RIPEMD-160 algorithm was designed by RIPE in 1996
24
+ * http://homes.esat.kuleuven.be/~bosselae/ripemd160.html
25
+ * http://ehash.iaik.tugraz.at/wiki/RIPEMD-160
26
+ */
27
+
28
+ #include <string.h>
29
+
30
+ #include <TrezorCrypto/ripemd160.h>
31
+ #include <TrezorCrypto/memzero.h>
32
+
33
+ /*
34
+ * 32-bit integer manipulation macros (little endian)
35
+ */
36
+ #ifndef GET_UINT32_LE
37
+ #define GET_UINT32_LE(n,b,i) \
38
+ { \
39
+ (n) = ( (uint32_t) (b)[(i) ] ) \
40
+ | ( (uint32_t) (b)[(i) + 1] << 8 ) \
41
+ | ( (uint32_t) (b)[(i) + 2] << 16 ) \
42
+ | ( (uint32_t) (b)[(i) + 3] << 24 ); \
43
+ }
44
+ #endif
45
+
46
+ #ifndef PUT_UINT32_LE
47
+ #define PUT_UINT32_LE(n,b,i) \
48
+ { \
49
+ (b)[(i) ] = (uint8_t) ( ( (n) ) & 0xFF ); \
50
+ (b)[(i) + 1] = (uint8_t) ( ( (n) >> 8 ) & 0xFF ); \
51
+ (b)[(i) + 2] = (uint8_t) ( ( (n) >> 16 ) & 0xFF ); \
52
+ (b)[(i) + 3] = (uint8_t) ( ( (n) >> 24 ) & 0xFF ); \
53
+ }
54
+ #endif
55
+
56
+ /*
57
+ * RIPEMD-160 context setup
58
+ */
59
+ void ripemd160_Init(RIPEMD160_CTX *ctx)
60
+ {
61
+ memset(ctx, 0, sizeof(RIPEMD160_CTX));
62
+ ctx->total[0] = 0;
63
+ ctx->total[1] = 0;
64
+ ctx->state[0] = 0x67452301;
65
+ ctx->state[1] = 0xEFCDAB89;
66
+ ctx->state[2] = 0x98BADCFE;
67
+ ctx->state[3] = 0x10325476;
68
+ ctx->state[4] = 0xC3D2E1F0;
69
+ }
70
+
71
+ #if !defined(MBEDTLS_RIPEMD160_PROCESS_ALT)
72
+ /*
73
+ * Process one block
74
+ */
75
+ void ripemd160_process( RIPEMD160_CTX *ctx, const uint8_t data[RIPEMD160_BLOCK_LENGTH] )
76
+ {
77
+ uint32_t A, B, C, D, E, Ap, Bp, Cp, Dp, Ep, X[16];
78
+
79
+ GET_UINT32_LE( X[ 0], data, 0 );
80
+ GET_UINT32_LE( X[ 1], data, 4 );
81
+ GET_UINT32_LE( X[ 2], data, 8 );
82
+ GET_UINT32_LE( X[ 3], data, 12 );
83
+ GET_UINT32_LE( X[ 4], data, 16 );
84
+ GET_UINT32_LE( X[ 5], data, 20 );
85
+ GET_UINT32_LE( X[ 6], data, 24 );
86
+ GET_UINT32_LE( X[ 7], data, 28 );
87
+ GET_UINT32_LE( X[ 8], data, 32 );
88
+ GET_UINT32_LE( X[ 9], data, 36 );
89
+ GET_UINT32_LE( X[10], data, 40 );
90
+ GET_UINT32_LE( X[11], data, 44 );
91
+ GET_UINT32_LE( X[12], data, 48 );
92
+ GET_UINT32_LE( X[13], data, 52 );
93
+ GET_UINT32_LE( X[14], data, 56 );
94
+ GET_UINT32_LE( X[15], data, 60 );
95
+
96
+ A = Ap = ctx->state[0];
97
+ B = Bp = ctx->state[1];
98
+ C = Cp = ctx->state[2];
99
+ D = Dp = ctx->state[3];
100
+ E = Ep = ctx->state[4];
101
+
102
+ #define F1( x, y, z ) ( x ^ y ^ z )
103
+ #define F2( x, y, z ) ( ( x & y ) | ( ~x & z ) )
104
+ #define F3( x, y, z ) ( ( x | ~y ) ^ z )
105
+ #define F4( x, y, z ) ( ( x & z ) | ( y & ~z ) )
106
+ #define F5( x, y, z ) ( x ^ ( y | ~z ) )
107
+
108
+ #define S( x, n ) ( ( x << n ) | ( x >> (32 - n) ) )
109
+
110
+ #define P( a, b, c, d, e, r, s, f, k ) \
111
+ a += f( b, c, d ) + X[r] + k; \
112
+ a = S( a, s ) + e; \
113
+ c = S( c, 10 );
114
+
115
+ #define P2( a, b, c, d, e, r, s, rp, sp ) \
116
+ P( a, b, c, d, e, r, s, F, K ); \
117
+ P( a ## p, b ## p, c ## p, d ## p, e ## p, rp, sp, Fp, Kp );
118
+
119
+ #define F F1
120
+ #define K 0x00000000
121
+ #define Fp F5
122
+ #define Kp 0x50A28BE6
123
+ P2( A, B, C, D, E, 0, 11, 5, 8 );
124
+ P2( E, A, B, C, D, 1, 14, 14, 9 );
125
+ P2( D, E, A, B, C, 2, 15, 7, 9 );
126
+ P2( C, D, E, A, B, 3, 12, 0, 11 );
127
+ P2( B, C, D, E, A, 4, 5, 9, 13 );
128
+ P2( A, B, C, D, E, 5, 8, 2, 15 );
129
+ P2( E, A, B, C, D, 6, 7, 11, 15 );
130
+ P2( D, E, A, B, C, 7, 9, 4, 5 );
131
+ P2( C, D, E, A, B, 8, 11, 13, 7 );
132
+ P2( B, C, D, E, A, 9, 13, 6, 7 );
133
+ P2( A, B, C, D, E, 10, 14, 15, 8 );
134
+ P2( E, A, B, C, D, 11, 15, 8, 11 );
135
+ P2( D, E, A, B, C, 12, 6, 1, 14 );
136
+ P2( C, D, E, A, B, 13, 7, 10, 14 );
137
+ P2( B, C, D, E, A, 14, 9, 3, 12 );
138
+ P2( A, B, C, D, E, 15, 8, 12, 6 );
139
+ #undef F
140
+ #undef K
141
+ #undef Fp
142
+ #undef Kp
143
+
144
+ #define F F2
145
+ #define K 0x5A827999
146
+ #define Fp F4
147
+ #define Kp 0x5C4DD124
148
+ P2( E, A, B, C, D, 7, 7, 6, 9 );
149
+ P2( D, E, A, B, C, 4, 6, 11, 13 );
150
+ P2( C, D, E, A, B, 13, 8, 3, 15 );
151
+ P2( B, C, D, E, A, 1, 13, 7, 7 );
152
+ P2( A, B, C, D, E, 10, 11, 0, 12 );
153
+ P2( E, A, B, C, D, 6, 9, 13, 8 );
154
+ P2( D, E, A, B, C, 15, 7, 5, 9 );
155
+ P2( C, D, E, A, B, 3, 15, 10, 11 );
156
+ P2( B, C, D, E, A, 12, 7, 14, 7 );
157
+ P2( A, B, C, D, E, 0, 12, 15, 7 );
158
+ P2( E, A, B, C, D, 9, 15, 8, 12 );
159
+ P2( D, E, A, B, C, 5, 9, 12, 7 );
160
+ P2( C, D, E, A, B, 2, 11, 4, 6 );
161
+ P2( B, C, D, E, A, 14, 7, 9, 15 );
162
+ P2( A, B, C, D, E, 11, 13, 1, 13 );
163
+ P2( E, A, B, C, D, 8, 12, 2, 11 );
164
+ #undef F
165
+ #undef K
166
+ #undef Fp
167
+ #undef Kp
168
+
169
+ #define F F3
170
+ #define K 0x6ED9EBA1
171
+ #define Fp F3
172
+ #define Kp 0x6D703EF3
173
+ P2( D, E, A, B, C, 3, 11, 15, 9 );
174
+ P2( C, D, E, A, B, 10, 13, 5, 7 );
175
+ P2( B, C, D, E, A, 14, 6, 1, 15 );
176
+ P2( A, B, C, D, E, 4, 7, 3, 11 );
177
+ P2( E, A, B, C, D, 9, 14, 7, 8 );
178
+ P2( D, E, A, B, C, 15, 9, 14, 6 );
179
+ P2( C, D, E, A, B, 8, 13, 6, 6 );
180
+ P2( B, C, D, E, A, 1, 15, 9, 14 );
181
+ P2( A, B, C, D, E, 2, 14, 11, 12 );
182
+ P2( E, A, B, C, D, 7, 8, 8, 13 );
183
+ P2( D, E, A, B, C, 0, 13, 12, 5 );
184
+ P2( C, D, E, A, B, 6, 6, 2, 14 );
185
+ P2( B, C, D, E, A, 13, 5, 10, 13 );
186
+ P2( A, B, C, D, E, 11, 12, 0, 13 );
187
+ P2( E, A, B, C, D, 5, 7, 4, 7 );
188
+ P2( D, E, A, B, C, 12, 5, 13, 5 );
189
+ #undef F
190
+ #undef K
191
+ #undef Fp
192
+ #undef Kp
193
+
194
+ #define F F4
195
+ #define K 0x8F1BBCDC
196
+ #define Fp F2
197
+ #define Kp 0x7A6D76E9
198
+ P2( C, D, E, A, B, 1, 11, 8, 15 );
199
+ P2( B, C, D, E, A, 9, 12, 6, 5 );
200
+ P2( A, B, C, D, E, 11, 14, 4, 8 );
201
+ P2( E, A, B, C, D, 10, 15, 1, 11 );
202
+ P2( D, E, A, B, C, 0, 14, 3, 14 );
203
+ P2( C, D, E, A, B, 8, 15, 11, 14 );
204
+ P2( B, C, D, E, A, 12, 9, 15, 6 );
205
+ P2( A, B, C, D, E, 4, 8, 0, 14 );
206
+ P2( E, A, B, C, D, 13, 9, 5, 6 );
207
+ P2( D, E, A, B, C, 3, 14, 12, 9 );
208
+ P2( C, D, E, A, B, 7, 5, 2, 12 );
209
+ P2( B, C, D, E, A, 15, 6, 13, 9 );
210
+ P2( A, B, C, D, E, 14, 8, 9, 12 );
211
+ P2( E, A, B, C, D, 5, 6, 7, 5 );
212
+ P2( D, E, A, B, C, 6, 5, 10, 15 );
213
+ P2( C, D, E, A, B, 2, 12, 14, 8 );
214
+ #undef F
215
+ #undef K
216
+ #undef Fp
217
+ #undef Kp
218
+
219
+ #define F F5
220
+ #define K 0xA953FD4E
221
+ #define Fp F1
222
+ #define Kp 0x00000000
223
+ P2( B, C, D, E, A, 4, 9, 12, 8 );
224
+ P2( A, B, C, D, E, 0, 15, 15, 5 );
225
+ P2( E, A, B, C, D, 5, 5, 10, 12 );
226
+ P2( D, E, A, B, C, 9, 11, 4, 9 );
227
+ P2( C, D, E, A, B, 7, 6, 1, 12 );
228
+ P2( B, C, D, E, A, 12, 8, 5, 5 );
229
+ P2( A, B, C, D, E, 2, 13, 8, 14 );
230
+ P2( E, A, B, C, D, 10, 12, 7, 6 );
231
+ P2( D, E, A, B, C, 14, 5, 6, 8 );
232
+ P2( C, D, E, A, B, 1, 12, 2, 13 );
233
+ P2( B, C, D, E, A, 3, 13, 13, 6 );
234
+ P2( A, B, C, D, E, 8, 14, 14, 5 );
235
+ P2( E, A, B, C, D, 11, 11, 0, 15 );
236
+ P2( D, E, A, B, C, 6, 8, 3, 13 );
237
+ P2( C, D, E, A, B, 15, 5, 9, 11 );
238
+ P2( B, C, D, E, A, 13, 6, 11, 11 );
239
+ #undef F
240
+ #undef K
241
+ #undef Fp
242
+ #undef Kp
243
+
244
+ C = ctx->state[1] + C + Dp;
245
+ ctx->state[1] = ctx->state[2] + D + Ep;
246
+ ctx->state[2] = ctx->state[3] + E + Ap;
247
+ ctx->state[3] = ctx->state[4] + A + Bp;
248
+ ctx->state[4] = ctx->state[0] + B + Cp;
249
+ ctx->state[0] = C;
250
+ }
251
+ #endif /* !MBEDTLS_RIPEMD160_PROCESS_ALT */
252
+
253
+ /*
254
+ * RIPEMD-160 process buffer
255
+ */
256
+ void ripemd160_Update( RIPEMD160_CTX *ctx, const uint8_t *input, uint32_t ilen )
257
+ {
258
+ uint32_t fill;
259
+ uint32_t left;
260
+
261
+ if( ilen == 0 )
262
+ return;
263
+
264
+ left = ctx->total[0] & 0x3F;
265
+ fill = RIPEMD160_BLOCK_LENGTH - left;
266
+
267
+ ctx->total[0] += (uint32_t) ilen;
268
+ ctx->total[0] &= 0xFFFFFFFF;
269
+
270
+ if( ctx->total[0] < (uint32_t) ilen )
271
+ ctx->total[1]++;
272
+
273
+ if( left && ilen >= fill )
274
+ {
275
+ memcpy( (void *) (ctx->buffer + left), input, fill );
276
+ ripemd160_process( ctx, ctx->buffer );
277
+ input += fill;
278
+ ilen -= fill;
279
+ left = 0;
280
+ }
281
+
282
+ while( ilen >= RIPEMD160_BLOCK_LENGTH )
283
+ {
284
+ ripemd160_process( ctx, input );
285
+ input += RIPEMD160_BLOCK_LENGTH;
286
+ ilen -= RIPEMD160_BLOCK_LENGTH;
287
+ }
288
+
289
+ if( ilen > 0 )
290
+ {
291
+ memcpy( (void *) (ctx->buffer + left), input, ilen );
292
+ }
293
+ }
294
+
295
+ static const uint8_t ripemd160_padding[RIPEMD160_BLOCK_LENGTH] =
296
+ {
297
+ 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
298
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
299
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
300
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
301
+ };
302
+
303
+ /*
304
+ * RIPEMD-160 final digest
305
+ */
306
+ void ripemd160_Final( RIPEMD160_CTX *ctx, uint8_t output[RIPEMD160_DIGEST_LENGTH] )
307
+ {
308
+ uint32_t last, padn;
309
+ uint32_t high, low;
310
+ uint8_t msglen[8];
311
+
312
+ high = ( ctx->total[0] >> 29 )
313
+ | ( ctx->total[1] << 3 );
314
+ low = ( ctx->total[0] << 3 );
315
+
316
+ PUT_UINT32_LE( low, msglen, 0 );
317
+ PUT_UINT32_LE( high, msglen, 4 );
318
+
319
+ last = ctx->total[0] & 0x3F;
320
+ padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
321
+
322
+ ripemd160_Update( ctx, ripemd160_padding, padn );
323
+ ripemd160_Update( ctx, msglen, 8 );
324
+
325
+ PUT_UINT32_LE( ctx->state[0], output, 0 );
326
+ PUT_UINT32_LE( ctx->state[1], output, 4 );
327
+ PUT_UINT32_LE( ctx->state[2], output, 8 );
328
+ PUT_UINT32_LE( ctx->state[3], output, 12 );
329
+ PUT_UINT32_LE( ctx->state[4], output, 16 );
330
+
331
+ memzero(ctx, sizeof(RIPEMD160_CTX));
332
+ }
333
+
334
+ /*
335
+ * output = RIPEMD-160( input buffer )
336
+ */
337
+ void ripemd160(const uint8_t *msg, uint32_t msg_len, uint8_t hash[RIPEMD160_DIGEST_LENGTH])
338
+ {
339
+ RIPEMD160_CTX ctx;
340
+ ripemd160_Init( &ctx );
341
+ ripemd160_Update( &ctx, msg, msg_len );
342
+ ripemd160_Final( &ctx, hash );
343
+ }