Skip to content

Latest commit

 

History

History
 
 

capi

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

README.md

BLAKE3 servil for C and C++

libb3_servil exposes blake3-servil's one-shot, incremental, batch, and streaming hashing through b3.h. The header documents each call's contract. It works with C11 and C++11.

Build and install

Build tools: Rust, a C compiler, cargo-c 0.10.26+cargo-0.100.0, and pkg-config, available on PATH.

On Linux or macOS, from the repository root:

cargo cinstall --release --manifest-path capi/Cargo.toml \
    --prefix="$HOME/.local" --libdir=lib
export PKG_CONFIG_PATH="$HOME/.local/lib/pkgconfig"

This installs include/b3.h, the static and shared libraries in lib/, and lib/pkgconfig/b3_servil.pc. The shared library has a versioned library name. --destdir=STAGING_DIRECTORY stages these files for packaging; the installed paths still use --prefix.

Hash a message

Save this as example.c:

#include <b3.h>
#include <stdio.h>

int main(void) {
    b3_mode mode = b3_plain();
    b3_digest digest = b3_hash(&mode, "hello", 5);
    for (unsigned i = 0; i < 32; ++i) printf("%02x", digest.bytes[i]);
    puts("");
    return 0;
}

Compile and run against the installation above:

pkg-config --cflags --libs b3_servil > b3-flags
cc example.c @b3-flags \
    -Xlinker -rpath -Xlinker "$HOME/.local/lib" -o example
./example

For an installation containing only the static library, use cargo cinstall --library-type=staticlib with the same installation options, and generate b3-flags with pkg-config --static --cflags --libs b3_servil. The --static flag supplies the system libraries Rust's static library needs.

Choose a call

  • b3_hash: one message already in memory.
  • b3_hasher_init, b3_hasher_update, b3_hasher_finalize: one message arriving in pieces.
  • b3_hash_many: a batch of equal-length messages.
  • b3_stream_*: a continuing series of messages, with results delivered to a callback. tests/check.c includes a complete example.

B3_VERSION identifies the header; b3_version() identifies the linked library. Both carry the release's full version string.