kibi-swipl-linux-x64-gnu 1.0.0

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 (550) hide show
  1. package/README.md +29 -0
  2. package/bin/swipl +0 -0
  3. package/bin/swipl-win +0 -0
  4. package/build-manifest.json +70 -0
  5. package/lib/cmake/swipl/SWIPLConfig.cmake +21 -0
  6. package/lib/cmake/swipl/SWIPLConfigVersion.cmake +65 -0
  7. package/lib/cmake/swipl/SWIPLTargets-release.cmake +28 -0
  8. package/lib/cmake/swipl/SWIPLTargets.cmake +109 -0
  9. package/lib/swipl/ABI +1 -0
  10. package/lib/swipl/LICENSE +41 -0
  11. package/lib/swipl/README.md +116 -0
  12. package/lib/swipl/app/README.md +25 -0
  13. package/lib/swipl/app/app.pl +87 -0
  14. package/lib/swipl/app/pack.pl +350 -0
  15. package/lib/swipl/app/qlf.pl +521 -0
  16. package/lib/swipl/app/splfr.pl +177 -0
  17. package/lib/swipl/app/sys.pl +310 -0
  18. package/lib/swipl/bin/swipl.home +1 -0
  19. package/lib/swipl/boot/apply.pl +73 -0
  20. package/lib/swipl/boot/attvar.pl +344 -0
  21. package/lib/swipl/boot/autoload.pl +1226 -0
  22. package/lib/swipl/boot/bags.pl +283 -0
  23. package/lib/swipl/boot/dcg.pl +388 -0
  24. package/lib/swipl/boot/dicts.pl +193 -0
  25. package/lib/swipl/boot/dwim.pl +485 -0
  26. package/lib/swipl/boot/engines.pl +152 -0
  27. package/lib/swipl/boot/expand.pl +1628 -0
  28. package/lib/swipl/boot/gc.pl +65 -0
  29. package/lib/swipl/boot/history.pl +304 -0
  30. package/lib/swipl/boot/init.pl +4682 -0
  31. package/lib/swipl/boot/iri.pl +64 -0
  32. package/lib/swipl/boot/license.pl +390 -0
  33. package/lib/swipl/boot/load.pl +81 -0
  34. package/lib/swipl/boot/messages.pl +2521 -0
  35. package/lib/swipl/boot/packs.pl +306 -0
  36. package/lib/swipl/boot/predopts.pl +154 -0
  37. package/lib/swipl/boot/qlf.pl +141 -0
  38. package/lib/swipl/boot/rc.pl +263 -0
  39. package/lib/swipl/boot/syspred.pl +1634 -0
  40. package/lib/swipl/boot/tabling.pl +2321 -0
  41. package/lib/swipl/boot/threads.pl +42 -0
  42. package/lib/swipl/boot/toplevel.pl +2248 -0
  43. package/lib/swipl/boot/topvars.pl +261 -0
  44. package/lib/swipl/boot.prc +0 -0
  45. package/lib/swipl/cmake/swipl.cmake +131 -0
  46. package/lib/swipl/customize/README.md +23 -0
  47. package/lib/swipl/customize/edit +101 -0
  48. package/lib/swipl/customize/init.pl +164 -0
  49. package/lib/swipl/demo/README.md +33 -0
  50. package/lib/swipl/demo/likes.pl +44 -0
  51. package/lib/swipl/doc/packages/examples/chr/bool.chr +281 -0
  52. package/lib/swipl/doc/packages/examples/chr/chrdif.chr +87 -0
  53. package/lib/swipl/doc/packages/examples/chr/chrfreeze.chr +6 -0
  54. package/lib/swipl/doc/packages/examples/chr/family.chr +116 -0
  55. package/lib/swipl/doc/packages/examples/chr/fib.chr +24 -0
  56. package/lib/swipl/doc/packages/examples/chr/fibonacci.chr +31 -0
  57. package/lib/swipl/doc/packages/examples/chr/gcd.chr +28 -0
  58. package/lib/swipl/doc/packages/examples/chr/leq.chr +34 -0
  59. package/lib/swipl/doc/packages/examples/chr/listdom.chr +138 -0
  60. package/lib/swipl/doc/packages/examples/chr/primes.chr +29 -0
  61. package/lib/swipl/doc/packages/examples/http/README.md +98 -0
  62. package/lib/swipl/doc/packages/examples/http/calc.pl +92 -0
  63. package/lib/swipl/doc/packages/examples/http/demo_body.pl +232 -0
  64. package/lib/swipl/doc/packages/examples/http/demo_client.pl +165 -0
  65. package/lib/swipl/doc/packages/examples/http/demo_daemon.pl +38 -0
  66. package/lib/swipl/doc/packages/examples/http/demo_files.pl +50 -0
  67. package/lib/swipl/doc/packages/examples/http/demo_hello.pl +15 -0
  68. package/lib/swipl/doc/packages/examples/http/demo_login.pl +280 -0
  69. package/lib/swipl/doc/packages/examples/http/demo_openid.pl +177 -0
  70. package/lib/swipl/doc/packages/examples/http/demo_pwp.pl +20 -0
  71. package/lib/swipl/doc/packages/examples/http/demo_rest.pl +56 -0
  72. package/lib/swipl/doc/packages/examples/http/demo_threads.pl +52 -0
  73. package/lib/swipl/doc/packages/examples/http/linux-init-script +126 -0
  74. package/lib/swipl/doc/packages/examples/http/pwp/context.pwp +23 -0
  75. package/lib/swipl/doc/packages/examples/http/pwp/index.pwp +25 -0
  76. package/lib/swipl/doc/packages/examples/http/pwp/pwp1.pwp +12 -0
  77. package/lib/swipl/doc/packages/examples/http/pwp/pwp2.pwp +10 -0
  78. package/lib/swipl/doc/packages/examples/http/pwp/pwp3.pwp +25 -0
  79. package/lib/swipl/doc/packages/examples/http/pwp/pwp4.pwp +23 -0
  80. package/lib/swipl/doc/packages/examples/http/pwp/pwp5.pwp +11 -0
  81. package/lib/swipl/doc/packages/examples/http/pwp/pwp6.pwp +3 -0
  82. package/lib/swipl/doc/packages/examples/http/pwp/pwp7.pwp +3 -0
  83. package/lib/swipl/doc/packages/examples/http/pwp/pwp8.pwp +3 -0
  84. package/lib/swipl/doc/packages/examples/http/pwp/pwpdb.pl +12 -0
  85. package/lib/swipl/doc/packages/examples/http/systemd-script.service +18 -0
  86. package/lib/swipl/doc/packages/examples/http/upstart-script.conf +20 -0
  87. package/lib/swipl/doc/packages/examples/plunit/read.pl +17 -0
  88. package/lib/swipl/doc/packages/examples/plunit/simple.pl +33 -0
  89. package/lib/swipl/doc/packages/examples/ssl/client.pl +83 -0
  90. package/lib/swipl/doc/packages/examples/ssl/etc/README +52 -0
  91. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.p12 +0 -0
  92. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-cert.pem +85 -0
  93. package/lib/swipl/doc/packages/examples/ssl/etc/client/client-key.pem +30 -0
  94. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/cacert.pem +82 -0
  95. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/careq.pem +18 -0
  96. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/crlnumber +1 -0
  97. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt +3 -0
  98. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/index.txt.attr +1 -0
  99. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7C.pem +85 -0
  100. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/newcerts/9DC08797A0F63F7D.pem +85 -0
  101. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/private/cakey.pem +30 -0
  102. package/lib/swipl/doc/packages/examples/ssl/etc/demoCA/serial +1 -0
  103. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-cert.pem +85 -0
  104. package/lib/swipl/doc/packages/examples/ssl/etc/server/server-key.pem +30 -0
  105. package/lib/swipl/doc/packages/examples/ssl/https.pl +267 -0
  106. package/lib/swipl/doc/packages/examples/ssl/server.pl +106 -0
  107. package/lib/swipl/include/SWI-Prolog.h +1544 -0
  108. package/lib/swipl/include/SWI-Stream.h +537 -0
  109. package/lib/swipl/include/Yap/YapInterface.h +283 -0
  110. package/lib/swipl/include/sicstus/sicstus.h +452 -0
  111. package/lib/swipl/lib/x86_64-linux/cgi.so +0 -0
  112. package/lib/swipl/lib/x86_64-linux/crypt.so +0 -0
  113. package/lib/swipl/lib/x86_64-linux/crypto4pl.so +0 -0
  114. package/lib/swipl/lib/x86_64-linux/double_metaphone.so +0 -0
  115. package/lib/swipl/lib/x86_64-linux/files.so +0 -0
  116. package/lib/swipl/lib/x86_64-linux/hashstream.so +0 -0
  117. package/lib/swipl/lib/x86_64-linux/http_stream.so +0 -0
  118. package/lib/swipl/lib/x86_64-linux/isub.so +0 -0
  119. package/lib/swipl/lib/x86_64-linux/json.so +0 -0
  120. package/lib/swipl/lib/x86_64-linux/libswipl.so.10 +0 -0
  121. package/lib/swipl/lib/x86_64-linux/mallocinfo.so +0 -0
  122. package/lib/swipl/lib/x86_64-linux/md54pl.so +0 -0
  123. package/lib/swipl/lib/x86_64-linux/memfile.so +0 -0
  124. package/lib/swipl/lib/x86_64-linux/ntriples.so +0 -0
  125. package/lib/swipl/lib/x86_64-linux/pcre4pl.so +0 -0
  126. package/lib/swipl/lib/x86_64-linux/porter_stem.so +0 -0
  127. package/lib/swipl/lib/x86_64-linux/process.so +0 -0
  128. package/lib/swipl/lib/x86_64-linux/prolog_stream.so +0 -0
  129. package/lib/swipl/lib/x86_64-linux/rdf_db.so +0 -0
  130. package/lib/swipl/lib/x86_64-linux/readutil.so +0 -0
  131. package/lib/swipl/lib/x86_64-linux/rlimit.so +0 -0
  132. package/lib/swipl/lib/x86_64-linux/sched.so +0 -0
  133. package/lib/swipl/lib/x86_64-linux/sgml2pl.so +0 -0
  134. package/lib/swipl/lib/x86_64-linux/sha4pl.so +0 -0
  135. package/lib/swipl/lib/x86_64-linux/snowball.so +0 -0
  136. package/lib/swipl/lib/x86_64-linux/socket.so +0 -0
  137. package/lib/swipl/lib/x86_64-linux/ssl4pl.so +0 -0
  138. package/lib/swipl/lib/x86_64-linux/streaminfo.so +0 -0
  139. package/lib/swipl/lib/x86_64-linux/syslog.so +0 -0
  140. package/lib/swipl/lib/x86_64-linux/time.so +0 -0
  141. package/lib/swipl/lib/x86_64-linux/turtle.so +0 -0
  142. package/lib/swipl/lib/x86_64-linux/uid.so +0 -0
  143. package/lib/swipl/lib/x86_64-linux/unix.so +0 -0
  144. package/lib/swipl/lib/x86_64-linux/uri.so +0 -0
  145. package/lib/swipl/lib/x86_64-linux/websocket.so +0 -0
  146. package/lib/swipl/lib/x86_64-linux/zlib4pl.so +0 -0
  147. package/lib/swipl/library/INDEX.pl +1020 -0
  148. package/lib/swipl/library/aggregate.pl +755 -0
  149. package/lib/swipl/library/ansi_term.pl +653 -0
  150. package/lib/swipl/library/apply.pl +426 -0
  151. package/lib/swipl/library/apply_macros.pl +497 -0
  152. package/lib/swipl/library/arithmetic.pl +320 -0
  153. package/lib/swipl/library/assoc.pl +522 -0
  154. package/lib/swipl/library/atom.pl +169 -0
  155. package/lib/swipl/library/backcomp.pl +688 -0
  156. package/lib/swipl/library/base32.pl +291 -0
  157. package/lib/swipl/library/base64.pl +441 -0
  158. package/lib/swipl/library/broadcast.pl +161 -0
  159. package/lib/swipl/library/build/cmake.pl +137 -0
  160. package/lib/swipl/library/build/conan.pl +232 -0
  161. package/lib/swipl/library/build/make.pl +168 -0
  162. package/lib/swipl/library/build/tools.pl +825 -0
  163. package/lib/swipl/library/charsio.pl +195 -0
  164. package/lib/swipl/library/check.pl +1097 -0
  165. package/lib/swipl/library/check_installation.pl +912 -0
  166. package/lib/swipl/library/clp/INDEX.pl +157 -0
  167. package/lib/swipl/library/clp/bounds.pl +2036 -0
  168. package/lib/swipl/library/clp/clp_distinct.pl +263 -0
  169. package/lib/swipl/library/clp/clp_events.pl +92 -0
  170. package/lib/swipl/library/clp/clpb.pl +1896 -0
  171. package/lib/swipl/library/clp/clpfd.pl +7906 -0
  172. package/lib/swipl/library/clp/simplex.pl +1580 -0
  173. package/lib/swipl/library/codesio.pl +182 -0
  174. package/lib/swipl/library/coinduction.pl +183 -0
  175. package/lib/swipl/library/console_input.pl +289 -0
  176. package/lib/swipl/library/csv.pl +611 -0
  177. package/lib/swipl/library/ctypes.pl +161 -0
  178. package/lib/swipl/library/date.pl +370 -0
  179. package/lib/swipl/library/dcg/INDEX.pl +35 -0
  180. package/lib/swipl/library/dcg/basics.pl +514 -0
  181. package/lib/swipl/library/dcg/high_order.pl +227 -0
  182. package/lib/swipl/library/debug.pl +499 -0
  183. package/lib/swipl/library/dialect/bim.pl +186 -0
  184. package/lib/swipl/library/dialect/commons.pl +77 -0
  185. package/lib/swipl/library/dialect/eclipse/test_util_iso.pl +355 -0
  186. package/lib/swipl/library/dialect/hprolog/format.pl +44 -0
  187. package/lib/swipl/library/dialect/hprolog.pl +314 -0
  188. package/lib/swipl/library/dialect/ifprolog.pl +1317 -0
  189. package/lib/swipl/library/dialect/iso/iso_predicates.pl +277 -0
  190. package/lib/swipl/library/dialect/sicstus/README.TXT +1 -0
  191. package/lib/swipl/library/dialect/sicstus/arrays.pl +121 -0
  192. package/lib/swipl/library/dialect/sicstus/block.pl +278 -0
  193. package/lib/swipl/library/dialect/sicstus/lists.pl +167 -0
  194. package/lib/swipl/library/dialect/sicstus/ordsets.pl +52 -0
  195. package/lib/swipl/library/dialect/sicstus/sockets.pl +174 -0
  196. package/lib/swipl/library/dialect/sicstus/system.pl +262 -0
  197. package/lib/swipl/library/dialect/sicstus/terms.pl +57 -0
  198. package/lib/swipl/library/dialect/sicstus/timeout.pl +92 -0
  199. package/lib/swipl/library/dialect/sicstus.pl +582 -0
  200. package/lib/swipl/library/dialect/sicstus4/aggregate.pl +60 -0
  201. package/lib/swipl/library/dialect/sicstus4/between.pl +62 -0
  202. package/lib/swipl/library/dialect/sicstus4/clpfd.pl +75 -0
  203. package/lib/swipl/library/dialect/sicstus4/file_systems.pl +413 -0
  204. package/lib/swipl/library/dialect/sicstus4/lists.pl +274 -0
  205. package/lib/swipl/library/dialect/sicstus4/ordsets.pl +54 -0
  206. package/lib/swipl/library/dialect/sicstus4/samsort.pl +86 -0
  207. package/lib/swipl/library/dialect/sicstus4/sets.pl +124 -0
  208. package/lib/swipl/library/dialect/sicstus4/sockets.pl +164 -0
  209. package/lib/swipl/library/dialect/sicstus4/system.pl +80 -0
  210. package/lib/swipl/library/dialect/sicstus4/terms.pl +89 -0
  211. package/lib/swipl/library/dialect/sicstus4/timeout.pl +43 -0
  212. package/lib/swipl/library/dialect/sicstus4/types.pl +103 -0
  213. package/lib/swipl/library/dialect/sicstus4.pl +200 -0
  214. package/lib/swipl/library/dialect/swi/syspred_options.pl +250 -0
  215. package/lib/swipl/library/dialect/xsb/README.md +20 -0
  216. package/lib/swipl/library/dialect/xsb/basics.pl +318 -0
  217. package/lib/swipl/library/dialect/xsb/consult.pl +87 -0
  218. package/lib/swipl/library/dialect/xsb/curr_sym.pl +57 -0
  219. package/lib/swipl/library/dialect/xsb/error_handler.pl +111 -0
  220. package/lib/swipl/library/dialect/xsb/gensym.pl +53 -0
  221. package/lib/swipl/library/dialect/xsb/gpp.pl +138 -0
  222. package/lib/swipl/library/dialect/xsb/intern.pl +48 -0
  223. package/lib/swipl/library/dialect/xsb/lists.pl +47 -0
  224. package/lib/swipl/library/dialect/xsb/machine.pl +295 -0
  225. package/lib/swipl/library/dialect/xsb/ordsets.pl +53 -0
  226. package/lib/swipl/library/dialect/xsb/setof.pl +54 -0
  227. package/lib/swipl/library/dialect/xsb/source.pl +308 -0
  228. package/lib/swipl/library/dialect/xsb/standard.pl +169 -0
  229. package/lib/swipl/library/dialect/xsb/storage.pl +70 -0
  230. package/lib/swipl/library/dialect/xsb/string.pl +76 -0
  231. package/lib/swipl/library/dialect/xsb/thread.pl +62 -0
  232. package/lib/swipl/library/dialect/xsb/timed_call.pl +158 -0
  233. package/lib/swipl/library/dialect/xsb.pl +688 -0
  234. package/lib/swipl/library/dialect/yap/README.TXT +8 -0
  235. package/lib/swipl/library/dialect/yap.pl +283 -0
  236. package/lib/swipl/library/dialect.pl +123 -0
  237. package/lib/swipl/library/dicts.pl +399 -0
  238. package/lib/swipl/library/dif.pl +426 -0
  239. package/lib/swipl/library/edinburgh.pl +138 -0
  240. package/lib/swipl/library/edit.pl +783 -0
  241. package/lib/swipl/library/error.pl +495 -0
  242. package/lib/swipl/library/exceptions.pl +231 -0
  243. package/lib/swipl/library/explain.pl +543 -0
  244. package/lib/swipl/library/ext/RDF/INDEX.pl +25 -0
  245. package/lib/swipl/library/ext/RDF/rdf.pl +450 -0
  246. package/lib/swipl/library/ext/RDF/rdf_parser.pl +649 -0
  247. package/lib/swipl/library/ext/RDF/rdf_triple.pl +448 -0
  248. package/lib/swipl/library/ext/RDF/rdf_write.pl +701 -0
  249. package/lib/swipl/library/ext/RDF/rewrite_term.pl +177 -0
  250. package/lib/swipl/library/ext/chr/chr/a_star.pl +80 -0
  251. package/lib/swipl/library/ext/chr/chr/binomialheap.pl +142 -0
  252. package/lib/swipl/library/ext/chr/chr/builtins.pl +629 -0
  253. package/lib/swipl/library/ext/chr/chr/chr_compiler_errors.pl +179 -0
  254. package/lib/swipl/library/ext/chr/chr/chr_compiler_options.pl +382 -0
  255. package/lib/swipl/library/ext/chr/chr/chr_compiler_utility.pl +338 -0
  256. package/lib/swipl/library/ext/chr/chr/chr_debug.pl +59 -0
  257. package/lib/swipl/library/ext/chr/chr/chr_hashtable_store.pl +425 -0
  258. package/lib/swipl/library/ext/chr/chr/chr_integertable_store.pl +139 -0
  259. package/lib/swipl/library/ext/chr/chr/chr_messages.pl +176 -0
  260. package/lib/swipl/library/ext/chr/chr/chr_op.pl +53 -0
  261. package/lib/swipl/library/ext/chr/chr/chr_runtime.pl +1016 -0
  262. package/lib/swipl/library/ext/chr/chr/chr_translate.pl +25424 -0
  263. package/lib/swipl/library/ext/chr/chr/clean_code.pl +252 -0
  264. package/lib/swipl/library/ext/chr/chr/find.pl +78 -0
  265. package/lib/swipl/library/ext/chr/chr/guard_entailment.pl +19432 -0
  266. package/lib/swipl/library/ext/chr/chr/listmap.pl +108 -0
  267. package/lib/swipl/library/ext/chr/chr/pairlist.pl +78 -0
  268. package/lib/swipl/library/ext/chr/chr.pl +686 -0
  269. package/lib/swipl/library/ext/clib/INDEX.pl +158 -0
  270. package/lib/swipl/library/ext/clib/cgi.pl +86 -0
  271. package/lib/swipl/library/ext/clib/crypt.pl +44 -0
  272. package/lib/swipl/library/ext/clib/filesex.pl +644 -0
  273. package/lib/swipl/library/ext/clib/hash_stream.pl +119 -0
  274. package/lib/swipl/library/ext/clib/mallocinfo.pl +138 -0
  275. package/lib/swipl/library/ext/clib/md5.pl +68 -0
  276. package/lib/swipl/library/ext/clib/memfile.pl +61 -0
  277. package/lib/swipl/library/ext/clib/process.pl +573 -0
  278. package/lib/swipl/library/ext/clib/prolog_server.pl +157 -0
  279. package/lib/swipl/library/ext/clib/prolog_stream.pl +80 -0
  280. package/lib/swipl/library/ext/clib/rlimit.pl +54 -0
  281. package/lib/swipl/library/ext/clib/sched.pl +85 -0
  282. package/lib/swipl/library/ext/clib/sha.pl +162 -0
  283. package/lib/swipl/library/ext/clib/socket.pl +1102 -0
  284. package/lib/swipl/library/ext/clib/streaminfo.pl +103 -0
  285. package/lib/swipl/library/ext/clib/streampool.pl +136 -0
  286. package/lib/swipl/library/ext/clib/syslog.pl +180 -0
  287. package/lib/swipl/library/ext/clib/time.pl +194 -0
  288. package/lib/swipl/library/ext/clib/udp_broadcast.pl +975 -0
  289. package/lib/swipl/library/ext/clib/uid.pl +220 -0
  290. package/lib/swipl/library/ext/clib/unix.pl +317 -0
  291. package/lib/swipl/library/ext/clib/uri.pl +530 -0
  292. package/lib/swipl/library/ext/clib/uuid.pl +207 -0
  293. package/lib/swipl/library/ext/http/http/INDEX.pl +266 -0
  294. package/lib/swipl/library/ext/http/http/README.md +34 -0
  295. package/lib/swipl/library/ext/http/http/ax.pl +189 -0
  296. package/lib/swipl/library/ext/http/http/dcg_basics.pl +49 -0
  297. package/lib/swipl/library/ext/http/http/graphql.pl +1367 -0
  298. package/lib/swipl/library/ext/http/http/html_decl.pl +416 -0
  299. package/lib/swipl/library/ext/http/http/html_head.pl +654 -0
  300. package/lib/swipl/library/ext/http/http/html_quasiquotations.pl +120 -0
  301. package/lib/swipl/library/ext/http/http/html_write.pl +1425 -0
  302. package/lib/swipl/library/ext/http/http/htmx.pl +139 -0
  303. package/lib/swipl/library/ext/http/http/http_authenticate.pl +364 -0
  304. package/lib/swipl/library/ext/http/http/http_client.pl +412 -0
  305. package/lib/swipl/library/ext/http/http/http_cookie.pl +245 -0
  306. package/lib/swipl/library/ext/http/http/http_cors.pl +176 -0
  307. package/lib/swipl/library/ext/http/http/http_digest.pl +820 -0
  308. package/lib/swipl/library/ext/http/http/http_dirindex.pl +296 -0
  309. package/lib/swipl/library/ext/http/http/http_dispatch.pl +1552 -0
  310. package/lib/swipl/library/ext/http/http/http_dyn_workers.pl +214 -0
  311. package/lib/swipl/library/ext/http/http/http_error.pl +126 -0
  312. package/lib/swipl/library/ext/http/http/http_exception.pl +225 -0
  313. package/lib/swipl/library/ext/http/http/http_files.pl +163 -0
  314. package/lib/swipl/library/ext/http/http/http_header.pl +2820 -0
  315. package/lib/swipl/library/ext/http/http/http_hook.pl +106 -0
  316. package/lib/swipl/library/ext/http/http/http_host.pl +204 -0
  317. package/lib/swipl/library/ext/http/http/http_load.pl +113 -0
  318. package/lib/swipl/library/ext/http/http/http_log.pl +738 -0
  319. package/lib/swipl/library/ext/http/http/http_multipart_plugin.pl +232 -0
  320. package/lib/swipl/library/ext/http/http/http_open.pl +1821 -0
  321. package/lib/swipl/library/ext/http/http/http_openid.pl +1561 -0
  322. package/lib/swipl/library/ext/http/http/http_parameters.pl +504 -0
  323. package/lib/swipl/library/ext/http/http/http_path.pl +380 -0
  324. package/lib/swipl/library/ext/http/http/http_proxy.pl +80 -0
  325. package/lib/swipl/library/ext/http/http/http_pwp.pl +351 -0
  326. package/lib/swipl/library/ext/http/http/http_redis_plugin.pl +332 -0
  327. package/lib/swipl/library/ext/http/http/http_server.pl +105 -0
  328. package/lib/swipl/library/ext/http/http/http_server_files.pl +126 -0
  329. package/lib/swipl/library/ext/http/http/http_server_health.pl +186 -0
  330. package/lib/swipl/library/ext/http/http/http_session.pl +1040 -0
  331. package/lib/swipl/library/ext/http/http/http_sgml_plugin.pl +137 -0
  332. package/lib/swipl/library/ext/http/http/http_stream.pl +376 -0
  333. package/lib/swipl/library/ext/http/http/http_unix_daemon.pl +989 -0
  334. package/lib/swipl/library/ext/http/http/http_wrapper.pl +559 -0
  335. package/lib/swipl/library/ext/http/http/hub.pl +600 -0
  336. package/lib/swipl/library/ext/http/http/js_write.pl +461 -0
  337. package/lib/swipl/library/ext/http/http/mimepack.pl +224 -0
  338. package/lib/swipl/library/ext/http/http/mimetype.pl +276 -0
  339. package/lib/swipl/library/ext/http/http/term_html.pl +797 -0
  340. package/lib/swipl/library/ext/http/http/thread_httpd.pl +1181 -0
  341. package/lib/swipl/library/ext/http/http/web/css/dirindex.css +24 -0
  342. package/lib/swipl/library/ext/http/http/web/css/openid.css +57 -0
  343. package/lib/swipl/library/ext/http/http/web/icons/back.png +0 -0
  344. package/lib/swipl/library/ext/http/http/web/icons/c.png +0 -0
  345. package/lib/swipl/library/ext/http/http/web/icons/compressed.png +0 -0
  346. package/lib/swipl/library/ext/http/http/web/icons/folder.png +0 -0
  347. package/lib/swipl/library/ext/http/http/web/icons/generic.png +0 -0
  348. package/lib/swipl/library/ext/http/http/web/icons/layout.png +0 -0
  349. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-square.png +0 -0
  350. package/lib/swipl/library/ext/http/http/web/icons/openid-logo-tiny.png +0 -0
  351. package/lib/swipl/library/ext/http/http/websocket.pl +729 -0
  352. package/lib/swipl/library/ext/http/http/yadis.pl +205 -0
  353. package/lib/swipl/library/ext/json/INDEX.pl +36 -0
  354. package/lib/swipl/library/ext/json/http/INDEX.pl +16 -0
  355. package/lib/swipl/library/ext/json/http/http_json.pl +490 -0
  356. package/lib/swipl/library/ext/json/http/js_grammar.pl +53 -0
  357. package/lib/swipl/library/ext/json/http/json.pl +48 -0
  358. package/lib/swipl/library/ext/json/http/json_convert.pl +48 -0
  359. package/lib/swipl/library/ext/json/json.pl +1215 -0
  360. package/lib/swipl/library/ext/json/json_convert.pl +681 -0
  361. package/lib/swipl/library/ext/json/json_grammar.pl +349 -0
  362. package/lib/swipl/library/ext/json/json_rpc_client.pl +423 -0
  363. package/lib/swipl/library/ext/json/json_rpc_common.pl +104 -0
  364. package/lib/swipl/library/ext/json/json_rpc_server.pl +489 -0
  365. package/lib/swipl/library/ext/json/json_schema.pl +2111 -0
  366. package/lib/swipl/library/ext/nlp/INDEX.pl +15 -0
  367. package/lib/swipl/library/ext/nlp/double_metaphone.pl +86 -0
  368. package/lib/swipl/library/ext/nlp/isub.pl +162 -0
  369. package/lib/swipl/library/ext/nlp/porter_stem.pl +50 -0
  370. package/lib/swipl/library/ext/nlp/snowball.pl +97 -0
  371. package/lib/swipl/library/ext/pcre/INDEX.pl +17 -0
  372. package/lib/swipl/library/ext/pcre/pcre.pl +974 -0
  373. package/lib/swipl/library/ext/plunit/INDEX.pl +20 -0
  374. package/lib/swipl/library/ext/plunit/plunit.pl +2631 -0
  375. package/lib/swipl/library/ext/plunit/test_wizard.pl +249 -0
  376. package/lib/swipl/library/ext/semweb/semweb/INDEX.pl +288 -0
  377. package/lib/swipl/library/ext/semweb/semweb/rdf11.pl +2106 -0
  378. package/lib/swipl/library/ext/semweb/semweb/rdf11_containers.pl +299 -0
  379. package/lib/swipl/library/ext/semweb/semweb/rdf_cache.pl +278 -0
  380. package/lib/swipl/library/ext/semweb/semweb/rdf_compare.pl +132 -0
  381. package/lib/swipl/library/ext/semweb/semweb/rdf_db.pl +3468 -0
  382. package/lib/swipl/library/ext/semweb/semweb/rdf_edit.pl +1145 -0
  383. package/lib/swipl/library/ext/semweb/semweb/rdf_http_plugin.pl +274 -0
  384. package/lib/swipl/library/ext/semweb/semweb/rdf_library.pl +1021 -0
  385. package/lib/swipl/library/ext/semweb/semweb/rdf_litindex.pl +1035 -0
  386. package/lib/swipl/library/ext/semweb/semweb/rdf_ntriples.pl +422 -0
  387. package/lib/swipl/library/ext/semweb/semweb/rdf_persistency.pl +1576 -0
  388. package/lib/swipl/library/ext/semweb/semweb/rdf_portray.pl +182 -0
  389. package/lib/swipl/library/ext/semweb/semweb/rdf_prefixes.pl +681 -0
  390. package/lib/swipl/library/ext/semweb/semweb/rdf_sandbox.pl +153 -0
  391. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle.pl +54 -0
  392. package/lib/swipl/library/ext/semweb/semweb/rdf_turtle_write.pl +1587 -0
  393. package/lib/swipl/library/ext/semweb/semweb/rdf_zlib_plugin.pl +52 -0
  394. package/lib/swipl/library/ext/semweb/semweb/rdfa.pl +1510 -0
  395. package/lib/swipl/library/ext/semweb/semweb/rdfs.pl +475 -0
  396. package/lib/swipl/library/ext/semweb/semweb/sparql_client.pl +643 -0
  397. package/lib/swipl/library/ext/semweb/semweb/turtle.pl +455 -0
  398. package/lib/swipl/library/ext/sgml/DTD/HTML4.dcl +88 -0
  399. package/lib/swipl/library/ext/sgml/DTD/HTML4.dtd +1092 -0
  400. package/lib/swipl/library/ext/sgml/DTD/HTML4.soc +6 -0
  401. package/lib/swipl/library/ext/sgml/DTD/HTML5.dtd +906 -0
  402. package/lib/swipl/library/ext/sgml/DTD/HTMLlat1.ent +195 -0
  403. package/lib/swipl/library/ext/sgml/DTD/HTMLspec.ent +77 -0
  404. package/lib/swipl/library/ext/sgml/DTD/HTMLsym.ent +241 -0
  405. package/lib/swipl/library/ext/sgml/INDEX.pl +64 -0
  406. package/lib/swipl/library/ext/sgml/c14n2.pl +203 -0
  407. package/lib/swipl/library/ext/sgml/iso_639.pl +631 -0
  408. package/lib/swipl/library/ext/sgml/pwp.pl +705 -0
  409. package/lib/swipl/library/ext/sgml/sgml.pl +815 -0
  410. package/lib/swipl/library/ext/sgml/sgml_write.pl +1003 -0
  411. package/lib/swipl/library/ext/sgml/xpath.pl +620 -0
  412. package/lib/swipl/library/ext/sgml/xsdp_types.pl +232 -0
  413. package/lib/swipl/library/ext/ssl/INDEX.pl +60 -0
  414. package/lib/swipl/library/ext/ssl/crypto.pl +1015 -0
  415. package/lib/swipl/library/ext/ssl/http/INDEX.pl +5 -0
  416. package/lib/swipl/library/ext/ssl/http/http_ssl_plugin.pl +296 -0
  417. package/lib/swipl/library/ext/ssl/saml.pl +609 -0
  418. package/lib/swipl/library/ext/ssl/ssl.pl +647 -0
  419. package/lib/swipl/library/ext/ssl/xmldsig.pl +391 -0
  420. package/lib/swipl/library/ext/ssl/xmlenc.pl +354 -0
  421. package/lib/swipl/library/ext/zlib/INDEX.pl +8 -0
  422. package/lib/swipl/library/ext/zlib/zlib.pl +112 -0
  423. package/lib/swipl/library/fastrw.pl +105 -0
  424. package/lib/swipl/library/files.pl +80 -0
  425. package/lib/swipl/library/gensym.pl +111 -0
  426. package/lib/swipl/library/git.pl +1027 -0
  427. package/lib/swipl/library/hashtable.pl +365 -0
  428. package/lib/swipl/library/heaps.pl +252 -0
  429. package/lib/swipl/library/hotfix.pl +239 -0
  430. package/lib/swipl/library/http/jquery.pl +103 -0
  431. package/lib/swipl/library/http/web/js/jquery-3.6.0.min.js +2 -0
  432. package/lib/swipl/library/increval.pl +217 -0
  433. package/lib/swipl/library/intercept.pl +263 -0
  434. package/lib/swipl/library/iostream.pl +237 -0
  435. package/lib/swipl/library/iri_scheme/file.pl +70 -0
  436. package/lib/swipl/library/lazy_lists.pl +481 -0
  437. package/lib/swipl/library/listing.pl +1362 -0
  438. package/lib/swipl/library/lists.pl +860 -0
  439. package/lib/swipl/library/lynx/INDEX.pl +14 -0
  440. package/lib/swipl/library/lynx/format.pl +380 -0
  441. package/lib/swipl/library/lynx/html_style.pl +129 -0
  442. package/lib/swipl/library/lynx/html_text.pl +865 -0
  443. package/lib/swipl/library/lynx/pldoc_style.pl +87 -0
  444. package/lib/swipl/library/macros.pl +451 -0
  445. package/lib/swipl/library/main.pl +1200 -0
  446. package/lib/swipl/library/make.pl +197 -0
  447. package/lib/swipl/library/modules.pl +129 -0
  448. package/lib/swipl/library/nb_rbtrees.pl +267 -0
  449. package/lib/swipl/library/nb_set.pl +203 -0
  450. package/lib/swipl/library/obfuscate.pl +115 -0
  451. package/lib/swipl/library/occurs.pl +241 -0
  452. package/lib/swipl/library/operators.pl +182 -0
  453. package/lib/swipl/library/option.pl +388 -0
  454. package/lib/swipl/library/optparse.pl +966 -0
  455. package/lib/swipl/library/ordsets.pl +518 -0
  456. package/lib/swipl/library/oset.pl +160 -0
  457. package/lib/swipl/library/pairs.pl +187 -0
  458. package/lib/swipl/library/persistency.pl +713 -0
  459. package/lib/swipl/library/pio.pl +47 -0
  460. package/lib/swipl/library/portray_text.pl +277 -0
  461. package/lib/swipl/library/pprint.pl +940 -0
  462. package/lib/swipl/library/predicate_options.pl +975 -0
  463. package/lib/swipl/library/prolog_autoload.pl +233 -0
  464. package/lib/swipl/library/prolog_breakpoints.pl +396 -0
  465. package/lib/swipl/library/prolog_clause.pl +1104 -0
  466. package/lib/swipl/library/prolog_code.pl +416 -0
  467. package/lib/swipl/library/prolog_codewalk.pl +1248 -0
  468. package/lib/swipl/library/prolog_colour.pl +3301 -0
  469. package/lib/swipl/library/prolog_colour.qlf +0 -0
  470. package/lib/swipl/library/prolog_config.pl +154 -0
  471. package/lib/swipl/library/prolog_coverage.pl +1333 -0
  472. package/lib/swipl/library/prolog_debug.pl +404 -0
  473. package/lib/swipl/library/prolog_deps.pl +675 -0
  474. package/lib/swipl/library/prolog_evaluable.pl +234 -0
  475. package/lib/swipl/library/prolog_format.pl +219 -0
  476. package/lib/swipl/library/prolog_history.pl +161 -0
  477. package/lib/swipl/library/prolog_jiti.pl +333 -0
  478. package/lib/swipl/library/prolog_locale.pl +61 -0
  479. package/lib/swipl/library/prolog_metainference.pl +307 -0
  480. package/lib/swipl/library/prolog_pack.pl +3906 -0
  481. package/lib/swipl/library/prolog_profile.pl +346 -0
  482. package/lib/swipl/library/prolog_qlfmake.pl +533 -0
  483. package/lib/swipl/library/prolog_source.pl +1188 -0
  484. package/lib/swipl/library/prolog_stack.pl +794 -0
  485. package/lib/swipl/library/prolog_trace.pl +365 -0
  486. package/lib/swipl/library/prolog_versions.pl +347 -0
  487. package/lib/swipl/library/prolog_wrap.pl +164 -0
  488. package/lib/swipl/library/prolog_xref.pl +3090 -0
  489. package/lib/swipl/library/prolog_xref.qlf +0 -0
  490. package/lib/swipl/library/pure_input.pl +266 -0
  491. package/lib/swipl/library/qpforeign.pl +695 -0
  492. package/lib/swipl/library/qsave.pl +1516 -0
  493. package/lib/swipl/library/quasi_quotations.pl +300 -0
  494. package/lib/swipl/library/quintus.pl +437 -0
  495. package/lib/swipl/library/random.pl +459 -0
  496. package/lib/swipl/library/rbtrees.pl +1153 -0
  497. package/lib/swipl/library/readln.pl +256 -0
  498. package/lib/swipl/library/readutil.pl +304 -0
  499. package/lib/swipl/library/record.pl +544 -0
  500. package/lib/swipl/library/rwlocks.pl +172 -0
  501. package/lib/swipl/library/sandbox.pl +1384 -0
  502. package/lib/swipl/library/semweb/dc.rdfs +198 -0
  503. package/lib/swipl/library/semweb/eor.rdfs +95 -0
  504. package/lib/swipl/library/semweb/owl.owl +287 -0
  505. package/lib/swipl/library/semweb/rdf_library.ttl +90 -0
  506. package/lib/swipl/library/semweb/rdfs.rdfs +251 -0
  507. package/lib/swipl/library/settings.pl +755 -0
  508. package/lib/swipl/library/shell.pl +462 -0
  509. package/lib/swipl/library/shlib.pl +670 -0
  510. package/lib/swipl/library/solution_sequences.pl +439 -0
  511. package/lib/swipl/library/sort.pl +119 -0
  512. package/lib/swipl/library/statistics.pl +541 -0
  513. package/lib/swipl/library/streams.pl +118 -0
  514. package/lib/swipl/library/strings.pl +469 -0
  515. package/lib/swipl/library/system.pl +95 -0
  516. package/lib/swipl/library/tables.pl +381 -0
  517. package/lib/swipl/library/tableutil.pl +771 -0
  518. package/lib/swipl/library/tabling.pl +42 -0
  519. package/lib/swipl/library/terms.pl +457 -0
  520. package/lib/swipl/library/theme/auto.pl +61 -0
  521. package/lib/swipl/library/theme/dark.pl +455 -0
  522. package/lib/swipl/library/theme/light.pl +45 -0
  523. package/lib/swipl/library/thread.pl +810 -0
  524. package/lib/swipl/library/thread_pool.pl +508 -0
  525. package/lib/swipl/library/threadutil.pl +574 -0
  526. package/lib/swipl/library/tty.pl +316 -0
  527. package/lib/swipl/library/ugraphs.pl +644 -0
  528. package/lib/swipl/library/unicode/INDEX.pl +6 -0
  529. package/lib/swipl/library/unicode/blocks.pl +414 -0
  530. package/lib/swipl/library/url.pl +1129 -0
  531. package/lib/swipl/library/utf8.pl +145 -0
  532. package/lib/swipl/library/varnumbers.pl +221 -0
  533. package/lib/swipl/library/vm.pl +251 -0
  534. package/lib/swipl/library/wfs.pl +205 -0
  535. package/lib/swipl/library/when.pl +263 -0
  536. package/lib/swipl/library/writef.pl +278 -0
  537. package/lib/swipl/library/www_browser.pl +251 -0
  538. package/lib/swipl/library/yall.pl +574 -0
  539. package/lib/swipl/library/zip.pl +211 -0
  540. package/lib/swipl/swipl.home +1 -0
  541. package/lib/vendor/libcrypto.so.3 +0 -0
  542. package/lib/vendor/libpcre2-8.so.0 +0 -0
  543. package/lib/vendor/libssl.so.3 +0 -0
  544. package/lib/vendor/libz.so.1 +0 -0
  545. package/licenses/OpenSSL-LICENSE.txt +177 -0
  546. package/licenses/PCRE2-COPYING +5 -0
  547. package/licenses/README.md +12 -0
  548. package/licenses/SWI-Prolog-LICENSE +41 -0
  549. package/licenses/zlib-LICENSE +22 -0
  550. package/package.json +27 -0
