templates.symmetric_encryption_scheme module

Generic classes used for creating a symmetric encryption scheme.

class templates.symmetric_encryption_scheme.SymmetricEncryptionScheme(key, **_kwargs)[source]

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

Abstract base class for a SymmetricEncryptionScheme. Subclass of EncryptionScheme.

__eq__(other)[source]

Compare equality of two SymmetricEncryptionSchemes

Parameters:

other (object) – The other object to compare with.

Raises:

TypeError – When the type of the other object is not the same is of this scheme.

Return type:

bool

Returns:

Boolean value representing (in)equality of self and other.

__init__(key, **_kwargs)[source]

Construct a SymmetricEncryptionScheme with the given key.

Parameters:
  • key (TypeVar(SK, bound= SymmetricKey)) – Symmetric key.

  • kwargs – Possible extra parameters for this scheme.

classmethod deserialize(json)[source]

Construct this scheme from the serialization.

Parameters:

json (Dict[str, Dict[str, int]]) – Serialization of this scheme.

Return type:

TypeVar(SE, bound= SymmetricEncryptionScheme[Any, Any, Any, Any, Any])

Returns:

An initialized version of this scheme.

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

Generate a new SymmetricEncryptionScheme from a security parameter.

Parameters:
  • args (Any) – Security parameter(s) and optional extra arguments for the SymmetricEncryptionScheme constructor.

  • kwargs (Any) – Security parameter(s) and optional extra arguments for the SymmetricEncryptionScheme constructor.

Return type:

TypeVar(SE, bound= SymmetricEncryptionScheme[Any, Any, Any, Any, Any])

Returns:

Symmetric cryptographic scheme

static generate_key_material(bit_length, *_args, **_kwargs)[source]

Method to generate key material (SymmetricKey) for this scheme.

Parameters:
  • bit_length (int) – Desired bit security of the secret key

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

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

Return type:

SymmetricKey

Returns:

The SymmetricKey that was generated.

property key: SK

SymmetricKey of this instantiation of the scheme.

Returns:

SymmetricKey of this instantiation.

serialize()[source]

Serialize the key of this encryption scheme.

Return type:

Dict[str, Dict[str, int]]

Returns:

Serialized key.

class templates.symmetric_encryption_scheme.SymmetricKey(key_value)[source]

Bases: object

Class for storing and generating symmetric key material

classmethod deserialize(json)[source]

Construct this key from its serialization.

Parameters:

json (Dict[str, int]) – Serialization of this key.

Return type:

SymmetricKey

Returns:

An initialized version of this key.

classmethod from_sec_param(sec_param)[source]

Class method that generates a uniformly random secret key

Parameters:

sec_param (int) – bit security of the key to be generated

Return type:

SymmetricKey

Returns:

uniformly random symmetric key with bit security equal to sec_param

serialize()[source]

Serialize this symmetric key.

Return type:

Dict[str, int]

Returns:

Dictionary object containing the value of this key.

classmethod to_bits(to_convert)[source]

Class method that converts alternate representations of a symmetric key to the right format

Parameters:

to_convert (Union[bytes, str]) – variable of type bytes or str (of format ‘0b{0,1}*’) to be converted

Return type:

List[int]

Returns:

list of integers in that are either 0 or 1