Skip to content
Live demo →

C ABI v2

Header: mvp/include/unicomm.h. Link against libunicomm_core.{so,dylib} or unicomm_core.dll. uni_abi_version() returns 2; a binding must check >= 2 before it uses the JSON functions (ADR-0017). Rules: UTF-8 C strings in, every returned char* is freed with uni_string_free, no panic crosses the boundary, all calls block (call from a worker thread if needed).

Function Purpose
int32_t uni_abi_version(void) ABI version, 2
void uni_string_free(char *p) free any string the library returned
char *uni_version_json(void) {"abi":2,"version":...,"policies":[...],"default_policy":"hybrid","profiles":[...],"key_exchange":{policy: groups}}
int32_t uni_request_json(const char *opts_json, char **out_json) one request, JSON in and out. Returns 0 on success, 1 on a request error, 2 on an internal error. *out_json is always set
int32_t uni_request(url, mode, http3, ca_path, out) v1, kept: one GET. mode 0 = pq-required, 1 = hybrid, 2 = classical; anything else is BAD_INPUT
int32_t uni_server_start(const char *cert_dir, int32_t demo_insecure) start the server in the background (:8443 hybrid, :8446 pq-required; demo_insecure != 0 adds :8444 and :8088). 0 started, 1 already started, -1 error
{"url":"https://localhost:8443/", "method":"GET", "headers":{"k":"v"}, "body":"...", "http3":false,
"ca_path":null, "policy":"hybrid", "require_pq":false, "timeout_ms":10000}
  • url is required and must be https://. Unknown keys are rejected (BAD_INPUT names the key).
  • policy: hybrid (default), pq-required, cnsa2, classical. profile (default or cnsa2) is a back-compat alias; if both are given they must agree.
  • require_pq: true turns hybrid into pq-required, leaves cnsa2 alone, and conflicts with classical.
  • http3: true with cnsa2 is BAD_INPUT. timeout_ms is 1 to 600000, default 10000.

Success: {"ok":true,"status":200,"protocol":"HTTP/1.1"|"HTTP/2"|"HTTP/3","key_exchange":"X25519MLKEM768","cipher":"TLS13_AES_256_GCM_SHA384","post_quantum":true,"policy":"hybrid","profile":"hybrid","headers":{...},"body":"..."}

Failure: {"ok":false,"error_code":"PQ_REQUIRED","error":"...","hint":"..."}

Code Meaning Typical fix
PQ_REQUIRED policy is pq-required or cnsa2 and the peer cannot do that key exchange upgrade the server, or use hybrid to allow classical fallback
TLS_HANDSHAKE TLS failed for another reason check TLS 1.3, SNI, ALPN
CERT_UNTRUSTED certificate does not chain to a trusted root or does not cover the name pass ca_path, or fix the chain
TIMEOUT no complete answer in time raise timeout_ms, check reachability and UDP for HTTP/3
BAD_INPUT invalid request: not https, unknown policy or key, cnsa2 with HTTP/3, bad header fix the call
CONNECT DNS failure, refused, unreachable check host, port, firewall
HTTP protocol error after the handshake see the message
LIBRARY binding-side only: native core not found or ABI below 2 build the core, or set UNICOMM_LIB
#include "unicomm.h"
#include <stdio.h>
int main(void) {
char *out = NULL;
int rc = uni_request_json("{\"url\":\"https://localhost:8443/\",\"policy\":\"pq-required\",\"ca_path\":\"certs/ca.pem\"}", &out);
printf("rc=%d %s\n", rc, out); // rc=0 and "post_quantum":true, or rc=1 and "error_code":"PQ_REQUIRED"
uni_string_free(out);
return rc;
}