Quick start
This example squares two encrypted numbers, bootstraps the result, and decrypts it. Key holder and evaluator run in one process here. Keys, roles and deployment shows how to split them.
import numpy as npimport yuenix
with yuenix.Context() as ctx: plan = ctx.plan(yuenix.Profile.CKKS64) keys = plan.generate_keys() # key holder: secret key stays here ev = keys.evaluator() # evaluator: public evaluation keys only
x = keys.encrypt(np.array([0.125, -0.25]), level=plan.capabilities.input_level) y = ev.bootstrap(x) sq = ev.mul(y, y) print(keys.decrypt(sq)[:2]) # ≈ [0.015625, 0.0625]#include <yuenix.h>#include <stdio.h>
#define CHECK(call) do { yuenix_status s = (call); if (s != YUENIX_OK) { \ fprintf(stderr, "%s\n", yuenix_last_error(ctx)); return 1; } } while (0)
int main(void) { yuenix_context* ctx = NULL; yuenix_plan* plan = NULL; yuenix_keyset* keys = NULL; yuenix_evaluator* ev = NULL; yuenix_ciphertext *x = NULL, *y = NULL, *sq = NULL; yuenix_capabilities caps = {.struct_size = sizeof caps}; yuenix_complex in[2] = {{0.125, 0}, {-0.25, 0}}, out[2];
CHECK(yuenix_context_create(NULL, &ctx)); CHECK(yuenix_plan_create(ctx, YUENIX_PROFILE_CKKS64, NULL, 0, &plan)); CHECK(yuenix_plan_query(plan, &caps)); CHECK(yuenix_keyset_generate(plan, &keys)); CHECK(yuenix_evaluator_from_keyset(keys, &ev));
CHECK(yuenix_encrypt(keys, in, 2, caps.input_level, &x)); CHECK(yuenix_bootstrap(ev, x, &y)); CHECK(yuenix_mul(ev, y, y, &sq)); CHECK(yuenix_decrypt(keys, sq, out, 2)); printf("%f %f\n", out[0].real, out[1].real);
yuenix_ciphertext_destroy(sq); yuenix_ciphertext_destroy(y); yuenix_ciphertext_destroy(x); yuenix_evaluator_destroy(ev); yuenix_keyset_destroy(keys); yuenix_plan_destroy(plan); yuenix_context_destroy(ctx); return 0;}Build with cc quick.c -I$YUENIX_ROOT/include -L$YUENIX_ROOT/lib -lyuenix.
What happened
Section titled “What happened”- The context selects the GPU, owns the CUDA stream and stores the last error message.
- The plan fixes the CKKS parameters, the bootstrapping circuit and the rotation set. See Plans and profiles.
- The keyset holds the secret key. The evaluator holds only evaluation keys.
bootstraprefreshes the ciphertext’s levels so that the multiplication has room. See Bootstrapping.