@@ -0,0 +1,1015 @@
1
+ /* Part of SWI-Prolog
2
+
3
+ Author: Markus Triska and Matt Lilley
4
+ WWW: http://www.swi-prolog.org
5
+ Copyright (c) 2004-2017, SWI-Prolog Foundation
6
+ VU University Amsterdam
7
+ All rights reserved.
8
+
9
+ Redistribution and use in source and binary forms, with or without
10
+ modification, are permitted provided that the following conditions
11
+ are met:
12
+
13
+ 1. Redistributions of source code must retain the above copyright
14
+ notice, this list of conditions and the following disclaimer.
15
+
16
+ 2. Redistributions in binary form must reproduce the above copyright
17
+ notice, this list of conditions and the following disclaimer in
18
+ the documentation and/or other materials provided with the
19
+ distribution.
20
+
21
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
+ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
+ LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
+ ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
+ POSSIBILITY OF SUCH DAMAGE.
33
+ */
34
+
35
+ :- module(crypto,
36
+ [ crypto_n_random_bytes/2, % +N, -Bytes
37
+ crypto_data_hash/3, % +Data, -Hash, +Options
38
+ crypto_file_hash/3, % +File, -Hash, +Options
39
+ crypto_context_new/2, % -Context, +Options
40
+ crypto_data_context/3, % +Data, +C0, -C
41
+ crypto_context_hash/2, % +Context, -Hash
42
+ crypto_open_hash_stream/3, % +InStream, -HashStream, +Options
43
+ crypto_stream_hash/2, % +HashStream, -Hash
44
+ crypto_password_hash/2, % +Password, ?Hash
45
+ crypto_password_hash/3, % +Password, ?Hash, +Options
46
+ crypto_data_hkdf/4, % +Data, +Length, -Bytes, +Options
47
+ ecdsa_sign/4, % +Key, +Data, -Signature, +Options
48
+ ecdsa_verify/4, % +Key, +Data, +Signature, +Options
49
+ crypto_data_decrypt/6, % +CipherText, +Algorithm, +Key, +IV, -PlainText, +Options
50
+ crypto_data_encrypt/6, % +PlainText, +Algorithm, +Key, +IV, -CipherText, +Options
51
+ hex_bytes/2, % ?Hex, ?List
52
+ rsa_private_decrypt/4, % +Key, +Ciphertext, -Plaintext, +Enc
53
+ rsa_private_encrypt/4, % +Key, +Plaintext, -Ciphertext, +Enc
54
+ rsa_public_decrypt/4, % +Key, +Ciphertext, -Plaintext, +Enc
55
+ rsa_public_encrypt/4, % +Key, +Plaintext, -Ciphertext, +Enc
56
+ rsa_sign/4, % +Key, +Data, -Signature, +Options
57
+ rsa_verify/4, % +Key, +Data, +Signature, +Options
58
+ crypto_modular_inverse/3, % +X, +M, -Y
59
+ crypto_generate_prime/3, % +N, -P, +Options
60
+ crypto_is_prime/2, % +P, +Options
61
+ crypto_name_curve/2, % +Name, -Curve
62
+ crypto_curve_order/2, % +Curve, -Order
63
+ crypto_curve_generator/2, % +Curve, -Generator
64
+ crypto_curve_scalar_mult/4 % +Curve, +Scalar, +Point, -Result
65
+ ]).
66
+ :- autoload(library(apply),[foldl/4,maplist/3]).
67
+ :- autoload(library(base64),[base64_encoded/3]).
68
+ :- autoload(library(error),[must_be/2,domain_error/2]).
69
+ :- autoload(library(lists),[append/3,select/3,reverse/2]).
70
+ :- autoload(library(option),[option/3,option/2]).
71
+
72
+ :- use_foreign_library(foreign(crypto4pl)).
73
+
74
+
75
+ /** <module> Cryptography and authentication library
76
+
77
+ This library provides bindings to functionality of OpenSSL that is
78
+ related to cryptography and authentication, not necessarily involving
79
+ connections, sockets or streams.
80
+
81
+ The hash functionality of this library subsumes and extends that of
82
+ `library(sha)`, `library(hash_stream)` and `library(md5)` by providing a
83
+ unified interface to all available digest algorithms.
84
+
85
+ The underlying OpenSSL library (`libcrypto`) is dynamically loaded if
86
+ _either_ `library(crypto)` or `library(ssl)` are loaded. Therefore, if
87
+ your application uses `library(ssl)`, you can use `library(crypto)` for
88
+ hashing without increasing the memory footprint of your application. In
89
+ other cases, the specialised hashing libraries are more lightweight but
90
+ less general alternatives to `library(crypto)`.
91
+
92
+ @author [Markus Triska](https://www.metalevel.at)
93
+ @author Matt Lilley
94
+ */
95
+
96
+ %% crypto_n_random_bytes(+N, -Bytes) is det
97
+ %
98
+ % Bytes is unified with a list of N cryptographically secure
99
+ % pseudo-random bytes. Each byte is an integer between 0 and 255. If
100
+ % the internal pseudo-random number generator (PRNG) has not been
101
+ % seeded with enough entropy to ensure an unpredictable byte
102
+ % sequence, an exception is thrown.
103
+ %
104
+ % One way to relate such a list of bytes to an _integer_ is to use
105
+ % CLP(FD) constraints as follows:
106
+ %
107
+ % ==
108
+ % :- use_module(library(clpfd)).
109
+ %
110
+ % bytes_integer(Bs, N) :-
111
+ % foldl(pow, Bs, 0-0, N-_).
112
+ %
113
+ % pow(B, N0-I0, N-I) :-
114
+ % B in 0..255,
115
+ % N #= N0 + B*256^I0,
116
+ % I #= I0 + 1.
117
+ % ==
118
+ %
119
+ % With this definition, you can generate a random 256-bit integer
120
+ % _from_ a list of 32 random _bytes_:
121
+ %
122
+ % ==
123
+ % ?- crypto_n_random_bytes(32, Bs),
124
+ % bytes_integer(Bs, I).
125
+ % Bs = [98, 9, 35, 100, 126, 174, 48, 176, 246|...],
126
+ % I = 109798276762338328820827...(53 digits omitted).
127
+ % ==
128
+ %
129
+ % The above relation also works in the other direction, letting you
130
+ % translate an integer _to_ a list of bytes. In addition, you can
131
+ % use hex_bytes/2 to convert bytes to _tokens_ that can be easily
132
+ % exchanged in your applications. This also works if you have
133
+ % compiled SWI-Prolog without support for large integers.
134
+
135
+
136
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
137
+ SHA256 is the current default for several hash-related predicates.
138
+ It is deemed sufficiently secure for the foreseeable future. Yet,
139
+ application programmers must be aware that the default may change in
140
+ future versions. The hash predicates all yield the algorithm they
141
+ used if a Prolog variable is used for the pertaining option.
142
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
143
+
144
+ default_hash(sha256).
145
+
146
+ functor_hash_options(F, Hash, Options0, [Option|Options]) :-
147
+ Option =.. [F,Hash],
148
+ ( select(Option, Options0, Options) ->
149
+ ( var(Hash) ->
150
+ default_hash(Hash)
151
+ ; must_be(atom, Hash)
152
+ )
153
+ ; Options = Options0,
154
+ default_hash(Hash)
155
+ ).
156
+
157
+
158
+ %% crypto_data_hash(+Data, -Hash, +Options) is det
159
+ %
160
+ % Hash is the hash of Data. The conversion is controlled
161
+ % by Options:
162
+ %
163
+ % * algorithm(+Algorithm)
164
+ % One of =md5= (_insecure_), =sha1= (_insecure_), =ripemd160=,
165
+ % =sha224=, =sha256=, =sha384=, =sha512=, =sha3_224=, =sha3_256=,
166
+ % =sha3_384=, =sha3_512=, =blake2s256= or =blake2b512=. The BLAKE
167
+ % digest algorithms require OpenSSL 1.1.0 or greater, and the SHA-3
168
+ % algorithms require OpenSSL 1.1.1 or greater. The default is a
169
+ % cryptographically secure algorithm. If you specify a variable,
170
+ % then that variable is unified with the algorithm that was used.
171
+ % * encoding(+Encoding)
172
+ % If Data is a sequence of character _codes_, this must be
173
+ % translated into a sequence of _bytes_, because that is what
174
+ % the hashing requires. The default encoding is =utf8=. The
175
+ % other meaningful value is =octet=, claiming that Data contains
176
+ % raw bytes.
177
+ % * hmac(+Key)
178
+ % If this option is specified, a _hash-based message authentication
179
+ % code_ (HMAC) is computed, using the specified Key which is either
180
+ % an atom, string or list of _bytes_. Any of the available digest
181
+ % algorithms can be used with this option. The cryptographic
182
+ % strength of the HMAC depends on that of the chosen algorithm and
183
+ % also on the key. This option requires OpenSSL 1.1.0 or greater.
184
+ %
185
+ % @param Data is either an atom, string or code-list
186
+ % @param Hash is an atom that represents the hash in hexadecimal encoding.
187
+ %
188
+ % @see hex_bytes/2 for conversion between hexadecimal encoding and
189
+ % lists of bytes.
190
+ % @see crypto_password_hash/2 for the important use case of passwords.
191
+
192
+ crypto_data_hash(Data, Hash, Options) :-
193
+ crypto_context_new(Context0, Options),
194
+ crypto_data_context(Data, Context0, Context),
195
+ crypto_context_hash(Context, Hash).
196
+
197
+ %! crypto_file_hash(+File, -Hash, +Options) is det.
198
+ %
199
+ % True if Hash is the hash of the content of File. For Options,
200
+ % see crypto_data_hash/3.
201
+
202
+ crypto_file_hash(File, Hash, Options) :-
203
+ setup_call_cleanup(open(File, read, In, [type(binary)]),
204
+ crypto_stream_hash(In, Hash, Options),
205
+ close(In)).
206
+
207
+ crypto_stream_hash(Stream, Hash, Options) :-
208
+ crypto_context_new(Context0, Options),
209
+ update_hash(Stream, Context0, Context),
210
+ crypto_context_hash(Context, Hash).
211
+
212
+ update_hash(In, Context0, Context) :-
213
+ ( at_end_of_stream(In)
214
+ -> Context = Context0
215
+ ; read_pending_codes(In, Data, []),
216
+ crypto_data_context(Data, Context0, Context1),
217
+ update_hash(In, Context1, Context)
218
+ ).
219
+
220
+
221
+ %! crypto_context_new(-Context, +Options) is det.
222
+ %
223
+ % Context is unified with the empty context, taking into account
224
+ % Options. The context can be used in crypto_data_context/3. For
225
+ % Options, see crypto_data_hash/3.
226
+ %
227
+ % @param Context is an opaque pure Prolog term that is subject to
228
+ % garbage collection.
229
+
230
+ crypto_context_new(Context, Options0) :-
231
+ functor_hash_options(algorithm, _, Options0, Options),
232
+ '_crypto_context_new'(Context, Options).
233
+
234
+
235
+ %! crypto_data_context(+Data, +Context0, -Context) is det
236
+ %
237
+ % Context0 is an existing computation context, and Context is the
238
+ % new context after hashing Data in addition to the previously
239
+ % hashed data. Context0 may be produced by a prior invocation of
240
+ % either crypto_context_new/2 or crypto_data_context/3 itself.
241
+ %
242
+ % This predicate allows a hash to be computed in chunks, which may
243
+ % be important while working with Metalink (RFC 5854), BitTorrent
244
+ % or similar technologies, or simply with big files.
245
+
246
+ crypto_data_context(Data, Context0, Context) :-
247
+ '_crypto_hash_context_copy'(Context0, Context),
248
+ '_crypto_update_hash_context'(Data, Context).
249
+
250
+
251
+ %! crypto_context_hash(+Context, -Hash)
252
+ %
253
+ % Obtain the hash code of Context. Hash is an atom representing
254
+ % the hash code that is associated with the current state of the
255
+ % computation context Context.
256
+
257
+ crypto_context_hash(Context, Hash) :-
258
+ '_crypto_hash_context_copy'(Context, Copy),
259
+ '_crypto_hash_context_hash'(Copy, List),
260
+ hex_bytes(Hash, List).
261
+
262
+ %! crypto_open_hash_stream(+OrgStream, -HashStream, +Options) is det.
263
+ %
264
+ % Open a filter stream on OrgStream that maintains a hash. The hash
265
+ % can be retrieved at any time using crypto_stream_hash/2. Available
266
+ % Options in addition to those of crypto_data_hash/3 are:
267
+ %
268
+ % - close_parent(+Bool)
269
+ % If `true` (default), closing the filter stream also closes the
270
+ % original (parent) stream.
271
+
272
+ crypto_open_hash_stream(OrgStream, HashStream, Options) :-
273
+ crypto_context_new(Context, Options),
274
+ '_crypto_open_hash_stream'(OrgStream, HashStream, Context).
275
+
276
+
277
+ %! crypto_stream_hash(+HashStream, -Hash) is det.
278
+ %
279
+ % Unify Hash with a hash for the bytes sent to or read from
280
+ % HashStream. Note that the hash is computed on the stream
281
+ % buffers. If the stream is an output stream, it is first flushed
282
+ % and the Digest represents the hash at the current location. If
283
+ % the stream is an input stream the Digest represents the hash of
284
+ % the processed input including the already buffered data.
285
+
286
+ crypto_stream_hash(Stream, Hash) :-
287
+ '_crypto_stream_hash_context'(Stream, Context),
288
+ crypto_context_hash(Context, Hash).
289
+
290
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
291
+ The so-called modular crypt format (MCF) is a standard for encoding
292
+ password hash strings. However, there's no official specification
293
+ document describing it. Nor is there a central registry of
294
+ identifiers or rules. This page describes what is known about it:
295
+
296
+ https://pythonhosted.org/passlib/modular_crypt_format.html
297
+
298
+ As of 2016, the MCF is deprecated in favor of the PHC String Format:
299
+
300
+ https://github.com/P-H-C/phc-string-format/blob/master/phc-sf-spec.md
301
+
302
+ This is what we are using below. For the time being, it is best to
303
+ treat these hashes as opaque atoms in applications. Please let me
304
+ know if you need to rely on any specifics of this format.
305
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
306
+
307
+ %! crypto_password_hash(+Password, ?Hash) is semidet.
308
+ %
309
+ % If Hash is instantiated, the predicate succeeds _iff_ the hash
310
+ % matches the given password. Otherwise, the call is equivalent to
311
+ % crypto_password_hash(Password, Hash, []) and computes a
312
+ % password-based hash using the default options.
313
+
314
+ crypto_password_hash(Password, Hash) :-
315
+ ( nonvar(Hash) ->
316
+ must_be(atom, Hash),
317
+ split_string(Hash, "$", "$", Parts),
318
+ ( Parts = ["pbkdf2-sha512",Ps,SaltB64,HashB64] ->
319
+ atom_to_term(Ps, t=Iterations, []),
320
+ bytes_base64(SaltBytes, SaltB64),
321
+ bytes_base64(HashBytes, HashB64),
322
+ '_crypto_password_hash_pbkdf2'(Password, SaltBytes, Iterations, HashBytes)
323
+ ; Parts = ["2a", _, _],
324
+ sub_atom(Hash, 0, 29, 31, Setting),
325
+ '_crypto_password_hash_bcrypt'(Password, Setting, Hash)
326
+ )
327
+ ; crypto_password_hash(Password, Hash, [])
328
+ ).
329
+
330
+ %! crypto_password_hash(+Password, -Hash, +Options) is det.
331
+ %
332
+ % Derive Hash based on Password. This predicate is similar to
333
+ % crypto_data_hash/3 in that it derives a hash from given data.
334
+ % However, it is tailored for the specific use case of
335
+ % _passwords_. One essential distinction is that for this use case,
336
+ % the derivation of a hash should be _as slow as possible_ to
337
+ % counteract brute-force attacks over possible passwords.
338
+ %
339
+ % Another important distinction is that equal passwords must yield,
340
+ % with very high probability, _different_ hashes. For this reason,
341
+ % cryptographically strong random numbers are automatically added to
342
+ % the password before a hash is derived.
343
+ %
344
+ % Hash is unified with an atom that contains the computed hash and all
345
+ % parameters that were used, except for the password. Instead of
346
+ % storing passwords, store these hashes. Later, you can verify the
347
+ % validity of a password with crypto_password_hash/2, comparing the
348
+ % then entered password to the stored hash. If you need to export this
349
+ % atom, you should treat it as opaque ASCII data with up to 255 bytes
350
+ % of length. The maximal length may increase in the future.
351
+ %
352
+ % Admissible options are:
353
+ %
354
+ % - algorithm(+Algorithm)
355
+ % The algorithm to use. Currently, the only available algorithms
356
+ % are =|pbkdf2-sha512|= (the default) and =bcrypt=.
357
+ % - cost(+C)
358
+ % C is an integer, denoting the binary logarithm of the number
359
+ % of _iterations_ used for the derivation of the hash. This
360
+ % means that the number of iterations is set to 2^C. Currently,
361
+ % the default is 17, and thus more than one hundred _thousand_
362
+ % iterations. You should set this option as high as your server
363
+ % and users can tolerate. The default is subject to change and
364
+ % will likely increase in the future or adapt to new algorithms.
365
+ % - salt(+Salt)
366
+ % Use the given list of bytes as salt. By default,
367
+ % cryptographically secure random numbers are generated for this
368
+ % purpose. The default is intended to be secure, and constitutes
369
+ % the typical use case of this predicate.
370
+ %
371
+ % Currently, PBKDF2 with SHA-512 is used as the hash derivation
372
+ % function, using 128 bits of salt. All default parameters, including
373
+ % the algorithm, are subject to change, and other algorithms will also
374
+ % become available in the future. Since computed hashes store all
375
+ % parameters that were used during their derivation, such changes will
376
+ % not affect the operation of existing deployments. Note though that
377
+ % new hashes will then be computed with the new default parameters.
378
+ %
379
+ % @see crypto_data_hkdf/4 for generating keys from Hash.
380
+
381
+ crypto_password_hash(Password, Hash, Options) :-
382
+ must_be(list, Options),
383
+ option(cost(C), Options, 17),
384
+ Iterations is 2^C,
385
+ option(algorithm(Algorithm), Options, 'pbkdf2-sha512'),
386
+ memberchk(Algorithm, ['pbkdf2-sha512', bcrypt]),
387
+ ( option(salt(SaltBytes), Options) ->
388
+ true
389
+ ; crypto_n_random_bytes(16, SaltBytes)
390
+ ),
391
+ ( Algorithm == 'pbkdf2-sha512'
392
+ -> '_crypto_password_hash_pbkdf2'(Password, SaltBytes, Iterations, HashBytes),
393
+ bytes_base64(HashBytes, HashB64),
394
+ bytes_base64(SaltBytes, SaltB64),
395
+ format(atom(Hash),
396
+ "$pbkdf2-sha512$t=~d$~w$~w", [Iterations,SaltB64,HashB64])
397
+ ; bcrypt_bytes_base64(SaltBytes, SaltB64),
398
+ option(cost(Cost), Options, 11),
399
+ format(string(Setting), "$2a$~|~`0t~d~2+$~w", [Cost, SaltB64]),
400
+ '_crypto_password_hash_bcrypt'(Password, Setting, Hash)
401
+ ).
402
+
403
+
404
+ /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
405
+ Bidirectional Bytes <-> Base64 conversion as required by PHC format.
406
+
407
+ Note that *no padding* must be used, and that we must be able
408
+ to encode the whole range of bytes, not only UTF-8 sequences!
409
+ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
410
+
411
+ bytes_base64(Bytes, Base64) :-
412
+ ( var(Bytes) ->
413
+ base64_encoded(Atom, Base64, [padding(false), encoding(iso_latin_1)]),
414
+ atom_codes(Atom, Bytes)
415
+ ; atom_codes(Atom, Bytes),
416
+ base64_encoded(Atom, Base64, [padding(false), encoding(iso_latin_1)])
417
+ ).
418
+
419
+ % Bcrypt uses a different alphabeta for base64 encoding, annoyingly
420
+ bcrypt_bytes_base64(Bytes, Base64) :-
421
+ ( var(Bytes) ->
422
+ base64_encoded(Atom, Base64, [padding(false), encoding(utf8),
423
+ charset(openbsd)]),
424
+ atom_codes(Atom, Bytes)
425
+ ; atom_codes(Atom, Bytes),
426
+ base64_encoded(Atom, Base64, [padding(false), encoding(utf8),
427
+ charset(openbsd)])
428
+ ).
429
+
430
+
431
+ %! crypto_data_hkdf(+Data, +Length, -Bytes, +Options) is det.
432
+ %
433
+ % Concentrate possibly dispersed entropy of Data and then expand it to
434
+ % the desired length. Bytes is unified with a list of _bytes_ of
435
+ % length Length, and is suitable as input keying material and
436
+ % initialization vectors to the symmetric encryption predicates.
437
+ %
438
+ % Admissible options are:
439
+ %
440
+ % - algorithm(+Algorithm)
441
+ % A hashing algorithm as specified to crypto_data_hash/3. The
442
+ % default is a cryptographically secure algorithm. If you
443
+ % specify a variable, then it is unified with the algorithm
444
+ % that was used.
445
+ % - info(+Info)
446
+ % Optional context and application specific information,
447
+ % specified as an atom, string or list of _bytes_. The default
448
+ % is the zero length atom ''.
449
+ % - salt(+List)
450
+ % Optionally, a list of _bytes_ that are used as salt. The
451
+ % default is all zeroes.
452
+ % - encoding(+Atom)
453
+ % Either =|utf8|= (default) or =|octet|=, denoting
454
+ % the representation of Data as in crypto_data_hash/3.
455
+ %
456
+ % The `info/1` option can be used to generate multiple keys from a
457
+ % single master key, using for example values such as =|key|= and
458
+ % =|iv|=, or the name of a file that is to be encrypted.
459
+ %
460
+ % This predicate requires OpenSSL 1.1.0 or greater.
461
+ %
462
+ % @see crypto_n_random_bytes/2 to obtain a suitable salt.
463
+ % @see crypto_data_hash/3 to compute a HMAC signature.
464
+
465
+
466
+ crypto_data_hkdf(Data, L, Bytes, Options0) :-
467
+ functor_hash_options(algorithm, Algorithm, Options0, Options),
468
+ option(salt(SaltBytes), Options, []),
469
+ option(info(Info), Options, ''),
470
+ option(encoding(Enc), Options, utf8),
471
+ '_crypto_data_hkdf'(Data, SaltBytes, Info, Algorithm, Enc, L, Bytes).
472
+
473
+ %! ecdsa_sign(+Key, +Data, -Signature, +Options)
474
+ %
475
+ % Create an ECDSA signature for Data with EC private key Key.
476
+ % Among the most common cases is signing a hash that was created
477
+ % with crypto_data_hash/3 or other predicates of this library. For
478
+ % this reason, the default encoding (`hex`) assumes that Data is
479
+ % an atom, string, character list or code list representing the
480
+ % data in hexadecimal notation. See rsa_sign/4 for an example.
481
+ %
482
+ % Options:
483
+ %
484
+ % - encoding(+Encoding)
485
+ % Encoding to use for Data. Default is `hex`. Alternatives
486
+ % are `octet`, `utf8` and `text`.
487
+
488
+ ecdsa_sign(private_key(ec(Private,Public0,Curve)), Data0, Signature, Options) :-
489
+ option(encoding(Enc0), Options, hex),
490
+ hex_encoding(Enc0, Data0, Enc, Data),
491
+ hex_bytes(Public0, Public),
492
+ '_crypto_ecdsa_sign'(ec(Private,Public,Curve), Data, Enc, Signature).
493
+
494
+ hex_encoding(hex, Data0, octet, Data) :- !,
495
+ hex_bytes(Data0, Data).
496
+ hex_encoding(Enc, Data, Enc, Data).
497
+
498
+ %! ecdsa_verify(+Key, +Data, +Signature, +Options) is semidet.
499
+ %
500
+ % True iff Signature can be verified as the ECDSA signature for
501
+ % Data, using the EC public key Key.
502
+ %
503
+ % Options:
504
+ %
505
+ % - encoding(+Encoding)
506
+ % Encoding to use for Data. Default is `hex`. Alternatives
507
+ % are `octet`, `utf8` and `text`.
508
+
509
+ ecdsa_verify(public_key(ec(Private,Public0,Curve)), Data0, Signature0, Options) :-
510
+ option(encoding(Enc0), Options, hex),
511
+ hex_encoding(Enc0, Data0, Enc, Data),
512
+ hex_bytes(Public0, Public),
513
+ hex_bytes(Signature0, Signature),
514
+ '_crypto_ecdsa_verify'(ec(Private,Public,Curve), Data, Enc, Signature).
515
+
516
+
517
+ %! hex_bytes(?Hex, ?List) is det.
518
+ %
519
+ % Relation between a hexadecimal sequence and a list of bytes. Hex
520
+ % is an atom, string, list of characters or list of codes in
521
+ % hexadecimal encoding. This is the format that is used by
522
+ % crypto_data_hash/3 and related predicates to represent _hashes_.
523
+ % Bytes is a list of _integers_ between 0 and 255 that represent the
524
+ % sequence as a list of bytes. At least one of the arguments must
525
+ % be instantiated. When converting List _to_ Hex, an _atom_ is used
526
+ % to represent the sequence of hexadecimal digits.
527
+ %
528
+ % Example:
529
+ %
530
+ % ==
531
+ % ?- hex_bytes('501ACE', Bs).
532
+ % Bs = [80, 26, 206].
533
+ % ==
534
+ %
535
+ % @see base64_encoded/3 for Base64 encoding, which is often used to
536
+ % transfer or embed binary data in applications.
537
+
538
+ hex_bytes(Hs, Bytes) :-
539
+ ( ground(Hs) ->
540
+ string_chars(Hs, Chars),
541
+ ( phrase(hex_bytes(Chars), Bytes)
542
+ -> true
543
+ ; domain_error(hex_encoding, Hs)
544
+ )
545
+ ; must_be(list(between(0,255)), Bytes),
546
+ phrase(bytes_hex(Bytes), Chars),
547
+ atom_chars(Hs, Chars)
548
+ ).
549
+
550
+ hex_bytes([]) --> [].
551
+ hex_bytes([H1,H2|Hs]) --> [Byte],
552
+ { char_type(H1, xdigit(High)),
553
+ char_type(H2, xdigit(Low)),
554
+ Byte is High*16 + Low },
555
+ hex_bytes(Hs).
556
+
557
+ bytes_hex([]) --> [].
558
+ bytes_hex([B|Bs]) -->
559
+ { High is B>>4,
560
+ Low is B /\ 0xf,
561
+ char_type(C0, xdigit(High)),
562
+ char_type(C1, xdigit(Low))
563
+ },
564
+ [C0,C1],
565
+ bytes_hex(Bs).
566
+
567
+ %! rsa_private_decrypt(+PrivateKey, +CipherText, -PlainText, +Options) is det.
568
+ %! rsa_private_encrypt(+PrivateKey, +PlainText, -CipherText, +Options) is det.
569
+ %! rsa_public_decrypt(+PublicKey, +CipherText, -PlainText, +Options) is det.
570
+ %! rsa_public_encrypt(+PublicKey, +PlainText, -CipherText, +Options) is det.
571
+ %
572
+ % RSA Public key encryption and decryption primitives. A string
573
+ % can be safely communicated by first encrypting it and have the
574
+ % peer decrypt it with the matching key and predicate. The length
575
+ % of the string is limited by the key length.
576
+ %
577
+ % Options:
578
+ %
579
+ % - encoding(+Encoding)
580
+ % Encoding to use for Data. Default is `utf8`. Alternatives
581
+ % are `utf8` and `octet`.
582
+ %
583
+ % - padding(+PaddingScheme)
584
+ % Padding scheme to use. Default is `pkcs1`. Alternatives
585
+ % are `pkcs1_oaep`, `sslv23` and `none`. Note that `none` should
586
+ % only be used if you implement cryptographically sound padding
587
+ % modes in your application code as encrypting unpadded data with
588
+ % RSA is insecure
589
+ %
590
+ % @see load_private_key/3, load_public_key/2 can be use to load
591
+ % keys from a file. The predicate load_certificate/2 can be used
592
+ % to obtain the public key from a certificate.
593
+ %
594
+ % @error ssl_error(Code, LibName, FuncName, Reason) is raised if
595
+ % there is an error, e.g., if the text is too long for the key.
596
+
597
+ %! rsa_sign(+Key, +Data, -Signature, +Options) is det.
598
+ %
599
+ % Create an RSA signature for Data with private key Key. Options:
600
+ %
601
+ % - type(+Type)
602
+ % SHA algorithm used to compute the digest. Values are
603
+ % `sha1`, `sha224`, `sha256`, `sha384` or `sha512`. The
604
+ % default is a cryptographically secure algorithm. If you
605
+ % specify a variable, then it is unified with the algorithm that
606
+ % was used.
607
+ %
608
+ % - encoding(+Encoding)
609
+ % Encoding to use for Data. Default is `hex`. Alternatives
610
+ % are `octet`, `utf8` and `text`.
611
+ %
612
+ % This predicate can be used to compute a =|sha256WithRSAEncryption|=
613
+ % signature as follows:
614
+ %
615
+ % ```
616
+ % sha256_with_rsa(PemKeyFile, Password, Data, Signature) :-
617
+ % Algorithm = sha256,
618
+ % read_key(PemKeyFile, Password, Key),
619
+ % crypto_data_hash(Data, Hash, [algorithm(Algorithm),
620
+ % encoding(octet)]),
621
+ % rsa_sign(Key, Hash, Signature, [type(Algorithm)]).
622
+ %
623
+ % read_key(File, Password, Key) :-
624
+ % setup_call_cleanup(
625
+ % open(File, read, In, [type(binary)]),
626
+ % load_private_key(In, Password, Key),
627
+ % close(In)).
628
+ % ```
629
+ %
630
+ % Note that a hash that is computed by crypto_data_hash/3 can be
631
+ % directly used in rsa_sign/4 as well as ecdsa_sign/4.
632
+
633
+ rsa_sign(Key, Data0, Signature, Options0) :-
634
+ functor_hash_options(type, Type, Options0, Options),
635
+ option(encoding(Enc0), Options, hex),
636
+ hex_encoding(Enc0, Data0, Enc, Data),
637
+ rsa_sign(Key, Type, Enc, Data, Signature).
638
+
639
+
640
+ %! rsa_verify(+Key, +Data, +Signature, +Options) is semidet.
641
+ %
642
+ % Verify an RSA signature for Data with public key Key.
643
+ %
644
+ % Options:
645
+ %
646
+ % - type(+Type)
647
+ % SHA algorithm used to compute the digest. Values are `sha1`,
648
+ % `sha224`, `sha256`, `sha384` or `sha512`. The default is the
649
+ % same as for rsa_sign/4. This option must match the algorithm
650
+ % that was used for signing. When operating with different parties,
651
+ % the used algorithm must be communicated over an authenticated
652
+ % channel.
653
+ %
654
+ % - encoding(+Encoding)
655
+ % Encoding to use for Data. Default is `hex`. Alternatives
656
+ % are `octet`, `utf8` and `text`.
657
+
658
+ rsa_verify(Key, Data0, Signature0, Options0) :-
659
+ functor_hash_options(type, Type, Options0, Options),
660
+ option(encoding(Enc0), Options, hex),
661
+ hex_encoding(Enc0, Data0, Enc, Data),
662
+ hex_bytes(Signature0, Signature),
663
+ rsa_verify(Key, Type, Enc, Data, Signature).
664
+
665
+ %! crypto_data_decrypt(+CipherText,
666
+ %! +Algorithm,
667
+ %! +Key,
668
+ %! +IV,
669
+ %! -PlainText,
670
+ %! +Options).
671
+ %
672
+ % Decrypt the given CipherText, using the symmetric algorithm
673
+ % Algorithm, key Key, and initialization vector IV, to give PlainText.
674
+ % CipherText must be a string, atom or list of codes or characters,
675
+ % and PlainText is created as a string. Key and IV are typically
676
+ % lists of _bytes_, though atoms and strings are also permitted.
677
+ % Algorithm must be an algorithm which your copy of OpenSSL knows. See
678
+ % crypto_data_encrypt/6 for an example.
679
+ %
680
+ % - encoding(+Encoding)
681
+ % Encoding to use for CipherText. Default is `utf8`.
682
+ % Alternatives are `utf8` and `octet`.
683
+ %
684
+ % - padding(+PaddingScheme)
685
+ % For block ciphers, the padding scheme to use. Default is
686
+ % `block`. You can disable padding by supplying `none` here.
687
+ %
688
+ % - tag(+Tag)
689
+ % For authenticated encryption schemes, the tag must be specified as
690
+ % a list of bytes exactly as they were generated upon encryption.
691
+ % This option requires OpenSSL 1.1.0 or greater.
692
+ %
693
+ % - min_tag_length(+Length)
694
+ % If the tag length is smaller than 16, this option must be used
695
+ % to permit such shorter tags. This is used as a safeguard against
696
+ % truncation attacks, where an attacker provides a short tag that
697
+ % is easier to guess.
698
+
699
+ crypto_data_decrypt(CipherText, Algorithm, Key, IV, PlainText, Options) :-
700
+ ( option(tag(Tag), Options) ->
701
+ option(min_tag_length(MinTagLength), Options, 16),
702
+ length(Tag, TagLength),
703
+ compare(C, TagLength, MinTagLength),
704
+ tag_length_ok(C, Tag)
705
+ ; Tag = []
706
+ ),
707
+ '_crypto_data_decrypt'(CipherText, Algorithm, Key, IV,
708
+ Tag, PlainText, Options).
709
+
710
+ % This test is important to prevent truncation attacks of the tag.
711
+
712
+ tag_length_ok(=, _).
713
+ tag_length_ok(>, _).
714
+ tag_length_ok(<, Tag) :- domain_error(tag_is_too_short, Tag).
715
+
716
+
717
+ %! crypto_data_encrypt(+PlainText,
718
+ %! +Algorithm,
719
+ %! +Key,
720
+ %! +IV,
721
+ %! -CipherText,
722
+ %! +Options).
723
+ %
724
+ % Encrypt the given PlainText, using the symmetric algorithm
725
+ % Algorithm, key Key, and initialization vector (or nonce) IV, to give
726
+ % CipherText.
727
+ %
728
+ % PlainText must be a string, atom or list of codes or characters, and
729
+ % CipherText is created as a string. Key and IV are typically lists
730
+ % of _bytes_, though atoms and strings are also permitted. Algorithm
731
+ % must be an algorithm which your copy of OpenSSL knows
732
+ % about.
733
+ %
734
+ % Keys and IVs can be chosen at random (using for example
735
+ % crypto_n_random_bytes/2) or derived from input keying material (IKM)
736
+ % using for example crypto_data_hkdf/4. This input is often a shared
737
+ % secret, such as a negotiated point on an elliptic curve, or the hash
738
+ % that was computed from a password via crypto_password_hash/3 with a
739
+ % freshly generated and specified _salt_.
740
+ %
741
+ % Reusing the same combination of Key and IV typically leaks at least
742
+ % _some_ information about the plaintext. For example, identical
743
+ % plaintexts will then correspond to identical ciphertexts. For some
744
+ % algorithms, reusing an IV with the same Key has disastrous results
745
+ % and can cause the loss of all properties that are otherwise
746
+ % guaranteed. Especially in such cases, an IV is also called a
747
+ % _nonce_ (number used once). If an IV is not needed for your
748
+ % algorithm (such as =|'aes-128-ecb'|=) then any value can be provided
749
+ % as it will be ignored by the underlying implementation. Note that
750
+ % such algorithms do not provide _semantic security_ and are thus
751
+ % insecure. You should use stronger algorithms instead.
752
+ %
753
+ % It is safe to store and transfer the used initialization vector (or
754
+ % nonce) in plain text, but the key _must be kept secret_.
755
+ %
756
+ % Commonly used algorithms include:
757
+ %
758
+ % $ =|'chacha20-poly1305'|= :
759
+ % A powerful and efficient _authenticated_ encryption scheme,
760
+ % providing secrecy and at the same time reliable protection
761
+ % against undetected _modifications_ of the encrypted data. This
762
+ % is a very good choice for virtually all use cases. It is a
763
+ % _stream cipher_ and can encrypt data of any length up to 256 GB.
764
+ % Further, the encrypted data has exactly the same length
765
+ % as the original, and no padding is used. It requires OpenSSL
766
+ % 1.1.0 or greater. See below for an example.
767
+ %
768
+ % $ =|'aes-128-gcm'|= :
769
+ % Also an authenticated encryption scheme. It uses a 128-bit
770
+ % (i.e., 16 bytes) key and a 96-bit (i.e., 12 bytes) nonce. It
771
+ % requires OpenSSL 1.1.0 or greater.
772
+ %
773
+ % $ =|'aes-128-cbc'|= :
774
+ % A _block cipher_ that provides secrecy, but does not protect
775
+ % against unintended modifications of the cipher text. This
776
+ % algorithm uses 128-bit (16 bytes) keys and initialization
777
+ % vectors. It works with all supported versions of OpenSSL. If
778
+ % possible, consider using an authenticated encryption scheme
779
+ % instead.
780
+ %
781
+ % Options:
782
+ %
783
+ % - encoding(+Encoding)
784
+ % Encoding to use for PlainText. Default is `utf8`. Alternatives
785
+ % are `utf8` and `octet`.
786
+ %
787
+ % - padding(+PaddingScheme)
788
+ % For block ciphers, the padding scheme to use. Default is
789
+ % `block`. You can disable padding by supplying `none` here. If
790
+ % padding is disabled for block ciphers, then the length of the
791
+ % ciphertext must be a multiple of the block size.
792
+ %
793
+ % - tag(-List)
794
+ % For authenticated encryption schemes, List is unified with a
795
+ % list of _bytes_ holding the tag. This tag must be provided for
796
+ % decryption. Authenticated encryption requires OpenSSL 1.1.0 or
797
+ % greater.
798
+ %
799
+ % - tag_length(+Length)
800
+ % For authenticated encryption schemes, the desired length of the
801
+ % tag, specified as the number of bytes. The default is
802
+ % 16. Smaller numbers are not recommended.
803
+ %
804
+ % For example, with OpenSSL 1.1.0 and greater, we can use the ChaCha20
805
+ % stream cipher with the Poly1305 authenticator. This cipher uses a
806
+ % 256-bit key and a 96-bit _nonce_, i.e., 32 and 12 _bytes_,
807
+ % respectively:
808
+ %
809
+ % ```
810
+ % ?- Algorithm = 'chacha20-poly1305',
811
+ % crypto_n_random_bytes(32, Key),
812
+ % crypto_n_random_bytes(12, IV),
813
+ % crypto_data_encrypt("this is some input", Algorithm,
814
+ % Key, IV, CipherText, [tag(Tag)]),
815
+ % crypto_data_decrypt(CipherText, Algorithm,
816
+ % Key, IV, RecoveredText, [tag(Tag)]).
817
+ % Algorithm = 'chacha20-poly1305',
818
+ % Key = [65, 147, 140, 197, 27, 60, 198, 50, 218|...],
819
+ % IV = [253, 232, 174, 84, 168, 208, 218, 168, 228|...],
820
+ % CipherText = <binary string>,
821
+ % Tag = [248, 220, 46, 62, 255, 9, 178, 130, 250|...],
822
+ % RecoveredText = "this is some input".
823
+ % ```
824
+ %
825
+ % In this example, we use crypto_n_random_bytes/2 to generate a key
826
+ % and nonce from cryptographically secure random numbers. For
827
+ % repeated applications, you must ensure that a nonce is only used
828
+ % _once_ together with the same key. Note that for _authenticated_
829
+ % encryption schemes, the _tag_ that was computed during encryption is
830
+ % necessary for decryption. It is safe to store and transfer the tag
831
+ % in plain text.
832
+ %
833
+ % @see crypto_data_decrypt/6.
834
+ % @see hex_bytes/2 for conversion between bytes and hex encoding.
835
+
836
+ crypto_data_encrypt(PlainText, Algorithm, Key, IV, CipherText, Options) :-
837
+ ( option(tag(AuthTag), Options) ->
838
+ option(tag_length(AuthLength), Options, 16)
839
+ ; AuthTag = _,
840
+ AuthLength = -1
841
+ ),
842
+ '_crypto_data_encrypt'(PlainText, Algorithm, Key, IV,
843
+ AuthLength, AuthTag, CipherText, Options).
844
+
845
+
846
+ %% crypto_modular_inverse(+X, +M, -Y) is det
847
+ %
848
+ % Compute the modular multiplicative inverse of the integer X. Y is
849
+ % unified with an integer such that X*Y is congruent to 1 modulo M.
850
+
851
+
852
+ crypto_modular_inverse(X, M, Y) :-
853
+ integer_serialized(X, XS),
854
+ integer_serialized(M, MS),
855
+ '_crypto_modular_inverse'(XS, MS, YHex),
856
+ hex_to_integer(YHex, Y).
857
+
858
+ integer_serialized(I, serialized(S)) :-
859
+ must_be(integer, I),
860
+ integer_atomic_sign(I, Sign),
861
+ Abs is abs(I),
862
+ format(atom(A0), "~16r", [Abs]),
863
+ atom_length(A0, L),
864
+ Rem is L mod 2,
865
+ hex_pad(Rem, Sign, A0, S).
866
+
867
+ integer_atomic_sign(I, S) :-
868
+ Sign is sign(I),
869
+ sign_atom(Sign, S).
870
+
871
+ sign_atom(-1, '-').
872
+ sign_atom( 0, '').
873
+ sign_atom( 1, '').
874
+
875
+ hex_pad(0, Sign, A0, A) :- atom_concat(Sign, A0, A).
876
+ hex_pad(1, Sign, A0, A) :- atomic_list_concat([Sign,'0',A0], A).
877
+
878
+ pow256(Byte, N0-I0, N-I) :-
879
+ N is N0 + Byte*256^I0,
880
+ I is I0 + 1.
881
+
882
+ hex_to_integer(Hex, N) :-
883
+ hex_bytes(Hex, Bytes0),
884
+ reverse(Bytes0, Bytes),
885
+ foldl(pow256, Bytes, 0-0, N-_).
886
+
887
+ %% crypto_generate_prime(+N, -P, +Options) is det
888
+ %
889
+ % Generate a prime P with at least N bits. Options is a list of options.
890
+ % Currently, the only supported option is:
891
+ %
892
+ % * safe(Boolean)
893
+ % If `Boolean` is `true` (default is `false`), then a _safe_ prime
894
+ % is generated. This means that P is of the form 2*Q + 1 where Q
895
+ % is also prime.
896
+
897
+ crypto_generate_prime(Bits, P, Options) :-
898
+ must_be(list, Options),
899
+ option(safe(Safe), Options, false),
900
+ '_crypto_generate_prime'(Bits, Hex, Safe, Options),
901
+ hex_to_integer(Hex, P).
902
+
903
+ %% crypto_is_prime(+P, +Options) is semidet
904
+ %
905
+ % True iff P passes a probabilistic primality test. Options is a
906
+ % list of options. Currently, the only supported option is:
907
+ %
908
+ % * iterations(N)
909
+ % N is the number of iterations that are performed. If this option
910
+ % is not specified, a number of iterations is used such that the
911
+ % probability of a false positive is at most 2^(-80).
912
+
913
+ crypto_is_prime(P0, Options) :-
914
+ must_be(integer, P0),
915
+ must_be(list, Options),
916
+ option(iterations(N), Options, -1),
917
+ integer_serialized(P0, P),
918
+ '_crypto_is_prime'(P, N).
919
+
920
+ %% crypto_name_curve(+Name, -Curve) is det
921
+ %
922
+ % Obtain a handle for a _named_ elliptic curve. Name is an atom, and
923
+ % Curve is unified with an opaque object that represents the curve.
924
+ % Currently, only elliptic curves over prime fields are
925
+ % supported. Examples of such curves are `prime256v1` and
926
+ % `secp256k1`.
927
+ %
928
+ % If you have OpenSSL installed, you can get a list of supported
929
+ % curves via:
930
+ %
931
+ % ==
932
+ % $ openssl ecparam -list_curves
933
+ % ==
934
+
935
+ %% crypto_curve_order(+Curve, -Order) is det
936
+ %
937
+ % Obtain the order of an elliptic curve. Order is an integer,
938
+ % denoting how many points on the curve can be reached by
939
+ % multiplying the curve's generator with a scalar.
940
+
941
+ crypto_curve_order(Curve, Order) :-
942
+ '_crypto_curve_order'(Curve, Hex),
943
+ hex_to_integer(Hex, Order).
944
+
945
+
946
+ %% crypto_curve_generator(+Curve, -Point) is det
947
+ %
948
+ % Point is the _generator_ of the elliptic curve Curve.
949
+
950
+ crypto_curve_generator(Curve, point(X,Y)) :-
951
+ '_crypto_curve_generator'(Curve, X0, Y0),
952
+ hex_to_integer(X0, X),
953
+ hex_to_integer(Y0, Y).
954
+
955
+ %% crypto_curve_scalar_mult(+Curve, +N, +Point, -R) is det
956
+ %
957
+ % R is the result of N times Point on the elliptic curve Curve. N
958
+ % must be an integer, and Point must be a point on the curve.
959
+
960
+ crypto_curve_scalar_mult(Curve, S0, point(X0,Y0), point(A,B)) :-
961
+ maplist(integer_serialized, [S0,X0,Y0], [S,X,Y]),
962
+ '_crypto_curve_scalar_mult'(Curve, S, X, Y, A0, B0),
963
+ hex_to_integer(A0, A),
964
+ hex_to_integer(B0, B).
965
+
966
+
967
+ /*******************************
968
+ * Sandboxing *
969
+ *******************************/
970
+
971
+ :- multifile sandbox:safe_primitive/1.
972
+
973
+ sandbox:safe_primitive(crypto:hex_bytes(_,_)).
974
+ sandbox:safe_primitive(crypto:crypto_n_random_bytes(_,_)).
975
+
976
+ sandbox:safe_primitive(crypto:crypto_data_hash(_,_,_)).
977
+ sandbox:safe_primitive(crypto:crypto_data_context(_,_,_)).
978
+ sandbox:safe_primitive(crypto:crypto_context_new(_,_)).
979
+ sandbox:safe_primitive(crypto:crypto_context_hash(_,_)).
980
+
981
+ sandbox:safe_primitive(crypto:crypto_password_hash(_,_)).
982
+ sandbox:safe_primitive(crypto:crypto_password_hash(_,_,_)).
983
+ sandbox:safe_primitive(crypto:crypto_data_hkdf(_,_,_,_)).
984
+
985
+ sandbox:safe_primitive(crypto:ecdsa_sign(_,_,_,_)).
986
+ sandbox:safe_primitive(crypto:ecdsa_verify(_,_,_,_)).
987
+
988
+ sandbox:safe_primitive(crypto:rsa_sign(_,_,_,_)).
989
+ sandbox:safe_primitive(crypto:rsa_verify(_,_,_,_)).
990
+ sandbox:safe_primitive(crypto:rsa_public_encrypt(_,_,_,_)).
991
+ sandbox:safe_primitive(crypto:rsa_public_decrypt(_,_,_,_)).
992
+ sandbox:safe_primitive(crypto:rsa_private_encrypt(_,_,_,_)).
993
+ sandbox:safe_primitive(crypto:rsa_private_decrypt(_,_,_,_)).
994
+
995
+ sandbox:safe_primitive(crypto:crypto_data_decrypt(_,_,_,_,_,_)).
996
+ sandbox:safe_primitive(crypto:crypto_data_encrypt(_,_,_,_,_,_)).
997
+
998
+ sandbox:safe_primitive(crypto:crypto_modular_inverse(_,_,_)).
999
+ sandbox:safe_primitive(crypto:crypto_generate_prime(_,_,_)).
1000
+ sandbox:safe_primitive(crypto:crypto_is_prime(_,_)).
1001
+
1002
+ sandbox:safe_primitive(crypto:crypto_name_curve(_,_)).
1003
+ sandbox:safe_primitive(crypto:crypto_curve_order(_,_)).
1004
+ sandbox:safe_primitive(crypto:crypto_curve_generator(_,_)).
1005
+ sandbox:safe_primitive(crypto:crypto_curve_scalar_mult(_,_,_,_)).
1006
+
1007
+ /*******************************
1008
+ * MESSAGES *
1009
+ *******************************/
1010
+
1011
+ :- multifile
1012
+ prolog:error_message//1.
1013
+
1014
+ prolog:error_message(ssl_error(ID, _Library, Function, Reason)) -->
1015
+ [ 'SSL(~w) ~w: ~w'-[ID, Function, Reason] ].