<!-- Copyright (c) 2026 defconxt. All rights reserved. -->
<!-- Licensed under AGPL-3.0 — see LICENSE file for details. -->

# API Reference — Implementing Homomorphic Encryption

## TenSEAL

### Context Creation

```python
import tenseal as ts
context = ts.context(
    ts.SCHEME_TYPE.CKKS,      # or BFV
    poly_modulus_degree=8192,
    coeff_mod_bit_sizes=[60, 40, 40, 60],
)
context.global_scale = 2**40
context.generate_galois_keys()
```

### CKKS Operations

| Operation | Method | Notes |
|---|---|---|
| Addition | `enc_a + enc_b` | Same scale required |
| Multiplication | `enc_a * enc_b` | Consumes noise budget |
| Dot product | `enc_a.dot(enc_b)` | Returns single value |
| Decrypt | `enc.decrypt()` | Returns list of floats |

### Security Parameters

| poly_modulus_degree | Security (bits) | Max mult depth |
|---|---|---|
| 4096 | 128 | 1-2 |
| 8192 | 128 | 3-5 |
| 16384 | 128 | 6-10 |

## Agent Script

```bash
node agent.js benchmark --poly-degree 8192 --iterations 100
node agent.js test --scheme ckks
node agent.js estimate --mult-depth 5 --security 128
```
