@fugood/llama.node 0.6.2 → 1.0.0-beta.1

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 (378) hide show
  1. package/CMakeLists.txt +40 -30
  2. package/README.md +4 -1
  3. package/lib/binding.js +41 -29
  4. package/lib/binding.ts +26 -25
  5. package/package.json +45 -10
  6. package/scripts/build.js +47 -0
  7. package/scripts/llama.cpp.patch +109 -0
  8. package/src/anyascii.c +22223 -0
  9. package/src/anyascii.h +42 -0
  10. package/src/tts_utils.cpp +20 -7
  11. package/src/tts_utils.h +2 -0
  12. package/bin/darwin/arm64/llama-node.node +0 -0
  13. package/bin/darwin/x64/llama-node.node +0 -0
  14. package/bin/linux/arm64/llama-node.node +0 -0
  15. package/bin/linux/x64/llama-node.node +0 -0
  16. package/bin/linux-cuda/arm64/llama-node.node +0 -0
  17. package/bin/linux-cuda/x64/llama-node.node +0 -0
  18. package/bin/linux-vulkan/arm64/llama-node.node +0 -0
  19. package/bin/linux-vulkan/x64/llama-node.node +0 -0
  20. package/bin/win32/x64/llama-node.node +0 -0
  21. package/bin/win32/x64/node.lib +0 -0
  22. package/bin/win32-vulkan/arm64/llama-node.node +0 -0
  23. package/bin/win32-vulkan/arm64/node.lib +0 -0
  24. package/bin/win32-vulkan/x64/llama-node.node +0 -0
  25. package/bin/win32-vulkan/x64/node.lib +0 -0
  26. package/patches/node-api-headers+1.1.0.patch +0 -26
  27. package/src/llama.cpp/.github/workflows/build-linux-cross.yml +0 -233
  28. package/src/llama.cpp/.github/workflows/build.yml +0 -1078
  29. package/src/llama.cpp/.github/workflows/close-issue.yml +0 -28
  30. package/src/llama.cpp/.github/workflows/docker.yml +0 -178
  31. package/src/llama.cpp/.github/workflows/editorconfig.yml +0 -29
  32. package/src/llama.cpp/.github/workflows/gguf-publish.yml +0 -44
  33. package/src/llama.cpp/.github/workflows/labeler.yml +0 -17
  34. package/src/llama.cpp/.github/workflows/python-check-requirements.yml +0 -33
  35. package/src/llama.cpp/.github/workflows/python-lint.yml +0 -30
  36. package/src/llama.cpp/.github/workflows/python-type-check.yml +0 -40
  37. package/src/llama.cpp/.github/workflows/release.yml +0 -739
  38. package/src/llama.cpp/.github/workflows/server.yml +0 -237
  39. package/src/llama.cpp/.github/workflows/winget.yml +0 -42
  40. package/src/llama.cpp/cmake/arm64-apple-clang.cmake +0 -16
  41. package/src/llama.cpp/cmake/arm64-windows-llvm.cmake +0 -16
  42. package/src/llama.cpp/cmake/build-info.cmake +0 -64
  43. package/src/llama.cpp/cmake/common.cmake +0 -35
  44. package/src/llama.cpp/cmake/git-vars.cmake +0 -22
  45. package/src/llama.cpp/cmake/x64-windows-llvm.cmake +0 -5
  46. package/src/llama.cpp/common/build-info.cpp.in +0 -4
  47. package/src/llama.cpp/docs/build.md +0 -561
  48. package/src/llama.cpp/examples/CMakeLists.txt +0 -43
  49. package/src/llama.cpp/examples/batched/CMakeLists.txt +0 -5
  50. package/src/llama.cpp/examples/batched/batched.cpp +0 -246
  51. package/src/llama.cpp/examples/chat-13B.bat +0 -57
  52. package/src/llama.cpp/examples/convert-llama2c-to-ggml/CMakeLists.txt +0 -5
  53. package/src/llama.cpp/examples/convert-llama2c-to-ggml/convert-llama2c-to-ggml.cpp +0 -941
  54. package/src/llama.cpp/examples/deprecation-warning/deprecation-warning.cpp +0 -35
  55. package/src/llama.cpp/examples/embedding/CMakeLists.txt +0 -5
  56. package/src/llama.cpp/examples/embedding/embedding.cpp +0 -323
  57. package/src/llama.cpp/examples/eval-callback/CMakeLists.txt +0 -10
  58. package/src/llama.cpp/examples/eval-callback/eval-callback.cpp +0 -194
  59. package/src/llama.cpp/examples/gen-docs/CMakeLists.txt +0 -5
  60. package/src/llama.cpp/examples/gen-docs/gen-docs.cpp +0 -83
  61. package/src/llama.cpp/examples/gguf/CMakeLists.txt +0 -5
  62. package/src/llama.cpp/examples/gguf/gguf.cpp +0 -265
  63. package/src/llama.cpp/examples/gguf-hash/CMakeLists.txt +0 -22
  64. package/src/llama.cpp/examples/gguf-hash/deps/rotate-bits/rotate-bits.h +0 -46
  65. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.c +0 -295
  66. package/src/llama.cpp/examples/gguf-hash/deps/sha1/sha1.h +0 -52
  67. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.c +0 -221
  68. package/src/llama.cpp/examples/gguf-hash/deps/sha256/sha256.h +0 -24
  69. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.c +0 -42
  70. package/src/llama.cpp/examples/gguf-hash/deps/xxhash/xxhash.h +0 -7093
  71. package/src/llama.cpp/examples/gguf-hash/gguf-hash.cpp +0 -694
  72. package/src/llama.cpp/examples/gritlm/CMakeLists.txt +0 -5
  73. package/src/llama.cpp/examples/gritlm/gritlm.cpp +0 -229
  74. package/src/llama.cpp/examples/jeopardy/questions.txt +0 -100
  75. package/src/llama.cpp/examples/llama.android/app/build.gradle.kts +0 -65
  76. package/src/llama.cpp/examples/llama.android/build.gradle.kts +0 -6
  77. package/src/llama.cpp/examples/llama.android/llama/build.gradle.kts +0 -71
  78. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/CMakeLists.txt +0 -53
  79. package/src/llama.cpp/examples/llama.android/llama/src/main/cpp/llama-android.cpp +0 -452
  80. package/src/llama.cpp/examples/llama.android/settings.gradle.kts +0 -18
  81. package/src/llama.cpp/examples/lookahead/CMakeLists.txt +0 -5
  82. package/src/llama.cpp/examples/lookahead/lookahead.cpp +0 -472
  83. package/src/llama.cpp/examples/lookup/CMakeLists.txt +0 -23
  84. package/src/llama.cpp/examples/lookup/lookup-create.cpp +0 -40
  85. package/src/llama.cpp/examples/lookup/lookup-merge.cpp +0 -47
  86. package/src/llama.cpp/examples/lookup/lookup-stats.cpp +0 -157
  87. package/src/llama.cpp/examples/lookup/lookup.cpp +0 -242
  88. package/src/llama.cpp/examples/parallel/CMakeLists.txt +0 -5
  89. package/src/llama.cpp/examples/parallel/parallel.cpp +0 -492
  90. package/src/llama.cpp/examples/passkey/CMakeLists.txt +0 -5
  91. package/src/llama.cpp/examples/passkey/passkey.cpp +0 -277
  92. package/src/llama.cpp/examples/retrieval/CMakeLists.txt +0 -5
  93. package/src/llama.cpp/examples/retrieval/retrieval.cpp +0 -304
  94. package/src/llama.cpp/examples/save-load-state/CMakeLists.txt +0 -5
  95. package/src/llama.cpp/examples/save-load-state/save-load-state.cpp +0 -246
  96. package/src/llama.cpp/examples/simple/CMakeLists.txt +0 -5
  97. package/src/llama.cpp/examples/simple/simple.cpp +0 -206
  98. package/src/llama.cpp/examples/simple-chat/CMakeLists.txt +0 -5
  99. package/src/llama.cpp/examples/simple-chat/simple-chat.cpp +0 -206
  100. package/src/llama.cpp/examples/simple-cmake-pkg/CMakeLists.txt +0 -11
  101. package/src/llama.cpp/examples/speculative/CMakeLists.txt +0 -5
  102. package/src/llama.cpp/examples/speculative/speculative.cpp +0 -644
  103. package/src/llama.cpp/examples/speculative-simple/CMakeLists.txt +0 -5
  104. package/src/llama.cpp/examples/speculative-simple/speculative-simple.cpp +0 -261
  105. package/src/llama.cpp/examples/sycl/CMakeLists.txt +0 -9
  106. package/src/llama.cpp/examples/sycl/build.sh +0 -23
  107. package/src/llama.cpp/examples/sycl/ls-sycl-device.cpp +0 -13
  108. package/src/llama.cpp/examples/sycl/run-llama2.sh +0 -27
  109. package/src/llama.cpp/examples/sycl/run-llama3.sh +0 -28
  110. package/src/llama.cpp/examples/sycl/win-build-sycl.bat +0 -33
  111. package/src/llama.cpp/examples/sycl/win-run-llama2.bat +0 -9
  112. package/src/llama.cpp/examples/sycl/win-run-llama3.bat +0 -9
  113. package/src/llama.cpp/examples/training/CMakeLists.txt +0 -5
  114. package/src/llama.cpp/examples/training/finetune.cpp +0 -96
  115. package/src/llama.cpp/ggml/cmake/GitVars.cmake +0 -22
  116. package/src/llama.cpp/ggml/cmake/common.cmake +0 -26
  117. package/src/llama.cpp/ggml/src/ggml-alloc.c +0 -1042
  118. package/src/llama.cpp/ggml/src/ggml-backend-impl.h +0 -255
  119. package/src/llama.cpp/ggml/src/ggml-backend-reg.cpp +0 -586
  120. package/src/llama.cpp/ggml/src/ggml-backend.cpp +0 -2008
  121. package/src/llama.cpp/ggml/src/ggml-blas/CMakeLists.txt +0 -87
  122. package/src/llama.cpp/ggml/src/ggml-blas/ggml-blas.cpp +0 -517
  123. package/src/llama.cpp/ggml/src/ggml-cann/CMakeLists.txt +0 -74
  124. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.cpp +0 -179
  125. package/src/llama.cpp/ggml/src/ggml-cann/acl_tensor.h +0 -258
  126. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.cpp +0 -2863
  127. package/src/llama.cpp/ggml/src/ggml-cann/aclnn_ops.h +0 -1110
  128. package/src/llama.cpp/ggml/src/ggml-cann/common.h +0 -420
  129. package/src/llama.cpp/ggml/src/ggml-cann/ggml-cann.cpp +0 -2570
  130. package/src/llama.cpp/ggml/src/ggml-common.h +0 -1857
  131. package/src/llama.cpp/ggml/src/ggml-cpu/cmake/FindSIMD.cmake +0 -100
  132. package/src/llama.cpp/ggml/src/ggml-cuda/CMakeLists.txt +0 -184
  133. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/cuda.h +0 -15
  134. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/hip.h +0 -243
  135. package/src/llama.cpp/ggml/src/ggml-cuda/vendors/musa.h +0 -140
  136. package/src/llama.cpp/ggml/src/ggml-hip/CMakeLists.txt +0 -131
  137. package/src/llama.cpp/ggml/src/ggml-impl.h +0 -601
  138. package/src/llama.cpp/ggml/src/ggml-kompute/CMakeLists.txt +0 -166
  139. package/src/llama.cpp/ggml/src/ggml-kompute/ggml-kompute.cpp +0 -2251
  140. package/src/llama.cpp/ggml/src/ggml-metal/CMakeLists.txt +0 -120
  141. package/src/llama.cpp/ggml/src/ggml-metal/ggml-metal-impl.h +0 -622
  142. package/src/llama.cpp/ggml/src/ggml-musa/CMakeLists.txt +0 -113
  143. package/src/llama.cpp/ggml/src/ggml-opencl/CMakeLists.txt +0 -96
  144. package/src/llama.cpp/ggml/src/ggml-opencl/ggml-opencl.cpp +0 -5124
  145. package/src/llama.cpp/ggml/src/ggml-opt.cpp +0 -1037
  146. package/src/llama.cpp/ggml/src/ggml-quants.c +0 -5232
  147. package/src/llama.cpp/ggml/src/ggml-quants.h +0 -100
  148. package/src/llama.cpp/ggml/src/ggml-rpc/CMakeLists.txt +0 -9
  149. package/src/llama.cpp/ggml/src/ggml-rpc/ggml-rpc.cpp +0 -1813
  150. package/src/llama.cpp/ggml/src/ggml-sycl/CMakeLists.txt +0 -189
  151. package/src/llama.cpp/ggml/src/ggml-sycl/backend.hpp +0 -37
  152. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.cpp +0 -239
  153. package/src/llama.cpp/ggml/src/ggml-sycl/binbcast.hpp +0 -39
  154. package/src/llama.cpp/ggml/src/ggml-sycl/common.cpp +0 -83
  155. package/src/llama.cpp/ggml/src/ggml-sycl/common.hpp +0 -493
  156. package/src/llama.cpp/ggml/src/ggml-sycl/concat.cpp +0 -197
  157. package/src/llama.cpp/ggml/src/ggml-sycl/concat.hpp +0 -20
  158. package/src/llama.cpp/ggml/src/ggml-sycl/conv.cpp +0 -100
  159. package/src/llama.cpp/ggml/src/ggml-sycl/conv.hpp +0 -20
  160. package/src/llama.cpp/ggml/src/ggml-sycl/convert.cpp +0 -623
  161. package/src/llama.cpp/ggml/src/ggml-sycl/convert.hpp +0 -34
  162. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.cpp +0 -701
  163. package/src/llama.cpp/ggml/src/ggml-sycl/cpy.hpp +0 -11
  164. package/src/llama.cpp/ggml/src/ggml-sycl/dequantize.hpp +0 -791
  165. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.cpp +0 -1160
  166. package/src/llama.cpp/ggml/src/ggml-sycl/dmmv.hpp +0 -27
  167. package/src/llama.cpp/ggml/src/ggml-sycl/dpct/helper.hpp +0 -2957
  168. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.cpp +0 -1536
  169. package/src/llama.cpp/ggml/src/ggml-sycl/element_wise.hpp +0 -75
  170. package/src/llama.cpp/ggml/src/ggml-sycl/gemm.hpp +0 -99
  171. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.cpp +0 -311
  172. package/src/llama.cpp/ggml/src/ggml-sycl/getrows.hpp +0 -20
  173. package/src/llama.cpp/ggml/src/ggml-sycl/ggml-sycl.cpp +0 -4443
  174. package/src/llama.cpp/ggml/src/ggml-sycl/gla.cpp +0 -105
  175. package/src/llama.cpp/ggml/src/ggml-sycl/gla.hpp +0 -8
  176. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.cpp +0 -136
  177. package/src/llama.cpp/ggml/src/ggml-sycl/im2col.hpp +0 -21
  178. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.cpp +0 -3030
  179. package/src/llama.cpp/ggml/src/ggml-sycl/mmq.hpp +0 -33
  180. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.cpp +0 -1108
  181. package/src/llama.cpp/ggml/src/ggml-sycl/mmvq.hpp +0 -27
  182. package/src/llama.cpp/ggml/src/ggml-sycl/norm.cpp +0 -474
  183. package/src/llama.cpp/ggml/src/ggml-sycl/norm.hpp +0 -26
  184. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.cpp +0 -46
  185. package/src/llama.cpp/ggml/src/ggml-sycl/outprod.hpp +0 -10
  186. package/src/llama.cpp/ggml/src/ggml-sycl/presets.hpp +0 -74
  187. package/src/llama.cpp/ggml/src/ggml-sycl/quants.hpp +0 -83
  188. package/src/llama.cpp/ggml/src/ggml-sycl/rope.cpp +0 -362
  189. package/src/llama.cpp/ggml/src/ggml-sycl/rope.hpp +0 -20
  190. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.cpp +0 -264
  191. package/src/llama.cpp/ggml/src/ggml-sycl/softmax.hpp +0 -20
  192. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.cpp +0 -13
  193. package/src/llama.cpp/ggml/src/ggml-sycl/sycl_hw.hpp +0 -23
  194. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.cpp +0 -73
  195. package/src/llama.cpp/ggml/src/ggml-sycl/tsembd.hpp +0 -20
  196. package/src/llama.cpp/ggml/src/ggml-sycl/vecdotq.hpp +0 -1215
  197. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.cpp +0 -305
  198. package/src/llama.cpp/ggml/src/ggml-sycl/wkv.hpp +0 -10
  199. package/src/llama.cpp/ggml/src/ggml-threading.cpp +0 -12
  200. package/src/llama.cpp/ggml/src/ggml-threading.h +0 -14
  201. package/src/llama.cpp/ggml/src/ggml-vulkan/CMakeLists.txt +0 -196
  202. package/src/llama.cpp/ggml/src/ggml-vulkan/ggml-vulkan.cpp +0 -10699
  203. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/CMakeLists.txt +0 -39
  204. package/src/llama.cpp/ggml/src/ggml-vulkan/vulkan-shaders/vulkan-shaders-gen.cpp +0 -751
  205. package/src/llama.cpp/ggml/src/ggml.c +0 -6550
  206. package/src/llama.cpp/ggml/src/gguf.cpp +0 -1330
  207. package/src/llama.cpp/models/.editorconfig +0 -1
  208. package/src/llama.cpp/models/ggml-vocab-aquila.gguf +0 -0
  209. package/src/llama.cpp/models/ggml-vocab-baichuan.gguf +0 -0
  210. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf +0 -0
  211. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.inp +0 -112
  212. package/src/llama.cpp/models/ggml-vocab-bert-bge.gguf.out +0 -46
  213. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.inp +0 -112
  214. package/src/llama.cpp/models/ggml-vocab-chameleon.gguf.out +0 -46
  215. package/src/llama.cpp/models/ggml-vocab-command-r.gguf +0 -0
  216. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.inp +0 -112
  217. package/src/llama.cpp/models/ggml-vocab-command-r.gguf.out +0 -46
  218. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf +0 -0
  219. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.inp +0 -112
  220. package/src/llama.cpp/models/ggml-vocab-deepseek-coder.gguf.out +0 -46
  221. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf +0 -0
  222. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.inp +0 -112
  223. package/src/llama.cpp/models/ggml-vocab-deepseek-llm.gguf.out +0 -46
  224. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.inp +0 -112
  225. package/src/llama.cpp/models/ggml-vocab-deepseek-r1-qwen.gguf.out +0 -46
  226. package/src/llama.cpp/models/ggml-vocab-falcon.gguf +0 -0
  227. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.inp +0 -112
  228. package/src/llama.cpp/models/ggml-vocab-falcon.gguf.out +0 -46
  229. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf +0 -0
  230. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.inp +0 -112
  231. package/src/llama.cpp/models/ggml-vocab-gpt-2.gguf.out +0 -46
  232. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.inp +0 -112
  233. package/src/llama.cpp/models/ggml-vocab-gpt-4o.gguf.out +0 -46
  234. package/src/llama.cpp/models/ggml-vocab-gpt-neox.gguf +0 -0
  235. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf +0 -0
  236. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.inp +0 -112
  237. package/src/llama.cpp/models/ggml-vocab-llama-bpe.gguf.out +0 -46
  238. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf +0 -0
  239. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.inp +0 -112
  240. package/src/llama.cpp/models/ggml-vocab-llama-spm.gguf.out +0 -46
  241. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.inp +0 -112
  242. package/src/llama.cpp/models/ggml-vocab-llama4.gguf.out +0 -46
  243. package/src/llama.cpp/models/ggml-vocab-mpt.gguf +0 -0
  244. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.inp +0 -112
  245. package/src/llama.cpp/models/ggml-vocab-mpt.gguf.out +0 -46
  246. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf +0 -0
  247. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.inp +0 -112
  248. package/src/llama.cpp/models/ggml-vocab-phi-3.gguf.out +0 -46
  249. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.inp +0 -112
  250. package/src/llama.cpp/models/ggml-vocab-pixtral.gguf.out +0 -46
  251. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf +0 -0
  252. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.inp +0 -112
  253. package/src/llama.cpp/models/ggml-vocab-qwen2.gguf.out +0 -46
  254. package/src/llama.cpp/models/ggml-vocab-refact.gguf +0 -0
  255. package/src/llama.cpp/models/ggml-vocab-refact.gguf.inp +0 -112
  256. package/src/llama.cpp/models/ggml-vocab-refact.gguf.out +0 -46
  257. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.inp +0 -112
  258. package/src/llama.cpp/models/ggml-vocab-roberta-bpe.gguf.out +0 -46
  259. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf +0 -0
  260. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.inp +0 -112
  261. package/src/llama.cpp/models/ggml-vocab-starcoder.gguf.out +0 -46
  262. package/src/llama.cpp/pocs/CMakeLists.txt +0 -14
  263. package/src/llama.cpp/pocs/vdot/CMakeLists.txt +0 -9
  264. package/src/llama.cpp/pocs/vdot/q8dot.cpp +0 -173
  265. package/src/llama.cpp/pocs/vdot/vdot.cpp +0 -311
  266. package/src/llama.cpp/prompts/LLM-questions.txt +0 -49
  267. package/src/llama.cpp/prompts/alpaca.txt +0 -1
  268. package/src/llama.cpp/prompts/assistant.txt +0 -31
  269. package/src/llama.cpp/prompts/chat-with-baichuan.txt +0 -4
  270. package/src/llama.cpp/prompts/chat-with-bob.txt +0 -7
  271. package/src/llama.cpp/prompts/chat-with-qwen.txt +0 -1
  272. package/src/llama.cpp/prompts/chat-with-vicuna-v0.txt +0 -7
  273. package/src/llama.cpp/prompts/chat-with-vicuna-v1.txt +0 -7
  274. package/src/llama.cpp/prompts/chat.txt +0 -28
  275. package/src/llama.cpp/prompts/dan-modified.txt +0 -1
  276. package/src/llama.cpp/prompts/dan.txt +0 -1
  277. package/src/llama.cpp/prompts/mnemonics.txt +0 -93
  278. package/src/llama.cpp/prompts/parallel-questions.txt +0 -43
  279. package/src/llama.cpp/prompts/reason-act.txt +0 -18
  280. package/src/llama.cpp/requirements/requirements-all.txt +0 -15
  281. package/src/llama.cpp/requirements/requirements-compare-llama-bench.txt +0 -2
  282. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf.txt +0 -7
  283. package/src/llama.cpp/requirements/requirements-convert_hf_to_gguf_update.txt +0 -7
  284. package/src/llama.cpp/requirements/requirements-convert_legacy_llama.txt +0 -5
  285. package/src/llama.cpp/requirements/requirements-convert_llama_ggml_to_gguf.txt +0 -1
  286. package/src/llama.cpp/requirements/requirements-convert_lora_to_gguf.txt +0 -4
  287. package/src/llama.cpp/requirements/requirements-gguf_editor_gui.txt +0 -3
  288. package/src/llama.cpp/requirements/requirements-pydantic.txt +0 -3
  289. package/src/llama.cpp/requirements/requirements-test-tokenizer-random.txt +0 -1
  290. package/src/llama.cpp/requirements/requirements-tool_bench.txt +0 -12
  291. package/src/llama.cpp/requirements.txt +0 -13
  292. package/src/llama.cpp/scripts/build-info.sh +0 -30
  293. package/src/llama.cpp/scripts/install-oneapi.bat +0 -19
  294. package/src/llama.cpp/scripts/xxd.cmake +0 -16
  295. package/src/llama.cpp/tests/CMakeLists.txt +0 -177
  296. package/src/llama.cpp/tests/get-model.cpp +0 -21
  297. package/src/llama.cpp/tests/get-model.h +0 -2
  298. package/src/llama.cpp/tests/test-arg-parser.cpp +0 -178
  299. package/src/llama.cpp/tests/test-autorelease.cpp +0 -24
  300. package/src/llama.cpp/tests/test-backend-ops.cpp +0 -4793
  301. package/src/llama.cpp/tests/test-barrier.cpp +0 -94
  302. package/src/llama.cpp/tests/test-c.c +0 -7
  303. package/src/llama.cpp/tests/test-chat-template.cpp +0 -417
  304. package/src/llama.cpp/tests/test-chat.cpp +0 -985
  305. package/src/llama.cpp/tests/test-double-float.cpp +0 -57
  306. package/src/llama.cpp/tests/test-gbnf-validator.cpp +0 -109
  307. package/src/llama.cpp/tests/test-gguf.cpp +0 -1338
  308. package/src/llama.cpp/tests/test-grammar-integration.cpp +0 -1308
  309. package/src/llama.cpp/tests/test-grammar-llguidance.cpp +0 -1201
  310. package/src/llama.cpp/tests/test-grammar-parser.cpp +0 -519
  311. package/src/llama.cpp/tests/test-json-schema-to-grammar.cpp +0 -1304
  312. package/src/llama.cpp/tests/test-llama-grammar.cpp +0 -408
  313. package/src/llama.cpp/tests/test-log.cpp +0 -39
  314. package/src/llama.cpp/tests/test-model-load-cancel.cpp +0 -27
  315. package/src/llama.cpp/tests/test-mtmd-c-api.c +0 -63
  316. package/src/llama.cpp/tests/test-opt.cpp +0 -904
  317. package/src/llama.cpp/tests/test-quantize-fns.cpp +0 -186
  318. package/src/llama.cpp/tests/test-quantize-perf.cpp +0 -365
  319. package/src/llama.cpp/tests/test-quantize-stats.cpp +0 -424
  320. package/src/llama.cpp/tests/test-regex-partial.cpp +0 -288
  321. package/src/llama.cpp/tests/test-rope.cpp +0 -262
  322. package/src/llama.cpp/tests/test-sampling.cpp +0 -399
  323. package/src/llama.cpp/tests/test-tokenizer-0.cpp +0 -312
  324. package/src/llama.cpp/tests/test-tokenizer-1-bpe.cpp +0 -155
  325. package/src/llama.cpp/tests/test-tokenizer-1-spm.cpp +0 -125
  326. package/src/llama.cpp/tools/CMakeLists.txt +0 -39
  327. package/src/llama.cpp/tools/batched-bench/CMakeLists.txt +0 -5
  328. package/src/llama.cpp/tools/batched-bench/batched-bench.cpp +0 -204
  329. package/src/llama.cpp/tools/cvector-generator/CMakeLists.txt +0 -5
  330. package/src/llama.cpp/tools/cvector-generator/completions.txt +0 -582
  331. package/src/llama.cpp/tools/cvector-generator/cvector-generator.cpp +0 -508
  332. package/src/llama.cpp/tools/cvector-generator/mean.hpp +0 -48
  333. package/src/llama.cpp/tools/cvector-generator/negative.txt +0 -4
  334. package/src/llama.cpp/tools/cvector-generator/pca.hpp +0 -315
  335. package/src/llama.cpp/tools/cvector-generator/positive.txt +0 -4
  336. package/src/llama.cpp/tools/export-lora/CMakeLists.txt +0 -5
  337. package/src/llama.cpp/tools/export-lora/export-lora.cpp +0 -434
  338. package/src/llama.cpp/tools/gguf-split/CMakeLists.txt +0 -5
  339. package/src/llama.cpp/tools/gguf-split/gguf-split.cpp +0 -583
  340. package/src/llama.cpp/tools/imatrix/CMakeLists.txt +0 -5
  341. package/src/llama.cpp/tools/imatrix/imatrix.cpp +0 -667
  342. package/src/llama.cpp/tools/llama-bench/CMakeLists.txt +0 -5
  343. package/src/llama.cpp/tools/llama-bench/llama-bench.cpp +0 -2024
  344. package/src/llama.cpp/tools/main/CMakeLists.txt +0 -5
  345. package/src/llama.cpp/tools/main/main.cpp +0 -977
  346. package/src/llama.cpp/tools/mtmd/CMakeLists.txt +0 -58
  347. package/src/llama.cpp/tools/mtmd/clip-impl.h +0 -462
  348. package/src/llama.cpp/tools/mtmd/clip.cpp +0 -4024
  349. package/src/llama.cpp/tools/mtmd/clip.h +0 -101
  350. package/src/llama.cpp/tools/mtmd/deprecation-warning.cpp +0 -22
  351. package/src/llama.cpp/tools/mtmd/miniaudio.h +0 -93468
  352. package/src/llama.cpp/tools/mtmd/mtmd-audio.cpp +0 -855
  353. package/src/llama.cpp/tools/mtmd/mtmd-audio.h +0 -62
  354. package/src/llama.cpp/tools/mtmd/mtmd-cli.cpp +0 -377
  355. package/src/llama.cpp/tools/mtmd/mtmd-helper.cpp +0 -297
  356. package/src/llama.cpp/tools/mtmd/mtmd.cpp +0 -942
  357. package/src/llama.cpp/tools/mtmd/mtmd.h +0 -362
  358. package/src/llama.cpp/tools/mtmd/requirements.txt +0 -5
  359. package/src/llama.cpp/tools/perplexity/CMakeLists.txt +0 -5
  360. package/src/llama.cpp/tools/perplexity/perplexity.cpp +0 -2063
  361. package/src/llama.cpp/tools/quantize/CMakeLists.txt +0 -6
  362. package/src/llama.cpp/tools/quantize/quantize.cpp +0 -519
  363. package/src/llama.cpp/tools/rpc/CMakeLists.txt +0 -4
  364. package/src/llama.cpp/tools/rpc/rpc-server.cpp +0 -322
  365. package/src/llama.cpp/tools/run/CMakeLists.txt +0 -16
  366. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.cpp +0 -1995
  367. package/src/llama.cpp/tools/run/linenoise.cpp/linenoise.h +0 -137
  368. package/src/llama.cpp/tools/run/run.cpp +0 -1261
  369. package/src/llama.cpp/tools/server/CMakeLists.txt +0 -51
  370. package/src/llama.cpp/tools/server/bench/requirements.txt +0 -2
  371. package/src/llama.cpp/tools/server/httplib.h +0 -10506
  372. package/src/llama.cpp/tools/server/server.cpp +0 -4966
  373. package/src/llama.cpp/tools/server/tests/requirements.txt +0 -8
  374. package/src/llama.cpp/tools/server/utils.hpp +0 -1337
  375. package/src/llama.cpp/tools/tokenize/CMakeLists.txt +0 -5
  376. package/src/llama.cpp/tools/tokenize/tokenize.cpp +0 -416
  377. package/src/llama.cpp/tools/tts/CMakeLists.txt +0 -5
  378. package/src/llama.cpp/tools/tts/tts.cpp +0 -1092
