Your first encrypted computation.
Add and multiply encrypted values, then decrypt the result and check it against the same calculation in the clear.
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 a native C/C++ build toolchain for the example’s dependencies. 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 9361627e38c646ade386cf0a3b71abf6e605ed61
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-ref --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:
- Prepare the keys. Create a secret key, a multiplication key, and the scratch memory used by the operations.
- Encode and encrypt. Pack the input vectors into plaintexts and encrypt them.
- 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. - 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
- Build outside the library checkout: download the standalone application.
- Separate client and evaluator: follow the serialized example.
- Explore more operations: continue with CKKS for numerical computation or Binary FHE for Boolean and integer computation.
- Resolve a build or runtime error: see Troubleshooting.