@scriptc/runtime 0.0.0 → 0.0.2

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 (416) hide show
  1. package/LICENSE +202 -0
  2. package/package.json +16 -6
  3. package/src/scr_array.c +488 -0
  4. package/src/scr_assert.c +1393 -0
  5. package/src/scr_async.c +2593 -0
  6. package/src/scr_async_dyn.c +607 -0
  7. package/src/scr_bytes.c +1425 -0
  8. package/src/scr_bytes_io.c +161 -0
  9. package/src/scr_child.c +3587 -0
  10. package/src/scr_closure.c +214 -0
  11. package/src/scr_console.c +143 -0
  12. package/src/scr_cycle.c +218 -0
  13. package/src/scr_dc.c +805 -0
  14. package/src/scr_dgram.c +1007 -0
  15. package/src/scr_dyn_handle.c +154 -0
  16. package/src/scr_dyn_invoke.c +644 -0
  17. package/src/scr_error.c +332 -0
  18. package/src/scr_events.c +714 -0
  19. package/src/scr_events_emitter.c +699 -0
  20. package/src/scr_exception.c +242 -0
  21. package/src/scr_fetch.c +1130 -0
  22. package/src/scr_fetch_curl.c +654 -0
  23. package/src/scr_http.c +3482 -0
  24. package/src/scr_http2.c +3030 -0
  25. package/src/scr_inspect.c +803 -0
  26. package/src/scr_inspect_island.c +51 -0
  27. package/src/scr_island.c +9363 -0
  28. package/src/scr_json.c +2151 -0
  29. package/src/scr_lib.c +3612 -0
  30. package/src/scr_loop_epoll.c +241 -0
  31. package/src/scr_loop_kqueue.c +121 -0
  32. package/src/scr_loop_wsapoll.c +208 -0
  33. package/src/scr_map.c +591 -0
  34. package/src/scr_net.c +3017 -0
  35. package/src/scr_net_island.c +458 -0
  36. package/src/scr_number.c +115 -0
  37. package/src/scr_object.c +25 -0
  38. package/src/scr_path.c +1266 -0
  39. package/src/scr_platform.h +119 -0
  40. package/src/scr_readline.c +287 -0
  41. package/src/scr_regex.c +1080 -0
  42. package/src/scr_runtime.h +5046 -0
  43. package/src/scr_stream.c +2877 -0
  44. package/src/scr_string.c +1264 -0
  45. package/src/scr_symbol.c +132 -0
  46. package/src/scr_test.c +662 -0
  47. package/src/scr_tls.c +1520 -0
  48. package/src/scr_union.c +105 -0
  49. package/src/scr_url.c +911 -0
  50. package/src/scr_url_internal.h +29 -0
  51. package/src/scr_url_params.c +561 -0
  52. package/src/scr_watch.c +568 -0
  53. package/src/scr_web.c +1778 -0
  54. package/src/scr_win.c +76 -0
  55. package/src/scr_zlib.c +197 -0
  56. package/src/scr_zlib_island.c +15 -0
  57. package/vendor/README.md +52 -0
  58. package/vendor/curl/COPYRIGHT +534 -0
  59. package/vendor/curl/include/curl/curl.h +3214 -0
  60. package/vendor/curl/include/curl/curlver.h +79 -0
  61. package/vendor/curl/include/curl/easy.h +125 -0
  62. package/vendor/curl/include/curl/header.h +74 -0
  63. package/vendor/curl/include/curl/mprintf.h +52 -0
  64. package/vendor/curl/include/curl/multi.h +460 -0
  65. package/vendor/curl/include/curl/options.h +70 -0
  66. package/vendor/curl/include/curl/stdcheaders.h +35 -0
  67. package/vendor/curl/include/curl/system.h +508 -0
  68. package/vendor/curl/include/curl/typecheck-gcc.h +716 -0
  69. package/vendor/curl/include/curl/urlapi.h +149 -0
  70. package/vendor/curl/include/curl/websockets.h +84 -0
  71. package/vendor/mbedtls/LICENSE +553 -0
  72. package/vendor/mbedtls/include/CMakeLists.txt +22 -0
  73. package/vendor/mbedtls/include/mbedtls/aes.h +631 -0
  74. package/vendor/mbedtls/include/mbedtls/aria.h +343 -0
  75. package/vendor/mbedtls/include/mbedtls/asn1.h +642 -0
  76. package/vendor/mbedtls/include/mbedtls/asn1write.h +390 -0
  77. package/vendor/mbedtls/include/mbedtls/base64.h +82 -0
  78. package/vendor/mbedtls/include/mbedtls/bignum.h +1088 -0
  79. package/vendor/mbedtls/include/mbedtls/block_cipher.h +76 -0
  80. package/vendor/mbedtls/include/mbedtls/build_info.h +194 -0
  81. package/vendor/mbedtls/include/mbedtls/camellia.h +305 -0
  82. package/vendor/mbedtls/include/mbedtls/ccm.h +526 -0
  83. package/vendor/mbedtls/include/mbedtls/chacha20.h +209 -0
  84. package/vendor/mbedtls/include/mbedtls/chachapoly.h +351 -0
  85. package/vendor/mbedtls/include/mbedtls/check_config.h +1149 -0
  86. package/vendor/mbedtls/include/mbedtls/cipher.h +1250 -0
  87. package/vendor/mbedtls/include/mbedtls/cmac.h +246 -0
  88. package/vendor/mbedtls/include/mbedtls/compat-2.x.h +46 -0
  89. package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_crypto.h +578 -0
  90. package/vendor/mbedtls/include/mbedtls/config_adjust_legacy_from_psa.h +873 -0
  91. package/vendor/mbedtls/include/mbedtls/config_adjust_psa_from_legacy.h +359 -0
  92. package/vendor/mbedtls/include/mbedtls/config_adjust_psa_superset_legacy.h +145 -0
  93. package/vendor/mbedtls/include/mbedtls/config_adjust_ssl.h +91 -0
  94. package/vendor/mbedtls/include/mbedtls/config_adjust_x509.h +35 -0
  95. package/vendor/mbedtls/include/mbedtls/config_psa.h +61 -0
  96. package/vendor/mbedtls/include/mbedtls/constant_time.h +36 -0
  97. package/vendor/mbedtls/include/mbedtls/ctr_drbg.h +596 -0
  98. package/vendor/mbedtls/include/mbedtls/debug.h +156 -0
  99. package/vendor/mbedtls/include/mbedtls/des.h +385 -0
  100. package/vendor/mbedtls/include/mbedtls/dhm.h +972 -0
  101. package/vendor/mbedtls/include/mbedtls/ecdh.h +455 -0
  102. package/vendor/mbedtls/include/mbedtls/ecdsa.h +674 -0
  103. package/vendor/mbedtls/include/mbedtls/ecjpake.h +298 -0
  104. package/vendor/mbedtls/include/mbedtls/ecp.h +1517 -0
  105. package/vendor/mbedtls/include/mbedtls/entropy.h +274 -0
  106. package/vendor/mbedtls/include/mbedtls/error.h +201 -0
  107. package/vendor/mbedtls/include/mbedtls/gcm.h +387 -0
  108. package/vendor/mbedtls/include/mbedtls/hkdf.h +124 -0
  109. package/vendor/mbedtls/include/mbedtls/hmac_drbg.h +434 -0
  110. package/vendor/mbedtls/include/mbedtls/lms.h +440 -0
  111. package/vendor/mbedtls/include/mbedtls/mbedtls_config.h +4446 -0
  112. package/vendor/mbedtls/include/mbedtls/md.h +526 -0
  113. package/vendor/mbedtls/include/mbedtls/md5.h +190 -0
  114. package/vendor/mbedtls/include/mbedtls/memory_buffer_alloc.h +142 -0
  115. package/vendor/mbedtls/include/mbedtls/net_sockets.h +299 -0
  116. package/vendor/mbedtls/include/mbedtls/nist_kw.h +166 -0
  117. package/vendor/mbedtls/include/mbedtls/oid.h +727 -0
  118. package/vendor/mbedtls/include/mbedtls/pem.h +160 -0
  119. package/vendor/mbedtls/include/mbedtls/pk.h +1303 -0
  120. package/vendor/mbedtls/include/mbedtls/pkcs12.h +186 -0
  121. package/vendor/mbedtls/include/mbedtls/pkcs5.h +198 -0
  122. package/vendor/mbedtls/include/mbedtls/pkcs7.h +252 -0
  123. package/vendor/mbedtls/include/mbedtls/platform.h +516 -0
  124. package/vendor/mbedtls/include/mbedtls/platform_time.h +79 -0
  125. package/vendor/mbedtls/include/mbedtls/platform_util.h +247 -0
  126. package/vendor/mbedtls/include/mbedtls/poly1305.h +168 -0
  127. package/vendor/mbedtls/include/mbedtls/private_access.h +20 -0
  128. package/vendor/mbedtls/include/mbedtls/psa_util.h +207 -0
  129. package/vendor/mbedtls/include/mbedtls/ripemd160.h +136 -0
  130. package/vendor/mbedtls/include/mbedtls/rsa.h +1170 -0
  131. package/vendor/mbedtls/include/mbedtls/sha1.h +219 -0
  132. package/vendor/mbedtls/include/mbedtls/sha256.h +200 -0
  133. package/vendor/mbedtls/include/mbedtls/sha3.h +172 -0
  134. package/vendor/mbedtls/include/mbedtls/sha512.h +208 -0
  135. package/vendor/mbedtls/include/mbedtls/ssl.h +5887 -0
  136. package/vendor/mbedtls/include/mbedtls/ssl_cache.h +187 -0
  137. package/vendor/mbedtls/include/mbedtls/ssl_ciphersuites.h +482 -0
  138. package/vendor/mbedtls/include/mbedtls/ssl_cookie.h +106 -0
  139. package/vendor/mbedtls/include/mbedtls/ssl_ticket.h +199 -0
  140. package/vendor/mbedtls/include/mbedtls/threading.h +167 -0
  141. package/vendor/mbedtls/include/mbedtls/timing.h +94 -0
  142. package/vendor/mbedtls/include/mbedtls/version.h +78 -0
  143. package/vendor/mbedtls/include/mbedtls/x509.h +500 -0
  144. package/vendor/mbedtls/include/mbedtls/x509_crl.h +184 -0
  145. package/vendor/mbedtls/include/mbedtls/x509_crt.h +1208 -0
  146. package/vendor/mbedtls/include/mbedtls/x509_csr.h +382 -0
  147. package/vendor/mbedtls/include/psa/build_info.h +20 -0
  148. package/vendor/mbedtls/include/psa/crypto.h +4998 -0
  149. package/vendor/mbedtls/include/psa/crypto_adjust_auto_enabled.h +31 -0
  150. package/vendor/mbedtls/include/psa/crypto_adjust_config_dependencies.h +51 -0
  151. package/vendor/mbedtls/include/psa/crypto_adjust_config_key_pair_types.h +101 -0
  152. package/vendor/mbedtls/include/psa/crypto_adjust_config_synonyms.h +49 -0
  153. package/vendor/mbedtls/include/psa/crypto_builtin_composites.h +214 -0
  154. package/vendor/mbedtls/include/psa/crypto_builtin_key_derivation.h +118 -0
  155. package/vendor/mbedtls/include/psa/crypto_builtin_primitives.h +114 -0
  156. package/vendor/mbedtls/include/psa/crypto_compat.h +230 -0
  157. package/vendor/mbedtls/include/psa/crypto_config.h +145 -0
  158. package/vendor/mbedtls/include/psa/crypto_driver_common.h +44 -0
  159. package/vendor/mbedtls/include/psa/crypto_driver_contexts_composites.h +151 -0
  160. package/vendor/mbedtls/include/psa/crypto_driver_contexts_key_derivation.h +52 -0
  161. package/vendor/mbedtls/include/psa/crypto_driver_contexts_primitives.h +105 -0
  162. package/vendor/mbedtls/include/psa/crypto_extra.h +2145 -0
  163. package/vendor/mbedtls/include/psa/crypto_legacy.h +88 -0
  164. package/vendor/mbedtls/include/psa/crypto_platform.h +102 -0
  165. package/vendor/mbedtls/include/psa/crypto_se_driver.h +1383 -0
  166. package/vendor/mbedtls/include/psa/crypto_sizes.h +1319 -0
  167. package/vendor/mbedtls/include/psa/crypto_struct.h +527 -0
  168. package/vendor/mbedtls/include/psa/crypto_types.h +508 -0
  169. package/vendor/mbedtls/include/psa/crypto_values.h +2782 -0
  170. package/vendor/mbedtls/library/aes.c +2294 -0
  171. package/vendor/mbedtls/library/aesce.c +624 -0
  172. package/vendor/mbedtls/library/aesce.h +136 -0
  173. package/vendor/mbedtls/library/aesni.c +846 -0
  174. package/vendor/mbedtls/library/aesni.h +162 -0
  175. package/vendor/mbedtls/library/alignment.h +704 -0
  176. package/vendor/mbedtls/library/aria.c +969 -0
  177. package/vendor/mbedtls/library/asn1parse.c +468 -0
  178. package/vendor/mbedtls/library/asn1write.c +440 -0
  179. package/vendor/mbedtls/library/base64.c +322 -0
  180. package/vendor/mbedtls/library/base64_internal.h +45 -0
  181. package/vendor/mbedtls/library/bignum.c +2583 -0
  182. package/vendor/mbedtls/library/bignum_core.c +1240 -0
  183. package/vendor/mbedtls/library/bignum_core.h +872 -0
  184. package/vendor/mbedtls/library/bignum_core_invasive.h +38 -0
  185. package/vendor/mbedtls/library/bignum_internal.h +122 -0
  186. package/vendor/mbedtls/library/bignum_mod.c +394 -0
  187. package/vendor/mbedtls/library/bignum_mod.h +452 -0
  188. package/vendor/mbedtls/library/bignum_mod_raw.c +276 -0
  189. package/vendor/mbedtls/library/bignum_mod_raw.h +416 -0
  190. package/vendor/mbedtls/library/bignum_mod_raw_invasive.h +34 -0
  191. package/vendor/mbedtls/library/block_cipher.c +207 -0
  192. package/vendor/mbedtls/library/block_cipher_internal.h +99 -0
  193. package/vendor/mbedtls/library/bn_mul.h +1094 -0
  194. package/vendor/mbedtls/library/camellia.c +1058 -0
  195. package/vendor/mbedtls/library/ccm.c +777 -0
  196. package/vendor/mbedtls/library/chacha20.c +563 -0
  197. package/vendor/mbedtls/library/chacha20_internal.h +23 -0
  198. package/vendor/mbedtls/library/chachapoly.c +487 -0
  199. package/vendor/mbedtls/library/check_crypto_config.h +136 -0
  200. package/vendor/mbedtls/library/cipher.c +1712 -0
  201. package/vendor/mbedtls/library/cipher_invasive.h +28 -0
  202. package/vendor/mbedtls/library/cipher_wrap.c +2482 -0
  203. package/vendor/mbedtls/library/cipher_wrap.h +178 -0
  204. package/vendor/mbedtls/library/cmac.c +1067 -0
  205. package/vendor/mbedtls/library/common.h +487 -0
  206. package/vendor/mbedtls/library/constant_time.c +247 -0
  207. package/vendor/mbedtls/library/constant_time_impl.h +541 -0
  208. package/vendor/mbedtls/library/constant_time_internal.h +579 -0
  209. package/vendor/mbedtls/library/ctr.h +35 -0
  210. package/vendor/mbedtls/library/ctr_drbg.c +1016 -0
  211. package/vendor/mbedtls/library/debug.c +475 -0
  212. package/vendor/mbedtls/library/debug_internal.h +185 -0
  213. package/vendor/mbedtls/library/des.c +1042 -0
  214. package/vendor/mbedtls/library/dhm.c +700 -0
  215. package/vendor/mbedtls/library/ecdh.c +696 -0
  216. package/vendor/mbedtls/library/ecdsa.c +858 -0
  217. package/vendor/mbedtls/library/ecjpake.c +1216 -0
  218. package/vendor/mbedtls/library/ecp.c +3674 -0
  219. package/vendor/mbedtls/library/ecp_curves.c +6125 -0
  220. package/vendor/mbedtls/library/ecp_curves_new.c +9 -0
  221. package/vendor/mbedtls/library/ecp_internal_alt.h +287 -0
  222. package/vendor/mbedtls/library/ecp_invasive.h +305 -0
  223. package/vendor/mbedtls/library/entropy.c +680 -0
  224. package/vendor/mbedtls/library/entropy_poll.c +233 -0
  225. package/vendor/mbedtls/library/entropy_poll.h +64 -0
  226. package/vendor/mbedtls/library/error.c +878 -0
  227. package/vendor/mbedtls/library/gcm.c +1330 -0
  228. package/vendor/mbedtls/library/hkdf.c +161 -0
  229. package/vendor/mbedtls/library/hmac_drbg.c +633 -0
  230. package/vendor/mbedtls/library/lmots.c +789 -0
  231. package/vendor/mbedtls/library/lmots.h +288 -0
  232. package/vendor/mbedtls/library/lms.c +778 -0
  233. package/vendor/mbedtls/library/md.c +1108 -0
  234. package/vendor/mbedtls/library/md5.c +426 -0
  235. package/vendor/mbedtls/library/md_psa.h +26 -0
  236. package/vendor/mbedtls/library/md_wrap.h +46 -0
  237. package/vendor/mbedtls/library/memory_buffer_alloc.c +751 -0
  238. package/vendor/mbedtls/library/mps_common.h +181 -0
  239. package/vendor/mbedtls/library/mps_error.h +89 -0
  240. package/vendor/mbedtls/library/mps_reader.c +538 -0
  241. package/vendor/mbedtls/library/mps_reader.h +366 -0
  242. package/vendor/mbedtls/library/mps_trace.c +112 -0
  243. package/vendor/mbedtls/library/mps_trace.h +154 -0
  244. package/vendor/mbedtls/library/net_sockets.c +694 -0
  245. package/vendor/mbedtls/library/nist_kw.c +729 -0
  246. package/vendor/mbedtls/library/oid.c +1166 -0
  247. package/vendor/mbedtls/library/padlock.c +157 -0
  248. package/vendor/mbedtls/library/padlock.h +111 -0
  249. package/vendor/mbedtls/library/pem.c +554 -0
  250. package/vendor/mbedtls/library/pk.c +1602 -0
  251. package/vendor/mbedtls/library/pk_ecc.c +261 -0
  252. package/vendor/mbedtls/library/pk_internal.h +241 -0
  253. package/vendor/mbedtls/library/pk_wrap.c +1618 -0
  254. package/vendor/mbedtls/library/pk_wrap.h +138 -0
  255. package/vendor/mbedtls/library/pkcs12.c +437 -0
  256. package/vendor/mbedtls/library/pkcs5.c +500 -0
  257. package/vendor/mbedtls/library/pkcs7.c +787 -0
  258. package/vendor/mbedtls/library/pkparse.c +1392 -0
  259. package/vendor/mbedtls/library/pkwrite.c +631 -0
  260. package/vendor/mbedtls/library/pkwrite.h +121 -0
  261. package/vendor/mbedtls/library/platform.c +402 -0
  262. package/vendor/mbedtls/library/platform_util.c +258 -0
  263. package/vendor/mbedtls/library/poly1305.c +492 -0
  264. package/vendor/mbedtls/library/psa_crypto.c +9532 -0
  265. package/vendor/mbedtls/library/psa_crypto_aead.c +646 -0
  266. package/vendor/mbedtls/library/psa_crypto_aead.h +499 -0
  267. package/vendor/mbedtls/library/psa_crypto_cipher.c +747 -0
  268. package/vendor/mbedtls/library/psa_crypto_cipher.h +316 -0
  269. package/vendor/mbedtls/library/psa_crypto_client.c +22 -0
  270. package/vendor/mbedtls/library/psa_crypto_core.h +983 -0
  271. package/vendor/mbedtls/library/psa_crypto_core_common.h +52 -0
  272. package/vendor/mbedtls/library/psa_crypto_driver_wrappers.h +2896 -0
  273. package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.c +256 -0
  274. package/vendor/mbedtls/library/psa_crypto_driver_wrappers_no_static.h +31 -0
  275. package/vendor/mbedtls/library/psa_crypto_ecp.c +594 -0
  276. package/vendor/mbedtls/library/psa_crypto_ecp.h +267 -0
  277. package/vendor/mbedtls/library/psa_crypto_ffdh.c +361 -0
  278. package/vendor/mbedtls/library/psa_crypto_ffdh.h +131 -0
  279. package/vendor/mbedtls/library/psa_crypto_hash.c +470 -0
  280. package/vendor/mbedtls/library/psa_crypto_hash.h +211 -0
  281. package/vendor/mbedtls/library/psa_crypto_invasive.h +92 -0
  282. package/vendor/mbedtls/library/psa_crypto_its.h +131 -0
  283. package/vendor/mbedtls/library/psa_crypto_mac.c +505 -0
  284. package/vendor/mbedtls/library/psa_crypto_mac.h +264 -0
  285. package/vendor/mbedtls/library/psa_crypto_pake.c +571 -0
  286. package/vendor/mbedtls/library/psa_crypto_pake.h +159 -0
  287. package/vendor/mbedtls/library/psa_crypto_random.c +181 -0
  288. package/vendor/mbedtls/library/psa_crypto_random.h +72 -0
  289. package/vendor/mbedtls/library/psa_crypto_random_impl.h +200 -0
  290. package/vendor/mbedtls/library/psa_crypto_rsa.c +714 -0
  291. package/vendor/mbedtls/library/psa_crypto_rsa.h +321 -0
  292. package/vendor/mbedtls/library/psa_crypto_se.c +373 -0
  293. package/vendor/mbedtls/library/psa_crypto_se.h +192 -0
  294. package/vendor/mbedtls/library/psa_crypto_slot_management.c +1137 -0
  295. package/vendor/mbedtls/library/psa_crypto_slot_management.h +344 -0
  296. package/vendor/mbedtls/library/psa_crypto_storage.c +481 -0
  297. package/vendor/mbedtls/library/psa_crypto_storage.h +392 -0
  298. package/vendor/mbedtls/library/psa_its_file.c +254 -0
  299. package/vendor/mbedtls/library/psa_util.c +614 -0
  300. package/vendor/mbedtls/library/psa_util_internal.h +100 -0
  301. package/vendor/mbedtls/library/ripemd160.c +490 -0
  302. package/vendor/mbedtls/library/rsa.c +3121 -0
  303. package/vendor/mbedtls/library/rsa_alt_helpers.c +455 -0
  304. package/vendor/mbedtls/library/rsa_alt_helpers.h +209 -0
  305. package/vendor/mbedtls/library/rsa_internal.h +188 -0
  306. package/vendor/mbedtls/library/sha1.c +480 -0
  307. package/vendor/mbedtls/library/sha256.c +983 -0
  308. package/vendor/mbedtls/library/sha3.c +721 -0
  309. package/vendor/mbedtls/library/sha512.c +1115 -0
  310. package/vendor/mbedtls/library/ssl_cache.c +410 -0
  311. package/vendor/mbedtls/library/ssl_ciphersuites.c +2050 -0
  312. package/vendor/mbedtls/library/ssl_ciphersuites_internal.h +154 -0
  313. package/vendor/mbedtls/library/ssl_client.c +1023 -0
  314. package/vendor/mbedtls/library/ssl_client.h +22 -0
  315. package/vendor/mbedtls/library/ssl_cookie.c +384 -0
  316. package/vendor/mbedtls/library/ssl_debug_helpers.h +85 -0
  317. package/vendor/mbedtls/library/ssl_debug_helpers_generated.c +251 -0
  318. package/vendor/mbedtls/library/ssl_misc.h +3198 -0
  319. package/vendor/mbedtls/library/ssl_msg.c +6619 -0
  320. package/vendor/mbedtls/library/ssl_ticket.c +556 -0
  321. package/vendor/mbedtls/library/ssl_tls.c +10234 -0
  322. package/vendor/mbedtls/library/ssl_tls12_client.c +3688 -0
  323. package/vendor/mbedtls/library/ssl_tls12_server.c +4311 -0
  324. package/vendor/mbedtls/library/ssl_tls13_client.c +3208 -0
  325. package/vendor/mbedtls/library/ssl_tls13_generic.c +1793 -0
  326. package/vendor/mbedtls/library/ssl_tls13_invasive.h +23 -0
  327. package/vendor/mbedtls/library/ssl_tls13_keys.c +1918 -0
  328. package/vendor/mbedtls/library/ssl_tls13_keys.h +668 -0
  329. package/vendor/mbedtls/library/ssl_tls13_server.c +3624 -0
  330. package/vendor/mbedtls/library/threading.c +193 -0
  331. package/vendor/mbedtls/library/threading_internal.h +28 -0
  332. package/vendor/mbedtls/library/timing.c +152 -0
  333. package/vendor/mbedtls/library/version.c +32 -0
  334. package/vendor/mbedtls/library/version_features.c +856 -0
  335. package/vendor/mbedtls/library/x509.c +1776 -0
  336. package/vendor/mbedtls/library/x509_create.c +570 -0
  337. package/vendor/mbedtls/library/x509_crl.c +708 -0
  338. package/vendor/mbedtls/library/x509_crt.c +3311 -0
  339. package/vendor/mbedtls/library/x509_csr.c +648 -0
  340. package/vendor/mbedtls/library/x509_internal.h +101 -0
  341. package/vendor/mbedtls/library/x509write.c +174 -0
  342. package/vendor/mbedtls/library/x509write_crt.c +688 -0
  343. package/vendor/mbedtls/library/x509write_csr.c +336 -0
  344. package/vendor/quickjs-ng/CMakeLists.txt +566 -0
  345. package/vendor/quickjs-ng/LICENSE +24 -0
  346. package/vendor/quickjs-ng/README.md +24 -0
  347. package/vendor/quickjs-ng/api-test.c +1195 -0
  348. package/vendor/quickjs-ng/builtin-array-fromasync.h +119 -0
  349. package/vendor/quickjs-ng/builtin-iterator-zip-keyed.h +332 -0
  350. package/vendor/quickjs-ng/builtin-iterator-zip.h +337 -0
  351. package/vendor/quickjs-ng/cutils.h +1998 -0
  352. package/vendor/quickjs-ng/dtoa.c +1619 -0
  353. package/vendor/quickjs-ng/dtoa.h +87 -0
  354. package/vendor/quickjs-ng/gen/function_source.c +81 -0
  355. package/vendor/quickjs-ng/gen/hello.c +53 -0
  356. package/vendor/quickjs-ng/gen/hello_module.c +106 -0
  357. package/vendor/quickjs-ng/gen/repl.c +3036 -0
  358. package/vendor/quickjs-ng/gen/standalone.c +323 -0
  359. package/vendor/quickjs-ng/gen/test_fib.c +81 -0
  360. package/vendor/quickjs-ng/libregexp-opcode.h +73 -0
  361. package/vendor/quickjs-ng/libregexp.c +3474 -0
  362. package/vendor/quickjs-ng/libregexp.h +101 -0
  363. package/vendor/quickjs-ng/libunicode-table.h +5173 -0
  364. package/vendor/quickjs-ng/libunicode.c +2069 -0
  365. package/vendor/quickjs-ng/libunicode.h +172 -0
  366. package/vendor/quickjs-ng/list.h +107 -0
  367. package/vendor/quickjs-ng/lre-test.c +52 -0
  368. package/vendor/quickjs-ng/qjs.c +762 -0
  369. package/vendor/quickjs-ng/qjsc.c +673 -0
  370. package/vendor/quickjs-ng/quickjs-atom.h +280 -0
  371. package/vendor/quickjs-ng/quickjs-c-atomics.h +54 -0
  372. package/vendor/quickjs-ng/quickjs-libc.c +5037 -0
  373. package/vendor/quickjs-ng/quickjs-libc.h +87 -0
  374. package/vendor/quickjs-ng/quickjs-opcode.h +377 -0
  375. package/vendor/quickjs-ng/quickjs.c +64041 -0
  376. package/vendor/quickjs-ng/quickjs.h +1447 -0
  377. package/vendor/quickjs-ng/run-test262.c +2374 -0
  378. package/vendor/quickjs-ng/unicode_gen.c +3121 -0
  379. package/vendor/quickjs-ng/unicode_gen_def.h +310 -0
  380. package/vendor/ryu/LICENSE-Boost +23 -0
  381. package/vendor/ryu/common.h +114 -0
  382. package/vendor/ryu/d2s.c +509 -0
  383. package/vendor/ryu/d2s_full_table.h +367 -0
  384. package/vendor/ryu/d2s_intrinsics.h +357 -0
  385. package/vendor/ryu/d2s_small_table.h +186 -0
  386. package/vendor/ryu/digit_table.h +35 -0
  387. package/vendor/ryu/ryu.h +46 -0
  388. package/vendor/zlib/LICENSE +22 -0
  389. package/vendor/zlib/adler32.c +164 -0
  390. package/vendor/zlib/compress.c +75 -0
  391. package/vendor/zlib/crc32.c +1049 -0
  392. package/vendor/zlib/crc32.h +9446 -0
  393. package/vendor/zlib/deflate.c +2139 -0
  394. package/vendor/zlib/deflate.h +377 -0
  395. package/vendor/zlib/gzclose.c +23 -0
  396. package/vendor/zlib/gzguts.h +214 -0
  397. package/vendor/zlib/gzlib.c +582 -0
  398. package/vendor/zlib/gzread.c +602 -0
  399. package/vendor/zlib/gzwrite.c +631 -0
  400. package/vendor/zlib/infback.c +628 -0
  401. package/vendor/zlib/inffast.c +320 -0
  402. package/vendor/zlib/inffast.h +11 -0
  403. package/vendor/zlib/inffixed.h +94 -0
  404. package/vendor/zlib/inflate.c +1526 -0
  405. package/vendor/zlib/inflate.h +126 -0
  406. package/vendor/zlib/inftrees.c +299 -0
  407. package/vendor/zlib/inftrees.h +62 -0
  408. package/vendor/zlib/trees.c +1117 -0
  409. package/vendor/zlib/trees.h +128 -0
  410. package/vendor/zlib/uncompr.c +85 -0
  411. package/vendor/zlib/zconf.h +543 -0
  412. package/vendor/zlib/zlib.h +1938 -0
  413. package/vendor/zlib/zutil.c +299 -0
  414. package/vendor/zlib/zutil.h +254 -0
  415. package/README.md +0 -3
  416. package/index.js +0 -2
