shamir.shamir module¶
Utility for Shamir secret sharing.
- class shamir.shamir.ShamirSecretSharingScheme(modulus, number_of_parties, polynomial_degree)[source]¶
Bases:
object
Class with Shamir Secret sharing functionality.
- __eq__(other)[source]¶
Compare equality between this ShamirSecretSharingScheme and the other object.
- Parameters:
other (
object
) – Object to compare with.- Return type:
bool
- Returns:
Boolean stating (in)equality
- __init__(modulus, number_of_parties, polynomial_degree)[source]¶
Initialize a $t$-out-of-$n$ secret sharing scheme where
$t$ = text{polynomial_degree} + 1$
$n$ = text{number_of_parties}$
Note that polynomial_degree is the same as the corruption threshold.
- Parameters:
modulus (
int
) – prime modulus of the coefficients in the polynomials used to create sharesnumber_of_parties (
int
) – number of shares that need to be created for each sharingpolynomial_degree (
int
) – degree of the polynomials used to create shares
- serialize()[source]¶
Serialization function
- Return type:
dict
[str
,int
]- Returns:
json object containing the necessary information to deserialize
Function that creates shares of a value for each party.
- Parameters:
secret (
int
) – secret to be shared- Return type:
- Returns:
sharing of the secret
- property van_der_monde: list[list[int]]¶
Vandermonde matrix for evaluation of polynomials at points [1,..,n]. This essentialy creates a matrix that precomputes i**j for all possible i**j that are needed for the evaluation of sharing polynomials. We now have that i**j = Vm[i][j]. To evaluate a polynomial p(x) = a0 + a1 * x + … + ad * x**d we can simply compute a0 * Vm[x][0] + a1 * Vm[x][1] + … + ad * Vm[x][d].
- Returns:
A VanDerMonde matrix of dimpensions self.polynomial_degree + 1 x self.number_of_parties
Bases:
object
Class that keeps track of the shares for a certain value
Add the shares belonging to the two given ShamirShares values together.
- Parameters:
other (
ShamirShares
) – Shares to be added to these shares.- Raises:
ValueError – In case a different secret sharing scheme was used.
- Return type:
- Returns:
New ShamirShares object where the shares have been added together.
Multiply the shares belonging to the two given ShamirShares values together. Only possible when both schemes are the same.
- Parameters:
other (
ShamirShares
) – Shares to be multiplied with these shares.- Return type:
- Returns:
New ShamirShares object where the shares have been multiplied together.
Multiply the shares belonging to this value with a given scalar integer or IntegerShares object. Note: This operation returns a Shamir sharing which inherits the statistical security of the integer sharing and should therefore only be used with caution.
- Parameters:
other (
Any
) – IntegerShares or scalar to be multiplied with these shares.- Raises:
ValueError – raised when shares are incompatible.
- Return type:
- Returns:
New ShamirShares object where the shares have been multiplied together.
String formatted version of this ShamirShares object.
- Return type:
str
- Returns:
Pretty string.
Subtract other ShamirShares (subtrahend) from these ShamirShares(minuend).
- Parameters:
other (
ShamirShares
) – Shares to be subtracted from these shares.- Raises:
ValueError – In case a different secret sharing scheme was used.
- Return type:
- Returns:
New ShamirShares object representing the difference between these shares and other.
Function that uses the shares from other parties to reconstruct the secret
- Raises:
ValueError – In case not enough shares are known to reconstruct the secret.
- Return type:
int
- Returns:
original secret
Serialization function
- Return type:
dict
[str
,int
|dict
[int
,int
] |dict
[str
,int
] |dict
[str
,dict
[str
,int
]]]- Returns:
json object containing the necessary information to deserialize