react-native-nitro-bsx 0.0.0-stage → 0.2.35

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 (931) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +7 -2
  3. package/android/CMakeLists.txt +28 -0
  4. package/android/build.gradle +99 -0
  5. package/android/src/main/AndroidManifest.xml +35 -0
  6. package/android/src/main/cpp/cpp-adapter.cpp +12 -0
  7. package/android/src/main/java/com/nitrobsx/BSXAlarmReceiver.kt +29 -0
  8. package/android/src/main/java/com/nitrobsx/BSXAlarmScheduler.kt +112 -0
  9. package/android/src/main/java/com/nitrobsx/BSXForegroundService.kt +78 -0
  10. package/android/src/main/java/com/nitrobsx/BSXNotifications.kt +47 -0
  11. package/android/src/main/java/com/nitrobsx/BSXServiceController.kt +90 -0
  12. package/android/src/main/java/com/nitrobsx/BSXWakeWorker.kt +136 -0
  13. package/android/src/main/java/com/nitrobsx/HeadlessJsTaskSupportShim.kt +41 -0
  14. package/android/src/main/java/com/nitrobsx/NitroBSXPackage.kt +28 -0
  15. package/android/src/main/res/drawable/bsx_ic_stat_swap.xml +9 -0
  16. package/cpp/BSXContext.cpp +263 -0
  17. package/cpp/BSXContext.h +49 -0
  18. package/cpp/BSXModule.cpp +21191 -0
  19. package/cpp/BSXModule.h +1523 -0
  20. package/cpp/CMakeLists.txt +463 -0
  21. package/cpp/HybridNitroBSX.cpp +1483 -0
  22. package/cpp/HybridNitroBSX.hpp +173 -0
  23. package/cpp/arith_uint256.cpp +232 -0
  24. package/cpp/arith_uint256.h +277 -0
  25. package/cpp/bsx/event.cpp +48 -0
  26. package/cpp/bsx/event.h +29 -0
  27. package/cpp/bsx/swap.h +293 -0
  28. package/cpp/bsx/types.cpp +486 -0
  29. package/cpp/bsx/types.h +308 -0
  30. package/cpp/bsx_db.cpp +4951 -0
  31. package/cpp/bsx_db.h +465 -0
  32. package/cpp/chain_client.h +143 -0
  33. package/cpp/cmake/GenVersion.cmake +52 -0
  34. package/cpp/coin_config.h.in +12 -0
  35. package/cpp/coins/block_index.cpp +33 -0
  36. package/cpp/coins/block_index.h +35 -0
  37. package/cpp/coins/btc/chainparams.cpp +70 -0
  38. package/cpp/coins/btc/chainparams.h +23 -0
  39. package/cpp/coins/btc/interface.h +30 -0
  40. package/cpp/coins/btc_base/interface.cpp +2200 -0
  41. package/cpp/coins/btc_base/interface.h +225 -0
  42. package/cpp/coins/btc_base/primitives.cpp +560 -0
  43. package/cpp/coins/btc_base/primitives.h +157 -0
  44. package/cpp/coins/btc_base/psbt.cpp +150 -0
  45. package/cpp/coins/btc_base/psbt.h +52 -0
  46. package/cpp/coins/btc_base/script.cpp +304 -0
  47. package/cpp/coins/btc_base/script.h +181 -0
  48. package/cpp/coins/chainparams.cpp +47 -0
  49. package/cpp/coins/chainparams.h +58 -0
  50. package/cpp/coins/firo/chainparams.cpp +52 -0
  51. package/cpp/coins/firo/chainparams.h +24 -0
  52. package/cpp/coins/firo/firo.cpp +118 -0
  53. package/cpp/coins/firo/firo.h +79 -0
  54. package/cpp/coins/firo/primitives.cpp +109 -0
  55. package/cpp/coins/firo/primitives.h +47 -0
  56. package/cpp/coins/interface.cpp +1815 -0
  57. package/cpp/coins/interface.h +554 -0
  58. package/cpp/coins/ltc/chainparams.cpp +70 -0
  59. package/cpp/coins/ltc/chainparams.h +22 -0
  60. package/cpp/coins/ltc/ltc.cpp +69 -0
  61. package/cpp/coins/ltc/ltc.h +82 -0
  62. package/cpp/coins/ltc/primitives.cpp +20 -0
  63. package/cpp/coins/ltc/primitives.h +18 -0
  64. package/cpp/coins/part/chainparams.cpp +89 -0
  65. package/cpp/coins/part/chainparams.h +47 -0
  66. package/cpp/coins/part/part.cpp +905 -0
  67. package/cpp/coins/part/part.h +164 -0
  68. package/cpp/coins/part/primitives.cpp +548 -0
  69. package/cpp/coins/part/primitives.h +187 -0
  70. package/cpp/coins/part/stake.cpp +330 -0
  71. package/cpp/coins/part/stake.h +92 -0
  72. package/cpp/coins/primitives.h +125 -0
  73. package/cpp/coins/registry.cpp +99 -0
  74. package/cpp/coins/registry.h +32 -0
  75. package/cpp/coins/script.h +18 -0
  76. package/cpp/coins/types.cpp +60 -0
  77. package/cpp/coins/types.h +41 -0
  78. package/cpp/coins/xmr/chainparams.cpp +28 -0
  79. package/cpp/coins/xmr/chainparams.h +24 -0
  80. package/cpp/coins/xmr/tx.cpp +670 -0
  81. package/cpp/coins/xmr/tx.h +77 -0
  82. package/cpp/coins/xmr/xmr.cpp +639 -0
  83. package/cpp/coins/xmr/xmr.h +223 -0
  84. package/cpp/compat/byteswap.h +74 -0
  85. package/cpp/compat/endian.h +98 -0
  86. package/cpp/compat/mbedtls/threading_alt.h +20 -0
  87. package/cpp/compat/sockets.h +160 -0
  88. package/cpp/contrib/mbedtls/CMakeLists.txt +566 -0
  89. package/cpp/contrib/mbedtls/LICENSE +553 -0
  90. package/cpp/contrib/mbedtls/cmake/MbedTLSConfig.cmake.in +3 -0
  91. package/cpp/contrib/mbedtls/doxygen/input/doc_encdec.h +52 -0
  92. package/cpp/contrib/mbedtls/doxygen/input/doc_hashing.h +30 -0
  93. package/cpp/contrib/mbedtls/doxygen/input/doc_mainpage.h +52 -0
  94. package/cpp/contrib/mbedtls/doxygen/input/doc_rng.h +27 -0
  95. package/cpp/contrib/mbedtls/doxygen/input/doc_ssltls.h +37 -0
  96. package/cpp/contrib/mbedtls/doxygen/input/doc_tcpip.h +32 -0
  97. package/cpp/contrib/mbedtls/doxygen/input/doc_x509.h +31 -0
  98. package/cpp/contrib/mbedtls/doxygen/mbedtls.doxyfile +56 -0
  99. package/cpp/contrib/mbedtls/framework/CMakeLists.txt +1 -0
  100. package/cpp/contrib/mbedtls/framework/LICENSE +553 -0
  101. package/cpp/contrib/mbedtls/include/CMakeLists.txt +21 -0
  102. package/cpp/contrib/mbedtls/include/mbedtls/build_info.h +93 -0
  103. package/cpp/contrib/mbedtls/include/mbedtls/debug.h +120 -0
  104. package/cpp/contrib/mbedtls/include/mbedtls/error.h +39 -0
  105. package/cpp/contrib/mbedtls/include/mbedtls/mbedtls_config.h +1189 -0
  106. package/cpp/contrib/mbedtls/include/mbedtls/net_sockets.h +299 -0
  107. package/cpp/contrib/mbedtls/include/mbedtls/oid.h +304 -0
  108. package/cpp/contrib/mbedtls/include/mbedtls/pkcs7.h +250 -0
  109. package/cpp/contrib/mbedtls/include/mbedtls/private/config_adjust_ssl.h +84 -0
  110. package/cpp/contrib/mbedtls/include/mbedtls/private/config_adjust_x509.h +35 -0
  111. package/cpp/contrib/mbedtls/include/mbedtls/ssl.h +5622 -0
  112. package/cpp/contrib/mbedtls/include/mbedtls/ssl_cache.h +187 -0
  113. package/cpp/contrib/mbedtls/include/mbedtls/ssl_ciphersuites.h +303 -0
  114. package/cpp/contrib/mbedtls/include/mbedtls/ssl_cookie.h +90 -0
  115. package/cpp/contrib/mbedtls/include/mbedtls/ssl_ticket.h +186 -0
  116. package/cpp/contrib/mbedtls/include/mbedtls/timing.h +105 -0
  117. package/cpp/contrib/mbedtls/include/mbedtls/version.h +69 -0
  118. package/cpp/contrib/mbedtls/include/mbedtls/x509.h +503 -0
  119. package/cpp/contrib/mbedtls/include/mbedtls/x509_crl.h +180 -0
  120. package/cpp/contrib/mbedtls/include/mbedtls/x509_crt.h +1174 -0
  121. package/cpp/contrib/mbedtls/include/mbedtls/x509_csr.h +368 -0
  122. package/cpp/contrib/mbedtls/library/CMakeLists.txt +375 -0
  123. package/cpp/contrib/mbedtls/library/Makefile +334 -0
  124. package/cpp/contrib/mbedtls/library/debug.c +285 -0
  125. package/cpp/contrib/mbedtls/library/debug_internal.h +108 -0
  126. package/cpp/contrib/mbedtls/library/error.c +505 -0
  127. package/cpp/contrib/mbedtls/library/mbedtls_check_config.h +376 -0
  128. package/cpp/contrib/mbedtls/library/mbedtls_common.h +51 -0
  129. package/cpp/contrib/mbedtls/library/mbedtls_config.c +40 -0
  130. package/cpp/contrib/mbedtls/library/mbedtls_config_check_before.h +1769 -0
  131. package/cpp/contrib/mbedtls/library/mbedtls_config_check_final.h +12 -0
  132. package/cpp/contrib/mbedtls/library/mbedtls_config_check_user.h +2436 -0
  133. package/cpp/contrib/mbedtls/library/mbedtls_platform_requirements.h +55 -0
  134. package/cpp/contrib/mbedtls/library/mbedtls_utils.h +23 -0
  135. package/cpp/contrib/mbedtls/library/mps_common.h +181 -0
  136. package/cpp/contrib/mbedtls/library/mps_error.h +89 -0
  137. package/cpp/contrib/mbedtls/library/mps_reader.c +538 -0
  138. package/cpp/contrib/mbedtls/library/mps_reader.h +366 -0
  139. package/cpp/contrib/mbedtls/library/mps_trace.c +112 -0
  140. package/cpp/contrib/mbedtls/library/mps_trace.h +154 -0
  141. package/cpp/contrib/mbedtls/library/net_sockets.c +684 -0
  142. package/cpp/contrib/mbedtls/library/pkcs7.c +784 -0
  143. package/cpp/contrib/mbedtls/library/ssl_cache.c +409 -0
  144. package/cpp/contrib/mbedtls/library/ssl_ciphersuites.c +996 -0
  145. package/cpp/contrib/mbedtls/library/ssl_ciphersuites_internal.h +108 -0
  146. package/cpp/contrib/mbedtls/library/ssl_client.c +1019 -0
  147. package/cpp/contrib/mbedtls/library/ssl_client.h +18 -0
  148. package/cpp/contrib/mbedtls/library/ssl_cookie.c +251 -0
  149. package/cpp/contrib/mbedtls/library/ssl_debug_helpers.h +83 -0
  150. package/cpp/contrib/mbedtls/library/ssl_debug_helpers_generated.c +243 -0
  151. package/cpp/contrib/mbedtls/library/ssl_misc.h +2851 -0
  152. package/cpp/contrib/mbedtls/library/ssl_msg.c +6275 -0
  153. package/cpp/contrib/mbedtls/library/ssl_ticket.c +453 -0
  154. package/cpp/contrib/mbedtls/library/ssl_tls.c +9048 -0
  155. package/cpp/contrib/mbedtls/library/ssl_tls12_client.c +3054 -0
  156. package/cpp/contrib/mbedtls/library/ssl_tls12_server.c +3546 -0
  157. package/cpp/contrib/mbedtls/library/ssl_tls13_client.c +3202 -0
  158. package/cpp/contrib/mbedtls/library/ssl_tls13_generic.c +1773 -0
  159. package/cpp/contrib/mbedtls/library/ssl_tls13_invasive.h +23 -0
  160. package/cpp/contrib/mbedtls/library/ssl_tls13_keys.c +1860 -0
  161. package/cpp/contrib/mbedtls/library/ssl_tls13_keys.h +668 -0
  162. package/cpp/contrib/mbedtls/library/ssl_tls13_server.c +3602 -0
  163. package/cpp/contrib/mbedtls/library/timing.c +76 -0
  164. package/cpp/contrib/mbedtls/library/version.c +30 -0
  165. package/cpp/contrib/mbedtls/library/version_features.c +244 -0
  166. package/cpp/contrib/mbedtls/library/x509.c +1848 -0
  167. package/cpp/contrib/mbedtls/library/x509_create.c +747 -0
  168. package/cpp/contrib/mbedtls/library/x509_crl.c +701 -0
  169. package/cpp/contrib/mbedtls/library/x509_crt.c +3278 -0
  170. package/cpp/contrib/mbedtls/library/x509_csr.c +642 -0
  171. package/cpp/contrib/mbedtls/library/x509_internal.h +97 -0
  172. package/cpp/contrib/mbedtls/library/x509_oid.c +603 -0
  173. package/cpp/contrib/mbedtls/library/x509_oid.h +150 -0
  174. package/cpp/contrib/mbedtls/library/x509write.c +171 -0
  175. package/cpp/contrib/mbedtls/library/x509write_crt.c +637 -0
  176. package/cpp/contrib/mbedtls/library/x509write_csr.c +317 -0
  177. package/cpp/contrib/mbedtls/pkgconfig/CMakeLists.txt +25 -0
  178. package/cpp/contrib/mbedtls/pkgconfig/JoinPaths.cmake +27 -0
  179. package/cpp/contrib/mbedtls/pkgconfig/mbedcrypto.pc.in +10 -0
  180. package/cpp/contrib/mbedtls/pkgconfig/mbedtls.pc.in +11 -0
  181. package/cpp/contrib/mbedtls/pkgconfig/mbedx509.pc.in +11 -0
  182. package/cpp/contrib/mbedtls/tf-psa-crypto/CMakeLists.txt +584 -0
  183. package/cpp/contrib/mbedtls/tf-psa-crypto/LICENSE +552 -0
  184. package/cpp/contrib/mbedtls/tf-psa-crypto/cmake/TF-PSA-CryptoConfig.cmake.in +3 -0
  185. package/cpp/contrib/mbedtls/tf-psa-crypto/core/CMakeLists.txt +193 -0
  186. package/cpp/contrib/mbedtls/tf-psa-crypto/core/alignment.h +700 -0
  187. package/cpp/contrib/mbedtls/tf-psa-crypto/core/check_crypto_config.h +111 -0
  188. package/cpp/contrib/mbedtls/tf-psa-crypto/core/crypto-library.make +57 -0
  189. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto.c +9820 -0
  190. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_client.c +22 -0
  191. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_core.h +972 -0
  192. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_core_common.h +52 -0
  193. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_driver_wrappers.h +3395 -0
  194. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_driver_wrappers_no_static.c +247 -0
  195. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_invasive.h +85 -0
  196. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_its.h +131 -0
  197. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_random.c +168 -0
  198. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_random.h +72 -0
  199. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_random_impl.h +215 -0
  200. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_slot_management.c +998 -0
  201. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_slot_management.h +330 -0
  202. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_storage.c +400 -0
  203. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_crypto_storage.h +201 -0
  204. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_its_file.c +254 -0
  205. package/cpp/contrib/mbedtls/tf-psa-crypto/core/psa_util.c +295 -0
  206. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_check_config.h +598 -0
  207. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_common.h +628 -0
  208. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config.c +72 -0
  209. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config_check_before.h +12 -0
  210. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config_check_final.h +12 -0
  211. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_config_check_user.h +1220 -0
  212. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_platform_requirements.h +62 -0
  213. package/cpp/contrib/mbedtls/tf-psa-crypto/core/tf_psa_crypto_version.c +28 -0
  214. package/cpp/contrib/mbedtls/tf-psa-crypto/dispatch/psa_crypto_driver_wrappers_no_static.h +31 -0
  215. package/cpp/contrib/mbedtls/tf-psa-crypto/doxygen/input/doc_mainpage.h.in +51 -0
  216. package/cpp/contrib/mbedtls/tf-psa-crypto/doxygen/tfpsacrypto.doxyfile.in +54 -0
  217. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/CMakeLists.txt +142 -0
  218. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/CMakeLists.txt +3 -0
  219. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/aes.h +607 -0
  220. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/aria.h +342 -0
  221. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/bignum.h +1137 -0
  222. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/block_cipher.h +76 -0
  223. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/camellia.h +302 -0
  224. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ccm.h +523 -0
  225. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/chacha20.h +230 -0
  226. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/chachapoly.h +339 -0
  227. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/cipher.h +1173 -0
  228. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/cmac.h +209 -0
  229. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/config_adjust_test_accelerators.h +111 -0
  230. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_adjust_config_enable_builtins.h +820 -0
  231. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_adjust_config_tweak_builtins.h +203 -0
  232. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_builtin_composites.h +278 -0
  233. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_builtin_key_derivation.h +120 -0
  234. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/crypto_builtin_primitives.h +136 -0
  235. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ctr_drbg.h +554 -0
  236. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ecdsa.h +667 -0
  237. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ecjpake.h +296 -0
  238. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ecp.h +1452 -0
  239. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/entropy.h +253 -0
  240. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/error_common.h +79 -0
  241. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/gcm.h +382 -0
  242. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/hmac_drbg.h +426 -0
  243. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/md5.h +169 -0
  244. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/pkcs5.h +123 -0
  245. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/poly1305.h +165 -0
  246. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/ripemd160.h +120 -0
  247. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/rsa.h +821 -0
  248. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha1.h +196 -0
  249. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha256.h +180 -0
  250. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha3.h +189 -0
  251. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private/sha512.h +188 -0
  252. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/include/mbedtls/private_access.h +53 -0
  253. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aes.c +2236 -0
  254. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesce.c +624 -0
  255. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesce.h +135 -0
  256. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesni.c +846 -0
  257. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aesni.h +162 -0
  258. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/aria.c +966 -0
  259. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum.c +2635 -0
  260. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_core.c +1242 -0
  261. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_core.h +885 -0
  262. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_core_invasive.h +38 -0
  263. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_internal.h +164 -0
  264. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod.c +394 -0
  265. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod.h +452 -0
  266. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod_raw.c +276 -0
  267. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod_raw.h +416 -0
  268. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bignum_mod_raw_invasive.h +34 -0
  269. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/block_cipher.c +207 -0
  270. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/block_cipher_internal.h +99 -0
  271. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/bn_mul.h +1094 -0
  272. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/camellia.c +1055 -0
  273. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ccm.c +773 -0
  274. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chacha20.c +576 -0
  275. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chacha20_neon.c +294 -0
  276. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chacha20_neon.h +62 -0
  277. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/chachapoly.c +479 -0
  278. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher.c +1126 -0
  279. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher_invasive.h +28 -0
  280. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher_wrap.c +1937 -0
  281. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cipher_wrap.h +173 -0
  282. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/cmac.c +911 -0
  283. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ctr.h +35 -0
  284. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ctr_drbg.c +1017 -0
  285. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecdsa.c +826 -0
  286. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecjpake.c +1206 -0
  287. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecp.c +3478 -0
  288. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecp_curves.c +4798 -0
  289. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ecp_invasive.h +220 -0
  290. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/entropy.c +677 -0
  291. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/entropy_poll.c +89 -0
  292. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/entropy_poll.h +44 -0
  293. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/gcm.c +1314 -0
  294. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/hmac_drbg.c +639 -0
  295. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/md5.c +419 -0
  296. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/md_psa.h +26 -0
  297. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/poly1305.c +488 -0
  298. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_aead.c +648 -0
  299. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_aead.h +499 -0
  300. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_cipher.c +752 -0
  301. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_cipher.h +314 -0
  302. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.c +921 -0
  303. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ecp.h +516 -0
  304. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ffdh.c +781 -0
  305. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_ffdh.h +131 -0
  306. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_hash.c +458 -0
  307. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_hash.h +211 -0
  308. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_mac.c +495 -0
  309. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_mac.h +264 -0
  310. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_pake.c +568 -0
  311. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_pake.h +159 -0
  312. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_rsa.c +698 -0
  313. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_rsa.h +321 -0
  314. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_xof.c +149 -0
  315. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_crypto_xof.h +155 -0
  316. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_util_internal.c +282 -0
  317. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/psa_util_internal.h +132 -0
  318. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/ripemd160.c +482 -0
  319. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa.c +2720 -0
  320. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_alt_helpers.c +294 -0
  321. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_alt_helpers.h +185 -0
  322. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_internal.h +172 -0
  323. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/rsa_invasive.h +57 -0
  324. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha1.c +473 -0
  325. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha256.c +956 -0
  326. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha3.c +951 -0
  327. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/builtin/src/sha512.c +1089 -0
  328. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/driver.cmake +54 -0
  329. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/CMakeLists.txt +45 -0
  330. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/Makefile.inc +5 -0
  331. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/README.md +5 -0
  332. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/Hacl_Curve25519.h +25 -0
  333. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlib/FStar_UInt128.h +124 -0
  334. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlib/FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8.h +280 -0
  335. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlib.h +29 -0
  336. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/c_endianness.h +206 -0
  337. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/builtin.h +16 -0
  338. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/callconv.h +48 -0
  339. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/compat.h +34 -0
  340. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/debug.h +57 -0
  341. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/target.h +102 -0
  342. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/types.h +61 -0
  343. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/kremlin/internal/wasmsupport.h +5 -0
  344. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/vs2013/Hacl_Curve25519.h +21 -0
  345. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/include/tf-psa-crypto/private/everest/x25519.h +48 -0
  346. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/Hacl_Curve25519.c +760 -0
  347. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/Hacl_Curve25519_joined.c +50 -0
  348. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/kremlib/FStar_UInt128_extracted.c +413 -0
  349. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/kremlib/FStar_UInt64_FStar_UInt32_FStar_UInt16_FStar_UInt8.c +100 -0
  350. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/legacy/Hacl_Curve25519.c +805 -0
  351. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/everest/library/x25519.c +52 -0
  352. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/CMakeLists.txt +36 -0
  353. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/Makefile.inc +5 -0
  354. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/README.md +4 -0
  355. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m/README.md +544 -0
  356. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m/p256-m.c +1514 -0
  357. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m/p256-m.h +135 -0
  358. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m_driver_entrypoints.c +312 -0
  359. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/p256-m/p256-m_driver_entrypoints.h +219 -0
  360. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/CMakeLists.txt +14 -0
  361. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/Makefile.inc +6 -0
  362. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/include/tf-psa-crypto/private/crypto_struct_pqcp.h +52 -0
  363. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/fips202_psa.h +117 -0
  364. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/pqcp-config.h +68 -0
  365. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/psa_crypto_mldsa.c +528 -0
  366. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/psa_crypto_mldsa.h +301 -0
  367. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/wrap_mldsa_native.c +66 -0
  368. package/cpp/contrib/mbedtls/tf-psa-crypto/drivers/pqcp/src/wrap_mldsa_native.h +37 -0
  369. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/CMakeLists.txt +3 -0
  370. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/lmots.c +768 -0
  371. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/lmots.h +272 -0
  372. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/lms.c +772 -0
  373. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/md.c +1182 -0
  374. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/md_wrap.h +46 -0
  375. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/nist_kw.c +458 -0
  376. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk.c +1464 -0
  377. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_ecc.c +175 -0
  378. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_internal.h +188 -0
  379. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_rsa.c +106 -0
  380. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_wrap.c +667 -0
  381. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pk_wrap.h +101 -0
  382. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pkparse.c +1351 -0
  383. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pkwrite.c +574 -0
  384. package/cpp/contrib/mbedtls/tf-psa-crypto/extras/pkwrite.h +101 -0
  385. package/cpp/contrib/mbedtls/tf-psa-crypto/framework/CMakeLists.txt +1 -0
  386. package/cpp/contrib/mbedtls/tf-psa-crypto/framework/LICENSE +553 -0
  387. package/cpp/contrib/mbedtls/tf-psa-crypto/include/CMakeLists.txt +41 -0
  388. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/asn1.h +623 -0
  389. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/asn1write.h +397 -0
  390. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/base64.h +81 -0
  391. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/compat-3-crypto.h +43 -0
  392. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/constant_time.h +36 -0
  393. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/lms.h +431 -0
  394. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/md.h +538 -0
  395. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/memory_buffer_alloc.h +142 -0
  396. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/nist_kw.h +106 -0
  397. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/pem.h +157 -0
  398. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/pk.h +888 -0
  399. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/platform.h +513 -0
  400. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/platform_time.h +79 -0
  401. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/platform_util.h +197 -0
  402. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/private/pk_private.h +150 -0
  403. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/psa_util.h +199 -0
  404. package/cpp/contrib/mbedtls/tf-psa-crypto/include/mbedtls/threading.h +412 -0
  405. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto.h +6082 -0
  406. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_compat.h +74 -0
  407. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_config.h +2073 -0
  408. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_common.h +42 -0
  409. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_contexts_composites.h +182 -0
  410. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_contexts_key_derivation.h +54 -0
  411. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_contexts_primitives.h +135 -0
  412. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_driver_random.h +49 -0
  413. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_extra.h +2115 -0
  414. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_platform.h +94 -0
  415. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_sizes.h +1301 -0
  416. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_struct.h +682 -0
  417. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_types.h +466 -0
  418. package/cpp/contrib/mbedtls/tf-psa-crypto/include/psa/crypto_values.h +2827 -0
  419. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/build_info.h +193 -0
  420. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_auto_enabled.h +23 -0
  421. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_dependencies.h +58 -0
  422. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_derived.h +135 -0
  423. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_key_pair_types.h +93 -0
  424. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_support.h +211 -0
  425. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/private/crypto_adjust_config_synonyms.h +41 -0
  426. package/cpp/contrib/mbedtls/tf-psa-crypto/include/tf-psa-crypto/version.h +44 -0
  427. package/cpp/contrib/mbedtls/tf-psa-crypto/objlib.cmake +71 -0
  428. package/cpp/contrib/mbedtls/tf-psa-crypto/pkgconfig/CMakeLists.txt +15 -0
  429. package/cpp/contrib/mbedtls/tf-psa-crypto/pkgconfig/JoinPaths.cmake +27 -0
  430. package/cpp/contrib/mbedtls/tf-psa-crypto/pkgconfig/tfpsacrypto.pc.in +10 -0
  431. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/CMakeLists.txt +3 -0
  432. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/memory_buffer_alloc.c +751 -0
  433. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/platform.c +362 -0
  434. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/platform_util.c +428 -0
  435. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/threading.c +311 -0
  436. package/cpp/contrib/mbedtls/tf-psa-crypto/platform/threading_internal.h +75 -0
  437. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/CMakeLists.txt +3 -0
  438. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/asn1parse.c +483 -0
  439. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/asn1write.c +465 -0
  440. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/base64.c +322 -0
  441. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/base64_internal.h +45 -0
  442. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/constant_time.c +247 -0
  443. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/constant_time_impl.h +514 -0
  444. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/constant_time_internal.h +540 -0
  445. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/crypto_oid.h +354 -0
  446. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/oid.c +469 -0
  447. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/pem.c +458 -0
  448. package/cpp/contrib/mbedtls/tf-psa-crypto/utilities/pkcs5.c +475 -0
  449. package/cpp/contrib/monero/LICENSE +41 -0
  450. package/cpp/contrib/monero/bsx/common/perf_timer.h +15 -0
  451. package/cpp/contrib/monero/bsx/common/threadpool.h +43 -0
  452. package/cpp/contrib/monero/bsx/hex.h +25 -0
  453. package/cpp/contrib/monero/bsx/misc_log_ex.h +61 -0
  454. package/cpp/contrib/monero/bsx/random.cpp +20 -0
  455. package/cpp/contrib/monero/contrib/epee/include/int-util.h +320 -0
  456. package/cpp/contrib/monero/contrib/epee/include/memwipe.h +81 -0
  457. package/cpp/contrib/monero/contrib/epee/include/misc_language.h +109 -0
  458. package/cpp/contrib/monero/contrib/epee/include/mlocker.h +89 -0
  459. package/cpp/contrib/monero/contrib/epee/include/span.h +189 -0
  460. package/cpp/contrib/monero/contrib/epee/include/warnings.h +31 -0
  461. package/cpp/contrib/monero/contrib/epee/src/memwipe.c +115 -0
  462. package/cpp/contrib/monero/contrib/epee/src/mlocker.cpp +197 -0
  463. package/cpp/contrib/monero/src/common/aligned.c +139 -0
  464. package/cpp/contrib/monero/src/common/aligned.h +42 -0
  465. package/cpp/contrib/monero/src/common/base58.cpp +259 -0
  466. package/cpp/contrib/monero/src/common/base58.h +46 -0
  467. package/cpp/contrib/monero/src/common/pod-class.h +43 -0
  468. package/cpp/contrib/monero/src/common/varint.h +138 -0
  469. package/cpp/contrib/monero/src/crypto/chacha.h +96 -0
  470. package/cpp/contrib/monero/src/crypto/crypto-ops-data.c +881 -0
  471. package/cpp/contrib/monero/src/crypto/crypto-ops.c +3891 -0
  472. package/cpp/contrib/monero/src/crypto/crypto-ops.h +167 -0
  473. package/cpp/contrib/monero/src/crypto/crypto.cpp +792 -0
  474. package/cpp/contrib/monero/src/crypto/crypto.h +359 -0
  475. package/cpp/contrib/monero/src/crypto/generic-ops.h +103 -0
  476. package/cpp/contrib/monero/src/crypto/hash-ops.h +105 -0
  477. package/cpp/contrib/monero/src/crypto/hash.c +57 -0
  478. package/cpp/contrib/monero/src/crypto/hash.h +110 -0
  479. package/cpp/contrib/monero/src/crypto/keccak.c +239 -0
  480. package/cpp/contrib/monero/src/crypto/keccak.h +40 -0
  481. package/cpp/contrib/monero/src/crypto/random.h +46 -0
  482. package/cpp/contrib/monero/src/crypto/tree-hash.c +257 -0
  483. package/cpp/contrib/monero/src/crypto/wallet/crypto.h +57 -0
  484. package/cpp/contrib/monero/src/crypto/wallet/ops.h +32 -0
  485. package/cpp/contrib/monero/src/cryptonote_config.h +365 -0
  486. package/cpp/contrib/monero/src/device/device.cpp +105 -0
  487. package/cpp/contrib/monero/src/device/device.hpp +274 -0
  488. package/cpp/contrib/monero/src/device/device_default.cpp +343 -0
  489. package/cpp/contrib/monero/src/device/device_default.hpp +156 -0
  490. package/cpp/contrib/monero/src/ringct/bulletproofs.cc +1097 -0
  491. package/cpp/contrib/monero/src/ringct/bulletproofs.h +51 -0
  492. package/cpp/contrib/monero/src/ringct/bulletproofs_plus.cc +1120 -0
  493. package/cpp/contrib/monero/src/ringct/bulletproofs_plus.h +49 -0
  494. package/cpp/contrib/monero/src/ringct/multiexp.cc +708 -0
  495. package/cpp/contrib/monero/src/ringct/multiexp.h +72 -0
  496. package/cpp/contrib/monero/src/ringct/rctCryptoOps.c +221 -0
  497. package/cpp/contrib/monero/src/ringct/rctCryptoOps.h +37 -0
  498. package/cpp/contrib/monero/src/ringct/rctOps.cpp +727 -0
  499. package/cpp/contrib/monero/src/ringct/rctOps.h +191 -0
  500. package/cpp/contrib/monero/src/ringct/rctSigs.cpp +1652 -0
  501. package/cpp/contrib/monero/src/ringct/rctSigs.h +143 -0
  502. package/cpp/contrib/monero/src/ringct/rctTypes.cpp +338 -0
  503. package/cpp/contrib/monero/src/ringct/rctTypes.h +842 -0
  504. package/cpp/contrib/monero/src/serialization/binary_archive.h +243 -0
  505. package/cpp/contrib/monero/src/serialization/container.h +146 -0
  506. package/cpp/contrib/monero/src/serialization/containers.h +127 -0
  507. package/cpp/contrib/monero/src/serialization/crypto.h +97 -0
  508. package/cpp/contrib/monero/src/serialization/debug_archive.h +53 -0
  509. package/cpp/contrib/monero/src/serialization/json_archive.h +193 -0
  510. package/cpp/contrib/monero/src/serialization/serialization.h +328 -0
  511. package/cpp/contrib/monero/src/serialization/variant.h +50 -0
  512. package/cpp/contrib/nlohmann/LICENSE.MIT +21 -0
  513. package/cpp/contrib/nlohmann/json.hpp +25526 -0
  514. package/cpp/contrib/nlohmann/json_fwd.hpp +187 -0
  515. package/cpp/contrib/notes.txt +96 -0
  516. package/cpp/contrib/secp256k1/CHANGELOG.md +214 -0
  517. package/cpp/contrib/secp256k1/CMakeLists.txt +392 -0
  518. package/cpp/contrib/secp256k1/CMakePresets.json +18 -0
  519. package/cpp/contrib/secp256k1/CONTRIBUTING.md +111 -0
  520. package/cpp/contrib/secp256k1/COPYING +19 -0
  521. package/cpp/contrib/secp256k1/Makefile.am +332 -0
  522. package/cpp/contrib/secp256k1/README.md +176 -0
  523. package/cpp/contrib/secp256k1/SECURITY.md +15 -0
  524. package/cpp/contrib/secp256k1/autogen.sh +3 -0
  525. package/cpp/contrib/secp256k1/ci/ci.sh +147 -0
  526. package/cpp/contrib/secp256k1/ci/linux-debian.Dockerfile +84 -0
  527. package/cpp/contrib/secp256k1/ci/travis.sh +68 -0
  528. package/cpp/contrib/secp256k1/cmake/CheckArm32Assembly.cmake +6 -0
  529. package/cpp/contrib/secp256k1/cmake/CheckMemorySanitizer.cmake +18 -0
  530. package/cpp/contrib/secp256k1/cmake/CheckStringOptionValue.cmake +10 -0
  531. package/cpp/contrib/secp256k1/cmake/CheckX86_64Assembly.cmake +15 -0
  532. package/cpp/contrib/secp256k1/cmake/DiscoverTests.cmake +71 -0
  533. package/cpp/contrib/secp256k1/cmake/FindValgrind.cmake +41 -0
  534. package/cpp/contrib/secp256k1/cmake/GeneratePkgConfigFile.cmake +8 -0
  535. package/cpp/contrib/secp256k1/cmake/TryAppendCFlags.cmake +24 -0
  536. package/cpp/contrib/secp256k1/cmake/arm-linux-gnueabihf.toolchain.cmake +3 -0
  537. package/cpp/contrib/secp256k1/cmake/config.cmake.in +5 -0
  538. package/cpp/contrib/secp256k1/cmake/source_arm32.s +9 -0
  539. package/cpp/contrib/secp256k1/cmake/x86_64-w64-mingw32.toolchain.cmake +3 -0
  540. package/cpp/contrib/secp256k1/configure.ac +590 -0
  541. package/cpp/contrib/secp256k1/contrib/lax_der_parsing.c +148 -0
  542. package/cpp/contrib/secp256k1/contrib/lax_der_parsing.h +97 -0
  543. package/cpp/contrib/secp256k1/contrib/lax_der_privatekey_parsing.c +112 -0
  544. package/cpp/contrib/secp256k1/contrib/lax_der_privatekey_parsing.h +95 -0
  545. package/cpp/contrib/secp256k1/doc/ellswift.md +483 -0
  546. package/cpp/contrib/secp256k1/doc/musig.md +54 -0
  547. package/cpp/contrib/secp256k1/doc/release-process.md +94 -0
  548. package/cpp/contrib/secp256k1/doc/safegcd_implementation.md +819 -0
  549. package/cpp/contrib/secp256k1/examples/CMakeLists.txt +33 -0
  550. package/cpp/contrib/secp256k1/examples/EXAMPLES_COPYING +121 -0
  551. package/cpp/contrib/secp256k1/examples/ecdh.c +121 -0
  552. package/cpp/contrib/secp256k1/examples/ecdsa.c +138 -0
  553. package/cpp/contrib/secp256k1/examples/ellswift.c +122 -0
  554. package/cpp/contrib/secp256k1/examples/examples_util.h +108 -0
  555. package/cpp/contrib/secp256k1/examples/musig.c +261 -0
  556. package/cpp/contrib/secp256k1/examples/schnorr.c +154 -0
  557. package/cpp/contrib/secp256k1/include/secp256k1.h +877 -0
  558. package/cpp/contrib/secp256k1/include/secp256k1_dleag.h +150 -0
  559. package/cpp/contrib/secp256k1/include/secp256k1_ecdh.h +63 -0
  560. package/cpp/contrib/secp256k1/include/secp256k1_ecdsaotves.h +55 -0
  561. package/cpp/contrib/secp256k1/include/secp256k1_ed25519.h +239 -0
  562. package/cpp/contrib/secp256k1/include/secp256k1_ellswift.h +200 -0
  563. package/cpp/contrib/secp256k1/include/secp256k1_extrakeys.h +250 -0
  564. package/cpp/contrib/secp256k1/include/secp256k1_generator.h +106 -0
  565. package/cpp/contrib/secp256k1/include/secp256k1_hash.h +45 -0
  566. package/cpp/contrib/secp256k1/include/secp256k1_musig.h +588 -0
  567. package/cpp/contrib/secp256k1/include/secp256k1_preallocated.h +134 -0
  568. package/cpp/contrib/secp256k1/include/secp256k1_recovery.h +123 -0
  569. package/cpp/contrib/secp256k1/include/secp256k1_schnorrsig.h +190 -0
  570. package/cpp/contrib/secp256k1/include/visibility.h +58 -0
  571. package/cpp/contrib/secp256k1/libsecp256k1.pc.in +12 -0
  572. package/cpp/contrib/secp256k1/sage/gen_exhaustive_groups.sage +156 -0
  573. package/cpp/contrib/secp256k1/sage/gen_split_lambda_constants.sage +123 -0
  574. package/cpp/contrib/secp256k1/sage/group_prover.sage +353 -0
  575. package/cpp/contrib/secp256k1/sage/prove_group_implementations.sage +285 -0
  576. package/cpp/contrib/secp256k1/sage/secp256k1_params.sage +39 -0
  577. package/cpp/contrib/secp256k1/sage/weierstrass_prover.sage +275 -0
  578. package/cpp/contrib/secp256k1/src/CMakeLists.txt +253 -0
  579. package/cpp/contrib/secp256k1/src/asm/field_10x26_arm.s +916 -0
  580. package/cpp/contrib/secp256k1/src/assumptions.h +87 -0
  581. package/cpp/contrib/secp256k1/src/checkmem.h +117 -0
  582. package/cpp/contrib/secp256k1/src/ecdsa.h +21 -0
  583. package/cpp/contrib/secp256k1/src/ecdsa_impl.h +312 -0
  584. package/cpp/contrib/secp256k1/src/eckey.h +28 -0
  585. package/cpp/contrib/secp256k1/src/eckey_impl.h +94 -0
  586. package/cpp/contrib/secp256k1/src/ecmult.h +64 -0
  587. package/cpp/contrib/secp256k1/src/ecmult_compute_table.h +16 -0
  588. package/cpp/contrib/secp256k1/src/ecmult_compute_table_impl.h +49 -0
  589. package/cpp/contrib/secp256k1/src/ecmult_const.h +38 -0
  590. package/cpp/contrib/secp256k1/src/ecmult_const_impl.h +402 -0
  591. package/cpp/contrib/secp256k1/src/ecmult_gen.h +144 -0
  592. package/cpp/contrib/secp256k1/src/ecmult_gen_compute_table.h +14 -0
  593. package/cpp/contrib/secp256k1/src/ecmult_gen_compute_table_impl.h +108 -0
  594. package/cpp/contrib/secp256k1/src/ecmult_gen_impl.h +341 -0
  595. package/cpp/contrib/secp256k1/src/ecmult_impl.h +869 -0
  596. package/cpp/contrib/secp256k1/src/field.h +354 -0
  597. package/cpp/contrib/secp256k1/src/field_10x26.h +57 -0
  598. package/cpp/contrib/secp256k1/src/field_10x26_impl.h +1234 -0
  599. package/cpp/contrib/secp256k1/src/field_5x52.h +62 -0
  600. package/cpp/contrib/secp256k1/src/field_5x52_impl.h +524 -0
  601. package/cpp/contrib/secp256k1/src/field_5x52_int128_impl.h +274 -0
  602. package/cpp/contrib/secp256k1/src/field_impl.h +462 -0
  603. package/cpp/contrib/secp256k1/src/group.h +224 -0
  604. package/cpp/contrib/secp256k1/src/group_impl.h +1024 -0
  605. package/cpp/contrib/secp256k1/src/hash.h +54 -0
  606. package/cpp/contrib/secp256k1/src/hash_impl.h +360 -0
  607. package/cpp/contrib/secp256k1/src/hsort.h +33 -0
  608. package/cpp/contrib/secp256k1/src/hsort_impl.h +125 -0
  609. package/cpp/contrib/secp256k1/src/int128.h +90 -0
  610. package/cpp/contrib/secp256k1/src/int128_impl.h +18 -0
  611. package/cpp/contrib/secp256k1/src/int128_native.h +19 -0
  612. package/cpp/contrib/secp256k1/src/int128_native_impl.h +94 -0
  613. package/cpp/contrib/secp256k1/src/int128_struct.h +14 -0
  614. package/cpp/contrib/secp256k1/src/int128_struct_impl.h +205 -0
  615. package/cpp/contrib/secp256k1/src/modinv32.h +43 -0
  616. package/cpp/contrib/secp256k1/src/modinv32_impl.h +725 -0
  617. package/cpp/contrib/secp256k1/src/modinv64.h +47 -0
  618. package/cpp/contrib/secp256k1/src/modinv64_impl.h +780 -0
  619. package/cpp/contrib/secp256k1/src/modules/dleag/Makefile.am.include +3 -0
  620. package/cpp/contrib/secp256k1/src/modules/dleag/main_impl.h +1073 -0
  621. package/cpp/contrib/secp256k1/src/modules/dleag/tests_impl.h +68 -0
  622. package/cpp/contrib/secp256k1/src/modules/ecdh/Makefile.am.include +5 -0
  623. package/cpp/contrib/secp256k1/src/modules/ecdh/bench_impl.h +54 -0
  624. package/cpp/contrib/secp256k1/src/modules/ecdh/main_impl.h +79 -0
  625. package/cpp/contrib/secp256k1/src/modules/ecdh/tests_impl.h +218 -0
  626. package/cpp/contrib/secp256k1/src/modules/ecdsaotves/Makefile.am.include +3 -0
  627. package/cpp/contrib/secp256k1/src/modules/ecdsaotves/main_impl.h +365 -0
  628. package/cpp/contrib/secp256k1/src/modules/ecdsaotves/tests_impl.h +49 -0
  629. package/cpp/contrib/secp256k1/src/modules/ed25519/Makefile.am.include +16 -0
  630. package/cpp/contrib/secp256k1/src/modules/ed25519/common.h +68 -0
  631. package/cpp/contrib/secp256k1/src/modules/ed25519/core_ed25519.h +229 -0
  632. package/cpp/contrib/secp256k1/src/modules/ed25519/main_impl.h +98 -0
  633. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/common.h +21 -0
  634. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/ed25519_ref10.h +2698 -0
  635. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/ed25519_ref10_fe_25_5.h +1056 -0
  636. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/ed25519_ref10_fe_51.h +518 -0
  637. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/base.h +1344 -0
  638. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/base2.h +40 -0
  639. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/constants.h +40 -0
  640. package/cpp/contrib/secp256k1/src/modules/ed25519/ref10/fe_25_5/fe.h +220 -0
  641. package/cpp/contrib/secp256k1/src/modules/ed25519/scalarmult_ed25519_ref10.h +417 -0
  642. package/cpp/contrib/secp256k1/src/modules/ed25519/sha512/hash_sha512.h +14 -0
  643. package/cpp/contrib/secp256k1/src/modules/ed25519/sha512/hash_sha512_cp.h +287 -0
  644. package/cpp/contrib/secp256k1/src/modules/ed25519/tests_impl.h +109 -0
  645. package/cpp/contrib/secp256k1/src/modules/ed25519/utils.h +97 -0
  646. package/cpp/contrib/secp256k1/src/modules/ellswift/Makefile.am.include +5 -0
  647. package/cpp/contrib/secp256k1/src/modules/ellswift/bench_impl.h +106 -0
  648. package/cpp/contrib/secp256k1/src/modules/ellswift/main_impl.h +581 -0
  649. package/cpp/contrib/secp256k1/src/modules/ellswift/tests_exhaustive_impl.h +39 -0
  650. package/cpp/contrib/secp256k1/src/modules/ellswift/tests_impl.h +544 -0
  651. package/cpp/contrib/secp256k1/src/modules/extrakeys/Makefile.am.include +4 -0
  652. package/cpp/contrib/secp256k1/src/modules/extrakeys/main_impl.h +285 -0
  653. package/cpp/contrib/secp256k1/src/modules/extrakeys/tests_exhaustive_impl.h +68 -0
  654. package/cpp/contrib/secp256k1/src/modules/extrakeys/tests_impl.h +484 -0
  655. package/cpp/contrib/secp256k1/src/modules/generator/Makefile.am.include +9 -0
  656. package/cpp/contrib/secp256k1/src/modules/generator/main_impl.h +271 -0
  657. package/cpp/contrib/secp256k1/src/modules/generator/tests_impl.h +227 -0
  658. package/cpp/contrib/secp256k1/src/modules/musig/Makefile.am.include +8 -0
  659. package/cpp/contrib/secp256k1/src/modules/musig/keyagg.h +32 -0
  660. package/cpp/contrib/secp256k1/src/modules/musig/keyagg_impl.h +275 -0
  661. package/cpp/contrib/secp256k1/src/modules/musig/main_impl.h +12 -0
  662. package/cpp/contrib/secp256k1/src/modules/musig/session.h +24 -0
  663. package/cpp/contrib/secp256k1/src/modules/musig/session_impl.h +795 -0
  664. package/cpp/contrib/secp256k1/src/modules/musig/tests_impl.h +1161 -0
  665. package/cpp/contrib/secp256k1/src/modules/musig/vectors.h +346 -0
  666. package/cpp/contrib/secp256k1/src/modules/recovery/Makefile.am.include +5 -0
  667. package/cpp/contrib/secp256k1/src/modules/recovery/bench_impl.h +62 -0
  668. package/cpp/contrib/secp256k1/src/modules/recovery/main_impl.h +159 -0
  669. package/cpp/contrib/secp256k1/src/modules/recovery/tests_exhaustive_impl.h +148 -0
  670. package/cpp/contrib/secp256k1/src/modules/recovery/tests_impl.h +339 -0
  671. package/cpp/contrib/secp256k1/src/modules/schnorrsig/Makefile.am.include +5 -0
  672. package/cpp/contrib/secp256k1/src/modules/schnorrsig/bench_impl.h +104 -0
  673. package/cpp/contrib/secp256k1/src/modules/schnorrsig/main_impl.h +263 -0
  674. package/cpp/contrib/secp256k1/src/modules/schnorrsig/tests_exhaustive_impl.h +214 -0
  675. package/cpp/contrib/secp256k1/src/modules/schnorrsig/tests_impl.h +1010 -0
  676. package/cpp/contrib/secp256k1/src/precompute_ecmult.c +91 -0
  677. package/cpp/contrib/secp256k1/src/precompute_ecmult_gen.c +101 -0
  678. package/cpp/contrib/secp256k1/src/precomputed_ecmult.c +16456 -0
  679. package/cpp/contrib/secp256k1/src/precomputed_ecmult.h +40 -0
  680. package/cpp/contrib/secp256k1/src/precomputed_ecmult_gen.c +1779 -0
  681. package/cpp/contrib/secp256k1/src/precomputed_ecmult_gen.h +28 -0
  682. package/cpp/contrib/secp256k1/src/scalar.h +108 -0
  683. package/cpp/contrib/secp256k1/src/scalar_4x64.h +19 -0
  684. package/cpp/contrib/secp256k1/src/scalar_4x64_impl.h +1010 -0
  685. package/cpp/contrib/secp256k1/src/scalar_8x32.h +19 -0
  686. package/cpp/contrib/secp256k1/src/scalar_8x32_impl.h +830 -0
  687. package/cpp/contrib/secp256k1/src/scalar_impl.h +321 -0
  688. package/cpp/contrib/secp256k1/src/scalar_low.h +24 -0
  689. package/cpp/contrib/secp256k1/src/scalar_low_impl.h +215 -0
  690. package/cpp/contrib/secp256k1/src/scratch.h +44 -0
  691. package/cpp/contrib/secp256k1/src/scratch_impl.h +99 -0
  692. package/cpp/contrib/secp256k1/src/secp256k1.c +896 -0
  693. package/cpp/contrib/secp256k1/src/selftest.h +35 -0
  694. package/cpp/contrib/secp256k1/src/testrand.h +45 -0
  695. package/cpp/contrib/secp256k1/src/testrand_impl.h +162 -0
  696. package/cpp/contrib/secp256k1/src/testutil.h +161 -0
  697. package/cpp/contrib/secp256k1/src/unit_test.c +479 -0
  698. package/cpp/contrib/secp256k1/src/unit_test.h +147 -0
  699. package/cpp/contrib/secp256k1/src/util.h +469 -0
  700. package/cpp/contrib/secp256k1/src/util_local_visibility.h +12 -0
  701. package/cpp/contrib/secp256k1/tools/check-abi.sh +67 -0
  702. package/cpp/contrib/secp256k1/tools/symbol-check.py +72 -0
  703. package/cpp/contrib/secp256k1/tools/test_vectors_musig2_generate.py +656 -0
  704. package/cpp/contrib/secp256k1/tools/tests_wycheproof_generate_ecdh.py +166 -0
  705. package/cpp/contrib/secp256k1/tools/tests_wycheproof_generate_ecdsa.py +111 -0
  706. package/cpp/contrib/secp256k1/tools/wycheproof_utils.py +12 -0
  707. package/cpp/contrib/secp256k1/wasm/test_module.html +320 -0
  708. package/cpp/contrib/secp256k1/wasm/wrap.cpp +331 -0
  709. package/cpp/contrib/sqlite3.h +14349 -0
  710. package/cpp/contrib/sqlite3mc_amalgamation.c +369890 -0
  711. package/cpp/contrib/sqlite3mc_amalgamation.h +15548 -0
  712. package/cpp/contrib/unilib/uninorms.cpp +393 -0
  713. package/cpp/contrib/unilib/uninorms.h +56 -0
  714. package/cpp/contrib/unilib/utf8.cpp +78 -0
  715. package/cpp/contrib/unilib/utf8.h +260 -0
  716. package/cpp/contrib/update_mbedtls.sh +85 -0
  717. package/cpp/crypto/aes.cpp +141 -0
  718. package/cpp/crypto/aes.h +67 -0
  719. package/cpp/crypto/chacha20.cpp +342 -0
  720. package/cpp/crypto/chacha20.h +82 -0
  721. package/cpp/crypto/chacha20poly1305.cpp +91 -0
  722. package/cpp/crypto/chacha20poly1305.h +46 -0
  723. package/cpp/crypto/common.h +85 -0
  724. package/cpp/crypto/ctaes/COPYING +21 -0
  725. package/cpp/crypto/ctaes/README.md +41 -0
  726. package/cpp/crypto/ctaes/bench.c +170 -0
  727. package/cpp/crypto/ctaes/ctaes.c +556 -0
  728. package/cpp/crypto/ctaes/ctaes.h +41 -0
  729. package/cpp/crypto/ctaes/test.c +110 -0
  730. package/cpp/crypto/extkey.cpp +257 -0
  731. package/cpp/crypto/extkey.h +66 -0
  732. package/cpp/crypto/hmac_sha512.cpp +37 -0
  733. package/cpp/crypto/hmac_sha512.h +32 -0
  734. package/cpp/crypto/merkle.cpp +47 -0
  735. package/cpp/crypto/merkle.h +20 -0
  736. package/cpp/crypto/poly1305.cpp +223 -0
  737. package/cpp/crypto/poly1305.h +59 -0
  738. package/cpp/crypto/ripemd160.cpp +292 -0
  739. package/cpp/crypto/ripemd160.h +28 -0
  740. package/cpp/crypto/scrypt-sse2.cpp +141 -0
  741. package/cpp/crypto/scrypt.cpp +336 -0
  742. package/cpp/crypto/scrypt.h +49 -0
  743. package/cpp/crypto/sealed_key.cpp +62 -0
  744. package/cpp/crypto/sealed_key.h +34 -0
  745. package/cpp/crypto/secure_bytes.h +16 -0
  746. package/cpp/crypto/sha512.cpp +206 -0
  747. package/cpp/crypto/sha512.h +29 -0
  748. package/cpp/crypto/util.cpp +77 -0
  749. package/cpp/crypto/util.h +32 -0
  750. package/cpp/debug_rpc.cpp +703 -0
  751. package/cpp/debug_rpc.h +63 -0
  752. package/cpp/electrum.cpp +931 -0
  753. package/cpp/electrum.h +169 -0
  754. package/cpp/engine/xmr_engine.cpp +463 -0
  755. package/cpp/engine/xmr_engine.h +84 -0
  756. package/cpp/engine/xmr_engine_c.cpp +141 -0
  757. package/cpp/engine/xmr_engine_c.h +35 -0
  758. package/cpp/fees.cpp +270 -0
  759. package/cpp/fees.h +60 -0
  760. package/cpp/height_search.cpp +64 -0
  761. package/cpp/height_search.h +27 -0
  762. package/cpp/main.cpp +146 -0
  763. package/cpp/messages_npb.cpp +701 -0
  764. package/cpp/messages_npb.h +667 -0
  765. package/cpp/mnemonic/mnemonic.cpp +715 -0
  766. package/cpp/mnemonic/mnemonic.h +52 -0
  767. package/cpp/mnemonic/wordlists/english.h +1103 -0
  768. package/cpp/mnemonic/wordlists/japanese.h +2212 -0
  769. package/cpp/network/bridge.cpp +232 -0
  770. package/cpp/network/bridge.h +115 -0
  771. package/cpp/network/ca_roots.cpp +114 -0
  772. package/cpp/network/ca_roots.h +12 -0
  773. package/cpp/network/http_client.cpp +261 -0
  774. package/cpp/network/http_client.h +33 -0
  775. package/cpp/network/pem.cpp +84 -0
  776. package/cpp/network/pem.h +22 -0
  777. package/cpp/network/psa_user_config.h +15 -0
  778. package/cpp/network/socks5.cpp +180 -0
  779. package/cpp/network/socks5.h +26 -0
  780. package/cpp/network/tls_transport.cpp +502 -0
  781. package/cpp/network/tls_transport.h +62 -0
  782. package/cpp/network/transport.cpp +169 -0
  783. package/cpp/network/transport.h +115 -0
  784. package/cpp/network/url.cpp +88 -0
  785. package/cpp/network/url.h +25 -0
  786. package/cpp/network/websocket.cpp +253 -0
  787. package/cpp/network/websocket.h +68 -0
  788. package/cpp/network/ws_transport.cpp +361 -0
  789. package/cpp/network/ws_transport.h +72 -0
  790. package/cpp/node_client.cpp +1196 -0
  791. package/cpp/node_client.h +209 -0
  792. package/cpp/node_scan.h +35 -0
  793. package/cpp/schema.cpp +1249 -0
  794. package/cpp/schema.h +132 -0
  795. package/cpp/smsg.cpp +453 -0
  796. package/cpp/smsg.h +43 -0
  797. package/cpp/support/allocators/secure.h +85 -0
  798. package/cpp/support/cleanse.cpp +35 -0
  799. package/cpp/support/cleanse.h +15 -0
  800. package/cpp/support/coop.cpp +319 -0
  801. package/cpp/support/coop.h +157 -0
  802. package/cpp/support/lockedpool.cpp +406 -0
  803. package/cpp/support/lockedpool.h +240 -0
  804. package/cpp/uint256.cpp +62 -0
  805. package/cpp/uint256.h +121 -0
  806. package/cpp/util/base58.cpp +181 -0
  807. package/cpp/util/base58.h +45 -0
  808. package/cpp/util/bech32.cpp +578 -0
  809. package/cpp/util/bech32.h +96 -0
  810. package/cpp/util/debug.cpp +23 -0
  811. package/cpp/util/debug.h +12 -0
  812. package/cpp/util/int.cpp +118 -0
  813. package/cpp/util/int.h +18 -0
  814. package/cpp/util/json.h +26 -0
  815. package/cpp/util/log.cpp +137 -0
  816. package/cpp/util/log.h +37 -0
  817. package/cpp/util/mutex.h +89 -0
  818. package/cpp/util/platform.cpp +90 -0
  819. package/cpp/util/platform.h +17 -0
  820. package/cpp/util/random.cpp +136 -0
  821. package/cpp/util/random.h +28 -0
  822. package/cpp/util/rpc.cpp +192 -0
  823. package/cpp/util/rpc.h +454 -0
  824. package/cpp/util/str.cpp +254 -0
  825. package/cpp/util/str.h +54 -0
  826. package/cpp/util/thread.cpp +17 -0
  827. package/cpp/util/thread.h +12 -0
  828. package/cpp/util/time.cpp +30 -0
  829. package/cpp/util/time.h +30 -0
  830. package/cpp/util/tinyformat.h +1163 -0
  831. package/cpp/util/vector.h +83 -0
  832. package/cpp/version.h.in +12 -0
  833. package/cpp/view_key_chain.h +283 -0
  834. package/cpp/wallet/account_wallet.cpp +668 -0
  835. package/cpp/wallet/account_wallet.h +136 -0
  836. package/cpp/wallet/base_wallet.cpp +302 -0
  837. package/cpp/wallet/base_wallet.h +129 -0
  838. package/cpp/wallet/debug_wallet.cpp +40 -0
  839. package/cpp/wallet/debug_wallet.h +36 -0
  840. package/cpp/wallet/encrypted_seed.cpp +96 -0
  841. package/cpp/wallet/encrypted_seed.h +41 -0
  842. package/cpp/wallet/host_wallet.cpp +85 -0
  843. package/cpp/wallet/host_wallet.h +51 -0
  844. package/cpp/wallet/native_wallet.cpp +34 -0
  845. package/cpp/wallet/native_wallet.h +28 -0
  846. package/cpp/wallet/xmr/account_wallet.cpp +803 -0
  847. package/cpp/wallet/xmr/account_wallet.h +139 -0
  848. package/cpp/wallet/xmr/builder.cpp +568 -0
  849. package/cpp/wallet/xmr/builder.h +65 -0
  850. package/cpp/wallet/xmr/chain.cpp +1437 -0
  851. package/cpp/wallet/xmr/chain.h +213 -0
  852. package/cpp/wallet/xmr/daemon.cpp +583 -0
  853. package/cpp/wallet/xmr/daemon.h +153 -0
  854. package/cpp/wallet/xmr/decoys.cpp +197 -0
  855. package/cpp/wallet/xmr/decoys.h +64 -0
  856. package/cpp/wallet/xmr/epee.cpp +448 -0
  857. package/cpp/wallet/xmr/epee.h +25 -0
  858. package/cpp/wallet/xmr/fee.cpp +169 -0
  859. package/cpp/wallet/xmr/fee.h +61 -0
  860. package/cpp/wallet/xmr/reserve_proof.cpp +169 -0
  861. package/cpp/wallet/xmr/reserve_proof.h +24 -0
  862. package/cpp/wallet/xmr/scanner.cpp +860 -0
  863. package/cpp/wallet/xmr/scanner.h +239 -0
  864. package/lib/commonjs/NativeNitroBSX.js +128 -0
  865. package/lib/commonjs/NativeNitroBSX.js.map +1 -0
  866. package/lib/commonjs/format.js +21 -0
  867. package/lib/commonjs/format.js.map +1 -0
  868. package/lib/commonjs/index.js +50 -0
  869. package/lib/commonjs/index.js.map +1 -0
  870. package/lib/commonjs/service.js +75 -0
  871. package/lib/commonjs/service.js.map +1 -0
  872. package/lib/commonjs/specs/NitroBSX.nitro.js +6 -0
  873. package/lib/commonjs/specs/NitroBSX.nitro.js.map +1 -0
  874. package/lib/module/NativeNitroBSX.js +124 -0
  875. package/lib/module/NativeNitroBSX.js.map +1 -0
  876. package/lib/module/format.js +15 -0
  877. package/lib/module/format.js.map +1 -0
  878. package/lib/module/index.js +7 -0
  879. package/lib/module/index.js.map +1 -0
  880. package/lib/module/service.js +66 -0
  881. package/lib/module/service.js.map +1 -0
  882. package/lib/module/specs/NitroBSX.nitro.js +4 -0
  883. package/lib/module/specs/NitroBSX.nitro.js.map +1 -0
  884. package/lib/typescript/commonjs/package.json +1 -0
  885. package/lib/typescript/commonjs/src/NativeNitroBSX.d.ts +94 -0
  886. package/lib/typescript/commonjs/src/NativeNitroBSX.d.ts.map +1 -0
  887. package/lib/typescript/commonjs/src/format.d.ts +3 -0
  888. package/lib/typescript/commonjs/src/format.d.ts.map +1 -0
  889. package/lib/typescript/commonjs/src/index.d.ts +5 -0
  890. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  891. package/lib/typescript/commonjs/src/service.d.ts +28 -0
  892. package/lib/typescript/commonjs/src/service.d.ts.map +1 -0
  893. package/lib/typescript/commonjs/src/specs/NitroBSX.nitro.d.ts +251 -0
  894. package/lib/typescript/commonjs/src/specs/NitroBSX.nitro.d.ts.map +1 -0
  895. package/lib/typescript/module/package.json +1 -0
  896. package/lib/typescript/module/src/NativeNitroBSX.d.ts +94 -0
  897. package/lib/typescript/module/src/NativeNitroBSX.d.ts.map +1 -0
  898. package/lib/typescript/module/src/format.d.ts +3 -0
  899. package/lib/typescript/module/src/format.d.ts.map +1 -0
  900. package/lib/typescript/module/src/index.d.ts +5 -0
  901. package/lib/typescript/module/src/index.d.ts.map +1 -0
  902. package/lib/typescript/module/src/service.d.ts +28 -0
  903. package/lib/typescript/module/src/service.d.ts.map +1 -0
  904. package/lib/typescript/module/src/specs/NitroBSX.nitro.d.ts +251 -0
  905. package/lib/typescript/module/src/specs/NitroBSX.nitro.d.ts.map +1 -0
  906. package/nitro.json +19 -0
  907. package/nitrogen/generated/android/NitroBSX+autolinking.cmake +81 -0
  908. package/nitrogen/generated/android/NitroBSX+autolinking.gradle +27 -0
  909. package/nitrogen/generated/android/NitroBSXOnLoad.cpp +49 -0
  910. package/nitrogen/generated/android/NitroBSXOnLoad.hpp +34 -0
  911. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrobsx/NitroBSXOnLoad.kt +35 -0
  912. package/nitrogen/generated/ios/NitroBSX+autolinking.rb +62 -0
  913. package/nitrogen/generated/ios/NitroBSX-Swift-Cxx-Bridge.cpp +17 -0
  914. package/nitrogen/generated/ios/NitroBSX-Swift-Cxx-Bridge.hpp +27 -0
  915. package/nitrogen/generated/ios/NitroBSX-Swift-Cxx-Umbrella.hpp +38 -0
  916. package/nitrogen/generated/ios/NitroBSXAutolinking.mm +35 -0
  917. package/nitrogen/generated/ios/NitroBSXAutolinking.swift +16 -0
  918. package/nitrogen/generated/shared/c++/HybridNitroBSXSpec.cpp +91 -0
  919. package/nitrogen/generated/shared/c++/HybridNitroBSXSpec.hpp +142 -0
  920. package/nitrogen/generated/shared/c++/NotificationPair.hpp +87 -0
  921. package/nitrogen/generated/shared/c++/SignOutcome.hpp +80 -0
  922. package/nitrogen/generated/shared/c++/SignTxResult.hpp +89 -0
  923. package/package.json +172 -4
  924. package/react-native-nitro-bsx.podspec +33 -0
  925. package/react-native.config.js +26 -0
  926. package/scripts/build-ios.sh +49 -0
  927. package/src/NativeNitroBSX.ts +203 -0
  928. package/src/format.ts +14 -0
  929. package/src/index.ts +4 -0
  930. package/src/service.ts +77 -0
  931. package/src/specs/NitroBSX.nitro.ts +300 -0