@@ -0,0 +1,1170 @@
1
+ /**
2
+ * \file rsa.h
3
+ *
4
+ * \brief This file provides an API for the RSA public-key cryptosystem.
5
+ *
6
+ * The RSA public-key cryptosystem is defined in <em>Public-Key
7
+ * Cryptography Standards (PKCS) #1 v1.5: RSA Encryption</em>
8
+ * and <em>Public-Key Cryptography Standards (PKCS) #1 v2.1:
9
+ * RSA Cryptography Specifications</em>.
10
+ *
11
+ */
12
+ /*
13
+ * Copyright The Mbed TLS Contributors
14
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
15
+ */
16
+ #ifndef MBEDTLS_RSA_H
17
+ #define MBEDTLS_RSA_H
18
+ #include "mbedtls/private_access.h"
19
+
20
+ #include "mbedtls/build_info.h"
21
+
22
+ #include "mbedtls/bignum.h"
23
+ #include "mbedtls/md.h"
24
+
25
+ #if defined(MBEDTLS_THREADING_C)
26
+ #include "mbedtls/threading.h"
27
+ #endif
28
+
29
+ /*
30
+ * RSA Error codes
31
+ */
32
+ /** Bad input parameters to function. */
33
+ #define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080
34
+ /** Input data contains invalid padding and is rejected. */
35
+ #define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100
36
+ /** Something failed during generation of a key. */
37
+ #define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180
38
+ /** Key failed to pass the validity check of the library. */
39
+ #define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200
40
+ /** The public key operation failed. */
41
+ #define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280
42
+ /** The private key operation failed. */
43
+ #define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300
44
+ /** The PKCS#1 verification failed. */
45
+ #define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380
46
+ /** The output buffer for decryption is not large enough. */
47
+ #define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400
48
+ /** The random generator failed to generate non-zeros. */
49
+ #define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480
50
+
51
+ /*
52
+ * RSA constants
53
+ */
54
+
55
+ #define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS#1 v1.5 encoding. */
56
+ #define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS#1 v2.1 encoding. */
57
+
58
+ #define MBEDTLS_RSA_SIGN 1 /**< Identifier for RSA signature operations. */
59
+ #define MBEDTLS_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */
60
+
61
+ #define MBEDTLS_RSA_SALT_LEN_ANY -1
62
+
63
+ /*
64
+ * The above constants may be used even if the RSA module is compile out,
65
+ * eg for alternative (PKCS#11) RSA implementations in the PK layers.
66
+ */
67
+
68
+ #ifdef __cplusplus
69
+ extern "C" {
70
+ #endif
71
+
72
+ #if !defined(MBEDTLS_RSA_ALT)
73
+ // Regular implementation
74
+ //
75
+
76
+ #if !defined(MBEDTLS_RSA_GEN_KEY_MIN_BITS)
77
+ #define MBEDTLS_RSA_GEN_KEY_MIN_BITS 1024
78
+ #elif MBEDTLS_RSA_GEN_KEY_MIN_BITS < 128
79
+ #error "MBEDTLS_RSA_GEN_KEY_MIN_BITS must be at least 128 bits"
80
+ #endif
81
+
82
+ /**
83
+ * \brief The RSA context structure.
84
+ */
85
+ typedef struct mbedtls_rsa_context {
86
+ int MBEDTLS_PRIVATE(ver); /*!< Reserved for internal purposes.
87
+ * Do not set this field in application
88
+ * code. Its meaning might change without
89
+ * notice. */
90
+ size_t MBEDTLS_PRIVATE(len); /*!< The size of \p N in Bytes. */
91
+
92
+ mbedtls_mpi MBEDTLS_PRIVATE(N); /*!< The public modulus. */
93
+ mbedtls_mpi MBEDTLS_PRIVATE(E); /*!< The public exponent. */
94
+
95
+ mbedtls_mpi MBEDTLS_PRIVATE(D); /*!< The private exponent. */
96
+ mbedtls_mpi MBEDTLS_PRIVATE(P); /*!< The first prime factor. */
97
+ mbedtls_mpi MBEDTLS_PRIVATE(Q); /*!< The second prime factor. */
98
+
99
+ mbedtls_mpi MBEDTLS_PRIVATE(DP); /*!< <code>D % (P - 1)</code>. */
100
+ mbedtls_mpi MBEDTLS_PRIVATE(DQ); /*!< <code>D % (Q - 1)</code>. */
101
+ mbedtls_mpi MBEDTLS_PRIVATE(QP); /*!< <code>1 / (Q % P)</code>. */
102
+
103
+ mbedtls_mpi MBEDTLS_PRIVATE(RN); /*!< cached <code>R^2 mod N</code>. */
104
+
105
+ mbedtls_mpi MBEDTLS_PRIVATE(RP); /*!< cached <code>R^2 mod P</code>. */
106
+ mbedtls_mpi MBEDTLS_PRIVATE(RQ); /*!< cached <code>R^2 mod Q</code>. */
107
+
108
+ mbedtls_mpi MBEDTLS_PRIVATE(Vi); /*!< The cached blinding value. */
109
+ mbedtls_mpi MBEDTLS_PRIVATE(Vf); /*!< The cached un-blinding value. */
110
+
111
+ int MBEDTLS_PRIVATE(padding); /*!< Selects padding mode:
112
+ #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
113
+ #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
114
+ int MBEDTLS_PRIVATE(hash_id); /*!< Hash identifier of mbedtls_md_type_t type,
115
+ as specified in md.h for use in the MGF
116
+ mask generating function used in the
117
+ EME-OAEP and EMSA-PSS encodings. */
118
+ #if defined(MBEDTLS_THREADING_C)
119
+ /* Invariant: the mutex is initialized iff ver != 0. */
120
+ mbedtls_threading_mutex_t MBEDTLS_PRIVATE(mutex); /*!< Thread-safety mutex. */
121
+ #endif
122
+ }
123
+ mbedtls_rsa_context;
124
+
125
+ #else /* MBEDTLS_RSA_ALT */
126
+ #include "rsa_alt.h"
127
+ #endif /* MBEDTLS_RSA_ALT */
128
+
129
+ /**
130
+ * \brief This function initializes an RSA context.
131
+ *
132
+ * \note This function initializes the padding and the hash
133
+ * identifier to respectively #MBEDTLS_RSA_PKCS_V15 and
134
+ * #MBEDTLS_MD_NONE. See mbedtls_rsa_set_padding() for more
135
+ * information about those parameters.
136
+ *
137
+ * \param ctx The RSA context to initialize. This must not be \c NULL.
138
+ */
139
+ void mbedtls_rsa_init(mbedtls_rsa_context *ctx);
140
+
141
+ /**
142
+ * \brief This function sets padding for an already initialized RSA
143
+ * context.
144
+ *
145
+ * \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
146
+ * encryption scheme and the RSASSA-PSS signature scheme.
147
+ *
148
+ * \note The \p hash_id parameter is ignored when using
149
+ * #MBEDTLS_RSA_PKCS_V15 padding.
150
+ *
151
+ * \note The choice of padding mode is strictly enforced for private
152
+ * key operations, since there might be security concerns in
153
+ * mixing padding modes. For public key operations it is
154
+ * a default value, which can be overridden by calling specific
155
+ * \c mbedtls_rsa_rsaes_xxx or \c mbedtls_rsa_rsassa_xxx
156
+ * functions.
157
+ *
158
+ * \note The hash selected in \p hash_id is always used for OEAP
159
+ * encryption. For PSS signatures, it is always used for
160
+ * making signatures, but can be overridden for verifying them.
161
+ * If set to #MBEDTLS_MD_NONE, it is always overridden.
162
+ *
163
+ * \param ctx The initialized RSA context to be configured.
164
+ * \param padding The padding mode to use. This must be either
165
+ * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
166
+ * \param hash_id The hash identifier for PSS or OAEP, if \p padding is
167
+ * #MBEDTLS_RSA_PKCS_V21. #MBEDTLS_MD_NONE is accepted by this
168
+ * function but may be not suitable for some operations.
169
+ * Ignored if \p padding is #MBEDTLS_RSA_PKCS_V15.
170
+ *
171
+ * \return \c 0 on success.
172
+ * \return #MBEDTLS_ERR_RSA_INVALID_PADDING failure:
173
+ * \p padding or \p hash_id is invalid.
174
+ */
175
+ int mbedtls_rsa_set_padding(mbedtls_rsa_context *ctx, int padding,
176
+ mbedtls_md_type_t hash_id);
177
+
178
+ /**
179
+ * \brief This function retrieves padding mode of initialized
180
+ * RSA context.
181
+ *
182
+ * \param ctx The initialized RSA context.
183
+ *
184
+ * \return RSA padding mode.
185
+ *
186
+ */
187
+ int mbedtls_rsa_get_padding_mode(const mbedtls_rsa_context *ctx);
188
+
189
+ /**
190
+ * \brief This function retrieves hash identifier of mbedtls_md_type_t
191
+ * type.
192
+ *
193
+ * \param ctx The initialized RSA context.
194
+ *
195
+ * \return Hash identifier of mbedtls_md_type_t type.
196
+ *
197
+ */
198
+ int mbedtls_rsa_get_md_alg(const mbedtls_rsa_context *ctx);
199
+
200
+ /**
201
+ * \brief This function imports a set of core parameters into an
202
+ * RSA context.
203
+ *
204
+ * \note This function can be called multiple times for successive
205
+ * imports, if the parameters are not simultaneously present.
206
+ *
207
+ * Any sequence of calls to this function should be followed
208
+ * by a call to mbedtls_rsa_complete(), which checks and
209
+ * completes the provided information to a ready-for-use
210
+ * public or private RSA key.
211
+ *
212
+ * \note See mbedtls_rsa_complete() for more information on which
213
+ * parameters are necessary to set up a private or public
214
+ * RSA key.
215
+ *
216
+ * \note The imported parameters are copied and need not be preserved
217
+ * for the lifetime of the RSA context being set up.
218
+ *
219
+ * \param ctx The initialized RSA context to store the parameters in.
220
+ * \param N The RSA modulus. This may be \c NULL.
221
+ * \param P The first prime factor of \p N. This may be \c NULL.
222
+ * \param Q The second prime factor of \p N. This may be \c NULL.
223
+ * \param D The private exponent. This may be \c NULL.
224
+ * \param E The public exponent. This may be \c NULL.
225
+ *
226
+ * \return \c 0 on success.
227
+ * \return A non-zero error code on failure.
228
+ */
229
+ int mbedtls_rsa_import(mbedtls_rsa_context *ctx,
230
+ const mbedtls_mpi *N,
231
+ const mbedtls_mpi *P, const mbedtls_mpi *Q,
232
+ const mbedtls_mpi *D, const mbedtls_mpi *E);
233
+
234
+ /**
235
+ * \brief This function imports core RSA parameters, in raw big-endian
236
+ * binary format, into an RSA context.
237
+ *
238
+ * \note This function can be called multiple times for successive
239
+ * imports, if the parameters are not simultaneously present.
240
+ *
241
+ * Any sequence of calls to this function should be followed
242
+ * by a call to mbedtls_rsa_complete(), which checks and
243
+ * completes the provided information to a ready-for-use
244
+ * public or private RSA key.
245
+ *
246
+ * \note See mbedtls_rsa_complete() for more information on which
247
+ * parameters are necessary to set up a private or public
248
+ * RSA key.
249
+ *
250
+ * \note The imported parameters are copied and need not be preserved
251
+ * for the lifetime of the RSA context being set up.
252
+ *
253
+ * \param ctx The initialized RSA context to store the parameters in.
254
+ * \param N The RSA modulus. This may be \c NULL.
255
+ * \param N_len The Byte length of \p N; it is ignored if \p N == NULL.
256
+ * \param P The first prime factor of \p N. This may be \c NULL.
257
+ * \param P_len The Byte length of \p P; it is ignored if \p P == NULL.
258
+ * \param Q The second prime factor of \p N. This may be \c NULL.
259
+ * \param Q_len The Byte length of \p Q; it is ignored if \p Q == NULL.
260
+ * \param D The private exponent. This may be \c NULL.
261
+ * \param D_len The Byte length of \p D; it is ignored if \p D == NULL.
262
+ * \param E The public exponent. This may be \c NULL.
263
+ * \param E_len The Byte length of \p E; it is ignored if \p E == NULL.
264
+ *
265
+ * \return \c 0 on success.
266
+ * \return A non-zero error code on failure.
267
+ */
268
+ int mbedtls_rsa_import_raw(mbedtls_rsa_context *ctx,
269
+ unsigned char const *N, size_t N_len,
270
+ unsigned char const *P, size_t P_len,
271
+ unsigned char const *Q, size_t Q_len,
272
+ unsigned char const *D, size_t D_len,
273
+ unsigned char const *E, size_t E_len);
274
+
275
+ /**
276
+ * \brief This function completes an RSA context from
277
+ * a set of imported core parameters.
278
+ *
279
+ * To setup an RSA public key, precisely \c N and \c E
280
+ * must have been imported.
281
+ *
282
+ * To setup an RSA private key, sufficient information must
283
+ * be present for the other parameters to be derivable.
284
+ *
285
+ * The default implementation supports the following:
286
+ * <ul><li>Derive \c P, \c Q from \c N, \c D, \c E.</li>
287
+ * <li>Derive \c N, \c D from \c P, \c Q, \c E.</li></ul>
288
+ * Alternative implementations need not support these.
289
+ *
290
+ * If this function runs successfully, it guarantees that
291
+ * the RSA context can be used for RSA operations without
292
+ * the risk of failure or crash.
293
+ *
294
+ * \warning This function need not perform consistency checks
295
+ * for the imported parameters. In particular, parameters that
296
+ * are not needed by the implementation might be silently
297
+ * discarded and left unchecked. To check the consistency
298
+ * of the key material, see mbedtls_rsa_check_privkey().
299
+ *
300
+ * \param ctx The initialized RSA context holding imported parameters.
301
+ *
302
+ * \return \c 0 on success.
303
+ * \return #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the attempted derivations
304
+ * failed.
305
+ *
306
+ */
307
+ int mbedtls_rsa_complete(mbedtls_rsa_context *ctx);
308
+
309
+ /**
310
+ * \brief This function exports the core parameters of an RSA key.
311
+ *
312
+ * If this function runs successfully, the non-NULL buffers
313
+ * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
314
+ * written, with additional unused space filled leading by
315
+ * zero Bytes.
316
+ *
317
+ * Possible reasons for returning
318
+ * #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:<ul>
319
+ * <li>An alternative RSA implementation is in use, which
320
+ * stores the key externally, and either cannot or should
321
+ * not export it into RAM.</li>
322
+ * <li>A SW or HW implementation might not support a certain
323
+ * deduction. For example, \p P, \p Q from \p N, \p D,
324
+ * and \p E if the former are not part of the
325
+ * implementation.</li></ul>
326
+ *
327
+ * If the function fails due to an unsupported operation,
328
+ * the RSA context stays intact and remains usable.
329
+ *
330
+ * \param ctx The initialized RSA context.
331
+ * \param N The MPI to hold the RSA modulus.
332
+ * This may be \c NULL if this field need not be exported.
333
+ * \param P The MPI to hold the first prime factor of \p N.
334
+ * This may be \c NULL if this field need not be exported.
335
+ * \param Q The MPI to hold the second prime factor of \p N.
336
+ * This may be \c NULL if this field need not be exported.
337
+ * \param D The MPI to hold the private exponent.
338
+ * This may be \c NULL if this field need not be exported.
339
+ * \param E The MPI to hold the public exponent.
340
+ * This may be \c NULL if this field need not be exported.
341
+ *
342
+ * \return \c 0 on success.
343
+ * \return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the
344
+ * requested parameters cannot be done due to missing
345
+ * functionality or because of security policies.
346
+ * \return A non-zero return code on any other failure.
347
+ *
348
+ */
349
+ int mbedtls_rsa_export(const mbedtls_rsa_context *ctx,
350
+ mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q,
351
+ mbedtls_mpi *D, mbedtls_mpi *E);
352
+
353
+ /**
354
+ * \brief This function exports core parameters of an RSA key
355
+ * in raw big-endian binary format.
356
+ *
357
+ * If this function runs successfully, the non-NULL buffers
358
+ * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
359
+ * written, with additional unused space filled leading by
360
+ * zero Bytes.
361
+ *
362
+ * Possible reasons for returning
363
+ * #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:<ul>
364
+ * <li>An alternative RSA implementation is in use, which
365
+ * stores the key externally, and either cannot or should
366
+ * not export it into RAM.</li>
367
+ * <li>A SW or HW implementation might not support a certain
368
+ * deduction. For example, \p P, \p Q from \p N, \p D,
369
+ * and \p E if the former are not part of the
370
+ * implementation.</li></ul>
371
+ * If the function fails due to an unsupported operation,
372
+ * the RSA context stays intact and remains usable.
373
+ *
374
+ * \note The length parameters are ignored if the corresponding
375
+ * buffer pointers are NULL.
376
+ *
377
+ * \param ctx The initialized RSA context.
378
+ * \param N The Byte array to store the RSA modulus,
379
+ * or \c NULL if this field need not be exported.
380
+ * \param N_len The size of the buffer for the modulus.
381
+ * \param P The Byte array to hold the first prime factor of \p N,
382
+ * or \c NULL if this field need not be exported.
383
+ * \param P_len The size of the buffer for the first prime factor.
384
+ * \param Q The Byte array to hold the second prime factor of \p N,
385
+ * or \c NULL if this field need not be exported.
386
+ * \param Q_len The size of the buffer for the second prime factor.
387
+ * \param D The Byte array to hold the private exponent,
388
+ * or \c NULL if this field need not be exported.
389
+ * \param D_len The size of the buffer for the private exponent.
390
+ * \param E The Byte array to hold the public exponent,
391
+ * or \c NULL if this field need not be exported.
392
+ * \param E_len The size of the buffer for the public exponent.
393
+ *
394
+ * \return \c 0 on success.
395
+ * \return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the
396
+ * requested parameters cannot be done due to missing
397
+ * functionality or because of security policies.
398
+ * \return A non-zero return code on any other failure.
399
+ */
400
+ int mbedtls_rsa_export_raw(const mbedtls_rsa_context *ctx,
401
+ unsigned char *N, size_t N_len,
402
+ unsigned char *P, size_t P_len,
403
+ unsigned char *Q, size_t Q_len,
404
+ unsigned char *D, size_t D_len,
405
+ unsigned char *E, size_t E_len);
406
+
407
+ /**
408
+ * \brief This function exports CRT parameters of a private RSA key.
409
+ *
410
+ * \note Alternative RSA implementations not using CRT-parameters
411
+ * internally can implement this function based on
412
+ * mbedtls_rsa_deduce_opt().
413
+ *
414
+ * \param ctx The initialized RSA context.
415
+ * \param DP The MPI to hold \c D modulo `P-1`,
416
+ * or \c NULL if it need not be exported.
417
+ * \param DQ The MPI to hold \c D modulo `Q-1`,
418
+ * or \c NULL if it need not be exported.
419
+ * \param QP The MPI to hold modular inverse of \c Q modulo \c P,
420
+ * or \c NULL if it need not be exported.
421
+ *
422
+ * \return \c 0 on success.
423
+ * \return A non-zero error code on failure.
424
+ *
425
+ */
426
+ int mbedtls_rsa_export_crt(const mbedtls_rsa_context *ctx,
427
+ mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP);
428
+
429
+ /**
430
+ * \brief This function retrieves the length of the RSA modulus in bits.
431
+ *
432
+ * \param ctx The initialized RSA context.
433
+ *
434
+ * \return The length of the RSA modulus in bits.
435
+ *
436
+ */
437
+ size_t mbedtls_rsa_get_bitlen(const mbedtls_rsa_context *ctx);
438
+
439
+ /**
440
+ * \brief This function retrieves the length of RSA modulus in Bytes.
441
+ *
442
+ * \param ctx The initialized RSA context.
443
+ *
444
+ * \return The length of the RSA modulus in Bytes.
445
+ *
446
+ */
447
+ size_t mbedtls_rsa_get_len(const mbedtls_rsa_context *ctx);
448
+
449
+ /**
450
+ * \brief This function generates an RSA keypair.
451
+ *
452
+ * \note mbedtls_rsa_init() must be called before this function,
453
+ * to set up the RSA context.
454
+ *
455
+ * \param ctx The initialized RSA context used to hold the key.
456
+ * \param f_rng The RNG function to be used for key generation.
457
+ * This is mandatory and must not be \c NULL.
458
+ * \param p_rng The RNG context to be passed to \p f_rng.
459
+ * This may be \c NULL if \p f_rng doesn't need a context.
460
+ * \param nbits The size of the public key in bits.
461
+ * \param exponent The public exponent to use. For example, \c 65537.
462
+ * This must be odd and greater than \c 1.
463
+ *
464
+ * \return \c 0 on success.
465
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
466
+ */
467
+ int mbedtls_rsa_gen_key(mbedtls_rsa_context *ctx,
468
+ mbedtls_f_rng_t *f_rng,
469
+ void *p_rng,
470
+ unsigned int nbits, int exponent);
471
+
472
+ /**
473
+ * \brief This function checks if a context contains at least an RSA
474
+ * public key.
475
+ *
476
+ * If the function runs successfully, it is guaranteed that
477
+ * enough information is present to perform an RSA public key
478
+ * operation using mbedtls_rsa_public().
479
+ *
480
+ * \param ctx The initialized RSA context to check.
481
+ *
482
+ * \return \c 0 on success.
483
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
484
+ *
485
+ */
486
+ int mbedtls_rsa_check_pubkey(const mbedtls_rsa_context *ctx);
487
+
488
+ /**
489
+ * \brief This function checks if a context contains an RSA private key
490
+ * and perform basic consistency checks.
491
+ *
492
+ * \note The consistency checks performed by this function not only
493
+ * ensure that mbedtls_rsa_private() can be called successfully
494
+ * on the given context, but that the various parameters are
495
+ * mutually consistent with high probability, in the sense that
496
+ * mbedtls_rsa_public() and mbedtls_rsa_private() are inverses.
497
+ *
498
+ * \warning This function should catch accidental misconfigurations
499
+ * like swapping of parameters, but it cannot establish full
500
+ * trust in neither the quality nor the consistency of the key
501
+ * material that was used to setup the given RSA context:
502
+ * <ul><li>Consistency: Imported parameters that are irrelevant
503
+ * for the implementation might be silently dropped. If dropped,
504
+ * the current function does not have access to them,
505
+ * and therefore cannot check them. See mbedtls_rsa_complete().
506
+ * If you want to check the consistency of the entire
507
+ * content of a PKCS1-encoded RSA private key, for example, you
508
+ * should use mbedtls_rsa_validate_params() before setting
509
+ * up the RSA context.
510
+ * Additionally, if the implementation performs empirical checks,
511
+ * these checks substantiate but do not guarantee consistency.</li>
512
+ * <li>Quality: This function is not expected to perform
513
+ * extended quality assessments like checking that the prime
514
+ * factors are safe. Additionally, it is the responsibility of the
515
+ * user to ensure the trustworthiness of the source of his RSA
516
+ * parameters, which goes beyond what is effectively checkable
517
+ * by the library.</li></ul>
518
+ *
519
+ * \param ctx The initialized RSA context to check.
520
+ *
521
+ * \return \c 0 on success.
522
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
523
+ */
524
+ int mbedtls_rsa_check_privkey(const mbedtls_rsa_context *ctx);
525
+
526
+ /**
527
+ * \brief This function checks a public-private RSA key pair.
528
+ *
529
+ * It checks each of the contexts, and makes sure they match.
530
+ *
531
+ * \param pub The initialized RSA context holding the public key.
532
+ * \param prv The initialized RSA context holding the private key.
533
+ *
534
+ * \return \c 0 on success.
535
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
536
+ */
537
+ int mbedtls_rsa_check_pub_priv(const mbedtls_rsa_context *pub,
538
+ const mbedtls_rsa_context *prv);
539
+
540
+ /**
541
+ * \brief This function performs an RSA public key operation.
542
+ *
543
+ * \param ctx The initialized RSA context to use.
544
+ * \param input The input buffer. This must be a readable buffer
545
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
546
+ * for an 2048-bit RSA modulus.
547
+ * \param output The output buffer. This must be a writable buffer
548
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
549
+ * for an 2048-bit RSA modulus.
550
+ *
551
+ * \note This function does not handle message padding.
552
+ *
553
+ * \note Make sure to set \p input[0] = 0 or ensure that
554
+ * input is smaller than \c N.
555
+ *
556
+ * \return \c 0 on success.
557
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
558
+ */
559
+ int mbedtls_rsa_public(mbedtls_rsa_context *ctx,
560
+ const unsigned char *input,
561
+ unsigned char *output);
562
+
563
+ /**
564
+ * \brief This function performs an RSA private key operation.
565
+ *
566
+ * \note Blinding is used if and only if a PRNG is provided.
567
+ *
568
+ * \note If blinding is used, both the base of exponentiation
569
+ * and the exponent are blinded, providing protection
570
+ * against some side-channel attacks.
571
+ *
572
+ * \warning It is deprecated and a security risk to not provide
573
+ * a PRNG here and thereby prevent the use of blinding.
574
+ * Future versions of the library may enforce the presence
575
+ * of a PRNG.
576
+ *
577
+ * \param ctx The initialized RSA context to use.
578
+ * \param f_rng The RNG function, used for blinding. It is mandatory.
579
+ * \param p_rng The RNG context to pass to \p f_rng. This may be \c NULL
580
+ * if \p f_rng doesn't need a context.
581
+ * \param input The input buffer. This must be a readable buffer
582
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
583
+ * for an 2048-bit RSA modulus.
584
+ * \param output The output buffer. This must be a writable buffer
585
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
586
+ * for an 2048-bit RSA modulus.
587
+ *
588
+ * \return \c 0 on success.
589
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
590
+ *
591
+ */
592
+ int mbedtls_rsa_private(mbedtls_rsa_context *ctx,
593
+ mbedtls_f_rng_t *f_rng,
594
+ void *p_rng,
595
+ const unsigned char *input,
596
+ unsigned char *output);
597
+
598
+ /**
599
+ * \brief This function adds the message padding, then performs an RSA
600
+ * operation.
601
+ *
602
+ * It is the generic wrapper for performing a PKCS#1 encryption
603
+ * operation.
604
+ *
605
+ * \param ctx The initialized RSA context to use.
606
+ * \param f_rng The RNG to use. It is used for padding generation
607
+ * and it is mandatory.
608
+ * \param p_rng The RNG context to be passed to \p f_rng. May be
609
+ * \c NULL if \p f_rng doesn't need a context argument.
610
+ * \param ilen The length of the plaintext in Bytes.
611
+ * \param input The input data to encrypt. This must be a readable
612
+ * buffer of size \p ilen Bytes. It may be \c NULL if
613
+ * `ilen == 0`.
614
+ * \param output The output buffer. This must be a writable buffer
615
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
616
+ * for an 2048-bit RSA modulus.
617
+ *
618
+ * \return \c 0 on success.
619
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
620
+ */
621
+ int mbedtls_rsa_pkcs1_encrypt(mbedtls_rsa_context *ctx,
622
+ mbedtls_f_rng_t *f_rng,
623
+ void *p_rng,
624
+ size_t ilen,
625
+ const unsigned char *input,
626
+ unsigned char *output);
627
+
628
+ /**
629
+ * \brief This function performs a PKCS#1 v1.5 encryption operation
630
+ * (RSAES-PKCS1-v1_5-ENCRYPT).
631
+ *
632
+ * \param ctx The initialized RSA context to use.
633
+ * \param f_rng The RNG function to use. It is mandatory and used for
634
+ * padding generation.
635
+ * \param p_rng The RNG context to be passed to \p f_rng. This may
636
+ * be \c NULL if \p f_rng doesn't need a context argument.
637
+ * \param ilen The length of the plaintext in Bytes.
638
+ * \param input The input data to encrypt. This must be a readable
639
+ * buffer of size \p ilen Bytes. It may be \c NULL if
640
+ * `ilen == 0`.
641
+ * \param output The output buffer. This must be a writable buffer
642
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
643
+ * for an 2048-bit RSA modulus.
644
+ *
645
+ * \return \c 0 on success.
646
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
647
+ */
648
+ int mbedtls_rsa_rsaes_pkcs1_v15_encrypt(mbedtls_rsa_context *ctx,
649
+ mbedtls_f_rng_t *f_rng,
650
+ void *p_rng,
651
+ size_t ilen,
652
+ const unsigned char *input,
653
+ unsigned char *output);
654
+
655
+ /**
656
+ * \brief This function performs a PKCS#1 v2.1 OAEP encryption
657
+ * operation (RSAES-OAEP-ENCRYPT).
658
+ *
659
+ * \note The output buffer must be as large as the size
660
+ * of ctx->N. For example, 128 Bytes if RSA-1024 is used.
661
+ *
662
+ * \param ctx The initialized RSA context to use.
663
+ * \param f_rng The RNG function to use. This is needed for padding
664
+ * generation and is mandatory.
665
+ * \param p_rng The RNG context to be passed to \p f_rng. This may
666
+ * be \c NULL if \p f_rng doesn't need a context argument.
667
+ * \param label The buffer holding the custom label to use.
668
+ * This must be a readable buffer of length \p label_len
669
+ * Bytes. It may be \c NULL if \p label_len is \c 0.
670
+ * \param label_len The length of the label in Bytes.
671
+ * \param ilen The length of the plaintext buffer \p input in Bytes.
672
+ * \param input The input data to encrypt. This must be a readable
673
+ * buffer of size \p ilen Bytes. It may be \c NULL if
674
+ * `ilen == 0`.
675
+ * \param output The output buffer. This must be a writable buffer
676
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
677
+ * for an 2048-bit RSA modulus.
678
+ *
679
+ * \return \c 0 on success.
680
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
681
+ */
682
+ int mbedtls_rsa_rsaes_oaep_encrypt(mbedtls_rsa_context *ctx,
683
+ mbedtls_f_rng_t *f_rng,
684
+ void *p_rng,
685
+ const unsigned char *label, size_t label_len,
686
+ size_t ilen,
687
+ const unsigned char *input,
688
+ unsigned char *output);
689
+
690
+ /**
691
+ * \brief This function performs an RSA operation, then removes the
692
+ * message padding.
693
+ *
694
+ * It is the generic wrapper for performing a PKCS#1 decryption
695
+ * operation.
696
+ *
697
+ * \warning When \p ctx->padding is set to #MBEDTLS_RSA_PKCS_V15,
698
+ * mbedtls_rsa_rsaes_pkcs1_v15_decrypt() is called, which is an
699
+ * inherently dangerous function (CWE-242). In that case, the
700
+ * return value of this function is sensitive, see the
701
+ * documentation of mbedtls_rsa_rsaes_pkcs1_v15_decrypt().
702
+ *
703
+ * \note The output buffer length \c output_max_len should be
704
+ * as large as the size \p ctx->len of \p ctx->N (for example,
705
+ * 128 Bytes if RSA-1024 is used) to be able to hold an
706
+ * arbitrary decrypted message. If it is not large enough to
707
+ * hold the decryption of the particular ciphertext provided,
708
+ * the function returns \c MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
709
+ *
710
+ * \param ctx The initialized RSA context to use.
711
+ * \param f_rng The RNG function. This is used for blinding and is
712
+ * mandatory; see mbedtls_rsa_private() for more.
713
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be
714
+ * \c NULL if \p f_rng doesn't need a context.
715
+ * \param olen The address at which to store the length of
716
+ * the plaintext. This must not be \c NULL.
717
+ * \param input The ciphertext buffer. This must be a readable buffer
718
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
719
+ * for an 2048-bit RSA modulus.
720
+ * \param output The buffer used to hold the plaintext. This must
721
+ * be a writable buffer of length \p output_max_len Bytes.
722
+ * \param output_max_len The length in Bytes of the output buffer \p output.
723
+ *
724
+ * \return \c 0 on success.
725
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
726
+ */
727
+ int mbedtls_rsa_pkcs1_decrypt(mbedtls_rsa_context *ctx,
728
+ mbedtls_f_rng_t *f_rng,
729
+ void *p_rng,
730
+ size_t *olen,
731
+ const unsigned char *input,
732
+ unsigned char *output,
733
+ size_t output_max_len);
734
+
735
+ /**
736
+ * \brief This function performs a PKCS#1 v1.5 decryption
737
+ * operation (RSAES-PKCS1-v1_5-DECRYPT).
738
+ *
739
+ * \warning This is an inherently dangerous function (CWE-242). Unless
740
+ * it is used in a side channel free and safe way,
741
+ * the calling code is vulnerable.
742
+ * Specifically, callers need to ensure an adversary cannot
743
+ * distinguish between success, MBEDTLS_ERR_RSA_INVALID_PADDING
744
+ * and MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE. Also, in the latter two
745
+ * cases, the values of the output bytes must be ignored, again
746
+ * without revealing whether that's the case.
747
+ *
748
+ * \note The output buffer length \c output_max_len should be
749
+ * as large as the size \p ctx->len of \p ctx->N, for example,
750
+ * 128 Bytes if RSA-1024 is used, to be able to hold an
751
+ * arbitrary decrypted message. If it is not large enough to
752
+ * hold the decryption of the particular ciphertext provided,
753
+ * the function returns #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
754
+ *
755
+ * \param ctx The initialized RSA context to use.
756
+ * \param f_rng The RNG function. This is used for blinding and is
757
+ * mandatory; see mbedtls_rsa_private() for more.
758
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be
759
+ * \c NULL if \p f_rng doesn't need a context.
760
+ * \param olen The address at which to store the length of
761
+ * the plaintext. This must not be \c NULL.
762
+ * \param input The ciphertext buffer. This must be a readable buffer
763
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
764
+ * for an 2048-bit RSA modulus.
765
+ * \param output The buffer used to hold the plaintext. This must
766
+ * be a writable buffer of length \p output_max_len Bytes.
767
+ * \param output_max_len The length in Bytes of the output buffer \p output.
768
+ *
769
+ * \return \c 0 on success.
770
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
771
+ *
772
+ */
773
+ int mbedtls_rsa_rsaes_pkcs1_v15_decrypt(mbedtls_rsa_context *ctx,
774
+ mbedtls_f_rng_t *f_rng,
775
+ void *p_rng,
776
+ size_t *olen,
777
+ const unsigned char *input,
778
+ unsigned char *output,
779
+ size_t output_max_len);
780
+
781
+ /**
782
+ * \brief This function performs a PKCS#1 v2.1 OAEP decryption
783
+ * operation (RSAES-OAEP-DECRYPT).
784
+ *
785
+ * \note The output buffer length \c output_max_len should be
786
+ * as large as the size \p ctx->len of \p ctx->N, for
787
+ * example, 128 Bytes if RSA-1024 is used, to be able to
788
+ * hold an arbitrary decrypted message. If it is not
789
+ * large enough to hold the decryption of the particular
790
+ * ciphertext provided, the function returns
791
+ * #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
792
+ *
793
+ * \param ctx The initialized RSA context to use.
794
+ * \param f_rng The RNG function. This is used for blinding and is
795
+ * mandatory.
796
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be
797
+ * \c NULL if \p f_rng doesn't need a context.
798
+ * \param label The buffer holding the custom label to use.
799
+ * This must be a readable buffer of length \p label_len
800
+ * Bytes. It may be \c NULL if \p label_len is \c 0.
801
+ * \param label_len The length of the label in Bytes.
802
+ * \param olen The address at which to store the length of
803
+ * the plaintext. This must not be \c NULL.
804
+ * \param input The ciphertext buffer. This must be a readable buffer
805
+ * of length \c ctx->len Bytes. For example, \c 256 Bytes
806
+ * for an 2048-bit RSA modulus.
807
+ * \param output The buffer used to hold the plaintext. This must
808
+ * be a writable buffer of length \p output_max_len Bytes.
809
+ * \param output_max_len The length in Bytes of the output buffer \p output.
810
+ *
811
+ * \return \c 0 on success.
812
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
813
+ */
814
+ int mbedtls_rsa_rsaes_oaep_decrypt(mbedtls_rsa_context *ctx,
815
+ mbedtls_f_rng_t *f_rng,
816
+ void *p_rng,
817
+ const unsigned char *label, size_t label_len,
818
+ size_t *olen,
819
+ const unsigned char *input,
820
+ unsigned char *output,
821
+ size_t output_max_len);
822
+
823
+ /**
824
+ * \brief This function performs a private RSA operation to sign
825
+ * a message digest using PKCS#1.
826
+ *
827
+ * It is the generic wrapper for performing a PKCS#1
828
+ * signature.
829
+ *
830
+ * \note The \p sig buffer must be as large as the size
831
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
832
+ *
833
+ * \note For PKCS#1 v2.1 encoding, see comments on
834
+ * mbedtls_rsa_rsassa_pss_sign() for details on
835
+ * \p md_alg and \p hash_id.
836
+ *
837
+ * \param ctx The initialized RSA context to use.
838
+ * \param f_rng The RNG function to use. This is mandatory and
839
+ * must not be \c NULL.
840
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
841
+ * if \p f_rng doesn't need a context argument.
842
+ * \param md_alg The message-digest algorithm used to hash the original data.
843
+ * Use #MBEDTLS_MD_NONE for signing raw data.
844
+ * \param hashlen The length of the message digest or raw data in Bytes.
845
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
846
+ * output length of the corresponding hash algorithm.
847
+ * \param hash The buffer holding the message digest or raw data.
848
+ * This must be a readable buffer of at least \p hashlen Bytes.
849
+ * \param sig The buffer to hold the signature. This must be a writable
850
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
851
+ * for an 2048-bit RSA modulus. A buffer length of
852
+ * #MBEDTLS_MPI_MAX_SIZE is always safe.
853
+ *
854
+ * \return \c 0 if the signing operation was successful.
855
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
856
+ */
857
+ int mbedtls_rsa_pkcs1_sign(mbedtls_rsa_context *ctx,
858
+ mbedtls_f_rng_t *f_rng,
859
+ void *p_rng,
860
+ mbedtls_md_type_t md_alg,
861
+ unsigned int hashlen,
862
+ const unsigned char *hash,
863
+ unsigned char *sig);
864
+
865
+ /**
866
+ * \brief This function performs a PKCS#1 v1.5 signature
867
+ * operation (RSASSA-PKCS1-v1_5-SIGN).
868
+ *
869
+ * \param ctx The initialized RSA context to use.
870
+ * \param f_rng The RNG function. This is used for blinding and is
871
+ * mandatory; see mbedtls_rsa_private() for more.
872
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
873
+ * if \p f_rng doesn't need a context argument.
874
+ * \param md_alg The message-digest algorithm used to hash the original data.
875
+ * Use #MBEDTLS_MD_NONE for signing raw data.
876
+ * \param hashlen The length of the message digest or raw data in Bytes.
877
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
878
+ * output length of the corresponding hash algorithm.
879
+ * \param hash The buffer holding the message digest or raw data.
880
+ * This must be a readable buffer of at least \p hashlen Bytes.
881
+ * \param sig The buffer to hold the signature. This must be a writable
882
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
883
+ * for an 2048-bit RSA modulus. A buffer length of
884
+ * #MBEDTLS_MPI_MAX_SIZE is always safe.
885
+ *
886
+ * \return \c 0 if the signing operation was successful.
887
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
888
+ */
889
+ int mbedtls_rsa_rsassa_pkcs1_v15_sign(mbedtls_rsa_context *ctx,
890
+ mbedtls_f_rng_t *f_rng,
891
+ void *p_rng,
892
+ mbedtls_md_type_t md_alg,
893
+ unsigned int hashlen,
894
+ const unsigned char *hash,
895
+ unsigned char *sig);
896
+
897
+ #if defined(MBEDTLS_PKCS1_V21)
898
+ /**
899
+ * \brief This function performs a PKCS#1 v2.1 PSS signature
900
+ * operation (RSASSA-PSS-SIGN).
901
+ *
902
+ * \note The \c hash_id set in \p ctx by calling
903
+ * mbedtls_rsa_set_padding() selects the hash used for the
904
+ * encoding operation and for the mask generation function
905
+ * (MGF1). For more details on the encoding operation and the
906
+ * mask generation function, consult <em>RFC-3447: Public-Key
907
+ * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
908
+ * Specifications</em>.
909
+ *
910
+ * \note This function enforces that the provided salt length complies
911
+ * with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1 v2.2) §9.1.1
912
+ * step 3. The constraint is that the hash length plus the salt
913
+ * length plus 2 bytes must be at most the key length. If this
914
+ * constraint is not met, this function returns
915
+ * #MBEDTLS_ERR_RSA_BAD_INPUT_DATA.
916
+ *
917
+ * \param ctx The initialized RSA context to use.
918
+ * \param f_rng The RNG function. It is mandatory and must not be \c NULL.
919
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
920
+ * if \p f_rng doesn't need a context argument.
921
+ * \param md_alg The message-digest algorithm used to hash the original data.
922
+ * Use #MBEDTLS_MD_NONE for signing raw data.
923
+ * \param hashlen The length of the message digest or raw data in Bytes.
924
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
925
+ * output length of the corresponding hash algorithm.
926
+ * \param hash The buffer holding the message digest or raw data.
927
+ * This must be a readable buffer of at least \p hashlen Bytes.
928
+ * \param saltlen The length of the salt that should be used.
929
+ * If passed #MBEDTLS_RSA_SALT_LEN_ANY, the function will use
930
+ * the largest possible salt length up to the hash length,
931
+ * which is the largest permitted by some standards including
932
+ * FIPS 186-4 §5.5.
933
+ * \param sig The buffer to hold the signature. This must be a writable
934
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
935
+ * for an 2048-bit RSA modulus. A buffer length of
936
+ * #MBEDTLS_MPI_MAX_SIZE is always safe.
937
+ *
938
+ * \return \c 0 if the signing operation was successful.
939
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
940
+ */
941
+ int mbedtls_rsa_rsassa_pss_sign_ext(mbedtls_rsa_context *ctx,
942
+ mbedtls_f_rng_t *f_rng,
943
+ void *p_rng,
944
+ mbedtls_md_type_t md_alg,
945
+ unsigned int hashlen,
946
+ const unsigned char *hash,
947
+ int saltlen,
948
+ unsigned char *sig);
949
+
950
+ /**
951
+ * \brief This function performs a PKCS#1 v2.1 PSS signature
952
+ * operation (RSASSA-PSS-SIGN).
953
+ *
954
+ * \note The \c hash_id set in \p ctx by calling
955
+ * mbedtls_rsa_set_padding() selects the hash used for the
956
+ * encoding operation and for the mask generation function
957
+ * (MGF1). For more details on the encoding operation and the
958
+ * mask generation function, consult <em>RFC-3447: Public-Key
959
+ * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
960
+ * Specifications</em>.
961
+ *
962
+ * \note This function always uses the maximum possible salt size,
963
+ * up to the length of the payload hash. This choice of salt
964
+ * size complies with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1
965
+ * v2.2) §9.1.1 step 3. Furthermore this function enforces a
966
+ * minimum salt size which is the hash size minus 2 bytes. If
967
+ * this minimum size is too large given the key size (the salt
968
+ * size, plus the hash size, plus 2 bytes must be no more than
969
+ * the key size in bytes), this function returns
970
+ * #MBEDTLS_ERR_RSA_BAD_INPUT_DATA.
971
+ *
972
+ * \param ctx The initialized RSA context to use.
973
+ * \param f_rng The RNG function. It is mandatory and must not be \c NULL.
974
+ * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
975
+ * if \p f_rng doesn't need a context argument.
976
+ * \param md_alg The message-digest algorithm used to hash the original data.
977
+ * Use #MBEDTLS_MD_NONE for signing raw data.
978
+ * \param hashlen The length of the message digest or raw data in Bytes.
979
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
980
+ * output length of the corresponding hash algorithm.
981
+ * \param hash The buffer holding the message digest or raw data.
982
+ * This must be a readable buffer of at least \p hashlen Bytes.
983
+ * \param sig The buffer to hold the signature. This must be a writable
984
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
985
+ * for an 2048-bit RSA modulus. A buffer length of
986
+ * #MBEDTLS_MPI_MAX_SIZE is always safe.
987
+ *
988
+ * \return \c 0 if the signing operation was successful.
989
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
990
+ */
991
+ int mbedtls_rsa_rsassa_pss_sign(mbedtls_rsa_context *ctx,
992
+ mbedtls_f_rng_t *f_rng,
993
+ void *p_rng,
994
+ mbedtls_md_type_t md_alg,
995
+ unsigned int hashlen,
996
+ const unsigned char *hash,
997
+ unsigned char *sig);
998
+ #endif /* MBEDTLS_PKCS1_V21 */
999
+
1000
+ /**
1001
+ * \brief This function performs a public RSA operation and checks
1002
+ * the message digest.
1003
+ *
1004
+ * This is the generic wrapper for performing a PKCS#1
1005
+ * verification.
1006
+ *
1007
+ * \note For PKCS#1 v2.1 encoding, see comments on
1008
+ * mbedtls_rsa_rsassa_pss_verify() about \c md_alg and
1009
+ * \c hash_id.
1010
+ *
1011
+ * \param ctx The initialized RSA public key context to use.
1012
+ * \param md_alg The message-digest algorithm used to hash the original data.
1013
+ * Use #MBEDTLS_MD_NONE for signing raw data.
1014
+ * \param hashlen The length of the message digest or raw data in Bytes.
1015
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
1016
+ * output length of the corresponding hash algorithm.
1017
+ * \param hash The buffer holding the message digest or raw data.
1018
+ * This must be a readable buffer of at least \p hashlen Bytes.
1019
+ * \param sig The buffer holding the signature. This must be a readable
1020
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1021
+ * for an 2048-bit RSA modulus.
1022
+ *
1023
+ * \return \c 0 if the verify operation was successful.
1024
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
1025
+ */
1026
+ int mbedtls_rsa_pkcs1_verify(mbedtls_rsa_context *ctx,
1027
+ mbedtls_md_type_t md_alg,
1028
+ unsigned int hashlen,
1029
+ const unsigned char *hash,
1030
+ const unsigned char *sig);
1031
+
1032
+ /**
1033
+ * \brief This function performs a PKCS#1 v1.5 verification
1034
+ * operation (RSASSA-PKCS1-v1_5-VERIFY).
1035
+ *
1036
+ * \param ctx The initialized RSA public key context to use.
1037
+ * \param md_alg The message-digest algorithm used to hash the original data.
1038
+ * Use #MBEDTLS_MD_NONE for signing raw data.
1039
+ * \param hashlen The length of the message digest or raw data in Bytes.
1040
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
1041
+ * output length of the corresponding hash algorithm.
1042
+ * \param hash The buffer holding the message digest or raw data.
1043
+ * This must be a readable buffer of at least \p hashlen Bytes.
1044
+ * \param sig The buffer holding the signature. This must be a readable
1045
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1046
+ * for an 2048-bit RSA modulus.
1047
+ *
1048
+ * \return \c 0 if the verify operation was successful.
1049
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
1050
+ */
1051
+ int mbedtls_rsa_rsassa_pkcs1_v15_verify(mbedtls_rsa_context *ctx,
1052
+ mbedtls_md_type_t md_alg,
1053
+ unsigned int hashlen,
1054
+ const unsigned char *hash,
1055
+ const unsigned char *sig);
1056
+
1057
+ /**
1058
+ * \brief This function performs a PKCS#1 v2.1 PSS verification
1059
+ * operation (RSASSA-PSS-VERIFY).
1060
+ *
1061
+ * \note The \c hash_id set in \p ctx by calling
1062
+ * mbedtls_rsa_set_padding() selects the hash used for the
1063
+ * encoding operation and for the mask generation function
1064
+ * (MGF1). For more details on the encoding operation and the
1065
+ * mask generation function, consult <em>RFC-3447: Public-Key
1066
+ * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
1067
+ * Specifications</em>. If the \c hash_id set in \p ctx by
1068
+ * mbedtls_rsa_set_padding() is #MBEDTLS_MD_NONE, the \p md_alg
1069
+ * parameter is used.
1070
+ *
1071
+ * \param ctx The initialized RSA public key context to use.
1072
+ * \param md_alg The message-digest algorithm used to hash the original data.
1073
+ * Use #MBEDTLS_MD_NONE for signing raw data.
1074
+ * \param hashlen The length of the message digest or raw data in Bytes.
1075
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
1076
+ * output length of the corresponding hash algorithm.
1077
+ * \param hash The buffer holding the message digest or raw data.
1078
+ * This must be a readable buffer of at least \p hashlen Bytes.
1079
+ * \param sig The buffer holding the signature. This must be a readable
1080
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1081
+ * for an 2048-bit RSA modulus.
1082
+ *
1083
+ * \return \c 0 if the verify operation was successful.
1084
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
1085
+ */
1086
+ int mbedtls_rsa_rsassa_pss_verify(mbedtls_rsa_context *ctx,
1087
+ mbedtls_md_type_t md_alg,
1088
+ unsigned int hashlen,
1089
+ const unsigned char *hash,
1090
+ const unsigned char *sig);
1091
+
1092
+ /**
1093
+ * \brief This function performs a PKCS#1 v2.1 PSS verification
1094
+ * operation (RSASSA-PSS-VERIFY).
1095
+ *
1096
+ * \note The \p sig buffer must be as large as the size
1097
+ * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
1098
+ *
1099
+ * \note The \c hash_id set in \p ctx by mbedtls_rsa_set_padding() is
1100
+ * ignored.
1101
+ *
1102
+ * \param ctx The initialized RSA public key context to use.
1103
+ * \param md_alg The message-digest algorithm used to hash the original data.
1104
+ * Use #MBEDTLS_MD_NONE for signing raw data.
1105
+ * \param hashlen The length of the message digest or raw data in Bytes.
1106
+ * If \p md_alg is not #MBEDTLS_MD_NONE, this must match the
1107
+ * output length of the corresponding hash algorithm.
1108
+ * \param hash The buffer holding the message digest or raw data.
1109
+ * This must be a readable buffer of at least \p hashlen Bytes.
1110
+ * \param mgf1_hash_id The message digest algorithm used for the
1111
+ * verification operation and the mask generation
1112
+ * function (MGF1). For more details on the encoding
1113
+ * operation and the mask generation function, consult
1114
+ * <em>RFC-3447: Public-Key Cryptography Standards
1115
+ * (PKCS) #1 v2.1: RSA Cryptography
1116
+ * Specifications</em>.
1117
+ * \param expected_salt_len The length of the salt used in padding. Use
1118
+ * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
1119
+ * \param sig The buffer holding the signature. This must be a readable
1120
+ * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1121
+ * for an 2048-bit RSA modulus.
1122
+ *
1123
+ * \return \c 0 if the verify operation was successful.
1124
+ * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
1125
+ */
1126
+ int mbedtls_rsa_rsassa_pss_verify_ext(mbedtls_rsa_context *ctx,
1127
+ mbedtls_md_type_t md_alg,
1128
+ unsigned int hashlen,
1129
+ const unsigned char *hash,
1130
+ mbedtls_md_type_t mgf1_hash_id,
1131
+ int expected_salt_len,
1132
+ const unsigned char *sig);
1133
+
1134
+ /**
1135
+ * \brief This function copies the components of an RSA context.
1136
+ *
1137
+ * \param dst The destination context. This must be initialized.
1138
+ * \param src The source context. This must be initialized.
1139
+ *
1140
+ * \return \c 0 on success.
1141
+ * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure.
1142
+ */
1143
+ int mbedtls_rsa_copy(mbedtls_rsa_context *dst, const mbedtls_rsa_context *src);
1144
+
1145
+ /**
1146
+ * \brief This function frees the components of an RSA key.
1147
+ *
1148
+ * \param ctx The RSA context to free. May be \c NULL, in which case
1149
+ * this function is a no-op. If it is not \c NULL, it must
1150
+ * point to an initialized RSA context.
1151
+ */
1152
+ void mbedtls_rsa_free(mbedtls_rsa_context *ctx);
1153
+
1154
+ #if defined(MBEDTLS_SELF_TEST)
1155
+
1156
+ /**
1157
+ * \brief The RSA checkup routine.
1158
+ *
1159
+ * \return \c 0 on success.
1160
+ * \return \c 1 on failure.
1161
+ */
1162
+ int mbedtls_rsa_self_test(int verbose);
1163
+
1164
+ #endif /* MBEDTLS_SELF_TEST */
1165
+
1166
+ #ifdef __cplusplus
1167
+ }
1168
+ #endif
1169
+
1170
+ #endif /* rsa.h */