venumML.venumpy.small_glwe

class Ciphertext:

Represents an encrypted ciphertext in the cryptographic scheme.

This class allows for homomorphic operations (addition, subtraction, multiplication) on ciphertexts and supports serialization to/from JSON format.

Attributes
  • _raw_cipher (object): The underlying raw ciphertext from the bindings.
  • _context (object): The context in which the ciphertext was created (either public or secret).
Ciphertext(raw_cipher, context)

Initializes a new ciphertext from a raw ciphertext and context.

Parameters
  • raw_cipher (object): The raw ciphertext object from the bindings.
  • context (object): The context associated with the ciphertext.
def decrypt(self):

Decrypts a ciphertext.

Returns
  • object: The decrypted value.
def into_json(self):

Serializes the ciphertext into a JSON format.

Returns
  • str: A JSON string representation of the ciphertext.
@staticmethod
def from_json(context, cipher_json):

Deserializes a JSON representation of a ciphertext.

Parameters
  • context (object): The context to associate with the deserialized Ciphertext.
  • cipher_json (str): The JSON string representing the ciphertext.
Returns
  • Ciphertext: A new Ciphertext object.
def into_bytes(self):

Serializes the ciphertext into bytes.

Returns
  • bytes: A byte representation of the ciphertext.
@staticmethod
def from_bytes(context, cipher_bytes):

Deserializes a byte representation of a ciphertext.

Parameters
  • context (object): The context to associate with the deserialized Ciphertext.
  • cipher_bytes (bytes): The bytes representing the ciphertext.
Returns
  • Ciphertext: A new Ciphertext object.
class Context:

Represents a general cryptographic context.

Provides methods to serialize and manage the precision of computations.

Attributes
  • _raw_ctx (object): The raw context object from the bindings.
def into_json(self):

Serializes the context into a JSON format.

Returns
  • str: A JSON string representation of the context.
def into_bytes(self):

Serializes the context into a byte format.

Returns
  • bytes: A byte representation of the context.
precision

Gets the floating point precision of the context.

Returns
  • int: The current precision.
class SecretContext(Context):

Represents a secret cryptographic context, used for key generation and decryption.

Attributes
  • _raw_ctx (object): The underlying raw secret context from the bindings.
SecretContext(bits_of_security=128, generate=True)

Initializes a new secret context.

Parameters
  • bits_of_security (int, optional): The bits of security for the cryptographic context (default is 128).
  • generate (bool, optional): Whether to generate a new secret context (default is True).
def encrypt(self, plaintext):

Encrypts a plaintext value using this secret context.

Parameters
  • plaintext (object): The value to encrypt.
Returns
  • Ciphertext: The encrypted value as a Ciphertext object.
def decrypt(self, ciphertext):

Decrypts a ciphertext using this secret context.

Parameters
  • ciphertext (Ciphertext): The Ciphertext object to decrypt.
Returns
  • object: The decrypted value.
def into_public(self):

Converts this secret context into a public context.

Returns
  • PublicContext: A new PublicContext object.
@classmethod
def from_json(cls, ctx_json):

Deserializes a secret context from a JSON string.

Parameters
  • ctx_json (str): The JSON string representing the secret context.
Returns
  • SecretContext: A new SecretContext object.
@classmethod
def from_bytes(cls, ctx_bytes):

Deserializes a secret context from byte representation.

Parameters
  • ctx_bytes (bytes): The bytes representing the secret context.
Returns
  • SecretContext: A new SecretContext object.
class PublicContext(Context):

Represents a public cryptographic context, used for encryption.

A PublicContext is generated from a SecretContext and allows for encryption operations, but not decryption.

Attributes
  • _raw_ctx (object): The raw public context object from the bindings.
PublicContext(generate=False)

Initializes a new public context.

Parameters
  • generate (bool, optional): Whether to generate a new public context (default is False).
def encrypt(self, plaintext):

Encrypts the provided plaintext values.

Parameters
  • plaintext (object): The value to encrypt.
Raises
  • Exception: Raised because public encryption is currently not supported.
Returns
  • None
def decrypt(self, ciphertext):

Decrypts the provided ciphertext.

Raises
  • Exception: Raised because public decryption is currently not supported.
Returns
  • None
@classmethod
def from_json(cls, ctx_json):

Deserializes a public context from a JSON string.

Parameters
  • ctx_json (str): The JSON string representing the public context.
Returns
  • PublicContext: A new PublicContext object.
@classmethod
def from_bytes(cls, ctx_bytes):

Deserializes a public context from byte representation.

Parameters
  • ctx_bytes (bytes): The bytes representing the public context.
Returns
  • PublicContext: A new PublicContext object.