API Reference

This section provides a high-level overview of the public C++ API of HEonGPU. The design is intended to be stable and intuitive, abstracting all underlying CUDA complexity and drawing inspiration from the user-friendly design of Microsoft SEAL. The API is organized within the heongpu namespace and is heavily templated to support different FHE schemes.

Core Enumerations

Scheme Selection

Used to specify the desired homomorphic encryption scheme during context creation.

namespace heongpu {
    enum class Scheme {
        BFV,
        CKKS,
        TFHE
    };
}
Key-Switching Method

The algorithm used for key-switching operations like relinearization and rotation is selected automatically from the P modulus base count: P_size == 1 -> KEYSWITCHING_METHOD_I, P_size > 1 -> KEYSWITCHING_METHOD_II. P_size == 0 is invalid.

namespace heongpu {
    enum class keyswitching_type {
        KEYSWITCHING_METHOD_I,  // Based on Fan-Vercauteren
        KEYSWITCHING_METHOD_II, // Hybrid method
    };
}

Context and Parameter Classes

HEContext

The central class that manages the entire cryptographic environment. It must be the first object instantiated. It holds the encryption parameters, validates them, and pre-computes necessary data on the GPU.

 1 template <Scheme scheme_type>
 2 class HEContext {
 3 public:
 4     // Constructor optionally takes security level.
 5     HEContext(sec_level_type sec_level = sec_level_type::sec128);
 6
 7     // Setters for core encryption parameters.
 8     void set_poly_modulus_degree(size_t degree);
 9     void set_coeff_modulus_default_values(int level);
10     void set_plain_modulus(int plain_modulus); // For BFV
11
12     // Finalizes the context and uploads pre-computations to the GPU.
13     void generate();
14 };

Key Management Classes

HEKeyGenerator

Generates all necessary cryptographic keys from a valid HEContext.

 1 template <Scheme scheme_type>
 2 class HEKeyGenerator {
 3 public:
 4     HEKeyGenerator(const HEContext<scheme_type>& context);
 5
 6     void generate_secret_key(Secretkey<scheme_type>& sk);
 7     void generate_public_key(Publickey<scheme_type>& pk, const Secretkey<scheme_type>& sk);
 8     void generate_relin_key(Relinkey<scheme_type>& rlk, const Secretkey<scheme_type>& sk);
 9     void generate_galois_key(/* ... */); // For rotations
10 };
Key Storage Classes

These classes are containers for the key data, which resides primarily on the GPU.

template <Scheme scheme_type> class Secretkey;
template <Scheme scheme_type> class Publickey;
template <Scheme scheme_type> class Relinkey;
template <Scheme scheme_type> class Galoiskey;

Data and Cryptographic Classes

Plaintext and Ciphertext

These classes hold the plaintext (encoded) and ciphertext data.

template <Scheme scheme_type> class Plaintext;
template <Scheme scheme_type> class Ciphertext;
HEEncoder

Handles the conversion of user data into the plaintext polynomial format required for encryption.

 1 template <Scheme scheme_type>
 2 class HEEncoder {
 3 public:
 4     HEEncoder(const HEContext<scheme_type>& context);
 5
 6     // BFV: Encodes a vector of integers.
 7     void encode(Plaintext<Scheme::BFV>& ptxt, const std::vector<uint64_t>& message);
 8
 9     // CKKS: Encodes a vector of doubles with a given scale.
10     void encode(Plaintext<Scheme::CKKS>& ptxt, const Message<Scheme::CKKS>& msg, double scale);
11
12     // Corresponding decode functions are also provided.
13     void decode(std::vector<uint64_t>& message, const Plaintext<Scheme::BFV>& ptxt);
14     void decode(Message<Scheme::CKKS>& msg, const Plaintext<Scheme::CKKS>& ptxt);
15 };
HEEncryptor and HEDecryptor

Perform the core cryptographic transformations.

 1 template <Scheme scheme_type>
 2 class HEEncryptor {
 3 public:
 4     HEEncryptor(const HEContext<scheme_type>& context, const Publickey<scheme_type>& pk);
 5     void encrypt(Ciphertext<scheme_type>& ctxt, const Plaintext<scheme_type>& ptxt);
 6 };
 7
 8 template <Scheme scheme_type>
 9 class HEDecryptor {
10 public:
11     HEDecryptor(const HEContext<scheme_type>& context, const Secretkey<scheme_type>& sk);
12     void decrypt(Plaintext<scheme_type>& ptxt, const Ciphertext<scheme_type>& ctxt);
13 };
HEArithmeticOperator

The primary class for executing all homomorphic operations on the GPU.

 1 template <Scheme scheme_type>
 2 class HEArithmeticOperator {
 3 public:
 4     HEArithmeticOperator(const HEContext<scheme_type>& context, const HEEncoder<scheme_type>& encoder);
 5
 6     // In-place and out-of-place arithmetic operations
 7     void add(const Ciphertext<scheme_type>& ctxt1, const Ciphertext<scheme_type>& ctxt2, Ciphertext<scheme_type>& result);
 8     void add_inplace(Ciphertext<scheme_type>& ctxt1, const Ciphertext<scheme_type>& ctxt2);
 9     void multiply(const Ciphertext<scheme_type>& ctxt1, const Ciphertext<scheme_type>& ctxt2, Ciphertext<scheme_type>& result);
10     void multiply_inplace(Ciphertext<scheme_type>& ctxt1, const Ciphertext<scheme_type>& ctxt2);
11
12     // Operations with plaintexts
13     void add_plain_inplace(Ciphertext<scheme_type>& ctxt, const Plaintext<scheme_type>& ptxt);
14     void multiply_plain_inplace(Ciphertext<scheme_type>& ctxt, const Plaintext<scheme_type>& ptxt);
15
16     // Key-switching and modulus management operations
17     void relinearize_inplace(Ciphertext<scheme_type>& ctxt, const Relinkey<scheme_type>& rlk);
18     void rotate_rows_inplace(Ciphertext<scheme_type>& ctxt, int steps, const Galoiskey<scheme_type>& gk);
19     void rescale_inplace(Ciphertext<Scheme::CKKS>& ctxt); // CKKS only
20 };