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,2236 @@
1
+ /*
2
+ * FIPS-197 compliant AES implementation
3
+ *
4
+ * Copyright The Mbed TLS Contributors
5
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
6
+ */
7
+ /*
8
+ * The AES block cipher was designed by Vincent Rijmen and Joan Daemen.
9
+ *
10
+ * https://csrc.nist.gov/csrc/media/projects/cryptographic-standards-and-guidelines/documents/aes-development/rijndael-ammended.pdf
11
+ * http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf
12
+ */
13
+
14
+ #include "tf_psa_crypto_common.h"
15
+
16
+ #if defined(MBEDTLS_AES_C)
17
+
18
+ #include <string.h>
19
+
20
+ #include "mbedtls/private/aes.h"
21
+ #include "mbedtls/platform.h"
22
+ #include "mbedtls/platform_util.h"
23
+ #include "mbedtls/private/error_common.h"
24
+
25
+ #if defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
26
+ #if !((defined(MBEDTLS_ARCH_IS_ARMV8_A) && defined(MBEDTLS_AESCE_C)) || \
27
+ (defined(MBEDTLS_ARCH_IS_X64) && defined(MBEDTLS_AESNI_C)) || \
28
+ (defined(MBEDTLS_ARCH_IS_X86) && defined(MBEDTLS_AESNI_C)))
29
+ #error "MBEDTLS_AES_USE_HARDWARE_ONLY defined, but not all prerequisites"
30
+ #endif
31
+ #endif
32
+
33
+ #if defined(MBEDTLS_AESNI_C)
34
+ #include "aesni.h"
35
+ #endif
36
+ #if defined(MBEDTLS_AESCE_C)
37
+ #include "aesce.h"
38
+ #endif
39
+
40
+ #include "mbedtls/platform.h"
41
+ #include "ctr.h"
42
+
43
+ /*
44
+ * This is a convenience shorthand macro to check if we need reverse S-box and
45
+ * reverse tables. It's private and only defined in this file.
46
+ */
47
+ #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
48
+ #define MBEDTLS_AES_NEED_REVERSE_TABLES
49
+ #endif
50
+
51
+ #if defined(MBEDTLS_AES_ROM_TABLES)
52
+ /*
53
+ * Forward S-box
54
+ */
55
+ MBEDTLS_MAYBE_UNUSED static const unsigned char FSb[256] =
56
+ {
57
+ 0x63, 0x7C, 0x77, 0x7B, 0xF2, 0x6B, 0x6F, 0xC5,
58
+ 0x30, 0x01, 0x67, 0x2B, 0xFE, 0xD7, 0xAB, 0x76,
59
+ 0xCA, 0x82, 0xC9, 0x7D, 0xFA, 0x59, 0x47, 0xF0,
60
+ 0xAD, 0xD4, 0xA2, 0xAF, 0x9C, 0xA4, 0x72, 0xC0,
61
+ 0xB7, 0xFD, 0x93, 0x26, 0x36, 0x3F, 0xF7, 0xCC,
62
+ 0x34, 0xA5, 0xE5, 0xF1, 0x71, 0xD8, 0x31, 0x15,
63
+ 0x04, 0xC7, 0x23, 0xC3, 0x18, 0x96, 0x05, 0x9A,
64
+ 0x07, 0x12, 0x80, 0xE2, 0xEB, 0x27, 0xB2, 0x75,
65
+ 0x09, 0x83, 0x2C, 0x1A, 0x1B, 0x6E, 0x5A, 0xA0,
66
+ 0x52, 0x3B, 0xD6, 0xB3, 0x29, 0xE3, 0x2F, 0x84,
67
+ 0x53, 0xD1, 0x00, 0xED, 0x20, 0xFC, 0xB1, 0x5B,
68
+ 0x6A, 0xCB, 0xBE, 0x39, 0x4A, 0x4C, 0x58, 0xCF,
69
+ 0xD0, 0xEF, 0xAA, 0xFB, 0x43, 0x4D, 0x33, 0x85,
70
+ 0x45, 0xF9, 0x02, 0x7F, 0x50, 0x3C, 0x9F, 0xA8,
71
+ 0x51, 0xA3, 0x40, 0x8F, 0x92, 0x9D, 0x38, 0xF5,
72
+ 0xBC, 0xB6, 0xDA, 0x21, 0x10, 0xFF, 0xF3, 0xD2,
73
+ 0xCD, 0x0C, 0x13, 0xEC, 0x5F, 0x97, 0x44, 0x17,
74
+ 0xC4, 0xA7, 0x7E, 0x3D, 0x64, 0x5D, 0x19, 0x73,
75
+ 0x60, 0x81, 0x4F, 0xDC, 0x22, 0x2A, 0x90, 0x88,
76
+ 0x46, 0xEE, 0xB8, 0x14, 0xDE, 0x5E, 0x0B, 0xDB,
77
+ 0xE0, 0x32, 0x3A, 0x0A, 0x49, 0x06, 0x24, 0x5C,
78
+ 0xC2, 0xD3, 0xAC, 0x62, 0x91, 0x95, 0xE4, 0x79,
79
+ 0xE7, 0xC8, 0x37, 0x6D, 0x8D, 0xD5, 0x4E, 0xA9,
80
+ 0x6C, 0x56, 0xF4, 0xEA, 0x65, 0x7A, 0xAE, 0x08,
81
+ 0xBA, 0x78, 0x25, 0x2E, 0x1C, 0xA6, 0xB4, 0xC6,
82
+ 0xE8, 0xDD, 0x74, 0x1F, 0x4B, 0xBD, 0x8B, 0x8A,
83
+ 0x70, 0x3E, 0xB5, 0x66, 0x48, 0x03, 0xF6, 0x0E,
84
+ 0x61, 0x35, 0x57, 0xB9, 0x86, 0xC1, 0x1D, 0x9E,
85
+ 0xE1, 0xF8, 0x98, 0x11, 0x69, 0xD9, 0x8E, 0x94,
86
+ 0x9B, 0x1E, 0x87, 0xE9, 0xCE, 0x55, 0x28, 0xDF,
87
+ 0x8C, 0xA1, 0x89, 0x0D, 0xBF, 0xE6, 0x42, 0x68,
88
+ 0x41, 0x99, 0x2D, 0x0F, 0xB0, 0x54, 0xBB, 0x16
89
+ };
90
+
91
+ /*
92
+ * Forward tables
93
+ */
94
+ #define FT \
95
+ \
96
+ V(A5, 63, 63, C6), V(84, 7C, 7C, F8), V(99, 77, 77, EE), V(8D, 7B, 7B, F6), \
97
+ V(0D, F2, F2, FF), V(BD, 6B, 6B, D6), V(B1, 6F, 6F, DE), V(54, C5, C5, 91), \
98
+ V(50, 30, 30, 60), V(03, 01, 01, 02), V(A9, 67, 67, CE), V(7D, 2B, 2B, 56), \
99
+ V(19, FE, FE, E7), V(62, D7, D7, B5), V(E6, AB, AB, 4D), V(9A, 76, 76, EC), \
100
+ V(45, CA, CA, 8F), V(9D, 82, 82, 1F), V(40, C9, C9, 89), V(87, 7D, 7D, FA), \
101
+ V(15, FA, FA, EF), V(EB, 59, 59, B2), V(C9, 47, 47, 8E), V(0B, F0, F0, FB), \
102
+ V(EC, AD, AD, 41), V(67, D4, D4, B3), V(FD, A2, A2, 5F), V(EA, AF, AF, 45), \
103
+ V(BF, 9C, 9C, 23), V(F7, A4, A4, 53), V(96, 72, 72, E4), V(5B, C0, C0, 9B), \
104
+ V(C2, B7, B7, 75), V(1C, FD, FD, E1), V(AE, 93, 93, 3D), V(6A, 26, 26, 4C), \
105
+ V(5A, 36, 36, 6C), V(41, 3F, 3F, 7E), V(02, F7, F7, F5), V(4F, CC, CC, 83), \
106
+ V(5C, 34, 34, 68), V(F4, A5, A5, 51), V(34, E5, E5, D1), V(08, F1, F1, F9), \
107
+ V(93, 71, 71, E2), V(73, D8, D8, AB), V(53, 31, 31, 62), V(3F, 15, 15, 2A), \
108
+ V(0C, 04, 04, 08), V(52, C7, C7, 95), V(65, 23, 23, 46), V(5E, C3, C3, 9D), \
109
+ V(28, 18, 18, 30), V(A1, 96, 96, 37), V(0F, 05, 05, 0A), V(B5, 9A, 9A, 2F), \
110
+ V(09, 07, 07, 0E), V(36, 12, 12, 24), V(9B, 80, 80, 1B), V(3D, E2, E2, DF), \
111
+ V(26, EB, EB, CD), V(69, 27, 27, 4E), V(CD, B2, B2, 7F), V(9F, 75, 75, EA), \
112
+ V(1B, 09, 09, 12), V(9E, 83, 83, 1D), V(74, 2C, 2C, 58), V(2E, 1A, 1A, 34), \
113
+ V(2D, 1B, 1B, 36), V(B2, 6E, 6E, DC), V(EE, 5A, 5A, B4), V(FB, A0, A0, 5B), \
114
+ V(F6, 52, 52, A4), V(4D, 3B, 3B, 76), V(61, D6, D6, B7), V(CE, B3, B3, 7D), \
115
+ V(7B, 29, 29, 52), V(3E, E3, E3, DD), V(71, 2F, 2F, 5E), V(97, 84, 84, 13), \
116
+ V(F5, 53, 53, A6), V(68, D1, D1, B9), V(00, 00, 00, 00), V(2C, ED, ED, C1), \
117
+ V(60, 20, 20, 40), V(1F, FC, FC, E3), V(C8, B1, B1, 79), V(ED, 5B, 5B, B6), \
118
+ V(BE, 6A, 6A, D4), V(46, CB, CB, 8D), V(D9, BE, BE, 67), V(4B, 39, 39, 72), \
119
+ V(DE, 4A, 4A, 94), V(D4, 4C, 4C, 98), V(E8, 58, 58, B0), V(4A, CF, CF, 85), \
120
+ V(6B, D0, D0, BB), V(2A, EF, EF, C5), V(E5, AA, AA, 4F), V(16, FB, FB, ED), \
121
+ V(C5, 43, 43, 86), V(D7, 4D, 4D, 9A), V(55, 33, 33, 66), V(94, 85, 85, 11), \
122
+ V(CF, 45, 45, 8A), V(10, F9, F9, E9), V(06, 02, 02, 04), V(81, 7F, 7F, FE), \
123
+ V(F0, 50, 50, A0), V(44, 3C, 3C, 78), V(BA, 9F, 9F, 25), V(E3, A8, A8, 4B), \
124
+ V(F3, 51, 51, A2), V(FE, A3, A3, 5D), V(C0, 40, 40, 80), V(8A, 8F, 8F, 05), \
125
+ V(AD, 92, 92, 3F), V(BC, 9D, 9D, 21), V(48, 38, 38, 70), V(04, F5, F5, F1), \
126
+ V(DF, BC, BC, 63), V(C1, B6, B6, 77), V(75, DA, DA, AF), V(63, 21, 21, 42), \
127
+ V(30, 10, 10, 20), V(1A, FF, FF, E5), V(0E, F3, F3, FD), V(6D, D2, D2, BF), \
128
+ V(4C, CD, CD, 81), V(14, 0C, 0C, 18), V(35, 13, 13, 26), V(2F, EC, EC, C3), \
129
+ V(E1, 5F, 5F, BE), V(A2, 97, 97, 35), V(CC, 44, 44, 88), V(39, 17, 17, 2E), \
130
+ V(57, C4, C4, 93), V(F2, A7, A7, 55), V(82, 7E, 7E, FC), V(47, 3D, 3D, 7A), \
131
+ V(AC, 64, 64, C8), V(E7, 5D, 5D, BA), V(2B, 19, 19, 32), V(95, 73, 73, E6), \
132
+ V(A0, 60, 60, C0), V(98, 81, 81, 19), V(D1, 4F, 4F, 9E), V(7F, DC, DC, A3), \
133
+ V(66, 22, 22, 44), V(7E, 2A, 2A, 54), V(AB, 90, 90, 3B), V(83, 88, 88, 0B), \
134
+ V(CA, 46, 46, 8C), V(29, EE, EE, C7), V(D3, B8, B8, 6B), V(3C, 14, 14, 28), \
135
+ V(79, DE, DE, A7), V(E2, 5E, 5E, BC), V(1D, 0B, 0B, 16), V(76, DB, DB, AD), \
136
+ V(3B, E0, E0, DB), V(56, 32, 32, 64), V(4E, 3A, 3A, 74), V(1E, 0A, 0A, 14), \
137
+ V(DB, 49, 49, 92), V(0A, 06, 06, 0C), V(6C, 24, 24, 48), V(E4, 5C, 5C, B8), \
138
+ V(5D, C2, C2, 9F), V(6E, D3, D3, BD), V(EF, AC, AC, 43), V(A6, 62, 62, C4), \
139
+ V(A8, 91, 91, 39), V(A4, 95, 95, 31), V(37, E4, E4, D3), V(8B, 79, 79, F2), \
140
+ V(32, E7, E7, D5), V(43, C8, C8, 8B), V(59, 37, 37, 6E), V(B7, 6D, 6D, DA), \
141
+ V(8C, 8D, 8D, 01), V(64, D5, D5, B1), V(D2, 4E, 4E, 9C), V(E0, A9, A9, 49), \
142
+ V(B4, 6C, 6C, D8), V(FA, 56, 56, AC), V(07, F4, F4, F3), V(25, EA, EA, CF), \
143
+ V(AF, 65, 65, CA), V(8E, 7A, 7A, F4), V(E9, AE, AE, 47), V(18, 08, 08, 10), \
144
+ V(D5, BA, BA, 6F), V(88, 78, 78, F0), V(6F, 25, 25, 4A), V(72, 2E, 2E, 5C), \
145
+ V(24, 1C, 1C, 38), V(F1, A6, A6, 57), V(C7, B4, B4, 73), V(51, C6, C6, 97), \
146
+ V(23, E8, E8, CB), V(7C, DD, DD, A1), V(9C, 74, 74, E8), V(21, 1F, 1F, 3E), \
147
+ V(DD, 4B, 4B, 96), V(DC, BD, BD, 61), V(86, 8B, 8B, 0D), V(85, 8A, 8A, 0F), \
148
+ V(90, 70, 70, E0), V(42, 3E, 3E, 7C), V(C4, B5, B5, 71), V(AA, 66, 66, CC), \
149
+ V(D8, 48, 48, 90), V(05, 03, 03, 06), V(01, F6, F6, F7), V(12, 0E, 0E, 1C), \
150
+ V(A3, 61, 61, C2), V(5F, 35, 35, 6A), V(F9, 57, 57, AE), V(D0, B9, B9, 69), \
151
+ V(91, 86, 86, 17), V(58, C1, C1, 99), V(27, 1D, 1D, 3A), V(B9, 9E, 9E, 27), \
152
+ V(38, E1, E1, D9), V(13, F8, F8, EB), V(B3, 98, 98, 2B), V(33, 11, 11, 22), \
153
+ V(BB, 69, 69, D2), V(70, D9, D9, A9), V(89, 8E, 8E, 07), V(A7, 94, 94, 33), \
154
+ V(B6, 9B, 9B, 2D), V(22, 1E, 1E, 3C), V(92, 87, 87, 15), V(20, E9, E9, C9), \
155
+ V(49, CE, CE, 87), V(FF, 55, 55, AA), V(78, 28, 28, 50), V(7A, DF, DF, A5), \
156
+ V(8F, 8C, 8C, 03), V(F8, A1, A1, 59), V(80, 89, 89, 09), V(17, 0D, 0D, 1A), \
157
+ V(DA, BF, BF, 65), V(31, E6, E6, D7), V(C6, 42, 42, 84), V(B8, 68, 68, D0), \
158
+ V(C3, 41, 41, 82), V(B0, 99, 99, 29), V(77, 2D, 2D, 5A), V(11, 0F, 0F, 1E), \
159
+ V(CB, B0, B0, 7B), V(FC, 54, 54, A8), V(D6, BB, BB, 6D), V(3A, 16, 16, 2C)
160
+
161
+ #define V(a, b, c, d) 0x##a##b##c##d
162
+ MBEDTLS_MAYBE_UNUSED static const uint32_t FT0[256] = { FT };
163
+ #undef V
164
+
165
+ #define V(a, b, c, d) 0x##b##c##d##a
166
+ MBEDTLS_MAYBE_UNUSED static const uint32_t FT1[256] = { FT };
167
+ #undef V
168
+
169
+ #define V(a, b, c, d) 0x##c##d##a##b
170
+ MBEDTLS_MAYBE_UNUSED static const uint32_t FT2[256] = { FT };
171
+ #undef V
172
+
173
+ #define V(a, b, c, d) 0x##d##a##b##c
174
+ MBEDTLS_MAYBE_UNUSED static const uint32_t FT3[256] = { FT };
175
+ #undef V
176
+
177
+ #undef FT
178
+
179
+ /*
180
+ * Reverse S-box
181
+ */
182
+ MBEDTLS_MAYBE_UNUSED static const unsigned char RSb[256] =
183
+ {
184
+ 0x52, 0x09, 0x6A, 0xD5, 0x30, 0x36, 0xA5, 0x38,
185
+ 0xBF, 0x40, 0xA3, 0x9E, 0x81, 0xF3, 0xD7, 0xFB,
186
+ 0x7C, 0xE3, 0x39, 0x82, 0x9B, 0x2F, 0xFF, 0x87,
187
+ 0x34, 0x8E, 0x43, 0x44, 0xC4, 0xDE, 0xE9, 0xCB,
188
+ 0x54, 0x7B, 0x94, 0x32, 0xA6, 0xC2, 0x23, 0x3D,
189
+ 0xEE, 0x4C, 0x95, 0x0B, 0x42, 0xFA, 0xC3, 0x4E,
190
+ 0x08, 0x2E, 0xA1, 0x66, 0x28, 0xD9, 0x24, 0xB2,
191
+ 0x76, 0x5B, 0xA2, 0x49, 0x6D, 0x8B, 0xD1, 0x25,
192
+ 0x72, 0xF8, 0xF6, 0x64, 0x86, 0x68, 0x98, 0x16,
193
+ 0xD4, 0xA4, 0x5C, 0xCC, 0x5D, 0x65, 0xB6, 0x92,
194
+ 0x6C, 0x70, 0x48, 0x50, 0xFD, 0xED, 0xB9, 0xDA,
195
+ 0x5E, 0x15, 0x46, 0x57, 0xA7, 0x8D, 0x9D, 0x84,
196
+ 0x90, 0xD8, 0xAB, 0x00, 0x8C, 0xBC, 0xD3, 0x0A,
197
+ 0xF7, 0xE4, 0x58, 0x05, 0xB8, 0xB3, 0x45, 0x06,
198
+ 0xD0, 0x2C, 0x1E, 0x8F, 0xCA, 0x3F, 0x0F, 0x02,
199
+ 0xC1, 0xAF, 0xBD, 0x03, 0x01, 0x13, 0x8A, 0x6B,
200
+ 0x3A, 0x91, 0x11, 0x41, 0x4F, 0x67, 0xDC, 0xEA,
201
+ 0x97, 0xF2, 0xCF, 0xCE, 0xF0, 0xB4, 0xE6, 0x73,
202
+ 0x96, 0xAC, 0x74, 0x22, 0xE7, 0xAD, 0x35, 0x85,
203
+ 0xE2, 0xF9, 0x37, 0xE8, 0x1C, 0x75, 0xDF, 0x6E,
204
+ 0x47, 0xF1, 0x1A, 0x71, 0x1D, 0x29, 0xC5, 0x89,
205
+ 0x6F, 0xB7, 0x62, 0x0E, 0xAA, 0x18, 0xBE, 0x1B,
206
+ 0xFC, 0x56, 0x3E, 0x4B, 0xC6, 0xD2, 0x79, 0x20,
207
+ 0x9A, 0xDB, 0xC0, 0xFE, 0x78, 0xCD, 0x5A, 0xF4,
208
+ 0x1F, 0xDD, 0xA8, 0x33, 0x88, 0x07, 0xC7, 0x31,
209
+ 0xB1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xEC, 0x5F,
210
+ 0x60, 0x51, 0x7F, 0xA9, 0x19, 0xB5, 0x4A, 0x0D,
211
+ 0x2D, 0xE5, 0x7A, 0x9F, 0x93, 0xC9, 0x9C, 0xEF,
212
+ 0xA0, 0xE0, 0x3B, 0x4D, 0xAE, 0x2A, 0xF5, 0xB0,
213
+ 0xC8, 0xEB, 0xBB, 0x3C, 0x83, 0x53, 0x99, 0x61,
214
+ 0x17, 0x2B, 0x04, 0x7E, 0xBA, 0x77, 0xD6, 0x26,
215
+ 0xE1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0C, 0x7D
216
+ };
217
+
218
+ /*
219
+ * Reverse tables
220
+ */
221
+ #define RT \
222
+ \
223
+ V(50, A7, F4, 51), V(53, 65, 41, 7E), V(C3, A4, 17, 1A), V(96, 5E, 27, 3A), \
224
+ V(CB, 6B, AB, 3B), V(F1, 45, 9D, 1F), V(AB, 58, FA, AC), V(93, 03, E3, 4B), \
225
+ V(55, FA, 30, 20), V(F6, 6D, 76, AD), V(91, 76, CC, 88), V(25, 4C, 02, F5), \
226
+ V(FC, D7, E5, 4F), V(D7, CB, 2A, C5), V(80, 44, 35, 26), V(8F, A3, 62, B5), \
227
+ V(49, 5A, B1, DE), V(67, 1B, BA, 25), V(98, 0E, EA, 45), V(E1, C0, FE, 5D), \
228
+ V(02, 75, 2F, C3), V(12, F0, 4C, 81), V(A3, 97, 46, 8D), V(C6, F9, D3, 6B), \
229
+ V(E7, 5F, 8F, 03), V(95, 9C, 92, 15), V(EB, 7A, 6D, BF), V(DA, 59, 52, 95), \
230
+ V(2D, 83, BE, D4), V(D3, 21, 74, 58), V(29, 69, E0, 49), V(44, C8, C9, 8E), \
231
+ V(6A, 89, C2, 75), V(78, 79, 8E, F4), V(6B, 3E, 58, 99), V(DD, 71, B9, 27), \
232
+ V(B6, 4F, E1, BE), V(17, AD, 88, F0), V(66, AC, 20, C9), V(B4, 3A, CE, 7D), \
233
+ V(18, 4A, DF, 63), V(82, 31, 1A, E5), V(60, 33, 51, 97), V(45, 7F, 53, 62), \
234
+ V(E0, 77, 64, B1), V(84, AE, 6B, BB), V(1C, A0, 81, FE), V(94, 2B, 08, F9), \
235
+ V(58, 68, 48, 70), V(19, FD, 45, 8F), V(87, 6C, DE, 94), V(B7, F8, 7B, 52), \
236
+ V(23, D3, 73, AB), V(E2, 02, 4B, 72), V(57, 8F, 1F, E3), V(2A, AB, 55, 66), \
237
+ V(07, 28, EB, B2), V(03, C2, B5, 2F), V(9A, 7B, C5, 86), V(A5, 08, 37, D3), \
238
+ V(F2, 87, 28, 30), V(B2, A5, BF, 23), V(BA, 6A, 03, 02), V(5C, 82, 16, ED), \
239
+ V(2B, 1C, CF, 8A), V(92, B4, 79, A7), V(F0, F2, 07, F3), V(A1, E2, 69, 4E), \
240
+ V(CD, F4, DA, 65), V(D5, BE, 05, 06), V(1F, 62, 34, D1), V(8A, FE, A6, C4), \
241
+ V(9D, 53, 2E, 34), V(A0, 55, F3, A2), V(32, E1, 8A, 05), V(75, EB, F6, A4), \
242
+ V(39, EC, 83, 0B), V(AA, EF, 60, 40), V(06, 9F, 71, 5E), V(51, 10, 6E, BD), \
243
+ V(F9, 8A, 21, 3E), V(3D, 06, DD, 96), V(AE, 05, 3E, DD), V(46, BD, E6, 4D), \
244
+ V(B5, 8D, 54, 91), V(05, 5D, C4, 71), V(6F, D4, 06, 04), V(FF, 15, 50, 60), \
245
+ V(24, FB, 98, 19), V(97, E9, BD, D6), V(CC, 43, 40, 89), V(77, 9E, D9, 67), \
246
+ V(BD, 42, E8, B0), V(88, 8B, 89, 07), V(38, 5B, 19, E7), V(DB, EE, C8, 79), \
247
+ V(47, 0A, 7C, A1), V(E9, 0F, 42, 7C), V(C9, 1E, 84, F8), V(00, 00, 00, 00), \
248
+ V(83, 86, 80, 09), V(48, ED, 2B, 32), V(AC, 70, 11, 1E), V(4E, 72, 5A, 6C), \
249
+ V(FB, FF, 0E, FD), V(56, 38, 85, 0F), V(1E, D5, AE, 3D), V(27, 39, 2D, 36), \
250
+ V(64, D9, 0F, 0A), V(21, A6, 5C, 68), V(D1, 54, 5B, 9B), V(3A, 2E, 36, 24), \
251
+ V(B1, 67, 0A, 0C), V(0F, E7, 57, 93), V(D2, 96, EE, B4), V(9E, 91, 9B, 1B), \
252
+ V(4F, C5, C0, 80), V(A2, 20, DC, 61), V(69, 4B, 77, 5A), V(16, 1A, 12, 1C), \
253
+ V(0A, BA, 93, E2), V(E5, 2A, A0, C0), V(43, E0, 22, 3C), V(1D, 17, 1B, 12), \
254
+ V(0B, 0D, 09, 0E), V(AD, C7, 8B, F2), V(B9, A8, B6, 2D), V(C8, A9, 1E, 14), \
255
+ V(85, 19, F1, 57), V(4C, 07, 75, AF), V(BB, DD, 99, EE), V(FD, 60, 7F, A3), \
256
+ V(9F, 26, 01, F7), V(BC, F5, 72, 5C), V(C5, 3B, 66, 44), V(34, 7E, FB, 5B), \
257
+ V(76, 29, 43, 8B), V(DC, C6, 23, CB), V(68, FC, ED, B6), V(63, F1, E4, B8), \
258
+ V(CA, DC, 31, D7), V(10, 85, 63, 42), V(40, 22, 97, 13), V(20, 11, C6, 84), \
259
+ V(7D, 24, 4A, 85), V(F8, 3D, BB, D2), V(11, 32, F9, AE), V(6D, A1, 29, C7), \
260
+ V(4B, 2F, 9E, 1D), V(F3, 30, B2, DC), V(EC, 52, 86, 0D), V(D0, E3, C1, 77), \
261
+ V(6C, 16, B3, 2B), V(99, B9, 70, A9), V(FA, 48, 94, 11), V(22, 64, E9, 47), \
262
+ V(C4, 8C, FC, A8), V(1A, 3F, F0, A0), V(D8, 2C, 7D, 56), V(EF, 90, 33, 22), \
263
+ V(C7, 4E, 49, 87), V(C1, D1, 38, D9), V(FE, A2, CA, 8C), V(36, 0B, D4, 98), \
264
+ V(CF, 81, F5, A6), V(28, DE, 7A, A5), V(26, 8E, B7, DA), V(A4, BF, AD, 3F), \
265
+ V(E4, 9D, 3A, 2C), V(0D, 92, 78, 50), V(9B, CC, 5F, 6A), V(62, 46, 7E, 54), \
266
+ V(C2, 13, 8D, F6), V(E8, B8, D8, 90), V(5E, F7, 39, 2E), V(F5, AF, C3, 82), \
267
+ V(BE, 80, 5D, 9F), V(7C, 93, D0, 69), V(A9, 2D, D5, 6F), V(B3, 12, 25, CF), \
268
+ V(3B, 99, AC, C8), V(A7, 7D, 18, 10), V(6E, 63, 9C, E8), V(7B, BB, 3B, DB), \
269
+ V(09, 78, 26, CD), V(F4, 18, 59, 6E), V(01, B7, 9A, EC), V(A8, 9A, 4F, 83), \
270
+ V(65, 6E, 95, E6), V(7E, E6, FF, AA), V(08, CF, BC, 21), V(E6, E8, 15, EF), \
271
+ V(D9, 9B, E7, BA), V(CE, 36, 6F, 4A), V(D4, 09, 9F, EA), V(D6, 7C, B0, 29), \
272
+ V(AF, B2, A4, 31), V(31, 23, 3F, 2A), V(30, 94, A5, C6), V(C0, 66, A2, 35), \
273
+ V(37, BC, 4E, 74), V(A6, CA, 82, FC), V(B0, D0, 90, E0), V(15, D8, A7, 33), \
274
+ V(4A, 98, 04, F1), V(F7, DA, EC, 41), V(0E, 50, CD, 7F), V(2F, F6, 91, 17), \
275
+ V(8D, D6, 4D, 76), V(4D, B0, EF, 43), V(54, 4D, AA, CC), V(DF, 04, 96, E4), \
276
+ V(E3, B5, D1, 9E), V(1B, 88, 6A, 4C), V(B8, 1F, 2C, C1), V(7F, 51, 65, 46), \
277
+ V(04, EA, 5E, 9D), V(5D, 35, 8C, 01), V(73, 74, 87, FA), V(2E, 41, 0B, FB), \
278
+ V(5A, 1D, 67, B3), V(52, D2, DB, 92), V(33, 56, 10, E9), V(13, 47, D6, 6D), \
279
+ V(8C, 61, D7, 9A), V(7A, 0C, A1, 37), V(8E, 14, F8, 59), V(89, 3C, 13, EB), \
280
+ V(EE, 27, A9, CE), V(35, C9, 61, B7), V(ED, E5, 1C, E1), V(3C, B1, 47, 7A), \
281
+ V(59, DF, D2, 9C), V(3F, 73, F2, 55), V(79, CE, 14, 18), V(BF, 37, C7, 73), \
282
+ V(EA, CD, F7, 53), V(5B, AA, FD, 5F), V(14, 6F, 3D, DF), V(86, DB, 44, 78), \
283
+ V(81, F3, AF, CA), V(3E, C4, 68, B9), V(2C, 34, 24, 38), V(5F, 40, A3, C2), \
284
+ V(72, C3, 1D, 16), V(0C, 25, E2, BC), V(8B, 49, 3C, 28), V(41, 95, 0D, FF), \
285
+ V(71, 01, A8, 39), V(DE, B3, 0C, 08), V(9C, E4, B4, D8), V(90, C1, 56, 64), \
286
+ V(61, 84, CB, 7B), V(70, B6, 32, D5), V(74, 5C, 6C, 48), V(42, 57, B8, D0)
287
+
288
+
289
+ #define V(a, b, c, d) 0x##a##b##c##d
290
+ MBEDTLS_MAYBE_UNUSED static const uint32_t RT0[256] = { RT };
291
+ #undef V
292
+
293
+ #define V(a, b, c, d) 0x##b##c##d##a
294
+ MBEDTLS_MAYBE_UNUSED static const uint32_t RT1[256] = { RT };
295
+ #undef V
296
+
297
+ #define V(a, b, c, d) 0x##c##d##a##b
298
+ MBEDTLS_MAYBE_UNUSED static const uint32_t RT2[256] = { RT };
299
+ #undef V
300
+
301
+ #define V(a, b, c, d) 0x##d##a##b##c
302
+ MBEDTLS_MAYBE_UNUSED static const uint32_t RT3[256] = { RT };
303
+ #undef V
304
+
305
+ #undef RT
306
+
307
+ /*
308
+ * Round constants
309
+ */
310
+ MBEDTLS_MAYBE_UNUSED static const uint32_t round_constants[10] =
311
+ {
312
+ 0x00000001, 0x00000002, 0x00000004, 0x00000008,
313
+ 0x00000010, 0x00000020, 0x00000040, 0x00000080,
314
+ 0x0000001B, 0x00000036
315
+ };
316
+
317
+ #else /* MBEDTLS_AES_ROM_TABLES */
318
+
319
+ /*
320
+ * Forward S-box & tables
321
+ */
322
+ MBEDTLS_MAYBE_UNUSED static unsigned char FSb[256];
323
+ MBEDTLS_MAYBE_UNUSED static uint32_t FT0[256];
324
+ MBEDTLS_MAYBE_UNUSED static uint32_t FT1[256];
325
+ MBEDTLS_MAYBE_UNUSED static uint32_t FT2[256];
326
+ MBEDTLS_MAYBE_UNUSED static uint32_t FT3[256];
327
+
328
+ /*
329
+ * Reverse S-box & tables
330
+ */
331
+ MBEDTLS_MAYBE_UNUSED static unsigned char RSb[256];
332
+
333
+ MBEDTLS_MAYBE_UNUSED static uint32_t RT0[256];
334
+ MBEDTLS_MAYBE_UNUSED static uint32_t RT1[256];
335
+ MBEDTLS_MAYBE_UNUSED static uint32_t RT2[256];
336
+ MBEDTLS_MAYBE_UNUSED static uint32_t RT3[256];
337
+
338
+ /*
339
+ * Round constants
340
+ */
341
+ MBEDTLS_MAYBE_UNUSED static uint32_t round_constants[10];
342
+
343
+ /*
344
+ * Tables generation code
345
+ */
346
+ #define ROTL8(x) (((x) << 8) & 0xFFFFFFFF) | ((x) >> 24)
347
+ #define XTIME(x) (((x) << 1) ^ (((x) & 0x80) ? 0x1B : 0x00))
348
+ #define MUL(x, y) (((x) && (y)) ? pow[(log[(x)]+log[(y)]) % 255] : 0)
349
+
350
+ MBEDTLS_MAYBE_UNUSED static int aes_init_done = 0;
351
+
352
+ MBEDTLS_MAYBE_UNUSED static void aes_gen_tables(void)
353
+ {
354
+ int i;
355
+ uint8_t x, y, z;
356
+ uint8_t pow[256];
357
+ uint8_t log[256];
358
+
359
+ /*
360
+ * compute pow and log tables over GF(2^8)
361
+ */
362
+ for (i = 0, x = 1; i < 256; i++) {
363
+ pow[i] = x;
364
+ log[x] = (uint8_t) i;
365
+ x ^= XTIME(x);
366
+ }
367
+
368
+ /*
369
+ * calculate the round constants
370
+ */
371
+ for (i = 0, x = 1; i < 10; i++) {
372
+ round_constants[i] = x;
373
+ x = XTIME(x);
374
+ }
375
+
376
+ /*
377
+ * generate the forward and reverse S-boxes
378
+ */
379
+ FSb[0x00] = 0x63;
380
+ #if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
381
+ RSb[0x63] = 0x00;
382
+ #endif
383
+
384
+ for (i = 1; i < 256; i++) {
385
+ x = pow[255 - log[i]];
386
+
387
+ y = x; y = (y << 1) | (y >> 7);
388
+ x ^= y; y = (y << 1) | (y >> 7);
389
+ x ^= y; y = (y << 1) | (y >> 7);
390
+ x ^= y; y = (y << 1) | (y >> 7);
391
+ x ^= y ^ 0x63;
392
+
393
+ FSb[i] = x;
394
+ #if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
395
+ RSb[x] = (unsigned char) i;
396
+ #endif
397
+ }
398
+
399
+ /*
400
+ * generate the forward and reverse tables
401
+ */
402
+ for (i = 0; i < 256; i++) {
403
+ x = FSb[i];
404
+ y = XTIME(x);
405
+ z = y ^ x;
406
+
407
+ FT0[i] = ((uint32_t) y) ^
408
+ ((uint32_t) x << 8) ^
409
+ ((uint32_t) x << 16) ^
410
+ ((uint32_t) z << 24);
411
+
412
+ #if !defined(MBEDTLS_AES_FEWER_TABLES)
413
+ FT1[i] = ROTL8(FT0[i]);
414
+ FT2[i] = ROTL8(FT1[i]);
415
+ FT3[i] = ROTL8(FT2[i]);
416
+ #endif /* !MBEDTLS_AES_FEWER_TABLES */
417
+
418
+ #if defined(MBEDTLS_AES_NEED_REVERSE_TABLES)
419
+ x = RSb[i];
420
+
421
+ RT0[i] = ((uint32_t) MUL(0x0E, x)) ^
422
+ ((uint32_t) MUL(0x09, x) << 8) ^
423
+ ((uint32_t) MUL(0x0D, x) << 16) ^
424
+ ((uint32_t) MUL(0x0B, x) << 24);
425
+
426
+ #if !defined(MBEDTLS_AES_FEWER_TABLES)
427
+ RT1[i] = ROTL8(RT0[i]);
428
+ RT2[i] = ROTL8(RT1[i]);
429
+ RT3[i] = ROTL8(RT2[i]);
430
+ #endif /* !MBEDTLS_AES_FEWER_TABLES */
431
+ #endif /* MBEDTLS_AES_NEED_REVERSE_TABLES */
432
+ }
433
+ }
434
+
435
+ #undef ROTL8
436
+
437
+ #endif /* MBEDTLS_AES_ROM_TABLES */
438
+
439
+ #if defined(MBEDTLS_AES_FEWER_TABLES)
440
+
441
+ #define ROTL8(x) ((uint32_t) ((x) << 8) + (uint32_t) ((x) >> 24))
442
+ #define ROTL16(x) ((uint32_t) ((x) << 16) + (uint32_t) ((x) >> 16))
443
+ #define ROTL24(x) ((uint32_t) ((x) << 24) + (uint32_t) ((x) >> 8))
444
+
445
+ #define AES_RT0(idx) RT0[idx]
446
+ #define AES_RT1(idx) ROTL8(RT0[idx])
447
+ #define AES_RT2(idx) ROTL16(RT0[idx])
448
+ #define AES_RT3(idx) ROTL24(RT0[idx])
449
+
450
+ #define AES_FT0(idx) FT0[idx]
451
+ #define AES_FT1(idx) ROTL8(FT0[idx])
452
+ #define AES_FT2(idx) ROTL16(FT0[idx])
453
+ #define AES_FT3(idx) ROTL24(FT0[idx])
454
+
455
+ #else /* MBEDTLS_AES_FEWER_TABLES */
456
+
457
+ #define AES_RT0(idx) RT0[idx]
458
+ #define AES_RT1(idx) RT1[idx]
459
+ #define AES_RT2(idx) RT2[idx]
460
+ #define AES_RT3(idx) RT3[idx]
461
+
462
+ #define AES_FT0(idx) FT0[idx]
463
+ #define AES_FT1(idx) FT1[idx]
464
+ #define AES_FT2(idx) FT2[idx]
465
+ #define AES_FT3(idx) FT3[idx]
466
+
467
+ #endif /* MBEDTLS_AES_FEWER_TABLES */
468
+
469
+ void mbedtls_aes_init(mbedtls_aes_context *ctx)
470
+ {
471
+ memset(ctx, 0, sizeof(mbedtls_aes_context));
472
+ }
473
+
474
+ void mbedtls_aes_free(mbedtls_aes_context *ctx)
475
+ {
476
+ if (ctx == NULL) {
477
+ return;
478
+ }
479
+
480
+ mbedtls_platform_zeroize(ctx, sizeof(mbedtls_aes_context));
481
+ }
482
+
483
+ mbedtls_aes_implementation mbedtls_aes_get_implementation(void)
484
+ {
485
+ #if defined(MBEDTLS_AESNI_HAVE_CODE)
486
+ if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
487
+ #if MBEDTLS_AESNI_HAVE_CODE == 1
488
+ return MBEDTLS_AES_IMP_AESNI_ASM;
489
+ #elif MBEDTLS_AESNI_HAVE_CODE == 2
490
+ return MBEDTLS_AES_IMP_AESNI_INTRINSICS;
491
+ #endif /* MBEDTLS_AESNI_HAVE_CODE == 1 || 2 */
492
+ }
493
+ #endif /* MBEDTLS_AESNI_HAVE_CODE */
494
+
495
+ #if defined(MBEDTLS_AESCE_HAVE_CODE)
496
+ if (MBEDTLS_AESCE_HAS_SUPPORT()) {
497
+ return MBEDTLS_AES_IMP_AESCE;
498
+ }
499
+ #endif
500
+
501
+ #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
502
+ return MBEDTLS_AES_IMP_SOFTWARE;
503
+ #endif
504
+ return MBEDTLS_AES_IMP_UNKNOWN;
505
+ }
506
+
507
+ #if defined(MBEDTLS_CIPHER_MODE_XTS)
508
+ void mbedtls_aes_xts_init(mbedtls_aes_xts_context *ctx)
509
+ {
510
+ mbedtls_aes_init(&ctx->crypt);
511
+ mbedtls_aes_init(&ctx->tweak);
512
+ }
513
+
514
+ void mbedtls_aes_xts_free(mbedtls_aes_xts_context *ctx)
515
+ {
516
+ if (ctx == NULL) {
517
+ return;
518
+ }
519
+
520
+ mbedtls_aes_free(&ctx->crypt);
521
+ mbedtls_aes_free(&ctx->tweak);
522
+ }
523
+ #endif /* MBEDTLS_CIPHER_MODE_XTS */
524
+
525
+ /* Some implementations need the round keys to be aligned.
526
+ * Return an offset to be added to buf, such that (buf + offset) is
527
+ * correctly aligned.
528
+ * Note that the offset is in units of elements of buf, i.e. 32-bit words,
529
+ * i.e. an offset of 1 means 4 bytes and so on.
530
+ */
531
+ #if defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2
532
+ #define MAY_NEED_TO_ALIGN
533
+ #endif
534
+
535
+ MBEDTLS_MAYBE_UNUSED static unsigned mbedtls_aes_rk_offset(uint32_t *buf)
536
+ {
537
+ #if defined(MAY_NEED_TO_ALIGN)
538
+ int align_16_bytes = 0;
539
+
540
+ #if defined(MBEDTLS_AESNI_C) && MBEDTLS_AESNI_HAVE_CODE == 2
541
+ if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
542
+ align_16_bytes = 1;
543
+ }
544
+ #endif
545
+
546
+ if (align_16_bytes) {
547
+ /* These implementations needs 16-byte alignment
548
+ * for the round key array. */
549
+ unsigned delta = ((uintptr_t) buf & 0x0000000fU) / 4;
550
+ if (delta == 0) {
551
+ return 0;
552
+ } else {
553
+ return 4 - delta; // 16 bytes = 4 uint32_t
554
+ }
555
+ }
556
+ #else /* MAY_NEED_TO_ALIGN */
557
+ (void) buf;
558
+ #endif /* MAY_NEED_TO_ALIGN */
559
+
560
+ return 0;
561
+ }
562
+
563
+ /*
564
+ * AES key schedule (encryption)
565
+ */
566
+ int mbedtls_aes_setkey_enc(mbedtls_aes_context *ctx, const unsigned char *key,
567
+ unsigned int keybits)
568
+ {
569
+ uint32_t *RK;
570
+
571
+ switch (keybits) {
572
+ case 128: ctx->nr = 10; break;
573
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
574
+ case 192: ctx->nr = 12; break;
575
+ case 256: ctx->nr = 14; break;
576
+ #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
577
+ default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
578
+ }
579
+
580
+ #if !defined(MBEDTLS_AES_ROM_TABLES)
581
+ if (aes_init_done == 0) {
582
+ aes_gen_tables();
583
+ aes_init_done = 1;
584
+ }
585
+ #endif
586
+
587
+ ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf);
588
+ RK = ctx->buf + ctx->rk_offset;
589
+
590
+ #if defined(MBEDTLS_AESNI_HAVE_CODE)
591
+ if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
592
+ return mbedtls_aesni_setkey_enc((unsigned char *) RK, key, keybits);
593
+ }
594
+ #endif
595
+
596
+ #if defined(MBEDTLS_AESCE_HAVE_CODE)
597
+ if (MBEDTLS_AESCE_HAS_SUPPORT()) {
598
+ return mbedtls_aesce_setkey_enc((unsigned char *) RK, key, keybits);
599
+ }
600
+ #endif
601
+
602
+ #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
603
+ for (unsigned int i = 0; i < (keybits >> 5); i++) {
604
+ RK[i] = MBEDTLS_GET_UINT32_LE(key, i << 2);
605
+ }
606
+
607
+ switch (ctx->nr) {
608
+ case 10:
609
+
610
+ for (unsigned int i = 0; i < 10; i++, RK += 4) {
611
+ RK[4] = RK[0] ^ round_constants[i] ^
612
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[3])]) ^
613
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[3])] << 8) ^
614
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[3])] << 16) ^
615
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[3])] << 24);
616
+
617
+ RK[5] = RK[1] ^ RK[4];
618
+ RK[6] = RK[2] ^ RK[5];
619
+ RK[7] = RK[3] ^ RK[6];
620
+ }
621
+ break;
622
+
623
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
624
+ case 12:
625
+
626
+ for (unsigned int i = 0; i < 8; i++, RK += 6) {
627
+ RK[6] = RK[0] ^ round_constants[i] ^
628
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[5])]) ^
629
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[5])] << 8) ^
630
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[5])] << 16) ^
631
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[5])] << 24);
632
+
633
+ RK[7] = RK[1] ^ RK[6];
634
+ RK[8] = RK[2] ^ RK[7];
635
+ RK[9] = RK[3] ^ RK[8];
636
+ RK[10] = RK[4] ^ RK[9];
637
+ RK[11] = RK[5] ^ RK[10];
638
+ }
639
+ break;
640
+
641
+ case 14:
642
+
643
+ for (unsigned int i = 0; i < 7; i++, RK += 8) {
644
+ RK[8] = RK[0] ^ round_constants[i] ^
645
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[7])]) ^
646
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[7])] << 8) ^
647
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[7])] << 16) ^
648
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[7])] << 24);
649
+
650
+ RK[9] = RK[1] ^ RK[8];
651
+ RK[10] = RK[2] ^ RK[9];
652
+ RK[11] = RK[3] ^ RK[10];
653
+
654
+ RK[12] = RK[4] ^
655
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(RK[11])]) ^
656
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(RK[11])] << 8) ^
657
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(RK[11])] << 16) ^
658
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(RK[11])] << 24);
659
+
660
+ RK[13] = RK[5] ^ RK[12];
661
+ RK[14] = RK[6] ^ RK[13];
662
+ RK[15] = RK[7] ^ RK[14];
663
+ }
664
+ break;
665
+ #endif /* !MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH */
666
+ }
667
+
668
+ return 0;
669
+ #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
670
+ }
671
+
672
+ /*
673
+ * AES key schedule (decryption)
674
+ */
675
+ #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
676
+ int mbedtls_aes_setkey_dec(mbedtls_aes_context *ctx, const unsigned char *key,
677
+ unsigned int keybits)
678
+ {
679
+ #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
680
+ uint32_t *SK;
681
+ #endif
682
+ int ret;
683
+ mbedtls_aes_context cty;
684
+ uint32_t *RK;
685
+
686
+
687
+ mbedtls_aes_init(&cty);
688
+
689
+ ctx->rk_offset = mbedtls_aes_rk_offset(ctx->buf);
690
+ RK = ctx->buf + ctx->rk_offset;
691
+
692
+ /* Also checks keybits */
693
+ if ((ret = mbedtls_aes_setkey_enc(&cty, key, keybits)) != 0) {
694
+ goto exit;
695
+ }
696
+
697
+ ctx->nr = cty.nr;
698
+
699
+ #if defined(MBEDTLS_AESNI_HAVE_CODE)
700
+ if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
701
+ mbedtls_aesni_inverse_key((unsigned char *) RK,
702
+ (const unsigned char *) (cty.buf + cty.rk_offset), ctx->nr);
703
+ goto exit;
704
+ }
705
+ #endif
706
+
707
+ #if defined(MBEDTLS_AESCE_HAVE_CODE)
708
+ if (MBEDTLS_AESCE_HAS_SUPPORT()) {
709
+ mbedtls_aesce_inverse_key(
710
+ (unsigned char *) RK,
711
+ (const unsigned char *) (cty.buf + cty.rk_offset),
712
+ ctx->nr);
713
+ goto exit;
714
+ }
715
+ #endif
716
+
717
+ #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
718
+ SK = cty.buf + cty.rk_offset + cty.nr * 4;
719
+
720
+ *RK++ = *SK++;
721
+ *RK++ = *SK++;
722
+ *RK++ = *SK++;
723
+ *RK++ = *SK++;
724
+ SK -= 8;
725
+ for (int i = ctx->nr - 1; i > 0; i--, SK -= 8) {
726
+ for (int j = 0; j < 4; j++, SK++) {
727
+ *RK++ = AES_RT0(FSb[MBEDTLS_BYTE_0(*SK)]) ^
728
+ AES_RT1(FSb[MBEDTLS_BYTE_1(*SK)]) ^
729
+ AES_RT2(FSb[MBEDTLS_BYTE_2(*SK)]) ^
730
+ AES_RT3(FSb[MBEDTLS_BYTE_3(*SK)]);
731
+ }
732
+ }
733
+
734
+ *RK++ = *SK++;
735
+ *RK++ = *SK++;
736
+ *RK++ = *SK++;
737
+ *RK++ = *SK++;
738
+ #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
739
+ exit:
740
+ mbedtls_aes_free(&cty);
741
+
742
+ return ret;
743
+ }
744
+ #endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
745
+
746
+ #if defined(MBEDTLS_CIPHER_MODE_XTS)
747
+ static int mbedtls_aes_xts_decode_keys(const unsigned char *key,
748
+ unsigned int keybits,
749
+ const unsigned char **key1,
750
+ unsigned int *key1bits,
751
+ const unsigned char **key2,
752
+ unsigned int *key2bits)
753
+ {
754
+ const unsigned int half_keybits = keybits / 2;
755
+ const unsigned int half_keybytes = half_keybits / 8;
756
+
757
+ switch (keybits) {
758
+ case 256: break;
759
+ case 512: break;
760
+ default: return MBEDTLS_ERR_AES_INVALID_KEY_LENGTH;
761
+ }
762
+
763
+ *key1bits = half_keybits;
764
+ *key2bits = half_keybits;
765
+ *key1 = &key[0];
766
+ *key2 = &key[half_keybytes];
767
+
768
+ return 0;
769
+ }
770
+
771
+ int mbedtls_aes_xts_setkey_enc(mbedtls_aes_xts_context *ctx,
772
+ const unsigned char *key,
773
+ unsigned int keybits)
774
+ {
775
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
776
+ const unsigned char *key1, *key2;
777
+ unsigned int key1bits, key2bits;
778
+
779
+ ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits,
780
+ &key2, &key2bits);
781
+ if (ret != 0) {
782
+ return ret;
783
+ }
784
+
785
+ /* Set the tweak key. Always set tweak key for the encryption mode. */
786
+ ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits);
787
+ if (ret != 0) {
788
+ return ret;
789
+ }
790
+
791
+ /* Set crypt key for encryption. */
792
+ return mbedtls_aes_setkey_enc(&ctx->crypt, key1, key1bits);
793
+ }
794
+
795
+ int mbedtls_aes_xts_setkey_dec(mbedtls_aes_xts_context *ctx,
796
+ const unsigned char *key,
797
+ unsigned int keybits)
798
+ {
799
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
800
+ const unsigned char *key1, *key2;
801
+ unsigned int key1bits, key2bits;
802
+
803
+ ret = mbedtls_aes_xts_decode_keys(key, keybits, &key1, &key1bits,
804
+ &key2, &key2bits);
805
+ if (ret != 0) {
806
+ return ret;
807
+ }
808
+
809
+ /* Set the tweak key. Always set tweak key for encryption. */
810
+ ret = mbedtls_aes_setkey_enc(&ctx->tweak, key2, key2bits);
811
+ if (ret != 0) {
812
+ return ret;
813
+ }
814
+
815
+ /* Set crypt key for decryption. */
816
+ return mbedtls_aes_setkey_dec(&ctx->crypt, key1, key1bits);
817
+ }
818
+ #endif /* MBEDTLS_CIPHER_MODE_XTS */
819
+
820
+ #define AES_FROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \
821
+ do \
822
+ { \
823
+ (X0) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y0)) ^ \
824
+ AES_FT1(MBEDTLS_BYTE_1(Y1)) ^ \
825
+ AES_FT2(MBEDTLS_BYTE_2(Y2)) ^ \
826
+ AES_FT3(MBEDTLS_BYTE_3(Y3)); \
827
+ \
828
+ (X1) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y1)) ^ \
829
+ AES_FT1(MBEDTLS_BYTE_1(Y2)) ^ \
830
+ AES_FT2(MBEDTLS_BYTE_2(Y3)) ^ \
831
+ AES_FT3(MBEDTLS_BYTE_3(Y0)); \
832
+ \
833
+ (X2) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y2)) ^ \
834
+ AES_FT1(MBEDTLS_BYTE_1(Y3)) ^ \
835
+ AES_FT2(MBEDTLS_BYTE_2(Y0)) ^ \
836
+ AES_FT3(MBEDTLS_BYTE_3(Y1)); \
837
+ \
838
+ (X3) = *RK++ ^ AES_FT0(MBEDTLS_BYTE_0(Y3)) ^ \
839
+ AES_FT1(MBEDTLS_BYTE_1(Y0)) ^ \
840
+ AES_FT2(MBEDTLS_BYTE_2(Y1)) ^ \
841
+ AES_FT3(MBEDTLS_BYTE_3(Y2)); \
842
+ } while (0)
843
+
844
+ #define AES_RROUND(X0, X1, X2, X3, Y0, Y1, Y2, Y3) \
845
+ do \
846
+ { \
847
+ (X0) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y0)) ^ \
848
+ AES_RT1(MBEDTLS_BYTE_1(Y3)) ^ \
849
+ AES_RT2(MBEDTLS_BYTE_2(Y2)) ^ \
850
+ AES_RT3(MBEDTLS_BYTE_3(Y1)); \
851
+ \
852
+ (X1) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y1)) ^ \
853
+ AES_RT1(MBEDTLS_BYTE_1(Y0)) ^ \
854
+ AES_RT2(MBEDTLS_BYTE_2(Y3)) ^ \
855
+ AES_RT3(MBEDTLS_BYTE_3(Y2)); \
856
+ \
857
+ (X2) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y2)) ^ \
858
+ AES_RT1(MBEDTLS_BYTE_1(Y1)) ^ \
859
+ AES_RT2(MBEDTLS_BYTE_2(Y0)) ^ \
860
+ AES_RT3(MBEDTLS_BYTE_3(Y3)); \
861
+ \
862
+ (X3) = *RK++ ^ AES_RT0(MBEDTLS_BYTE_0(Y3)) ^ \
863
+ AES_RT1(MBEDTLS_BYTE_1(Y2)) ^ \
864
+ AES_RT2(MBEDTLS_BYTE_2(Y1)) ^ \
865
+ AES_RT3(MBEDTLS_BYTE_3(Y0)); \
866
+ } while (0)
867
+
868
+ #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
869
+ /*
870
+ * AES-ECB block encryption
871
+ */
872
+ MBEDTLS_CHECK_RETURN_TYPICAL
873
+ static int mbedtls_internal_aes_encrypt(mbedtls_aes_context *ctx,
874
+ const unsigned char input[16],
875
+ unsigned char output[16])
876
+ {
877
+ int i;
878
+ uint32_t *RK = ctx->buf + ctx->rk_offset;
879
+ struct {
880
+ uint32_t X[4];
881
+ uint32_t Y[4];
882
+ } t;
883
+
884
+ t.X[0] = MBEDTLS_GET_UINT32_LE(input, 0); t.X[0] ^= *RK++;
885
+ t.X[1] = MBEDTLS_GET_UINT32_LE(input, 4); t.X[1] ^= *RK++;
886
+ t.X[2] = MBEDTLS_GET_UINT32_LE(input, 8); t.X[2] ^= *RK++;
887
+ t.X[3] = MBEDTLS_GET_UINT32_LE(input, 12); t.X[3] ^= *RK++;
888
+
889
+ for (i = (ctx->nr >> 1) - 1; i > 0; i--) {
890
+ AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
891
+ AES_FROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]);
892
+ }
893
+
894
+ AES_FROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
895
+
896
+ t.X[0] = *RK++ ^ \
897
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[0])]) ^
898
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[1])] << 8) ^
899
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[2])] << 16) ^
900
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[3])] << 24);
901
+
902
+ t.X[1] = *RK++ ^ \
903
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[1])]) ^
904
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[2])] << 8) ^
905
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[3])] << 16) ^
906
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[0])] << 24);
907
+
908
+ t.X[2] = *RK++ ^ \
909
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[2])]) ^
910
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[3])] << 8) ^
911
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[0])] << 16) ^
912
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[1])] << 24);
913
+
914
+ t.X[3] = *RK++ ^ \
915
+ ((uint32_t) FSb[MBEDTLS_BYTE_0(t.Y[3])]) ^
916
+ ((uint32_t) FSb[MBEDTLS_BYTE_1(t.Y[0])] << 8) ^
917
+ ((uint32_t) FSb[MBEDTLS_BYTE_2(t.Y[1])] << 16) ^
918
+ ((uint32_t) FSb[MBEDTLS_BYTE_3(t.Y[2])] << 24);
919
+
920
+ MBEDTLS_PUT_UINT32_LE(t.X[0], output, 0);
921
+ MBEDTLS_PUT_UINT32_LE(t.X[1], output, 4);
922
+ MBEDTLS_PUT_UINT32_LE(t.X[2], output, 8);
923
+ MBEDTLS_PUT_UINT32_LE(t.X[3], output, 12);
924
+
925
+ mbedtls_platform_zeroize(&t, sizeof(t));
926
+
927
+ return 0;
928
+ }
929
+
930
+ #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
931
+ /*
932
+ * AES-ECB block decryption
933
+ */
934
+ MBEDTLS_CHECK_RETURN_TYPICAL
935
+ static int mbedtls_internal_aes_decrypt(mbedtls_aes_context *ctx,
936
+ const unsigned char input[16],
937
+ unsigned char output[16])
938
+ {
939
+ int i;
940
+ uint32_t *RK = ctx->buf + ctx->rk_offset;
941
+ struct {
942
+ uint32_t X[4];
943
+ uint32_t Y[4];
944
+ } t;
945
+
946
+ t.X[0] = MBEDTLS_GET_UINT32_LE(input, 0); t.X[0] ^= *RK++;
947
+ t.X[1] = MBEDTLS_GET_UINT32_LE(input, 4); t.X[1] ^= *RK++;
948
+ t.X[2] = MBEDTLS_GET_UINT32_LE(input, 8); t.X[2] ^= *RK++;
949
+ t.X[3] = MBEDTLS_GET_UINT32_LE(input, 12); t.X[3] ^= *RK++;
950
+
951
+ for (i = (ctx->nr >> 1) - 1; i > 0; i--) {
952
+ AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
953
+ AES_RROUND(t.X[0], t.X[1], t.X[2], t.X[3], t.Y[0], t.Y[1], t.Y[2], t.Y[3]);
954
+ }
955
+
956
+ AES_RROUND(t.Y[0], t.Y[1], t.Y[2], t.Y[3], t.X[0], t.X[1], t.X[2], t.X[3]);
957
+
958
+ t.X[0] = *RK++ ^ \
959
+ ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[0])]) ^
960
+ ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[3])] << 8) ^
961
+ ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[2])] << 16) ^
962
+ ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[1])] << 24);
963
+
964
+ t.X[1] = *RK++ ^ \
965
+ ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[1])]) ^
966
+ ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[0])] << 8) ^
967
+ ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[3])] << 16) ^
968
+ ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[2])] << 24);
969
+
970
+ t.X[2] = *RK++ ^ \
971
+ ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[2])]) ^
972
+ ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[1])] << 8) ^
973
+ ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[0])] << 16) ^
974
+ ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[3])] << 24);
975
+
976
+ t.X[3] = *RK++ ^ \
977
+ ((uint32_t) RSb[MBEDTLS_BYTE_0(t.Y[3])]) ^
978
+ ((uint32_t) RSb[MBEDTLS_BYTE_1(t.Y[2])] << 8) ^
979
+ ((uint32_t) RSb[MBEDTLS_BYTE_2(t.Y[1])] << 16) ^
980
+ ((uint32_t) RSb[MBEDTLS_BYTE_3(t.Y[0])] << 24);
981
+
982
+ MBEDTLS_PUT_UINT32_LE(t.X[0], output, 0);
983
+ MBEDTLS_PUT_UINT32_LE(t.X[1], output, 4);
984
+ MBEDTLS_PUT_UINT32_LE(t.X[2], output, 8);
985
+ MBEDTLS_PUT_UINT32_LE(t.X[3], output, 12);
986
+
987
+ mbedtls_platform_zeroize(&t, sizeof(t));
988
+
989
+ return 0;
990
+ }
991
+ #endif /* !MBEDTLS_BLOCK_CIPHER_NO_DECRYPT */
992
+ #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
993
+ /*
994
+ * Our intrinsics-based implementation of AESNI requires the round keys to be
995
+ * aligned on a 16-byte boundary. We take care of this before creating them,
996
+ * but the AES context may have moved (this can happen if the library is
997
+ * called from a language with managed memory), and in later calls it might
998
+ * have a different alignment with respect to 16-byte memory. So we may need
999
+ * to realign.
1000
+ */
1001
+ #if defined(MAY_NEED_TO_ALIGN)
1002
+ MBEDTLS_MAYBE_UNUSED static void aes_maybe_realign(mbedtls_aes_context *ctx)
1003
+ {
1004
+ unsigned new_offset = mbedtls_aes_rk_offset(ctx->buf);
1005
+ if (new_offset != ctx->rk_offset) {
1006
+ memmove(ctx->buf + new_offset, // new address
1007
+ ctx->buf + ctx->rk_offset, // current address
1008
+ (ctx->nr + 1) * 16); // number of round keys * bytes per rk
1009
+ ctx->rk_offset = new_offset;
1010
+ }
1011
+ }
1012
+ #endif /* MAY_NEED_TO_ALIGN */
1013
+ /*
1014
+ * AES-ECB block encryption/decryption
1015
+ */
1016
+ int mbedtls_aes_crypt_ecb(mbedtls_aes_context *ctx,
1017
+ int mode,
1018
+ const unsigned char input[16],
1019
+ unsigned char output[16])
1020
+ {
1021
+ if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
1022
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1023
+ }
1024
+
1025
+ #if defined(MAY_NEED_TO_ALIGN)
1026
+ aes_maybe_realign(ctx);
1027
+ #endif
1028
+
1029
+ #if defined(MBEDTLS_AESNI_HAVE_CODE)
1030
+ if (mbedtls_aesni_has_support(MBEDTLS_AESNI_AES)) {
1031
+ return mbedtls_aesni_crypt_ecb(ctx, mode, input, output);
1032
+ }
1033
+ #endif
1034
+
1035
+ #if defined(MBEDTLS_AESCE_HAVE_CODE)
1036
+ if (MBEDTLS_AESCE_HAS_SUPPORT()) {
1037
+ return mbedtls_aesce_crypt_ecb(ctx, mode, input, output);
1038
+ }
1039
+ #endif
1040
+
1041
+ #if !defined(MBEDTLS_AES_USE_HARDWARE_ONLY)
1042
+ #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
1043
+ if (mode == MBEDTLS_AES_DECRYPT) {
1044
+ return mbedtls_internal_aes_decrypt(ctx, input, output);
1045
+ } else
1046
+ #endif
1047
+ {
1048
+ return mbedtls_internal_aes_encrypt(ctx, input, output);
1049
+ }
1050
+ #endif /* !MBEDTLS_AES_USE_HARDWARE_ONLY */
1051
+ }
1052
+
1053
+ #if defined(MBEDTLS_CIPHER_MODE_CBC)
1054
+
1055
+ /*
1056
+ * AES-CBC buffer encryption/decryption
1057
+ */
1058
+ int mbedtls_aes_crypt_cbc(mbedtls_aes_context *ctx,
1059
+ int mode,
1060
+ size_t length,
1061
+ unsigned char iv[16],
1062
+ const unsigned char *input,
1063
+ unsigned char *output)
1064
+ {
1065
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
1066
+ unsigned char temp[16];
1067
+
1068
+ if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
1069
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1070
+ }
1071
+
1072
+ /* Nothing to do if length is zero. */
1073
+ if (length == 0) {
1074
+ return 0;
1075
+ }
1076
+
1077
+ if (length % 16) {
1078
+ return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH;
1079
+ }
1080
+
1081
+ const unsigned char *ivp = iv;
1082
+
1083
+ if (mode == MBEDTLS_AES_DECRYPT) {
1084
+ while (length > 0) {
1085
+ memcpy(temp, input, 16);
1086
+ ret = mbedtls_aes_crypt_ecb(ctx, mode, input, output);
1087
+ if (ret != 0) {
1088
+ goto exit;
1089
+ }
1090
+ /* Avoid using the NEON implementation of mbedtls_xor. Because of the dependency on
1091
+ * the result for the next block in CBC, and the cost of transferring that data from
1092
+ * NEON registers, NEON is slower on aarch64. */
1093
+ mbedtls_xor_no_simd(output, output, iv, 16);
1094
+
1095
+ memcpy(iv, temp, 16);
1096
+
1097
+ input += 16;
1098
+ output += 16;
1099
+ length -= 16;
1100
+ }
1101
+ } else {
1102
+ while (length > 0) {
1103
+ mbedtls_xor_no_simd(output, input, ivp, 16);
1104
+
1105
+ ret = mbedtls_aes_crypt_ecb(ctx, mode, output, output);
1106
+ if (ret != 0) {
1107
+ goto exit;
1108
+ }
1109
+ ivp = output;
1110
+
1111
+ input += 16;
1112
+ output += 16;
1113
+ length -= 16;
1114
+ }
1115
+ memcpy(iv, ivp, 16);
1116
+ }
1117
+ ret = 0;
1118
+
1119
+ exit:
1120
+ return ret;
1121
+ }
1122
+ #endif /* MBEDTLS_CIPHER_MODE_CBC */
1123
+
1124
+ #if defined(MBEDTLS_CIPHER_MODE_XTS)
1125
+
1126
+ typedef unsigned char mbedtls_be128[16];
1127
+
1128
+ /*
1129
+ * GF(2^128) multiplication function
1130
+ *
1131
+ * This function multiplies a field element by x in the polynomial field
1132
+ * representation. It uses 64-bit word operations to gain speed but compensates
1133
+ * for machine endianness and hence works correctly on both big and little
1134
+ * endian machines.
1135
+ */
1136
+ #if defined(MBEDTLS_AESCE_C) || defined(MBEDTLS_AESNI_C)
1137
+ MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
1138
+ #endif
1139
+ static inline void mbedtls_gf128mul_x_ble(unsigned char r[16],
1140
+ const unsigned char x[16])
1141
+ {
1142
+ uint64_t a, b, ra, rb;
1143
+
1144
+ a = MBEDTLS_GET_UINT64_LE(x, 0);
1145
+ b = MBEDTLS_GET_UINT64_LE(x, 8);
1146
+
1147
+ ra = (a << 1) ^ 0x0087 >> (8 - ((b >> 63) << 3));
1148
+ rb = (a >> 63) | (b << 1);
1149
+
1150
+ MBEDTLS_PUT_UINT64_LE(ra, r, 0);
1151
+ MBEDTLS_PUT_UINT64_LE(rb, r, 8);
1152
+ }
1153
+
1154
+ /*
1155
+ * AES-XTS buffer encryption/decryption
1156
+ *
1157
+ * Use of MBEDTLS_OPTIMIZE_FOR_PERFORMANCE here and for mbedtls_gf128mul_x_ble()
1158
+ * is a 3x performance improvement for gcc -Os, if we have hardware AES support.
1159
+ */
1160
+ #if defined(MBEDTLS_AESCE_C) || defined(MBEDTLS_AESNI_C)
1161
+ MBEDTLS_OPTIMIZE_FOR_PERFORMANCE
1162
+ #endif
1163
+ int mbedtls_aes_crypt_xts(mbedtls_aes_xts_context *ctx,
1164
+ int mode,
1165
+ size_t length,
1166
+ const unsigned char data_unit[16],
1167
+ const unsigned char *input,
1168
+ unsigned char *output)
1169
+ {
1170
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
1171
+ size_t blocks = length / 16;
1172
+ size_t leftover = length % 16;
1173
+ unsigned char tweak[16];
1174
+ unsigned char prev_tweak[16];
1175
+ unsigned char tmp[16];
1176
+
1177
+ if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
1178
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1179
+ }
1180
+
1181
+ /* Data units must be at least 16 bytes long. */
1182
+ if (length < 16) {
1183
+ return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH;
1184
+ }
1185
+
1186
+ /* NIST SP 800-38E disallows data units larger than 2**20 blocks. */
1187
+ if (length > (1 << 20) * 16) {
1188
+ return MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH;
1189
+ }
1190
+
1191
+ /* Compute the tweak. */
1192
+ ret = mbedtls_aes_crypt_ecb(&ctx->tweak, MBEDTLS_AES_ENCRYPT,
1193
+ data_unit, tweak);
1194
+ if (ret != 0) {
1195
+ return ret;
1196
+ }
1197
+
1198
+ while (blocks--) {
1199
+ if (MBEDTLS_UNLIKELY(leftover && (mode == MBEDTLS_AES_DECRYPT) && blocks == 0)) {
1200
+ /* We are on the last block in a decrypt operation that has
1201
+ * leftover bytes, so we need to use the next tweak for this block,
1202
+ * and this tweak for the leftover bytes. Save the current tweak for
1203
+ * the leftovers and then update the current tweak for use on this,
1204
+ * the last full block. */
1205
+ memcpy(prev_tweak, tweak, sizeof(tweak));
1206
+ mbedtls_gf128mul_x_ble(tweak, tweak);
1207
+ }
1208
+
1209
+ mbedtls_xor(tmp, input, tweak, 16);
1210
+
1211
+ ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp);
1212
+ if (ret != 0) {
1213
+ return ret;
1214
+ }
1215
+
1216
+ mbedtls_xor(output, tmp, tweak, 16);
1217
+
1218
+ /* Update the tweak for the next block. */
1219
+ mbedtls_gf128mul_x_ble(tweak, tweak);
1220
+
1221
+ output += 16;
1222
+ input += 16;
1223
+ }
1224
+
1225
+ if (leftover) {
1226
+ /* If we are on the leftover bytes in a decrypt operation, we need to
1227
+ * use the previous tweak for these bytes (as saved in prev_tweak). */
1228
+ unsigned char *t = mode == MBEDTLS_AES_DECRYPT ? prev_tweak : tweak;
1229
+
1230
+ /* We are now on the final part of the data unit, which doesn't divide
1231
+ * evenly by 16. It's time for ciphertext stealing. */
1232
+ size_t i;
1233
+ unsigned char *prev_output = output - 16;
1234
+
1235
+ /* Copy ciphertext bytes from the previous block to our output for each
1236
+ * byte of ciphertext we won't steal. */
1237
+ for (i = 0; i < leftover; i++) {
1238
+ output[i] = prev_output[i];
1239
+ }
1240
+
1241
+ /* Copy the remainder of the input for this final round. */
1242
+ mbedtls_xor(tmp, input, t, leftover);
1243
+
1244
+ /* Copy ciphertext bytes from the previous block for input in this
1245
+ * round. */
1246
+ mbedtls_xor(tmp + i, prev_output + i, t + i, 16 - i);
1247
+
1248
+ ret = mbedtls_aes_crypt_ecb(&ctx->crypt, mode, tmp, tmp);
1249
+ if (ret != 0) {
1250
+ return ret;
1251
+ }
1252
+
1253
+ /* Write the result back to the previous block, overriding the previous
1254
+ * output we copied. */
1255
+ mbedtls_xor(prev_output, tmp, t, 16);
1256
+ }
1257
+
1258
+ return 0;
1259
+ }
1260
+ #endif /* MBEDTLS_CIPHER_MODE_XTS */
1261
+
1262
+ #if defined(MBEDTLS_CIPHER_MODE_CFB)
1263
+ /*
1264
+ * AES-CFB128 buffer encryption/decryption
1265
+ */
1266
+ int mbedtls_aes_crypt_cfb128(mbedtls_aes_context *ctx,
1267
+ int mode,
1268
+ size_t length,
1269
+ size_t *iv_off,
1270
+ unsigned char iv[16],
1271
+ const unsigned char *input,
1272
+ unsigned char *output)
1273
+ {
1274
+ int c;
1275
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
1276
+ size_t n;
1277
+
1278
+ if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
1279
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1280
+ }
1281
+
1282
+ n = *iv_off;
1283
+
1284
+ if (n > 15) {
1285
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1286
+ }
1287
+
1288
+ if (mode == MBEDTLS_AES_DECRYPT) {
1289
+ while (length--) {
1290
+ if (n == 0) {
1291
+ ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
1292
+ if (ret != 0) {
1293
+ goto exit;
1294
+ }
1295
+ }
1296
+
1297
+ c = *input++;
1298
+ *output++ = (unsigned char) (c ^ iv[n]);
1299
+ iv[n] = (unsigned char) c;
1300
+
1301
+ n = (n + 1) & 0x0F;
1302
+ }
1303
+ } else {
1304
+ while (length--) {
1305
+ if (n == 0) {
1306
+ ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
1307
+ if (ret != 0) {
1308
+ goto exit;
1309
+ }
1310
+ }
1311
+
1312
+ iv[n] = *output++ = (unsigned char) (iv[n] ^ *input++);
1313
+
1314
+ n = (n + 1) & 0x0F;
1315
+ }
1316
+ }
1317
+
1318
+ *iv_off = n;
1319
+ ret = 0;
1320
+
1321
+ exit:
1322
+ return ret;
1323
+ }
1324
+
1325
+ /*
1326
+ * AES-CFB8 buffer encryption/decryption
1327
+ */
1328
+ int mbedtls_aes_crypt_cfb8(mbedtls_aes_context *ctx,
1329
+ int mode,
1330
+ size_t length,
1331
+ unsigned char iv[16],
1332
+ const unsigned char *input,
1333
+ unsigned char *output)
1334
+ {
1335
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
1336
+ unsigned char c;
1337
+ unsigned char ov[17];
1338
+
1339
+ if (mode != MBEDTLS_AES_ENCRYPT && mode != MBEDTLS_AES_DECRYPT) {
1340
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1341
+ }
1342
+ while (length--) {
1343
+ memcpy(ov, iv, 16);
1344
+ ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
1345
+ if (ret != 0) {
1346
+ goto exit;
1347
+ }
1348
+
1349
+ if (mode == MBEDTLS_AES_DECRYPT) {
1350
+ ov[16] = *input;
1351
+ }
1352
+
1353
+ c = *output++ = (unsigned char) (iv[0] ^ *input++);
1354
+
1355
+ if (mode == MBEDTLS_AES_ENCRYPT) {
1356
+ ov[16] = c;
1357
+ }
1358
+
1359
+ memcpy(iv, ov + 1, 16);
1360
+ }
1361
+ ret = 0;
1362
+
1363
+ exit:
1364
+ return ret;
1365
+ }
1366
+ #endif /* MBEDTLS_CIPHER_MODE_CFB */
1367
+
1368
+ #if defined(MBEDTLS_CIPHER_MODE_OFB)
1369
+ /*
1370
+ * AES-OFB (Output Feedback Mode) buffer encryption/decryption
1371
+ */
1372
+ int mbedtls_aes_crypt_ofb(mbedtls_aes_context *ctx,
1373
+ size_t length,
1374
+ size_t *iv_off,
1375
+ unsigned char iv[16],
1376
+ const unsigned char *input,
1377
+ unsigned char *output)
1378
+ {
1379
+ int ret = 0;
1380
+ size_t n;
1381
+
1382
+ n = *iv_off;
1383
+
1384
+ if (n > 15) {
1385
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1386
+ }
1387
+
1388
+ while (length--) {
1389
+ if (n == 0) {
1390
+ ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, iv, iv);
1391
+ if (ret != 0) {
1392
+ goto exit;
1393
+ }
1394
+ }
1395
+ *output++ = *input++ ^ iv[n];
1396
+
1397
+ n = (n + 1) & 0x0F;
1398
+ }
1399
+
1400
+ *iv_off = n;
1401
+
1402
+ exit:
1403
+ return ret;
1404
+ }
1405
+ #endif /* MBEDTLS_CIPHER_MODE_OFB */
1406
+
1407
+ #if defined(MBEDTLS_CIPHER_MODE_CTR)
1408
+ /*
1409
+ * AES-CTR buffer encryption/decryption
1410
+ */
1411
+ int mbedtls_aes_crypt_ctr(mbedtls_aes_context *ctx,
1412
+ size_t length,
1413
+ size_t *nc_off,
1414
+ unsigned char nonce_counter[16],
1415
+ unsigned char stream_block[16],
1416
+ const unsigned char *input,
1417
+ unsigned char *output)
1418
+ {
1419
+ int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
1420
+
1421
+ size_t offset = *nc_off;
1422
+
1423
+ if (offset > 0x0F) {
1424
+ return MBEDTLS_ERR_AES_BAD_INPUT_DATA;
1425
+ }
1426
+
1427
+ for (size_t i = 0; i < length;) {
1428
+ size_t n = 16;
1429
+ if (offset == 0) {
1430
+ ret = mbedtls_aes_crypt_ecb(ctx, MBEDTLS_AES_ENCRYPT, nonce_counter, stream_block);
1431
+ if (ret != 0) {
1432
+ goto exit;
1433
+ }
1434
+ mbedtls_ctr_increment_counter(nonce_counter);
1435
+ } else {
1436
+ n -= offset;
1437
+ }
1438
+
1439
+ if (n > (length - i)) {
1440
+ n = (length - i);
1441
+ }
1442
+ mbedtls_xor(&output[i], &input[i], &stream_block[offset], n);
1443
+ // offset might be non-zero for the last block, but in that case, we don't use it again
1444
+ offset = 0;
1445
+ i += n;
1446
+ }
1447
+
1448
+ // capture offset for future resumption
1449
+ *nc_off = (*nc_off + length) % 16;
1450
+
1451
+ ret = 0;
1452
+
1453
+ exit:
1454
+ return ret;
1455
+ }
1456
+ #endif /* MBEDTLS_CIPHER_MODE_CTR */
1457
+
1458
+ #if defined(MBEDTLS_SELF_TEST)
1459
+ /*
1460
+ * AES test vectors from:
1461
+ *
1462
+ * http://csrc.nist.gov/archive/aes/rijndael/rijndael-vals.zip
1463
+ */
1464
+ #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
1465
+ static const unsigned char aes_test_ecb_dec[][16] =
1466
+ {
1467
+ { 0x44, 0x41, 0x6A, 0xC2, 0xD1, 0xF5, 0x3C, 0x58,
1468
+ 0x33, 0x03, 0x91, 0x7E, 0x6B, 0xE9, 0xEB, 0xE0 },
1469
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1470
+ { 0x48, 0xE3, 0x1E, 0x9E, 0x25, 0x67, 0x18, 0xF2,
1471
+ 0x92, 0x29, 0x31, 0x9C, 0x19, 0xF1, 0x5B, 0xA4 },
1472
+ { 0x05, 0x8C, 0xCF, 0xFD, 0xBB, 0xCB, 0x38, 0x2D,
1473
+ 0x1F, 0x6F, 0x56, 0x58, 0x5D, 0x8A, 0x4A, 0xDE }
1474
+ #endif
1475
+ };
1476
+ #endif
1477
+
1478
+ static const unsigned char aes_test_ecb_enc[][16] =
1479
+ {
1480
+ { 0xC3, 0x4C, 0x05, 0x2C, 0xC0, 0xDA, 0x8D, 0x73,
1481
+ 0x45, 0x1A, 0xFE, 0x5F, 0x03, 0xBE, 0x29, 0x7F },
1482
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1483
+ { 0xF3, 0xF6, 0x75, 0x2A, 0xE8, 0xD7, 0x83, 0x11,
1484
+ 0x38, 0xF0, 0x41, 0x56, 0x06, 0x31, 0xB1, 0x14 },
1485
+ { 0x8B, 0x79, 0xEE, 0xCC, 0x93, 0xA0, 0xEE, 0x5D,
1486
+ 0xFF, 0x30, 0xB4, 0xEA, 0x21, 0x63, 0x6D, 0xA4 }
1487
+ #endif
1488
+ };
1489
+
1490
+ #if defined(MBEDTLS_CIPHER_MODE_CBC)
1491
+ static const unsigned char aes_test_cbc_dec[][16] =
1492
+ {
1493
+ { 0xFA, 0xCA, 0x37, 0xE0, 0xB0, 0xC8, 0x53, 0x73,
1494
+ 0xDF, 0x70, 0x6E, 0x73, 0xF7, 0xC9, 0xAF, 0x86 },
1495
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1496
+ { 0x5D, 0xF6, 0x78, 0xDD, 0x17, 0xBA, 0x4E, 0x75,
1497
+ 0xB6, 0x17, 0x68, 0xC6, 0xAD, 0xEF, 0x7C, 0x7B },
1498
+ { 0x48, 0x04, 0xE1, 0x81, 0x8F, 0xE6, 0x29, 0x75,
1499
+ 0x19, 0xA3, 0xE8, 0x8C, 0x57, 0x31, 0x04, 0x13 }
1500
+ #endif
1501
+ };
1502
+
1503
+ static const unsigned char aes_test_cbc_enc[][16] =
1504
+ {
1505
+ { 0x8A, 0x05, 0xFC, 0x5E, 0x09, 0x5A, 0xF4, 0x84,
1506
+ 0x8A, 0x08, 0xD3, 0x28, 0xD3, 0x68, 0x8E, 0x3D },
1507
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1508
+ { 0x7B, 0xD9, 0x66, 0xD5, 0x3A, 0xD8, 0xC1, 0xBB,
1509
+ 0x85, 0xD2, 0xAD, 0xFA, 0xE8, 0x7B, 0xB1, 0x04 },
1510
+ { 0xFE, 0x3C, 0x53, 0x65, 0x3E, 0x2F, 0x45, 0xB5,
1511
+ 0x6F, 0xCD, 0x88, 0xB2, 0xCC, 0x89, 0x8F, 0xF0 }
1512
+ #endif
1513
+ };
1514
+ #endif /* MBEDTLS_CIPHER_MODE_CBC */
1515
+
1516
+ #if defined(MBEDTLS_CIPHER_MODE_CFB)
1517
+ /*
1518
+ * AES-CFB128 test vectors from:
1519
+ *
1520
+ * http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf
1521
+ */
1522
+ static const unsigned char aes_test_cfb128_key[][32] =
1523
+ {
1524
+ { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
1525
+ 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
1526
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1527
+ { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
1528
+ 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
1529
+ 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
1530
+ { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
1531
+ 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
1532
+ 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
1533
+ 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
1534
+ #endif
1535
+ };
1536
+
1537
+ static const unsigned char aes_test_cfb128_iv[16] =
1538
+ {
1539
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1540
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
1541
+ };
1542
+
1543
+ static const unsigned char aes_test_cfb128_pt[64] =
1544
+ {
1545
+ 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
1546
+ 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
1547
+ 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
1548
+ 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
1549
+ 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
1550
+ 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
1551
+ 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
1552
+ 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
1553
+ };
1554
+
1555
+ static const unsigned char aes_test_cfb128_ct[][64] =
1556
+ {
1557
+ { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
1558
+ 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
1559
+ 0xC8, 0xA6, 0x45, 0x37, 0xA0, 0xB3, 0xA9, 0x3F,
1560
+ 0xCD, 0xE3, 0xCD, 0xAD, 0x9F, 0x1C, 0xE5, 0x8B,
1561
+ 0x26, 0x75, 0x1F, 0x67, 0xA3, 0xCB, 0xB1, 0x40,
1562
+ 0xB1, 0x80, 0x8C, 0xF1, 0x87, 0xA4, 0xF4, 0xDF,
1563
+ 0xC0, 0x4B, 0x05, 0x35, 0x7C, 0x5D, 0x1C, 0x0E,
1564
+ 0xEA, 0xC4, 0xC6, 0x6F, 0x9F, 0xF7, 0xF2, 0xE6 },
1565
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1566
+ { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
1567
+ 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
1568
+ 0x67, 0xCE, 0x7F, 0x7F, 0x81, 0x17, 0x36, 0x21,
1569
+ 0x96, 0x1A, 0x2B, 0x70, 0x17, 0x1D, 0x3D, 0x7A,
1570
+ 0x2E, 0x1E, 0x8A, 0x1D, 0xD5, 0x9B, 0x88, 0xB1,
1571
+ 0xC8, 0xE6, 0x0F, 0xED, 0x1E, 0xFA, 0xC4, 0xC9,
1572
+ 0xC0, 0x5F, 0x9F, 0x9C, 0xA9, 0x83, 0x4F, 0xA0,
1573
+ 0x42, 0xAE, 0x8F, 0xBA, 0x58, 0x4B, 0x09, 0xFF },
1574
+ { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
1575
+ 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
1576
+ 0x39, 0xFF, 0xED, 0x14, 0x3B, 0x28, 0xB1, 0xC8,
1577
+ 0x32, 0x11, 0x3C, 0x63, 0x31, 0xE5, 0x40, 0x7B,
1578
+ 0xDF, 0x10, 0x13, 0x24, 0x15, 0xE5, 0x4B, 0x92,
1579
+ 0xA1, 0x3E, 0xD0, 0xA8, 0x26, 0x7A, 0xE2, 0xF9,
1580
+ 0x75, 0xA3, 0x85, 0x74, 0x1A, 0xB9, 0xCE, 0xF8,
1581
+ 0x20, 0x31, 0x62, 0x3D, 0x55, 0xB1, 0xE4, 0x71 }
1582
+ #endif
1583
+ };
1584
+ #endif /* MBEDTLS_CIPHER_MODE_CFB */
1585
+
1586
+ #if defined(MBEDTLS_CIPHER_MODE_OFB)
1587
+ /*
1588
+ * AES-OFB test vectors from:
1589
+ *
1590
+ * https://csrc.nist.gov/publications/detail/sp/800-38a/final
1591
+ */
1592
+ static const unsigned char aes_test_ofb_key[][32] =
1593
+ {
1594
+ { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
1595
+ 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C },
1596
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1597
+ { 0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
1598
+ 0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
1599
+ 0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B },
1600
+ { 0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
1601
+ 0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
1602
+ 0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
1603
+ 0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4 }
1604
+ #endif
1605
+ };
1606
+
1607
+ static const unsigned char aes_test_ofb_iv[16] =
1608
+ {
1609
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1610
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F
1611
+ };
1612
+
1613
+ static const unsigned char aes_test_ofb_pt[64] =
1614
+ {
1615
+ 0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
1616
+ 0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
1617
+ 0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
1618
+ 0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
1619
+ 0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
1620
+ 0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
1621
+ 0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
1622
+ 0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10
1623
+ };
1624
+
1625
+ static const unsigned char aes_test_ofb_ct[][64] =
1626
+ {
1627
+ { 0x3B, 0x3F, 0xD9, 0x2E, 0xB7, 0x2D, 0xAD, 0x20,
1628
+ 0x33, 0x34, 0x49, 0xF8, 0xE8, 0x3C, 0xFB, 0x4A,
1629
+ 0x77, 0x89, 0x50, 0x8d, 0x16, 0x91, 0x8f, 0x03,
1630
+ 0xf5, 0x3c, 0x52, 0xda, 0xc5, 0x4e, 0xd8, 0x25,
1631
+ 0x97, 0x40, 0x05, 0x1e, 0x9c, 0x5f, 0xec, 0xf6,
1632
+ 0x43, 0x44, 0xf7, 0xa8, 0x22, 0x60, 0xed, 0xcc,
1633
+ 0x30, 0x4c, 0x65, 0x28, 0xf6, 0x59, 0xc7, 0x78,
1634
+ 0x66, 0xa5, 0x10, 0xd9, 0xc1, 0xd6, 0xae, 0x5e },
1635
+ #if !defined(MBEDTLS_AES_ONLY_128_BIT_KEY_LENGTH)
1636
+ { 0xCD, 0xC8, 0x0D, 0x6F, 0xDD, 0xF1, 0x8C, 0xAB,
1637
+ 0x34, 0xC2, 0x59, 0x09, 0xC9, 0x9A, 0x41, 0x74,
1638
+ 0xfc, 0xc2, 0x8b, 0x8d, 0x4c, 0x63, 0x83, 0x7c,
1639
+ 0x09, 0xe8, 0x17, 0x00, 0xc1, 0x10, 0x04, 0x01,
1640
+ 0x8d, 0x9a, 0x9a, 0xea, 0xc0, 0xf6, 0x59, 0x6f,
1641
+ 0x55, 0x9c, 0x6d, 0x4d, 0xaf, 0x59, 0xa5, 0xf2,
1642
+ 0x6d, 0x9f, 0x20, 0x08, 0x57, 0xca, 0x6c, 0x3e,
1643
+ 0x9c, 0xac, 0x52, 0x4b, 0xd9, 0xac, 0xc9, 0x2a },
1644
+ { 0xDC, 0x7E, 0x84, 0xBF, 0xDA, 0x79, 0x16, 0x4B,
1645
+ 0x7E, 0xCD, 0x84, 0x86, 0x98, 0x5D, 0x38, 0x60,
1646
+ 0x4f, 0xeb, 0xdc, 0x67, 0x40, 0xd2, 0x0b, 0x3a,
1647
+ 0xc8, 0x8f, 0x6a, 0xd8, 0x2a, 0x4f, 0xb0, 0x8d,
1648
+ 0x71, 0xab, 0x47, 0xa0, 0x86, 0xe8, 0x6e, 0xed,
1649
+ 0xf3, 0x9d, 0x1c, 0x5b, 0xba, 0x97, 0xc4, 0x08,
1650
+ 0x01, 0x26, 0x14, 0x1d, 0x67, 0xf3, 0x7b, 0xe8,
1651
+ 0x53, 0x8f, 0x5a, 0x8b, 0xe7, 0x40, 0xe4, 0x84 }
1652
+ #endif
1653
+ };
1654
+ #endif /* MBEDTLS_CIPHER_MODE_OFB */
1655
+
1656
+ #if defined(MBEDTLS_CIPHER_MODE_CTR)
1657
+ /*
1658
+ * AES-CTR test vectors from:
1659
+ *
1660
+ * http://www.faqs.org/rfcs/rfc3686.html
1661
+ */
1662
+
1663
+ static const unsigned char aes_test_ctr_key[][16] =
1664
+ {
1665
+ { 0xAE, 0x68, 0x52, 0xF8, 0x12, 0x10, 0x67, 0xCC,
1666
+ 0x4B, 0xF7, 0xA5, 0x76, 0x55, 0x77, 0xF3, 0x9E },
1667
+ { 0x7E, 0x24, 0x06, 0x78, 0x17, 0xFA, 0xE0, 0xD7,
1668
+ 0x43, 0xD6, 0xCE, 0x1F, 0x32, 0x53, 0x91, 0x63 },
1669
+ { 0x76, 0x91, 0xBE, 0x03, 0x5E, 0x50, 0x20, 0xA8,
1670
+ 0xAC, 0x6E, 0x61, 0x85, 0x29, 0xF9, 0xA0, 0xDC }
1671
+ };
1672
+
1673
+ static const unsigned char aes_test_ctr_nonce_counter[][16] =
1674
+ {
1675
+ { 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00,
1676
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 },
1677
+ { 0x00, 0x6C, 0xB6, 0xDB, 0xC0, 0x54, 0x3B, 0x59,
1678
+ 0xDA, 0x48, 0xD9, 0x0B, 0x00, 0x00, 0x00, 0x01 },
1679
+ { 0x00, 0xE0, 0x01, 0x7B, 0x27, 0x77, 0x7F, 0x3F,
1680
+ 0x4A, 0x17, 0x86, 0xF0, 0x00, 0x00, 0x00, 0x01 }
1681
+ };
1682
+
1683
+ static const unsigned char aes_test_ctr_pt[][48] =
1684
+ {
1685
+ { 0x53, 0x69, 0x6E, 0x67, 0x6C, 0x65, 0x20, 0x62,
1686
+ 0x6C, 0x6F, 0x63, 0x6B, 0x20, 0x6D, 0x73, 0x67 },
1687
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1688
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
1689
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1690
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
1691
+
1692
+ { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
1693
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
1694
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1695
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
1696
+ 0x20, 0x21, 0x22, 0x23 }
1697
+ };
1698
+
1699
+ static const unsigned char aes_test_ctr_ct[][48] =
1700
+ {
1701
+ { 0xE4, 0x09, 0x5D, 0x4F, 0xB7, 0xA7, 0xB3, 0x79,
1702
+ 0x2D, 0x61, 0x75, 0xA3, 0x26, 0x13, 0x11, 0xB8 },
1703
+ { 0x51, 0x04, 0xA1, 0x06, 0x16, 0x8A, 0x72, 0xD9,
1704
+ 0x79, 0x0D, 0x41, 0xEE, 0x8E, 0xDA, 0xD3, 0x88,
1705
+ 0xEB, 0x2E, 0x1E, 0xFC, 0x46, 0xDA, 0x57, 0xC8,
1706
+ 0xFC, 0xE6, 0x30, 0xDF, 0x91, 0x41, 0xBE, 0x28 },
1707
+ { 0xC1, 0xCF, 0x48, 0xA8, 0x9F, 0x2F, 0xFD, 0xD9,
1708
+ 0xCF, 0x46, 0x52, 0xE9, 0xEF, 0xDB, 0x72, 0xD7,
1709
+ 0x45, 0x40, 0xA4, 0x2B, 0xDE, 0x6D, 0x78, 0x36,
1710
+ 0xD5, 0x9A, 0x5C, 0xEA, 0xAE, 0xF3, 0x10, 0x53,
1711
+ 0x25, 0xB2, 0x07, 0x2F }
1712
+ };
1713
+
1714
+ static const int aes_test_ctr_len[3] =
1715
+ { 16, 32, 36 };
1716
+ #endif /* MBEDTLS_CIPHER_MODE_CTR */
1717
+
1718
+ #if defined(MBEDTLS_CIPHER_MODE_XTS)
1719
+ /*
1720
+ * AES-XTS test vectors from:
1721
+ *
1722
+ * IEEE P1619/D16 Annex B
1723
+ * https://web.archive.org/web/20150629024421/http://grouper.ieee.org/groups/1619/email/pdf00086.pdf
1724
+ * (Archived from original at http://grouper.ieee.org/groups/1619/email/pdf00086.pdf)
1725
+ */
1726
+ static const unsigned char aes_test_xts_key[][32] =
1727
+ {
1728
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1729
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1730
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1731
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1732
+ { 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
1733
+ 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
1734
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
1735
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 },
1736
+ { 0xff, 0xfe, 0xfd, 0xfc, 0xfb, 0xfa, 0xf9, 0xf8,
1737
+ 0xf7, 0xf6, 0xf5, 0xf4, 0xf3, 0xf2, 0xf1, 0xf0,
1738
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
1739
+ 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22 },
1740
+ };
1741
+
1742
+ static const unsigned char aes_test_xts_pt32[][32] =
1743
+ {
1744
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1745
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1746
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1747
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1748
+ { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
1749
+ 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
1750
+ 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
1751
+ 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 },
1752
+ { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
1753
+ 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
1754
+ 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44,
1755
+ 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 },
1756
+ };
1757
+
1758
+ static const unsigned char aes_test_xts_ct32[][32] =
1759
+ {
1760
+ { 0x91, 0x7c, 0xf6, 0x9e, 0xbd, 0x68, 0xb2, 0xec,
1761
+ 0x9b, 0x9f, 0xe9, 0xa3, 0xea, 0xdd, 0xa6, 0x92,
1762
+ 0xcd, 0x43, 0xd2, 0xf5, 0x95, 0x98, 0xed, 0x85,
1763
+ 0x8c, 0x02, 0xc2, 0x65, 0x2f, 0xbf, 0x92, 0x2e },
1764
+ { 0xc4, 0x54, 0x18, 0x5e, 0x6a, 0x16, 0x93, 0x6e,
1765
+ 0x39, 0x33, 0x40, 0x38, 0xac, 0xef, 0x83, 0x8b,
1766
+ 0xfb, 0x18, 0x6f, 0xff, 0x74, 0x80, 0xad, 0xc4,
1767
+ 0x28, 0x93, 0x82, 0xec, 0xd6, 0xd3, 0x94, 0xf0 },
1768
+ { 0xaf, 0x85, 0x33, 0x6b, 0x59, 0x7a, 0xfc, 0x1a,
1769
+ 0x90, 0x0b, 0x2e, 0xb2, 0x1e, 0xc9, 0x49, 0xd2,
1770
+ 0x92, 0xdf, 0x4c, 0x04, 0x7e, 0x0b, 0x21, 0x53,
1771
+ 0x21, 0x86, 0xa5, 0x97, 0x1a, 0x22, 0x7a, 0x89 },
1772
+ };
1773
+
1774
+ static const unsigned char aes_test_xts_data_unit[][16] =
1775
+ {
1776
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1777
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1778
+ { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00,
1779
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1780
+ { 0x33, 0x33, 0x33, 0x33, 0x33, 0x00, 0x00, 0x00,
1781
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
1782
+ };
1783
+
1784
+ #endif /* MBEDTLS_CIPHER_MODE_XTS */
1785
+
1786
+ /*
1787
+ * Checkup routine
1788
+ */
1789
+ int mbedtls_aes_self_test(int verbose)
1790
+ {
1791
+ int ret = 0, i, j, u, mode;
1792
+ unsigned int keybits;
1793
+ unsigned char key[32];
1794
+ unsigned char buf[64];
1795
+ const unsigned char *aes_tests;
1796
+ #if defined(MBEDTLS_CIPHER_MODE_CBC) || defined(MBEDTLS_CIPHER_MODE_CFB) || \
1797
+ defined(MBEDTLS_CIPHER_MODE_OFB)
1798
+ unsigned char iv[16];
1799
+ #endif
1800
+ #if defined(MBEDTLS_CIPHER_MODE_CBC)
1801
+ unsigned char prv[16];
1802
+ #endif
1803
+ #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_CFB) || \
1804
+ defined(MBEDTLS_CIPHER_MODE_OFB)
1805
+ size_t offset;
1806
+ #endif
1807
+ #if defined(MBEDTLS_CIPHER_MODE_CTR) || defined(MBEDTLS_CIPHER_MODE_XTS)
1808
+ int len;
1809
+ #endif
1810
+ #if defined(MBEDTLS_CIPHER_MODE_CTR)
1811
+ unsigned char nonce_counter[16];
1812
+ unsigned char stream_block[16];
1813
+ #endif
1814
+ mbedtls_aes_context ctx;
1815
+
1816
+ memset(key, 0, 32);
1817
+ mbedtls_aes_init(&ctx);
1818
+
1819
+ if (verbose != 0) {
1820
+ mbedtls_aes_implementation aes_imp = mbedtls_aes_get_implementation();
1821
+ switch (aes_imp) {
1822
+ case MBEDTLS_AES_IMP_AESNI_ASM:
1823
+ mbedtls_printf(" AES note: AESNI code present (assembly implementation).\n");
1824
+ mbedtls_printf(" AES note: using AESNI.\n");
1825
+ break;
1826
+ case MBEDTLS_AES_IMP_AESNI_INTRINSICS:
1827
+ mbedtls_printf(" AES note: AESNI code present (intrinsics implementation).\n");
1828
+ mbedtls_printf(" AES note: using AESNI.\n");
1829
+ break;
1830
+ case MBEDTLS_AES_IMP_AESCE:
1831
+ mbedtls_printf(" AES note: using AESCE.\n");
1832
+ break;
1833
+ case MBEDTLS_AES_IMP_SOFTWARE:
1834
+ mbedtls_printf(" AES note: built-in implementation.\n");
1835
+ break;
1836
+ case MBEDTLS_AES_IMP_UNKNOWN:
1837
+ break;
1838
+ }
1839
+ }
1840
+
1841
+ /*
1842
+ * ECB mode
1843
+ */
1844
+ {
1845
+ static const int num_tests =
1846
+ sizeof(aes_test_ecb_enc) / sizeof(*aes_test_ecb_enc);
1847
+
1848
+ for (i = 0; i < num_tests << 1; i++) {
1849
+ u = i >> 1;
1850
+ keybits = 128 + u * 64;
1851
+ mode = i & 1;
1852
+
1853
+ if (verbose != 0) {
1854
+ mbedtls_printf(" AES-ECB-%3u (%s): ", keybits,
1855
+ (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
1856
+ }
1857
+ #if defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
1858
+ if (mode == MBEDTLS_AES_DECRYPT) {
1859
+ if (verbose != 0) {
1860
+ mbedtls_printf("skipped\n");
1861
+ }
1862
+ continue;
1863
+ }
1864
+ #endif
1865
+
1866
+ memset(buf, 0, 16);
1867
+
1868
+ #if !defined(MBEDTLS_BLOCK_CIPHER_NO_DECRYPT)
1869
+ if (mode == MBEDTLS_AES_DECRYPT) {
1870
+ ret = mbedtls_aes_setkey_dec(&ctx, key, keybits);
1871
+ aes_tests = aes_test_ecb_dec[u];
1872
+ } else
1873
+ #endif
1874
+ {
1875
+ ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
1876
+ aes_tests = aes_test_ecb_enc[u];
1877
+ }
1878
+
1879
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
1880
+ mbedtls_printf("skipped\n");
1881
+ continue;
1882
+ } else if (ret != 0) {
1883
+ goto exit;
1884
+ }
1885
+
1886
+ for (j = 0; j < 10000; j++) {
1887
+ ret = mbedtls_aes_crypt_ecb(&ctx, mode, buf, buf);
1888
+ if (ret != 0) {
1889
+ goto exit;
1890
+ }
1891
+ }
1892
+
1893
+ if (memcmp(buf, aes_tests, 16) != 0) {
1894
+ ret = 1;
1895
+ goto exit;
1896
+ }
1897
+
1898
+ if (verbose != 0) {
1899
+ mbedtls_printf("passed\n");
1900
+ }
1901
+ }
1902
+
1903
+ if (verbose != 0) {
1904
+ mbedtls_printf("\n");
1905
+ }
1906
+ }
1907
+
1908
+ #if defined(MBEDTLS_CIPHER_MODE_CBC)
1909
+ /*
1910
+ * CBC mode
1911
+ */
1912
+ {
1913
+ static const int num_tests =
1914
+ sizeof(aes_test_cbc_dec) / sizeof(*aes_test_cbc_dec);
1915
+
1916
+ for (i = 0; i < num_tests << 1; i++) {
1917
+ u = i >> 1;
1918
+ keybits = 128 + u * 64;
1919
+ mode = i & 1;
1920
+
1921
+ if (verbose != 0) {
1922
+ mbedtls_printf(" AES-CBC-%3u (%s): ", keybits,
1923
+ (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
1924
+ }
1925
+
1926
+ memset(iv, 0, 16);
1927
+ memset(prv, 0, 16);
1928
+ memset(buf, 0, 16);
1929
+
1930
+ if (mode == MBEDTLS_AES_DECRYPT) {
1931
+ ret = mbedtls_aes_setkey_dec(&ctx, key, keybits);
1932
+ aes_tests = aes_test_cbc_dec[u];
1933
+ } else {
1934
+ ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
1935
+ aes_tests = aes_test_cbc_enc[u];
1936
+ }
1937
+
1938
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
1939
+ mbedtls_printf("skipped\n");
1940
+ continue;
1941
+ } else if (ret != 0) {
1942
+ goto exit;
1943
+ }
1944
+
1945
+ for (j = 0; j < 10000; j++) {
1946
+ if (mode == MBEDTLS_AES_ENCRYPT) {
1947
+ unsigned char tmp[16];
1948
+
1949
+ memcpy(tmp, prv, 16);
1950
+ memcpy(prv, buf, 16);
1951
+ memcpy(buf, tmp, 16);
1952
+ }
1953
+
1954
+ ret = mbedtls_aes_crypt_cbc(&ctx, mode, 16, iv, buf, buf);
1955
+ if (ret != 0) {
1956
+ goto exit;
1957
+ }
1958
+
1959
+ }
1960
+
1961
+ if (memcmp(buf, aes_tests, 16) != 0) {
1962
+ ret = 1;
1963
+ goto exit;
1964
+ }
1965
+
1966
+ if (verbose != 0) {
1967
+ mbedtls_printf("passed\n");
1968
+ }
1969
+ }
1970
+
1971
+ if (verbose != 0) {
1972
+ mbedtls_printf("\n");
1973
+ }
1974
+ }
1975
+ #endif /* MBEDTLS_CIPHER_MODE_CBC */
1976
+
1977
+ #if defined(MBEDTLS_CIPHER_MODE_CFB)
1978
+ /*
1979
+ * CFB128 mode
1980
+ */
1981
+ {
1982
+ static const int num_tests =
1983
+ sizeof(aes_test_cfb128_key) / sizeof(*aes_test_cfb128_key);
1984
+
1985
+ for (i = 0; i < num_tests << 1; i++) {
1986
+ u = i >> 1;
1987
+ keybits = 128 + u * 64;
1988
+ mode = i & 1;
1989
+
1990
+ if (verbose != 0) {
1991
+ mbedtls_printf(" AES-CFB128-%3u (%s): ", keybits,
1992
+ (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
1993
+ }
1994
+
1995
+ memcpy(iv, aes_test_cfb128_iv, 16);
1996
+ memcpy(key, aes_test_cfb128_key[u], keybits / 8);
1997
+
1998
+ offset = 0;
1999
+ ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
2000
+
2001
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
2002
+ mbedtls_printf("skipped\n");
2003
+ continue;
2004
+ } else if (ret != 0) {
2005
+ goto exit;
2006
+ }
2007
+
2008
+ if (mode == MBEDTLS_AES_DECRYPT) {
2009
+ memcpy(buf, aes_test_cfb128_ct[u], 64);
2010
+ aes_tests = aes_test_cfb128_pt;
2011
+ } else {
2012
+ memcpy(buf, aes_test_cfb128_pt, 64);
2013
+ aes_tests = aes_test_cfb128_ct[u];
2014
+ }
2015
+
2016
+ ret = mbedtls_aes_crypt_cfb128(&ctx, mode, 64, &offset, iv, buf, buf);
2017
+ if (ret != 0) {
2018
+ goto exit;
2019
+ }
2020
+
2021
+ if (memcmp(buf, aes_tests, 64) != 0) {
2022
+ ret = 1;
2023
+ goto exit;
2024
+ }
2025
+
2026
+ if (verbose != 0) {
2027
+ mbedtls_printf("passed\n");
2028
+ }
2029
+ }
2030
+
2031
+ if (verbose != 0) {
2032
+ mbedtls_printf("\n");
2033
+ }
2034
+ }
2035
+ #endif /* MBEDTLS_CIPHER_MODE_CFB */
2036
+
2037
+ #if defined(MBEDTLS_CIPHER_MODE_OFB)
2038
+ /*
2039
+ * OFB mode
2040
+ */
2041
+ {
2042
+ static const int num_tests =
2043
+ sizeof(aes_test_ofb_key) / sizeof(*aes_test_ofb_key);
2044
+
2045
+ for (i = 0; i < num_tests << 1; i++) {
2046
+ u = i >> 1;
2047
+ keybits = 128 + u * 64;
2048
+ mode = i & 1;
2049
+
2050
+ if (verbose != 0) {
2051
+ mbedtls_printf(" AES-OFB-%3u (%s): ", keybits,
2052
+ (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
2053
+ }
2054
+
2055
+ memcpy(iv, aes_test_ofb_iv, 16);
2056
+ memcpy(key, aes_test_ofb_key[u], keybits / 8);
2057
+
2058
+ offset = 0;
2059
+ ret = mbedtls_aes_setkey_enc(&ctx, key, keybits);
2060
+
2061
+ if (ret == MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED && keybits == 192) {
2062
+ mbedtls_printf("skipped\n");
2063
+ continue;
2064
+ } else if (ret != 0) {
2065
+ goto exit;
2066
+ }
2067
+
2068
+ if (mode == MBEDTLS_AES_DECRYPT) {
2069
+ memcpy(buf, aes_test_ofb_ct[u], 64);
2070
+ aes_tests = aes_test_ofb_pt;
2071
+ } else {
2072
+ memcpy(buf, aes_test_ofb_pt, 64);
2073
+ aes_tests = aes_test_ofb_ct[u];
2074
+ }
2075
+
2076
+ ret = mbedtls_aes_crypt_ofb(&ctx, 64, &offset, iv, buf, buf);
2077
+ if (ret != 0) {
2078
+ goto exit;
2079
+ }
2080
+
2081
+ if (memcmp(buf, aes_tests, 64) != 0) {
2082
+ ret = 1;
2083
+ goto exit;
2084
+ }
2085
+
2086
+ if (verbose != 0) {
2087
+ mbedtls_printf("passed\n");
2088
+ }
2089
+ }
2090
+
2091
+ if (verbose != 0) {
2092
+ mbedtls_printf("\n");
2093
+ }
2094
+ }
2095
+ #endif /* MBEDTLS_CIPHER_MODE_OFB */
2096
+
2097
+ #if defined(MBEDTLS_CIPHER_MODE_CTR)
2098
+ /*
2099
+ * CTR mode
2100
+ */
2101
+ {
2102
+ static const int num_tests =
2103
+ sizeof(aes_test_ctr_key) / sizeof(*aes_test_ctr_key);
2104
+
2105
+ for (i = 0; i < num_tests << 1; i++) {
2106
+ u = i >> 1;
2107
+ mode = i & 1;
2108
+
2109
+ if (verbose != 0) {
2110
+ mbedtls_printf(" AES-CTR-128 (%s): ",
2111
+ (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
2112
+ }
2113
+
2114
+ memcpy(nonce_counter, aes_test_ctr_nonce_counter[u], 16);
2115
+ memcpy(key, aes_test_ctr_key[u], 16);
2116
+
2117
+ offset = 0;
2118
+ if ((ret = mbedtls_aes_setkey_enc(&ctx, key, 128)) != 0) {
2119
+ goto exit;
2120
+ }
2121
+
2122
+ len = aes_test_ctr_len[u];
2123
+
2124
+ if (mode == MBEDTLS_AES_DECRYPT) {
2125
+ memcpy(buf, aes_test_ctr_ct[u], len);
2126
+ aes_tests = aes_test_ctr_pt[u];
2127
+ } else {
2128
+ memcpy(buf, aes_test_ctr_pt[u], len);
2129
+ aes_tests = aes_test_ctr_ct[u];
2130
+ }
2131
+
2132
+ ret = mbedtls_aes_crypt_ctr(&ctx, len, &offset, nonce_counter,
2133
+ stream_block, buf, buf);
2134
+ if (ret != 0) {
2135
+ goto exit;
2136
+ }
2137
+
2138
+ if (memcmp(buf, aes_tests, len) != 0) {
2139
+ ret = 1;
2140
+ goto exit;
2141
+ }
2142
+
2143
+ if (verbose != 0) {
2144
+ mbedtls_printf("passed\n");
2145
+ }
2146
+ }
2147
+ }
2148
+
2149
+ if (verbose != 0) {
2150
+ mbedtls_printf("\n");
2151
+ }
2152
+ #endif /* MBEDTLS_CIPHER_MODE_CTR */
2153
+
2154
+ #if defined(MBEDTLS_CIPHER_MODE_XTS)
2155
+ /*
2156
+ * XTS mode
2157
+ */
2158
+ {
2159
+ static const int num_tests =
2160
+ sizeof(aes_test_xts_key) / sizeof(*aes_test_xts_key);
2161
+ mbedtls_aes_xts_context ctx_xts;
2162
+
2163
+ mbedtls_aes_xts_init(&ctx_xts);
2164
+
2165
+ for (i = 0; i < num_tests << 1; i++) {
2166
+ const unsigned char *data_unit;
2167
+ u = i >> 1;
2168
+ mode = i & 1;
2169
+
2170
+ if (verbose != 0) {
2171
+ mbedtls_printf(" AES-XTS-128 (%s): ",
2172
+ (mode == MBEDTLS_AES_DECRYPT) ? "dec" : "enc");
2173
+ }
2174
+
2175
+ memset(key, 0, sizeof(key));
2176
+ memcpy(key, aes_test_xts_key[u], 32);
2177
+ data_unit = aes_test_xts_data_unit[u];
2178
+
2179
+ len = sizeof(*aes_test_xts_ct32);
2180
+
2181
+ if (mode == MBEDTLS_AES_DECRYPT) {
2182
+ ret = mbedtls_aes_xts_setkey_dec(&ctx_xts, key, 256);
2183
+ if (ret != 0) {
2184
+ goto exit;
2185
+ }
2186
+ memcpy(buf, aes_test_xts_ct32[u], len);
2187
+ aes_tests = aes_test_xts_pt32[u];
2188
+ } else {
2189
+ ret = mbedtls_aes_xts_setkey_enc(&ctx_xts, key, 256);
2190
+ if (ret != 0) {
2191
+ goto exit;
2192
+ }
2193
+ memcpy(buf, aes_test_xts_pt32[u], len);
2194
+ aes_tests = aes_test_xts_ct32[u];
2195
+ }
2196
+
2197
+
2198
+ ret = mbedtls_aes_crypt_xts(&ctx_xts, mode, len, data_unit,
2199
+ buf, buf);
2200
+ if (ret != 0) {
2201
+ goto exit;
2202
+ }
2203
+
2204
+ if (memcmp(buf, aes_tests, len) != 0) {
2205
+ ret = 1;
2206
+ goto exit;
2207
+ }
2208
+
2209
+ if (verbose != 0) {
2210
+ mbedtls_printf("passed\n");
2211
+ }
2212
+ }
2213
+
2214
+ if (verbose != 0) {
2215
+ mbedtls_printf("\n");
2216
+ }
2217
+
2218
+ mbedtls_aes_xts_free(&ctx_xts);
2219
+ }
2220
+ #endif /* MBEDTLS_CIPHER_MODE_XTS */
2221
+
2222
+ ret = 0;
2223
+
2224
+ exit:
2225
+ if (ret != 0 && verbose != 0) {
2226
+ mbedtls_printf("failed\n");
2227
+ }
2228
+
2229
+ mbedtls_aes_free(&ctx);
2230
+
2231
+ return ret;
2232
+ }
2233
+
2234
+ #endif /* MBEDTLS_SELF_TEST */
2235
+
2236
+ #endif /* MBEDTLS_AES_C */