templates.asymmetric_encryption_scheme module¶
Generic classes used for creating an asymmetric encryption scheme.
- class templates.asymmetric_encryption_scheme.AsymmetricEncryptionScheme(public_key, secret_key, *_args, **_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, *_args, **_kwargs)[source]¶
Construct an AsymmetricEncryptionScheme with the given keypair and optional keyword arguments. All keyword arguments are combined with the public key to create an ID, so all the __init__ of a custom subclass of AsymmetricEncryptionScheme should pass all their parameter values as keyword arguments to this __init__ for the ID generation to work properly. If this does not happen, then schemes might be considered equal when they are totally different.
- 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.*_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.
- classmethod from_public_key(public_key, **kwargs)[source]¶
Generate a new AsymmetricEncryptionScheme from a public key (e.g. when received from another party) and possibly additional parameters.
- Parameters:
public_key (
TypeVar
(PK
, bound=PublicKey
)) – The PublicKey of this scheme instantiation.**kwargs (
Any
) – Optional extra keyword arguments for the constructor.
- Return type:
Self
- Returns:
A new EncryptionScheme.
- classmethod from_security_parameter(*args, **kwargs)[source]¶
Generate a new AsymmetricEncryptionScheme from a security parameter. Note that regular arguments will be passed to the generate_key_material method, so all parameter that are required for the constructor should be passed as keyword arguments.
- Parameters:
*args (
Any
) – Security parameter(s) for key generation.**kwargs (
Any
) – Security parameter(s) and optional extra arguments for the constructor.
- Raises:
ValueError – If a keyword argument is not valid for key generation or the constructor.
- Return type:
Self
- Returns:
A new EncryptionScheme.
- abstractmethod classmethod 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.
- 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(*args, **kwargs)[source]¶
Bases:
Protocol
Public Key of an AsymmetricEncryptionScheme.
This should be subclassed for every AsymmetricEncryptionScheme.
- static deserialize(obj, **_kwargs)[source]¶
Deserialization function for public keys, which will be passed to the communication module.
- Parameters:
obj (
Any
) – serialized version of a PublicKey.**_kwargs (
Any
) – optional extra keyword arguments
- Raises:
SerializationError – When communication library is not installed.
- Return type:
- Returns:
Deserialized PublicKey from the given dict.
- serialize(**_kwargs)[source]¶
Serialization function for public keys, which will be passed to the communication module.
- Parameters:
**_kwargs (
Any
) – Optional extra keyword arguments.- Raises:
SerializationError – When communication library is not installed.
- Return type:
Any
- Returns:
serialized version of this PublicKey.
- class templates.asymmetric_encryption_scheme.SecretKey(*args, **kwargs)[source]¶
Bases:
Protocol
Secret Key of an AsymmetricEncryptionScheme.
This should be subclassed for every AsymmetricEncryptionScheme.
- static deserialize(obj, **_kwargs)[source]¶
Deserialization function for public keys, which will be passed to the communication module.
- Parameters:
obj (
Any
) – serialized version of a SecretKey.**_kwargs (
Any
) – optional extra keyword arguments
- Raises:
SerializationError – When communication library is not installed.
- Return type:
- Returns:
Deserialized SecretKey from the given dict.
- serialize(**_kwargs)[source]¶
Serialization function for secret keys, which will be passed to the communication module.
- Parameters:
**_kwargs (
Any
) – Optional extra keyword arguments.- Raises:
SerializationError – When communication library is not installed.
- Return type:
Any
- Returns:
serialized version of this SecretKey.