visaljs 0.0.0-stage → 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 (520) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +45 -2
  3. package/cli.js +8084 -0
  4. package/node/include/js_node.h +46 -0
  5. package/node/prelude/async_hooks.js +88 -0
  6. package/node/prelude/buffer.js +31 -0
  7. package/node/prelude/crypto.js +114 -0
  8. package/node/prelude/events.js +227 -0
  9. package/node/prelude/fs.js +79 -0
  10. package/node/prelude/http.js +536 -0
  11. package/node/prelude/http2.js +30 -0
  12. package/node/prelude/internal/crypto/asym.js +333 -0
  13. package/node/prelude/internal/crypto/cipher.js +205 -0
  14. package/node/prelude/internal/crypto/hash.js +137 -0
  15. package/node/prelude/internal/crypto/kdf.js +182 -0
  16. package/node/prelude/internal/crypto/keys.js +603 -0
  17. package/node/prelude/internal/crypto/random.js +118 -0
  18. package/node/prelude/internal/crypto/util.js +76 -0
  19. package/node/prelude/internal/errors.js +88 -0
  20. package/node/prelude/internal/querystring.js +105 -0
  21. package/node/prelude/module.js +53 -0
  22. package/node/prelude/net.js +51 -0
  23. package/node/prelude/os.js +129 -0
  24. package/node/prelude/path.js +257 -0
  25. package/node/prelude/process.js +21 -0
  26. package/node/prelude/querystring.js +469 -0
  27. package/node/prelude/stream.js +1327 -0
  28. package/node/prelude/stream_promises.js +7 -0
  29. package/node/prelude/stream_web.js +6 -0
  30. package/node/prelude/string_decoder.js +236 -0
  31. package/node/prelude/tty.js +18 -0
  32. package/node/prelude/url.js +1156 -0
  33. package/node/prelude/util.js +64 -0
  34. package/node/prelude/zlib.js +81 -0
  35. package/node/src/host_fs.c +126 -0
  36. package/node/src/host_http.c +486 -0
  37. package/node/src/host_os.c +505 -0
  38. package/node/src/host_sys.c +78 -0
  39. package/node/third_party/libuv/LICENSE +19 -0
  40. package/node/third_party/libuv/include/uv/aix.h +32 -0
  41. package/node/third_party/libuv/include/uv/bsd.h +34 -0
  42. package/node/third_party/libuv/include/uv/darwin.h +61 -0
  43. package/node/third_party/libuv/include/uv/errno.h +483 -0
  44. package/node/third_party/libuv/include/uv/linux.h +34 -0
  45. package/node/third_party/libuv/include/uv/os390.h +33 -0
  46. package/node/third_party/libuv/include/uv/posix.h +31 -0
  47. package/node/third_party/libuv/include/uv/sunos.h +44 -0
  48. package/node/third_party/libuv/include/uv/threadpool.h +37 -0
  49. package/node/third_party/libuv/include/uv/tree.h +521 -0
  50. package/node/third_party/libuv/include/uv/unix.h +512 -0
  51. package/node/third_party/libuv/include/uv/version.h +43 -0
  52. package/node/third_party/libuv/include/uv/win.h +698 -0
  53. package/node/third_party/libuv/include/uv.h +1990 -0
  54. package/node/third_party/libuv/src/fs-poll.c +290 -0
  55. package/node/third_party/libuv/src/heap-inl.h +245 -0
  56. package/node/third_party/libuv/src/idna.c +560 -0
  57. package/node/third_party/libuv/src/idna.h +31 -0
  58. package/node/third_party/libuv/src/inet.c +298 -0
  59. package/node/third_party/libuv/src/queue.h +90 -0
  60. package/node/third_party/libuv/src/random.c +123 -0
  61. package/node/third_party/libuv/src/strscpy.c +38 -0
  62. package/node/third_party/libuv/src/strscpy.h +39 -0
  63. package/node/third_party/libuv/src/strtok.c +52 -0
  64. package/node/third_party/libuv/src/strtok.h +27 -0
  65. package/node/third_party/libuv/src/thread-common.c +175 -0
  66. package/node/third_party/libuv/src/threadpool.c +419 -0
  67. package/node/third_party/libuv/src/timer.c +200 -0
  68. package/node/third_party/libuv/src/unix/async.c +418 -0
  69. package/node/third_party/libuv/src/unix/bsd-ifaddrs.c +164 -0
  70. package/node/third_party/libuv/src/unix/core.c +2104 -0
  71. package/node/third_party/libuv/src/unix/darwin-proctitle.c +176 -0
  72. package/node/third_party/libuv/src/unix/darwin-stub.h +97 -0
  73. package/node/third_party/libuv/src/unix/darwin-syscalls.h +17 -0
  74. package/node/third_party/libuv/src/unix/darwin.c +237 -0
  75. package/node/third_party/libuv/src/unix/dl.c +80 -0
  76. package/node/third_party/libuv/src/unix/fs.c +2303 -0
  77. package/node/third_party/libuv/src/unix/fsevents.c +906 -0
  78. package/node/third_party/libuv/src/unix/getaddrinfo.c +252 -0
  79. package/node/third_party/libuv/src/unix/getnameinfo.c +121 -0
  80. package/node/third_party/libuv/src/unix/internal.h +530 -0
  81. package/node/third_party/libuv/src/unix/kqueue.c +667 -0
  82. package/node/third_party/libuv/src/unix/linux.c +2761 -0
  83. package/node/third_party/libuv/src/unix/loop-watcher.c +68 -0
  84. package/node/third_party/libuv/src/unix/loop.c +240 -0
  85. package/node/third_party/libuv/src/unix/pipe.c +555 -0
  86. package/node/third_party/libuv/src/unix/poll.c +159 -0
  87. package/node/third_party/libuv/src/unix/process.c +1123 -0
  88. package/node/third_party/libuv/src/unix/procfs-exepath.c +45 -0
  89. package/node/third_party/libuv/src/unix/proctitle.c +157 -0
  90. package/node/third_party/libuv/src/unix/random-devurandom.c +93 -0
  91. package/node/third_party/libuv/src/unix/random-getentropy.c +57 -0
  92. package/node/third_party/libuv/src/unix/random-getrandom.c +86 -0
  93. package/node/third_party/libuv/src/unix/random-sysctl-linux.c +99 -0
  94. package/node/third_party/libuv/src/unix/signal.c +581 -0
  95. package/node/third_party/libuv/src/unix/stream.c +1567 -0
  96. package/node/third_party/libuv/src/unix/tcp.c +673 -0
  97. package/node/third_party/libuv/src/unix/thread.c +975 -0
  98. package/node/third_party/libuv/src/unix/tty.c +510 -0
  99. package/node/third_party/libuv/src/unix/udp.c +1434 -0
  100. package/node/third_party/libuv/src/uv-common.c +1051 -0
  101. package/node/third_party/libuv/src/uv-common.h +474 -0
  102. package/node/third_party/libuv/src/uv-data-getter-setters.c +119 -0
  103. package/node/third_party/libuv/src/version.c +45 -0
  104. package/node/third_party/llhttp/LICENSE +22 -0
  105. package/node/third_party/llhttp/api.c +509 -0
  106. package/node/third_party/llhttp/http.c +170 -0
  107. package/node/third_party/llhttp/llhttp.c +10099 -0
  108. package/node/third_party/llhttp/llhttp.h +907 -0
  109. package/package.json +25 -4
  110. package/runtime/include/js_atoms.gen.h +68 -0
  111. package/runtime/include/js_atoms.h +54 -0
  112. package/runtime/include/js_bigint.h +93 -0
  113. package/runtime/include/js_buffer.h +79 -0
  114. package/runtime/include/js_builtins.h +168 -0
  115. package/runtime/include/js_console.h +58 -0
  116. package/runtime/include/js_convert.h +22 -0
  117. package/runtime/include/js_core.def +188 -0
  118. package/runtime/include/js_crypto.h +58 -0
  119. package/runtime/include/js_error.h +37 -0
  120. package/runtime/include/js_exception.h +65 -0
  121. package/runtime/include/js_function.h +167 -0
  122. package/runtime/include/js_gc.h +195 -0
  123. package/runtime/include/js_generator.h +96 -0
  124. package/runtime/include/js_host.h +19 -0
  125. package/runtime/include/js_jobs.h +84 -0
  126. package/runtime/include/js_module.h +16 -0
  127. package/runtime/include/js_object.h +384 -0
  128. package/runtime/include/js_ops.h +111 -0
  129. package/runtime/include/js_promise.h +45 -0
  130. package/runtime/include/js_regexp.h +25 -0
  131. package/runtime/include/js_runtime.h +30 -0
  132. package/runtime/include/js_symbol.h +62 -0
  133. package/runtime/include/js_web.h +110 -0
  134. package/runtime/include/jscell.h +48 -0
  135. package/runtime/include/jscontext.h +240 -0
  136. package/runtime/include/jsnum.h +42 -0
  137. package/runtime/include/jsstring.h +161 -0
  138. package/runtime/include/jsvalue.h +142 -0
  139. package/runtime/src/arguments.c +115 -0
  140. package/runtime/src/array.c +1145 -0
  141. package/runtime/src/arraybuffer.c +608 -0
  142. package/runtime/src/async_iter.c +479 -0
  143. package/runtime/src/atoms.c +157 -0
  144. package/runtime/src/base64.c +107 -0
  145. package/runtime/src/bigint.c +1189 -0
  146. package/runtime/src/blob.c +371 -0
  147. package/runtime/src/buffer.c +1357 -0
  148. package/runtime/src/builtin_table.c +100 -0
  149. package/runtime/src/builtins.c +987 -0
  150. package/runtime/src/builtins_util.h +53 -0
  151. package/runtime/src/collections.c +912 -0
  152. package/runtime/src/components.c +28 -0
  153. package/runtime/src/console.c +637 -0
  154. package/runtime/src/convert.c +82 -0
  155. package/runtime/src/core_all.c +21 -0
  156. package/runtime/src/crypto.c +116 -0
  157. package/runtime/src/crypto_asym.c +644 -0
  158. package/runtime/src/crypto_cipher.c +671 -0
  159. package/runtime/src/crypto_hash.c +260 -0
  160. package/runtime/src/crypto_host.c +414 -0
  161. package/runtime/src/crypto_internal.h +304 -0
  162. package/runtime/src/crypto_kdf.c +143 -0
  163. package/runtime/src/crypto_key.c +171 -0
  164. package/runtime/src/crypto_pkey.c +794 -0
  165. package/runtime/src/crypto_subtle.c +1675 -0
  166. package/runtime/src/date.c +940 -0
  167. package/runtime/src/domexception.c +169 -0
  168. package/runtime/src/elements.c +312 -0
  169. package/runtime/src/elements.h +45 -0
  170. package/runtime/src/encoding.c +485 -0
  171. package/runtime/src/error.c +297 -0
  172. package/runtime/src/events.c +793 -0
  173. package/runtime/src/exception.c +56 -0
  174. package/runtime/src/fetch.c +772 -0
  175. package/runtime/src/function.c +530 -0
  176. package/runtime/src/gc.c +803 -0
  177. package/runtime/src/generator.c +218 -0
  178. package/runtime/src/global.c +119 -0
  179. package/runtime/src/headers.c +557 -0
  180. package/runtime/src/inspect.c +1792 -0
  181. package/runtime/src/internal.h +80 -0
  182. package/runtime/src/iterate.c +94 -0
  183. package/runtime/src/iterator.c +409 -0
  184. package/runtime/src/jobs.c +337 -0
  185. package/runtime/src/jsnum.c +353 -0
  186. package/runtime/src/json.c +1028 -0
  187. package/runtime/src/math.c +243 -0
  188. package/runtime/src/module.c +336 -0
  189. package/runtime/src/number.c +176 -0
  190. package/runtime/src/object.c +1265 -0
  191. package/runtime/src/ops.c +322 -0
  192. package/runtime/src/os.c +196 -0
  193. package/runtime/src/os.h +29 -0
  194. package/runtime/src/process.c +432 -0
  195. package/runtime/src/promise.c +721 -0
  196. package/runtime/src/proxy.c +570 -0
  197. package/runtime/src/reflect.c +194 -0
  198. package/runtime/src/regexp.c +1141 -0
  199. package/runtime/src/regexp_anchor.h +34 -0
  200. package/runtime/src/regexp_message.h +32 -0
  201. package/runtime/src/shape.c +294 -0
  202. package/runtime/src/shape.h +46 -0
  203. package/runtime/src/streams.c +1046 -0
  204. package/runtime/src/streams.h +47 -0
  205. package/runtime/src/string.c +364 -0
  206. package/runtime/src/string_builtins.c +837 -0
  207. package/runtime/src/symbol.c +143 -0
  208. package/runtime/src/test_host.c +59 -0
  209. package/runtime/src/typedarray.c +1330 -0
  210. package/runtime/src/tznames.gen.h +712 -0
  211. package/runtime/src/uri.c +169 -0
  212. package/runtime/src/url.c +2116 -0
  213. package/runtime/src/weak.c +486 -0
  214. package/runtime/src/web.c +214 -0
  215. package/runtime/src/wrapper.c +59 -0
  216. package/runtime/src/writable.c +1486 -0
  217. package/runtime/third_party/ada-idna/LICENSE-MIT +18 -0
  218. package/runtime/third_party/ada-idna/README.md +27 -0
  219. package/runtime/third_party/ada-idna/convert.mjs +83 -0
  220. package/runtime/third_party/ada-idna/idna.c +416 -0
  221. package/runtime/third_party/ada-idna/idna.h +15 -0
  222. package/runtime/third_party/ada-idna/idna_tables.h +2657 -0
  223. package/runtime/third_party/bearssl/LICENSE.txt +21 -0
  224. package/runtime/third_party/bearssl/README.txt +136 -0
  225. package/runtime/third_party/bearssl/VERSION +1 -0
  226. package/runtime/third_party/bearssl/inc/bearssl.h +183 -0
  227. package/runtime/third_party/bearssl/inc/bearssl_aead.h +1059 -0
  228. package/runtime/third_party/bearssl/inc/bearssl_block.h +2618 -0
  229. package/runtime/third_party/bearssl/inc/bearssl_ec.h +967 -0
  230. package/runtime/third_party/bearssl/inc/bearssl_hash.h +1346 -0
  231. package/runtime/third_party/bearssl/inc/bearssl_hmac.h +241 -0
  232. package/runtime/third_party/bearssl/inc/bearssl_kdf.h +284 -0
  233. package/runtime/third_party/bearssl/inc/bearssl_pem.h +294 -0
  234. package/runtime/third_party/bearssl/inc/bearssl_prf.h +150 -0
  235. package/runtime/third_party/bearssl/inc/bearssl_rand.h +397 -0
  236. package/runtime/third_party/bearssl/inc/bearssl_rsa.h +1655 -0
  237. package/runtime/third_party/bearssl/inc/bearssl_ssl.h +4296 -0
  238. package/runtime/third_party/bearssl/inc/bearssl_x509.h +1474 -0
  239. package/runtime/third_party/bearssl/src/aead/ccm.c +346 -0
  240. package/runtime/third_party/bearssl/src/aead/eax.c +525 -0
  241. package/runtime/third_party/bearssl/src/aead/gcm.c +318 -0
  242. package/runtime/third_party/bearssl/src/codec/ccopy.c +44 -0
  243. package/runtime/third_party/bearssl/src/codec/dec16be.c +38 -0
  244. package/runtime/third_party/bearssl/src/codec/dec16le.c +38 -0
  245. package/runtime/third_party/bearssl/src/codec/dec32be.c +38 -0
  246. package/runtime/third_party/bearssl/src/codec/dec32le.c +38 -0
  247. package/runtime/third_party/bearssl/src/codec/dec64be.c +38 -0
  248. package/runtime/third_party/bearssl/src/codec/dec64le.c +38 -0
  249. package/runtime/third_party/bearssl/src/codec/enc16be.c +38 -0
  250. package/runtime/third_party/bearssl/src/codec/enc16le.c +38 -0
  251. package/runtime/third_party/bearssl/src/codec/enc32be.c +38 -0
  252. package/runtime/third_party/bearssl/src/codec/enc32le.c +38 -0
  253. package/runtime/third_party/bearssl/src/codec/enc64be.c +38 -0
  254. package/runtime/third_party/bearssl/src/codec/enc64le.c +38 -0
  255. package/runtime/third_party/bearssl/src/codec/pemdec.c +526 -0
  256. package/runtime/third_party/bearssl/src/codec/pemdec.t0 +314 -0
  257. package/runtime/third_party/bearssl/src/codec/pemenc.c +173 -0
  258. package/runtime/third_party/bearssl/src/config.h +247 -0
  259. package/runtime/third_party/bearssl/src/ec/ec_all_m15.c +121 -0
  260. package/runtime/third_party/bearssl/src/ec/ec_all_m31.c +171 -0
  261. package/runtime/third_party/bearssl/src/ec/ec_c25519_i15.c +398 -0
  262. package/runtime/third_party/bearssl/src/ec/ec_c25519_i31.c +390 -0
  263. package/runtime/third_party/bearssl/src/ec/ec_c25519_m15.c +1478 -0
  264. package/runtime/third_party/bearssl/src/ec/ec_c25519_m31.c +800 -0
  265. package/runtime/third_party/bearssl/src/ec/ec_c25519_m62.c +605 -0
  266. package/runtime/third_party/bearssl/src/ec/ec_c25519_m64.c +831 -0
  267. package/runtime/third_party/bearssl/src/ec/ec_curve25519.c +46 -0
  268. package/runtime/third_party/bearssl/src/ec/ec_default.c +36 -0
  269. package/runtime/third_party/bearssl/src/ec/ec_keygen.c +86 -0
  270. package/runtime/third_party/bearssl/src/ec/ec_p256_m15.c +2124 -0
  271. package/runtime/third_party/bearssl/src/ec/ec_p256_m31.c +1469 -0
  272. package/runtime/third_party/bearssl/src/ec/ec_p256_m62.c +1765 -0
  273. package/runtime/third_party/bearssl/src/ec/ec_p256_m64.c +1781 -0
  274. package/runtime/third_party/bearssl/src/ec/ec_prime_i15.c +824 -0
  275. package/runtime/third_party/bearssl/src/ec/ec_prime_i31.c +826 -0
  276. package/runtime/third_party/bearssl/src/ec/ec_pubkey.c +85 -0
  277. package/runtime/third_party/bearssl/src/ec/ec_secp256r1.c +51 -0
  278. package/runtime/third_party/bearssl/src/ec/ec_secp384r1.c +57 -0
  279. package/runtime/third_party/bearssl/src/ec/ec_secp521r1.c +64 -0
  280. package/runtime/third_party/bearssl/src/ec/ecdsa_atr.c +134 -0
  281. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_asn1.c +36 -0
  282. package/runtime/third_party/bearssl/src/ec/ecdsa_default_sign_raw.c +36 -0
  283. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_asn1.c +36 -0
  284. package/runtime/third_party/bearssl/src/ec/ecdsa_default_vrfy_raw.c +36 -0
  285. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_bits.c +47 -0
  286. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_asn1.c +45 -0
  287. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_sign_raw.c +174 -0
  288. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_asn1.c +48 -0
  289. package/runtime/third_party/bearssl/src/ec/ecdsa_i15_vrfy_raw.c +166 -0
  290. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_bits.c +47 -0
  291. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_asn1.c +45 -0
  292. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_sign_raw.c +173 -0
  293. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_asn1.c +48 -0
  294. package/runtime/third_party/bearssl/src/ec/ecdsa_i31_vrfy_raw.c +165 -0
  295. package/runtime/third_party/bearssl/src/ec/ecdsa_rta.c +121 -0
  296. package/runtime/third_party/bearssl/src/hash/dig_oid.c +84 -0
  297. package/runtime/third_party/bearssl/src/hash/dig_size.c +50 -0
  298. package/runtime/third_party/bearssl/src/hash/ghash_ctmul.c +345 -0
  299. package/runtime/third_party/bearssl/src/hash/ghash_ctmul32.c +251 -0
  300. package/runtime/third_party/bearssl/src/hash/ghash_ctmul64.c +154 -0
  301. package/runtime/third_party/bearssl/src/hash/ghash_pclmul.c +389 -0
  302. package/runtime/third_party/bearssl/src/hash/ghash_pwr8.c +411 -0
  303. package/runtime/third_party/bearssl/src/hash/md5.c +208 -0
  304. package/runtime/third_party/bearssl/src/hash/md5sha1.c +141 -0
  305. package/runtime/third_party/bearssl/src/hash/mgf1.c +56 -0
  306. package/runtime/third_party/bearssl/src/hash/multihash.c +166 -0
  307. package/runtime/third_party/bearssl/src/hash/sha1.c +191 -0
  308. package/runtime/third_party/bearssl/src/hash/sha2big.c +285 -0
  309. package/runtime/third_party/bearssl/src/hash/sha2small.c +341 -0
  310. package/runtime/third_party/bearssl/src/inner.h +2577 -0
  311. package/runtime/third_party/bearssl/src/int/i15_add.c +46 -0
  312. package/runtime/third_party/bearssl/src/int/i15_bitlen.c +44 -0
  313. package/runtime/third_party/bearssl/src/int/i15_decmod.c +124 -0
  314. package/runtime/third_party/bearssl/src/int/i15_decode.c +56 -0
  315. package/runtime/third_party/bearssl/src/int/i15_decred.c +100 -0
  316. package/runtime/third_party/bearssl/src/int/i15_encode.c +56 -0
  317. package/runtime/third_party/bearssl/src/int/i15_fmont.c +59 -0
  318. package/runtime/third_party/bearssl/src/int/i15_iszero.c +39 -0
  319. package/runtime/third_party/bearssl/src/int/i15_moddiv.c +465 -0
  320. package/runtime/third_party/bearssl/src/int/i15_modpow.c +50 -0
  321. package/runtime/third_party/bearssl/src/int/i15_modpow2.c +160 -0
  322. package/runtime/third_party/bearssl/src/int/i15_montmul.c +184 -0
  323. package/runtime/third_party/bearssl/src/int/i15_mulacc.c +61 -0
  324. package/runtime/third_party/bearssl/src/int/i15_muladd.c +173 -0
  325. package/runtime/third_party/bearssl/src/int/i15_ninv15.c +38 -0
  326. package/runtime/third_party/bearssl/src/int/i15_reduce.c +66 -0
  327. package/runtime/third_party/bearssl/src/int/i15_rshift.c +47 -0
  328. package/runtime/third_party/bearssl/src/int/i15_sub.c +46 -0
  329. package/runtime/third_party/bearssl/src/int/i15_tmont.c +36 -0
  330. package/runtime/third_party/bearssl/src/int/i31_add.c +46 -0
  331. package/runtime/third_party/bearssl/src/int/i31_bitlen.c +44 -0
  332. package/runtime/third_party/bearssl/src/int/i31_decmod.c +124 -0
  333. package/runtime/third_party/bearssl/src/int/i31_decode.c +57 -0
  334. package/runtime/third_party/bearssl/src/int/i31_decred.c +103 -0
  335. package/runtime/third_party/bearssl/src/int/i31_encode.c +79 -0
  336. package/runtime/third_party/bearssl/src/int/i31_fmont.c +60 -0
  337. package/runtime/third_party/bearssl/src/int/i31_iszero.c +39 -0
  338. package/runtime/third_party/bearssl/src/int/i31_moddiv.c +488 -0
  339. package/runtime/third_party/bearssl/src/int/i31_modpow.c +65 -0
  340. package/runtime/third_party/bearssl/src/int/i31_modpow2.c +160 -0
  341. package/runtime/third_party/bearssl/src/int/i31_montmul.c +127 -0
  342. package/runtime/third_party/bearssl/src/int/i31_mulacc.c +74 -0
  343. package/runtime/third_party/bearssl/src/int/i31_muladd.c +157 -0
  344. package/runtime/third_party/bearssl/src/int/i31_ninv31.c +39 -0
  345. package/runtime/third_party/bearssl/src/int/i31_reduce.c +66 -0
  346. package/runtime/third_party/bearssl/src/int/i31_rshift.c +47 -0
  347. package/runtime/third_party/bearssl/src/int/i31_sub.c +46 -0
  348. package/runtime/third_party/bearssl/src/int/i31_tmont.c +36 -0
  349. package/runtime/third_party/bearssl/src/int/i32_add.c +51 -0
  350. package/runtime/third_party/bearssl/src/int/i32_bitlen.c +44 -0
  351. package/runtime/third_party/bearssl/src/int/i32_decmod.c +77 -0
  352. package/runtime/third_party/bearssl/src/int/i32_decode.c +63 -0
  353. package/runtime/third_party/bearssl/src/int/i32_decred.c +107 -0
  354. package/runtime/third_party/bearssl/src/int/i32_div32.c +56 -0
  355. package/runtime/third_party/bearssl/src/int/i32_encode.c +72 -0
  356. package/runtime/third_party/bearssl/src/int/i32_fmont.c +60 -0
  357. package/runtime/third_party/bearssl/src/int/i32_iszero.c +39 -0
  358. package/runtime/third_party/bearssl/src/int/i32_modpow.c +65 -0
  359. package/runtime/third_party/bearssl/src/int/i32_montmul.c +69 -0
  360. package/runtime/third_party/bearssl/src/int/i32_mulacc.c +56 -0
  361. package/runtime/third_party/bearssl/src/int/i32_muladd.c +138 -0
  362. package/runtime/third_party/bearssl/src/int/i32_ninv32.c +39 -0
  363. package/runtime/third_party/bearssl/src/int/i32_reduce.c +66 -0
  364. package/runtime/third_party/bearssl/src/int/i32_sub.c +51 -0
  365. package/runtime/third_party/bearssl/src/int/i32_tmont.c +36 -0
  366. package/runtime/third_party/bearssl/src/int/i62_modpow2.c +493 -0
  367. package/runtime/third_party/bearssl/src/kdf/hkdf.c +107 -0
  368. package/runtime/third_party/bearssl/src/kdf/shake.c +590 -0
  369. package/runtime/third_party/bearssl/src/mac/hmac.c +122 -0
  370. package/runtime/third_party/bearssl/src/mac/hmac_ct.c +193 -0
  371. package/runtime/third_party/bearssl/src/rand/aesctr_drbg.c +206 -0
  372. package/runtime/third_party/bearssl/src/rand/hmac_drbg.c +157 -0
  373. package/runtime/third_party/bearssl/src/rand/sysrng.c +252 -0
  374. package/runtime/third_party/bearssl/src/rsa/rsa_default_keygen.c +38 -0
  375. package/runtime/third_party/bearssl/src/rsa/rsa_default_modulus.c +36 -0
  376. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_decrypt.c +38 -0
  377. package/runtime/third_party/bearssl/src/rsa/rsa_default_oaep_encrypt.c +38 -0
  378. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_sign.c +38 -0
  379. package/runtime/third_party/bearssl/src/rsa/rsa_default_pkcs1_vrfy.c +38 -0
  380. package/runtime/third_party/bearssl/src/rsa/rsa_default_priv.c +38 -0
  381. package/runtime/third_party/bearssl/src/rsa/rsa_default_privexp.c +36 -0
  382. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_sign.c +38 -0
  383. package/runtime/third_party/bearssl/src/rsa/rsa_default_pss_vrfy.c +38 -0
  384. package/runtime/third_party/bearssl/src/rsa/rsa_default_pub.c +38 -0
  385. package/runtime/third_party/bearssl/src/rsa/rsa_default_pubexp.c +36 -0
  386. package/runtime/third_party/bearssl/src/rsa/rsa_i15_keygen.c +583 -0
  387. package/runtime/third_party/bearssl/src/rsa/rsa_i15_modulus.c +99 -0
  388. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_decrypt.c +41 -0
  389. package/runtime/third_party/bearssl/src/rsa/rsa_i15_oaep_encrypt.c +44 -0
  390. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_sign.c +37 -0
  391. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pkcs1_vrfy.c +43 -0
  392. package/runtime/third_party/bearssl/src/rsa/rsa_i15_priv.c +209 -0
  393. package/runtime/third_party/bearssl/src/rsa/rsa_i15_privexp.c +320 -0
  394. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_sign.c +40 -0
  395. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pss_vrfy.c +44 -0
  396. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pub.c +113 -0
  397. package/runtime/third_party/bearssl/src/rsa/rsa_i15_pubexp.c +152 -0
  398. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen.c +37 -0
  399. package/runtime/third_party/bearssl/src/rsa/rsa_i31_keygen_inner.c +608 -0
  400. package/runtime/third_party/bearssl/src/rsa/rsa_i31_modulus.c +99 -0
  401. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_decrypt.c +41 -0
  402. package/runtime/third_party/bearssl/src/rsa/rsa_i31_oaep_encrypt.c +44 -0
  403. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_sign.c +37 -0
  404. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pkcs1_vrfy.c +43 -0
  405. package/runtime/third_party/bearssl/src/rsa/rsa_i31_priv.c +203 -0
  406. package/runtime/third_party/bearssl/src/rsa/rsa_i31_privexp.c +318 -0
  407. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_sign.c +40 -0
  408. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pss_vrfy.c +44 -0
  409. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pub.c +106 -0
  410. package/runtime/third_party/bearssl/src/rsa/rsa_i31_pubexp.c +152 -0
  411. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_decrypt.c +41 -0
  412. package/runtime/third_party/bearssl/src/rsa/rsa_i32_oaep_encrypt.c +44 -0
  413. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_sign.c +37 -0
  414. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pkcs1_vrfy.c +43 -0
  415. package/runtime/third_party/bearssl/src/rsa/rsa_i32_priv.c +160 -0
  416. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_sign.c +40 -0
  417. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pss_vrfy.c +44 -0
  418. package/runtime/third_party/bearssl/src/rsa/rsa_i32_pub.c +77 -0
  419. package/runtime/third_party/bearssl/src/rsa/rsa_i62_keygen.c +57 -0
  420. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_decrypt.c +61 -0
  421. package/runtime/third_party/bearssl/src/rsa/rsa_i62_oaep_encrypt.c +64 -0
  422. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_sign.c +57 -0
  423. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pkcs1_vrfy.c +63 -0
  424. package/runtime/third_party/bearssl/src/rsa/rsa_i62_priv.c +223 -0
  425. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_sign.c +60 -0
  426. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pss_vrfy.c +64 -0
  427. package/runtime/third_party/bearssl/src/rsa/rsa_i62_pub.c +125 -0
  428. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_pad.c +112 -0
  429. package/runtime/third_party/bearssl/src/rsa/rsa_oaep_unpad.c +145 -0
  430. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_pad.c +100 -0
  431. package/runtime/third_party/bearssl/src/rsa/rsa_pkcs1_sig_unpad.c +121 -0
  432. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_pad.c +106 -0
  433. package/runtime/third_party/bearssl/src/rsa/rsa_pss_sig_unpad.c +121 -0
  434. package/runtime/third_party/bearssl/src/rsa/rsa_ssl_decrypt.c +52 -0
  435. package/runtime/third_party/bearssl/src/settings.c +306 -0
  436. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcdec.c +69 -0
  437. package/runtime/third_party/bearssl/src/symcipher/aes_big_cbcenc.c +67 -0
  438. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctr.c +84 -0
  439. package/runtime/third_party/bearssl/src/symcipher/aes_big_ctrcbc.c +142 -0
  440. package/runtime/third_party/bearssl/src/symcipher/aes_big_dec.c +254 -0
  441. package/runtime/third_party/bearssl/src/symcipher/aes_big_enc.c +157 -0
  442. package/runtime/third_party/bearssl/src/symcipher/aes_common.c +112 -0
  443. package/runtime/third_party/bearssl/src/symcipher/aes_ct.c +328 -0
  444. package/runtime/third_party/bearssl/src/symcipher/aes_ct64.c +398 -0
  445. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcdec.c +104 -0
  446. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_cbcenc.c +81 -0
  447. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctr.c +114 -0
  448. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_ctrcbc.c +433 -0
  449. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_dec.c +159 -0
  450. package/runtime/third_party/bearssl/src/symcipher/aes_ct64_enc.c +115 -0
  451. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcdec.c +111 -0
  452. package/runtime/third_party/bearssl/src/symcipher/aes_ct_cbcenc.c +91 -0
  453. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctr.c +116 -0
  454. package/runtime/third_party/bearssl/src/symcipher/aes_ct_ctrcbc.c +422 -0
  455. package/runtime/third_party/bearssl/src/symcipher/aes_ct_dec.c +170 -0
  456. package/runtime/third_party/bearssl/src/symcipher/aes_ct_enc.c +112 -0
  457. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8.c +445 -0
  458. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcdec.c +670 -0
  459. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_cbcenc.c +417 -0
  460. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctr.c +717 -0
  461. package/runtime/third_party/bearssl/src/symcipher/aes_pwr8_ctrcbc.c +946 -0
  462. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcdec.c +69 -0
  463. package/runtime/third_party/bearssl/src/symcipher/aes_small_cbcenc.c +67 -0
  464. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctr.c +84 -0
  465. package/runtime/third_party/bearssl/src/symcipher/aes_small_ctrcbc.c +142 -0
  466. package/runtime/third_party/bearssl/src/symcipher/aes_small_dec.c +176 -0
  467. package/runtime/third_party/bearssl/src/symcipher/aes_small_enc.c +129 -0
  468. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni.c +240 -0
  469. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcdec.c +223 -0
  470. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_cbcenc.c +122 -0
  471. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctr.c +211 -0
  472. package/runtime/third_party/bearssl/src/symcipher/aes_x86ni_ctrcbc.c +596 -0
  473. package/runtime/third_party/bearssl/src/symcipher/chacha20_ct.c +106 -0
  474. package/runtime/third_party/bearssl/src/symcipher/chacha20_sse2.c +237 -0
  475. package/runtime/third_party/bearssl/src/symcipher/des_ct.c +411 -0
  476. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcdec.c +87 -0
  477. package/runtime/third_party/bearssl/src/symcipher/des_ct_cbcenc.c +69 -0
  478. package/runtime/third_party/bearssl/src/symcipher/des_support.c +166 -0
  479. package/runtime/third_party/bearssl/src/symcipher/des_tab.c +310 -0
  480. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcdec.c +85 -0
  481. package/runtime/third_party/bearssl/src/symcipher/des_tab_cbcenc.c +67 -0
  482. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul.c +260 -0
  483. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmul32.c +297 -0
  484. package/runtime/third_party/bearssl/src/symcipher/poly1305_ctmulq.c +475 -0
  485. package/runtime/third_party/bearssl/src/symcipher/poly1305_i15.c +221 -0
  486. package/runtime/third_party/bearssl/src/x509/asn1.t0 +757 -0
  487. package/runtime/third_party/bearssl/src/x509/asn1enc.c +93 -0
  488. package/runtime/third_party/bearssl/src/x509/encode_ec_pk8der.c +110 -0
  489. package/runtime/third_party/bearssl/src/x509/encode_ec_rawder.c +161 -0
  490. package/runtime/third_party/bearssl/src/x509/encode_rsa_pk8der.c +97 -0
  491. package/runtime/third_party/bearssl/src/x509/encode_rsa_rawder.c +96 -0
  492. package/runtime/third_party/bearssl/src/x509/skey_decoder.c +653 -0
  493. package/runtime/third_party/bearssl/src/x509/skey_decoder.t0 +376 -0
  494. package/runtime/third_party/bearssl/src/x509/x509_decoder.c +776 -0
  495. package/runtime/third_party/bearssl/src/x509/x509_decoder.t0 +324 -0
  496. package/runtime/third_party/bearssl/src/x509/x509_knownkey.c +105 -0
  497. package/runtime/third_party/bearssl/src/x509/x509_minimal.c +1722 -0
  498. package/runtime/third_party/bearssl/src/x509/x509_minimal.t0 +1526 -0
  499. package/runtime/third_party/bearssl/src/x509/x509_minimal_full.c +59 -0
  500. package/runtime/third_party/quickjs-dtoa/LICENSE +22 -0
  501. package/runtime/third_party/quickjs-dtoa/README.md +23 -0
  502. package/runtime/third_party/quickjs-dtoa/dtoa.c +1640 -0
  503. package/runtime/third_party/quickjs-dtoa/dtoa.h +83 -0
  504. package/runtime/third_party/quickjs-dtoa/dtoa_compat.h +89 -0
  505. package/runtime/third_party/quickjs-regexp/LICENSE +22 -0
  506. package/runtime/third_party/quickjs-regexp/README.md +22 -0
  507. package/runtime/third_party/quickjs-regexp/cutils.c +641 -0
  508. package/runtime/third_party/quickjs-regexp/cutils.h +457 -0
  509. package/runtime/third_party/quickjs-regexp/libregexp-opcode.h +73 -0
  510. package/runtime/third_party/quickjs-regexp/libregexp.c +3448 -0
  511. package/runtime/third_party/quickjs-regexp/libregexp.h +65 -0
  512. package/runtime/third_party/quickjs-regexp/libunicode-table.h +5206 -0
  513. package/runtime/third_party/quickjs-regexp/libunicode.c +2124 -0
  514. package/runtime/third_party/quickjs-regexp/libunicode.h +196 -0
  515. package/runtime/third_party/v8-ieee754/LICENSE +61 -0
  516. package/runtime/third_party/v8-ieee754/README.md +22 -0
  517. package/runtime/third_party/v8-ieee754/convert.py +84 -0
  518. package/runtime/third_party/v8-ieee754/ieee754.c +3030 -0
  519. package/runtime/third_party/v8-ieee754/ieee754.h +27 -0
  520. package/runtime/tools/regexp_compile.c +90 -0
