@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,1319 @@
1
+ /**
2
+ * \file psa/crypto_sizes.h
3
+ *
4
+ * \brief PSA cryptography module: Mbed TLS buffer size macros
5
+ *
6
+ * \note This file may not be included directly. Applications must
7
+ * include psa/crypto.h.
8
+ *
9
+ * This file contains the definitions of macros that are useful to
10
+ * compute buffer sizes. The signatures and semantics of these macros
11
+ * are standardized, but the definitions are not, because they depend on
12
+ * the available algorithms and, in some cases, on permitted tolerances
13
+ * on buffer sizes.
14
+ *
15
+ * In implementations with isolation between the application and the
16
+ * cryptography module, implementers should take care to ensure that
17
+ * the definitions that are exposed to applications match what the
18
+ * module implements.
19
+ *
20
+ * Macros that compute sizes whose values do not depend on the
21
+ * implementation are in crypto.h.
22
+ */
23
+ /*
24
+ * Copyright The Mbed TLS Contributors
25
+ * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
26
+ */
27
+
28
+ #ifndef PSA_CRYPTO_SIZES_H
29
+ #define PSA_CRYPTO_SIZES_H
30
+
31
+ /*
32
+ * Include the build-time configuration information header. Here, we do not
33
+ * include `"mbedtls/build_info.h"` directly but `"psa/build_info.h"`, which
34
+ * is basically just an alias to it. This is to ease the maintenance of the
35
+ * TF-PSA-Crypto repository which has a different build system and
36
+ * configuration.
37
+ */
38
+ #include "psa/build_info.h"
39
+
40
+ #define PSA_BITS_TO_BYTES(bits) (((bits) + 7u) / 8u)
41
+ #define PSA_BYTES_TO_BITS(bytes) ((bytes) * 8u)
42
+ #define PSA_MAX_OF_THREE(a, b, c) ((a) <= (b) ? (b) <= (c) ? \
43
+ (c) : (b) : (a) <= (c) ? (c) : (a))
44
+
45
+ #define PSA_ROUND_UP_TO_MULTIPLE(block_size, length) \
46
+ (((length) + (block_size) - 1) / (block_size) * (block_size))
47
+
48
+ /** The size of the output of psa_hash_finish(), in bytes.
49
+ *
50
+ * This is also the hash size that psa_hash_verify() expects.
51
+ *
52
+ * \param alg A hash algorithm (\c PSA_ALG_XXX value such that
53
+ * #PSA_ALG_IS_HASH(\p alg) is true), or an HMAC algorithm
54
+ * (#PSA_ALG_HMAC(\c hash_alg) where \c hash_alg is a
55
+ * hash algorithm).
56
+ *
57
+ * \return The hash size for the specified hash algorithm.
58
+ * If the hash algorithm is not recognized, return 0.
59
+ */
60
+ #define PSA_HASH_LENGTH(alg) \
61
+ ( \
62
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 16u : \
63
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 20u : \
64
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 20u : \
65
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 28u : \
66
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 32u : \
67
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 48u : \
68
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 64u : \
69
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 28u : \
70
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 32u : \
71
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 28u : \
72
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 32u : \
73
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 48u : \
74
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 64u : \
75
+ 0u)
76
+
77
+ /** The input block size of a hash algorithm, in bytes.
78
+ *
79
+ * Hash algorithms process their input data in blocks. Hash operations will
80
+ * retain any partial blocks until they have enough input to fill the block or
81
+ * until the operation is finished.
82
+ * This affects the output from psa_hash_suspend().
83
+ *
84
+ * \param alg A hash algorithm (\c PSA_ALG_XXX value such that
85
+ * PSA_ALG_IS_HASH(\p alg) is true).
86
+ *
87
+ * \return The block size in bytes for the specified hash algorithm.
88
+ * If the hash algorithm is not recognized, return 0.
89
+ * An implementation can return either 0 or the correct size for a
90
+ * hash algorithm that it recognizes, but does not support.
91
+ */
92
+ #define PSA_HASH_BLOCK_LENGTH(alg) \
93
+ ( \
94
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_MD5 ? 64u : \
95
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_RIPEMD160 ? 64u : \
96
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_1 ? 64u : \
97
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_224 ? 64u : \
98
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_256 ? 64u : \
99
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_384 ? 128u : \
100
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512 ? 128u : \
101
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_224 ? 128u : \
102
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA_512_256 ? 128u : \
103
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_224 ? 144u : \
104
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_256 ? 136u : \
105
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_384 ? 104u : \
106
+ PSA_ALG_HMAC_GET_HASH(alg) == PSA_ALG_SHA3_512 ? 72u : \
107
+ 0u)
108
+
109
+ /** \def PSA_HASH_MAX_SIZE
110
+ *
111
+ * Maximum size of a hash.
112
+ *
113
+ * This macro expands to a compile-time constant integer. This value
114
+ * is the maximum size of a hash in bytes.
115
+ */
116
+ /* Note: for HMAC-SHA-3, the block size is 144 bytes for HMAC-SHA3-224,
117
+ * 136 bytes for HMAC-SHA3-256, 104 bytes for SHA3-384, 72 bytes for
118
+ * HMAC-SHA3-512. */
119
+ /* Note: PSA_HASH_MAX_SIZE should be kept in sync with MBEDTLS_MD_MAX_SIZE,
120
+ * see the note on MBEDTLS_MD_MAX_SIZE for details. */
121
+ #if defined(PSA_WANT_ALG_SHA3_224)
122
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 144u
123
+ #elif defined(PSA_WANT_ALG_SHA3_256)
124
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 136u
125
+ #elif defined(PSA_WANT_ALG_SHA_512)
126
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128u
127
+ #elif defined(PSA_WANT_ALG_SHA_384)
128
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 128u
129
+ #elif defined(PSA_WANT_ALG_SHA3_384)
130
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 104u
131
+ #elif defined(PSA_WANT_ALG_SHA3_512)
132
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 72u
133
+ #elif defined(PSA_WANT_ALG_SHA_256)
134
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64u
135
+ #elif defined(PSA_WANT_ALG_SHA_224)
136
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64u
137
+ #else /* SHA-1 or smaller */
138
+ #define PSA_HMAC_MAX_HASH_BLOCK_SIZE 64u
139
+ #endif
140
+
141
+ #if defined(PSA_WANT_ALG_SHA_512) || defined(PSA_WANT_ALG_SHA3_512)
142
+ #define PSA_HASH_MAX_SIZE 64u
143
+ #elif defined(PSA_WANT_ALG_SHA_384) || defined(PSA_WANT_ALG_SHA3_384)
144
+ #define PSA_HASH_MAX_SIZE 48u
145
+ #elif defined(PSA_WANT_ALG_SHA_256) || defined(PSA_WANT_ALG_SHA3_256)
146
+ #define PSA_HASH_MAX_SIZE 32u
147
+ #elif defined(PSA_WANT_ALG_SHA_224) || defined(PSA_WANT_ALG_SHA3_224)
148
+ #define PSA_HASH_MAX_SIZE 28u
149
+ #else /* SHA-1 or smaller */
150
+ #define PSA_HASH_MAX_SIZE 20u
151
+ #endif
152
+
153
+ /** \def PSA_MAC_MAX_SIZE
154
+ *
155
+ * Maximum size of a MAC.
156
+ *
157
+ * This macro expands to a compile-time constant integer. This value
158
+ * is the maximum size of a MAC in bytes.
159
+ */
160
+ /* All non-HMAC MACs have a maximum size that's smaller than the
161
+ * minimum possible value of PSA_HASH_MAX_SIZE in this implementation. */
162
+ /* Note that the encoding of truncated MAC algorithms limits this value
163
+ * to 64 bytes.
164
+ */
165
+ #define PSA_MAC_MAX_SIZE PSA_HASH_MAX_SIZE
166
+
167
+ /** The length of a tag for an AEAD algorithm, in bytes.
168
+ *
169
+ * This macro can be used to allocate a buffer of sufficient size to store the
170
+ * tag output from psa_aead_finish().
171
+ *
172
+ * See also #PSA_AEAD_TAG_MAX_SIZE.
173
+ *
174
+ * \param key_type The type of the AEAD key.
175
+ * \param key_bits The size of the AEAD key in bits.
176
+ * \param alg An AEAD algorithm
177
+ * (\c PSA_ALG_XXX value such that
178
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
179
+ *
180
+ * \return The tag length for the specified algorithm and key.
181
+ * If the AEAD algorithm does not have an identified
182
+ * tag that can be distinguished from the rest of
183
+ * the ciphertext, return 0.
184
+ * If the key type or AEAD algorithm is not
185
+ * recognized, or the parameters are incompatible,
186
+ * return 0.
187
+ */
188
+ #define PSA_AEAD_TAG_LENGTH(key_type, key_bits, alg) \
189
+ (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
190
+ PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \
191
+ ((void) (key_bits), 0u))
192
+
193
+ /** The maximum tag size for all supported AEAD algorithms, in bytes.
194
+ *
195
+ * See also #PSA_AEAD_TAG_LENGTH(\p key_type, \p key_bits, \p alg).
196
+ */
197
+ #define PSA_AEAD_TAG_MAX_SIZE 16u
198
+
199
+ /* The maximum size of an RSA key on this implementation, in bits.
200
+ * This is a vendor-specific macro.
201
+ *
202
+ * Mbed TLS does not set a hard limit on the size of RSA keys: any key
203
+ * whose parameters fit in a bignum is accepted. However large keys can
204
+ * induce a large memory usage and long computation times. Unlike other
205
+ * auxiliary macros in this file and in crypto.h, which reflect how the
206
+ * library is configured, this macro defines how the library is
207
+ * configured. This implementation refuses to import or generate an
208
+ * RSA key whose size is larger than the value defined here.
209
+ *
210
+ * Note that an implementation may set different size limits for different
211
+ * operations, and does not need to accept all key sizes up to the limit. */
212
+ #define PSA_VENDOR_RSA_MAX_KEY_BITS 4096u
213
+
214
+ /* The minimum size of an RSA key on this implementation, in bits.
215
+ * This is a vendor-specific macro.
216
+ *
217
+ * Limits RSA key generation to a minimum due to avoid accidental misuse.
218
+ * This value cannot be less than 128 bits.
219
+ */
220
+ #if defined(MBEDTLS_RSA_GEN_KEY_MIN_BITS)
221
+ #define PSA_VENDOR_RSA_GENERATE_MIN_KEY_BITS MBEDTLS_RSA_GEN_KEY_MIN_BITS
222
+ #else
223
+ #define PSA_VENDOR_RSA_GENERATE_MIN_KEY_BITS 1024
224
+ #endif
225
+
226
+ /* The maximum size of an DH key on this implementation, in bits.
227
+ * This is a vendor-specific macro.*/
228
+ #if defined(PSA_WANT_DH_RFC7919_8192)
229
+ #define PSA_VENDOR_FFDH_MAX_KEY_BITS 8192u
230
+ #elif defined(PSA_WANT_DH_RFC7919_6144)
231
+ #define PSA_VENDOR_FFDH_MAX_KEY_BITS 6144u
232
+ #elif defined(PSA_WANT_DH_RFC7919_4096)
233
+ #define PSA_VENDOR_FFDH_MAX_KEY_BITS 4096u
234
+ #elif defined(PSA_WANT_DH_RFC7919_3072)
235
+ #define PSA_VENDOR_FFDH_MAX_KEY_BITS 3072u
236
+ #elif defined(PSA_WANT_DH_RFC7919_2048)
237
+ #define PSA_VENDOR_FFDH_MAX_KEY_BITS 2048u
238
+ #else
239
+ #define PSA_VENDOR_FFDH_MAX_KEY_BITS 0u
240
+ #endif
241
+
242
+ /* The maximum size of an ECC key on this implementation, in bits.
243
+ * This is a vendor-specific macro. */
244
+ #if defined(PSA_WANT_ECC_SECP_R1_521)
245
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 521u
246
+ #elif defined(PSA_WANT_ECC_BRAINPOOL_P_R1_512)
247
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 512u
248
+ #elif defined(PSA_WANT_ECC_MONTGOMERY_448)
249
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 448u
250
+ #elif defined(PSA_WANT_ECC_SECP_R1_384)
251
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 384u
252
+ #elif defined(PSA_WANT_ECC_BRAINPOOL_P_R1_384)
253
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 384u
254
+ #elif defined(PSA_WANT_ECC_SECP_R1_256)
255
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 256u
256
+ #elif defined(PSA_WANT_ECC_SECP_K1_256)
257
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 256u
258
+ #elif defined(PSA_WANT_ECC_BRAINPOOL_P_R1_256)
259
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 256u
260
+ #elif defined(PSA_WANT_ECC_MONTGOMERY_255)
261
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 255u
262
+ #elif defined(PSA_WANT_ECC_SECP_R1_224)
263
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 224u
264
+ #elif defined(PSA_WANT_ECC_SECP_K1_224)
265
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 224u
266
+ #elif defined(PSA_WANT_ECC_SECP_R1_192)
267
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 192u
268
+ #elif defined(PSA_WANT_ECC_SECP_K1_192)
269
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 192u
270
+ #else
271
+ #define PSA_VENDOR_ECC_MAX_CURVE_BITS 0u
272
+ #endif
273
+
274
+ /** This macro returns the maximum supported length of the PSK for the
275
+ * TLS-1.2 PSK-to-MS key derivation
276
+ * (#PSA_ALG_TLS12_PSK_TO_MS(\c hash_alg)).
277
+ *
278
+ * The maximum supported length does not depend on the chosen hash algorithm.
279
+ *
280
+ * Quoting RFC 4279, Sect 5.3:
281
+ * TLS implementations supporting these ciphersuites MUST support
282
+ * arbitrary PSK identities up to 128 octets in length, and arbitrary
283
+ * PSKs up to 64 octets in length. Supporting longer identities and
284
+ * keys is RECOMMENDED.
285
+ *
286
+ * Therefore, no implementation should define a value smaller than 64
287
+ * for #PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE.
288
+ */
289
+ #define PSA_TLS12_PSK_TO_MS_PSK_MAX_SIZE 128u
290
+
291
+ /* The expected size of input passed to psa_tls12_ecjpake_to_pms_input,
292
+ * which is expected to work with P-256 curve only. */
293
+ #define PSA_TLS12_ECJPAKE_TO_PMS_INPUT_SIZE 65u
294
+
295
+ /* The size of a serialized K.X coordinate to be used in
296
+ * psa_tls12_ecjpake_to_pms_input. This function only accepts the P-256
297
+ * curve. */
298
+ #define PSA_TLS12_ECJPAKE_TO_PMS_DATA_SIZE 32u
299
+
300
+ /* The maximum number of iterations for PBKDF2 on this implementation, in bits.
301
+ * This is a vendor-specific macro. This can be configured if necessary */
302
+ #define PSA_VENDOR_PBKDF2_MAX_ITERATIONS 0xffffffffU
303
+
304
+ /** The maximum size of a block cipher. */
305
+ #define PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE 16u
306
+
307
+ /** The size of the output of psa_mac_sign_finish(), in bytes.
308
+ *
309
+ * This is also the MAC size that psa_mac_verify_finish() expects.
310
+ *
311
+ * \warning This macro may evaluate its arguments multiple times or
312
+ * zero times, so you should not pass arguments that contain
313
+ * side effects.
314
+ *
315
+ * \param key_type The type of the MAC key.
316
+ * \param key_bits The size of the MAC key in bits.
317
+ * \param alg A MAC algorithm (\c PSA_ALG_XXX value such that
318
+ * #PSA_ALG_IS_MAC(\p alg) is true).
319
+ *
320
+ * \return The MAC size for the specified algorithm with
321
+ * the specified key parameters.
322
+ * \return 0 if the MAC algorithm is not recognized.
323
+ * \return Either 0 or the correct size for a MAC algorithm that
324
+ * the implementation recognizes, but does not support.
325
+ * \return Unspecified if the key parameters are not consistent
326
+ * with the algorithm.
327
+ */
328
+ #define PSA_MAC_LENGTH(key_type, key_bits, alg) \
329
+ ((alg) & PSA_ALG_MAC_TRUNCATION_MASK ? PSA_MAC_TRUNCATED_LENGTH(alg) : \
330
+ PSA_ALG_IS_HMAC(alg) ? PSA_HASH_LENGTH(PSA_ALG_HMAC_GET_HASH(alg)) : \
331
+ PSA_ALG_IS_BLOCK_CIPHER_MAC(alg) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
332
+ ((void) (key_type), (void) (key_bits), 0u))
333
+
334
+ /** The maximum size of the output of psa_aead_encrypt(), in bytes.
335
+ *
336
+ * If the size of the ciphertext buffer is at least this large, it is
337
+ * guaranteed that psa_aead_encrypt() will not fail due to an
338
+ * insufficient buffer size. Depending on the algorithm, the actual size of
339
+ * the ciphertext may be smaller.
340
+ *
341
+ * See also #PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(\p plaintext_length).
342
+ *
343
+ * \warning This macro may evaluate its arguments multiple times or
344
+ * zero times, so you should not pass arguments that contain
345
+ * side effects.
346
+ *
347
+ * \param key_type A symmetric key type that is
348
+ * compatible with algorithm \p alg.
349
+ * \param alg An AEAD algorithm
350
+ * (\c PSA_ALG_XXX value such that
351
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
352
+ * \param plaintext_length Size of the plaintext in bytes.
353
+ *
354
+ * \return The AEAD ciphertext size for the specified
355
+ * algorithm.
356
+ * If the key type or AEAD algorithm is not
357
+ * recognized, or the parameters are incompatible,
358
+ * return 0.
359
+ */
360
+ #define PSA_AEAD_ENCRYPT_OUTPUT_SIZE(key_type, alg, plaintext_length) \
361
+ (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
362
+ (plaintext_length) + PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \
363
+ 0u)
364
+
365
+ /** A sufficient output buffer size for psa_aead_encrypt(), for any of the
366
+ * supported key types and AEAD algorithms.
367
+ *
368
+ * If the size of the ciphertext buffer is at least this large, it is guaranteed
369
+ * that psa_aead_encrypt() will not fail due to an insufficient buffer size.
370
+ *
371
+ * \note This macro returns a compile-time constant if its arguments are
372
+ * compile-time constants.
373
+ *
374
+ * See also #PSA_AEAD_ENCRYPT_OUTPUT_SIZE(\p key_type, \p alg,
375
+ * \p plaintext_length).
376
+ *
377
+ * \param plaintext_length Size of the plaintext in bytes.
378
+ *
379
+ * \return A sufficient output buffer size for any of the
380
+ * supported key types and AEAD algorithms.
381
+ *
382
+ */
383
+ #define PSA_AEAD_ENCRYPT_OUTPUT_MAX_SIZE(plaintext_length) \
384
+ ((plaintext_length) + PSA_AEAD_TAG_MAX_SIZE)
385
+
386
+
387
+ /** The maximum size of the output of psa_aead_decrypt(), in bytes.
388
+ *
389
+ * If the size of the plaintext buffer is at least this large, it is
390
+ * guaranteed that psa_aead_decrypt() will not fail due to an
391
+ * insufficient buffer size. Depending on the algorithm, the actual size of
392
+ * the plaintext may be smaller.
393
+ *
394
+ * See also #PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(\p ciphertext_length).
395
+ *
396
+ * \warning This macro may evaluate its arguments multiple times or
397
+ * zero times, so you should not pass arguments that contain
398
+ * side effects.
399
+ *
400
+ * \param key_type A symmetric key type that is
401
+ * compatible with algorithm \p alg.
402
+ * \param alg An AEAD algorithm
403
+ * (\c PSA_ALG_XXX value such that
404
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
405
+ * \param ciphertext_length Size of the plaintext in bytes.
406
+ *
407
+ * \return The AEAD ciphertext size for the specified
408
+ * algorithm.
409
+ * If the key type or AEAD algorithm is not
410
+ * recognized, or the parameters are incompatible,
411
+ * return 0.
412
+ */
413
+ #define PSA_AEAD_DECRYPT_OUTPUT_SIZE(key_type, alg, ciphertext_length) \
414
+ (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
415
+ (ciphertext_length) > PSA_ALG_AEAD_GET_TAG_LENGTH(alg) ? \
416
+ (ciphertext_length) - PSA_ALG_AEAD_GET_TAG_LENGTH(alg) : \
417
+ 0u)
418
+
419
+ /** A sufficient output buffer size for psa_aead_decrypt(), for any of the
420
+ * supported key types and AEAD algorithms.
421
+ *
422
+ * If the size of the plaintext buffer is at least this large, it is guaranteed
423
+ * that psa_aead_decrypt() will not fail due to an insufficient buffer size.
424
+ *
425
+ * \note This macro returns a compile-time constant if its arguments are
426
+ * compile-time constants.
427
+ *
428
+ * See also #PSA_AEAD_DECRYPT_OUTPUT_SIZE(\p key_type, \p alg,
429
+ * \p ciphertext_length).
430
+ *
431
+ * \param ciphertext_length Size of the ciphertext in bytes.
432
+ *
433
+ * \return A sufficient output buffer size for any of the
434
+ * supported key types and AEAD algorithms.
435
+ *
436
+ */
437
+ #define PSA_AEAD_DECRYPT_OUTPUT_MAX_SIZE(ciphertext_length) \
438
+ (ciphertext_length)
439
+
440
+ /** The default nonce size for an AEAD algorithm, in bytes.
441
+ *
442
+ * This macro can be used to allocate a buffer of sufficient size to
443
+ * store the nonce output from #psa_aead_generate_nonce().
444
+ *
445
+ * See also #PSA_AEAD_NONCE_MAX_SIZE.
446
+ *
447
+ * \note This is not the maximum size of nonce supported as input to
448
+ * #psa_aead_set_nonce(), #psa_aead_encrypt() or #psa_aead_decrypt(),
449
+ * just the default size that is generated by #psa_aead_generate_nonce().
450
+ *
451
+ * \warning This macro may evaluate its arguments multiple times or
452
+ * zero times, so you should not pass arguments that contain
453
+ * side effects.
454
+ *
455
+ * \param key_type A symmetric key type that is compatible with
456
+ * algorithm \p alg.
457
+ *
458
+ * \param alg An AEAD algorithm (\c PSA_ALG_XXX value such that
459
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
460
+ *
461
+ * \return The default nonce size for the specified key type and algorithm.
462
+ * If the key type or AEAD algorithm is not recognized,
463
+ * or the parameters are incompatible, return 0.
464
+ */
465
+ #define PSA_AEAD_NONCE_LENGTH(key_type, alg) \
466
+ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) == 16 ? \
467
+ MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CCM) ? 13u : \
468
+ MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_GCM) ? 12u : \
469
+ 0u : \
470
+ (key_type) == PSA_KEY_TYPE_CHACHA20 && \
471
+ MBEDTLS_PSA_ALG_AEAD_EQUAL(alg, PSA_ALG_CHACHA20_POLY1305) ? 12u : \
472
+ 0u)
473
+
474
+ /** The maximum default nonce size among all supported pairs of key types and
475
+ * AEAD algorithms, in bytes.
476
+ *
477
+ * This is equal to or greater than any value that #PSA_AEAD_NONCE_LENGTH()
478
+ * may return.
479
+ *
480
+ * \note This is not the maximum size of nonce supported as input to
481
+ * #psa_aead_set_nonce(), #psa_aead_encrypt() or #psa_aead_decrypt(),
482
+ * just the largest size that may be generated by
483
+ * #psa_aead_generate_nonce().
484
+ */
485
+ #define PSA_AEAD_NONCE_MAX_SIZE 13u
486
+
487
+ /** A sufficient output buffer size for psa_aead_update().
488
+ *
489
+ * If the size of the output buffer is at least this large, it is
490
+ * guaranteed that psa_aead_update() will not fail due to an
491
+ * insufficient buffer size. The actual size of the output may be smaller
492
+ * in any given call.
493
+ *
494
+ * See also #PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(\p input_length).
495
+ *
496
+ * \warning This macro may evaluate its arguments multiple times or
497
+ * zero times, so you should not pass arguments that contain
498
+ * side effects.
499
+ *
500
+ * \param key_type A symmetric key type that is
501
+ * compatible with algorithm \p alg.
502
+ * \param alg An AEAD algorithm
503
+ * (\c PSA_ALG_XXX value such that
504
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
505
+ * \param input_length Size of the input in bytes.
506
+ *
507
+ * \return A sufficient output buffer size for the specified
508
+ * algorithm.
509
+ * If the key type or AEAD algorithm is not
510
+ * recognized, or the parameters are incompatible,
511
+ * return 0.
512
+ */
513
+ /* For all the AEAD modes defined in this specification, it is possible
514
+ * to emit output without delay. However, hardware may not always be
515
+ * capable of this. So for modes based on a block cipher, allow the
516
+ * implementation to delay the output until it has a full block. */
517
+ #define PSA_AEAD_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
518
+ (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 ? \
519
+ PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
520
+ PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), (input_length)) : \
521
+ (input_length) : \
522
+ 0u)
523
+
524
+ /** A sufficient output buffer size for psa_aead_update(), for any of the
525
+ * supported key types and AEAD algorithms.
526
+ *
527
+ * If the size of the output buffer is at least this large, it is guaranteed
528
+ * that psa_aead_update() will not fail due to an insufficient buffer size.
529
+ *
530
+ * See also #PSA_AEAD_UPDATE_OUTPUT_SIZE(\p key_type, \p alg, \p input_length).
531
+ *
532
+ * \param input_length Size of the input in bytes.
533
+ */
534
+ #define PSA_AEAD_UPDATE_OUTPUT_MAX_SIZE(input_length) \
535
+ (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, (input_length)))
536
+
537
+ /** A sufficient ciphertext buffer size for psa_aead_finish().
538
+ *
539
+ * If the size of the ciphertext buffer is at least this large, it is
540
+ * guaranteed that psa_aead_finish() will not fail due to an
541
+ * insufficient ciphertext buffer size. The actual size of the output may
542
+ * be smaller in any given call.
543
+ *
544
+ * See also #PSA_AEAD_FINISH_OUTPUT_MAX_SIZE.
545
+ *
546
+ * \param key_type A symmetric key type that is
547
+ compatible with algorithm \p alg.
548
+ * \param alg An AEAD algorithm
549
+ * (\c PSA_ALG_XXX value such that
550
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
551
+ *
552
+ * \return A sufficient ciphertext buffer size for the
553
+ * specified algorithm.
554
+ * If the key type or AEAD algorithm is not
555
+ * recognized, or the parameters are incompatible,
556
+ * return 0.
557
+ */
558
+ #define PSA_AEAD_FINISH_OUTPUT_SIZE(key_type, alg) \
559
+ (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
560
+ PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
561
+ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
562
+ 0u)
563
+
564
+ /** A sufficient ciphertext buffer size for psa_aead_finish(), for any of the
565
+ * supported key types and AEAD algorithms.
566
+ *
567
+ * See also #PSA_AEAD_FINISH_OUTPUT_SIZE(\p key_type, \p alg).
568
+ */
569
+ #define PSA_AEAD_FINISH_OUTPUT_MAX_SIZE (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)
570
+
571
+ /** A sufficient plaintext buffer size for psa_aead_verify().
572
+ *
573
+ * If the size of the plaintext buffer is at least this large, it is
574
+ * guaranteed that psa_aead_verify() will not fail due to an
575
+ * insufficient plaintext buffer size. The actual size of the output may
576
+ * be smaller in any given call.
577
+ *
578
+ * See also #PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE.
579
+ *
580
+ * \param key_type A symmetric key type that is
581
+ * compatible with algorithm \p alg.
582
+ * \param alg An AEAD algorithm
583
+ * (\c PSA_ALG_XXX value such that
584
+ * #PSA_ALG_IS_AEAD(\p alg) is true).
585
+ *
586
+ * \return A sufficient plaintext buffer size for the
587
+ * specified algorithm.
588
+ * If the key type or AEAD algorithm is not
589
+ * recognized, or the parameters are incompatible,
590
+ * return 0.
591
+ */
592
+ #define PSA_AEAD_VERIFY_OUTPUT_SIZE(key_type, alg) \
593
+ (PSA_AEAD_NONCE_LENGTH(key_type, alg) != 0 && \
594
+ PSA_ALG_IS_AEAD_ON_BLOCK_CIPHER(alg) ? \
595
+ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
596
+ 0u)
597
+
598
+ /** A sufficient plaintext buffer size for psa_aead_verify(), for any of the
599
+ * supported key types and AEAD algorithms.
600
+ *
601
+ * See also #PSA_AEAD_VERIFY_OUTPUT_SIZE(\p key_type, \p alg).
602
+ */
603
+ #define PSA_AEAD_VERIFY_OUTPUT_MAX_SIZE (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)
604
+
605
+ #define PSA_RSA_MINIMUM_PADDING_SIZE(alg) \
606
+ (PSA_ALG_IS_RSA_OAEP(alg) ? \
607
+ 2u * PSA_HASH_LENGTH(PSA_ALG_RSA_OAEP_GET_HASH(alg)) + 1u : \
608
+ 11u /*PKCS#1v1.5*/)
609
+
610
+ /**
611
+ * \brief ECDSA signature size for a given curve bit size
612
+ *
613
+ * \param curve_bits Curve size in bits.
614
+ * \return Signature size in bytes.
615
+ *
616
+ * \note This macro returns a compile-time constant if its argument is one.
617
+ */
618
+ #define PSA_ECDSA_SIGNATURE_SIZE(curve_bits) \
619
+ (PSA_BITS_TO_BYTES(curve_bits) * 2u)
620
+
621
+ /** Sufficient signature buffer size for psa_sign_hash().
622
+ *
623
+ * This macro returns a sufficient buffer size for a signature using a key
624
+ * of the specified type and size, with the specified algorithm.
625
+ * Note that the actual size of the signature may be smaller
626
+ * (some algorithms produce a variable-size signature).
627
+ *
628
+ * \warning This function may call its arguments multiple times or
629
+ * zero times, so you should not pass arguments that contain
630
+ * side effects.
631
+ *
632
+ * \param key_type An asymmetric key type (this may indifferently be a
633
+ * key pair type or a public key type).
634
+ * \param key_bits The size of the key in bits.
635
+ * \param alg The signature algorithm.
636
+ *
637
+ * \return If the parameters are valid and supported, return
638
+ * a buffer size in bytes that guarantees that
639
+ * psa_sign_hash() will not fail with
640
+ * #PSA_ERROR_BUFFER_TOO_SMALL.
641
+ * If the parameters are a valid combination that is not supported,
642
+ * return either a sensible size or 0.
643
+ * If the parameters are not valid, the
644
+ * return value is unspecified.
645
+ */
646
+ #define PSA_SIGN_OUTPUT_SIZE(key_type, key_bits, alg) \
647
+ (PSA_KEY_TYPE_IS_RSA(key_type) ? ((void) alg, PSA_BITS_TO_BYTES(key_bits)) : \
648
+ PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_ECDSA_SIGNATURE_SIZE(key_bits) : \
649
+ ((void) alg, 0u))
650
+
651
+ #define PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE \
652
+ PSA_ECDSA_SIGNATURE_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
653
+
654
+ /** \def PSA_SIGNATURE_MAX_SIZE
655
+ *
656
+ * Maximum size of an asymmetric signature.
657
+ *
658
+ * This macro expands to a compile-time constant integer. This value
659
+ * is the maximum size of a signature in bytes.
660
+ */
661
+ #define PSA_SIGNATURE_MAX_SIZE 1
662
+
663
+ #if (defined(PSA_WANT_ALG_ECDSA) || defined(PSA_WANT_ALG_DETERMINISTIC_ECDSA)) && \
664
+ (PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE > PSA_SIGNATURE_MAX_SIZE)
665
+ #undef PSA_SIGNATURE_MAX_SIZE
666
+ #define PSA_SIGNATURE_MAX_SIZE PSA_VENDOR_ECDSA_SIGNATURE_MAX_SIZE
667
+ #endif
668
+ #if (defined(PSA_WANT_ALG_RSA_PKCS1V15_SIGN) || defined(PSA_WANT_ALG_RSA_PSS)) && \
669
+ (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS) > PSA_SIGNATURE_MAX_SIZE)
670
+ #undef PSA_SIGNATURE_MAX_SIZE
671
+ #define PSA_SIGNATURE_MAX_SIZE PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS)
672
+ #endif
673
+
674
+ /** Sufficient output buffer size for psa_asymmetric_encrypt().
675
+ *
676
+ * This macro returns a sufficient buffer size for a ciphertext produced using
677
+ * a key of the specified type and size, with the specified algorithm.
678
+ * Note that the actual size of the ciphertext may be smaller, depending
679
+ * on the algorithm.
680
+ *
681
+ * \warning This function may call its arguments multiple times or
682
+ * zero times, so you should not pass arguments that contain
683
+ * side effects.
684
+ *
685
+ * \param key_type An asymmetric key type (this may indifferently be a
686
+ * key pair type or a public key type).
687
+ * \param key_bits The size of the key in bits.
688
+ * \param alg The asymmetric encryption algorithm.
689
+ *
690
+ * \return If the parameters are valid and supported, return
691
+ * a buffer size in bytes that guarantees that
692
+ * psa_asymmetric_encrypt() will not fail with
693
+ * #PSA_ERROR_BUFFER_TOO_SMALL.
694
+ * If the parameters are a valid combination that is not supported,
695
+ * return either a sensible size or 0.
696
+ * If the parameters are not valid, the
697
+ * return value is unspecified.
698
+ */
699
+ #define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
700
+ (PSA_KEY_TYPE_IS_RSA(key_type) ? \
701
+ ((void) alg, PSA_BITS_TO_BYTES(key_bits)) : \
702
+ 0u)
703
+
704
+ /** A sufficient output buffer size for psa_asymmetric_encrypt(), for any
705
+ * supported asymmetric encryption.
706
+ *
707
+ * See also #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\p key_type, \p key_bits, \p alg).
708
+ */
709
+ /* This macro assumes that RSA is the only supported asymmetric encryption. */
710
+ #define PSA_ASYMMETRIC_ENCRYPT_OUTPUT_MAX_SIZE \
711
+ (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))
712
+
713
+ /** Sufficient output buffer size for psa_asymmetric_decrypt().
714
+ *
715
+ * This macro returns a sufficient buffer size for a plaintext produced using
716
+ * a key of the specified type and size, with the specified algorithm.
717
+ * Note that the actual size of the plaintext may be smaller, depending
718
+ * on the algorithm.
719
+ *
720
+ * \warning This function may call its arguments multiple times or
721
+ * zero times, so you should not pass arguments that contain
722
+ * side effects.
723
+ *
724
+ * \param key_type An asymmetric key type (this may indifferently be a
725
+ * key pair type or a public key type).
726
+ * \param key_bits The size of the key in bits.
727
+ * \param alg The asymmetric encryption algorithm.
728
+ *
729
+ * \return If the parameters are valid and supported, return
730
+ * a buffer size in bytes that guarantees that
731
+ * psa_asymmetric_decrypt() will not fail with
732
+ * #PSA_ERROR_BUFFER_TOO_SMALL.
733
+ * If the parameters are a valid combination that is not supported,
734
+ * return either a sensible size or 0.
735
+ * If the parameters are not valid, the
736
+ * return value is unspecified.
737
+ */
738
+ #define PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(key_type, key_bits, alg) \
739
+ (PSA_KEY_TYPE_IS_RSA(key_type) ? \
740
+ PSA_BITS_TO_BYTES(key_bits) - PSA_RSA_MINIMUM_PADDING_SIZE(alg) : \
741
+ 0u)
742
+
743
+ /** A sufficient output buffer size for psa_asymmetric_decrypt(), for any
744
+ * supported asymmetric decryption.
745
+ *
746
+ * This macro assumes that RSA is the only supported asymmetric encryption.
747
+ *
748
+ * See also #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\p key_type, \p key_bits, \p alg).
749
+ */
750
+ #define PSA_ASYMMETRIC_DECRYPT_OUTPUT_MAX_SIZE \
751
+ (PSA_BITS_TO_BYTES(PSA_VENDOR_RSA_MAX_KEY_BITS))
752
+
753
+ /* Maximum size of the ASN.1 encoding of an INTEGER with the specified
754
+ * number of bits.
755
+ *
756
+ * This definition assumes that bits <= 2^19 - 9 so that the length field
757
+ * is at most 3 bytes. The length of the encoding is the length of the
758
+ * bit string padded to a whole number of bytes plus:
759
+ * - 1 type byte;
760
+ * - 1 to 3 length bytes;
761
+ * - 0 to 1 bytes of leading 0 due to the sign bit.
762
+ */
763
+ #define PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(bits) \
764
+ ((bits) / 8u + 5u)
765
+
766
+ /* Maximum size of the export encoding of an RSA public key.
767
+ * Assumes that the public exponent is less than 2^32.
768
+ *
769
+ * RSAPublicKey ::= SEQUENCE {
770
+ * modulus INTEGER, -- n
771
+ * publicExponent INTEGER } -- e
772
+ *
773
+ * - 4 bytes of SEQUENCE overhead;
774
+ * - n : INTEGER;
775
+ * - 7 bytes for the public exponent.
776
+ */
777
+ #define PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) \
778
+ (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) + 11u)
779
+
780
+ /* Maximum size of the export encoding of an RSA key pair.
781
+ * Assumes that the public exponent is less than 2^32 and that the size
782
+ * difference between the two primes is at most 1 bit.
783
+ *
784
+ * RSAPrivateKey ::= SEQUENCE {
785
+ * version Version, -- 0
786
+ * modulus INTEGER, -- N-bit
787
+ * publicExponent INTEGER, -- 32-bit
788
+ * privateExponent INTEGER, -- N-bit
789
+ * prime1 INTEGER, -- N/2-bit
790
+ * prime2 INTEGER, -- N/2-bit
791
+ * exponent1 INTEGER, -- N/2-bit
792
+ * exponent2 INTEGER, -- N/2-bit
793
+ * coefficient INTEGER, -- N/2-bit
794
+ * }
795
+ *
796
+ * - 4 bytes of SEQUENCE overhead;
797
+ * - 3 bytes of version;
798
+ * - 7 half-size INTEGERs plus 2 full-size INTEGERs,
799
+ * overapproximated as 9 half-size INTEGERS;
800
+ * - 7 bytes for the public exponent.
801
+ */
802
+ #define PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) \
803
+ (9u * PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE((key_bits) / 2u + 1u) + 14u)
804
+
805
+ /* Maximum size of the export encoding of a DSA public key.
806
+ *
807
+ * SubjectPublicKeyInfo ::= SEQUENCE {
808
+ * algorithm AlgorithmIdentifier,
809
+ * subjectPublicKey BIT STRING } -- contains DSAPublicKey
810
+ * AlgorithmIdentifier ::= SEQUENCE {
811
+ * algorithm OBJECT IDENTIFIER,
812
+ * parameters Dss-Params } -- SEQUENCE of 3 INTEGERs
813
+ * DSAPublicKey ::= INTEGER -- public key, Y
814
+ *
815
+ * - 3 * 4 bytes of SEQUENCE overhead;
816
+ * - 1 + 1 + 7 bytes of algorithm (DSA OID);
817
+ * - 4 bytes of BIT STRING overhead;
818
+ * - 3 full-size INTEGERs (p, g, y);
819
+ * - 1 + 1 + 32 bytes for 1 sub-size INTEGER (q <= 256 bits).
820
+ */
821
+ #define PSA_KEY_EXPORT_DSA_PUBLIC_KEY_MAX_SIZE(key_bits) \
822
+ (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3u + 59u)
823
+
824
+ /* Maximum size of the export encoding of a DSA key pair.
825
+ *
826
+ * DSAPrivateKey ::= SEQUENCE {
827
+ * version Version, -- 0
828
+ * prime INTEGER, -- p
829
+ * subprime INTEGER, -- q
830
+ * generator INTEGER, -- g
831
+ * public INTEGER, -- y
832
+ * private INTEGER, -- x
833
+ * }
834
+ *
835
+ * - 4 bytes of SEQUENCE overhead;
836
+ * - 3 bytes of version;
837
+ * - 3 full-size INTEGERs (p, g, y);
838
+ * - 2 * (1 + 1 + 32) bytes for 2 sub-size INTEGERs (q, x <= 256 bits).
839
+ */
840
+ #define PSA_KEY_EXPORT_DSA_KEY_PAIR_MAX_SIZE(key_bits) \
841
+ (PSA_KEY_EXPORT_ASN1_INTEGER_MAX_SIZE(key_bits) * 3u + 75u)
842
+
843
+ /* Maximum size of the export encoding of an ECC public key.
844
+ *
845
+ * The representation of an ECC public key is:
846
+ * - The byte 0x04;
847
+ * - `x_P` as a `ceiling(m/8)`-byte string, big-endian;
848
+ * - `y_P` as a `ceiling(m/8)`-byte string, big-endian;
849
+ * - where m is the bit size associated with the curve.
850
+ *
851
+ * - 1 byte + 2 * point size.
852
+ */
853
+ #define PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) \
854
+ (2u * PSA_BITS_TO_BYTES(key_bits) + 1u)
855
+
856
+ /* Maximum size of the export encoding of an ECC key pair.
857
+ *
858
+ * An ECC key pair is represented by the secret value.
859
+ */
860
+ #define PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) \
861
+ (PSA_BITS_TO_BYTES(key_bits))
862
+
863
+ /* Maximum size of the export encoding of an DH key pair.
864
+ *
865
+ * An DH key pair is represented by the secret value.
866
+ */
867
+ #define PSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE(key_bits) \
868
+ (PSA_BITS_TO_BYTES(key_bits))
869
+
870
+ /* Maximum size of the export encoding of an DH public key.
871
+ */
872
+ #define PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(key_bits) \
873
+ (PSA_BITS_TO_BYTES(key_bits))
874
+
875
+ /** Sufficient output buffer size for psa_export_key() or
876
+ * psa_export_public_key().
877
+ *
878
+ * This macro returns a compile-time constant if its arguments are
879
+ * compile-time constants.
880
+ *
881
+ * \warning This macro may evaluate its arguments multiple times or
882
+ * zero times, so you should not pass arguments that contain
883
+ * side effects.
884
+ *
885
+ * The following code illustrates how to allocate enough memory to export
886
+ * a key by querying the key type and size at runtime.
887
+ * \code{c}
888
+ * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
889
+ * psa_status_t status;
890
+ * status = psa_get_key_attributes(key, &attributes);
891
+ * if (status != PSA_SUCCESS) handle_error(...);
892
+ * psa_key_type_t key_type = psa_get_key_type(&attributes);
893
+ * size_t key_bits = psa_get_key_bits(&attributes);
894
+ * size_t buffer_size = PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits);
895
+ * psa_reset_key_attributes(&attributes);
896
+ * uint8_t *buffer = malloc(buffer_size);
897
+ * if (buffer == NULL) handle_error(...);
898
+ * size_t buffer_length;
899
+ * status = psa_export_key(key, buffer, buffer_size, &buffer_length);
900
+ * if (status != PSA_SUCCESS) handle_error(...);
901
+ * \endcode
902
+ *
903
+ * \param key_type A supported key type.
904
+ * \param key_bits The size of the key in bits.
905
+ *
906
+ * \return If the parameters are valid and supported, return
907
+ * a buffer size in bytes that guarantees that
908
+ * psa_export_key() or psa_export_public_key() will not fail with
909
+ * #PSA_ERROR_BUFFER_TOO_SMALL.
910
+ * If the parameters are a valid combination that is not supported,
911
+ * return either a sensible size or 0.
912
+ * If the parameters are not valid, the return value is unspecified.
913
+ */
914
+ #define PSA_EXPORT_KEY_OUTPUT_SIZE(key_type, key_bits) \
915
+ ((key_type) == PSA_KEY_TYPE_RSA_KEY_PAIR ? PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(key_bits) : \
916
+ (key_type) == PSA_KEY_TYPE_RSA_PUBLIC_KEY ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \
917
+ PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) ? PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(key_bits) : \
918
+ PSA_KEY_TYPE_IS_ECC_PUBLIC_KEY(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \
919
+ PSA_BITS_TO_BYTES(key_bits)) /*unstructured; FFDH public or private*/
920
+
921
+ /** Sufficient output buffer size for psa_export_public_key().
922
+ *
923
+ * This macro returns a compile-time constant if its arguments are
924
+ * compile-time constants.
925
+ *
926
+ * \warning This macro may evaluate its arguments multiple times or
927
+ * zero times, so you should not pass arguments that contain
928
+ * side effects.
929
+ *
930
+ * The following code illustrates how to allocate enough memory to export
931
+ * a public key by querying the key type and size at runtime.
932
+ * \code{c}
933
+ * psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
934
+ * psa_status_t status;
935
+ * status = psa_get_key_attributes(key, &attributes);
936
+ * if (status != PSA_SUCCESS) handle_error(...);
937
+ * psa_key_type_t key_type = psa_get_key_type(&attributes);
938
+ * size_t key_bits = psa_get_key_bits(&attributes);
939
+ * size_t buffer_size = PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits);
940
+ * psa_reset_key_attributes(&attributes);
941
+ * uint8_t *buffer = malloc(buffer_size);
942
+ * if (buffer == NULL) handle_error(...);
943
+ * size_t buffer_length;
944
+ * status = psa_export_public_key(key, buffer, buffer_size, &buffer_length);
945
+ * if (status != PSA_SUCCESS) handle_error(...);
946
+ * \endcode
947
+ *
948
+ * \param key_type A public key or key pair key type.
949
+ * \param key_bits The size of the key in bits.
950
+ *
951
+ * \return If the parameters are valid and supported, return
952
+ * a buffer size in bytes that guarantees that
953
+ * psa_export_public_key() will not fail with
954
+ * #PSA_ERROR_BUFFER_TOO_SMALL.
955
+ * If the parameters are a valid combination that is not
956
+ * supported, return either a sensible size or 0.
957
+ * If the parameters are not valid,
958
+ * the return value is unspecified.
959
+ *
960
+ * If the parameters are valid and supported,
961
+ * return the same result as
962
+ * #PSA_EXPORT_KEY_OUTPUT_SIZE(
963
+ * \p #PSA_KEY_TYPE_PUBLIC_KEY_OF_KEY_PAIR(\p key_type),
964
+ * \p key_bits).
965
+ */
966
+ #define PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(key_type, key_bits) \
967
+ (PSA_KEY_TYPE_IS_RSA(key_type) ? PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(key_bits) : \
968
+ PSA_KEY_TYPE_IS_ECC(key_type) ? PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(key_bits) : \
969
+ PSA_KEY_TYPE_IS_DH(key_type) ? PSA_BITS_TO_BYTES(key_bits) : \
970
+ 0u)
971
+
972
+ /** Sufficient buffer size for exporting any asymmetric key pair.
973
+ *
974
+ * This macro expands to a compile-time constant integer. This value is
975
+ * a sufficient buffer size when calling psa_export_key() to export any
976
+ * asymmetric key pair, regardless of the exact key type and key size.
977
+ *
978
+ * See also #PSA_EXPORT_KEY_OUTPUT_SIZE(\p key_type, \p key_bits).
979
+ */
980
+ #define PSA_EXPORT_KEY_PAIR_MAX_SIZE 1
981
+
982
+ #if defined(PSA_WANT_KEY_TYPE_ECC_KEY_PAIR_BASIC) && \
983
+ (PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) > \
984
+ PSA_EXPORT_KEY_PAIR_MAX_SIZE)
985
+ #undef PSA_EXPORT_KEY_PAIR_MAX_SIZE
986
+ #define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
987
+ PSA_KEY_EXPORT_ECC_KEY_PAIR_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
988
+ #endif
989
+ #if defined(PSA_WANT_KEY_TYPE_RSA_KEY_PAIR_BASIC) && \
990
+ (PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > \
991
+ PSA_EXPORT_KEY_PAIR_MAX_SIZE)
992
+ #undef PSA_EXPORT_KEY_PAIR_MAX_SIZE
993
+ #define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
994
+ PSA_KEY_EXPORT_RSA_KEY_PAIR_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)
995
+ #endif
996
+ #if defined(PSA_WANT_KEY_TYPE_DH_KEY_PAIR_BASIC) && \
997
+ (PSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS) > \
998
+ PSA_EXPORT_KEY_PAIR_MAX_SIZE)
999
+ #undef PSA_EXPORT_KEY_PAIR_MAX_SIZE
1000
+ #define PSA_EXPORT_KEY_PAIR_MAX_SIZE \
1001
+ PSA_KEY_EXPORT_FFDH_KEY_PAIR_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS)
1002
+ #endif
1003
+
1004
+ /** Sufficient buffer size for exporting any asymmetric public key.
1005
+ *
1006
+ * This macro expands to a compile-time constant integer. This value is
1007
+ * a sufficient buffer size when calling psa_export_key() or
1008
+ * psa_export_public_key() to export any asymmetric public key,
1009
+ * regardless of the exact key type and key size.
1010
+ *
1011
+ * See also #PSA_EXPORT_PUBLIC_KEY_OUTPUT_SIZE(\p key_type, \p key_bits).
1012
+ */
1013
+ #define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE 1
1014
+
1015
+ #if defined(PSA_WANT_KEY_TYPE_ECC_PUBLIC_KEY) && \
1016
+ (PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS) > \
1017
+ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
1018
+ #undef PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
1019
+ #define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
1020
+ PSA_KEY_EXPORT_ECC_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_ECC_MAX_CURVE_BITS)
1021
+ #endif
1022
+ #if defined(PSA_WANT_KEY_TYPE_RSA_PUBLIC_KEY) && \
1023
+ (PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS) > \
1024
+ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
1025
+ #undef PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
1026
+ #define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
1027
+ PSA_KEY_EXPORT_RSA_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_RSA_MAX_KEY_BITS)
1028
+ #endif
1029
+ #if defined(PSA_WANT_KEY_TYPE_DH_PUBLIC_KEY) && \
1030
+ (PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS) > \
1031
+ PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
1032
+ #undef PSA_EXPORT_PUBLIC_KEY_MAX_SIZE
1033
+ #define PSA_EXPORT_PUBLIC_KEY_MAX_SIZE \
1034
+ PSA_KEY_EXPORT_FFDH_PUBLIC_KEY_MAX_SIZE(PSA_VENDOR_FFDH_MAX_KEY_BITS)
1035
+ #endif
1036
+
1037
+ /* This is the name that was standardized in PSA Crypto v1.3 */
1038
+ #define PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE \
1039
+ ((PSA_EXPORT_KEY_PAIR_MAX_SIZE > PSA_EXPORT_PUBLIC_KEY_MAX_SIZE) ? \
1040
+ PSA_EXPORT_KEY_PAIR_MAX_SIZE : PSA_EXPORT_PUBLIC_KEY_MAX_SIZE)
1041
+
1042
+ /* This is our old custom name from before it was in the spec,
1043
+ * keep it around in case users were relying on it. */
1044
+ #define PSA_EXPORT_KEY_PAIR_OR_PUBLIC_MAX_SIZE \
1045
+ PSA_EXPORT_ASYMMETRIC_KEY_MAX_SIZE
1046
+
1047
+ /** Sufficient output buffer size for psa_raw_key_agreement().
1048
+ *
1049
+ * This macro returns a compile-time constant if its arguments are
1050
+ * compile-time constants.
1051
+ *
1052
+ * \warning This macro may evaluate its arguments multiple times or
1053
+ * zero times, so you should not pass arguments that contain
1054
+ * side effects.
1055
+ *
1056
+ * See also #PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE.
1057
+ *
1058
+ * \param key_type A supported key type.
1059
+ * \param key_bits The size of the key in bits.
1060
+ *
1061
+ * \return If the parameters are valid and supported, return
1062
+ * a buffer size in bytes that guarantees that
1063
+ * psa_raw_key_agreement() will not fail with
1064
+ * #PSA_ERROR_BUFFER_TOO_SMALL.
1065
+ * If the parameters are a valid combination that
1066
+ * is not supported, return either a sensible size or 0.
1067
+ * If the parameters are not valid,
1068
+ * the return value is unspecified.
1069
+ */
1070
+ #define PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(key_type, key_bits) \
1071
+ ((PSA_KEY_TYPE_IS_ECC_KEY_PAIR(key_type) || \
1072
+ PSA_KEY_TYPE_IS_DH_KEY_PAIR(key_type)) ? PSA_BITS_TO_BYTES(key_bits) : 0u)
1073
+
1074
+ /** Maximum size of the output from psa_raw_key_agreement().
1075
+ *
1076
+ * This macro expands to a compile-time constant integer. This value is the
1077
+ * maximum size of the output any raw key agreement algorithm, in bytes.
1078
+ *
1079
+ * See also #PSA_RAW_KEY_AGREEMENT_OUTPUT_SIZE(\p key_type, \p key_bits).
1080
+ */
1081
+ #define PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE 1
1082
+
1083
+ #if defined(PSA_WANT_ALG_ECDH) && \
1084
+ (PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS) > PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE)
1085
+ #undef PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE
1086
+ #define PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE PSA_BITS_TO_BYTES(PSA_VENDOR_ECC_MAX_CURVE_BITS)
1087
+ #endif
1088
+ #if defined(PSA_WANT_ALG_FFDH) && \
1089
+ (PSA_BITS_TO_BYTES(PSA_VENDOR_FFDH_MAX_KEY_BITS) > PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE)
1090
+ #undef PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE
1091
+ #define PSA_RAW_KEY_AGREEMENT_OUTPUT_MAX_SIZE PSA_BITS_TO_BYTES(PSA_VENDOR_FFDH_MAX_KEY_BITS)
1092
+ #endif
1093
+
1094
+ /** Maximum key length for ciphers.
1095
+ *
1096
+ * Since there is no additional PSA_WANT_xxx symbol to specifiy the size of
1097
+ * the key once a cipher is enabled (as it happens for asymmetric keys for
1098
+ * example), the maximum key length is taken into account for each cipher.
1099
+ * The resulting value will be the maximum cipher's key length given depending
1100
+ * on which ciphers are enabled.
1101
+ *
1102
+ * Note: max value for AES used below would be doubled if XTS were enabled, but
1103
+ * this mode is currently not supported in Mbed TLS implementation of PSA
1104
+ * APIs.
1105
+ */
1106
+ #if (defined(PSA_WANT_KEY_TYPE_AES) || defined(PSA_WANT_KEY_TYPE_ARIA) || \
1107
+ defined(PSA_WANT_KEY_TYPE_CAMELLIA) || defined(PSA_WANT_KEY_TYPE_CHACHA20))
1108
+ #define PSA_CIPHER_MAX_KEY_LENGTH 32u
1109
+ #elif defined(PSA_WANT_KEY_TYPE_DES)
1110
+ #define PSA_CIPHER_MAX_KEY_LENGTH 24u
1111
+ #else
1112
+ #define PSA_CIPHER_MAX_KEY_LENGTH 0u
1113
+ #endif
1114
+
1115
+ /** The default IV size for a cipher algorithm, in bytes.
1116
+ *
1117
+ * The IV that is generated as part of a call to #psa_cipher_encrypt() is always
1118
+ * the default IV length for the algorithm.
1119
+ *
1120
+ * This macro can be used to allocate a buffer of sufficient size to
1121
+ * store the IV output from #psa_cipher_generate_iv() when using
1122
+ * a multi-part cipher operation.
1123
+ *
1124
+ * See also #PSA_CIPHER_IV_MAX_SIZE.
1125
+ *
1126
+ * \warning This macro may evaluate its arguments multiple times or
1127
+ * zero times, so you should not pass arguments that contain
1128
+ * side effects.
1129
+ *
1130
+ * \param key_type A symmetric key type that is compatible with algorithm \p alg.
1131
+ *
1132
+ * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that #PSA_ALG_IS_CIPHER(\p alg) is true).
1133
+ *
1134
+ * \return The default IV size for the specified key type and algorithm.
1135
+ * If the algorithm does not use an IV, return 0.
1136
+ * If the key type or cipher algorithm is not recognized,
1137
+ * or the parameters are incompatible, return 0.
1138
+ */
1139
+ #define PSA_CIPHER_IV_LENGTH(key_type, alg) \
1140
+ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) > 1 && \
1141
+ ((alg) == PSA_ALG_CTR || \
1142
+ (alg) == PSA_ALG_CFB || \
1143
+ (alg) == PSA_ALG_OFB || \
1144
+ (alg) == PSA_ALG_XTS || \
1145
+ (alg) == PSA_ALG_CBC_NO_PADDING || \
1146
+ (alg) == PSA_ALG_CBC_PKCS7) ? PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
1147
+ (key_type) == PSA_KEY_TYPE_CHACHA20 && \
1148
+ (alg) == PSA_ALG_STREAM_CIPHER ? 12u : \
1149
+ (alg) == PSA_ALG_CCM_STAR_NO_TAG ? 13u : \
1150
+ 0u)
1151
+
1152
+ /** The maximum IV size for all supported cipher algorithms, in bytes.
1153
+ *
1154
+ * See also #PSA_CIPHER_IV_LENGTH().
1155
+ */
1156
+ #define PSA_CIPHER_IV_MAX_SIZE 16u
1157
+
1158
+ /** The maximum size of the output of psa_cipher_encrypt(), in bytes.
1159
+ *
1160
+ * If the size of the output buffer is at least this large, it is guaranteed
1161
+ * that psa_cipher_encrypt() will not fail due to an insufficient buffer size.
1162
+ * Depending on the algorithm, the actual size of the output might be smaller.
1163
+ *
1164
+ * See also #PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(\p input_length).
1165
+ *
1166
+ * \warning This macro may evaluate its arguments multiple times or
1167
+ * zero times, so you should not pass arguments that contain
1168
+ * side effects.
1169
+ *
1170
+ * \param key_type A symmetric key type that is compatible with algorithm
1171
+ * alg.
1172
+ * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that
1173
+ * #PSA_ALG_IS_CIPHER(\p alg) is true).
1174
+ * \param input_length Size of the input in bytes.
1175
+ *
1176
+ * \return A sufficient output size for the specified key type and
1177
+ * algorithm. If the key type or cipher algorithm is not
1178
+ * recognized, or the parameters are incompatible,
1179
+ * return 0.
1180
+ */
1181
+ #define PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(key_type, alg, input_length) \
1182
+ (alg == PSA_ALG_CBC_PKCS7 ? \
1183
+ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 0 ? \
1184
+ PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), \
1185
+ (input_length) + 1u) + \
1186
+ PSA_CIPHER_IV_LENGTH((key_type), (alg)) : 0u) : \
1187
+ (PSA_ALG_IS_CIPHER(alg) ? \
1188
+ (input_length) + PSA_CIPHER_IV_LENGTH((key_type), (alg)) : \
1189
+ 0u))
1190
+
1191
+ /** A sufficient output buffer size for psa_cipher_encrypt(), for any of the
1192
+ * supported key types and cipher algorithms.
1193
+ *
1194
+ * If the size of the output buffer is at least this large, it is guaranteed
1195
+ * that psa_cipher_encrypt() will not fail due to an insufficient buffer size.
1196
+ *
1197
+ * See also #PSA_CIPHER_ENCRYPT_OUTPUT_SIZE(\p key_type, \p alg, \p input_length).
1198
+ *
1199
+ * \param input_length Size of the input in bytes.
1200
+ *
1201
+ */
1202
+ #define PSA_CIPHER_ENCRYPT_OUTPUT_MAX_SIZE(input_length) \
1203
+ (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, \
1204
+ (input_length) + 1u) + \
1205
+ PSA_CIPHER_IV_MAX_SIZE)
1206
+
1207
+ /** The maximum size of the output of psa_cipher_decrypt(), in bytes.
1208
+ *
1209
+ * If the size of the output buffer is at least this large, it is guaranteed
1210
+ * that psa_cipher_decrypt() will not fail due to an insufficient buffer size.
1211
+ * Depending on the algorithm, the actual size of the output might be smaller.
1212
+ *
1213
+ * See also #PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(\p input_length).
1214
+ *
1215
+ * \param key_type A symmetric key type that is compatible with algorithm
1216
+ * alg.
1217
+ * \param alg A cipher algorithm (\c PSA_ALG_XXX value such that
1218
+ * #PSA_ALG_IS_CIPHER(\p alg) is true).
1219
+ * \param input_length Size of the input in bytes.
1220
+ *
1221
+ * \return A sufficient output size for the specified key type and
1222
+ * algorithm. If the key type or cipher algorithm is not
1223
+ * recognized, or the parameters are incompatible,
1224
+ * return 0.
1225
+ */
1226
+ #define PSA_CIPHER_DECRYPT_OUTPUT_SIZE(key_type, alg, input_length) \
1227
+ (PSA_ALG_IS_CIPHER(alg) && \
1228
+ ((key_type) & PSA_KEY_TYPE_CATEGORY_MASK) == PSA_KEY_TYPE_CATEGORY_SYMMETRIC ? \
1229
+ (input_length) : \
1230
+ 0u)
1231
+
1232
+ /** A sufficient output buffer size for psa_cipher_decrypt(), for any of the
1233
+ * supported key types and cipher algorithms.
1234
+ *
1235
+ * If the size of the output buffer is at least this large, it is guaranteed
1236
+ * that psa_cipher_decrypt() will not fail due to an insufficient buffer size.
1237
+ *
1238
+ * See also #PSA_CIPHER_DECRYPT_OUTPUT_SIZE(\p key_type, \p alg, \p input_length).
1239
+ *
1240
+ * \param input_length Size of the input in bytes.
1241
+ */
1242
+ #define PSA_CIPHER_DECRYPT_OUTPUT_MAX_SIZE(input_length) \
1243
+ (input_length)
1244
+
1245
+ /** A sufficient output buffer size for psa_cipher_update().
1246
+ *
1247
+ * If the size of the output buffer is at least this large, it is guaranteed
1248
+ * that psa_cipher_update() will not fail due to an insufficient buffer size.
1249
+ * The actual size of the output might be smaller in any given call.
1250
+ *
1251
+ * See also #PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(\p input_length).
1252
+ *
1253
+ * \param key_type A symmetric key type that is compatible with algorithm
1254
+ * alg.
1255
+ * \param alg A cipher algorithm (PSA_ALG_XXX value such that
1256
+ * #PSA_ALG_IS_CIPHER(\p alg) is true).
1257
+ * \param input_length Size of the input in bytes.
1258
+ *
1259
+ * \return A sufficient output size for the specified key type and
1260
+ * algorithm. If the key type or cipher algorithm is not
1261
+ * recognized, or the parameters are incompatible, return 0.
1262
+ */
1263
+ #define PSA_CIPHER_UPDATE_OUTPUT_SIZE(key_type, alg, input_length) \
1264
+ (PSA_ALG_IS_CIPHER(alg) ? \
1265
+ (PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) != 0 ? \
1266
+ (((alg) == PSA_ALG_CBC_PKCS7 || \
1267
+ (alg) == PSA_ALG_CBC_NO_PADDING || \
1268
+ (alg) == PSA_ALG_ECB_NO_PADDING) ? \
1269
+ PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type), \
1270
+ input_length) : \
1271
+ (input_length)) : 0u) : \
1272
+ 0u)
1273
+
1274
+ /** A sufficient output buffer size for psa_cipher_update(), for any of the
1275
+ * supported key types and cipher algorithms.
1276
+ *
1277
+ * If the size of the output buffer is at least this large, it is guaranteed
1278
+ * that psa_cipher_update() will not fail due to an insufficient buffer size.
1279
+ *
1280
+ * See also #PSA_CIPHER_UPDATE_OUTPUT_SIZE(\p key_type, \p alg, \p input_length).
1281
+ *
1282
+ * \param input_length Size of the input in bytes.
1283
+ */
1284
+ #define PSA_CIPHER_UPDATE_OUTPUT_MAX_SIZE(input_length) \
1285
+ (PSA_ROUND_UP_TO_MULTIPLE(PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE, input_length))
1286
+
1287
+ /** A sufficient ciphertext buffer size for psa_cipher_finish().
1288
+ *
1289
+ * If the size of the ciphertext buffer is at least this large, it is
1290
+ * guaranteed that psa_cipher_finish() will not fail due to an insufficient
1291
+ * ciphertext buffer size. The actual size of the output might be smaller in
1292
+ * any given call.
1293
+ *
1294
+ * See also #PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE().
1295
+ *
1296
+ * \param key_type A symmetric key type that is compatible with algorithm
1297
+ * alg.
1298
+ * \param alg A cipher algorithm (PSA_ALG_XXX value such that
1299
+ * #PSA_ALG_IS_CIPHER(\p alg) is true).
1300
+ * \return A sufficient output size for the specified key type and
1301
+ * algorithm. If the key type or cipher algorithm is not
1302
+ * recognized, or the parameters are incompatible, return 0.
1303
+ */
1304
+ #define PSA_CIPHER_FINISH_OUTPUT_SIZE(key_type, alg) \
1305
+ (PSA_ALG_IS_CIPHER(alg) ? \
1306
+ (alg == PSA_ALG_CBC_PKCS7 ? \
1307
+ PSA_BLOCK_CIPHER_BLOCK_LENGTH(key_type) : \
1308
+ 0u) : \
1309
+ 0u)
1310
+
1311
+ /** A sufficient ciphertext buffer size for psa_cipher_finish(), for any of the
1312
+ * supported key types and cipher algorithms.
1313
+ *
1314
+ * See also #PSA_CIPHER_FINISH_OUTPUT_SIZE(\p key_type, \p alg).
1315
+ */
1316
+ #define PSA_CIPHER_FINISH_OUTPUT_MAX_SIZE \
1317
+ (PSA_BLOCK_CIPHER_BLOCK_MAX_SIZE)
1318
+
1319
+ #endif /* PSA_CRYPTO_SIZES_H */