templates.encryption_scheme module¶
Generic classes used for creating an encryption scheme.
- class templates.encryption_scheme.Ciphertext(raw_value, scheme, **_kwargs)[source]¶
Bases:
Generic[CV]Ciphertext objects support addition and multiplication by plaintext scalars.
- abstractmethod __eq__(other)[source]¶
Method that determines whether two Ciphertexts are the same.
- Parameters:
other (
object) – Ciphertext to be compared to Self.- Return type:
bool- Returns:
Boolean indicating whether they are the same.
- __init__(raw_value, scheme, **_kwargs)[source]¶
Constructs a Ciphertext with the given ciphertext value encrypted using the specified scheme.
- Parameters:
raw_value (
TypeVar(CV)) – value of the ciphertextscheme (
EncryptionScheme[Any,Any,Any,Self]) – encryption scheme used for creating this ciphertext**_kwargs (
Any) – Optional extra keyword arguments for the constructor.
- scheme:
EncryptionScheme[Any,Any,Any,Self]¶
- property value: CV¶
Raw value of the ciphertext.
- Returns:
Value of the ciphertext.
- class templates.encryption_scheme.EncodedPlaintext(value, scheme)[source]¶
Bases:
Generic[RP]Class that contains the encoding of a plaintext for a particular scheme.
Constructs an EncodedPlaintext with the given value and encoding as specified in the scheme.
- Parameters:
value (
TypeVar(RP)) – value of the plaintext after encodingscheme (
EncryptionScheme[Any,Any,TypeVar(RP),Any]) – encryption scheme that specifies the used encoding
- Raises:
TypeError – provided scheme has the incorrect type.
- __post_init__()[source]¶
Validate encryption scheme.
- Raises:
TypeError – Scheme is of the wrong type.
- Return type:
None
- scheme:
EncryptionScheme[Any,Any,TypeVar(RP),Any]¶
- value:
TypeVar(RP)¶
- class templates.encryption_scheme.EncryptionScheme(*_args, **_kwargs)[source]¶
Bases:
InstanceManagerMixin,ABC,Generic[KM,PT,RP,CT]Abstract base class to define generic Homomorphic Encryption Scheme functionality. Can be used for all kinds of encryption schemes.
Most easily constructed using the from_security_parameter method.
- abstractmethod __eq__(other)[source]¶
Method that determines whether two EncryptionSchemes are the same.
- Parameters:
other (
object) – EncryptionScheme to be compared to Self.- Return type:
bool- Returns:
Boolean indicating whether they are the same.
- __init__(*_args, **_kwargs)[source]¶
Construct a new EncryptionScheme.
- Parameters:
*_args (
Any) – Optional extra arguments for the constructor of a concrete implementation.**_kwargs (
Any) – Optional extra keyword arguments for the constructor of a concrete implementation.
- abstractmethod decode(encoded_plaintext)[source]¶
Decode an EncodedPlaintext using the specified encoding scheme.
- Parameters:
encoded_plaintext (
EncodedPlaintext[TypeVar(RP)]) – Plaintext to be decoded.- Return type:
TypeVar(PT)- Returns:
Decoded Plaintext value
- decrypt(ciphertext, apply_encoding=True)[source]¶
Decrypts the input ciphertext.
- Parameters:
ciphertext (
TypeVar(CT, bound= Ciphertext[Any])) – Ciphertext to be decrypted.apply_encoding (
bool) – Boolean indicating whether the decrypted ciphertext is decoded before it is returned.
- Return type:
TypeVar(PT)- Returns:
Plaintext decrypted value.
- decrypt_sequence(ciphertext_sequence, apply_encoding=True)[source]¶
Decrypts the list of input ciphertext.
- Parameters:
ciphertext_sequence (
Iterable[TypeVar(CT, bound= Ciphertext[Any])]) – Sequence of Ciphertext to be decrypted.apply_encoding (
bool) – Boolean indicating whether the decrypted ciphertext is decoded before it is returned.
- Return type:
Iterator[TypeVar(PT)]- Returns:
A list of Plaintext decrypted values.
- abstractmethod encode(plaintext)[source]¶
Encode a supported Plaintext using the specified encoding scheme.
- Parameters:
plaintext (
TypeVar(PT)) – Plaintext to be encoded.- Return type:
EncodedPlaintext[TypeVar(RP)]- Returns:
EncodedPlaintext object containing the encoded value.
- encrypt(plaintext, apply_encoding=True)[source]¶
Encrypts the entered (encoded) Plaintext. Also encodes the Plaintext when this is required.
- Parameters:
plaintext (
Union[TypeVar(PT),EncodedPlaintext[TypeVar(RP)]]) – Plaintext or EncodedPlaintext to be encrypted.apply_encoding (
bool) – Boolean indicating whether a non-encoded plaintext should be encoded. If False, the plaintext is encrypted in raw form.
- Return type:
TypeVar(CT, bound= Ciphertext[Any])- Returns:
Ciphertext object containing the encrypted value of the plaintext.
- encrypt_sequence(plaintext_sequence, apply_encoding=True)[source]¶
Encrypts the entered sequence of (encoded) Plaintext. Also encodes a Plaintext when this is required.
- Parameters:
plaintext_sequence (
Iterable[TypeVar(PT)] |Iterable[EncodedPlaintext[TypeVar(RP)]]) – Sequence of Plaintext or EncodedPlaintext to be encrypted.apply_encoding (
bool) – Boolean indicating whether a non-encoded plaintext should be encoded. If False, the plaintext is encrypted in raw form.
- Return type:
Iterator[TypeVar(CT, bound= Ciphertext[Any])]- Returns:
Ciphertext object containing the encrypted value of the plaintext.
- abstractmethod classmethod from_security_parameter(*args, **kwargs)[source]¶
Generate a new EncryptionScheme from a security parameter.
- Parameters:
*args (
Any) – Security parameter(s) and optional extra arguments for the EncryptionScheme constructor.**kwargs (
Any) – Security parameter(s) and optional extra arguments for the EncryptionScheme constructor.
- Return type:
Self- Returns:
A new EncryptionScheme.
- abstractmethod static generate_key_material(*args, **kwargs)[source]¶
Method to generate key material (format depending on the type of scheme) for this scheme.
- Parameters:
*args (
Any) – Required arguments to generate said key material.**kwargs (
Any) – Required keyword arguments to generate said key material.
- Return type:
TypeVar(KM)