@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,1303 @@
1
+ /**
2
+ * \file pk.h
3
+ *
4
+ * \brief Public Key abstraction layer
5
+ */
6
+ /*
7
+ * Copyright The Mbed TLS Contributors
8
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9
+ */
10
+
11
+ #ifndef MBEDTLS_PK_H
12
+ #define MBEDTLS_PK_H
13
+ #include "mbedtls/private_access.h"
14
+
15
+ #include "mbedtls/build_info.h"
16
+
17
+ #include "mbedtls/md.h"
18
+
19
+ #if defined(MBEDTLS_RSA_C)
20
+ #include "mbedtls/rsa.h"
21
+ #endif
22
+
23
+ #if defined(MBEDTLS_ECP_C)
24
+ #include "mbedtls/ecp.h"
25
+ #endif
26
+
27
+ #if defined(MBEDTLS_ECDSA_C)
28
+ #include "mbedtls/ecdsa.h"
29
+ #endif
30
+
31
+ #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
32
+ #include "psa/crypto.h"
33
+ #endif
34
+
35
+ /** Memory allocation failed. */
36
+ #define MBEDTLS_ERR_PK_ALLOC_FAILED -0x3F80
37
+ /** Type mismatch, eg attempt to encrypt with an ECDSA key */
38
+ #define MBEDTLS_ERR_PK_TYPE_MISMATCH -0x3F00
39
+ /** Bad input parameters to function. */
40
+ #define MBEDTLS_ERR_PK_BAD_INPUT_DATA -0x3E80
41
+ /** Read/write of file failed. */
42
+ #define MBEDTLS_ERR_PK_FILE_IO_ERROR -0x3E00
43
+ /** Unsupported key version */
44
+ #define MBEDTLS_ERR_PK_KEY_INVALID_VERSION -0x3D80
45
+ /** Invalid key tag or value. */
46
+ #define MBEDTLS_ERR_PK_KEY_INVALID_FORMAT -0x3D00
47
+ /** Key algorithm is unsupported (only RSA and EC are supported). */
48
+ #define MBEDTLS_ERR_PK_UNKNOWN_PK_ALG -0x3C80
49
+ /** Private key password can't be empty. */
50
+ #define MBEDTLS_ERR_PK_PASSWORD_REQUIRED -0x3C00
51
+ /** Given private key password does not allow for correct decryption. */
52
+ #define MBEDTLS_ERR_PK_PASSWORD_MISMATCH -0x3B80
53
+ /** The pubkey tag or value is invalid (only RSA and EC are supported). */
54
+ #define MBEDTLS_ERR_PK_INVALID_PUBKEY -0x3B00
55
+ /** The algorithm tag or value is invalid. */
56
+ #define MBEDTLS_ERR_PK_INVALID_ALG -0x3A80
57
+ /** Elliptic curve is unsupported (only NIST curves are supported). */
58
+ #define MBEDTLS_ERR_PK_UNKNOWN_NAMED_CURVE -0x3A00
59
+ /** Unavailable feature, e.g. RSA disabled for RSA key. */
60
+ #define MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE -0x3980
61
+ /** The buffer contains a valid signature followed by more data. */
62
+ #define MBEDTLS_ERR_PK_SIG_LEN_MISMATCH -0x3900
63
+ /** The output buffer is too small. */
64
+ #define MBEDTLS_ERR_PK_BUFFER_TOO_SMALL -0x3880
65
+
66
+ #ifdef __cplusplus
67
+ extern "C" {
68
+ #endif
69
+
70
+ /**
71
+ * \brief Public key types
72
+ */
73
+ typedef enum {
74
+ MBEDTLS_PK_NONE=0,
75
+ MBEDTLS_PK_RSA,
76
+ MBEDTLS_PK_ECKEY,
77
+ MBEDTLS_PK_ECKEY_DH,
78
+ MBEDTLS_PK_ECDSA,
79
+ MBEDTLS_PK_RSA_ALT,
80
+ MBEDTLS_PK_RSASSA_PSS,
81
+ MBEDTLS_PK_OPAQUE,
82
+ } mbedtls_pk_type_t;
83
+
84
+ /**
85
+ * \brief Options for RSASSA-PSS signature verification.
86
+ * See \c mbedtls_rsa_rsassa_pss_verify_ext()
87
+ */
88
+ typedef struct mbedtls_pk_rsassa_pss_options {
89
+ /** The digest to use for MGF1 in PSS.
90
+ *
91
+ * \note When #MBEDTLS_USE_PSA_CRYPTO is enabled and #MBEDTLS_RSA_C is
92
+ * disabled, this must be equal to the \c md_alg argument passed
93
+ * to mbedtls_pk_verify_ext(). In a future version of the library,
94
+ * this constraint may apply whenever #MBEDTLS_USE_PSA_CRYPTO is
95
+ * enabled regardless of the status of #MBEDTLS_RSA_C.
96
+ */
97
+ mbedtls_md_type_t mgf1_hash_id;
98
+
99
+ /** The expected length of the salt, in bytes. This may be
100
+ * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
101
+ *
102
+ * \note When #MBEDTLS_USE_PSA_CRYPTO is enabled, only
103
+ * #MBEDTLS_RSA_SALT_LEN_ANY is valid. Any other value may be
104
+ * ignored (allowing any salt length).
105
+ */
106
+ int expected_salt_len;
107
+
108
+ } mbedtls_pk_rsassa_pss_options;
109
+
110
+ /**
111
+ * \brief Maximum size of a signature made by mbedtls_pk_sign().
112
+ */
113
+ /* We need to set MBEDTLS_PK_SIGNATURE_MAX_SIZE to the maximum signature
114
+ * size among the supported signature types. Do it by starting at 0,
115
+ * then incrementally increasing to be large enough for each supported
116
+ * signature mechanism.
117
+ *
118
+ * The resulting value can be 0, for example if MBEDTLS_ECDH_C is enabled
119
+ * (which allows the pk module to be included) but neither MBEDTLS_ECDSA_C
120
+ * nor MBEDTLS_RSA_C nor any opaque signature mechanism (PSA or RSA_ALT).
121
+ */
122
+ #define MBEDTLS_PK_SIGNATURE_MAX_SIZE 0
123
+
124
+ #if (defined(MBEDTLS_RSA_C) || defined(MBEDTLS_PK_RSA_ALT_SUPPORT)) && \
125
+ MBEDTLS_MPI_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
126
+ /* For RSA, the signature can be as large as the bignum module allows.
127
+ * For RSA_ALT, the signature size is not necessarily tied to what the
128
+ * bignum module can do, but in the absence of any specific setting,
129
+ * we use that (rsa_alt_sign_wrap in library/pk_wrap.h will check). */
130
+ #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
131
+ #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_MPI_MAX_SIZE
132
+ #endif
133
+
134
+ #if defined(MBEDTLS_ECDSA_C) && \
135
+ MBEDTLS_ECDSA_MAX_LEN > MBEDTLS_PK_SIGNATURE_MAX_SIZE
136
+ /* For ECDSA, the ecdsa module exports a constant for the maximum
137
+ * signature size. */
138
+ #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
139
+ #define MBEDTLS_PK_SIGNATURE_MAX_SIZE MBEDTLS_ECDSA_MAX_LEN
140
+ #endif
141
+
142
+ #if defined(MBEDTLS_USE_PSA_CRYPTO)
143
+ #if PSA_SIGNATURE_MAX_SIZE > MBEDTLS_PK_SIGNATURE_MAX_SIZE
144
+ /* PSA_SIGNATURE_MAX_SIZE is the maximum size of a signature made
145
+ * through the PSA API in the PSA representation. */
146
+ #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
147
+ #define MBEDTLS_PK_SIGNATURE_MAX_SIZE PSA_SIGNATURE_MAX_SIZE
148
+ #endif
149
+
150
+ #if PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11 > MBEDTLS_PK_SIGNATURE_MAX_SIZE
151
+ /* The Mbed TLS representation is different for ECDSA signatures:
152
+ * PSA uses the raw concatenation of r and s,
153
+ * whereas Mbed TLS uses the ASN.1 representation (SEQUENCE of two INTEGERs).
154
+ * Add the overhead of ASN.1: up to (1+2) + 2 * (1+2+1) for the
155
+ * types, lengths (represented by up to 2 bytes), and potential leading
156
+ * zeros of the INTEGERs and the SEQUENCE. */
157
+ #undef MBEDTLS_PK_SIGNATURE_MAX_SIZE
158
+ #define MBEDTLS_PK_SIGNATURE_MAX_SIZE (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE + 11)
159
+ #endif
160
+ #endif /* defined(MBEDTLS_USE_PSA_CRYPTO) */
161
+
162
+ /* Internal helper to define which fields in the pk_context structure below
163
+ * should be used for EC keys: legacy ecp_keypair or the raw (PSA friendly)
164
+ * format. It should be noted that this only affects how data is stored, not
165
+ * which functions are used for various operations. The overall picture looks
166
+ * like this:
167
+ * - if USE_PSA is not defined and ECP_C is defined then use ecp_keypair data
168
+ * structure and legacy functions
169
+ * - if USE_PSA is defined and
170
+ * - if ECP_C then use ecp_keypair structure, convert data to a PSA friendly
171
+ * format and use PSA functions
172
+ * - if !ECP_C then use new raw data and PSA functions directly.
173
+ *
174
+ * The main reason for the "intermediate" (USE_PSA + ECP_C) above is that as long
175
+ * as ECP_C is defined mbedtls_pk_ec() gives the user a read/write access to the
176
+ * ecp_keypair structure inside the pk_context so they can modify it using
177
+ * ECP functions which are not under PK module's control.
178
+ */
179
+ #if defined(MBEDTLS_USE_PSA_CRYPTO) && defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \
180
+ !defined(MBEDTLS_ECP_C)
181
+ #define MBEDTLS_PK_USE_PSA_EC_DATA
182
+ #endif
183
+
184
+ /**
185
+ * \brief Types for interfacing with the debug module
186
+ */
187
+ typedef enum {
188
+ MBEDTLS_PK_DEBUG_NONE = 0,
189
+ MBEDTLS_PK_DEBUG_MPI,
190
+ MBEDTLS_PK_DEBUG_ECP,
191
+ MBEDTLS_PK_DEBUG_PSA_EC,
192
+ } mbedtls_pk_debug_type;
193
+
194
+ /**
195
+ * \brief Item to send to the debug module
196
+ */
197
+ typedef struct mbedtls_pk_debug_item {
198
+ mbedtls_pk_debug_type MBEDTLS_PRIVATE(type);
199
+ const char *MBEDTLS_PRIVATE(name);
200
+ void *MBEDTLS_PRIVATE(value);
201
+ } mbedtls_pk_debug_item;
202
+
203
+ /** Maximum number of item send for debugging, plus 1 */
204
+ #define MBEDTLS_PK_DEBUG_MAX_ITEMS 3
205
+
206
+ /**
207
+ * \brief Public key information and operations
208
+ *
209
+ * \note The library does not support custom pk info structures,
210
+ * only built-in structures returned by
211
+ * mbedtls_cipher_info_from_type().
212
+ */
213
+ typedef struct mbedtls_pk_info_t mbedtls_pk_info_t;
214
+
215
+ #define MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN \
216
+ PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
217
+ /**
218
+ * \brief Public key container
219
+ */
220
+ typedef struct mbedtls_pk_context {
221
+ /** Method table */
222
+ const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info);
223
+ /** Underlying type-specific key context */
224
+ void *MBEDTLS_PRIVATE(pk_ctx);
225
+
226
+ /* The following field is used to store the ID of a private key in the
227
+ * following cases:
228
+ * - opaque key when MBEDTLS_USE_PSA_CRYPTO is defined
229
+ * - normal key when MBEDTLS_PK_USE_PSA_EC_DATA is defined. In this case:
230
+ * - the pk_ctx above is not not used to store the private key anymore.
231
+ * Actually that field not populated at all in this case because also
232
+ * the public key will be stored in raw format as explained below
233
+ * - this ID is used for all private key operations (ex: sign, check
234
+ * key pair, key write, etc) using PSA functions
235
+ *
236
+ * Note: this private key storing solution only affects EC keys, not the
237
+ * other ones. The latters still use the pk_ctx to store their own
238
+ * context. */
239
+ #if defined(MBEDTLS_USE_PSA_CRYPTO)
240
+ mbedtls_svc_key_id_t MBEDTLS_PRIVATE(priv_id); /**< Key ID for opaque keys */
241
+ #endif /* MBEDTLS_USE_PSA_CRYPTO */
242
+ /* The following fields are meant for storing the public key in raw format
243
+ * which is handy for:
244
+ * - easily importing it into the PSA context
245
+ * - reducing the ECP module dependencies in the PK one.
246
+ *
247
+ * When MBEDTLS_PK_USE_PSA_EC_DATA is enabled:
248
+ * - the pk_ctx above is not used anymore for storing the public key
249
+ * inside the ecp_keypair structure
250
+ * - the following fields are used for all public key operations: signature
251
+ * verify, key pair check and key write.
252
+ * - For a key pair, priv_id contains the private key. For a public key,
253
+ * priv_id is null.
254
+ * Of course, when MBEDTLS_PK_USE_PSA_EC_DATA is not enabled, the legacy
255
+ * ecp_keypair structure is used for storing the public key and performing
256
+ * all the operations.
257
+ *
258
+ * Note: This new public key storing solution only works for EC keys, not
259
+ * other ones. The latters still use pk_ctx to store their own
260
+ * context.
261
+ */
262
+ #if defined(MBEDTLS_PK_USE_PSA_EC_DATA)
263
+ uint8_t MBEDTLS_PRIVATE(pub_raw)[MBEDTLS_PK_MAX_EC_PUBKEY_RAW_LEN]; /**< Raw public key */
264
+ size_t MBEDTLS_PRIVATE(pub_raw_len); /**< Valid bytes in "pub_raw" */
265
+ psa_ecc_family_t MBEDTLS_PRIVATE(ec_family); /**< EC family of pk */
266
+ size_t MBEDTLS_PRIVATE(ec_bits); /**< Curve's bits of pk */
267
+ #endif /* MBEDTLS_PK_USE_PSA_EC_DATA */
268
+ } mbedtls_pk_context;
269
+
270
+ #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
271
+ /**
272
+ * \brief Context for resuming operations
273
+ */
274
+ typedef struct {
275
+ const mbedtls_pk_info_t *MBEDTLS_PRIVATE(pk_info); /**< Public key information */
276
+ void *MBEDTLS_PRIVATE(rs_ctx); /**< Underlying restart context */
277
+ } mbedtls_pk_restart_ctx;
278
+ #else /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
279
+ /* Now we can declare functions that take a pointer to that */
280
+ typedef void mbedtls_pk_restart_ctx;
281
+ #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
282
+
283
+ #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
284
+ /**
285
+ * \brief Types for RSA-alt abstraction
286
+ */
287
+ typedef int (*mbedtls_pk_rsa_alt_decrypt_func)(void *ctx, size_t *olen,
288
+ const unsigned char *input, unsigned char *output,
289
+ size_t output_max_len);
290
+ typedef int (*mbedtls_pk_rsa_alt_sign_func)(void *ctx,
291
+ mbedtls_f_rng_t *f_rng,
292
+ void *p_rng,
293
+ mbedtls_md_type_t md_alg, unsigned int hashlen,
294
+ const unsigned char *hash, unsigned char *sig);
295
+ typedef size_t (*mbedtls_pk_rsa_alt_key_len_func)(void *ctx);
296
+ #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
297
+
298
+ /**
299
+ * \brief Return information associated with the given PK type
300
+ *
301
+ * \param pk_type PK type to search for.
302
+ *
303
+ * \return The PK info associated with the type or NULL if not found.
304
+ */
305
+ const mbedtls_pk_info_t *mbedtls_pk_info_from_type(mbedtls_pk_type_t pk_type);
306
+
307
+ /**
308
+ * \brief Initialize a #mbedtls_pk_context (as NONE).
309
+ *
310
+ * \param ctx The context to initialize.
311
+ * This must not be \c NULL.
312
+ */
313
+ void mbedtls_pk_init(mbedtls_pk_context *ctx);
314
+
315
+ /**
316
+ * \brief Free the components of a #mbedtls_pk_context.
317
+ *
318
+ * \param ctx The context to clear. It must have been initialized.
319
+ * If this is \c NULL, this function does nothing.
320
+ *
321
+ * \note For contexts that have been set up with
322
+ * mbedtls_pk_setup_opaque(), this does not free the underlying
323
+ * PSA key and you still need to call psa_destroy_key()
324
+ * independently if you want to destroy that key.
325
+ */
326
+ void mbedtls_pk_free(mbedtls_pk_context *ctx);
327
+
328
+ #if defined(MBEDTLS_ECDSA_C) && defined(MBEDTLS_ECP_RESTARTABLE)
329
+ /**
330
+ * \brief Initialize a restart context
331
+ *
332
+ * \param ctx The context to initialize.
333
+ * This must not be \c NULL.
334
+ */
335
+ void mbedtls_pk_restart_init(mbedtls_pk_restart_ctx *ctx);
336
+
337
+ /**
338
+ * \brief Free the components of a restart context
339
+ *
340
+ * \param ctx The context to clear. It must have been initialized.
341
+ * If this is \c NULL, this function does nothing.
342
+ */
343
+ void mbedtls_pk_restart_free(mbedtls_pk_restart_ctx *ctx);
344
+ #endif /* MBEDTLS_ECDSA_C && MBEDTLS_ECP_RESTARTABLE */
345
+
346
+ /**
347
+ * \brief Initialize a PK context with the information given
348
+ * and allocates the type-specific PK subcontext.
349
+ *
350
+ * \param ctx Context to initialize. It must not have been set
351
+ * up yet (type #MBEDTLS_PK_NONE).
352
+ * \param info Information to use
353
+ *
354
+ * \return 0 on success,
355
+ * MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input,
356
+ * MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
357
+ *
358
+ * \note For contexts holding an RSA-alt key, use
359
+ * \c mbedtls_pk_setup_rsa_alt() instead.
360
+ */
361
+ int mbedtls_pk_setup(mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info);
362
+
363
+ #if defined(MBEDTLS_USE_PSA_CRYPTO)
364
+ /**
365
+ * \brief Initialize a PK context to wrap a PSA key.
366
+ *
367
+ * This function creates a PK context which wraps a PSA key. The PSA wrapped
368
+ * key must be an EC or RSA key pair (DH is not suported in the PK module).
369
+ *
370
+ * Under the hood PSA functions will be used to perform the required
371
+ * operations and, based on the key type, used algorithms will be:
372
+ * * EC:
373
+ * * verify, verify_ext, sign, sign_ext: ECDSA.
374
+ * * RSA:
375
+ * * sign, decrypt: use the primary algorithm in the wrapped PSA key;
376
+ * * sign_ext: RSA PSS if the pk_type is #MBEDTLS_PK_RSASSA_PSS, otherwise
377
+ * it falls back to the sign() case;
378
+ * * verify, verify_ext, encrypt: not supported.
379
+ *
380
+ * In order for the above operations to succeed, the policy of the wrapped PSA
381
+ * key must allow the specified algorithm.
382
+ *
383
+ * Opaque PK contexts wrapping an EC keys also support \c mbedtls_pk_check_pair(),
384
+ * whereas RSA ones do not.
385
+ *
386
+ * \warning The PSA wrapped key must remain valid as long as the wrapping PK
387
+ * context is in use, that is at least between the point this function
388
+ * is called and the point mbedtls_pk_free() is called on this context.
389
+ *
390
+ * \param ctx The context to initialize. It must be empty (type NONE).
391
+ * \param key The PSA key to wrap, which must hold an ECC or RSA key pair.
392
+ *
393
+ * \return \c 0 on success.
394
+ * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA on invalid input (context already
395
+ * used, invalid key identifier).
396
+ * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the key is not an ECC or
397
+ * RSA key pair.
398
+ * \return #MBEDTLS_ERR_PK_ALLOC_FAILED on allocation failure.
399
+ */
400
+ int mbedtls_pk_setup_opaque(mbedtls_pk_context *ctx,
401
+ const mbedtls_svc_key_id_t key);
402
+ #endif /* MBEDTLS_USE_PSA_CRYPTO */
403
+
404
+ #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
405
+ /**
406
+ * \brief Initialize an RSA-alt context
407
+ *
408
+ * \param ctx Context to initialize. It must not have been set
409
+ * up yet (type #MBEDTLS_PK_NONE).
410
+ * \param key RSA key pointer
411
+ * \param decrypt_func Decryption function
412
+ * \param sign_func Signing function
413
+ * \param key_len_func Function returning key length in bytes
414
+ *
415
+ * \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
416
+ * context wasn't already initialized as RSA_ALT.
417
+ *
418
+ * \note This function replaces \c mbedtls_pk_setup() for RSA-alt.
419
+ */
420
+ int mbedtls_pk_setup_rsa_alt(mbedtls_pk_context *ctx, void *key,
421
+ mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
422
+ mbedtls_pk_rsa_alt_sign_func sign_func,
423
+ mbedtls_pk_rsa_alt_key_len_func key_len_func);
424
+ #endif /* MBEDTLS_PK_RSA_ALT_SUPPORT */
425
+
426
+ /**
427
+ * \brief Get the size in bits of the underlying key
428
+ *
429
+ * \param ctx The context to query. It must have been initialized.
430
+ *
431
+ * \return Key size in bits, or 0 on error
432
+ */
433
+ size_t mbedtls_pk_get_bitlen(const mbedtls_pk_context *ctx);
434
+
435
+ /**
436
+ * \brief Get the length in bytes of the underlying key
437
+ *
438
+ * \param ctx The context to query. It must have been initialized.
439
+ *
440
+ * \return Key length in bytes, or 0 on error
441
+ */
442
+ static inline size_t mbedtls_pk_get_len(const mbedtls_pk_context *ctx)
443
+ {
444
+ return (mbedtls_pk_get_bitlen(ctx) + 7) / 8;
445
+ }
446
+
447
+ /**
448
+ * \brief Tell if a context can do the operation given by type
449
+ *
450
+ * \param ctx The context to query. It must have been initialized.
451
+ * \param type The desired type.
452
+ *
453
+ * \return 1 if the context can do operations on the given type.
454
+ * \return 0 if the context cannot do the operations on the given
455
+ * type. This is always the case for a context that has
456
+ * been initialized but not set up, or that has been
457
+ * cleared with mbedtls_pk_free().
458
+ */
459
+ int mbedtls_pk_can_do(const mbedtls_pk_context *ctx, mbedtls_pk_type_t type);
460
+
461
+ #if defined(MBEDTLS_USE_PSA_CRYPTO)
462
+ /**
463
+ * \brief Tell if context can do the operation given by PSA algorithm
464
+ *
465
+ * \param ctx The context to query. It must have been initialized.
466
+ * \param alg PSA algorithm to check against, the following are allowed:
467
+ * PSA_ALG_RSA_PKCS1V15_SIGN(hash),
468
+ * PSA_ALG_RSA_PSS(hash),
469
+ * PSA_ALG_RSA_PKCS1V15_CRYPT,
470
+ * PSA_ALG_ECDSA(hash),
471
+ * PSA_ALG_ECDH, where hash is a specific hash.
472
+ * \param usage PSA usage flag to check against, must be composed of:
473
+ * PSA_KEY_USAGE_SIGN_HASH
474
+ * PSA_KEY_USAGE_DECRYPT
475
+ * PSA_KEY_USAGE_DERIVE.
476
+ * Context key must match all passed usage flags.
477
+ *
478
+ * \warning Since the set of allowed algorithms and usage flags may be
479
+ * expanded in the future, the return value \c 0 should not
480
+ * be taken in account for non-allowed algorithms and usage
481
+ * flags.
482
+ *
483
+ * \return 1 if the context can do operations on the given type.
484
+ * \return 0 if the context cannot do the operations on the given
485
+ * type, for non-allowed algorithms and usage flags, or
486
+ * for a context that has been initialized but not set up
487
+ * or that has been cleared with mbedtls_pk_free().
488
+ */
489
+ int mbedtls_pk_can_do_ext(const mbedtls_pk_context *ctx, psa_algorithm_t alg,
490
+ psa_key_usage_t usage);
491
+ #endif /* MBEDTLS_USE_PSA_CRYPTO */
492
+
493
+ #if defined(MBEDTLS_PSA_CRYPTO_CLIENT)
494
+ /**
495
+ * \brief Determine valid PSA attributes that can be used to
496
+ * import a key into PSA.
497
+ *
498
+ * The attributes determined by this function are suitable
499
+ * for calling mbedtls_pk_import_into_psa() to create
500
+ * a PSA key with the same key material.
501
+ *
502
+ * The typical flow of operations involving this function is
503
+ * ```
504
+ * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
505
+ * int ret = mbedtls_pk_get_psa_attributes(pk, &attributes);
506
+ * if (ret != 0) ...; // error handling omitted
507
+ * // Tweak attributes if desired
508
+ * psa_key_id_t key_id = 0;
509
+ * ret = mbedtls_pk_import_into_psa(pk, &attributes, &key_id);
510
+ * if (ret != 0) ...; // error handling omitted
511
+ * ```
512
+ *
513
+ * \note This function does not support RSA-alt contexts
514
+ * (set up with mbedtls_pk_setup_rsa_alt()).
515
+ *
516
+ * \param[in] pk The PK context to use. It must have been set up.
517
+ * It can either contain a key pair or just a public key.
518
+ * \param usage A single `PSA_KEY_USAGE_xxx` flag among the following:
519
+ * - #PSA_KEY_USAGE_DECRYPT: \p pk must contain a
520
+ * key pair. The output \p attributes will contain a
521
+ * key pair type, and the usage policy will allow
522
+ * #PSA_KEY_USAGE_ENCRYPT as well as
523
+ * #PSA_KEY_USAGE_DECRYPT.
524
+ * - #PSA_KEY_USAGE_DERIVE: \p pk must contain a
525
+ * key pair. The output \p attributes will contain a
526
+ * key pair type.
527
+ * - #PSA_KEY_USAGE_ENCRYPT: The output
528
+ * \p attributes will contain a public key type.
529
+ * - #PSA_KEY_USAGE_SIGN_HASH: \p pk must contain a
530
+ * key pair. The output \p attributes will contain a
531
+ * key pair type, and the usage policy will allow
532
+ * #PSA_KEY_USAGE_VERIFY_HASH as well as
533
+ * #PSA_KEY_USAGE_SIGN_HASH.
534
+ * - #PSA_KEY_USAGE_SIGN_MESSAGE: \p pk must contain a
535
+ * key pair. The output \p attributes will contain a
536
+ * key pair type, and the usage policy will allow
537
+ * #PSA_KEY_USAGE_VERIFY_MESSAGE as well as
538
+ * #PSA_KEY_USAGE_SIGN_MESSAGE.
539
+ * - #PSA_KEY_USAGE_VERIFY_HASH: The output
540
+ * \p attributes will contain a public key type.
541
+ * - #PSA_KEY_USAGE_VERIFY_MESSAGE: The output
542
+ * \p attributes will contain a public key type.
543
+ * \param[out] attributes
544
+ * On success, valid attributes to import the key into PSA.
545
+ * - The lifetime and key identifier are unchanged. If the
546
+ * attribute structure was initialized or reset before
547
+ * calling this function, this will result in a volatile
548
+ * key. Call psa_set_key_identifier() before or after this
549
+ * function if you wish to create a persistent key. Call
550
+ * psa_set_key_lifetime() before or after this function if
551
+ * you wish to import the key in a secure element.
552
+ * - The key type and bit-size are determined by the contents
553
+ * of the PK context. If the PK context contains a key
554
+ * pair, the key type can be either a key pair type or
555
+ * the corresponding public key type, depending on
556
+ * \p usage. If the PK context contains a public key,
557
+ * the key type is a public key type.
558
+ * - The key's policy is determined by the key type and
559
+ * the \p usage parameter. The usage always allows
560
+ * \p usage, exporting and copying the key, and
561
+ * possibly other permissions as documented for the
562
+ * \p usage parameter.
563
+ * The permitted algorithm policy is determined as follows
564
+ * based on the #mbedtls_pk_type_t type of \p pk,
565
+ * the chosen \p usage and other factors:
566
+ * - #MBEDTLS_PK_RSA whose underlying
567
+ * #mbedtls_rsa_context has the padding mode
568
+ * #MBEDTLS_RSA_PKCS_V15:
569
+ * #PSA_ALG_RSA_PKCS1V15_SIGN(#PSA_ALG_ANY_HASH)
570
+ * if \p usage is SIGN/VERIFY, and
571
+ * #PSA_ALG_RSA_PKCS1V15_CRYPT
572
+ * if \p usage is ENCRYPT/DECRYPT.
573
+ * - #MBEDTLS_PK_RSA whose underlying
574
+ * #mbedtls_rsa_context has the padding mode
575
+ * #MBEDTLS_RSA_PKCS_V21 and the digest type
576
+ * corresponding to the PSA algorithm \c hash:
577
+ * #PSA_ALG_RSA_PSS_ANY_SALT(#PSA_ALG_ANY_HASH)
578
+ * if \p usage is SIGN/VERIFY, and
579
+ * #PSA_ALG_RSA_OAEP(\c hash)
580
+ * if \p usage is ENCRYPT/DECRYPT.
581
+ * - #MBEDTLS_PK_RSA_ALT: not supported.
582
+ * - #MBEDTLS_PK_ECDSA or #MBEDTLS_PK_ECKEY
583
+ * if \p usage is SIGN/VERIFY:
584
+ * #PSA_ALG_DETERMINISTIC_ECDSA(#PSA_ALG_ANY_HASH)
585
+ * if #MBEDTLS_ECDSA_DETERMINISTIC is enabled,
586
+ * otherwise #PSA_ALG_ECDSA(#PSA_ALG_ANY_HASH).
587
+ * - #MBEDTLS_PK_ECKEY_DH or #MBEDTLS_PK_ECKEY
588
+ * if \p usage is DERIVE:
589
+ * #PSA_ALG_ECDH.
590
+ * - #MBEDTLS_PK_OPAQUE: same as the primary algorithm
591
+ * set for the underlying PSA key, except that
592
+ * sign/decrypt flags are removed if the type is
593
+ * set to a public key type.
594
+ * The underlying key must allow \p usage.
595
+ * Note that the enrollment algorithm set with
596
+ * psa_set_key_enrollment_algorithm() is not copied.
597
+ *
598
+ * \return 0 on success.
599
+ * #MBEDTLS_ERR_PK_TYPE_MISMATCH if \p pk does not contain
600
+ * a key of the type identified in \p attributes.
601
+ * Another error code on other failures.
602
+ */
603
+ int mbedtls_pk_get_psa_attributes(const mbedtls_pk_context *pk,
604
+ psa_key_usage_t usage,
605
+ psa_key_attributes_t *attributes);
606
+
607
+ /**
608
+ * \brief Import a key into the PSA key store.
609
+ *
610
+ * This function is equivalent to calling psa_import_key()
611
+ * with the key material from \p pk.
612
+ *
613
+ * The typical way to use this function is:
614
+ * -# Call mbedtls_pk_get_psa_attributes() to obtain
615
+ * attributes for the given key.
616
+ * -# If desired, modify the attributes, for example:
617
+ * - To create a persistent key, call
618
+ * psa_set_key_identifier() and optionally
619
+ * psa_set_key_lifetime().
620
+ * - To import only the public part of a key pair:
621
+ *
622
+ * psa_set_key_type(&attributes,
623
+ * PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(
624
+ * psa_get_key_type(&attributes)));
625
+ * - Restrict the key usage if desired.
626
+ * -# Call mbedtls_pk_import_into_psa().
627
+ *
628
+ * \note This function does not support RSA-alt contexts
629
+ * (set up with mbedtls_pk_setup_rsa_alt()).
630
+ *
631
+ * \param[in] pk The PK context to use. It must have been set up.
632
+ * It can either contain a key pair or just a public key.
633
+ * \param[in] attributes
634
+ * The attributes to use for the new key. They must be
635
+ * compatible with \p pk. In particular, the key type
636
+ * must match the content of \p pk.
637
+ * If \p pk contains a key pair, the key type in
638
+ * attributes can be either the key pair type or the
639
+ * corresponding public key type (to import only the
640
+ * public part).
641
+ * \param[out] key_id
642
+ * On success, the identifier of the newly created key.
643
+ * On error, this is #MBEDTLS_SVC_KEY_ID_INIT.
644
+ *
645
+ * \return 0 on success.
646
+ * #MBEDTLS_ERR_PK_TYPE_MISMATCH if \p pk does not contain
647
+ * a key of the type identified in \p attributes.
648
+ * Another error code on other failures.
649
+ */
650
+ int mbedtls_pk_import_into_psa(const mbedtls_pk_context *pk,
651
+ const psa_key_attributes_t *attributes,
652
+ mbedtls_svc_key_id_t *key_id);
653
+
654
+ /**
655
+ * \brief Create a PK context starting from a key stored in PSA.
656
+ * This key:
657
+ * - must be exportable and
658
+ * - must be an RSA or EC key pair or public key (FFDH is not supported in PK).
659
+ *
660
+ * The resulting PK object will be a transparent type:
661
+ * - #MBEDTLS_PK_RSA for RSA keys or
662
+ * - #MBEDTLS_PK_ECKEY for EC keys.
663
+ *
664
+ * Once this functions returns the PK object will be completely
665
+ * independent from the original PSA key that it was generated
666
+ * from.
667
+ * Calling mbedtls_pk_sign(), mbedtls_pk_verify(),
668
+ * mbedtls_pk_encrypt(), mbedtls_pk_decrypt() on the resulting
669
+ * PK context will perform the corresponding algorithm for that
670
+ * PK context type.
671
+ * * For ECDSA, the choice of deterministic vs randomized will
672
+ * be based on the compile-time setting #MBEDTLS_ECDSA_DETERMINISTIC.
673
+ * * For an RSA key, the output PK context will allow both
674
+ * encrypt/decrypt and sign/verify regardless of the original
675
+ * key's policy.
676
+ * The original key's policy determines the output key's padding
677
+ * mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS,
678
+ * otherwise PKCS1 v1.5 is set.
679
+ *
680
+ * \param key_id The key identifier of the key stored in PSA.
681
+ * \param pk The PK context that will be filled. It must be initialized,
682
+ * but not set up.
683
+ *
684
+ * \return 0 on success.
685
+ * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA in case the provided input
686
+ * parameters are not correct.
687
+ */
688
+ int mbedtls_pk_copy_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk);
689
+
690
+ /**
691
+ * \brief Create a PK context for the public key of a PSA key.
692
+ *
693
+ * The key must be an RSA or ECC key. It can be either a
694
+ * public key or a key pair, and only the public key is copied.
695
+ * The resulting PK object will be a transparent type:
696
+ * - #MBEDTLS_PK_RSA for RSA keys or
697
+ * - #MBEDTLS_PK_ECKEY for EC keys.
698
+ *
699
+ * Once this functions returns the PK object will be completely
700
+ * independent from the original PSA key that it was generated
701
+ * from.
702
+ * Calling mbedtls_pk_verify() or
703
+ * mbedtls_pk_encrypt() on the resulting
704
+ * PK context will perform the corresponding algorithm for that
705
+ * PK context type.
706
+ *
707
+ * For an RSA key, the output PK context will allow both
708
+ * encrypt and verify regardless of the original key's policy.
709
+ * The original key's policy determines the output key's padding
710
+ * mode: PCKS1 v2.1 is set if the PSA key policy is OAEP or PSS,
711
+ * otherwise PKCS1 v1.5 is set.
712
+ *
713
+ * \param key_id The key identifier of the key stored in PSA.
714
+ * \param pk The PK context that will be filled. It must be initialized,
715
+ * but not set up.
716
+ *
717
+ * \return 0 on success.
718
+ * \return MBEDTLS_ERR_PK_BAD_INPUT_DATA in case the provided input
719
+ * parameters are not correct.
720
+ */
721
+ int mbedtls_pk_copy_public_from_psa(mbedtls_svc_key_id_t key_id, mbedtls_pk_context *pk);
722
+ #endif /* MBEDTLS_PSA_CRYPTO_CLIENT */
723
+
724
+ /**
725
+ * \brief Verify signature (including padding if relevant).
726
+ *
727
+ * \param ctx The PK context to use. It must have been set up.
728
+ * \param md_alg Hash algorithm used.
729
+ * This can be #MBEDTLS_MD_NONE if the signature algorithm
730
+ * does not rely on a hash algorithm (non-deterministic
731
+ * ECDSA, RSA PKCS#1 v1.5).
732
+ * For PKCS#1 v1.5, if \p md_alg is #MBEDTLS_MD_NONE, then
733
+ * \p hash is the DigestInfo structure used by RFC 8017
734
+ * &sect;9.2 steps 3&ndash;6. If \p md_alg is a valid hash
735
+ * algorithm then \p hash is the digest itself, and this
736
+ * function calculates the DigestInfo encoding internally.
737
+ * \param hash Hash of the message to sign
738
+ * \param hash_len Hash length
739
+ * \param sig Signature to verify
740
+ * \param sig_len Signature length
741
+ *
742
+ * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
743
+ * either PKCS#1 v1.5 or PSS (accepting any salt length),
744
+ * depending on the padding mode in the underlying RSA context.
745
+ * For a pk object constructed by parsing, this is PKCS#1 v1.5
746
+ * by default. Use mbedtls_pk_verify_ext() to explicitly select
747
+ * a different algorithm.
748
+ *
749
+ * \return 0 on success (signature is valid),
750
+ * #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
751
+ * signature in \p sig but its length is less than \p sig_len,
752
+ * or a specific error code.
753
+ */
754
+ int mbedtls_pk_verify(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
755
+ const unsigned char *hash, size_t hash_len,
756
+ const unsigned char *sig, size_t sig_len);
757
+
758
+ /**
759
+ * \brief Restartable version of \c mbedtls_pk_verify()
760
+ *
761
+ * \note Performs the same job as \c mbedtls_pk_verify(), but can
762
+ * return early and restart according to the limit set with
763
+ * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC
764
+ * operations. For RSA, same as \c mbedtls_pk_verify().
765
+ *
766
+ * \param ctx The PK context to use. It must have been set up.
767
+ * \param md_alg Hash algorithm used (see notes)
768
+ * \param hash Hash of the message to sign
769
+ * \param hash_len Hash length or 0 (see notes)
770
+ * \param sig Signature to verify
771
+ * \param sig_len Signature length
772
+ * \param rs_ctx Restart context (NULL to disable restart)
773
+ *
774
+ * \return See \c mbedtls_pk_verify(), or
775
+ * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
776
+ * operations was reached: see \c mbedtls_ecp_set_max_ops().
777
+ */
778
+ int mbedtls_pk_verify_restartable(mbedtls_pk_context *ctx,
779
+ mbedtls_md_type_t md_alg,
780
+ const unsigned char *hash, size_t hash_len,
781
+ const unsigned char *sig, size_t sig_len,
782
+ mbedtls_pk_restart_ctx *rs_ctx);
783
+
784
+ /**
785
+ * \brief Verify signature, with options.
786
+ * (Includes verification of the padding depending on type.)
787
+ *
788
+ * \param type Signature type (inc. possible padding type) to verify
789
+ * \param options Pointer to type-specific options, or NULL
790
+ * \param ctx The PK context to use. It must have been set up.
791
+ * \param md_alg Hash algorithm used (see notes)
792
+ * \param hash Hash of the message to sign
793
+ * \param hash_len Hash length or 0 (see notes)
794
+ * \param sig Signature to verify
795
+ * \param sig_len Signature length
796
+ *
797
+ * \return 0 on success (signature is valid),
798
+ * #MBEDTLS_ERR_PK_TYPE_MISMATCH if the PK context can't be
799
+ * used for this type of signatures,
800
+ * #MBEDTLS_ERR_PK_SIG_LEN_MISMATCH if there is a valid
801
+ * signature in \p sig but its length is less than \p sig_len,
802
+ * or a specific error code.
803
+ *
804
+ * \note If hash_len is 0, then the length associated with md_alg
805
+ * is used instead, or an error returned if it is invalid.
806
+ *
807
+ * \note md_alg may be MBEDTLS_MD_NONE, only if hash_len != 0
808
+ *
809
+ * \note If type is MBEDTLS_PK_RSASSA_PSS, then options must point
810
+ * to a mbedtls_pk_rsassa_pss_options structure,
811
+ * otherwise it must be NULL. Note that if
812
+ * #MBEDTLS_USE_PSA_CRYPTO is defined, the salt length is not
813
+ * verified as PSA_ALG_RSA_PSS_ANY_SALT is used.
814
+ */
815
+ int mbedtls_pk_verify_ext(mbedtls_pk_type_t type, const void *options,
816
+ mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
817
+ const unsigned char *hash, size_t hash_len,
818
+ const unsigned char *sig, size_t sig_len);
819
+
820
+ /**
821
+ * \brief Make signature, including padding if relevant.
822
+ *
823
+ * \param ctx The PK context to use. It must have been set up
824
+ * with a private key.
825
+ * \param md_alg Hash algorithm used (see notes)
826
+ * \param hash Hash of the message to sign
827
+ * \param hash_len Hash length
828
+ * \param sig Place to write the signature.
829
+ * It must have enough room for the signature.
830
+ * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
831
+ * You may use a smaller buffer if it is large enough
832
+ * given the key type.
833
+ * \param sig_size The size of the \p sig buffer in bytes.
834
+ * \param sig_len On successful return,
835
+ * the number of bytes written to \p sig.
836
+ * \param f_rng RNG function, must not be \c NULL.
837
+ * \param p_rng RNG parameter
838
+ *
839
+ * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
840
+ * either PKCS#1 v1.5 or PSS (using the largest possible salt
841
+ * length up to the hash length), depending on the padding mode
842
+ * in the underlying RSA context. For a pk object constructed
843
+ * by parsing, this is PKCS#1 v1.5 by default. Use
844
+ * mbedtls_pk_sign_ext() to explicitly select a different
845
+ * algorithm.
846
+ *
847
+ * \return 0 on success, or a specific error code.
848
+ *
849
+ * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
850
+ * For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
851
+ */
852
+ int mbedtls_pk_sign(mbedtls_pk_context *ctx, mbedtls_md_type_t md_alg,
853
+ const unsigned char *hash, size_t hash_len,
854
+ unsigned char *sig, size_t sig_size, size_t *sig_len,
855
+ mbedtls_f_rng_t *f_rng, void *p_rng);
856
+
857
+ /**
858
+ * \brief Make signature given a signature type.
859
+ *
860
+ * \param pk_type Signature type.
861
+ * \param ctx The PK context to use. It must have been set up
862
+ * with a private key.
863
+ * \param md_alg Hash algorithm used (see notes)
864
+ * \param hash Hash of the message to sign
865
+ * \param hash_len Hash length
866
+ * \param sig Place to write the signature.
867
+ * It must have enough room for the signature.
868
+ * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
869
+ * You may use a smaller buffer if it is large enough
870
+ * given the key type.
871
+ * \param sig_size The size of the \p sig buffer in bytes.
872
+ * \param sig_len On successful return,
873
+ * the number of bytes written to \p sig.
874
+ * \param f_rng RNG function, must not be \c NULL.
875
+ * \param p_rng RNG parameter
876
+ *
877
+ * \return 0 on success, or a specific error code.
878
+ *
879
+ * \note When \p pk_type is #MBEDTLS_PK_RSASSA_PSS,
880
+ * see #PSA_ALG_RSA_PSS for a description of PSS options used.
881
+ *
882
+ * \note For RSA, md_alg may be MBEDTLS_MD_NONE if hash_len != 0.
883
+ * For ECDSA, md_alg may never be MBEDTLS_MD_NONE.
884
+ *
885
+ */
886
+ int mbedtls_pk_sign_ext(mbedtls_pk_type_t pk_type,
887
+ mbedtls_pk_context *ctx,
888
+ mbedtls_md_type_t md_alg,
889
+ const unsigned char *hash, size_t hash_len,
890
+ unsigned char *sig, size_t sig_size, size_t *sig_len,
891
+ mbedtls_f_rng_t *f_rng,
892
+ void *p_rng);
893
+
894
+ /**
895
+ * \brief Restartable version of \c mbedtls_pk_sign()
896
+ *
897
+ * \note Performs the same job as \c mbedtls_pk_sign(), but can
898
+ * return early and restart according to the limit set with
899
+ * \c mbedtls_ecp_set_max_ops() to reduce blocking for ECC
900
+ * operations. For RSA, same as \c mbedtls_pk_sign().
901
+ *
902
+ * \param ctx The PK context to use. It must have been set up
903
+ * with a private key.
904
+ * \param md_alg Hash algorithm used (see notes for mbedtls_pk_sign())
905
+ * \param hash Hash of the message to sign
906
+ * \param hash_len Hash length
907
+ * \param sig Place to write the signature.
908
+ * It must have enough room for the signature.
909
+ * #MBEDTLS_PK_SIGNATURE_MAX_SIZE is always enough.
910
+ * You may use a smaller buffer if it is large enough
911
+ * given the key type.
912
+ * \param sig_size The size of the \p sig buffer in bytes.
913
+ * \param sig_len On successful return,
914
+ * the number of bytes written to \p sig.
915
+ * \param f_rng RNG function, must not be \c NULL.
916
+ * \param p_rng RNG parameter
917
+ * \param rs_ctx Restart context (NULL to disable restart)
918
+ *
919
+ * \return See \c mbedtls_pk_sign().
920
+ * \return #MBEDTLS_ERR_ECP_IN_PROGRESS if maximum number of
921
+ * operations was reached: see \c mbedtls_ecp_set_max_ops().
922
+ */
923
+ int mbedtls_pk_sign_restartable(mbedtls_pk_context *ctx,
924
+ mbedtls_md_type_t md_alg,
925
+ const unsigned char *hash, size_t hash_len,
926
+ unsigned char *sig, size_t sig_size, size_t *sig_len,
927
+ mbedtls_f_rng_t *f_rng, void *p_rng,
928
+ mbedtls_pk_restart_ctx *rs_ctx);
929
+
930
+ /**
931
+ * \brief Decrypt message (including padding if relevant).
932
+ *
933
+ * \warning When using PKCS#1 v1.5 (see note below), this is an
934
+ * inherently dangerous function (CWE-242) and the return value
935
+ * is sensitive, see mbedtls_rsa_rsaes_pkcs1_v15_decrypt().
936
+ *
937
+ * \note For keys of type #MBEDTLS_PK_RSA, the encryption algorithm is
938
+ * either PKCS#1 v1.5 or OAEP, depending on the padding mode in
939
+ * the underlying RSA context. For a pk object constructed by
940
+ * parsing, this is PKCS#1 v1.5 by default.
941
+ *
942
+ * \param ctx The PK context to use. It must have been set up
943
+ * with a private key.
944
+ * \param input Input to decrypt
945
+ * \param ilen Input size
946
+ * \param output Decrypted output
947
+ * \param olen Decrypted message length
948
+ * \param osize Size of the output buffer
949
+ * \param f_rng RNG function, must not be \c NULL.
950
+ * \param p_rng RNG parameter
951
+ *
952
+ * \return 0 on success, or a specific error code.
953
+ */
954
+ int mbedtls_pk_decrypt(mbedtls_pk_context *ctx,
955
+ const unsigned char *input, size_t ilen,
956
+ unsigned char *output, size_t *olen, size_t osize,
957
+ mbedtls_f_rng_t *f_rng, void *p_rng);
958
+
959
+ /**
960
+ * \brief Encrypt message (including padding if relevant).
961
+ *
962
+ * \param ctx The PK context to use. It must have been set up.
963
+ * \param input Message to encrypt
964
+ * \param ilen Message size
965
+ * \param output Encrypted output
966
+ * \param olen Encrypted output length
967
+ * \param osize Size of the output buffer
968
+ * \param f_rng RNG function, must not be \c NULL.
969
+ * \param p_rng RNG parameter
970
+ *
971
+ * \note For keys of type #MBEDTLS_PK_RSA, the signature algorithm is
972
+ * either PKCS#1 v1.5 or OAEP, depending on the padding mode in
973
+ * the underlying RSA context. For a pk object constructed by
974
+ * parsing, this is PKCS#1 v1.5 by default.
975
+ *
976
+ * \note \p f_rng is used for padding generation.
977
+ *
978
+ * \return 0 on success, or a specific error code.
979
+ */
980
+ int mbedtls_pk_encrypt(mbedtls_pk_context *ctx,
981
+ const unsigned char *input, size_t ilen,
982
+ unsigned char *output, size_t *olen, size_t osize,
983
+ mbedtls_f_rng_t *f_rng, void *p_rng);
984
+
985
+ /**
986
+ * \brief Check if a public-private pair of keys matches.
987
+ *
988
+ * \param pub Context holding a public key.
989
+ * \param prv Context holding a private (and public) key.
990
+ * \param f_rng RNG function, must not be \c NULL.
991
+ * \param p_rng RNG parameter
992
+ *
993
+ * \return \c 0 on success (keys were checked and match each other).
994
+ * \return #MBEDTLS_ERR_PK_FEATURE_UNAVAILABLE if the keys could not
995
+ * be checked - in that case they may or may not match.
996
+ * \return #MBEDTLS_ERR_PK_BAD_INPUT_DATA if a context is invalid.
997
+ * \return Another non-zero value if the keys do not match.
998
+ */
999
+ int mbedtls_pk_check_pair(const mbedtls_pk_context *pub,
1000
+ const mbedtls_pk_context *prv,
1001
+ mbedtls_f_rng_t *f_rng,
1002
+ void *p_rng);
1003
+
1004
+ /**
1005
+ * \brief Export debug information
1006
+ *
1007
+ * \param ctx The PK context to use. It must have been initialized.
1008
+ * \param items Place to write debug items
1009
+ *
1010
+ * \return 0 on success or MBEDTLS_ERR_PK_BAD_INPUT_DATA
1011
+ */
1012
+ int mbedtls_pk_debug(const mbedtls_pk_context *ctx, mbedtls_pk_debug_item *items);
1013
+
1014
+ /**
1015
+ * \brief Access the type name
1016
+ *
1017
+ * \param ctx The PK context to use. It must have been initialized.
1018
+ *
1019
+ * \return Type name on success, or "invalid PK"
1020
+ */
1021
+ const char *mbedtls_pk_get_name(const mbedtls_pk_context *ctx);
1022
+
1023
+ /**
1024
+ * \brief Get the key type
1025
+ *
1026
+ * \param ctx The PK context to use. It must have been initialized.
1027
+ *
1028
+ * \return Type on success.
1029
+ * \return #MBEDTLS_PK_NONE for a context that has not been set up.
1030
+ */
1031
+ mbedtls_pk_type_t mbedtls_pk_get_type(const mbedtls_pk_context *ctx);
1032
+
1033
+ #if defined(MBEDTLS_RSA_C)
1034
+ /**
1035
+ * Quick access to an RSA context inside a PK context.
1036
+ *
1037
+ * \warning This function can only be used when the type of the context, as
1038
+ * returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_RSA.
1039
+ * Ensuring that is the caller's responsibility.
1040
+ * Alternatively, you can check whether this function returns NULL.
1041
+ *
1042
+ * \return The internal RSA context held by the PK context, or NULL.
1043
+ */
1044
+ static inline mbedtls_rsa_context *mbedtls_pk_rsa(const mbedtls_pk_context pk)
1045
+ {
1046
+ switch (mbedtls_pk_get_type(&pk)) {
1047
+ case MBEDTLS_PK_RSA:
1048
+ return (mbedtls_rsa_context *) (pk).MBEDTLS_PRIVATE(pk_ctx);
1049
+ default:
1050
+ return NULL;
1051
+ }
1052
+ }
1053
+ #endif /* MBEDTLS_RSA_C */
1054
+
1055
+ #if defined(MBEDTLS_ECP_C)
1056
+ /**
1057
+ * Quick access to an EC context inside a PK context.
1058
+ *
1059
+ * \warning This function can only be used when the type of the context, as
1060
+ * returned by mbedtls_pk_get_type(), is #MBEDTLS_PK_ECKEY,
1061
+ * #MBEDTLS_PK_ECKEY_DH, or #MBEDTLS_PK_ECDSA.
1062
+ * Ensuring that is the caller's responsibility.
1063
+ * Alternatively, you can check whether this function returns NULL.
1064
+ *
1065
+ * \return The internal EC context held by the PK context, or NULL.
1066
+ */
1067
+ static inline mbedtls_ecp_keypair *mbedtls_pk_ec(const mbedtls_pk_context pk)
1068
+ {
1069
+ switch (mbedtls_pk_get_type(&pk)) {
1070
+ case MBEDTLS_PK_ECKEY:
1071
+ case MBEDTLS_PK_ECKEY_DH:
1072
+ case MBEDTLS_PK_ECDSA:
1073
+ return (mbedtls_ecp_keypair *) (pk).MBEDTLS_PRIVATE(pk_ctx);
1074
+ default:
1075
+ return NULL;
1076
+ }
1077
+ }
1078
+ #endif /* MBEDTLS_ECP_C */
1079
+
1080
+ #if defined(MBEDTLS_PK_PARSE_C)
1081
+ /** \ingroup pk_module */
1082
+ /**
1083
+ * \brief Parse a private key in PEM or DER format
1084
+ *
1085
+ * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
1086
+ * subsystem must have been initialized by calling
1087
+ * psa_crypto_init() before calling this function.
1088
+ *
1089
+ * \param ctx The PK context to fill. It must have been initialized
1090
+ * but not set up.
1091
+ * \param key Input buffer to parse.
1092
+ * The buffer must contain the input exactly, with no
1093
+ * extra trailing material. For PEM, the buffer must
1094
+ * contain a null-terminated string.
1095
+ * \param keylen Size of \b key in bytes.
1096
+ * For PEM data, this includes the terminating null byte,
1097
+ * so \p keylen must be equal to `strlen(key) + 1`.
1098
+ * \param pwd Optional password for decryption.
1099
+ * Pass \c NULL if expecting a non-encrypted key.
1100
+ * Pass a string of \p pwdlen bytes if expecting an encrypted
1101
+ * key; a non-encrypted key will also be accepted.
1102
+ * The empty password is not supported.
1103
+ * \param pwdlen Size of the password in bytes.
1104
+ * Ignored if \p pwd is \c NULL.
1105
+ * \param f_rng RNG function, must not be \c NULL. Used for blinding.
1106
+ * \param p_rng RNG parameter
1107
+ *
1108
+ * \note On entry, ctx must be empty, either freshly initialised
1109
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
1110
+ * specific key type, check the result with mbedtls_pk_can_do().
1111
+ *
1112
+ * \note The key is also checked for correctness.
1113
+ *
1114
+ * \return 0 if successful, or a specific PK or PEM error code
1115
+ */
1116
+ int mbedtls_pk_parse_key(mbedtls_pk_context *ctx,
1117
+ const unsigned char *key, size_t keylen,
1118
+ const unsigned char *pwd, size_t pwdlen,
1119
+ mbedtls_f_rng_t *f_rng, void *p_rng);
1120
+
1121
+ /** \ingroup pk_module */
1122
+ /**
1123
+ * \brief Parse a public key in PEM or DER format
1124
+ *
1125
+ * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
1126
+ * subsystem must have been initialized by calling
1127
+ * psa_crypto_init() before calling this function.
1128
+ *
1129
+ * \param ctx The PK context to fill. It must have been initialized
1130
+ * but not set up.
1131
+ * \param key Input buffer to parse.
1132
+ * The buffer must contain the input exactly, with no
1133
+ * extra trailing material. For PEM, the buffer must
1134
+ * contain a null-terminated string.
1135
+ * \param keylen Size of \b key in bytes.
1136
+ * For PEM data, this includes the terminating null byte,
1137
+ * so \p keylen must be equal to `strlen(key) + 1`.
1138
+ *
1139
+ * \note On entry, ctx must be empty, either freshly initialised
1140
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
1141
+ * specific key type, check the result with mbedtls_pk_can_do().
1142
+ *
1143
+ * \note For compressed points, see #MBEDTLS_ECP_PF_COMPRESSED for
1144
+ * limitations.
1145
+ *
1146
+ * \note The key is also checked for correctness.
1147
+ *
1148
+ * \return 0 if successful, or a specific PK or PEM error code
1149
+ */
1150
+ int mbedtls_pk_parse_public_key(mbedtls_pk_context *ctx,
1151
+ const unsigned char *key, size_t keylen);
1152
+
1153
+ #if defined(MBEDTLS_FS_IO)
1154
+ /** \ingroup pk_module */
1155
+ /**
1156
+ * \brief Load and parse a private key
1157
+ *
1158
+ * \note If #MBEDTLS_USE_PSA_CRYPTO is enabled, the PSA crypto
1159
+ * subsystem must have been initialized by calling
1160
+ * psa_crypto_init() before calling this function.
1161
+ *
1162
+ * \param ctx The PK context to fill. It must have been initialized
1163
+ * but not set up.
1164
+ * \param path filename to read the private key from
1165
+ * \param password Optional password to decrypt the file.
1166
+ * Pass \c NULL if expecting a non-encrypted key.
1167
+ * Pass a null-terminated string if expecting an encrypted
1168
+ * key; a non-encrypted key will also be accepted.
1169
+ * The empty password is not supported.
1170
+ * \param f_rng RNG function, must not be \c NULL. Used for blinding.
1171
+ * \param p_rng RNG parameter
1172
+ *
1173
+ * \note On entry, ctx must be empty, either freshly initialised
1174
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If you need a
1175
+ * specific key type, check the result with mbedtls_pk_can_do().
1176
+ *
1177
+ * \note The key is also checked for correctness.
1178
+ *
1179
+ * \return 0 if successful, or a specific PK or PEM error code
1180
+ */
1181
+ int mbedtls_pk_parse_keyfile(mbedtls_pk_context *ctx,
1182
+ const char *path, const char *password,
1183
+ mbedtls_f_rng_t *f_rng, void *p_rng);
1184
+
1185
+ /** \ingroup pk_module */
1186
+ /**
1187
+ * \brief Load and parse a public key
1188
+ *
1189
+ * \param ctx The PK context to fill. It must have been initialized
1190
+ * but not set up.
1191
+ * \param path filename to read the public key from
1192
+ *
1193
+ * \note On entry, ctx must be empty, either freshly initialised
1194
+ * with mbedtls_pk_init() or reset with mbedtls_pk_free(). If
1195
+ * you need a specific key type, check the result with
1196
+ * mbedtls_pk_can_do().
1197
+ *
1198
+ * \note The key is also checked for correctness.
1199
+ *
1200
+ * \return 0 if successful, or a specific PK or PEM error code
1201
+ */
1202
+ int mbedtls_pk_parse_public_keyfile(mbedtls_pk_context *ctx, const char *path);
1203
+ #endif /* MBEDTLS_FS_IO */
1204
+ #endif /* MBEDTLS_PK_PARSE_C */
1205
+
1206
+ #if defined(MBEDTLS_PK_WRITE_C)
1207
+ /**
1208
+ * \brief Write a private key to a PKCS#1 or SEC1 DER structure
1209
+ * Note: data is written at the end of the buffer! Use the
1210
+ * return value to determine where you should start
1211
+ * using the buffer
1212
+ *
1213
+ * \param ctx PK context which must contain a valid private key.
1214
+ * \param buf buffer to write to
1215
+ * \param size size of the buffer
1216
+ *
1217
+ * \return length of data written if successful, or a specific
1218
+ * error code
1219
+ */
1220
+ int mbedtls_pk_write_key_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1221
+
1222
+ /**
1223
+ * \brief Write a public key to a SubjectPublicKeyInfo DER structure
1224
+ * Note: data is written at the end of the buffer! Use the
1225
+ * return value to determine where you should start
1226
+ * using the buffer
1227
+ *
1228
+ * \param ctx PK context which must contain a valid public or private key.
1229
+ * \param buf buffer to write to
1230
+ * \param size size of the buffer
1231
+ *
1232
+ * \return length of data written if successful, or a specific
1233
+ * error code
1234
+ */
1235
+ int mbedtls_pk_write_pubkey_der(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1236
+
1237
+ #if defined(MBEDTLS_PEM_WRITE_C)
1238
+ /**
1239
+ * \brief Write a public key to a PEM string
1240
+ *
1241
+ * \param ctx PK context which must contain a valid public or private key.
1242
+ * \param buf Buffer to write to. The output includes a
1243
+ * terminating null byte.
1244
+ * \param size Size of the buffer in bytes.
1245
+ *
1246
+ * \return 0 if successful, or a specific error code
1247
+ */
1248
+ int mbedtls_pk_write_pubkey_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1249
+
1250
+ /**
1251
+ * \brief Write a private key to a PKCS#1 or SEC1 PEM string
1252
+ *
1253
+ * \param ctx PK context which must contain a valid private key.
1254
+ * \param buf Buffer to write to. The output includes a
1255
+ * terminating null byte.
1256
+ * \param size Size of the buffer in bytes.
1257
+ *
1258
+ * \return 0 if successful, or a specific error code
1259
+ */
1260
+ int mbedtls_pk_write_key_pem(const mbedtls_pk_context *ctx, unsigned char *buf, size_t size);
1261
+ #endif /* MBEDTLS_PEM_WRITE_C */
1262
+ #endif /* MBEDTLS_PK_WRITE_C */
1263
+
1264
+ /*
1265
+ * WARNING: Low-level functions. You probably do not want to use these unless
1266
+ * you are certain you do ;)
1267
+ */
1268
+
1269
+ #if defined(MBEDTLS_PK_PARSE_C)
1270
+ /**
1271
+ * \brief Parse a SubjectPublicKeyInfo DER structure
1272
+ *
1273
+ * \param p the position in the ASN.1 data
1274
+ * \param end end of the buffer
1275
+ * \param pk The PK context to fill. It must have been initialized
1276
+ * but not set up.
1277
+ *
1278
+ * \return 0 if successful, or a specific PK error code
1279
+ */
1280
+ int mbedtls_pk_parse_subpubkey(unsigned char **p, const unsigned char *end,
1281
+ mbedtls_pk_context *pk);
1282
+ #endif /* MBEDTLS_PK_PARSE_C */
1283
+
1284
+ #if defined(MBEDTLS_PK_WRITE_C)
1285
+ /**
1286
+ * \brief Write a subjectPublicKey to ASN.1 data
1287
+ * Note: function works backwards in data buffer
1288
+ *
1289
+ * \param p reference to current position pointer
1290
+ * \param start start of the buffer (for bounds-checking)
1291
+ * \param key PK context which must contain a valid public or private key.
1292
+ *
1293
+ * \return the length written or a negative error code
1294
+ */
1295
+ int mbedtls_pk_write_pubkey(unsigned char **p, unsigned char *start,
1296
+ const mbedtls_pk_context *key);
1297
+ #endif /* MBEDTLS_PK_WRITE_C */
1298
+
1299
+ #ifdef __cplusplus
1300
+ }
1301
+ #endif
1302
+
1303
+ #endif /* MBEDTLS_PK_H */