Skip to content
SDKs · ClientIn developmentView source

Native C

RootHerald.lib on Windows (TBS), librootherald.a on Linux (tpm2-tss) and macOS (Secure Enclave). One header, byte-identical across the three repos and sdk-ios; CI fails on drift.

In development

This SDK is implemented but not yet published to its package registry. Until it ships, collect an opaque evidence blob on the device and appraise it server-side with @rootherald/node (or any available server SDK). The API shown below is the planned surface and may change before release.

terminal (Linux)bash
mkdir rootherald
tar -xzf rootherald-linux-x64.tar.gz -C rootherald
cd rootherald && sha256sum -c SHA256SUMS
PowerShell (Windows)text
mkdir rootherald
tar -xzf rootherald-windows-x64.tar.gz -C rootherald
cd rootherald
Get-Content SHA256SUMS | ForEach-Object {
  $hash, $file = $_ -split "  "
  $ok = (Get-FileHash $file).Hash -eq $hash
  if ($ok) { "OK $file" } else { "FAILED $file" }
}

Each archive holds lib/, include/ and SHA256SUMS.

Releases: sdk-windows · sdk-linux · sdk-macos. The archive is not code-signed and does not need to be: you link it, and your certificate signs the result.

The calls

rootherald.h (abridged, ABI 8.1)c
typedef struct RH_HANDLE__     *RH_HANDLE;       /* one TPM session */
typedef struct RH_KEY_HANDLE__ *RH_KEY_HANDLE;   /* an app key loaded under it */

RH_STATUS RootHeraldOpen(RH_HANDLE* out);                    /* no key, no endpoint */
void      RootHeraldClose(RH_HANDLE h);                      /* closes every key under it */
RH_STATUS RootHeraldPreCheck(RH_HANDLE h, RH_POSTURE* out);  /* local readiness; capabilities, app_keys_supported */

/* 1. Enroll: two legs. Leg 1 creates this installation's attestation key and writes it as a blob;
   leg 2 takes the blob back. Only leg 2 needs elevation on Windows. */
RH_STATUS RootHeraldEnrollBegin(RH_HANDLE h, char* buf, size_t cap, size_t* out_len,
                                uint8_t* ak_blob, size_t ak_cap, size_t* ak_len);
RH_STATUS RootHeraldEnrollComplete(RH_HANDLE h, const char* challenge_json, size_t len,
                                   char* buf, size_t cap, size_t* out_len,
                                   const uint8_t* ak_blob, size_t ak_len);

/* 2. Mint a key: the attestation key certifies a new key over the server's nonce.
   key_challenge is the relayed "rhk1c.…" string and carries the purpose, sign or decrypt;
   key_blob is the new key, kept by the app. */
RH_STATUS RootHeraldMintKey(RH_HANDLE h, const char* key_challenge,
                            const uint8_t* ak_blob, size_t ak_len,
                            char* certification, size_t cap, size_t* len,
                            uint8_t* key_blob, size_t key_cap, size_t* key_len);

/* 3. Attest: evidence only. challenge is the relayed "rhc1.…" string; anything else is RH_ERR_INVALID_ARG.
   ak_blob is required on a TPM platform; NULL and 0 on macOS. */
RH_STATUS RootHeraldAttest(RH_HANDLE h, const char* challenge,
                           const uint8_t* ak_blob, size_t ak_len,
                           char* evidence, size_t evidence_cap, size_t* evidence_len);

/* Keys. No network, no nonce. ES256 emits r||s (64 bytes); RS256 emits PKCS#1 v1.5 (256 bytes).
   Decrypt opens the envelope the backend's encryptToDevice addressed to a decrypt key; a sign key
   is RH_ERR_INVALID_ARG, an envelope that does not open is RH_ERR_DECRYPT_FAILED. */
RH_STATUS RootHeraldLoadKey(RH_HANDLE h, const uint8_t* blob, size_t len, RH_KEY_HANDLE* out);
RH_STATUS RootHeraldKeyInfo(RH_KEY_HANDLE key, RH_KEY_INFO* out);   /* purpose, alg, signature_len */
RH_STATUS RootHeraldSign(RH_KEY_HANDLE key, const uint8_t* data, size_t len,
                         uint8_t* sig, size_t sig_cap, size_t* sig_len);
RH_STATUS RootHeraldDecrypt(RH_KEY_HANDLE key, const char* jwe, size_t jwe_len,
                            uint8_t* plaintext, size_t cap, size_t* out_len);
void      RootHeraldCloseKey(RH_KEY_HANDLE key);
RH_STATUS RootHeraldCheckKey(RH_HANDLE h, const uint8_t* blob, size_t len);   /* still loads? */

const char* RootHeraldErrorString(RH_STATUS);
const char* RootHeraldAbiVersion(void);      /* "8.1" */

Every byte-producing call takes (buf, cap, out_len) and returns RH_ERR_BUFFER_TOO_SMALL with *out_len set when the buffer is short. The library never allocates, so there is nothing to free. Attest and MintKey do their TPM work before they know the size, so start with a generous buffer and grow once; when a buffer is short they set every length and write nothing until all fit. A buffer the size of the envelope always fits Decrypt's plaintext, and an empty plaintext is RH_OK with *out_len 0. The SDK writes no files: the attestation key blob from EnrollBegin and each key blob from MintKey are yours to store, and the attestation key blob is passed back to every Attest and MintKey. The key family is the SDK's choice from what the TPM supports, ECC P-256 or RSA-2048, reported in RH_POSTURE.capabilities. Every RH_STATUS is on the status codes page.

Linking

CMakeLists.txtbash
find_package(RootHerald CONFIG REQUIRED)
target_link_libraries(your_app PRIVATE RootHerald::sdk)

The Windows and Linux archives are CMake packages. Point CMAKE_PREFIX_PATH at the extracted directory, and RootHerald::sdk brings its own link dependencies: tbs, bcrypt, crypt32 and advapi32 on Windows; tss2-esys, tss2-tctildr, tss2-mu and libcrypto on Linux, found through pkg-config. On Linux, install them with apt install libtss2-dev libssl-dev pkg-config. The macOS archive has no CMake package: link lib/librootherald.a and Security.framework.

Threads and elevation

A handle is not thread-safe and the library takes no locks: one session per thread, or serialise. Each enrollment on Windows needs elevation, for EnrollComplete only; see Windows elevation. Check RootHeraldAbiVersion() at startup against the header you compiled with.