templates.randomized_encryption_scheme module
Generic classes for creating an EncryptionScheme that allows for precomputed, or stored randomness.
- class templates.randomized_encryption_scheme.RandomizableCiphertext(raw_value, scheme, *, fresh=False)[source]
Bases:
Generic
[KM
,PT
,RP
,CV
,RR
],Ciphertext
[KM
,PT
,RP
,CV
],ABC
Ciphertext that can be rerandomized. Subclass of Ciphertext.
- __init__(raw_value, scheme, *, fresh=False)[source]
Construct a RandomizableCiphertext, with the given value for the given EncryptionScheme.
- Parameters:
raw_value (
Any
) – Ciphertext value.scheme (
RandomizedEncryptionScheme
[TypeVar
(KM
),TypeVar
(PT
),TypeVar
(RP
),TypeVar
(CV
),Self
,TypeVar
(RR
)]) – RandomizedEncryptionScheme that is used to encrypt this ciphertext.fresh (
bool
) – Indicates whether fresh randomness is already applied to the raw_value.
- Raises:
TypeError – When scheme has the incorrect type.
- abstract apply_randomness(randomization_value)[source]
Apply a random value to rerandomize this ciphertext.
- Parameters:
randomization_value (
TypeVar
(RR
)) – Random value used to rerandomize this ciphertext.- Return type:
None
- property fresh: bool
Indicate whether the ciphertest has fresh randomness.
Ciphertexts that are send to other parties should generally be fresh. This can be achieved by calling self.randomize().
- Returns:
True if the randomness is fresh, False otherwise.
- get_value()[source]
Get the raw value of the ciphertext.
Accessing this value marks the ciphertext as not fresh. If this is not desired, call the peek_value method.
- Return type:
TypeVar
(CV
)- Returns:
Value of the ciphertext
- peek_value()[source]
Peek at the raw value of the ciphertext.
Accessing this value does not change the freshness of the ciphertext. If this is not desired, call the get_value method.
- Return type:
TypeVar
(CV
)- Returns:
Value of the ciphertext
- randomize()[source]
Rerandomize this ciphertext object.
- Return type:
Self
- Returns:
The rerandomized object (self).
-
scheme:
RandomizedEncryptionScheme
[TypeVar
(KM
),TypeVar
(PT
),TypeVar
(RP
),TypeVar
(CV
),Any
,TypeVar
(RR
)]
- property value: CV
Raw value of the ciphertext.
- Returns:
Value of the ciphertext
- class templates.randomized_encryption_scheme.RandomizedEncryptionScheme(debug=False)[source]
Bases:
Generic
[KM
,PT
,RP
,CV
,RC
,RR
],EncryptionScheme
[KM
,PT
,RP
,CV
,RC
],ABC
Abstract base class for a RandomizedEncryptionScheme. Subclass of EncryptionScheme
- __init__(debug=False)[source]
Initiate a RandomizedEncryptionScheme.
- Parameters:
debug (
bool
) – Flag to determine whether debug information should be displayed.
- boot_randomness_generation(amount, max_workers=None)[source]
Boots processes to generate randomness.
Creates new randomness-generating processes if none exist yet. If they already exist, request them to generate more randomness.
More specifically: if no ProcessSource is yet registered to the internal RandomnessManager, then such a source is registered with priority -10.
NOTE: Please call shut_down after user the scheme to ensure that all sources are shut down properly!
- Parameters:
amount (
int
) – Amount of random values to generate (additionally).max_workers (
Optional
[int
]) – Number of workers that generate randomness in parallel. If None, then this will default to the number of CPUs on the current device. This parameter is ignored if there already are randomness-generating processes.
- Return type:
None
- get_randomness()[source]
Get new randomness from the randomness source.
- Return type:
TypeVar
(RR
)- Returns:
One random value.
- register_randomness_source(*args, **kwargs)[source]
Register a new source of randomness.
For the parameters, see
RandomnessManager.register_source()
.- Return type:
None
- shut_down()[source]
Shut down scheme’s randomness manager and inform user of mismatch in amount of randomness requested and randomness used if applicable.
Give the shut down signal to the scheme’s randomness to shut down all managed sources. If the amount of randomness generated via boot_randomness_generation is not equal to the amount of randomness used by the scheme, a warning is issued to inform the user of the mismatch. This allows the user to tune the amount of pregenerated randomness and improve efficiency.
- Return type:
None
- unsafe_encrypt(plaintext, apply_encoding=True)[source]
Encrypts the entered (encoded) Plaintext, but does not apply randomness. 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
(RC
, bound= RandomizableCiphertext[Any, Any, Any, Any, Any])- Returns:
Non-randomized RandomizableCiphertext object containing the encrypted value of the plaintext.
- exception templates.randomized_encryption_scheme.RandomizedEncryptionSchemeWarning[source]
Bases:
UserWarning
Issued for warnings related to the randomness generation.
- exception templates.randomized_encryption_scheme.TooLittleRandomnessWarning[source]
Bases:
RandomizedEncryptionSchemeWarning
Issued when less randomness has been generated than required by the protocol, resulting in randomness needing to be generated on the fly.
- exception templates.randomized_encryption_scheme.TooMuchRandomnessWarning[source]
Bases:
RandomizedEncryptionSchemeWarning
Issued when more randomness has been generated than used by the protocol.