poulpyFully homomorphic encryption
GitHub ↗Get started →
Menu

Your first encrypted computation.

Add and multiply encrypted values, then decrypt the result and check it against the same calculation in the clear.

Source guide · 7dd13e6Markdown

This walkthrough runs Poulpy’s maintained ckks_hello example. Using the portable CPU backend, it computes (a + b) × b / 32 on encrypted vectors. No AVX instructions or GPU are required.

1. Get the source

You need Git, Rust installed through rustup, and your platform’s build tools, which provide the system linker. On Linux, install your distribution’s build tools; on macOS, install the Xcode command line tools; on Windows, use the Visual Studio C++ build tools or WSL.

git clone https://github.com/poulpy-fhe/poulpy.git
cd poulpy
git checkout 7dd13e6aa9808982f5355fb6acb70ca434de4e35

Run the following commands from this directory. Rustup selects the nightly toolchain pinned in the repository’s rust-toolchain.toml and downloads it if needed.

2. Run the example

cargo run --locked --release -p poulpy-cpu-portable --features enable-ckks --example ckks_hello

The first run downloads and compiles the dependencies. Later runs reuse the compiled files.

When the encrypted calculation matches the expected result, the example finishes with:

ok: z = (a + b) * b verified on 512 slots

It also reports the encoding scale, remaining ciphertext budget, and maximum error. CKKS produces an approximate numerical result; the example checks that its error stays below its chosen tolerance.

3. Follow the computation

Open ckks_hello.rs. The example has four stages:

  1. Prepare the keys. Create a secret key, a multiplication key, and the scratch memory used by the operations.
  2. Encode and encrypt. Pack the input vectors into plaintexts and encrypt them.
  3. Compute on ciphertexts. Add the encrypted vectors, multiply by the second vector, and rescale. The call ckks_div_pow2_assign(..., 5) divides the result by 32.
  4. Decrypt and verify. Decode and compare against (a + b) × b / 32. The success message above abbreviates the calculation.

Change the input values in the example and run the same command again to see the verification use your new inputs.

The fixed randomness seeds and small parameters in these examples are for learning and reproducible checks. For application parameters, continue with the parameter guide and security responsibilities.

Choose your next step