templates.asymmetric_encryption_scheme module

Generic classes used for creating an asymmetric encryption scheme.

class templates.asymmetric_encryption_scheme.AsymmetricEncryptionScheme(public_key, secret_key, **_kwargs)[source]

Bases: Generic[KM, PT, RP, CV, CT, PK, SK], EncryptionScheme[KM, PT, RP, CV, CT], ABC

Abstract base class for an AsymmetricEncryptionScheme. Subclass of EncryptionScheme.

__init__(public_key, secret_key, **_kwargs)[source]

Construct an AsymmetricEncryptionScheme with the given keypair.

Parameters:
  • public_key (TypeVar(PK, bound= PublicKey)) – Asymmetric PublicKey.

  • secret_key (Optional[TypeVar(SK, bound= SecretKey)]) – Asymmetric SecretKey, might be None when the SecretKey is unknown.

  • kwargs – Possible extra parameters for this scheme.

classmethod from_public_key(public_key, **kwargs)[source]

Generate a new AsymmetricEncryptionScheme from a public key (e.g. when received from another party).

Parameters:
  • public_key (TypeVar(PK, bound= PublicKey)) – The PublicKey of this scheme instantiation. constructor.

  • kwargs (Any) – Optional extra arguments for the EncryptionScheme constructor.

Return type:

TypeVar(AE, bound= AsymmetricEncryptionScheme[Any, Any, Any, Any, Any, Any, Any])

Returns:

A new EncryptionScheme.

classmethod from_security_parameter(*args, **kwargs)[source]

Generate a new AsymmetricEncryptionScheme 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:

TypeVar(AE, bound= AsymmetricEncryptionScheme[Any, Any, Any, Any, Any, Any, Any])

Returns:

A new EncryptionScheme.

abstract static generate_key_material(*args, **kwargs)[source]

Method to generate key material (PublicKey and SecretKey) for this scheme.

Parameters:
  • args (Any) – Required arguments to generate said key material.

  • kwargs (Any) – Required arguments to generate said key material.

Return type:

TypeVar(KM)

Returns:

Tuple containing first the PublicKey of this scheme and then the SecretKey.

classmethod get_instance_from_public_key(public_key, **kwargs)[source]

Generate a new AsymmetricEncryptionScheme from a public key (e.g. when received from another party).

Parameters:
  • public_key (PublicKey) – The PublicKey of this scheme instantiation. constructor.

  • kwargs (Any) – Optional extra arguments for the EncryptionScheme constructor.

Return type:

TypeVar(AE, bound= AsymmetricEncryptionScheme[Any, Any, Any, Any, Any, Any, Any])

Returns:

A new EncryptionScheme.

classmethod get_instance_from_sec_param(*sec_params, **kw_sec_params)[source]

Function that makes sure that when an instance of the given class has already instantiated before with similar security parameter, a reference is returned to that scheme

Parameters:
  • sec_params (Any) – positional security parameters

  • kw_sec_params (Any) – keyword security parameters

Return type:

TypeVar(AE, bound= AsymmetricEncryptionScheme[Any, Any, Any, Any, Any, Any, Any])

Returns:

Either a newly instantiated scheme or a reference to an already existing scheme

classmethod id_from_sec_param(*sec_params, **kw_sec_params)[source]

Function that returns an identifier based on the security parameters

Parameters:
  • sec_params (Any) – positional security parameters

  • kw_sec_params (Any) – keyword security parameters

Return type:

int

Returns:

identifier of type int

property public_key: PK

PublicKey of this instantiation of the scheme.

Returns:

PublicKey of this instantiation.

property secret_key: SK | None

SecretKey of this instantiation of the scheme.

Returns:

SecretKey of this instantiation, or None when it is unknown.

class templates.asymmetric_encryption_scheme.PublicKey[source]

Bases: object

Public Key of an AsymmetricEncryptionScheme.

This should be subclassed for every AsymmetricEncryptionScheme.

class templates.asymmetric_encryption_scheme.SecretKey[source]

Bases: object

Secret Key of an AsymmetricEncryptionScheme.

This should be subclassed for every AsymmetricEncryptionScheme.