@@ -0,0 +1,2698 @@
1
+
2
+ #ifndef SECP256K1_MODULE_ED25519_REF10_ED25519
3
+ #define SECP256K1_MODULE_ED25519_REF10_ED25519
4
+
5
+ #include <stddef.h>
6
+ #include <stdint.h>
7
+ #include <stdlib.h>
8
+ #include <string.h>
9
+
10
+ #include "../common.h"
11
+ #include "../utils.h"
12
+
13
+ /*
14
+ fe means field element.
15
+ Here the field is \Z/(2^255-19).
16
+ */
17
+
18
+ #ifdef HAVE_TI_MODE
19
+ typedef uint64_t fe25519[5];
20
+ #else
21
+ typedef int32_t fe25519[10];
22
+ #endif
23
+
24
+ void fe25519_invert(fe25519 out, const fe25519 z);
25
+ void fe25519_frombytes(fe25519 h, const unsigned char *s);
26
+ void fe25519_tobytes(unsigned char *s, const fe25519 h);
27
+
28
+ #ifdef HAVE_TI_MODE
29
+ #error "TODO"
30
+ # include "ed25519_ref10_fe_51.h"
31
+ #else
32
+ # include "ed25519_ref10_fe_25_5.h"
33
+ #endif
34
+
35
+
36
+ /*
37
+ ge means group element.
38
+
39
+ Here the group is the set of pairs (x,y) of field elements
40
+ satisfying -x^2 + y^2 = 1 + d x^2y^2
41
+ where d = -121665/121666.
42
+
43
+ Representations:
44
+ ge25519_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
45
+ ge25519_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
46
+ ge25519_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
47
+ ge25519_precomp (Duif): (y+x,y-x,2dxy)
48
+ */
49
+
50
+ typedef struct {
51
+ fe25519 X;
52
+ fe25519 Y;
53
+ fe25519 Z;
54
+ } ge25519_p2;
55
+
56
+ typedef struct {
57
+ fe25519 X;
58
+ fe25519 Y;
59
+ fe25519 Z;
60
+ fe25519 T;
61
+ } ge25519_p3;
62
+
63
+ typedef struct {
64
+ fe25519 X;
65
+ fe25519 Y;
66
+ fe25519 Z;
67
+ fe25519 T;
68
+ } ge25519_p1p1;
69
+
70
+ typedef struct {
71
+ fe25519 yplusx;
72
+ fe25519 yminusx;
73
+ fe25519 xy2d;
74
+ } ge25519_precomp;
75
+
76
+ typedef struct {
77
+ fe25519 YplusX;
78
+ fe25519 YminusX;
79
+ fe25519 Z;
80
+ fe25519 T2d;
81
+ } ge25519_cached;
82
+
83
+ static uint64_t
84
+ load_3(const unsigned char *in)
85
+ {
86
+ uint64_t result;
87
+
88
+ result = (uint64_t) in[0];
89
+ result |= ((uint64_t) in[1]) << 8;
90
+ result |= ((uint64_t) in[2]) << 16;
91
+
92
+ return result;
93
+ }
94
+
95
+ static uint64_t
96
+ load_4(const unsigned char *in)
97
+ {
98
+ uint64_t result;
99
+
100
+ result = (uint64_t) in[0];
101
+ result |= ((uint64_t) in[1]) << 8;
102
+ result |= ((uint64_t) in[2]) << 16;
103
+ result |= ((uint64_t) in[3]) << 24;
104
+
105
+ return result;
106
+ }
107
+
108
+ /*
109
+ * Field arithmetic:
110
+ * Use 5*51 bit limbs on 64-bit systems with support for 128 bit arithmetic,
111
+ * and 10*25.5 bit limbs elsewhere.
112
+ *
113
+ * Functions used elsewhere that are candidates for inlining are defined
114
+ * via "private/curve25519_ref10.h".
115
+ */
116
+
117
+ #ifdef HAVE_TI_MODE
118
+ # include "fe_51/constants.h"
119
+ # include "fe_51/fe.h"
120
+ #else
121
+ # include "fe_25_5/constants.h"
122
+ # include "fe_25_5/fe.h"
123
+ #endif
124
+
125
+ void
126
+ fe25519_invert(fe25519 out, const fe25519 z)
127
+ {
128
+ fe25519 t0;
129
+ fe25519 t1;
130
+ fe25519 t2;
131
+ fe25519 t3;
132
+ int i;
133
+
134
+ fe25519_sq(t0, z);
135
+ fe25519_sq(t1, t0);
136
+ fe25519_sq(t1, t1);
137
+ fe25519_mul(t1, z, t1);
138
+ fe25519_mul(t0, t0, t1);
139
+ fe25519_sq(t2, t0);
140
+ fe25519_mul(t1, t1, t2);
141
+ fe25519_sq(t2, t1);
142
+ for (i = 1; i < 5; ++i) {
143
+ fe25519_sq(t2, t2);
144
+ }
145
+ fe25519_mul(t1, t2, t1);
146
+ fe25519_sq(t2, t1);
147
+ for (i = 1; i < 10; ++i) {
148
+ fe25519_sq(t2, t2);
149
+ }
150
+ fe25519_mul(t2, t2, t1);
151
+ fe25519_sq(t3, t2);
152
+ for (i = 1; i < 20; ++i) {
153
+ fe25519_sq(t3, t3);
154
+ }
155
+ fe25519_mul(t2, t3, t2);
156
+ for (i = 1; i < 11; ++i) {
157
+ fe25519_sq(t2, t2);
158
+ }
159
+ fe25519_mul(t1, t2, t1);
160
+ fe25519_sq(t2, t1);
161
+ for (i = 1; i < 50; ++i) {
162
+ fe25519_sq(t2, t2);
163
+ }
164
+ fe25519_mul(t2, t2, t1);
165
+ fe25519_sq(t3, t2);
166
+ for (i = 1; i < 100; ++i) {
167
+ fe25519_sq(t3, t3);
168
+ }
169
+ fe25519_mul(t2, t3, t2);
170
+ for (i = 1; i < 51; ++i) {
171
+ fe25519_sq(t2, t2);
172
+ }
173
+ fe25519_mul(t1, t2, t1);
174
+ for (i = 1; i < 6; ++i) {
175
+ fe25519_sq(t1, t1);
176
+ }
177
+ fe25519_mul(out, t1, t0);
178
+ }
179
+
180
+ static void
181
+ fe25519_pow22523(fe25519 out, const fe25519 z)
182
+ {
183
+ fe25519 t0;
184
+ fe25519 t1;
185
+ fe25519 t2;
186
+ int i;
187
+
188
+ fe25519_sq(t0, z);
189
+ fe25519_sq(t1, t0);
190
+ fe25519_sq(t1, t1);
191
+ fe25519_mul(t1, z, t1);
192
+ fe25519_mul(t0, t0, t1);
193
+ fe25519_sq(t0, t0);
194
+ fe25519_mul(t0, t1, t0);
195
+ fe25519_sq(t1, t0);
196
+ for (i = 1; i < 5; ++i) {
197
+ fe25519_sq(t1, t1);
198
+ }
199
+ fe25519_mul(t0, t1, t0);
200
+ fe25519_sq(t1, t0);
201
+ for (i = 1; i < 10; ++i) {
202
+ fe25519_sq(t1, t1);
203
+ }
204
+ fe25519_mul(t1, t1, t0);
205
+ fe25519_sq(t2, t1);
206
+ for (i = 1; i < 20; ++i) {
207
+ fe25519_sq(t2, t2);
208
+ }
209
+ fe25519_mul(t1, t2, t1);
210
+ for (i = 1; i < 11; ++i) {
211
+ fe25519_sq(t1, t1);
212
+ }
213
+ fe25519_mul(t0, t1, t0);
214
+ fe25519_sq(t1, t0);
215
+ for (i = 1; i < 50; ++i) {
216
+ fe25519_sq(t1, t1);
217
+ }
218
+ fe25519_mul(t1, t1, t0);
219
+ fe25519_sq(t2, t1);
220
+ for (i = 1; i < 100; ++i) {
221
+ fe25519_sq(t2, t2);
222
+ }
223
+ fe25519_mul(t1, t2, t1);
224
+ for (i = 1; i < 51; ++i) {
225
+ fe25519_sq(t1, t1);
226
+ }
227
+ fe25519_mul(t0, t1, t0);
228
+ fe25519_sq(t0, t0);
229
+ fe25519_sq(t0, t0);
230
+ fe25519_mul(out, t0, z);
231
+ }
232
+
233
+ static void
234
+ fe25519_cneg(fe25519 h, const fe25519 f, unsigned int b)
235
+ {
236
+ fe25519 negf;
237
+
238
+ fe25519_neg(negf, f);
239
+ fe25519_copy(h, f);
240
+ fe25519_cmov(h, negf, b);
241
+ }
242
+
243
+ static void
244
+ fe25519_abs(fe25519 h, const fe25519 f)
245
+ {
246
+ fe25519_cneg(h, f, fe25519_isnegative(f));
247
+ }
248
+
249
+ static void
250
+ fe25519_sqmul(fe25519 s, const int n, const fe25519 a)
251
+ {
252
+ int i;
253
+
254
+ for (i = 0; i < n; i++) {
255
+ fe25519_sq(s, s);
256
+ }
257
+ fe25519_mul(s, s, a);
258
+ }
259
+
260
+ static unsigned int
261
+ fe25519_notsquare(const fe25519 x)
262
+ {
263
+ fe25519 _10, _11, _1100, _1111, _11110000, _11111111;
264
+ fe25519 t, u, v;
265
+ unsigned char s[32];
266
+
267
+ /* Jacobi symbol - x^((p-1)/2) */
268
+ fe25519_mul(_10, x, x);
269
+ fe25519_mul(_11, x, _10);
270
+ fe25519_sq(_1100, _11);
271
+ fe25519_sq(_1100, _1100);
272
+ fe25519_mul(_1111, _11, _1100);
273
+ fe25519_sq(_11110000, _1111);
274
+ fe25519_sq(_11110000, _11110000);
275
+ fe25519_sq(_11110000, _11110000);
276
+ fe25519_sq(_11110000, _11110000);
277
+ fe25519_mul(_11111111, _1111, _11110000);
278
+ fe25519_copy(t, _11111111);
279
+ fe25519_sqmul(t, 2, _11);
280
+ fe25519_copy(u, t);
281
+ fe25519_sqmul(t, 10, u);
282
+ fe25519_sqmul(t, 10, u);
283
+ fe25519_copy(v, t);
284
+ fe25519_sqmul(t, 30, v);
285
+ fe25519_copy(v, t);
286
+ fe25519_sqmul(t, 60, v);
287
+ fe25519_copy(v, t);
288
+ fe25519_sqmul(t, 120, v);
289
+ fe25519_sqmul(t, 10, u);
290
+ fe25519_sqmul(t, 3, _11);
291
+ fe25519_sq(t, t);
292
+
293
+ fe25519_tobytes(s, t);
294
+
295
+ return s[1] & 1;
296
+ }
297
+
298
+ /*
299
+ r = p + q
300
+ */
301
+
302
+ void
303
+ ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q)
304
+ {
305
+ fe25519 t0;
306
+
307
+ fe25519_add(r->X, p->Y, p->X);
308
+ fe25519_sub(r->Y, p->Y, p->X);
309
+ fe25519_mul(r->Z, r->X, q->YplusX);
310
+ fe25519_mul(r->Y, r->Y, q->YminusX);
311
+ fe25519_mul(r->T, q->T2d, p->T);
312
+ fe25519_mul(r->X, p->Z, q->Z);
313
+ fe25519_add(t0, r->X, r->X);
314
+ fe25519_sub(r->X, r->Z, r->Y);
315
+ fe25519_add(r->Y, r->Z, r->Y);
316
+ fe25519_add(r->Z, t0, r->T);
317
+ fe25519_sub(r->T, t0, r->T);
318
+ }
319
+
320
+ static void
321
+ slide_vartime(signed char *r, const unsigned char *a)
322
+ {
323
+ int i;
324
+ int b;
325
+ int k;
326
+ int ribs;
327
+ int cmp;
328
+
329
+ for (i = 0; i < 256; ++i) {
330
+ r[i] = 1 & (a[i >> 3] >> (i & 7));
331
+ }
332
+ for (i = 0; i < 256; ++i) {
333
+ if (! r[i]) {
334
+ continue;
335
+ }
336
+ for (b = 1; b <= 6 && i + b < 256; ++b) {
337
+ if (! r[i + b]) {
338
+ continue;
339
+ }
340
+ ribs = r[i + b] << b;
341
+ cmp = r[i] + ribs;
342
+ if (cmp <= 15) {
343
+ r[i] = cmp;
344
+ r[i + b] = 0;
345
+ } else {
346
+ cmp = r[i] - ribs;
347
+ if (cmp < -15) {
348
+ break;
349
+ }
350
+ r[i] = cmp;
351
+ for (k = i + b; k < 256; ++k) {
352
+ if (! r[k]) {
353
+ r[k] = 1;
354
+ break;
355
+ }
356
+ r[k] = 0;
357
+ }
358
+ }
359
+ }
360
+ }
361
+ }
362
+
363
+ int
364
+ ge25519_frombytes(ge25519_p3 *h, const unsigned char *s)
365
+ {
366
+ fe25519 u;
367
+ fe25519 v;
368
+ fe25519 v3;
369
+ fe25519 vxx;
370
+ fe25519 m_root_check, p_root_check;
371
+ fe25519 negx;
372
+ fe25519 x_sqrtm1;
373
+ int has_m_root, has_p_root;
374
+
375
+ fe25519_frombytes(h->Y, s);
376
+ fe25519_1(h->Z);
377
+ fe25519_sq(u, h->Y);
378
+ fe25519_mul(v, u, d1);
379
+ fe25519_sub(u, u, h->Z); /* u = y^2-1 */
380
+ fe25519_add(v, v, h->Z); /* v = dy^2+1 */
381
+
382
+ fe25519_sq(v3, v);
383
+ fe25519_mul(v3, v3, v); /* v3 = v^3 */
384
+ fe25519_sq(h->X, v3);
385
+ fe25519_mul(h->X, h->X, v);
386
+ fe25519_mul(h->X, h->X, u); /* x = uv^7 */
387
+
388
+ fe25519_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */
389
+ fe25519_mul(h->X, h->X, v3);
390
+ fe25519_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */
391
+
392
+ fe25519_sq(vxx, h->X);
393
+ fe25519_mul(vxx, vxx, v);
394
+ fe25519_sub(m_root_check, vxx, u); /* vx^2-u */
395
+ fe25519_add(p_root_check, vxx, u); /* vx^2+u */
396
+ has_m_root = fe25519_iszero(m_root_check);
397
+ has_p_root = fe25519_iszero(p_root_check);
398
+ fe25519_mul(x_sqrtm1, h->X, sqrtm1); /* x*sqrt(-1) */
399
+ fe25519_cmov(h->X, x_sqrtm1, 1 - has_m_root);
400
+
401
+ fe25519_neg(negx, h->X);
402
+ fe25519_cmov(h->X, negx, fe25519_isnegative(h->X) ^ (s[31] >> 7));
403
+ fe25519_mul(h->T, h->X, h->Y);
404
+
405
+ return (has_m_root | has_p_root) - 1;
406
+ }
407
+
408
+ int
409
+ ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s)
410
+ {
411
+ fe25519 u;
412
+ fe25519 v;
413
+ fe25519 v3;
414
+ fe25519 vxx;
415
+ fe25519 m_root_check, p_root_check;
416
+
417
+ fe25519_frombytes(h->Y, s);
418
+ fe25519_1(h->Z);
419
+ fe25519_sq(u, h->Y);
420
+ fe25519_mul(v, u, d1);
421
+ fe25519_sub(u, u, h->Z); /* u = y^2-1 */
422
+ fe25519_add(v, v, h->Z); /* v = dy^2+1 */
423
+
424
+ fe25519_sq(v3, v);
425
+ fe25519_mul(v3, v3, v); /* v3 = v^3 */
426
+ fe25519_sq(h->X, v3);
427
+ fe25519_mul(h->X, h->X, v);
428
+ fe25519_mul(h->X, h->X, u); /* x = uv^7 */
429
+
430
+ fe25519_pow22523(h->X, h->X); /* x = (uv^7)^((q-5)/8) */
431
+ fe25519_mul(h->X, h->X, v3);
432
+ fe25519_mul(h->X, h->X, u); /* x = uv^3(uv^7)^((q-5)/8) */
433
+
434
+ fe25519_sq(vxx, h->X);
435
+ fe25519_mul(vxx, vxx, v);
436
+ fe25519_sub(m_root_check, vxx, u); /* vx^2-u */
437
+ if (fe25519_iszero(m_root_check) == 0) {
438
+ fe25519_add(p_root_check, vxx, u); /* vx^2+u */
439
+ if (fe25519_iszero(p_root_check) == 0) {
440
+ return -1;
441
+ }
442
+ fe25519_mul(h->X, h->X, sqrtm1);
443
+ }
444
+
445
+ if (fe25519_isnegative(h->X) == (s[31] >> 7)) {
446
+ fe25519_neg(h->X, h->X);
447
+ }
448
+ fe25519_mul(h->T, h->X, h->Y);
449
+
450
+ return 0;
451
+ }
452
+
453
+ /*
454
+ r = p + q
455
+ */
456
+
457
+ static void
458
+ ge25519_madd(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_precomp *q)
459
+ {
460
+ fe25519 t0;
461
+
462
+ fe25519_add(r->X, p->Y, p->X);
463
+ fe25519_sub(r->Y, p->Y, p->X);
464
+ fe25519_mul(r->Z, r->X, q->yplusx);
465
+ fe25519_mul(r->Y, r->Y, q->yminusx);
466
+ fe25519_mul(r->T, q->xy2d, p->T);
467
+ fe25519_add(t0, p->Z, p->Z);
468
+ fe25519_sub(r->X, r->Z, r->Y);
469
+ fe25519_add(r->Y, r->Z, r->Y);
470
+ fe25519_add(r->Z, t0, r->T);
471
+ fe25519_sub(r->T, t0, r->T);
472
+ }
473
+
474
+ /*
475
+ r = p - q
476
+ */
477
+
478
+ static void
479
+ ge25519_msub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_precomp *q)
480
+ {
481
+ fe25519 t0;
482
+
483
+ fe25519_add(r->X, p->Y, p->X);
484
+ fe25519_sub(r->Y, p->Y, p->X);
485
+ fe25519_mul(r->Z, r->X, q->yminusx);
486
+ fe25519_mul(r->Y, r->Y, q->yplusx);
487
+ fe25519_mul(r->T, q->xy2d, p->T);
488
+ fe25519_add(t0, p->Z, p->Z);
489
+ fe25519_sub(r->X, r->Z, r->Y);
490
+ fe25519_add(r->Y, r->Z, r->Y);
491
+ fe25519_sub(r->Z, t0, r->T);
492
+ fe25519_add(r->T, t0, r->T);
493
+ }
494
+
495
+ /*
496
+ r = p
497
+ */
498
+
499
+ void
500
+ ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p)
501
+ {
502
+ fe25519_mul(r->X, p->X, p->T);
503
+ fe25519_mul(r->Y, p->Y, p->Z);
504
+ fe25519_mul(r->Z, p->Z, p->T);
505
+ }
506
+
507
+ /*
508
+ r = p
509
+ */
510
+
511
+ void
512
+ ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p)
513
+ {
514
+ fe25519_mul(r->X, p->X, p->T);
515
+ fe25519_mul(r->Y, p->Y, p->Z);
516
+ fe25519_mul(r->Z, p->Z, p->T);
517
+ fe25519_mul(r->T, p->X, p->Y);
518
+ }
519
+
520
+ static void
521
+ ge25519_p2_0(ge25519_p2 *h)
522
+ {
523
+ fe25519_0(h->X);
524
+ fe25519_1(h->Y);
525
+ fe25519_1(h->Z);
526
+ }
527
+
528
+ /*
529
+ r = 2 * p
530
+ */
531
+
532
+ static void
533
+ ge25519_p2_dbl(ge25519_p1p1 *r, const ge25519_p2 *p)
534
+ {
535
+ fe25519 t0;
536
+
537
+ fe25519_sq(r->X, p->X);
538
+ fe25519_sq(r->Z, p->Y);
539
+ fe25519_sq2(r->T, p->Z);
540
+ fe25519_add(r->Y, p->X, p->Y);
541
+ fe25519_sq(t0, r->Y);
542
+ fe25519_add(r->Y, r->Z, r->X);
543
+ fe25519_sub(r->Z, r->Z, r->X);
544
+ fe25519_sub(r->X, t0, r->Y);
545
+ fe25519_sub(r->T, r->T, r->Z);
546
+ }
547
+
548
+ static void
549
+ ge25519_p3_0(ge25519_p3 *h)
550
+ {
551
+ fe25519_0(h->X);
552
+ fe25519_1(h->Y);
553
+ fe25519_1(h->Z);
554
+ fe25519_0(h->T);
555
+ }
556
+
557
+ static void
558
+ ge25519_cached_0(ge25519_cached *h)
559
+ {
560
+ fe25519_1(h->YplusX);
561
+ fe25519_1(h->YminusX);
562
+ fe25519_1(h->Z);
563
+ fe25519_0(h->T2d);
564
+ }
565
+
566
+ /*
567
+ r = p
568
+ */
569
+
570
+ void
571
+ ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p)
572
+ {
573
+ fe25519_add(r->YplusX, p->Y, p->X);
574
+ fe25519_sub(r->YminusX, p->Y, p->X);
575
+ fe25519_copy(r->Z, p->Z);
576
+ fe25519_mul(r->T2d, p->T, d2);
577
+ }
578
+
579
+ static void
580
+ ge25519_p3_to_precomp(ge25519_precomp *pi, const ge25519_p3 *p)
581
+ {
582
+ fe25519 recip;
583
+ fe25519 x;
584
+ fe25519 y;
585
+ fe25519 xy;
586
+
587
+ fe25519_invert(recip, p->Z);
588
+ fe25519_mul(x, p->X, recip);
589
+ fe25519_mul(y, p->Y, recip);
590
+ fe25519_add(pi->yplusx, y, x);
591
+ fe25519_sub(pi->yminusx, y, x);
592
+ fe25519_mul(xy, x, y);
593
+ fe25519_mul(pi->xy2d, xy, d2);
594
+ }
595
+
596
+ /*
597
+ r = p
598
+ */
599
+
600
+ static void
601
+ ge25519_p3_to_p2(ge25519_p2 *r, const ge25519_p3 *p)
602
+ {
603
+ fe25519_copy(r->X, p->X);
604
+ fe25519_copy(r->Y, p->Y);
605
+ fe25519_copy(r->Z, p->Z);
606
+ }
607
+
608
+ void
609
+ ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h)
610
+ {
611
+ fe25519 recip;
612
+ fe25519 x;
613
+ fe25519 y;
614
+
615
+ fe25519_invert(recip, h->Z);
616
+ fe25519_mul(x, h->X, recip);
617
+ fe25519_mul(y, h->Y, recip);
618
+ fe25519_tobytes(s, y);
619
+ s[31] ^= fe25519_isnegative(x) << 7;
620
+ }
621
+
622
+ /*
623
+ r = 2 * p
624
+ */
625
+
626
+ static void
627
+ ge25519_p3_dbl(ge25519_p1p1 *r, const ge25519_p3 *p)
628
+ {
629
+ ge25519_p2 q;
630
+ ge25519_p3_to_p2(&q, p);
631
+ ge25519_p2_dbl(r, &q);
632
+ }
633
+
634
+ static void
635
+ ge25519_precomp_0(ge25519_precomp *h)
636
+ {
637
+ fe25519_1(h->yplusx);
638
+ fe25519_1(h->yminusx);
639
+ fe25519_0(h->xy2d);
640
+ }
641
+
642
+ static unsigned char
643
+ equal(signed char b, signed char c)
644
+ {
645
+ unsigned char ub = b;
646
+ unsigned char uc = c;
647
+ unsigned char x = ub ^ uc; /* 0: yes; 1..255: no */
648
+ uint32_t y = (uint32_t) x; /* 0: yes; 1..255: no */
649
+
650
+ y -= 1; /* 4294967295: yes; 0..254: no */
651
+ y >>= 31; /* 1: yes; 0: no */
652
+
653
+ return y;
654
+ }
655
+
656
+ static unsigned char
657
+ negative(signed char b)
658
+ {
659
+ /* 18446744073709551361..18446744073709551615: yes; 0..255: no */
660
+ uint64_t x = b;
661
+
662
+ x >>= 63; /* 1: yes; 0: no */
663
+
664
+ return x;
665
+ }
666
+
667
+ static void
668
+ ge25519_cmov(ge25519_precomp *t, const ge25519_precomp *u, unsigned char b)
669
+ {
670
+ fe25519_cmov(t->yplusx, u->yplusx, b);
671
+ fe25519_cmov(t->yminusx, u->yminusx, b);
672
+ fe25519_cmov(t->xy2d, u->xy2d, b);
673
+ }
674
+
675
+ static void
676
+ ge25519_cmov_cached(ge25519_cached *t, const ge25519_cached *u, unsigned char b)
677
+ {
678
+ fe25519_cmov(t->YplusX, u->YplusX, b);
679
+ fe25519_cmov(t->YminusX, u->YminusX, b);
680
+ fe25519_cmov(t->Z, u->Z, b);
681
+ fe25519_cmov(t->T2d, u->T2d, b);
682
+ }
683
+
684
+ static void
685
+ ge25519_cmov8(ge25519_precomp *t, const ge25519_precomp precomp[8], const signed char b)
686
+ {
687
+ ge25519_precomp minust;
688
+ const unsigned char bnegative = negative(b);
689
+ const unsigned char babs = b - (((-bnegative) & b) * ((signed char) 1 << 1));
690
+
691
+ ge25519_precomp_0(t);
692
+ ge25519_cmov(t, &precomp[0], equal(babs, 1));
693
+ ge25519_cmov(t, &precomp[1], equal(babs, 2));
694
+ ge25519_cmov(t, &precomp[2], equal(babs, 3));
695
+ ge25519_cmov(t, &precomp[3], equal(babs, 4));
696
+ ge25519_cmov(t, &precomp[4], equal(babs, 5));
697
+ ge25519_cmov(t, &precomp[5], equal(babs, 6));
698
+ ge25519_cmov(t, &precomp[6], equal(babs, 7));
699
+ ge25519_cmov(t, &precomp[7], equal(babs, 8));
700
+ fe25519_copy(minust.yplusx, t->yminusx);
701
+ fe25519_copy(minust.yminusx, t->yplusx);
702
+ fe25519_neg(minust.xy2d, t->xy2d);
703
+ ge25519_cmov(t, &minust, bnegative);
704
+ }
705
+
706
+ static void
707
+ ge25519_cmov8_base(ge25519_precomp *t, const int pos, const signed char b)
708
+ {
709
+ static const ge25519_precomp base[32][8] = { /* base[i][j] = (j+1)*256^i*B */
710
+ #ifdef HAVE_TI_MODE
711
+ # include "fe_51/base.h"
712
+ #else
713
+ # include "fe_25_5/base.h"
714
+ #endif
715
+ };
716
+ ge25519_cmov8(t, base[pos], b);
717
+ }
718
+
719
+ static void
720
+ ge25519_cmov8_cached(ge25519_cached *t, const ge25519_cached cached[8], const signed char b)
721
+ {
722
+ ge25519_cached minust;
723
+ const unsigned char bnegative = negative(b);
724
+ const unsigned char babs = b - (((-bnegative) & b) * ((signed char) 1 << 1));
725
+
726
+ ge25519_cached_0(t);
727
+ ge25519_cmov_cached(t, &cached[0], equal(babs, 1));
728
+ ge25519_cmov_cached(t, &cached[1], equal(babs, 2));
729
+ ge25519_cmov_cached(t, &cached[2], equal(babs, 3));
730
+ ge25519_cmov_cached(t, &cached[3], equal(babs, 4));
731
+ ge25519_cmov_cached(t, &cached[4], equal(babs, 5));
732
+ ge25519_cmov_cached(t, &cached[5], equal(babs, 6));
733
+ ge25519_cmov_cached(t, &cached[6], equal(babs, 7));
734
+ ge25519_cmov_cached(t, &cached[7], equal(babs, 8));
735
+ fe25519_copy(minust.YplusX, t->YminusX);
736
+ fe25519_copy(minust.YminusX, t->YplusX);
737
+ fe25519_copy(minust.Z, t->Z);
738
+ fe25519_neg(minust.T2d, t->T2d);
739
+ ge25519_cmov_cached(t, &minust, bnegative);
740
+ }
741
+
742
+ /*
743
+ r = p - q
744
+ */
745
+
746
+ void
747
+ ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q)
748
+ {
749
+ fe25519 t0;
750
+
751
+ fe25519_add(r->X, p->Y, p->X);
752
+ fe25519_sub(r->Y, p->Y, p->X);
753
+ fe25519_mul(r->Z, r->X, q->YminusX);
754
+ fe25519_mul(r->Y, r->Y, q->YplusX);
755
+ fe25519_mul(r->T, q->T2d, p->T);
756
+ fe25519_mul(r->X, p->Z, q->Z);
757
+ fe25519_add(t0, r->X, r->X);
758
+ fe25519_sub(r->X, r->Z, r->Y);
759
+ fe25519_add(r->Y, r->Z, r->Y);
760
+ fe25519_sub(r->Z, t0, r->T);
761
+ fe25519_add(r->T, t0, r->T);
762
+ }
763
+
764
+ void
765
+ ge25519_tobytes(unsigned char *s, const ge25519_p2 *h)
766
+ {
767
+ fe25519 recip;
768
+ fe25519 x;
769
+ fe25519 y;
770
+
771
+ fe25519_invert(recip, h->Z);
772
+ fe25519_mul(x, h->X, recip);
773
+ fe25519_mul(y, h->Y, recip);
774
+ fe25519_tobytes(s, y);
775
+ s[31] ^= fe25519_isnegative(x) << 7;
776
+ }
777
+
778
+ /*
779
+ r = a * A + b * B
780
+ where a = a[0]+256*a[1]+...+256^31 a[31].
781
+ and b = b[0]+256*b[1]+...+256^31 b[31].
782
+ B is the Ed25519 base point (x,4/5) with x positive.
783
+
784
+ Only used for signatures verification.
785
+ */
786
+
787
+ void
788
+ ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a,
789
+ const ge25519_p3 *A, const unsigned char *b)
790
+ {
791
+ static const ge25519_precomp Bi[8] = {
792
+ #ifdef HAVE_TI_MODE
793
+ # include "fe_51/base2.h"
794
+ #else
795
+ # include "fe_25_5/base2.h"
796
+ #endif
797
+ };
798
+ signed char aslide[256];
799
+ signed char bslide[256];
800
+ ge25519_cached Ai[8]; /* A,3A,5A,7A,9A,11A,13A,15A */
801
+ ge25519_p1p1 t;
802
+ ge25519_p3 u;
803
+ ge25519_p3 A2;
804
+ int i;
805
+
806
+ slide_vartime(aslide, a);
807
+ slide_vartime(bslide, b);
808
+
809
+ ge25519_p3_to_cached(&Ai[0], A);
810
+
811
+ ge25519_p3_dbl(&t, A);
812
+ ge25519_p1p1_to_p3(&A2, &t);
813
+
814
+ ge25519_add(&t, &A2, &Ai[0]);
815
+ ge25519_p1p1_to_p3(&u, &t);
816
+ ge25519_p3_to_cached(&Ai[1], &u);
817
+
818
+ ge25519_add(&t, &A2, &Ai[1]);
819
+ ge25519_p1p1_to_p3(&u, &t);
820
+ ge25519_p3_to_cached(&Ai[2], &u);
821
+
822
+ ge25519_add(&t, &A2, &Ai[2]);
823
+ ge25519_p1p1_to_p3(&u, &t);
824
+ ge25519_p3_to_cached(&Ai[3], &u);
825
+
826
+ ge25519_add(&t, &A2, &Ai[3]);
827
+ ge25519_p1p1_to_p3(&u, &t);
828
+ ge25519_p3_to_cached(&Ai[4], &u);
829
+
830
+ ge25519_add(&t, &A2, &Ai[4]);
831
+ ge25519_p1p1_to_p3(&u, &t);
832
+ ge25519_p3_to_cached(&Ai[5], &u);
833
+
834
+ ge25519_add(&t, &A2, &Ai[5]);
835
+ ge25519_p1p1_to_p3(&u, &t);
836
+ ge25519_p3_to_cached(&Ai[6], &u);
837
+
838
+ ge25519_add(&t, &A2, &Ai[6]);
839
+ ge25519_p1p1_to_p3(&u, &t);
840
+ ge25519_p3_to_cached(&Ai[7], &u);
841
+
842
+ ge25519_p2_0(r);
843
+
844
+ for (i = 255; i >= 0; --i) {
845
+ if (aslide[i] || bslide[i]) {
846
+ break;
847
+ }
848
+ }
849
+
850
+ for (; i >= 0; --i) {
851
+ ge25519_p2_dbl(&t, r);
852
+
853
+ if (aslide[i] > 0) {
854
+ ge25519_p1p1_to_p3(&u, &t);
855
+ ge25519_add(&t, &u, &Ai[aslide[i] / 2]);
856
+ } else if (aslide[i] < 0) {
857
+ ge25519_p1p1_to_p3(&u, &t);
858
+ ge25519_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
859
+ }
860
+
861
+ if (bslide[i] > 0) {
862
+ ge25519_p1p1_to_p3(&u, &t);
863
+ ge25519_madd(&t, &u, &Bi[bslide[i] / 2]);
864
+ } else if (bslide[i] < 0) {
865
+ ge25519_p1p1_to_p3(&u, &t);
866
+ ge25519_msub(&t, &u, &Bi[(-bslide[i]) / 2]);
867
+ }
868
+
869
+ ge25519_p1p1_to_p2(r, &t);
870
+ }
871
+ }
872
+
873
+ /*
874
+ h = a * p
875
+ where a = a[0]+256*a[1]+...+256^31 a[31]
876
+
877
+ Preconditions:
878
+ a[31] <= 127
879
+
880
+ p is public
881
+ */
882
+
883
+ void
884
+ ge25519_scalarmult(ge25519_p3 *h, const unsigned char *a, const ge25519_p3 *p)
885
+ {
886
+ signed char e[64];
887
+ signed char carry;
888
+ ge25519_p1p1 r;
889
+ ge25519_p2 s;
890
+ ge25519_p1p1 t2, t3, t4, t5, t6, t7, t8;
891
+ ge25519_p3 p2, p3, p4, p5, p6, p7, p8;
892
+ ge25519_cached pi[8];
893
+ ge25519_cached t;
894
+ int i;
895
+
896
+ ge25519_p3_to_cached(&pi[1 - 1], p); /* p */
897
+
898
+ ge25519_p3_dbl(&t2, p);
899
+ ge25519_p1p1_to_p3(&p2, &t2);
900
+ ge25519_p3_to_cached(&pi[2 - 1], &p2); /* 2p = 2*p */
901
+
902
+ ge25519_add(&t3, p, &pi[2 - 1]);
903
+ ge25519_p1p1_to_p3(&p3, &t3);
904
+ ge25519_p3_to_cached(&pi[3 - 1], &p3); /* 3p = 2p+p */
905
+
906
+ ge25519_p3_dbl(&t4, &p2);
907
+ ge25519_p1p1_to_p3(&p4, &t4);
908
+ ge25519_p3_to_cached(&pi[4 - 1], &p4); /* 4p = 2*2p */
909
+
910
+ ge25519_add(&t5, p, &pi[4 - 1]);
911
+ ge25519_p1p1_to_p3(&p5, &t5);
912
+ ge25519_p3_to_cached(&pi[5 - 1], &p5); /* 5p = 4p+p */
913
+
914
+ ge25519_p3_dbl(&t6, &p3);
915
+ ge25519_p1p1_to_p3(&p6, &t6);
916
+ ge25519_p3_to_cached(&pi[6 - 1], &p6); /* 6p = 2*3p */
917
+
918
+ ge25519_add(&t7, p, &pi[6 - 1]);
919
+ ge25519_p1p1_to_p3(&p7, &t7);
920
+ ge25519_p3_to_cached(&pi[7 - 1], &p7); /* 7p = 6p+p */
921
+
922
+ ge25519_p3_dbl(&t8, &p4);
923
+ ge25519_p1p1_to_p3(&p8, &t8);
924
+ ge25519_p3_to_cached(&pi[8 - 1], &p8); /* 8p = 2*4p */
925
+
926
+ for (i = 0; i < 32; ++i) {
927
+ e[2 * i + 0] = (a[i] >> 0) & 15;
928
+ e[2 * i + 1] = (a[i] >> 4) & 15;
929
+ }
930
+ /* each e[i] is between 0 and 15 */
931
+ /* e[63] is between 0 and 7 */
932
+
933
+ carry = 0;
934
+ for (i = 0; i < 63; ++i) {
935
+ e[i] += carry;
936
+ carry = e[i] + 8;
937
+ carry >>= 4;
938
+ e[i] -= carry * ((signed char) 1 << 4);
939
+ }
940
+ e[63] += carry;
941
+ /* each e[i] is between -8 and 8 */
942
+
943
+ ge25519_p3_0(h);
944
+
945
+ for (i = 63; i != 0; i--) {
946
+ ge25519_cmov8_cached(&t, pi, e[i]);
947
+ ge25519_add(&r, h, &t);
948
+
949
+ ge25519_p1p1_to_p2(&s, &r);
950
+ ge25519_p2_dbl(&r, &s);
951
+ ge25519_p1p1_to_p2(&s, &r);
952
+ ge25519_p2_dbl(&r, &s);
953
+ ge25519_p1p1_to_p2(&s, &r);
954
+ ge25519_p2_dbl(&r, &s);
955
+ ge25519_p1p1_to_p2(&s, &r);
956
+ ge25519_p2_dbl(&r, &s);
957
+
958
+ ge25519_p1p1_to_p3(h, &r); /* *16 */
959
+ }
960
+ ge25519_cmov8_cached(&t, pi, e[i]);
961
+ ge25519_add(&r, h, &t);
962
+
963
+ ge25519_p1p1_to_p3(h, &r);
964
+ }
965
+
966
+ /*
967
+ h = a * B (with precomputation)
968
+ where a = a[0]+256*a[1]+...+256^31 a[31]
969
+ B is the Ed25519 base point (x,4/5) with x positive
970
+ (as bytes: 0x5866666666666666666666666666666666666666666666666666666666666666)
971
+
972
+ Preconditions:
973
+ a[31] <= 127
974
+ */
975
+
976
+ void
977
+ ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a)
978
+ {
979
+ signed char e[64];
980
+ signed char carry;
981
+ ge25519_p1p1 r;
982
+ ge25519_p2 s;
983
+ ge25519_precomp t;
984
+ int i;
985
+
986
+ for (i = 0; i < 32; ++i) {
987
+ e[2 * i + 0] = (a[i] >> 0) & 15;
988
+ e[2 * i + 1] = (a[i] >> 4) & 15;
989
+ }
990
+ /* each e[i] is between 0 and 15 */
991
+ /* e[63] is between 0 and 7 */
992
+
993
+ carry = 0;
994
+ for (i = 0; i < 63; ++i) {
995
+ e[i] += carry;
996
+ carry = e[i] + 8;
997
+ carry >>= 4;
998
+ e[i] -= carry * ((signed char) 1 << 4);
999
+ }
1000
+ e[63] += carry;
1001
+ /* each e[i] is between -8 and 8 */
1002
+
1003
+ ge25519_p3_0(h);
1004
+
1005
+ for (i = 1; i < 64; i += 2) {
1006
+ ge25519_cmov8_base(&t, i / 2, e[i]);
1007
+ ge25519_madd(&r, h, &t);
1008
+ ge25519_p1p1_to_p3(h, &r);
1009
+ }
1010
+
1011
+ ge25519_p3_dbl(&r, h);
1012
+ ge25519_p1p1_to_p2(&s, &r);
1013
+ ge25519_p2_dbl(&r, &s);
1014
+ ge25519_p1p1_to_p2(&s, &r);
1015
+ ge25519_p2_dbl(&r, &s);
1016
+ ge25519_p1p1_to_p2(&s, &r);
1017
+ ge25519_p2_dbl(&r, &s);
1018
+ ge25519_p1p1_to_p3(h, &r);
1019
+
1020
+ for (i = 0; i < 64; i += 2) {
1021
+ ge25519_cmov8_base(&t, i / 2, e[i]);
1022
+ ge25519_madd(&r, h, &t);
1023
+ ge25519_p1p1_to_p3(h, &r);
1024
+ }
1025
+ }
1026
+
1027
+ /* multiply by the order of the main subgroup l = 2^252+27742317777372353535851937790883648493 */
1028
+ static void
1029
+ ge25519_mul_l(ge25519_p3 *r, const ge25519_p3 *A)
1030
+ {
1031
+ static const signed char aslide[253] = {
1032
+ 13, 0, 0, 0, 0, -1, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, -13, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, 0, 11, 0, 0, 0, 0, -13, 0, 0, 0, 0, 0, 0, -3, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 3, 0, 0, 0, 0, -11, 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 7, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1
1033
+ };
1034
+ ge25519_cached Ai[8];
1035
+ ge25519_p1p1 t;
1036
+ ge25519_p3 u;
1037
+ ge25519_p3 A2;
1038
+ int i;
1039
+
1040
+ ge25519_p3_to_cached(&Ai[0], A);
1041
+ ge25519_p3_dbl(&t, A);
1042
+ ge25519_p1p1_to_p3(&A2, &t);
1043
+ ge25519_add(&t, &A2, &Ai[0]);
1044
+ ge25519_p1p1_to_p3(&u, &t);
1045
+ ge25519_p3_to_cached(&Ai[1], &u);
1046
+ ge25519_add(&t, &A2, &Ai[1]);
1047
+ ge25519_p1p1_to_p3(&u, &t);
1048
+ ge25519_p3_to_cached(&Ai[2], &u);
1049
+ ge25519_add(&t, &A2, &Ai[2]);
1050
+ ge25519_p1p1_to_p3(&u, &t);
1051
+ ge25519_p3_to_cached(&Ai[3], &u);
1052
+ ge25519_add(&t, &A2, &Ai[3]);
1053
+ ge25519_p1p1_to_p3(&u, &t);
1054
+ ge25519_p3_to_cached(&Ai[4], &u);
1055
+ ge25519_add(&t, &A2, &Ai[4]);
1056
+ ge25519_p1p1_to_p3(&u, &t);
1057
+ ge25519_p3_to_cached(&Ai[5], &u);
1058
+ ge25519_add(&t, &A2, &Ai[5]);
1059
+ ge25519_p1p1_to_p3(&u, &t);
1060
+ ge25519_p3_to_cached(&Ai[6], &u);
1061
+ ge25519_add(&t, &A2, &Ai[6]);
1062
+ ge25519_p1p1_to_p3(&u, &t);
1063
+ ge25519_p3_to_cached(&Ai[7], &u);
1064
+
1065
+ ge25519_p3_0(r);
1066
+
1067
+ for (i = 252; i >= 0; --i) {
1068
+ ge25519_p3_dbl(&t, r);
1069
+
1070
+ if (aslide[i] > 0) {
1071
+ ge25519_p1p1_to_p3(&u, &t);
1072
+ ge25519_add(&t, &u, &Ai[aslide[i] / 2]);
1073
+ } else if (aslide[i] < 0) {
1074
+ ge25519_p1p1_to_p3(&u, &t);
1075
+ ge25519_sub(&t, &u, &Ai[(-aslide[i]) / 2]);
1076
+ }
1077
+
1078
+ ge25519_p1p1_to_p3(r, &t);
1079
+ }
1080
+ }
1081
+
1082
+ int
1083
+ ge25519_is_on_curve(const ge25519_p3 *p)
1084
+ {
1085
+ fe25519 x2;
1086
+ fe25519 y2;
1087
+ fe25519 z2;
1088
+ fe25519 z4;
1089
+ fe25519 t0;
1090
+ fe25519 t1;
1091
+
1092
+ fe25519_sq(x2, p->X);
1093
+ fe25519_sq(y2, p->Y);
1094
+ fe25519_sq(z2, p->Z);
1095
+ fe25519_sub(t0, y2, x2);
1096
+ fe25519_mul(t0, t0, z2);
1097
+
1098
+ fe25519_mul(t1, x2, y2);
1099
+ fe25519_mul(t1, t1, d1);
1100
+ fe25519_sq(z4, z2);
1101
+ fe25519_add(t1, t1, z4);
1102
+ fe25519_sub(t0, t0, t1);
1103
+
1104
+ return fe25519_iszero(t0);
1105
+ }
1106
+
1107
+ int
1108
+ ge25519_is_on_main_subgroup(const ge25519_p3 *p)
1109
+ {
1110
+ ge25519_p3 pl;
1111
+
1112
+ ge25519_mul_l(&pl, p);
1113
+
1114
+ return fe25519_iszero(pl.X);
1115
+ }
1116
+
1117
+ int
1118
+ ge25519_is_canonical(const unsigned char *s)
1119
+ {
1120
+ unsigned char c;
1121
+ unsigned char d;
1122
+ unsigned int i;
1123
+
1124
+ c = (s[31] & 0x7f) ^ 0x7f;
1125
+ for (i = 30; i > 0; i--) {
1126
+ c |= s[i] ^ 0xff;
1127
+ }
1128
+ c = (((unsigned int) c) - 1U) >> 8;
1129
+ d = (0xed - 1U - (unsigned int) s[0]) >> 8;
1130
+
1131
+ return 1 - (c & d & 1);
1132
+ }
1133
+
1134
+ int
1135
+ ge25519_has_small_order(const unsigned char s[32])
1136
+ {
1137
+ CRYPTO_ALIGN(16)
1138
+ static const unsigned char blacklist[][32] = {
1139
+ /* 0 (order 4) */
1140
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1141
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1142
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1143
+ /* 1 (order 1) */
1144
+ { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1145
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1146
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1147
+ /* 2707385501144840649318225287225658788936804267575313519463743609750303402022
1148
+ (order 8) */
1149
+ { 0x26, 0xe8, 0x95, 0x8f, 0xc2, 0xb2, 0x27, 0xb0, 0x45, 0xc3, 0xf4,
1150
+ 0x89, 0xf2, 0xef, 0x98, 0xf0, 0xd5, 0xdf, 0xac, 0x05, 0xd3, 0xc6,
1151
+ 0x33, 0x39, 0xb1, 0x38, 0x02, 0x88, 0x6d, 0x53, 0xfc, 0x05 },
1152
+ /* 55188659117513257062467267217118295137698188065244968500265048394206261417927
1153
+ (order 8) */
1154
+ { 0xc7, 0x17, 0x6a, 0x70, 0x3d, 0x4d, 0xd8, 0x4f, 0xba, 0x3c, 0x0b,
1155
+ 0x76, 0x0d, 0x10, 0x67, 0x0f, 0x2a, 0x20, 0x53, 0xfa, 0x2c, 0x39,
1156
+ 0xcc, 0xc6, 0x4e, 0xc7, 0xfd, 0x77, 0x92, 0xac, 0x03, 0x7a },
1157
+ /* p-1 (order 2) */
1158
+ { 0xec, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1159
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1160
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },
1161
+ /* p (=0, order 4) */
1162
+ { 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1163
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1164
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f },
1165
+ /* p+1 (=1, order 1) */
1166
+ { 0xee, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1167
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
1168
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }
1169
+ };
1170
+ unsigned char c[7] = { 0 };
1171
+ unsigned int k;
1172
+ size_t i, j;
1173
+
1174
+ COMPILER_ASSERT(7 == sizeof blacklist / sizeof blacklist[0]);
1175
+ for (j = 0; j < 31; j++) {
1176
+ for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {
1177
+ c[i] |= s[j] ^ blacklist[i][j];
1178
+ }
1179
+ }
1180
+ for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {
1181
+ c[i] |= (s[j] & 0x7f) ^ blacklist[i][j];
1182
+ }
1183
+ k = 0;
1184
+ for (i = 0; i < sizeof blacklist / sizeof blacklist[0]; i++) {
1185
+ k |= (c[i] - 1);
1186
+ }
1187
+ return (int) ((k >> 8) & 1);
1188
+ }
1189
+
1190
+ /*
1191
+ Input:
1192
+ a[0]+256*a[1]+...+256^31*a[31] = a
1193
+ b[0]+256*b[1]+...+256^31*b[31] = b
1194
+ *
1195
+ Output:
1196
+ s[0]+256*s[1]+...+256^31*s[31] = (ab) mod l
1197
+ where l = 2^252 + 27742317777372353535851937790883648493.
1198
+ */
1199
+
1200
+ void
1201
+ sc25519_mul(unsigned char s[32], const unsigned char a[32], const unsigned char b[32])
1202
+ {
1203
+ int64_t a0 = 2097151 & load_3(a);
1204
+ int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
1205
+ int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
1206
+ int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
1207
+ int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
1208
+ int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
1209
+ int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
1210
+ int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
1211
+ int64_t a8 = 2097151 & load_3(a + 21);
1212
+ int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
1213
+ int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
1214
+ int64_t a11 = (load_4(a + 28) >> 7);
1215
+
1216
+ int64_t b0 = 2097151 & load_3(b);
1217
+ int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
1218
+ int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
1219
+ int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
1220
+ int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
1221
+ int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
1222
+ int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
1223
+ int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
1224
+ int64_t b8 = 2097151 & load_3(b + 21);
1225
+ int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
1226
+ int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
1227
+ int64_t b11 = (load_4(b + 28) >> 7);
1228
+
1229
+ int64_t s0;
1230
+ int64_t s1;
1231
+ int64_t s2;
1232
+ int64_t s3;
1233
+ int64_t s4;
1234
+ int64_t s5;
1235
+ int64_t s6;
1236
+ int64_t s7;
1237
+ int64_t s8;
1238
+ int64_t s9;
1239
+ int64_t s10;
1240
+ int64_t s11;
1241
+ int64_t s12;
1242
+ int64_t s13;
1243
+ int64_t s14;
1244
+ int64_t s15;
1245
+ int64_t s16;
1246
+ int64_t s17;
1247
+ int64_t s18;
1248
+ int64_t s19;
1249
+ int64_t s20;
1250
+ int64_t s21;
1251
+ int64_t s22;
1252
+ int64_t s23;
1253
+
1254
+ int64_t carry0;
1255
+ int64_t carry1;
1256
+ int64_t carry2;
1257
+ int64_t carry3;
1258
+ int64_t carry4;
1259
+ int64_t carry5;
1260
+ int64_t carry6;
1261
+ int64_t carry7;
1262
+ int64_t carry8;
1263
+ int64_t carry9;
1264
+ int64_t carry10;
1265
+ int64_t carry11;
1266
+ int64_t carry12;
1267
+ int64_t carry13;
1268
+ int64_t carry14;
1269
+ int64_t carry15;
1270
+ int64_t carry16;
1271
+ int64_t carry17;
1272
+ int64_t carry18;
1273
+ int64_t carry19;
1274
+ int64_t carry20;
1275
+ int64_t carry21;
1276
+ int64_t carry22;
1277
+
1278
+ s0 = a0 * b0;
1279
+ s1 = a0 * b1 + a1 * b0;
1280
+ s2 = a0 * b2 + a1 * b1 + a2 * b0;
1281
+ s3 = a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
1282
+ s4 = a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
1283
+ s5 = a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
1284
+ s6 = a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 + a6 * b0;
1285
+ s7 = a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
1286
+ a6 * b1 + a7 * b0;
1287
+ s8 = a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
1288
+ a6 * b2 + a7 * b1 + a8 * b0;
1289
+ s9 = a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
1290
+ a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
1291
+ s10 = a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
1292
+ a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
1293
+ s11 = a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
1294
+ a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
1295
+ s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 +
1296
+ a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
1297
+ s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 +
1298
+ a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2;
1299
+ s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 +
1300
+ a9 * b5 + a10 * b4 + a11 * b3;
1301
+ s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 +
1302
+ a10 * b5 + a11 * b4;
1303
+ s16 =
1304
+ a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
1305
+ s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
1306
+ s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
1307
+ s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
1308
+ s20 = a9 * b11 + a10 * b10 + a11 * b9;
1309
+ s21 = a10 * b11 + a11 * b10;
1310
+ s22 = a11 * b11;
1311
+ s23 = 0;
1312
+
1313
+ carry0 = (s0 + (int64_t) (1L << 20)) >> 21;
1314
+ s1 += carry0;
1315
+ s0 -= carry0 * ((uint64_t) 1L << 21);
1316
+ carry2 = (s2 + (int64_t) (1L << 20)) >> 21;
1317
+ s3 += carry2;
1318
+ s2 -= carry2 * ((uint64_t) 1L << 21);
1319
+ carry4 = (s4 + (int64_t) (1L << 20)) >> 21;
1320
+ s5 += carry4;
1321
+ s4 -= carry4 * ((uint64_t) 1L << 21);
1322
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
1323
+ s7 += carry6;
1324
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1325
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
1326
+ s9 += carry8;
1327
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1328
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
1329
+ s11 += carry10;
1330
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1331
+ carry12 = (s12 + (int64_t) (1L << 20)) >> 21;
1332
+ s13 += carry12;
1333
+ s12 -= carry12 * ((uint64_t) 1L << 21);
1334
+ carry14 = (s14 + (int64_t) (1L << 20)) >> 21;
1335
+ s15 += carry14;
1336
+ s14 -= carry14 * ((uint64_t) 1L << 21);
1337
+ carry16 = (s16 + (int64_t) (1L << 20)) >> 21;
1338
+ s17 += carry16;
1339
+ s16 -= carry16 * ((uint64_t) 1L << 21);
1340
+ carry18 = (s18 + (int64_t) (1L << 20)) >> 21;
1341
+ s19 += carry18;
1342
+ s18 -= carry18 * ((uint64_t) 1L << 21);
1343
+ carry20 = (s20 + (int64_t) (1L << 20)) >> 21;
1344
+ s21 += carry20;
1345
+ s20 -= carry20 * ((uint64_t) 1L << 21);
1346
+ carry22 = (s22 + (int64_t) (1L << 20)) >> 21;
1347
+ s23 += carry22;
1348
+ s22 -= carry22 * ((uint64_t) 1L << 21);
1349
+
1350
+ carry1 = (s1 + (int64_t) (1L << 20)) >> 21;
1351
+ s2 += carry1;
1352
+ s1 -= carry1 * ((uint64_t) 1L << 21);
1353
+ carry3 = (s3 + (int64_t) (1L << 20)) >> 21;
1354
+ s4 += carry3;
1355
+ s3 -= carry3 * ((uint64_t) 1L << 21);
1356
+ carry5 = (s5 + (int64_t) (1L << 20)) >> 21;
1357
+ s6 += carry5;
1358
+ s5 -= carry5 * ((uint64_t) 1L << 21);
1359
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
1360
+ s8 += carry7;
1361
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1362
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
1363
+ s10 += carry9;
1364
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1365
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
1366
+ s12 += carry11;
1367
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1368
+ carry13 = (s13 + (int64_t) (1L << 20)) >> 21;
1369
+ s14 += carry13;
1370
+ s13 -= carry13 * ((uint64_t) 1L << 21);
1371
+ carry15 = (s15 + (int64_t) (1L << 20)) >> 21;
1372
+ s16 += carry15;
1373
+ s15 -= carry15 * ((uint64_t) 1L << 21);
1374
+ carry17 = (s17 + (int64_t) (1L << 20)) >> 21;
1375
+ s18 += carry17;
1376
+ s17 -= carry17 * ((uint64_t) 1L << 21);
1377
+ carry19 = (s19 + (int64_t) (1L << 20)) >> 21;
1378
+ s20 += carry19;
1379
+ s19 -= carry19 * ((uint64_t) 1L << 21);
1380
+ carry21 = (s21 + (int64_t) (1L << 20)) >> 21;
1381
+ s22 += carry21;
1382
+ s21 -= carry21 * ((uint64_t) 1L << 21);
1383
+
1384
+ s11 += s23 * 666643;
1385
+ s12 += s23 * 470296;
1386
+ s13 += s23 * 654183;
1387
+ s14 -= s23 * 997805;
1388
+ s15 += s23 * 136657;
1389
+ s16 -= s23 * 683901;
1390
+
1391
+ s10 += s22 * 666643;
1392
+ s11 += s22 * 470296;
1393
+ s12 += s22 * 654183;
1394
+ s13 -= s22 * 997805;
1395
+ s14 += s22 * 136657;
1396
+ s15 -= s22 * 683901;
1397
+
1398
+ s9 += s21 * 666643;
1399
+ s10 += s21 * 470296;
1400
+ s11 += s21 * 654183;
1401
+ s12 -= s21 * 997805;
1402
+ s13 += s21 * 136657;
1403
+ s14 -= s21 * 683901;
1404
+
1405
+ s8 += s20 * 666643;
1406
+ s9 += s20 * 470296;
1407
+ s10 += s20 * 654183;
1408
+ s11 -= s20 * 997805;
1409
+ s12 += s20 * 136657;
1410
+ s13 -= s20 * 683901;
1411
+
1412
+ s7 += s19 * 666643;
1413
+ s8 += s19 * 470296;
1414
+ s9 += s19 * 654183;
1415
+ s10 -= s19 * 997805;
1416
+ s11 += s19 * 136657;
1417
+ s12 -= s19 * 683901;
1418
+
1419
+ s6 += s18 * 666643;
1420
+ s7 += s18 * 470296;
1421
+ s8 += s18 * 654183;
1422
+ s9 -= s18 * 997805;
1423
+ s10 += s18 * 136657;
1424
+ s11 -= s18 * 683901;
1425
+
1426
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
1427
+ s7 += carry6;
1428
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1429
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
1430
+ s9 += carry8;
1431
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1432
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
1433
+ s11 += carry10;
1434
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1435
+ carry12 = (s12 + (int64_t) (1L << 20)) >> 21;
1436
+ s13 += carry12;
1437
+ s12 -= carry12 * ((uint64_t) 1L << 21);
1438
+ carry14 = (s14 + (int64_t) (1L << 20)) >> 21;
1439
+ s15 += carry14;
1440
+ s14 -= carry14 * ((uint64_t) 1L << 21);
1441
+ carry16 = (s16 + (int64_t) (1L << 20)) >> 21;
1442
+ s17 += carry16;
1443
+ s16 -= carry16 * ((uint64_t) 1L << 21);
1444
+
1445
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
1446
+ s8 += carry7;
1447
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1448
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
1449
+ s10 += carry9;
1450
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1451
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
1452
+ s12 += carry11;
1453
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1454
+ carry13 = (s13 + (int64_t) (1L << 20)) >> 21;
1455
+ s14 += carry13;
1456
+ s13 -= carry13 * ((uint64_t) 1L << 21);
1457
+ carry15 = (s15 + (int64_t) (1L << 20)) >> 21;
1458
+ s16 += carry15;
1459
+ s15 -= carry15 * ((uint64_t) 1L << 21);
1460
+
1461
+ s5 += s17 * 666643;
1462
+ s6 += s17 * 470296;
1463
+ s7 += s17 * 654183;
1464
+ s8 -= s17 * 997805;
1465
+ s9 += s17 * 136657;
1466
+ s10 -= s17 * 683901;
1467
+
1468
+ s4 += s16 * 666643;
1469
+ s5 += s16 * 470296;
1470
+ s6 += s16 * 654183;
1471
+ s7 -= s16 * 997805;
1472
+ s8 += s16 * 136657;
1473
+ s9 -= s16 * 683901;
1474
+
1475
+ s3 += s15 * 666643;
1476
+ s4 += s15 * 470296;
1477
+ s5 += s15 * 654183;
1478
+ s6 -= s15 * 997805;
1479
+ s7 += s15 * 136657;
1480
+ s8 -= s15 * 683901;
1481
+
1482
+ s2 += s14 * 666643;
1483
+ s3 += s14 * 470296;
1484
+ s4 += s14 * 654183;
1485
+ s5 -= s14 * 997805;
1486
+ s6 += s14 * 136657;
1487
+ s7 -= s14 * 683901;
1488
+
1489
+ s1 += s13 * 666643;
1490
+ s2 += s13 * 470296;
1491
+ s3 += s13 * 654183;
1492
+ s4 -= s13 * 997805;
1493
+ s5 += s13 * 136657;
1494
+ s6 -= s13 * 683901;
1495
+
1496
+ s0 += s12 * 666643;
1497
+ s1 += s12 * 470296;
1498
+ s2 += s12 * 654183;
1499
+ s3 -= s12 * 997805;
1500
+ s4 += s12 * 136657;
1501
+ s5 -= s12 * 683901;
1502
+ s12 = 0;
1503
+
1504
+ carry0 = (s0 + (int64_t) (1L << 20)) >> 21;
1505
+ s1 += carry0;
1506
+ s0 -= carry0 * ((uint64_t) 1L << 21);
1507
+ carry2 = (s2 + (int64_t) (1L << 20)) >> 21;
1508
+ s3 += carry2;
1509
+ s2 -= carry2 * ((uint64_t) 1L << 21);
1510
+ carry4 = (s4 + (int64_t) (1L << 20)) >> 21;
1511
+ s5 += carry4;
1512
+ s4 -= carry4 * ((uint64_t) 1L << 21);
1513
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
1514
+ s7 += carry6;
1515
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1516
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
1517
+ s9 += carry8;
1518
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1519
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
1520
+ s11 += carry10;
1521
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1522
+
1523
+ carry1 = (s1 + (int64_t) (1L << 20)) >> 21;
1524
+ s2 += carry1;
1525
+ s1 -= carry1 * ((uint64_t) 1L << 21);
1526
+ carry3 = (s3 + (int64_t) (1L << 20)) >> 21;
1527
+ s4 += carry3;
1528
+ s3 -= carry3 * ((uint64_t) 1L << 21);
1529
+ carry5 = (s5 + (int64_t) (1L << 20)) >> 21;
1530
+ s6 += carry5;
1531
+ s5 -= carry5 * ((uint64_t) 1L << 21);
1532
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
1533
+ s8 += carry7;
1534
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1535
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
1536
+ s10 += carry9;
1537
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1538
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
1539
+ s12 += carry11;
1540
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1541
+
1542
+ s0 += s12 * 666643;
1543
+ s1 += s12 * 470296;
1544
+ s2 += s12 * 654183;
1545
+ s3 -= s12 * 997805;
1546
+ s4 += s12 * 136657;
1547
+ s5 -= s12 * 683901;
1548
+ s12 = 0;
1549
+
1550
+ carry0 = s0 >> 21;
1551
+ s1 += carry0;
1552
+ s0 -= carry0 * ((uint64_t) 1L << 21);
1553
+ carry1 = s1 >> 21;
1554
+ s2 += carry1;
1555
+ s1 -= carry1 * ((uint64_t) 1L << 21);
1556
+ carry2 = s2 >> 21;
1557
+ s3 += carry2;
1558
+ s2 -= carry2 * ((uint64_t) 1L << 21);
1559
+ carry3 = s3 >> 21;
1560
+ s4 += carry3;
1561
+ s3 -= carry3 * ((uint64_t) 1L << 21);
1562
+ carry4 = s4 >> 21;
1563
+ s5 += carry4;
1564
+ s4 -= carry4 * ((uint64_t) 1L << 21);
1565
+ carry5 = s5 >> 21;
1566
+ s6 += carry5;
1567
+ s5 -= carry5 * ((uint64_t) 1L << 21);
1568
+ carry6 = s6 >> 21;
1569
+ s7 += carry6;
1570
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1571
+ carry7 = s7 >> 21;
1572
+ s8 += carry7;
1573
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1574
+ carry8 = s8 >> 21;
1575
+ s9 += carry8;
1576
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1577
+ carry9 = s9 >> 21;
1578
+ s10 += carry9;
1579
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1580
+ carry10 = s10 >> 21;
1581
+ s11 += carry10;
1582
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1583
+ carry11 = s11 >> 21;
1584
+ s12 += carry11;
1585
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1586
+
1587
+ s0 += s12 * 666643;
1588
+ s1 += s12 * 470296;
1589
+ s2 += s12 * 654183;
1590
+ s3 -= s12 * 997805;
1591
+ s4 += s12 * 136657;
1592
+ s5 -= s12 * 683901;
1593
+
1594
+ carry0 = s0 >> 21;
1595
+ s1 += carry0;
1596
+ s0 -= carry0 * ((uint64_t) 1L << 21);
1597
+ carry1 = s1 >> 21;
1598
+ s2 += carry1;
1599
+ s1 -= carry1 * ((uint64_t) 1L << 21);
1600
+ carry2 = s2 >> 21;
1601
+ s3 += carry2;
1602
+ s2 -= carry2 * ((uint64_t) 1L << 21);
1603
+ carry3 = s3 >> 21;
1604
+ s4 += carry3;
1605
+ s3 -= carry3 * ((uint64_t) 1L << 21);
1606
+ carry4 = s4 >> 21;
1607
+ s5 += carry4;
1608
+ s4 -= carry4 * ((uint64_t) 1L << 21);
1609
+ carry5 = s5 >> 21;
1610
+ s6 += carry5;
1611
+ s5 -= carry5 * ((uint64_t) 1L << 21);
1612
+ carry6 = s6 >> 21;
1613
+ s7 += carry6;
1614
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1615
+ carry7 = s7 >> 21;
1616
+ s8 += carry7;
1617
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1618
+ carry8 = s8 >> 21;
1619
+ s9 += carry8;
1620
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1621
+ carry9 = s9 >> 21;
1622
+ s10 += carry9;
1623
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1624
+ carry10 = s10 >> 21;
1625
+ s11 += carry10;
1626
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1627
+
1628
+ s[0] = s0 >> 0;
1629
+ s[1] = s0 >> 8;
1630
+ s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
1631
+ s[3] = s1 >> 3;
1632
+ s[4] = s1 >> 11;
1633
+ s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
1634
+ s[6] = s2 >> 6;
1635
+ s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
1636
+ s[8] = s3 >> 1;
1637
+ s[9] = s3 >> 9;
1638
+ s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
1639
+ s[11] = s4 >> 4;
1640
+ s[12] = s4 >> 12;
1641
+ s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));
1642
+ s[14] = s5 >> 7;
1643
+ s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));
1644
+ s[16] = s6 >> 2;
1645
+ s[17] = s6 >> 10;
1646
+ s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));
1647
+ s[19] = s7 >> 5;
1648
+ s[20] = s7 >> 13;
1649
+ s[21] = s8 >> 0;
1650
+ s[22] = s8 >> 8;
1651
+ s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));
1652
+ s[24] = s9 >> 3;
1653
+ s[25] = s9 >> 11;
1654
+ s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));
1655
+ s[27] = s10 >> 6;
1656
+ s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));
1657
+ s[29] = s11 >> 1;
1658
+ s[30] = s11 >> 9;
1659
+ s[31] = s11 >> 17;
1660
+ }
1661
+
1662
+ /*
1663
+ Input:
1664
+ a[0]+256*a[1]+...+256^31*a[31] = a
1665
+ b[0]+256*b[1]+...+256^31*b[31] = b
1666
+ c[0]+256*c[1]+...+256^31*c[31] = c
1667
+ *
1668
+ Output:
1669
+ s[0]+256*s[1]+...+256^31*s[31] = (ab+c) mod l
1670
+ where l = 2^252 + 27742317777372353535851937790883648493.
1671
+ */
1672
+
1673
+ void
1674
+ sc25519_muladd(unsigned char s[32], const unsigned char a[32],
1675
+ const unsigned char b[32], const unsigned char c[32])
1676
+ {
1677
+ int64_t a0 = 2097151 & load_3(a);
1678
+ int64_t a1 = 2097151 & (load_4(a + 2) >> 5);
1679
+ int64_t a2 = 2097151 & (load_3(a + 5) >> 2);
1680
+ int64_t a3 = 2097151 & (load_4(a + 7) >> 7);
1681
+ int64_t a4 = 2097151 & (load_4(a + 10) >> 4);
1682
+ int64_t a5 = 2097151 & (load_3(a + 13) >> 1);
1683
+ int64_t a6 = 2097151 & (load_4(a + 15) >> 6);
1684
+ int64_t a7 = 2097151 & (load_3(a + 18) >> 3);
1685
+ int64_t a8 = 2097151 & load_3(a + 21);
1686
+ int64_t a9 = 2097151 & (load_4(a + 23) >> 5);
1687
+ int64_t a10 = 2097151 & (load_3(a + 26) >> 2);
1688
+ int64_t a11 = (load_4(a + 28) >> 7);
1689
+
1690
+ int64_t b0 = 2097151 & load_3(b);
1691
+ int64_t b1 = 2097151 & (load_4(b + 2) >> 5);
1692
+ int64_t b2 = 2097151 & (load_3(b + 5) >> 2);
1693
+ int64_t b3 = 2097151 & (load_4(b + 7) >> 7);
1694
+ int64_t b4 = 2097151 & (load_4(b + 10) >> 4);
1695
+ int64_t b5 = 2097151 & (load_3(b + 13) >> 1);
1696
+ int64_t b6 = 2097151 & (load_4(b + 15) >> 6);
1697
+ int64_t b7 = 2097151 & (load_3(b + 18) >> 3);
1698
+ int64_t b8 = 2097151 & load_3(b + 21);
1699
+ int64_t b9 = 2097151 & (load_4(b + 23) >> 5);
1700
+ int64_t b10 = 2097151 & (load_3(b + 26) >> 2);
1701
+ int64_t b11 = (load_4(b + 28) >> 7);
1702
+
1703
+ int64_t c0 = 2097151 & load_3(c);
1704
+ int64_t c1 = 2097151 & (load_4(c + 2) >> 5);
1705
+ int64_t c2 = 2097151 & (load_3(c + 5) >> 2);
1706
+ int64_t c3 = 2097151 & (load_4(c + 7) >> 7);
1707
+ int64_t c4 = 2097151 & (load_4(c + 10) >> 4);
1708
+ int64_t c5 = 2097151 & (load_3(c + 13) >> 1);
1709
+ int64_t c6 = 2097151 & (load_4(c + 15) >> 6);
1710
+ int64_t c7 = 2097151 & (load_3(c + 18) >> 3);
1711
+ int64_t c8 = 2097151 & load_3(c + 21);
1712
+ int64_t c9 = 2097151 & (load_4(c + 23) >> 5);
1713
+ int64_t c10 = 2097151 & (load_3(c + 26) >> 2);
1714
+ int64_t c11 = (load_4(c + 28) >> 7);
1715
+
1716
+ int64_t s0;
1717
+ int64_t s1;
1718
+ int64_t s2;
1719
+ int64_t s3;
1720
+ int64_t s4;
1721
+ int64_t s5;
1722
+ int64_t s6;
1723
+ int64_t s7;
1724
+ int64_t s8;
1725
+ int64_t s9;
1726
+ int64_t s10;
1727
+ int64_t s11;
1728
+ int64_t s12;
1729
+ int64_t s13;
1730
+ int64_t s14;
1731
+ int64_t s15;
1732
+ int64_t s16;
1733
+ int64_t s17;
1734
+ int64_t s18;
1735
+ int64_t s19;
1736
+ int64_t s20;
1737
+ int64_t s21;
1738
+ int64_t s22;
1739
+ int64_t s23;
1740
+
1741
+ int64_t carry0;
1742
+ int64_t carry1;
1743
+ int64_t carry2;
1744
+ int64_t carry3;
1745
+ int64_t carry4;
1746
+ int64_t carry5;
1747
+ int64_t carry6;
1748
+ int64_t carry7;
1749
+ int64_t carry8;
1750
+ int64_t carry9;
1751
+ int64_t carry10;
1752
+ int64_t carry11;
1753
+ int64_t carry12;
1754
+ int64_t carry13;
1755
+ int64_t carry14;
1756
+ int64_t carry15;
1757
+ int64_t carry16;
1758
+ int64_t carry17;
1759
+ int64_t carry18;
1760
+ int64_t carry19;
1761
+ int64_t carry20;
1762
+ int64_t carry21;
1763
+ int64_t carry22;
1764
+
1765
+ s0 = c0 + a0 * b0;
1766
+ s1 = c1 + a0 * b1 + a1 * b0;
1767
+ s2 = c2 + a0 * b2 + a1 * b1 + a2 * b0;
1768
+ s3 = c3 + a0 * b3 + a1 * b2 + a2 * b1 + a3 * b0;
1769
+ s4 = c4 + a0 * b4 + a1 * b3 + a2 * b2 + a3 * b1 + a4 * b0;
1770
+ s5 = c5 + a0 * b5 + a1 * b4 + a2 * b3 + a3 * b2 + a4 * b1 + a5 * b0;
1771
+ s6 = c6 + a0 * b6 + a1 * b5 + a2 * b4 + a3 * b3 + a4 * b2 + a5 * b1 +
1772
+ a6 * b0;
1773
+ s7 = c7 + a0 * b7 + a1 * b6 + a2 * b5 + a3 * b4 + a4 * b3 + a5 * b2 +
1774
+ a6 * b1 + a7 * b0;
1775
+ s8 = c8 + a0 * b8 + a1 * b7 + a2 * b6 + a3 * b5 + a4 * b4 + a5 * b3 +
1776
+ a6 * b2 + a7 * b1 + a8 * b0;
1777
+ s9 = c9 + a0 * b9 + a1 * b8 + a2 * b7 + a3 * b6 + a4 * b5 + a5 * b4 +
1778
+ a6 * b3 + a7 * b2 + a8 * b1 + a9 * b0;
1779
+ s10 = c10 + a0 * b10 + a1 * b9 + a2 * b8 + a3 * b7 + a4 * b6 + a5 * b5 +
1780
+ a6 * b4 + a7 * b3 + a8 * b2 + a9 * b1 + a10 * b0;
1781
+ s11 = c11 + a0 * b11 + a1 * b10 + a2 * b9 + a3 * b8 + a4 * b7 + a5 * b6 +
1782
+ a6 * b5 + a7 * b4 + a8 * b3 + a9 * b2 + a10 * b1 + a11 * b0;
1783
+ s12 = a1 * b11 + a2 * b10 + a3 * b9 + a4 * b8 + a5 * b7 + a6 * b6 +
1784
+ a7 * b5 + a8 * b4 + a9 * b3 + a10 * b2 + a11 * b1;
1785
+ s13 = a2 * b11 + a3 * b10 + a4 * b9 + a5 * b8 + a6 * b7 + a7 * b6 +
1786
+ a8 * b5 + a9 * b4 + a10 * b3 + a11 * b2;
1787
+ s14 = a3 * b11 + a4 * b10 + a5 * b9 + a6 * b8 + a7 * b7 + a8 * b6 +
1788
+ a9 * b5 + a10 * b4 + a11 * b3;
1789
+ s15 = a4 * b11 + a5 * b10 + a6 * b9 + a7 * b8 + a8 * b7 + a9 * b6 +
1790
+ a10 * b5 + a11 * b4;
1791
+ s16 =
1792
+ a5 * b11 + a6 * b10 + a7 * b9 + a8 * b8 + a9 * b7 + a10 * b6 + a11 * b5;
1793
+ s17 = a6 * b11 + a7 * b10 + a8 * b9 + a9 * b8 + a10 * b7 + a11 * b6;
1794
+ s18 = a7 * b11 + a8 * b10 + a9 * b9 + a10 * b8 + a11 * b7;
1795
+ s19 = a8 * b11 + a9 * b10 + a10 * b9 + a11 * b8;
1796
+ s20 = a9 * b11 + a10 * b10 + a11 * b9;
1797
+ s21 = a10 * b11 + a11 * b10;
1798
+ s22 = a11 * b11;
1799
+ s23 = 0;
1800
+
1801
+ carry0 = (s0 + (int64_t) (1L << 20)) >> 21;
1802
+ s1 += carry0;
1803
+ s0 -= carry0 * ((uint64_t) 1L << 21);
1804
+ carry2 = (s2 + (int64_t) (1L << 20)) >> 21;
1805
+ s3 += carry2;
1806
+ s2 -= carry2 * ((uint64_t) 1L << 21);
1807
+ carry4 = (s4 + (int64_t) (1L << 20)) >> 21;
1808
+ s5 += carry4;
1809
+ s4 -= carry4 * ((uint64_t) 1L << 21);
1810
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
1811
+ s7 += carry6;
1812
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1813
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
1814
+ s9 += carry8;
1815
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1816
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
1817
+ s11 += carry10;
1818
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1819
+ carry12 = (s12 + (int64_t) (1L << 20)) >> 21;
1820
+ s13 += carry12;
1821
+ s12 -= carry12 * ((uint64_t) 1L << 21);
1822
+ carry14 = (s14 + (int64_t) (1L << 20)) >> 21;
1823
+ s15 += carry14;
1824
+ s14 -= carry14 * ((uint64_t) 1L << 21);
1825
+ carry16 = (s16 + (int64_t) (1L << 20)) >> 21;
1826
+ s17 += carry16;
1827
+ s16 -= carry16 * ((uint64_t) 1L << 21);
1828
+ carry18 = (s18 + (int64_t) (1L << 20)) >> 21;
1829
+ s19 += carry18;
1830
+ s18 -= carry18 * ((uint64_t) 1L << 21);
1831
+ carry20 = (s20 + (int64_t) (1L << 20)) >> 21;
1832
+ s21 += carry20;
1833
+ s20 -= carry20 * ((uint64_t) 1L << 21);
1834
+ carry22 = (s22 + (int64_t) (1L << 20)) >> 21;
1835
+ s23 += carry22;
1836
+ s22 -= carry22 * ((uint64_t) 1L << 21);
1837
+
1838
+ carry1 = (s1 + (int64_t) (1L << 20)) >> 21;
1839
+ s2 += carry1;
1840
+ s1 -= carry1 * ((uint64_t) 1L << 21);
1841
+ carry3 = (s3 + (int64_t) (1L << 20)) >> 21;
1842
+ s4 += carry3;
1843
+ s3 -= carry3 * ((uint64_t) 1L << 21);
1844
+ carry5 = (s5 + (int64_t) (1L << 20)) >> 21;
1845
+ s6 += carry5;
1846
+ s5 -= carry5 * ((uint64_t) 1L << 21);
1847
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
1848
+ s8 += carry7;
1849
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1850
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
1851
+ s10 += carry9;
1852
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1853
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
1854
+ s12 += carry11;
1855
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1856
+ carry13 = (s13 + (int64_t) (1L << 20)) >> 21;
1857
+ s14 += carry13;
1858
+ s13 -= carry13 * ((uint64_t) 1L << 21);
1859
+ carry15 = (s15 + (int64_t) (1L << 20)) >> 21;
1860
+ s16 += carry15;
1861
+ s15 -= carry15 * ((uint64_t) 1L << 21);
1862
+ carry17 = (s17 + (int64_t) (1L << 20)) >> 21;
1863
+ s18 += carry17;
1864
+ s17 -= carry17 * ((uint64_t) 1L << 21);
1865
+ carry19 = (s19 + (int64_t) (1L << 20)) >> 21;
1866
+ s20 += carry19;
1867
+ s19 -= carry19 * ((uint64_t) 1L << 21);
1868
+ carry21 = (s21 + (int64_t) (1L << 20)) >> 21;
1869
+ s22 += carry21;
1870
+ s21 -= carry21 * ((uint64_t) 1L << 21);
1871
+
1872
+ s11 += s23 * 666643;
1873
+ s12 += s23 * 470296;
1874
+ s13 += s23 * 654183;
1875
+ s14 -= s23 * 997805;
1876
+ s15 += s23 * 136657;
1877
+ s16 -= s23 * 683901;
1878
+
1879
+ s10 += s22 * 666643;
1880
+ s11 += s22 * 470296;
1881
+ s12 += s22 * 654183;
1882
+ s13 -= s22 * 997805;
1883
+ s14 += s22 * 136657;
1884
+ s15 -= s22 * 683901;
1885
+
1886
+ s9 += s21 * 666643;
1887
+ s10 += s21 * 470296;
1888
+ s11 += s21 * 654183;
1889
+ s12 -= s21 * 997805;
1890
+ s13 += s21 * 136657;
1891
+ s14 -= s21 * 683901;
1892
+
1893
+ s8 += s20 * 666643;
1894
+ s9 += s20 * 470296;
1895
+ s10 += s20 * 654183;
1896
+ s11 -= s20 * 997805;
1897
+ s12 += s20 * 136657;
1898
+ s13 -= s20 * 683901;
1899
+
1900
+ s7 += s19 * 666643;
1901
+ s8 += s19 * 470296;
1902
+ s9 += s19 * 654183;
1903
+ s10 -= s19 * 997805;
1904
+ s11 += s19 * 136657;
1905
+ s12 -= s19 * 683901;
1906
+
1907
+ s6 += s18 * 666643;
1908
+ s7 += s18 * 470296;
1909
+ s8 += s18 * 654183;
1910
+ s9 -= s18 * 997805;
1911
+ s10 += s18 * 136657;
1912
+ s11 -= s18 * 683901;
1913
+
1914
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
1915
+ s7 += carry6;
1916
+ s6 -= carry6 * ((uint64_t) 1L << 21);
1917
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
1918
+ s9 += carry8;
1919
+ s8 -= carry8 * ((uint64_t) 1L << 21);
1920
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
1921
+ s11 += carry10;
1922
+ s10 -= carry10 * ((uint64_t) 1L << 21);
1923
+ carry12 = (s12 + (int64_t) (1L << 20)) >> 21;
1924
+ s13 += carry12;
1925
+ s12 -= carry12 * ((uint64_t) 1L << 21);
1926
+ carry14 = (s14 + (int64_t) (1L << 20)) >> 21;
1927
+ s15 += carry14;
1928
+ s14 -= carry14 * ((uint64_t) 1L << 21);
1929
+ carry16 = (s16 + (int64_t) (1L << 20)) >> 21;
1930
+ s17 += carry16;
1931
+ s16 -= carry16 * ((uint64_t) 1L << 21);
1932
+
1933
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
1934
+ s8 += carry7;
1935
+ s7 -= carry7 * ((uint64_t) 1L << 21);
1936
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
1937
+ s10 += carry9;
1938
+ s9 -= carry9 * ((uint64_t) 1L << 21);
1939
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
1940
+ s12 += carry11;
1941
+ s11 -= carry11 * ((uint64_t) 1L << 21);
1942
+ carry13 = (s13 + (int64_t) (1L << 20)) >> 21;
1943
+ s14 += carry13;
1944
+ s13 -= carry13 * ((uint64_t) 1L << 21);
1945
+ carry15 = (s15 + (int64_t) (1L << 20)) >> 21;
1946
+ s16 += carry15;
1947
+ s15 -= carry15 * ((uint64_t) 1L << 21);
1948
+
1949
+ s5 += s17 * 666643;
1950
+ s6 += s17 * 470296;
1951
+ s7 += s17 * 654183;
1952
+ s8 -= s17 * 997805;
1953
+ s9 += s17 * 136657;
1954
+ s10 -= s17 * 683901;
1955
+
1956
+ s4 += s16 * 666643;
1957
+ s5 += s16 * 470296;
1958
+ s6 += s16 * 654183;
1959
+ s7 -= s16 * 997805;
1960
+ s8 += s16 * 136657;
1961
+ s9 -= s16 * 683901;
1962
+
1963
+ s3 += s15 * 666643;
1964
+ s4 += s15 * 470296;
1965
+ s5 += s15 * 654183;
1966
+ s6 -= s15 * 997805;
1967
+ s7 += s15 * 136657;
1968
+ s8 -= s15 * 683901;
1969
+
1970
+ s2 += s14 * 666643;
1971
+ s3 += s14 * 470296;
1972
+ s4 += s14 * 654183;
1973
+ s5 -= s14 * 997805;
1974
+ s6 += s14 * 136657;
1975
+ s7 -= s14 * 683901;
1976
+
1977
+ s1 += s13 * 666643;
1978
+ s2 += s13 * 470296;
1979
+ s3 += s13 * 654183;
1980
+ s4 -= s13 * 997805;
1981
+ s5 += s13 * 136657;
1982
+ s6 -= s13 * 683901;
1983
+
1984
+ s0 += s12 * 666643;
1985
+ s1 += s12 * 470296;
1986
+ s2 += s12 * 654183;
1987
+ s3 -= s12 * 997805;
1988
+ s4 += s12 * 136657;
1989
+ s5 -= s12 * 683901;
1990
+ s12 = 0;
1991
+
1992
+ carry0 = (s0 + (int64_t) (1L << 20)) >> 21;
1993
+ s1 += carry0;
1994
+ s0 -= carry0 * ((uint64_t) 1L << 21);
1995
+ carry2 = (s2 + (int64_t) (1L << 20)) >> 21;
1996
+ s3 += carry2;
1997
+ s2 -= carry2 * ((uint64_t) 1L << 21);
1998
+ carry4 = (s4 + (int64_t) (1L << 20)) >> 21;
1999
+ s5 += carry4;
2000
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2001
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
2002
+ s7 += carry6;
2003
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2004
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
2005
+ s9 += carry8;
2006
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2007
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
2008
+ s11 += carry10;
2009
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2010
+
2011
+ carry1 = (s1 + (int64_t) (1L << 20)) >> 21;
2012
+ s2 += carry1;
2013
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2014
+ carry3 = (s3 + (int64_t) (1L << 20)) >> 21;
2015
+ s4 += carry3;
2016
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2017
+ carry5 = (s5 + (int64_t) (1L << 20)) >> 21;
2018
+ s6 += carry5;
2019
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2020
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
2021
+ s8 += carry7;
2022
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2023
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
2024
+ s10 += carry9;
2025
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2026
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
2027
+ s12 += carry11;
2028
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2029
+
2030
+ s0 += s12 * 666643;
2031
+ s1 += s12 * 470296;
2032
+ s2 += s12 * 654183;
2033
+ s3 -= s12 * 997805;
2034
+ s4 += s12 * 136657;
2035
+ s5 -= s12 * 683901;
2036
+ s12 = 0;
2037
+
2038
+ carry0 = s0 >> 21;
2039
+ s1 += carry0;
2040
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2041
+ carry1 = s1 >> 21;
2042
+ s2 += carry1;
2043
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2044
+ carry2 = s2 >> 21;
2045
+ s3 += carry2;
2046
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2047
+ carry3 = s3 >> 21;
2048
+ s4 += carry3;
2049
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2050
+ carry4 = s4 >> 21;
2051
+ s5 += carry4;
2052
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2053
+ carry5 = s5 >> 21;
2054
+ s6 += carry5;
2055
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2056
+ carry6 = s6 >> 21;
2057
+ s7 += carry6;
2058
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2059
+ carry7 = s7 >> 21;
2060
+ s8 += carry7;
2061
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2062
+ carry8 = s8 >> 21;
2063
+ s9 += carry8;
2064
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2065
+ carry9 = s9 >> 21;
2066
+ s10 += carry9;
2067
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2068
+ carry10 = s10 >> 21;
2069
+ s11 += carry10;
2070
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2071
+ carry11 = s11 >> 21;
2072
+ s12 += carry11;
2073
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2074
+
2075
+ s0 += s12 * 666643;
2076
+ s1 += s12 * 470296;
2077
+ s2 += s12 * 654183;
2078
+ s3 -= s12 * 997805;
2079
+ s4 += s12 * 136657;
2080
+ s5 -= s12 * 683901;
2081
+
2082
+ carry0 = s0 >> 21;
2083
+ s1 += carry0;
2084
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2085
+ carry1 = s1 >> 21;
2086
+ s2 += carry1;
2087
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2088
+ carry2 = s2 >> 21;
2089
+ s3 += carry2;
2090
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2091
+ carry3 = s3 >> 21;
2092
+ s4 += carry3;
2093
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2094
+ carry4 = s4 >> 21;
2095
+ s5 += carry4;
2096
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2097
+ carry5 = s5 >> 21;
2098
+ s6 += carry5;
2099
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2100
+ carry6 = s6 >> 21;
2101
+ s7 += carry6;
2102
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2103
+ carry7 = s7 >> 21;
2104
+ s8 += carry7;
2105
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2106
+ carry8 = s8 >> 21;
2107
+ s9 += carry8;
2108
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2109
+ carry9 = s9 >> 21;
2110
+ s10 += carry9;
2111
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2112
+ carry10 = s10 >> 21;
2113
+ s11 += carry10;
2114
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2115
+
2116
+ s[0] = s0 >> 0;
2117
+ s[1] = s0 >> 8;
2118
+ s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
2119
+ s[3] = s1 >> 3;
2120
+ s[4] = s1 >> 11;
2121
+ s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
2122
+ s[6] = s2 >> 6;
2123
+ s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
2124
+ s[8] = s3 >> 1;
2125
+ s[9] = s3 >> 9;
2126
+ s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
2127
+ s[11] = s4 >> 4;
2128
+ s[12] = s4 >> 12;
2129
+ s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));
2130
+ s[14] = s5 >> 7;
2131
+ s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));
2132
+ s[16] = s6 >> 2;
2133
+ s[17] = s6 >> 10;
2134
+ s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));
2135
+ s[19] = s7 >> 5;
2136
+ s[20] = s7 >> 13;
2137
+ s[21] = s8 >> 0;
2138
+ s[22] = s8 >> 8;
2139
+ s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));
2140
+ s[24] = s9 >> 3;
2141
+ s[25] = s9 >> 11;
2142
+ s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));
2143
+ s[27] = s10 >> 6;
2144
+ s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));
2145
+ s[29] = s11 >> 1;
2146
+ s[30] = s11 >> 9;
2147
+ s[31] = s11 >> 17;
2148
+ }
2149
+
2150
+ /*
2151
+ Input:
2152
+ a[0]+256*a[1]+...+256^31*a[31] = a
2153
+ *
2154
+ Output:
2155
+ s[0]+256*s[1]+...+256^31*s[31] = a^2 mod l
2156
+ where l = 2^252 + 27742317777372353535851937790883648493.
2157
+ */
2158
+
2159
+ static void
2160
+ sc25519_sq(unsigned char *s, const unsigned char *a)
2161
+ {
2162
+ sc25519_mul(s, a, a);
2163
+ }
2164
+
2165
+ /*
2166
+ Input:
2167
+ s[0]+256*a[1]+...+256^31*a[31] = a
2168
+ n
2169
+ *
2170
+ Output:
2171
+ s[0]+256*s[1]+...+256^31*s[31] = x * s^(s^n) mod l
2172
+ where l = 2^252 + 27742317777372353535851937790883648493.
2173
+ Overwrites s in place.
2174
+ */
2175
+
2176
+ static void
2177
+ sc25519_sqmul(unsigned char s[32], const int n, const unsigned char a[32])
2178
+ {
2179
+ int i;
2180
+
2181
+ for (i = 0; i < n; i++) {
2182
+ sc25519_sq(s, s);
2183
+ }
2184
+ sc25519_mul(s, s, a);
2185
+ }
2186
+
2187
+ void
2188
+ sc25519_invert(unsigned char recip[32], const unsigned char s[32])
2189
+ {
2190
+ unsigned char _10[32], _100[32], _1000[32], _10000[32], _100000[32],
2191
+ _1000000[32], _10010011[32], _10010111[32], _100110[32], _1010[32],
2192
+ _1010000[32], _1010011[32], _1011[32], _10110[32], _10111101[32],
2193
+ _11[32], _1100011[32], _1100111[32], _11010011[32], _1101011[32],
2194
+ _11100111[32], _11101011[32], _11110101[32];
2195
+
2196
+ sc25519_sq(_10, s);
2197
+ sc25519_mul(_11, s, _10);
2198
+ sc25519_mul(_100, s, _11);
2199
+ sc25519_sq(_1000, _100);
2200
+ sc25519_mul(_1010, _10, _1000);
2201
+ sc25519_mul(_1011, s, _1010);
2202
+ sc25519_sq(_10000, _1000);
2203
+ sc25519_sq(_10110, _1011);
2204
+ sc25519_mul(_100000, _1010, _10110);
2205
+ sc25519_mul(_100110, _10000, _10110);
2206
+ sc25519_sq(_1000000, _100000);
2207
+ sc25519_mul(_1010000, _10000, _1000000);
2208
+ sc25519_mul(_1010011, _11, _1010000);
2209
+ sc25519_mul(_1100011, _10000, _1010011);
2210
+ sc25519_mul(_1100111, _100, _1100011);
2211
+ sc25519_mul(_1101011, _100, _1100111);
2212
+ sc25519_mul(_10010011, _1000000, _1010011);
2213
+ sc25519_mul(_10010111, _100, _10010011);
2214
+ sc25519_mul(_10111101, _100110, _10010111);
2215
+ sc25519_mul(_11010011, _10110, _10111101);
2216
+ sc25519_mul(_11100111, _1010000, _10010111);
2217
+ sc25519_mul(_11101011, _100, _11100111);
2218
+ sc25519_mul(_11110101, _1010, _11101011);
2219
+
2220
+ sc25519_mul(recip, _1011, _11110101);
2221
+ sc25519_sqmul(recip, 126, _1010011);
2222
+ sc25519_sqmul(recip, 9, _10);
2223
+ sc25519_mul(recip, recip, _11110101);
2224
+ sc25519_sqmul(recip, 7, _1100111);
2225
+ sc25519_sqmul(recip, 9, _11110101);
2226
+ sc25519_sqmul(recip, 11, _10111101);
2227
+ sc25519_sqmul(recip, 8, _11100111);
2228
+ sc25519_sqmul(recip, 9, _1101011);
2229
+ sc25519_sqmul(recip, 6, _1011);
2230
+ sc25519_sqmul(recip, 14, _10010011);
2231
+ sc25519_sqmul(recip, 10, _1100011);
2232
+ sc25519_sqmul(recip, 9, _10010111);
2233
+ sc25519_sqmul(recip, 10, _11110101);
2234
+ sc25519_sqmul(recip, 8, _11010011);
2235
+ sc25519_sqmul(recip, 8, _11101011);
2236
+ }
2237
+
2238
+ /*
2239
+ Input:
2240
+ s[0]+256*s[1]+...+256^63*s[63] = s
2241
+ *
2242
+ Output:
2243
+ s[0]+256*s[1]+...+256^31*s[31] = s mod l
2244
+ where l = 2^252 + 27742317777372353535851937790883648493.
2245
+ Overwrites s in place.
2246
+ */
2247
+
2248
+ void
2249
+ sc25519_reduce(unsigned char s[64])
2250
+ {
2251
+ int64_t s0 = 2097151 & load_3(s);
2252
+ int64_t s1 = 2097151 & (load_4(s + 2) >> 5);
2253
+ int64_t s2 = 2097151 & (load_3(s + 5) >> 2);
2254
+ int64_t s3 = 2097151 & (load_4(s + 7) >> 7);
2255
+ int64_t s4 = 2097151 & (load_4(s + 10) >> 4);
2256
+ int64_t s5 = 2097151 & (load_3(s + 13) >> 1);
2257
+ int64_t s6 = 2097151 & (load_4(s + 15) >> 6);
2258
+ int64_t s7 = 2097151 & (load_3(s + 18) >> 3);
2259
+ int64_t s8 = 2097151 & load_3(s + 21);
2260
+ int64_t s9 = 2097151 & (load_4(s + 23) >> 5);
2261
+ int64_t s10 = 2097151 & (load_3(s + 26) >> 2);
2262
+ int64_t s11 = 2097151 & (load_4(s + 28) >> 7);
2263
+ int64_t s12 = 2097151 & (load_4(s + 31) >> 4);
2264
+ int64_t s13 = 2097151 & (load_3(s + 34) >> 1);
2265
+ int64_t s14 = 2097151 & (load_4(s + 36) >> 6);
2266
+ int64_t s15 = 2097151 & (load_3(s + 39) >> 3);
2267
+ int64_t s16 = 2097151 & load_3(s + 42);
2268
+ int64_t s17 = 2097151 & (load_4(s + 44) >> 5);
2269
+ int64_t s18 = 2097151 & (load_3(s + 47) >> 2);
2270
+ int64_t s19 = 2097151 & (load_4(s + 49) >> 7);
2271
+ int64_t s20 = 2097151 & (load_4(s + 52) >> 4);
2272
+ int64_t s21 = 2097151 & (load_3(s + 55) >> 1);
2273
+ int64_t s22 = 2097151 & (load_4(s + 57) >> 6);
2274
+ int64_t s23 = (load_4(s + 60) >> 3);
2275
+
2276
+ int64_t carry0;
2277
+ int64_t carry1;
2278
+ int64_t carry2;
2279
+ int64_t carry3;
2280
+ int64_t carry4;
2281
+ int64_t carry5;
2282
+ int64_t carry6;
2283
+ int64_t carry7;
2284
+ int64_t carry8;
2285
+ int64_t carry9;
2286
+ int64_t carry10;
2287
+ int64_t carry11;
2288
+ int64_t carry12;
2289
+ int64_t carry13;
2290
+ int64_t carry14;
2291
+ int64_t carry15;
2292
+ int64_t carry16;
2293
+
2294
+ s11 += s23 * 666643;
2295
+ s12 += s23 * 470296;
2296
+ s13 += s23 * 654183;
2297
+ s14 -= s23 * 997805;
2298
+ s15 += s23 * 136657;
2299
+ s16 -= s23 * 683901;
2300
+
2301
+ s10 += s22 * 666643;
2302
+ s11 += s22 * 470296;
2303
+ s12 += s22 * 654183;
2304
+ s13 -= s22 * 997805;
2305
+ s14 += s22 * 136657;
2306
+ s15 -= s22 * 683901;
2307
+
2308
+ s9 += s21 * 666643;
2309
+ s10 += s21 * 470296;
2310
+ s11 += s21 * 654183;
2311
+ s12 -= s21 * 997805;
2312
+ s13 += s21 * 136657;
2313
+ s14 -= s21 * 683901;
2314
+
2315
+ s8 += s20 * 666643;
2316
+ s9 += s20 * 470296;
2317
+ s10 += s20 * 654183;
2318
+ s11 -= s20 * 997805;
2319
+ s12 += s20 * 136657;
2320
+ s13 -= s20 * 683901;
2321
+
2322
+ s7 += s19 * 666643;
2323
+ s8 += s19 * 470296;
2324
+ s9 += s19 * 654183;
2325
+ s10 -= s19 * 997805;
2326
+ s11 += s19 * 136657;
2327
+ s12 -= s19 * 683901;
2328
+
2329
+ s6 += s18 * 666643;
2330
+ s7 += s18 * 470296;
2331
+ s8 += s18 * 654183;
2332
+ s9 -= s18 * 997805;
2333
+ s10 += s18 * 136657;
2334
+ s11 -= s18 * 683901;
2335
+
2336
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
2337
+ s7 += carry6;
2338
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2339
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
2340
+ s9 += carry8;
2341
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2342
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
2343
+ s11 += carry10;
2344
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2345
+ carry12 = (s12 + (int64_t) (1L << 20)) >> 21;
2346
+ s13 += carry12;
2347
+ s12 -= carry12 * ((uint64_t) 1L << 21);
2348
+ carry14 = (s14 + (int64_t) (1L << 20)) >> 21;
2349
+ s15 += carry14;
2350
+ s14 -= carry14 * ((uint64_t) 1L << 21);
2351
+ carry16 = (s16 + (int64_t) (1L << 20)) >> 21;
2352
+ s17 += carry16;
2353
+ s16 -= carry16 * ((uint64_t) 1L << 21);
2354
+
2355
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
2356
+ s8 += carry7;
2357
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2358
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
2359
+ s10 += carry9;
2360
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2361
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
2362
+ s12 += carry11;
2363
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2364
+ carry13 = (s13 + (int64_t) (1L << 20)) >> 21;
2365
+ s14 += carry13;
2366
+ s13 -= carry13 * ((uint64_t) 1L << 21);
2367
+ carry15 = (s15 + (int64_t) (1L << 20)) >> 21;
2368
+ s16 += carry15;
2369
+ s15 -= carry15 * ((uint64_t) 1L << 21);
2370
+
2371
+ s5 += s17 * 666643;
2372
+ s6 += s17 * 470296;
2373
+ s7 += s17 * 654183;
2374
+ s8 -= s17 * 997805;
2375
+ s9 += s17 * 136657;
2376
+ s10 -= s17 * 683901;
2377
+
2378
+ s4 += s16 * 666643;
2379
+ s5 += s16 * 470296;
2380
+ s6 += s16 * 654183;
2381
+ s7 -= s16 * 997805;
2382
+ s8 += s16 * 136657;
2383
+ s9 -= s16 * 683901;
2384
+
2385
+ s3 += s15 * 666643;
2386
+ s4 += s15 * 470296;
2387
+ s5 += s15 * 654183;
2388
+ s6 -= s15 * 997805;
2389
+ s7 += s15 * 136657;
2390
+ s8 -= s15 * 683901;
2391
+
2392
+ s2 += s14 * 666643;
2393
+ s3 += s14 * 470296;
2394
+ s4 += s14 * 654183;
2395
+ s5 -= s14 * 997805;
2396
+ s6 += s14 * 136657;
2397
+ s7 -= s14 * 683901;
2398
+
2399
+ s1 += s13 * 666643;
2400
+ s2 += s13 * 470296;
2401
+ s3 += s13 * 654183;
2402
+ s4 -= s13 * 997805;
2403
+ s5 += s13 * 136657;
2404
+ s6 -= s13 * 683901;
2405
+
2406
+ s0 += s12 * 666643;
2407
+ s1 += s12 * 470296;
2408
+ s2 += s12 * 654183;
2409
+ s3 -= s12 * 997805;
2410
+ s4 += s12 * 136657;
2411
+ s5 -= s12 * 683901;
2412
+ s12 = 0;
2413
+
2414
+ carry0 = (s0 + (int64_t) (1L << 20)) >> 21;
2415
+ s1 += carry0;
2416
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2417
+ carry2 = (s2 + (int64_t) (1L << 20)) >> 21;
2418
+ s3 += carry2;
2419
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2420
+ carry4 = (s4 + (int64_t) (1L << 20)) >> 21;
2421
+ s5 += carry4;
2422
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2423
+ carry6 = (s6 + (int64_t) (1L << 20)) >> 21;
2424
+ s7 += carry6;
2425
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2426
+ carry8 = (s8 + (int64_t) (1L << 20)) >> 21;
2427
+ s9 += carry8;
2428
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2429
+ carry10 = (s10 + (int64_t) (1L << 20)) >> 21;
2430
+ s11 += carry10;
2431
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2432
+
2433
+ carry1 = (s1 + (int64_t) (1L << 20)) >> 21;
2434
+ s2 += carry1;
2435
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2436
+ carry3 = (s3 + (int64_t) (1L << 20)) >> 21;
2437
+ s4 += carry3;
2438
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2439
+ carry5 = (s5 + (int64_t) (1L << 20)) >> 21;
2440
+ s6 += carry5;
2441
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2442
+ carry7 = (s7 + (int64_t) (1L << 20)) >> 21;
2443
+ s8 += carry7;
2444
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2445
+ carry9 = (s9 + (int64_t) (1L << 20)) >> 21;
2446
+ s10 += carry9;
2447
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2448
+ carry11 = (s11 + (int64_t) (1L << 20)) >> 21;
2449
+ s12 += carry11;
2450
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2451
+
2452
+ s0 += s12 * 666643;
2453
+ s1 += s12 * 470296;
2454
+ s2 += s12 * 654183;
2455
+ s3 -= s12 * 997805;
2456
+ s4 += s12 * 136657;
2457
+ s5 -= s12 * 683901;
2458
+ s12 = 0;
2459
+
2460
+ carry0 = s0 >> 21;
2461
+ s1 += carry0;
2462
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2463
+ carry1 = s1 >> 21;
2464
+ s2 += carry1;
2465
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2466
+ carry2 = s2 >> 21;
2467
+ s3 += carry2;
2468
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2469
+ carry3 = s3 >> 21;
2470
+ s4 += carry3;
2471
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2472
+ carry4 = s4 >> 21;
2473
+ s5 += carry4;
2474
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2475
+ carry5 = s5 >> 21;
2476
+ s6 += carry5;
2477
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2478
+ carry6 = s6 >> 21;
2479
+ s7 += carry6;
2480
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2481
+ carry7 = s7 >> 21;
2482
+ s8 += carry7;
2483
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2484
+ carry8 = s8 >> 21;
2485
+ s9 += carry8;
2486
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2487
+ carry9 = s9 >> 21;
2488
+ s10 += carry9;
2489
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2490
+ carry10 = s10 >> 21;
2491
+ s11 += carry10;
2492
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2493
+ carry11 = s11 >> 21;
2494
+ s12 += carry11;
2495
+ s11 -= carry11 * ((uint64_t) 1L << 21);
2496
+
2497
+ s0 += s12 * 666643;
2498
+ s1 += s12 * 470296;
2499
+ s2 += s12 * 654183;
2500
+ s3 -= s12 * 997805;
2501
+ s4 += s12 * 136657;
2502
+ s5 -= s12 * 683901;
2503
+
2504
+ carry0 = s0 >> 21;
2505
+ s1 += carry0;
2506
+ s0 -= carry0 * ((uint64_t) 1L << 21);
2507
+ carry1 = s1 >> 21;
2508
+ s2 += carry1;
2509
+ s1 -= carry1 * ((uint64_t) 1L << 21);
2510
+ carry2 = s2 >> 21;
2511
+ s3 += carry2;
2512
+ s2 -= carry2 * ((uint64_t) 1L << 21);
2513
+ carry3 = s3 >> 21;
2514
+ s4 += carry3;
2515
+ s3 -= carry3 * ((uint64_t) 1L << 21);
2516
+ carry4 = s4 >> 21;
2517
+ s5 += carry4;
2518
+ s4 -= carry4 * ((uint64_t) 1L << 21);
2519
+ carry5 = s5 >> 21;
2520
+ s6 += carry5;
2521
+ s5 -= carry5 * ((uint64_t) 1L << 21);
2522
+ carry6 = s6 >> 21;
2523
+ s7 += carry6;
2524
+ s6 -= carry6 * ((uint64_t) 1L << 21);
2525
+ carry7 = s7 >> 21;
2526
+ s8 += carry7;
2527
+ s7 -= carry7 * ((uint64_t) 1L << 21);
2528
+ carry8 = s8 >> 21;
2529
+ s9 += carry8;
2530
+ s8 -= carry8 * ((uint64_t) 1L << 21);
2531
+ carry9 = s9 >> 21;
2532
+ s10 += carry9;
2533
+ s9 -= carry9 * ((uint64_t) 1L << 21);
2534
+ carry10 = s10 >> 21;
2535
+ s11 += carry10;
2536
+ s10 -= carry10 * ((uint64_t) 1L << 21);
2537
+
2538
+ s[0] = s0 >> 0;
2539
+ s[1] = s0 >> 8;
2540
+ s[2] = (s0 >> 16) | (s1 * ((uint64_t) 1 << 5));
2541
+ s[3] = s1 >> 3;
2542
+ s[4] = s1 >> 11;
2543
+ s[5] = (s1 >> 19) | (s2 * ((uint64_t) 1 << 2));
2544
+ s[6] = s2 >> 6;
2545
+ s[7] = (s2 >> 14) | (s3 * ((uint64_t) 1 << 7));
2546
+ s[8] = s3 >> 1;
2547
+ s[9] = s3 >> 9;
2548
+ s[10] = (s3 >> 17) | (s4 * ((uint64_t) 1 << 4));
2549
+ s[11] = s4 >> 4;
2550
+ s[12] = s4 >> 12;
2551
+ s[13] = (s4 >> 20) | (s5 * ((uint64_t) 1 << 1));
2552
+ s[14] = s5 >> 7;
2553
+ s[15] = (s5 >> 15) | (s6 * ((uint64_t) 1 << 6));
2554
+ s[16] = s6 >> 2;
2555
+ s[17] = s6 >> 10;
2556
+ s[18] = (s6 >> 18) | (s7 * ((uint64_t) 1 << 3));
2557
+ s[19] = s7 >> 5;
2558
+ s[20] = s7 >> 13;
2559
+ s[21] = s8 >> 0;
2560
+ s[22] = s8 >> 8;
2561
+ s[23] = (s8 >> 16) | (s9 * ((uint64_t) 1 << 5));
2562
+ s[24] = s9 >> 3;
2563
+ s[25] = s9 >> 11;
2564
+ s[26] = (s9 >> 19) | (s10 * ((uint64_t) 1 << 2));
2565
+ s[27] = s10 >> 6;
2566
+ s[28] = (s10 >> 14) | (s11 * ((uint64_t) 1 << 7));
2567
+ s[29] = s11 >> 1;
2568
+ s[30] = s11 >> 9;
2569
+ s[31] = s11 >> 17;
2570
+ }
2571
+
2572
+ int
2573
+ sc25519_is_canonical(const unsigned char s[32])
2574
+ {
2575
+ /* 2^252+27742317777372353535851937790883648493 */
2576
+ static const unsigned char L[32] = {
2577
+ 0xed, 0xd3, 0xf5, 0x5c, 0x1a, 0x63, 0x12, 0x58, 0xd6, 0x9c, 0xf7,
2578
+ 0xa2, 0xde, 0xf9, 0xde, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2579
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10
2580
+ };
2581
+ unsigned char c = 0;
2582
+ unsigned char n = 1;
2583
+ unsigned int i = 32;
2584
+
2585
+ do {
2586
+ i--;
2587
+ c |= ((s[i] - L[i]) >> 8) & n;
2588
+ n &= ((s[i] ^ L[i]) - 1) >> 8;
2589
+ } while (i != 0);
2590
+
2591
+ return (c != 0);
2592
+ }
2593
+
2594
+ static void
2595
+ ge25519_elligator2(unsigned char s[32], const fe25519 r, const unsigned char x_sign)
2596
+ {
2597
+ fe25519 gx;
2598
+ fe25519 negx;
2599
+ fe25519 rr2;
2600
+ fe25519 x, x2, x3;
2601
+ ge25519_p3 p3;
2602
+ ge25519_p1p1 p1;
2603
+ ge25519_p2 p2;
2604
+ unsigned int notsquare;
2605
+
2606
+ fe25519_sq2(rr2, r);
2607
+ rr2[0]++;
2608
+ fe25519_invert(rr2, rr2);
2609
+ fe25519_mul32(x, rr2, curve25519_A[0]);
2610
+ fe25519_neg(x, x);
2611
+
2612
+ fe25519_sq(x2, x);
2613
+ fe25519_mul(x3, x, x2);
2614
+ fe25519_add(gx, x3, x);
2615
+ fe25519_mul32(x2, x2, curve25519_A[0]);
2616
+ fe25519_add(gx, x2, gx);
2617
+
2618
+ notsquare = fe25519_notsquare(gx);
2619
+ fe25519_neg(negx, x);
2620
+ fe25519_cmov(x, negx, notsquare);
2621
+ fe25519_0(x2);
2622
+ fe25519_cmov(x2, curve25519_A, notsquare);
2623
+ fe25519_sub(x, x, x2);
2624
+
2625
+ /* yed = (x-1)/(x+1) */
2626
+ {
2627
+ fe25519 one;
2628
+ fe25519 x_plus_one;
2629
+ fe25519 x_plus_one_inv;
2630
+ fe25519 x_minus_one;
2631
+ fe25519 yed;
2632
+
2633
+ fe25519_1(one);
2634
+ fe25519_add(x_plus_one, x, one);
2635
+ fe25519_sub(x_minus_one, x, one);
2636
+ fe25519_invert(x_plus_one_inv, x_plus_one);
2637
+ fe25519_mul(yed, x_minus_one, x_plus_one_inv);
2638
+ fe25519_tobytes(s, yed);
2639
+ }
2640
+
2641
+ /* recover x */
2642
+ s[31] |= x_sign;
2643
+ if (ge25519_frombytes(&p3, s) != 0) {
2644
+ abort(); /* LCOV_EXCL_LINE */
2645
+ }
2646
+
2647
+ /* multiply by the cofactor */
2648
+ ge25519_p3_dbl(&p1, &p3);
2649
+ ge25519_p1p1_to_p2(&p2, &p1);
2650
+ ge25519_p2_dbl(&p1, &p2);
2651
+ ge25519_p1p1_to_p2(&p2, &p1);
2652
+ ge25519_p2_dbl(&p1, &p2);
2653
+ ge25519_p1p1_to_p3(&p3, &p1);
2654
+
2655
+ ge25519_p3_tobytes(s, &p3);
2656
+ }
2657
+
2658
+ void
2659
+ ge25519_from_uniform(unsigned char s[32], const unsigned char r[32])
2660
+ {
2661
+ fe25519 r_fe;
2662
+ unsigned char x_sign;
2663
+
2664
+ memcpy(s, r, 32);
2665
+ x_sign = s[31] & 0x80;
2666
+ s[31] &= 0x7f;
2667
+ fe25519_frombytes(r_fe, s);
2668
+ ge25519_elligator2(s, r_fe, x_sign);
2669
+ }
2670
+
2671
+ void
2672
+ ge25519_from_hash(unsigned char s[32], const unsigned char h[64])
2673
+ {
2674
+ unsigned char fl[32];
2675
+ unsigned char gl[32];
2676
+ fe25519 fe_f;
2677
+ fe25519 fe_g;
2678
+ size_t i;
2679
+ unsigned char x_sign;
2680
+
2681
+ x_sign = h[0] & 0x80;
2682
+ for (i = 0; i < 32; i++) {
2683
+ fl[i] = h[63 - i];
2684
+ gl[i] = h[31 - i];
2685
+ }
2686
+ fl[31] &= 0x7f;
2687
+ gl[31] &= 0x7f;
2688
+ fe25519_frombytes(fe_f, fl);
2689
+ fe25519_frombytes(fe_g, gl);
2690
+ fe_f[0] += (h[32] >> 7) * 19;
2691
+ for (i = 0; i < sizeof (fe25519) / sizeof fe_f[0]; i++) {
2692
+ fe_f[i] += 38 * fe_g[i];
2693
+ }
2694
+ fe25519_reduce(fe_f, fe_f);
2695
+ ge25519_elligator2(s, fe_f, x_sign);
2696
+ }
2697
+
2698
+ #endif