templates.homomorphic_encryption_scheme module

Abstract base classes for various types of Homomorphic Encryption Schemes.

class templates.homomorphic_encryption_scheme.AdditiveHomomorphicCiphertext(raw_value, scheme, *, fresh=False)[source]

Bases: HomomorphicCiphertext[PT, CV, RR]

AdditiveHomomorphicCiphertext objects delegate binary operations such as addition and multiplication to the corresponding additive homomorphic encryption scheme.

__add__(other)[source]

Add other to the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to add to self.

Return type:

Self

Returns:

Addition of other to this ciphertext.

__mul__(other)[source]

Multiply other with the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Return type:

Self

Returns:

Multiplication of other with this ciphertext.

__neg__()[source]

Negate the underlying plaintext of this ciphertext.

Return type:

Self

Returns:

Negated ciphertext.

__radd__(other)

Add other to the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to add to self.

Return type:

Self

Returns:

Addition of other to this ciphertext.

__rmul__(other)

Multiply other with the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Return type:

Self

Returns:

Multiplication of other with this ciphertext.

__rsub__(other)[source]

Subtract other from the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to subtract from.

Return type:

Self

Returns:

Subtraction of other from this ciphertext.

__sub__(other)[source]

Subtract other from the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to subtract from self.

Raises:

TypeError – The other object has an unsupported type for subtraction from this ciphertext.

Return type:

Self

Returns:

Subtraction of other from this ciphertext.

scheme: AdditiveHomomorphicEncryptionScheme[Any, TypeVar(PT), Any, Self, TypeVar(RR)]
class templates.homomorphic_encryption_scheme.AdditiveHomomorphicEncryptionScheme(debug=False)[source]

Bases: HomomorphicEncryptionScheme[KM, PT, RP, AdditiveHomomorphicCT, RR], ABC

Abstract base class to define Additive Homomorphic Encryption Scheme functionality.

Most easily constructed using the from_security_parameter method.

abstractmethod add(ciphertext, other)[source]

Add the underlying plaintext value of ciphertext with the (underlying) plaintext value of other. Where other can either be another ciphertext or a plaintext, depending on the scheme.

Parameters:
  • ciphertext (TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any])) – First Ciphertext of which the underlying plaintext is added.

  • other (Union[TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any]), TypeVar(PT)]) – Plaintext or ciphertext to add to self.

Raises:

NotImplementedError – Raised when addition is not supported by this scheme.

Return type:

TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any])

Returns:

A Ciphertext containing the encryption of the addition of both values.

abstractmethod mul(ciphertext, other)[source]

Multiply the underlying plaintext value of ciphertext with a plaintext value.

Parameters:
  • ciphertext (TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any])) – Ciphertext of which the underlying plaintext is multiplied.

  • other (Union[TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any]), TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Raises:

NotImplementedError – Raised when multiplication is not supported by this scheme.

Return type:

TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any])

Returns:

A Ciphertext containing the encryption of the product of both values.

abstractmethod neg(ciphertext)[source]

Negate the underlying plaintext of this ciphertext. I.e. if the original plaintext of this ciphertext was 5 this method returns the ciphertext that has -5 as underlying plaintext.

Parameters:

ciphertext (TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any])) – Ciphertext of which the underlying plaintext should be negated.

Raises:

NotImplementedError – Raised when negation is not supported by this scheme.

Return type:

TypeVar(AdditiveHomomorphicCT, bound= AdditiveHomomorphicCiphertext[Any, Any, Any])

Returns:

Ciphertext object corresponding to the negated plaintext.

class templates.homomorphic_encryption_scheme.FullyHomomorphicCiphertext(raw_value, scheme, *, fresh=False)[source]

Bases: AdditiveHomomorphicCiphertext[PT, CV, RR], MultiplicativeHomomorphicCiphertext[PT, CV, RR]

MultiplicativeHomomorphicCiphertext objects delegate binary operations such as multiplication to the corresponding additive homomorphic encryption scheme.

__mul__(other)[source]

