templates.homomorphism module

Homomorphism abstract classes which must be implemented to be able to create a sigma protocol.

class templates.homomorphism.CompressibleHomomorphism(*args, **kwargs)[source]

Bases: Homomorphism[InputElementT, HomomorphismOutputT, ChallengeT], Protocol[InputElementT, HomomorphismOutputT, ChallengeT]

An abstract class which extends the Homomorphism-class with functions. The additional functions enable the compression mechanism to compress the sigma protocol.

__add__(other)[source]

Add two homomorphisms mapping from the same groups $mathbb{G}^n$ and $mathbb{H}$ to generate a new homomorphism.

Parameters:

other (object) – the homomorphism to add

Return type:

Self

Returns:

The new homomorphism also mapping from $mathbb{G}^n$ to $mathbb{H}$.

__mul__(other)[source]

Multiply the homomorphism by the challenge.

Parameters:

other (object) – the challenge to multiply by.

Return type:

Self

Returns:

A new homomorphism mapping from the same groups.

split_in_half()[source]

Split the homomorphism into two new homomorphisms where the input size is of length $n/2$. The homomorphisms are split into a left and right half and map from the same groups.

Return type:

tuple[Self, Self]

Returns:

Tuple of two homomorphisms with input size of $n/2$, with the left half being the first element and the right half being the second element of the tuple.

class templates.homomorphism.CompressibleHomomorphismInput(*args, **kwargs)[source]

Bases: HomomorphismInput[InputElementT], Protocol[InputElementT]

Homomorphism input which can also be compressed. For the compression the input must be able to be split into two halves.

split_in_half()[source]

Split the homomorphism input into two equal parts. Such that each part can evaluate an input vector of half the length.

Return type:

tuple[Self, Self]

Returns:

Tuple consisting of left and right homomorphism

class templates.homomorphism.Homomorphism(*args, **kwargs)[source]

Bases: Protocol[InputElementT, HomomorphismOutputT, ChallengeT]

The homomorphism class is a class consisting of abstract methods. The class must be able to take in a vector of length $n$ and evaluate to an output. The size of $n$ is determined by a local property called expected_input_size.

The homomorphism class is also known as the function $psi$ in literature.

The homomorphism assumes you can multiply the InputElement and HomomorphismOutput by the Challenge and that InputElement objects can be added together.

challenge_from_bytes(hash_bytes)[source]

Create a challenge from the bytes that are received. The bytes must create a consistent way of generating the challenge.

Parameters:

hash_bytes (bytes) – the bytes to generate the challenge from

Return type:

TypeVar(ChallengeT, covariant=True)

Returns:

a Challenge object derived from the bytes

evaluate(homomorphism_input)[source]

Apply the homomorphism to the input.

Parameters:

homomorphism_input (HomomorphismInput[TypeVar(InputElementT)]) – The input vector and any additional information necessary

Return type:

TypeVar(HomomorphismOutputT, bound= SupportsMultiplicationAndAddition)

Returns:

The output of the homomorphism applied to the input

property input_size: int

The length of the vector that can be processed by the homomorphism.

Returns:

integer indicating the length of the excepted vector input

output_to_bytes(output)[source]

Transform the homomorphism output to a representation in bytes.

Parameters:

output (TypeVar(HomomorphismOutputT, bound= SupportsMultiplicationAndAddition)) – The output to transform

Return type:

bytes

Returns:

bytes representing the homomorphism output

random_input()[source]

Generate a vector of length $n$ consisting of random input elements.

Return type:

HomomorphismInput[TypeVar(InputElementT)]

Returns:

List of $n$ random input elements

class templates.homomorphism.HomomorphismInput(*args, **kwargs)[source]

Bases: Protocol[InputElementT]

Input for a homomorphism. The input should be additively homomorphic and be able to multiply with the challenge generated by the homomorphism.

property input_vector: list[InputElementT]

The input vector to which a homomorphism is applied

Returns:

vector of input elements

class templates.homomorphism.SupportsMultiplicationAndAddition(*args, **kwargs)[source]

Bases: Protocol

Protocol which states that a multiplication function must be provided.

__add__(other)[source]

Add the object with another object and return the result :type other: object :param other: Object to do addition with :rtype: Self :return: The result of the addition

__mul__(other)[source]

Multiply the object with another object and return the result :type other: object :param other: Object to multiply with :rtype: Self :return: The result of the multiplication