hetorch.backend.base
Abstract backend interface for HE operations
Classes
Ciphertext(args, kwargs)
Abstract ciphertext representation
This is a base class that all backend-specific ciphertext implementations should inherit from.
HEBackend(args, kwargs)
Abstract interface for HE backend implementations
This defines the contract that all HE backends must implement, whether they are real (SEAL, OpenFHE) or fake (PyTorch simulation).
Methods:
bootstrap(self, ct: hetorch.backend.base.Ciphertext) -\> hetorch.backend.base.Ciphertext
Bootstrap ciphertext to refresh noise budget
Args: ct: Ciphertext to bootstrap
Returns: Bootstrapped ciphertext
Raises: NotImplementedError: If backend doesn't support bootstrapping
cadd(self, ct1: hetorch.backend.base.Ciphertext, ct2: hetorch.backend.base.Ciphertext) -\> hetorch.backend.base.Ciphertext
Ciphertext addition
Args: ct1: First ciphertext ct2: Second ciphertext
Returns: Result ciphertext (ct1 + ct2)
cmult(self, ct1: hetorch.backend.base.Ciphertext, ct2: hetorch.backend.base.Ciphertext) -\> hetorch.backend.base.Ciphertext
Ciphertext multiplication
Args: ct1: First ciphertext ct2: Second ciphertext
Returns: Result ciphertext (ct1 * ct2)
decrypt(self, ct: hetorch.backend.base.Ciphertext) -\> torch.Tensor
Decrypt a ciphertext to plaintext tensor
Args: ct: Ciphertext to decrypt
Returns: Decrypted tensor
encrypt(self, tensor: torch.Tensor, info: hetorch.core.ciphertext.CiphertextInfo = None) -\> hetorch.backend.base.Ciphertext
Encrypt a plaintext tensor
Args: tensor: Input tensor to encrypt info: Optional ciphertext metadata
Returns: Encrypted ciphertext
get_cost_model(self) -\> hetorch.backend.cost_model.CostModel
Return cost model for this backend
Returns: CostModel instance for estimating operation costs
get_supported_operations(self) -\> List[str]
Return list of supported HE operations
Returns: List of operation names (e.g., ["cadd", "cmult", "rotate"])
padd(self, ct: hetorch.backend.base.Ciphertext, pt: torch.Tensor) -\> hetorch.backend.base.Ciphertext
Add plaintext to ciphertext
Args: ct: Ciphertext pt: Plaintext tensor
Returns: Result ciphertext (ct + pt)
Raises: NotImplementedError: If backend doesn't support plaintext operations
pmult(self, ct: hetorch.backend.base.Ciphertext, pt: torch.Tensor) -\> hetorch.backend.base.Ciphertext
Multiply ciphertext by plaintext
Args: ct: Ciphertext pt: Plaintext tensor
Returns: Result ciphertext (ct * pt)
Raises: NotImplementedError: If backend doesn't support plaintext operations
rescale(self, ct: hetorch.backend.base.Ciphertext) -\> hetorch.backend.base.Ciphertext
Rescale ciphertext (CKKS)
Args: ct: Ciphertext to rescale
Returns: Rescaled ciphertext
Raises: NotImplementedError: If backend doesn't support rescaling
rotate(self, ct: hetorch.backend.base.Ciphertext, steps: int) -\> hetorch.backend.base.Ciphertext
Ciphertext rotation
Args: ct: Input ciphertext steps: Number of rotation steps
Returns: Rotated ciphertext