@@ -1,265 +0,0 @@
1
- #include "ggml.h"
2
- #include "gguf.h"
3
-
4
- #include <cstdio>
5
- #include <string>
6
- #include <sstream>
7
- #include <vector>
8
-
9
- #undef MIN
10
- #undef MAX
11
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
12
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
13
-
14
- template <typename T>
15
- static std::string to_string(const T & val) {
16
- std::stringstream ss;
17
- ss << val;
18
- return ss.str();
19
- }
20
-
21
- static bool gguf_ex_write(const std::string & fname) {
22
- struct gguf_context * ctx = gguf_init_empty();
23
-
24
- gguf_set_val_u8 (ctx, "some.parameter.uint8", 0x12);
25
- gguf_set_val_i8 (ctx, "some.parameter.int8", -0x13);
26
- gguf_set_val_u16 (ctx, "some.parameter.uint16", 0x1234);
27
- gguf_set_val_i16 (ctx, "some.parameter.int16", -0x1235);
28
- gguf_set_val_u32 (ctx, "some.parameter.uint32", 0x12345678);
29
- gguf_set_val_i32 (ctx, "some.parameter.int32", -0x12345679);
30
- gguf_set_val_f32 (ctx, "some.parameter.float32", 0.123456789f);
31
- gguf_set_val_u64 (ctx, "some.parameter.uint64", 0x123456789abcdef0ull);
32
- gguf_set_val_i64 (ctx, "some.parameter.int64", -0x123456789abcdef1ll);
33
- gguf_set_val_f64 (ctx, "some.parameter.float64", 0.1234567890123456789);
34
- gguf_set_val_bool(ctx, "some.parameter.bool", true);
35
- gguf_set_val_str (ctx, "some.parameter.string", "hello world");
36
-
37
- gguf_set_arr_data(ctx, "some.parameter.arr.i16", GGUF_TYPE_INT16, std::vector<int16_t>{ 1, 2, 3, 4, }.data(), 4);
38
- gguf_set_arr_data(ctx, "some.parameter.arr.f32", GGUF_TYPE_FLOAT32, std::vector<float>{ 3.145f, 2.718f, 1.414f, }.data(), 3);
39
- gguf_set_arr_str (ctx, "some.parameter.arr.str", std::vector<const char *>{ "hello", "world", "!" }.data(), 3);
40
-
41
- struct ggml_init_params params = {
42
- /*.mem_size =*/ 128ull*1024ull*1024ull,
43
- /*.mem_buffer =*/ NULL,
44
- /*.no_alloc =*/ false,
45
- };
46
-
47
- struct ggml_context * ctx_data = ggml_init(params);
48
-
49
- const int n_tensors = 10;
50
-
51
- // tensor infos
52
- for (int i = 0; i < n_tensors; ++i) {
53
- const std::string name = "tensor_" + to_string(i);
54
-
55
- int64_t ne[GGML_MAX_DIMS] = { 1 };
56
- int32_t n_dims = rand() % GGML_MAX_DIMS + 1;
57
-
58
- for (int j = 0; j < n_dims; ++j) {
59
- ne[j] = rand() % 10 + 1;
60
- }
61
-
62
- struct ggml_tensor * cur = ggml_new_tensor(ctx_data, GGML_TYPE_F32, n_dims, ne);
63
- ggml_set_name(cur, name.c_str());
64
-
65
- {
66
- float * data = (float *) cur->data;
67
- for (int j = 0; j < ggml_nelements(cur); ++j) {
68
- data[j] = 100 + i;
69
- }
70
- }
71
-
72
- gguf_add_tensor(ctx, cur);
73
- }
74
-
75
- gguf_write_to_file(ctx, fname.c_str(), false);
76
-
77
- printf("%s: wrote file '%s;\n", __func__, fname.c_str());
78
-
79
- ggml_free(ctx_data);
80
- gguf_free(ctx);
81
-
82
- return true;
83
- }
84
-
85
- // just read tensor info
86
- static bool gguf_ex_read_0(const std::string & fname) {
87
- struct gguf_init_params params = {
88
- /*.no_alloc = */ false,
89
- /*.ctx = */ NULL,
90
- };
91
-
92
- struct gguf_context * ctx = gguf_init_from_file(fname.c_str(), params);
93
-
94
- if (!ctx) {
95
- fprintf(stderr, "%s: failed to load '%s'\n", __func__, fname.c_str());
96
- return false;
97
- }
98
-
99
- printf("%s: version: %d\n", __func__, gguf_get_version(ctx));
100
- printf("%s: alignment: %zu\n", __func__, gguf_get_alignment(ctx));
101
- printf("%s: data offset: %zu\n", __func__, gguf_get_data_offset(ctx));
102
-
103
- // kv
104
- {
105
- const int n_kv = gguf_get_n_kv(ctx);
106
-
107
- printf("%s: n_kv: %d\n", __func__, n_kv);
108
-
109
- for (int i = 0; i < n_kv; ++i) {
110
- const char * key = gguf_get_key(ctx, i);
111
-
112
- printf("%s: kv[%d]: key = %s\n", __func__, i, key);
113
- }
114
- }
115
-
116
- // find kv string
117
- {
118
- const char * findkey = "some.parameter.string";
119
-
120
- const int keyidx = gguf_find_key(ctx, findkey);
121
- if (keyidx == -1) {
122
- printf("%s: find key: %s not found.\n", __func__, findkey);
123
- } else {
124
- const char * key_value = gguf_get_val_str(ctx, keyidx);
125
- printf("%s: find key: %s found, kv[%d] value = %s\n", __func__, findkey, keyidx, key_value);
126
- }
127
- }
128
-
129
- // tensor info
130
- {
131
- const int n_tensors = gguf_get_n_tensors(ctx);
132
-
133
- printf("%s: n_tensors: %d\n", __func__, n_tensors);
134
-
135
- for (int i = 0; i < n_tensors; ++i) {
136
- const char * name = gguf_get_tensor_name (ctx, i);
137
- const size_t size = gguf_get_tensor_size (ctx, i);
138
- const size_t offset = gguf_get_tensor_offset(ctx, i);
139
-
140
- printf("%s: tensor[%d]: name = %s, size = %zu, offset = %zu\n", __func__, i, name, size, offset);
141
- }
142
- }
143
-
144
- gguf_free(ctx);
145
-
146
- return true;
147
- }
148
-
149
- // read and create ggml_context containing the tensors and their data
150
- static bool gguf_ex_read_1(const std::string & fname, bool check_data) {
151
- struct ggml_context * ctx_data = NULL;
152
-
153
- struct gguf_init_params params = {
154
- /*.no_alloc = */ false,
155
- /*.ctx = */ &ctx_data,
156
- };
157
-
158
- struct gguf_context * ctx = gguf_init_from_file(fname.c_str(), params);
159
-
160
- printf("%s: version: %d\n", __func__, gguf_get_version(ctx));
161
- printf("%s: alignment: %zu\n", __func__, gguf_get_alignment(ctx));
162
- printf("%s: data offset: %zu\n", __func__, gguf_get_data_offset(ctx));
163
-
164
- // kv
165
- {
166
- const int n_kv = gguf_get_n_kv(ctx);
167
-
168
- printf("%s: n_kv: %d\n", __func__, n_kv);
169
-
170
- for (int i = 0; i < n_kv; ++i) {
171
- const char * key = gguf_get_key(ctx, i);
172
-
173
- printf("%s: kv[%d]: key = %s\n", __func__, i, key);
174
- }
175
- }
176
-
177
- // tensor info
178
- {
179
- const int n_tensors = gguf_get_n_tensors(ctx);
180
-
181
- printf("%s: n_tensors: %d\n", __func__, n_tensors);
182
-
183
- for (int i = 0; i < n_tensors; ++i) {
184
- const char * name = gguf_get_tensor_name (ctx, i);
185
- const size_t size = gguf_get_tensor_size (ctx, i);
186
- const size_t offset = gguf_get_tensor_offset(ctx, i);
187
-
188
- printf("%s: tensor[%d]: name = %s, size = %zu, offset = %zu\n", __func__, i, name, size, offset);
189
- }
190
- }
191
-
192
- // data
193
- {
194
- const int n_tensors = gguf_get_n_tensors(ctx);
195
-
196
- for (int i = 0; i < n_tensors; ++i) {
197
- printf("%s: reading tensor %d data\n", __func__, i);
198
-
199
- const char * name = gguf_get_tensor_name(ctx, i);
200
-
201
- struct ggml_tensor * cur = ggml_get_tensor(ctx_data, name);
202
-
203
- printf("%s: tensor[%d]: n_dims = %d, ne = (%d, %d, %d, %d), name = %s, data = %p\n",
204
- __func__, i, ggml_n_dims(cur), int(cur->ne[0]), int(cur->ne[1]), int(cur->ne[2]), int(cur->ne[3]), cur->name, cur->data);
205
-
206
- // print first 10 elements
207
- const float * data = (const float *) cur->data;
208
-
209
- printf("%s data[:10] : ", name);
210
- for (int j = 0; j < MIN(10, ggml_nelements(cur)); ++j) {
211
- printf("%f ", data[j]);
212
- }
213
- printf("\n\n");
214
-
215
- // check data
216
- if (check_data) {
217
- const float * data = (const float *) cur->data;
218
- for (int j = 0; j < ggml_nelements(cur); ++j) {
219
- if (data[j] != 100 + i) {
220
- fprintf(stderr, "%s: tensor[%d], data[%d]: found %f, expected %f\n", __func__, i, j, data[j], float(100 + i));
221
- gguf_free(ctx);
222
- return false;
223
- }
224
- }
225
- }
226
- }
227
- }
228
-
229
- printf("%s: ctx_data size: %zu\n", __func__, ggml_get_mem_size(ctx_data));
230
-
231
- ggml_free(ctx_data);
232
- gguf_free(ctx);
233
-
234
- return true;
235
- }
236
-
237
- int main(int argc, char ** argv) {
238
- if (argc < 3) {
239
- printf("usage: %s data.gguf r|w [n]\n", argv[0]);
240
- printf("r: read data.gguf file\n");
241
- printf("w: write data.gguf file\n");
242
- printf("n: no check of tensor data\n");
243
- return -1;
244
- }
245
- bool check_data = true;
246
- if (argc == 4) {
247
- check_data = false;
248
- }
249
-
250
- srand(123456);
251
-
252
- const std::string fname(argv[1]);
253
- const std::string mode (argv[2]);
254
-
255
- GGML_ASSERT((mode == "r" || mode == "w") && "mode must be r or w");
256
-
257
- if (mode == "w") {
258
- GGML_ASSERT(gguf_ex_write(fname) && "failed to write gguf file");
259
- } else if (mode == "r") {
260
- GGML_ASSERT(gguf_ex_read_0(fname) && "failed to read gguf file");
261
- GGML_ASSERT(gguf_ex_read_1(fname, check_data) && "failed to read gguf file");
262
- }
263
-
264
- return 0;
265
- }
@@ -1,22 +0,0 @@
1
- set(TARGET llama-gguf-hash)
2
- add_executable(${TARGET} gguf-hash.cpp)
3
- install(TARGETS ${TARGET} RUNTIME)
4
-
5
- # clibs dependencies
6
- include_directories(deps/)
7
-
8
- add_library(xxhash OBJECT deps/xxhash/xxhash.c deps/xxhash/xxhash.h)
9
- target_link_libraries(${TARGET} PRIVATE xxhash)
10
-
11
- add_library(sha1 OBJECT deps/sha1/sha1.c deps/sha1/sha1.h)
12
- target_link_libraries(${TARGET} PRIVATE sha1)
13
- if (NOT MSVC)
14
- # disable warnings in 3rd party code
15
- target_compile_options(sha1 PRIVATE -w)
16
- endif()
17
-
18
- add_library(sha256 OBJECT deps/sha256/sha256.c deps/sha256/sha256.h)
19
- target_link_libraries(${TARGET} PRIVATE sha256)
20
-
21
- target_link_libraries(${TARGET} PRIVATE ggml ${CMAKE_THREAD_LIBS_INIT})
22
- target_compile_features(${TARGET} PRIVATE cxx_std_17)
@@ -1,46 +0,0 @@
1
-
2
-
3
- #ifndef __ROTATE_DEFS_H
4
- #define __ROTATE_DEFS_H
5
-
6
- #ifdef _MSC_VER
7
-
8
- #include <stdlib.h>
9
-
10
- #define ROTL32(v, n) _rotl((v), (n))
11
- #define ROTL64(v, n) _rotl64((v), (n))
12
-
13
- #define ROTR32(v, n) _rotr((v), (n))
14
- #define ROTR64(v, n) _rotr64((v), (n))
15
-
16
- #else
17
-
18
- #include <stdint.h>
19
-
20
- #define U8V(v) ((uint8_t)(v) & 0xFFU)
21
- #define U16V(v) ((uint16_t)(v) & 0xFFFFU)
22
- #define U32V(v) ((uint32_t)(v) & 0xFFFFFFFFU)
23
- #define U64V(v) ((uint64_t)(v) & 0xFFFFFFFFFFFFFFFFU)
24
-
25
- #define ROTL32(v, n) \
26
- (U32V((uint32_t)(v) << (n)) | ((uint32_t)(v) >> (32 - (n))))
27
-
28
- // tests fail if we don't have this cast...
29
- #define ROTL64(v, n) \
30
- (U64V((uint64_t)(v) << (n)) | ((uint64_t)(v) >> (64 - (n))))
31
-
32
- #define ROTR32(v, n) ROTL32(v, 32 - (n))
33
- #define ROTR64(v, n) ROTL64(v, 64 - (n))
34
-
35
- #endif
36
-
37
- #define ROTL8(v, n) \
38
- (U8V((uint8_t)(v) << (n)) | ((uint8_t)(v) >> (8 - (n))))
39
-
40
- #define ROTL16(v, n) \
41
- (U16V((uint16_t)(v) << (n)) | ((uint16_t)(v) >> (16 - (n))))
42
-
43
- #define ROTR8(v, n) ROTL8(v, 8 - (n))
44
- #define ROTR16(v, n) ROTL16(v, 16 - (n))
45
-
46
- #endif
@@ -1,295 +0,0 @@
1
- /*
2
- SHA-1 in C
3
- By Steve Reid <steve@edmweb.com>
4
- 100% Public Domain
5
-
6
- Test Vectors (from FIPS PUB 180-1)
7
- "abc"
8
- A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
9
- "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
10
- 84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
11
- A million repetitions of "a"
12
- 34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
13
- */
14
-
15
- /* #define LITTLE_ENDIAN * This should be #define'd already, if true. */
16
- /* #define SHA1HANDSOFF * Copies data before messing with it. */
17
-
18
- #define SHA1HANDSOFF
19
-
20
- #include <stdio.h>
21
- #include <string.h>
22
-
23
- /* for uint32_t */
24
- #include <stdint.h>
25
-
26
- #include "sha1.h"
27
-
28
-
29
- #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits))))
30
-
31
- /* blk0() and blk() perform the initial expand. */
32
- /* I got the idea of expanding during the round function from SSLeay */
33
- #if BYTE_ORDER == LITTLE_ENDIAN
34
- #define blk0(i) (block->l[i] = (rol(block->l[i],24)&0xFF00FF00) \
35
- |(rol(block->l[i],8)&0x00FF00FF))
36
- #elif BYTE_ORDER == BIG_ENDIAN
37
- #define blk0(i) block->l[i]
38
- #else
39
- #error "Endianness not defined!"
40
- #endif
41
- #define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
42
- ^block->l[(i+2)&15]^block->l[i&15],1))
43
-
44
- /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
45
- #define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
46
- #define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
47
- #define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
48
- #define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
49
- #define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
50
-
51
-
52
- /* Hash a single 512-bit block. This is the core of the algorithm. */
53
-
54
- void SHA1Transform(
55
- uint32_t state[5],
56
- const unsigned char buffer[64]
57
- )
58
- {
59
- uint32_t a, b, c, d, e;
60
-
61
- typedef union
62
- {
63
- unsigned char c[64];
64
- uint32_t l[16];
65
- } CHAR64LONG16;
66
-
67
- #ifdef SHA1HANDSOFF
68
- CHAR64LONG16 block[1]; /* use array to appear as a pointer */
69
-
70
- memcpy(block, buffer, 64);
71
- #else
72
- /* The following had better never be used because it causes the
73
- * pointer-to-const buffer to be cast into a pointer to non-const.
74
- * And the result is written through. I threw a "const" in, hoping
75
- * this will cause a diagnostic.
76
- */
77
- CHAR64LONG16 *block = (const CHAR64LONG16 *) buffer;
78
- #endif
79
- /* Copy context->state[] to working vars */
80
- a = state[0];
81
- b = state[1];
82
- c = state[2];
83
- d = state[3];
84
- e = state[4];
85
- /* 4 rounds of 20 operations each. Loop unrolled. */
86
- R0(a, b, c, d, e, 0);
87
- R0(e, a, b, c, d, 1);
88
- R0(d, e, a, b, c, 2);
89
- R0(c, d, e, a, b, 3);
90
- R0(b, c, d, e, a, 4);
91
- R0(a, b, c, d, e, 5);
92
- R0(e, a, b, c, d, 6);
93
- R0(d, e, a, b, c, 7);
94
- R0(c, d, e, a, b, 8);
95
- R0(b, c, d, e, a, 9);
96
- R0(a, b, c, d, e, 10);
97
- R0(e, a, b, c, d, 11);
98
- R0(d, e, a, b, c, 12);
99
- R0(c, d, e, a, b, 13);
100
- R0(b, c, d, e, a, 14);
101
- R0(a, b, c, d, e, 15);
102
- R1(e, a, b, c, d, 16);
103
- R1(d, e, a, b, c, 17);
104
- R1(c, d, e, a, b, 18);
105
- R1(b, c, d, e, a, 19);
106
- R2(a, b, c, d, e, 20);
107
- R2(e, a, b, c, d, 21);
108
- R2(d, e, a, b, c, 22);
109
- R2(c, d, e, a, b, 23);
110
- R2(b, c, d, e, a, 24);
111
- R2(a, b, c, d, e, 25);
112
- R2(e, a, b, c, d, 26);
113
- R2(d, e, a, b, c, 27);
114
- R2(c, d, e, a, b, 28);
115
- R2(b, c, d, e, a, 29);
116
- R2(a, b, c, d, e, 30);
117
- R2(e, a, b, c, d, 31);
118
- R2(d, e, a, b, c, 32);
119
- R2(c, d, e, a, b, 33);
120
- R2(b, c, d, e, a, 34);
121
- R2(a, b, c, d, e, 35);
122
- R2(e, a, b, c, d, 36);
123
- R2(d, e, a, b, c, 37);
124
- R2(c, d, e, a, b, 38);
125
- R2(b, c, d, e, a, 39);
126
- R3(a, b, c, d, e, 40);
127
- R3(e, a, b, c, d, 41);
128
- R3(d, e, a, b, c, 42);
129
- R3(c, d, e, a, b, 43);
130
- R3(b, c, d, e, a, 44);
131
- R3(a, b, c, d, e, 45);
132
- R3(e, a, b, c, d, 46);
133
- R3(d, e, a, b, c, 47);
134
- R3(c, d, e, a, b, 48);
135
- R3(b, c, d, e, a, 49);
136
- R3(a, b, c, d, e, 50);
137
- R3(e, a, b, c, d, 51);
138
- R3(d, e, a, b, c, 52);
139
- R3(c, d, e, a, b, 53);
140
- R3(b, c, d, e, a, 54);
141
- R3(a, b, c, d, e, 55);
142
- R3(e, a, b, c, d, 56);
143
- R3(d, e, a, b, c, 57);
144
- R3(c, d, e, a, b, 58);
145
- R3(b, c, d, e, a, 59);
146
- R4(a, b, c, d, e, 60);
147
- R4(e, a, b, c, d, 61);
148
- R4(d, e, a, b, c, 62);
149
- R4(c, d, e, a, b, 63);
150
- R4(b, c, d, e, a, 64);
151
- R4(a, b, c, d, e, 65);
152
- R4(e, a, b, c, d, 66);
153
- R4(d, e, a, b, c, 67);
154
- R4(c, d, e, a, b, 68);
155
- R4(b, c, d, e, a, 69);
156
- R4(a, b, c, d, e, 70);
157
- R4(e, a, b, c, d, 71);
158
- R4(d, e, a, b, c, 72);
159
- R4(c, d, e, a, b, 73);
160
- R4(b, c, d, e, a, 74);
161
- R4(a, b, c, d, e, 75);
162
- R4(e, a, b, c, d, 76);
163
- R4(d, e, a, b, c, 77);
164
- R4(c, d, e, a, b, 78);
165
- R4(b, c, d, e, a, 79);
166
- /* Add the working vars back into context.state[] */
167
- state[0] += a;
168
- state[1] += b;
169
- state[2] += c;
170
- state[3] += d;
171
- state[4] += e;
172
- /* Wipe variables */
173
- a = b = c = d = e = 0;
174
- #ifdef SHA1HANDSOFF
175
- memset(block, '\0', sizeof(block));
176
- #endif
177
- }
178
-
179
-
180
- /* SHA1Init - Initialize new context */
181
-
182
- void SHA1Init(
183
- SHA1_CTX * context
184
- )
185
- {
186
- /* SHA1 initialization constants */
187
- context->state[0] = 0x67452301;
188
- context->state[1] = 0xEFCDAB89;
189
- context->state[2] = 0x98BADCFE;
190
- context->state[3] = 0x10325476;
191
- context->state[4] = 0xC3D2E1F0;
192
- context->count[0] = context->count[1] = 0;
193
- }
194
-
195
-
196
- /* Run your data through this. */
197
-
198
- void SHA1Update(
199
- SHA1_CTX * context,
200
- const unsigned char *data,
201
- uint32_t len
202
- )
203
- {
204
- uint32_t i;
205
-
206
- uint32_t j;
207
-
208
- j = context->count[0];
209
- if ((context->count[0] += len << 3) < j)
210
- context->count[1]++;
211
- context->count[1] += (len >> 29);
212
- j = (j >> 3) & 63;
213
- if ((j + len) > 63)
214
- {
215
- memcpy(&context->buffer[j], data, (i = 64 - j));
216
- SHA1Transform(context->state, context->buffer);
217
- for (; i + 63 < len; i += 64)
218
- {
219
- SHA1Transform(context->state, &data[i]);
220
- }
221
- j = 0;
222
- }
223
- else
224
- i = 0;
225
- memcpy(&context->buffer[j], &data[i], len - i);
226
- }
227
-
228
-
229
- /* Add padding and return the message digest. */
230
-
231
- void SHA1Final(
232
- unsigned char digest[20],
233
- SHA1_CTX * context
234
- )
235
- {
236
- unsigned i;
237
-
238
- unsigned char finalcount[8];
239
-
240
- unsigned char c;
241
-
242
- #if 0 /* untested "improvement" by DHR */
243
- /* Convert context->count to a sequence of bytes
244
- * in finalcount. Second element first, but
245
- * big-endian order within element.
246
- * But we do it all backwards.
247
- */
248
- unsigned char *fcp = &finalcount[8];
249
-
250
- for (i = 0; i < 2; i++)
251
- {
252
- uint32_t t = context->count[i];
253
-
254
- int j;
255
-
256
- for (j = 0; j < 4; t >>= 8, j++)
257
- *--fcp = (unsigned char) t}
258
- #else
259
- for (i = 0; i < 8; i++)
260
- {
261
- finalcount[i] = (unsigned char) ((context->count[(i >= 4 ? 0 : 1)] >> ((3 - (i & 3)) * 8)) & 255); /* Endian independent */
262
- }
263
- #endif
264
- c = 0200;
265
- SHA1Update(context, &c, 1);
266
- while ((context->count[0] & 504) != 448)
267
- {
268
- c = 0000;
269
- SHA1Update(context, &c, 1);
270
- }
271
- SHA1Update(context, finalcount, 8); /* Should cause a SHA1Transform() */
272
- for (i = 0; i < 20; i++)
273
- {
274
- digest[i] = (unsigned char)
275
- ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255);
276
- }
277
- /* Wipe variables */
278
- memset(context, '\0', sizeof(*context));
279
- memset(&finalcount, '\0', sizeof(finalcount));
280
- }
281
-
282
- void SHA1(
283
- char *hash_out,
284
- const char *str,
285
- uint32_t len)
286
- {
287
- SHA1_CTX ctx;
288
- unsigned int ii;
289
-
290
- SHA1Init(&ctx);
291
- for (ii=0; ii<len; ii+=1)
292
- SHA1Update(&ctx, (const unsigned char*)str + ii, 1);
293
- SHA1Final((unsigned char *)hash_out, &ctx);
294
- }
295
-
@@ -1,52 +0,0 @@
1
- #ifndef SHA1_H
2
- #define SHA1_H
3
-
4
- /*
5
- SHA-1 in C
6
- By Steve Reid <steve@edmweb.com>
7
- 100% Public Domain
8
- */
9
-
10
- #include "stdint.h"
11
-
12
- #if defined(__cplusplus)
13
- extern "C" {
14
- #endif
15
-
16
- typedef struct
17
- {
18
- uint32_t state[5];
19
- uint32_t count[2];
20
- unsigned char buffer[64];
21
- } SHA1_CTX;
22
-
23
- void SHA1Transform(
24
- uint32_t state[5],
25
- const unsigned char buffer[64]
26
- );
27
-
28
- void SHA1Init(
29
- SHA1_CTX * context
30
- );
31
-
32
- void SHA1Update(
33
- SHA1_CTX * context,
34
- const unsigned char *data,
35
- uint32_t len
36
- );
37
-
38
- void SHA1Final(
39
- unsigned char digest[20],
40
- SHA1_CTX * context
41
- );
42
-
43
- void SHA1(
44
- char *hash_out,
45
- const char *str,
46
- uint32_t len);
47
-
48
- #if defined(__cplusplus)
49
- }
50
- #endif
51
-
52
- #endif /* SHA1_H */