From 36c9ab36cf4a57ea6d161e284284fa01a7de842c Mon Sep 17 00:00:00 2001 From: York Jasper Niebuhr Date: Sat, 22 Nov 2025 22:46:38 +0100 Subject: [PATCH] Bfv API update --- include/bfv.hpp | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/include/bfv.hpp b/include/bfv.hpp index d0e9961..21ed5d9 100644 --- a/include/bfv.hpp +++ b/include/bfv.hpp @@ -42,33 +42,37 @@ struct plaintext { using ciphertext = int; +// TODO -> Exception with enum that differentiates reason (e.g. CONTEXT_NO_PRIVATE) + // Inheriting from context class allows pluggability of implementations (e.g. SEAL vs. GPU) -class context { -public: - context(const context& other) = delete; - context(context&& other) noexcept; - context& operator=(const context& other) = delete; - context& operator=(context&& other) noexcept; +struct context { + static constexpr int PUBLIC_COMPONENT = 1; + static constexpr int PRIVATE_COMPONENT = 2; - context(); virtual ~context(); - virtual bool allocate(ciphertext& ct) = 0; - virtual bool free(ciphertext ct) = 0; - virtual bool serialize(ciphertext ct, void* buf, std::size_t& n) = 0; - virtual bool deserialize(ciphertext ct, const void* buf, std::size_t n) = 0; - virtual bool encrypt(const plaintext& pt, ciphertext ct) = 0; - virtual bool decrypt(ciphertext ct, plaintext& pt) = 0; - virtual bool add_cipher_plain(ciphertext a, const plaintext& b, ciphertext res) = 0; - virtual bool add_cipher_cipher(ciphertext a, ciphertext b, ciphertext res) = 0; - virtual bool sub_cipher_plain(ciphertext a, const plaintext& b, ciphertext res) = 0; - virtual bool sub_cipher_cipher(ciphertext a, ciphertext b, ciphertext res) = 0; - virtual bool mul_cipher_plain(ciphertext a, const plaintext& b, ciphertext res) = 0; - virtual bool mul_cipher_cipher(ciphertext a, ciphertext b, ciphertext res) = 0; - virtual bool rot_cipher_rows(ciphertext ct, int r, ciphertext res) = 0; - virtual bool swap_cipher_rows(ciphertext ct, ciphertext res) = 0; - virtual bool noise_budget(ciphertext ct, std::size_t& budget) = 0; + virtual void new_components(int components) = 0; // context default constructs empty + virtual void has_components(int components) const = 0; + virtual void clone_components(int components, std::shared_ptr& ptr) const = 0; + // virtual void dump_components(int components, void* buf, std::size_t& n) const = 0; + // virtual void load_components(int components, const void* buf, std::size_t n) = 0; + + virtual void allocate(ciphertext& ct) = 0; + virtual void free(ciphertext ct) = 0; + virtual void serialize(ciphertext ct, void* buf, std::size_t& n) const = 0; + virtual void deserialize(ciphertext ct, const void* buf, std::size_t n) const = 0; + virtual void encrypt(const plaintext& pt, ciphertext ct) const = 0; + virtual void decrypt(ciphertext ct, plaintext& pt) const = 0; // private + virtual void add_cipher_plain(ciphertext a, const plaintext& b, ciphertext res) const = 0; + virtual void add_cipher_cipher(ciphertext a, ciphertext b, ciphertext res) const = 0; + virtual void sub_cipher_plain(ciphertext a, const plaintext& b, ciphertext res) const = 0; + virtual void sub_cipher_cipher(ciphertext a, ciphertext b, ciphertext res) const = 0; + virtual void mul_cipher_plain(ciphertext a, const plaintext& b, ciphertext res) const = 0; + virtual void mul_cipher_cipher(ciphertext a, ciphertext b, ciphertext res) const = 0; + virtual void rot_cipher_rows(ciphertext ct, int r, ciphertext res) const = 0; + virtual void swap_cipher_rows(ciphertext ct, ciphertext res) const = 0; + virtual void noise_budget(ciphertext ct, std::size_t& budget) const = 0; // private }; /*