Multiply other with the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Return type:

Self

Returns:

Multiplication of other with this ciphertext.

__rmul__(other)

Multiply other with the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Return type:

Self

Returns:

Multiplication of other with this ciphertext.

scheme: FullyHomomorphicEncryptionScheme[Any, TypeVar(PT), Any, Self, TypeVar(RR)]
class templates.homomorphic_encryption_scheme.FullyHomomorphicEncryptionScheme(debug=False)[source]

Bases: AdditiveHomomorphicEncryptionScheme[KM, PT, RP, FullyHomomorphicCT, RR], MultiplicativeHomomorphicEncryptionScheme[KM, PT, RP, FullyHomomorphicCT, RR]

Abstract base class for Fully Homomorphic Encryption Schemes.

class templates.homomorphic_encryption_scheme.HomomorphicCiphertext(raw_value, scheme, *, fresh=False)[source]

Bases: Generic[PT, CV, RR], RandomizableCiphertext[CV, RR]

HomomorphicCiphertext objects delegate relevant binary operations to the corresponding homomorphic encryption scheme.

scheme: HomomorphicEncryptionScheme[Any, TypeVar(PT), Any, Self, TypeVar(RR)]
class templates.homomorphic_encryption_scheme.HomomorphicEncryptionScheme(debug=False)[source]

Bases: RandomizedEncryptionScheme[KM, PT, RP, HomomorphicCT, RR]

Abstract base class to define generic Homomorphic Encryption Scheme functionality.

Most easily constructed using the from_security_parameter method.

__init__(debug=False)

Initiate a RandomizedEncryptionScheme.

Parameters:

debug (bool) – Flag to determine whether debug information should be displayed.

class templates.homomorphic_encryption_scheme.MultiplicativeHomomorphicCiphertext(raw_value, scheme, *, fresh=False)[source]

Bases: HomomorphicCiphertext[PT, CV, RR]

MultiplicativeHomomorphicCiphertext objects delegate binary operations such as multiplication to the corresponding additive homomorphic encryption scheme.

__mul__(other)[source]

Multiply other with the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Return type:

Self

Returns:

Multiplication of other with this ciphertext.

__rmul__(other)

Multiply other with the underlying plaintext of this ciphertext.

Parameters:

other (Union[Self, TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Return type:

Self

Returns:

Multiplication of other with this ciphertext.

scheme: MultiplicativeHomomorphicEncryptionScheme[Any, TypeVar(PT), Any, Self, TypeVar(RR)]
class templates.homomorphic_encryption_scheme.MultiplicativeHomomorphicEncryptionScheme(debug=False)[source]

Bases: HomomorphicEncryptionScheme[KM, PT, RP, MultiplicativeHomomorphicCT, RR], ABC

Abstract base class to define Multiplicative Homomorphic Encryption Scheme functionality.

Most easily constructed using the from_security_parameter method.

abstractmethod mul(ciphertext, other)[source]

Multiply the underlying plaintext value of ciphertext with the (underlying) plaintext value of other. Where other can either be another ciphertext or a plaintext, depending on the scheme.

Parameters:
  • ciphertext (TypeVar(MultiplicativeHomomorphicCT, bound= MultiplicativeHomomorphicCiphertext[Any, Any, Any])) – First Ciphertext of which the underlying plaintext is multiplied.

  • other (Union[TypeVar(MultiplicativeHomomorphicCT, bound= MultiplicativeHomomorphicCiphertext[Any, Any, Any]), TypeVar(PT)]) – Plaintext or ciphertext to multiply with.

Raises:

NotImplementedError – Raised when multiplication is not supported by this scheme.

Return type:

TypeVar(MultiplicativeHomomorphicCT, bound= MultiplicativeHomomorphicCiphertext[Any, Any, Any])

Returns:

A Ciphertext containing the encryption of the product of both values.

class templates.homomorphic_encryption_scheme.SupportsNeg(*args, **kwargs)[source]

Bases: Protocol[T_co]

An ABC with one abstract method __neg__.