@@ -0,0 +1,493 @@
1
+ /*
2
+ * Copyright (c) 2017 Thomas Pornin <pornin@bolet.org>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * "Software"), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "inner.h"
26
+
27
+ #if BR_INT128 || BR_UMUL128
28
+
29
+ #if BR_INT128
30
+
31
+ /*
32
+ * Compute x*y+v1+v2. Operands are 64-bit, and result is 128-bit, with
33
+ * high word in "hi" and low word in "lo".
34
+ */
35
+ #define FMA1(hi, lo, x, y, v1, v2) do { \
36
+ unsigned __int128 fmaz; \
37
+ fmaz = (unsigned __int128)(x) * (unsigned __int128)(y) \
38
+ + (unsigned __int128)(v1) + (unsigned __int128)(v2); \
39
+ (hi) = (uint64_t)(fmaz >> 64); \
40
+ (lo) = (uint64_t)fmaz; \
41
+ } while (0)
42
+
43
+ /*
44
+ * Compute x1*y1+x2*y2+v1+v2. Operands are 64-bit, and result is 128-bit,
45
+ * with high word in "hi" and low word in "lo".
46
+ *
47
+ * Callers should ensure that the two inner products, and the v1 and v2
48
+ * operands, are multiple of 4 (this is not used by this specific definition
49
+ * but may help other implementations).
50
+ */
51
+ #define FMA2(hi, lo, x1, y1, x2, y2, v1, v2) do { \
52
+ unsigned __int128 fmaz; \
53
+ fmaz = (unsigned __int128)(x1) * (unsigned __int128)(y1) \
54
+ + (unsigned __int128)(x2) * (unsigned __int128)(y2) \
55
+ + (unsigned __int128)(v1) + (unsigned __int128)(v2); \
56
+ (hi) = (uint64_t)(fmaz >> 64); \
57
+ (lo) = (uint64_t)fmaz; \
58
+ } while (0)
59
+
60
+ #elif BR_UMUL128
61
+
62
+ #include <intrin.h>
63
+
64
+ #define FMA1(hi, lo, x, y, v1, v2) do { \
65
+ uint64_t fmahi, fmalo; \
66
+ unsigned char fmacc; \
67
+ fmalo = _umul128((x), (y), &fmahi); \
68
+ fmacc = _addcarry_u64(0, fmalo, (v1), &fmalo); \
69
+ _addcarry_u64(fmacc, fmahi, 0, &fmahi); \
70
+ fmacc = _addcarry_u64(0, fmalo, (v2), &(lo)); \
71
+ _addcarry_u64(fmacc, fmahi, 0, &(hi)); \
72
+ } while (0)
73
+
74
+ /*
75
+ * Normally we should use _addcarry_u64() for FMA2 too, but it makes
76
+ * Visual Studio crash. Instead we use this version, which leverages
77
+ * the fact that the vx operands, and the products, are multiple of 4.
78
+ * This is unfortunately slower.
79
+ */
80
+ #define FMA2(hi, lo, x1, y1, x2, y2, v1, v2) do { \
81
+ uint64_t fma1hi, fma1lo; \
82
+ uint64_t fma2hi, fma2lo; \
83
+ uint64_t fmatt; \
84
+ fma1lo = _umul128((x1), (y1), &fma1hi); \
85
+ fma2lo = _umul128((x2), (y2), &fma2hi); \
86
+ fmatt = (fma1lo >> 2) + (fma2lo >> 2) \
87
+ + ((v1) >> 2) + ((v2) >> 2); \
88
+ (lo) = fmatt << 2; \
89
+ (hi) = fma1hi + fma2hi + (fmatt >> 62); \
90
+ } while (0)
91
+
92
+ /*
93
+ * The FMA2 macro definition we would prefer to use, but it triggers
94
+ * an internal compiler error in Visual Studio 2015.
95
+ *
96
+ #define FMA2(hi, lo, x1, y1, x2, y2, v1, v2) do { \
97
+ uint64_t fma1hi, fma1lo; \
98
+ uint64_t fma2hi, fma2lo; \
99
+ unsigned char fmacc; \
100
+ fma1lo = _umul128((x1), (y1), &fma1hi); \
101
+ fma2lo = _umul128((x2), (y2), &fma2hi); \
102
+ fmacc = _addcarry_u64(0, fma1lo, (v1), &fma1lo); \
103
+ _addcarry_u64(fmacc, fma1hi, 0, &fma1hi); \
104
+ fmacc = _addcarry_u64(0, fma2lo, (v2), &fma2lo); \
105
+ _addcarry_u64(fmacc, fma2hi, 0, &fma2hi); \
106
+ fmacc = _addcarry_u64(0, fma1lo, fma2lo, &(lo)); \
107
+ _addcarry_u64(fmacc, fma1hi, fma2hi, &(hi)); \
108
+ } while (0)
109
+ */
110
+
111
+ #endif
112
+
113
+ #define MASK62 ((uint64_t)0x3FFFFFFFFFFFFFFF)
114
+ #define MUL62_lo(x, y) (((uint64_t)(x) * (uint64_t)(y)) & MASK62)
115
+
116
+ /*
117
+ * Subtract b from a, and return the final carry. If 'ctl32' is 0, then
118
+ * a[] is kept unmodified, but the final carry is still computed and
119
+ * returned.
120
+ */
121
+ static uint32_t
122
+ i62_sub(uint64_t *a, const uint64_t *b, size_t num, uint32_t ctl32)
123
+ {
124
+ uint64_t cc, mask;
125
+ size_t u;
126
+
127
+ cc = 0;
128
+ ctl32 = -ctl32;
129
+ mask = (uint64_t)ctl32 | ((uint64_t)ctl32 << 32);
130
+ for (u = 0; u < num; u ++) {
131
+ uint64_t aw, bw, dw;
132
+
133
+ aw = a[u];
134
+ bw = b[u];
135
+ dw = aw - bw - cc;
136
+ cc = dw >> 63;
137
+ dw &= MASK62;
138
+ a[u] = aw ^ (mask & (dw ^ aw));
139
+ }
140
+ return (uint32_t)cc;
141
+ }
142
+
143
+ /*
144
+ * Montgomery multiplication, over arrays of 62-bit values. The
145
+ * destination array (d) must be distinct from the other operands
146
+ * (x, y and m). All arrays are in little-endian format (least
147
+ * significant word comes first) over 'num' words.
148
+ */
149
+ static void
150
+ montymul(uint64_t *d, const uint64_t *x, const uint64_t *y,
151
+ const uint64_t *m, size_t num, uint64_t m0i)
152
+ {
153
+ uint64_t dh;
154
+ size_t u, num4;
155
+
156
+ num4 = 1 + ((num - 1) & ~(size_t)3);
157
+ memset(d, 0, num * sizeof *d);
158
+ dh = 0;
159
+ for (u = 0; u < num; u ++) {
160
+ size_t v;
161
+ uint64_t f, xu;
162
+ uint64_t r, zh;
163
+ uint64_t hi, lo;
164
+
165
+ xu = x[u] << 2;
166
+ f = MUL62_lo(d[0] + MUL62_lo(x[u], y[0]), m0i) << 2;
167
+
168
+ FMA2(hi, lo, xu, y[0], f, m[0], d[0] << 2, 0);
169
+ r = hi;
170
+
171
+ for (v = 1; v < num4; v += 4) {
172
+ FMA2(hi, lo, xu, y[v + 0],
173
+ f, m[v + 0], d[v + 0] << 2, r << 2);
174
+ r = hi + (r >> 62);
175
+ d[v - 1] = lo >> 2;
176
+ FMA2(hi, lo, xu, y[v + 1],
177
+ f, m[v + 1], d[v + 1] << 2, r << 2);
178
+ r = hi + (r >> 62);
179
+ d[v + 0] = lo >> 2;
180
+ FMA2(hi, lo, xu, y[v + 2],
181
+ f, m[v + 2], d[v + 2] << 2, r << 2);
182
+ r = hi + (r >> 62);
183
+ d[v + 1] = lo >> 2;
184
+ FMA2(hi, lo, xu, y[v + 3],
185
+ f, m[v + 3], d[v + 3] << 2, r << 2);
186
+ r = hi + (r >> 62);
187
+ d[v + 2] = lo >> 2;
188
+ }
189
+ for (; v < num; v ++) {
190
+ FMA2(hi, lo, xu, y[v], f, m[v], d[v] << 2, r << 2);
191
+ r = hi + (r >> 62);
192
+ d[v - 1] = lo >> 2;
193
+ }
194
+
195
+ zh = dh + r;
196
+ d[num - 1] = zh & MASK62;
197
+ dh = zh >> 62;
198
+ }
199
+ i62_sub(d, m, num, (uint32_t)dh | NOT(i62_sub(d, m, num, 0)));
200
+ }
201
+
202
+ /*
203
+ * Conversion back from Montgomery representation.
204
+ */
205
+ static void
206
+ frommonty(uint64_t *x, const uint64_t *m, size_t num, uint64_t m0i)
207
+ {
208
+ size_t u, v;
209
+
210
+ for (u = 0; u < num; u ++) {
211
+ uint64_t f, cc;
212
+
213
+ f = MUL62_lo(x[0], m0i) << 2;
214
+ cc = 0;
215
+ for (v = 0; v < num; v ++) {
216
+ uint64_t hi, lo;
217
+
218
+ FMA1(hi, lo, f, m[v], x[v] << 2, cc);
219
+ cc = hi << 2;
220
+ if (v != 0) {
221
+ x[v - 1] = lo >> 2;
222
+ }
223
+ }
224
+ x[num - 1] = cc >> 2;
225
+ }
226
+ i62_sub(x, m, num, NOT(i62_sub(x, m, num, 0)));
227
+ }
228
+
229
+ /* see inner.h */
230
+ uint32_t
231
+ br_i62_modpow_opt(uint32_t *x31, const unsigned char *e, size_t elen,
232
+ const uint32_t *m31, uint32_t m0i31, uint64_t *tmp, size_t twlen)
233
+ {
234
+ size_t u, mw31num, mw62num;
235
+ uint64_t *x, *m, *t1, *t2;
236
+ uint64_t m0i;
237
+ uint32_t acc;
238
+ int win_len, acc_len;
239
+
240
+ /*
241
+ * Get modulus size, in words.
242
+ */
243
+ mw31num = (m31[0] + 31) >> 5;
244
+ mw62num = (mw31num + 1) >> 1;
245
+
246
+ /*
247
+ * In order to apply this function, we must have enough room to
248
+ * copy the operand and modulus into the temporary array, along
249
+ * with at least two temporaries. If there is not enough room,
250
+ * switch to br_i31_modpow(). We also use br_i31_modpow() if the
251
+ * modulus length is not at least four words (94 bits or more).
252
+ */
253
+ if (mw31num < 4 || (mw62num << 2) > twlen) {
254
+ /*
255
+ * We assume here that we can split an aligned uint64_t
256
+ * into two properly aligned uint32_t. Since both types
257
+ * are supposed to have an exact width with no padding,
258
+ * then this property must hold.
259
+ */
260
+ size_t txlen;
261
+
262
+ txlen = mw31num + 1;
263
+ if (twlen < txlen) {
264
+ return 0;
265
+ }
266
+ br_i31_modpow(x31, e, elen, m31, m0i31,
267
+ (uint32_t *)tmp, (uint32_t *)tmp + txlen);
268
+ return 1;
269
+ }
270
+
271
+ /*
272
+ * Convert x to Montgomery representation: this means that
273
+ * we replace x with x*2^z mod m, where z is the smallest multiple
274
+ * of the word size such that 2^z >= m. We want to reuse the 31-bit
275
+ * functions here (for constant-time operation), but we need z
276
+ * for a 62-bit word size.
277
+ */
278
+ for (u = 0; u < mw62num; u ++) {
279
+ br_i31_muladd_small(x31, 0, m31);
280
+ br_i31_muladd_small(x31, 0, m31);
281
+ }
282
+
283
+ /*
284
+ * Assemble operands into arrays of 62-bit words. Note that
285
+ * all the arrays of 62-bit words that we will handle here
286
+ * are without any leading size word.
287
+ *
288
+ * We also adjust tmp and twlen to account for the words used
289
+ * for these extra arrays.
290
+ */
291
+ m = tmp;
292
+ x = tmp + mw62num;
293
+ tmp += (mw62num << 1);
294
+ twlen -= (mw62num << 1);
295
+ for (u = 0; u < mw31num; u += 2) {
296
+ size_t v;
297
+
298
+ v = u >> 1;
299
+ if ((u + 1) == mw31num) {
300
+ m[v] = (uint64_t)m31[u + 1];
301
+ x[v] = (uint64_t)x31[u + 1];
302
+ } else {
303
+ m[v] = (uint64_t)m31[u + 1]
304
+ + ((uint64_t)m31[u + 2] << 31);
305
+ x[v] = (uint64_t)x31[u + 1]
306
+ + ((uint64_t)x31[u + 2] << 31);
307
+ }
308
+ }
309
+
310
+ /*
311
+ * Compute window size. We support windows up to 5 bits; for a
312
+ * window of size k bits, we need 2^k+1 temporaries (for k = 1,
313
+ * we use special code that uses only 2 temporaries).
314
+ */
315
+ for (win_len = 5; win_len > 1; win_len --) {
316
+ if ((((uint32_t)1 << win_len) + 1) * mw62num <= twlen) {
317
+ break;
318
+ }
319
+ }
320
+
321
+ t1 = tmp;
322
+ t2 = tmp + mw62num;
323
+
324
+ /*
325
+ * Compute m0i, which is equal to -(1/m0) mod 2^62. We were
326
+ * provided with m0i31, which already fulfills this property
327
+ * modulo 2^31; the single expression below is then sufficient.
328
+ */
329
+ m0i = (uint64_t)m0i31;
330
+ m0i = MUL62_lo(m0i, (uint64_t)2 + MUL62_lo(m0i, m[0]));
331
+
332
+ /*
333
+ * Compute window contents. If the window has size one bit only,
334
+ * then t2 is set to x; otherwise, t2[0] is left untouched, and
335
+ * t2[k] is set to x^k (for k >= 1).
336
+ */
337
+ if (win_len == 1) {
338
+ memcpy(t2, x, mw62num * sizeof *x);
339
+ } else {
340
+ uint64_t *base;
341
+
342
+ memcpy(t2 + mw62num, x, mw62num * sizeof *x);
343
+ base = t2 + mw62num;
344
+ for (u = 2; u < ((unsigned)1 << win_len); u ++) {
345
+ montymul(base + mw62num, base, x, m, mw62num, m0i);
346
+ base += mw62num;
347
+ }
348
+ }
349
+
350
+ /*
351
+ * Set x to 1, in Montgomery representation. We again use the
352
+ * 31-bit code.
353
+ */
354
+ br_i31_zero(x31, m31[0]);
355
+ x31[(m31[0] + 31) >> 5] = 1;
356
+ br_i31_muladd_small(x31, 0, m31);
357
+ if (mw31num & 1) {
358
+ br_i31_muladd_small(x31, 0, m31);
359
+ }
360
+ for (u = 0; u < mw31num; u += 2) {
361
+ size_t v;
362
+
363
+ v = u >> 1;
364
+ if ((u + 1) == mw31num) {
365
+ x[v] = (uint64_t)x31[u + 1];
366
+ } else {
367
+ x[v] = (uint64_t)x31[u + 1]
368
+ + ((uint64_t)x31[u + 2] << 31);
369
+ }
370
+ }
371
+
372
+ /*
373
+ * We process bits from most to least significant. At each
374
+ * loop iteration, we have acc_len bits in acc.
375
+ */
376
+ acc = 0;
377
+ acc_len = 0;
378
+ while (acc_len > 0 || elen > 0) {
379
+ int i, k;
380
+ uint32_t bits;
381
+ uint64_t mask1, mask2;
382
+
383
+ /*
384
+ * Get the next bits.
385
+ */
386
+ k = win_len;
387
+ if (acc_len < win_len) {
388
+ if (elen > 0) {
389
+ acc = (acc << 8) | *e ++;
390
+ elen --;
391
+ acc_len += 8;
392
+ } else {
393
+ k = acc_len;
394
+ }
395
+ }
396
+ bits = (acc >> (acc_len - k)) & (((uint32_t)1 << k) - 1);
397
+ acc_len -= k;
398
+
399
+ /*
400
+ * We could get exactly k bits. Compute k squarings.
401
+ */
402
+ for (i = 0; i < k; i ++) {
403
+ montymul(t1, x, x, m, mw62num, m0i);
404
+ memcpy(x, t1, mw62num * sizeof *x);
405
+ }
406
+
407
+ /*
408
+ * Window lookup: we want to set t2 to the window
409
+ * lookup value, assuming the bits are non-zero. If
410
+ * the window length is 1 bit only, then t2 is
411
+ * already set; otherwise, we do a constant-time lookup.
412
+ */
413
+ if (win_len > 1) {
414
+ uint64_t *base;
415
+
416
+ memset(t2, 0, mw62num * sizeof *t2);
417
+ base = t2 + mw62num;
418
+ for (u = 1; u < ((uint32_t)1 << k); u ++) {
419
+ uint64_t mask;
420
+ size_t v;
421
+
422
+ mask = -(uint64_t)EQ(u, bits);
423
+ for (v = 0; v < mw62num; v ++) {
424
+ t2[v] |= mask & base[v];
425
+ }
426
+ base += mw62num;
427
+ }
428
+ }
429
+
430
+ /*
431
+ * Multiply with the looked-up value. We keep the product
432
+ * only if the exponent bits are not all-zero.
433
+ */
434
+ montymul(t1, x, t2, m, mw62num, m0i);
435
+ mask1 = -(uint64_t)EQ(bits, 0);
436
+ mask2 = ~mask1;
437
+ for (u = 0; u < mw62num; u ++) {
438
+ x[u] = (mask1 & x[u]) | (mask2 & t1[u]);
439
+ }
440
+ }
441
+
442
+ /*
443
+ * Convert back from Montgomery representation.
444
+ */
445
+ frommonty(x, m, mw62num, m0i);
446
+
447
+ /*
448
+ * Convert result into 31-bit words.
449
+ */
450
+ for (u = 0; u < mw31num; u += 2) {
451
+ uint64_t zw;
452
+
453
+ zw = x[u >> 1];
454
+ x31[u + 1] = (uint32_t)zw & 0x7FFFFFFF;
455
+ if ((u + 1) < mw31num) {
456
+ x31[u + 2] = (uint32_t)(zw >> 31);
457
+ }
458
+ }
459
+ return 1;
460
+ }
461
+
462
+ #else
463
+
464
+ /* see inner.h */
465
+ uint32_t
466
+ br_i62_modpow_opt(uint32_t *x31, const unsigned char *e, size_t elen,
467
+ const uint32_t *m31, uint32_t m0i31, uint64_t *tmp, size_t twlen)
468
+ {
469
+ size_t mwlen;
470
+
471
+ mwlen = (m31[0] + 63) >> 5;
472
+ if (twlen < mwlen) {
473
+ return 0;
474
+ }
475
+ return br_i31_modpow_opt(x31, e, elen, m31, m0i31,
476
+ (uint32_t *)tmp, twlen << 1);
477
+ }
478
+
479
+ #endif
480
+
481
+ /* see inner.h */
482
+ uint32_t
483
+ br_i62_modpow_opt_as_i31(uint32_t *x31, const unsigned char *e, size_t elen,
484
+ const uint32_t *m31, uint32_t m0i31, uint32_t *tmp, size_t twlen)
485
+ {
486
+ /*
487
+ * As documented, this function expects the 'tmp' argument to be
488
+ * 64-bit aligned. This is OK since this function is internal (it
489
+ * is not part of BearSSL's public API).
490
+ */
491
+ return br_i62_modpow_opt(x31, e, elen, m31, m0i31,
492
+ (uint64_t *)tmp, twlen >> 1);
493
+ }
@@ -0,0 +1,107 @@
1
+ /*
2
+ * Copyright (c) 2018 Thomas Pornin <pornin@bolet.org>
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining
5
+ * a copy of this software and associated documentation files (the
6
+ * "Software"), to deal in the Software without restriction, including
7
+ * without limitation the rights to use, copy, modify, merge, publish,
8
+ * distribute, sublicense, and/or sell copies of the Software, and to
9
+ * permit persons to whom the Software is furnished to do so, subject to
10
+ * the following conditions:
11
+ *
12
+ * The above copyright notice and this permission notice shall be
13
+ * included in all copies or substantial portions of the Software.
14
+ *
15
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ #include "inner.h"
26
+
27
+ const unsigned char br_hkdf_no_salt = 0;
28
+
29
+ /* see bearssl_kdf.h */
30
+ void
31
+ br_hkdf_init(br_hkdf_context *hc, const br_hash_class *digest_vtable,
32
+ const void *salt, size_t salt_len)
33
+ {
34
+ br_hmac_key_context kc;
35
+ unsigned char tmp[64];
36
+
37
+ if (salt == BR_HKDF_NO_SALT) {
38
+ salt = tmp;
39
+ salt_len = br_digest_size(digest_vtable);
40
+ memset(tmp, 0, salt_len);
41
+ }
42
+ br_hmac_key_init(&kc, digest_vtable, salt, salt_len);
43
+ br_hmac_init(&hc->u.hmac_ctx, &kc, 0);
44
+ hc->dig_len = br_hmac_size(&hc->u.hmac_ctx);
45
+ }
46
+
47
+ /* see bearssl_kdf.h */
48
+ void
49
+ br_hkdf_inject(br_hkdf_context *hc, const void *ikm, size_t ikm_len)
50
+ {
51
+ br_hmac_update(&hc->u.hmac_ctx, ikm, ikm_len);
52
+ }
53
+
54
+ /* see bearssl_kdf.h */
55
+ void
56
+ br_hkdf_flip(br_hkdf_context *hc)
57
+ {
58
+ unsigned char tmp[64];
59
+
60
+ br_hmac_out(&hc->u.hmac_ctx, tmp);
61
+ br_hmac_key_init(&hc->u.prk_ctx,
62
+ br_hmac_get_digest(&hc->u.hmac_ctx), tmp, hc->dig_len);
63
+ hc->ptr = hc->dig_len;
64
+ hc->chunk_num = 0;
65
+ }
66
+
67
+ /* see bearssl_kdf.h */
68
+ size_t
69
+ br_hkdf_produce(br_hkdf_context *hc,
70
+ const void *info, size_t info_len, void *out, size_t out_len)
71
+ {
72
+ size_t tlen;
73
+
74
+ tlen = 0;
75
+ while (out_len > 0) {
76
+ size_t clen;
77
+
78
+ if (hc->ptr == hc->dig_len) {
79
+ br_hmac_context hmac_ctx;
80
+ unsigned char x;
81
+
82
+ hc->chunk_num ++;
83
+ if (hc->chunk_num == 256) {
84
+ return tlen;
85
+ }
86
+ x = hc->chunk_num;
87
+ br_hmac_init(&hmac_ctx, &hc->u.prk_ctx, 0);
88
+ if (x != 1) {
89
+ br_hmac_update(&hmac_ctx, hc->buf, hc->dig_len);
90
+ }
91
+ br_hmac_update(&hmac_ctx, info, info_len);
92
+ br_hmac_update(&hmac_ctx, &x, 1);
93
+ br_hmac_out(&hmac_ctx, hc->buf);
94
+ hc->ptr = 0;
95
+ }
96
+ clen = hc->dig_len - hc->ptr;
97
+ if (clen > out_len) {
98
+ clen = out_len;
99
+ }
100
+ memcpy(out, hc->buf + hc->ptr, clen);
101
+ out = (unsigned char *)out + clen;
102
+ out_len -= clen;
103
+ hc->ptr += clen;
104
+ tlen += clen;
105
+ }
106
+ return tlen;
107
+ }