🐙 Poulpy-Core
Poulpy-Core is a Rust crate built on poulpy-hal, providing scheme- and backend-agnostic Module-LWE-based homomorphic encryption building blocks.
Getting Started
poulpy-core exposes its public API as soon as the crate is imported. Backend
crates own the feature flags that wire concrete implementations into that API.
The backend conformance tests are instantiated by backend crates. To run the portable reference backend core suite:
poulpy-core is backend-agnostic. Concrete execution lives in backend crates such as
poulpy-cpu-ref, poulpy-cpu-avx, or poulpy-cpu-avx512, which provide the backend type BE used by
poulpy_hal::layouts::Module<BE>. The HAL remains dispatch-only: poulpy-cpu-ref
hosts the default implementations, while accelerated backends override selected methods.
The canonical public traits live under poulpy_core::api::*:
use ;
use ;
For a runnable end-to-end example using a concrete backend, see
poulpy-cpu-ref/examples/core_encryption.rs.
Crate Organization
poulpy-core follows the same four-module layer pattern used throughout the Poulpy workspace:
┌─────────┐ ┌─────────┐ ┌─────────────┐ ┌────────────────┐
│ api │────►│ oep │────►│ delegates │◄────│ default │
└─────────┘ └─────────┘ └─────────────┘ └────────────────┘
| Module | Role |
|---|---|
api |
Public traits for Module-LWE operations (GLWEEncryptSk, GLWEAutomorphism, GLWETensoring, …). Trait bounds reference oep for the backend capabilities they need. |
oep |
Open Extension Points. Unsafe backend dispatch traits (one per operation family). A blanket impl wires any conforming backend to the corresponding default method automatically. Macros (impl_*_defaults_full!) are what a backend crate calls to opt in. |
default |
Portable algorithm implementations as safe trait methods — the fallback every backend gets for free. |
delegates |
Implements each api trait on Module<BE> by dispatching through oep. |
Overriding an operation: a backend implements the corresponding oep trait directly instead of relying on the blanket wiring to default. Only the operations that need a faster or device-native implementation require an override; everything else is inherited automatically.
Layouts
This crate defines three categories of layouts for LWE, GLWE, GGLWE, and GGSW objects (and their derivatives), all instantiated using poulpy-hal layouts. Each serves a distinct purpose:
- Standard → Front-end, serializable layouts. These are backend-agnostic and act as inputs/outputs of computations (e.g.,
GGLWEAutomorphismKey). - Compressed → Compact serializable variants of the standard layouts. They are not usable for computation but significantly reduce storage size (e.g.,
GGLWEAutomorphismKeyCompressed). - Prepared → Backend-optimized, opaque layouts used only for computation (write-only). These store preprocessed data for efficient execution on a specific backend (e.g.,
GGLWEAutomorphismKeyPrepared).
All standard and compressed layouts implement the WriterTo and ReaderFrom traits, enabling straightforward serialization/deserialization with any type implementing Write or Read:
Example Workflow
flowchart TD
A[GGLWEAutomorphismKeyCompressed]-->|decompress|B[GGLWEAutomorphismKey]-->|prepare|C[GGLWEAutomorphismKeyPrepared]
Equivalent Rust:
let mut atk_compressed: =
alloc;
let mut atk: =
alloc;
module.decompress_automorphism_key;
let mut atk_prep = atk.prepare_alloc;
Encryption & Decryption
- Encryption → Supported for all standard and compressed layouts.
- Decryption → Only directly available for
LWECiphertextandGLWECiphertext. However, it remains naturally usable onGGLWEandGGSWobjects, since these are vectors/matrices ofGLWECiphertext.
let mut atk: =
alloc;
module.glwe_automorphism_key_encrypt_sk;
module.glwe_decrypt;
Keyswitching, Automorphism & External Product
Keyswitching, automorphisms and external products are supported for all ciphertext types where they are well-defined.
This includes subtypes such as GGLWEAutomorphismKey.
For example:
module.glwe_external_product;
module.ggsw_automorphism;
Additional Features
- Ciphertexts:
LWEandGLWE GLWEring packingGLWEtrace- Noise analysis for
GLWE,GGLWE,GGSW - Basic operations over
GLWEciphertexts and plaintexts
Tests
A fully generic backend conformance suite is available in src/test_suite.
Concrete backend crates instantiate it via poulpy_core::core_backend_test_suite!, keeping
poulpy-core free of any concrete backend dependency.
Useful commands: