.. _api_reference: 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. .. code-block:: cpp namespace heongpu { enum class Scheme { BFV, CKKS, TFHE }; } **Key-Switching Method** Selects the algorithm used for key-switching operations like relinearization and rotation. .. code-block:: cpp namespace heongpu { enum class keyswitching_type { KEYSWITCHING_METHOD_I, // Based on Fan-Vercauteren KEYSWITCHING_METHOD_II, // Hybrid method KEYSWITCHING_METHOD_III // Key decomposition method (relinearization only) }; } 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. .. code-block:: cpp :linenos: template class HEContext { public: // Constructor requires selecting a key-switching method. HEContext(keyswitching_type method); // Setters for core encryption parameters. void set_poly_modulus_degree(size_t degree); void set_coeff_modulus_default_values(int level); void set_plain_modulus(int plain_modulus); // For BFV // Finalizes the context and uploads pre-computations to the GPU. void generate(); }; Key Management Classes ---------------------- **HEKeyGenerator** Generates all necessary cryptographic keys from a valid ``HEContext``. .. code-block:: cpp :linenos: template class HEKeyGenerator { public: HEKeyGenerator(const HEContext& context); void generate_secret_key(Secretkey& sk); void generate_public_key(Publickey& pk, const Secretkey& sk); void generate_relin_key(Relinkey& rlk, const Secretkey& sk); void generate_galois_key(/* ... */); // For rotations }; **Key Storage Classes** These classes are containers for the key data, which resides primarily on the GPU. .. code-block:: cpp template class Secretkey; template class Publickey; template class Relinkey; template class Galoiskey; Data and Cryptographic Classes ------------------------------ **Plaintext and Ciphertext** These classes hold the plaintext (encoded) and ciphertext data. .. code-block:: cpp template class Plaintext; template class Ciphertext; **HEEncoder** Handles the conversion of user data into the plaintext polynomial format required for encryption. .. code-block:: cpp :linenos: template class HEEncoder { public: HEEncoder(const HEContext& context); // BFV: Encodes a vector of integers. void encode(Plaintext& ptxt, const std::vector& message); // CKKS: Encodes a vector of doubles with a given scale. void encode(Plaintext& ptxt, const Message& msg, double scale); // Corresponding decode functions are also provided. void decode(std::vector& message, const Plaintext& ptxt); void decode(Message& msg, const Plaintext& ptxt); }; **HEEncryptor and HEDecryptor** Perform the core cryptographic transformations. .. code-block:: cpp :linenos: template class HEEncryptor { public: HEEncryptor(const HEContext& context, const Publickey& pk); void encrypt(Ciphertext& ctxt, const Plaintext& ptxt); }; template class HEDecryptor { public: HEDecryptor(const HEContext& context, const Secretkey& sk); void decrypt(Plaintext& ptxt, const Ciphertext& ctxt); }; **HEArithmeticOperator** The primary class for executing all homomorphic operations on the GPU. .. code-block:: cpp :linenos: template class HEArithmeticOperator { public: HEArithmeticOperator(const HEContext& context, const HEEncoder& encoder); // In-place and out-of-place arithmetic operations void add(const Ciphertext& ctxt1, const Ciphertext& ctxt2, Ciphertext& result); void add_inplace(Ciphertext& ctxt1, const Ciphertext& ctxt2); void multiply(const Ciphertext& ctxt1, const Ciphertext& ctxt2, Ciphertext& result); void multiply_inplace(Ciphertext& ctxt1, const Ciphertext& ctxt2); // Operations with plaintexts void add_plain_inplace(Ciphertext& ctxt, const Plaintext& ptxt); void multiply_plain_inplace(Ciphertext& ctxt, const Plaintext& ptxt); // Key-switching and modulus management operations void relinearize_inplace(Ciphertext& ctxt, const Relinkey& rlk); void rotate_rows_inplace(Ciphertext& ctxt, int steps, const Galoiskey& gk); void rescale_inplace(Ciphertext& ctxt); // CKKS only };