mpyc.secgroups
index
github.com/lschoe/mpyc/blob/v0.10/mpyc/secgroups.py

This module provides secure (secret-shared) types of finite groups in MPyC.
 
Secure versions of all groups supported by the module mpyc.fingroups are available:
symmetric groups, quadratic residues, elliptic curve groups, and class groups.

 
Modules
       
asyncio
mpyc.asyncoro
mpyc.fingroups
functools
inspect
itertools
mpyc

 
Classes
       
mpyc.asyncoro.SecureObject(builtins.object)
SecureFiniteGroup
SecureClassGroupForm
SecureEllipticCurvePoint
SecureQuadraticResidue
SecureSchnorrGroupElement
SecureSymmetricGroupElement

 
class SecureClassGroupForm(SecureFiniteGroup)
    SecureClassGroupForm(value=None)
 
Common base class for secure (secret-shared) class group forms.
 
 
Method resolution order:
SecureClassGroupForm
SecureFiniteGroup
mpyc.asyncoro.SecureObject
builtins.object

Methods defined here:
__getitem__(self, key)
__init__(self, value=None)
Ensure all coefficients are of secure type.
 
Enforce value is a tuple.
set_share(self, value)
Set share to the given value.
 
The share is set directly (or recursively, for a composite SecureObject),
using callbacks if value contains Futures that are not yet done.

Class methods defined here:
decode(M, Z) from builtins.type
equality(f1, f2, /) from builtins.type
Return a == b.
inversion(f, /) from builtins.type
Return @-inverse of a (written ~a).
operation(f1, f2, /) from builtins.type
Return a @ b.
operation2(f, /) from builtins.type
Return a @ a.

Data and other attributes defined here:
__annotations__ = {}

Methods inherited from SecureFiniteGroup:
__add__(self, other)
__eq__(self, other)
Return self==value.
__invert__(self)
__matmul__(self, other)
__mul__(self, other)
__ne__(self, other)
Return self!=value.
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rmatmul__(self, other)
__rmul__(self, other)
__rsub__(self, other)
__rtruediv__(self, other)
__sub__(self, other)
__truediv__(self, other)
__xor__(self, other)
inverse(self)
For ease of use.

Class methods inherited from SecureFiniteGroup:
if_else(c, a, b) from builtins.type
Secure selection based on binary condition c between group elements a and b.
 
Condition c must be of a secure number type compatible with the group,
and its value should be 0 or 1. Input a must be compatible with the group as
well, either of the secure type cls or of type cls.group. Same for input b.
repeat(a, x) from builtins.type
Return xth @-power of a (written a^x), for any integral number x.
 
Base a is either a public or a secure group element.
Exponent x is either a public or a secure integral number.
Possibly a, x are lists (of same length)
repeat_public(a, x) from builtins.type

Data and other attributes inherited from SecureFiniteGroup:
__hash__ = None
identity = None

Methods inherited from mpyc.asyncoro.SecureObject:
__array_function__(self, func, types, args, kwargs)
Redirect __array_function__ call to array class, if any.
 
To support calls like np.block([[secint(9), -1], [1, secint(7)]]).
__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
Delegate __array_ufunc__ call to corresponding operator call.
 
Provisional support for calls like np.less(secint(9), 10).
__bool__(self)
Use of secret-shared objects in Boolean expressions makes no sense.
__deepcopy__(self, memo)
Let SecureObjects behave as immutable objects.
 
Introduced for github.com/meilof/oblif.

Data descriptors inherited from mpyc.asyncoro.SecureObject:
share

 
class SecureEllipticCurvePoint(SecureFiniteGroup)
    SecureEllipticCurvePoint(value=None)
 
Common base class for secure (secret-shared) elliptic curve points.
 
 
Method resolution order:
SecureEllipticCurvePoint
SecureFiniteGroup
mpyc.asyncoro.SecureObject
builtins.object

Methods defined here:
__getitem__(self, key)
__init__(self, value=None)
Ensure all coefficients are of secure field type.
 
Enforce value is a tuple.
normalize(self)
set_share(self, value)
Set share to the given value.
 
The share is set directly (or recursively, for a composite SecureObject),
using callbacks if value contains Futures that are not yet done.

Class methods defined here:
decode(M, Z, gap=256) from builtins.type
equality(a, b, /) from builtins.type
Return a == b.
inversion(a, /) from builtins.type
Return @-inverse of a (written ~a).
operation(a, b, /) from builtins.type
Return a @ b.

Data and other attributes defined here:
__annotations__ = {}

Methods inherited from SecureFiniteGroup:
__add__(self, other)
__eq__(self, other)
Return self==value.
__invert__(self)
__matmul__(self, other)
__mul__(self, other)
__ne__(self, other)
Return self!=value.
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rmatmul__(self, other)
__rmul__(self, other)
__rsub__(self, other)
__rtruediv__(self, other)
__sub__(self, other)
__truediv__(self, other)
__xor__(self, other)
inverse(self)
For ease of use.

Class methods inherited from SecureFiniteGroup:
if_else(c, a, b) from builtins.type
Secure selection based on binary condition c between group elements a and b.
 
Condition c must be of a secure number type compatible with the group,
and its value should be 0 or 1. Input a must be compatible with the group as
well, either of the secure type cls or of type cls.group. Same for input b.
operation2(a, /) from builtins.type
Return a @ a.
repeat(a, x) from builtins.type
Return xth @-power of a (written a^x), for any integral number x.
 
Base a is either a public or a secure group element.
Exponent x is either a public or a secure integral number.
Possibly a, x are lists (of same length)
repeat_public(a, x) from builtins.type

Data and other attributes inherited from SecureFiniteGroup:
__hash__ = None
identity = None

Methods inherited from mpyc.asyncoro.SecureObject:
__array_function__(self, func, types, args, kwargs)
Redirect __array_function__ call to array class, if any.
 
To support calls like np.block([[secint(9), -1], [1, secint(7)]]).
__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
Delegate __array_ufunc__ call to corresponding operator call.
 
Provisional support for calls like np.less(secint(9), 10).
__bool__(self)
Use of secret-shared objects in Boolean expressions makes no sense.
__deepcopy__(self, memo)
Let SecureObjects behave as immutable objects.
 
Introduced for github.com/meilof/oblif.

Data descriptors inherited from mpyc.asyncoro.SecureObject:
share

 
class SecureFiniteGroup(mpyc.asyncoro.SecureObject)
    SecureFiniteGroup(value=None)
 
Abstract base class for secure (secret-shared) finite groups elements.
 
 
Method resolution order:
SecureFiniteGroup
mpyc.asyncoro.SecureObject
builtins.object

Methods defined here:
__add__(self, other)
__eq__(self, other)
Return self==value.
__invert__(self)
__matmul__(self, other)
__mul__(self, other)
__ne__(self, other)
Return self!=value.
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rmatmul__(self, other)
__rmul__(self, other)
__rsub__(self, other)
__rtruediv__(self, other)
__sub__(self, other)
__truediv__(self, other)
__xor__(self, other)
inverse(self)
For ease of use.

Class methods defined here:
equality(a, b, /) from builtins.type
Return a == b.
if_else(c, a, b) from builtins.type
Secure selection based on binary condition c between group elements a and b.
 
Condition c must be of a secure number type compatible with the group,
and its value should be 0 or 1. Input a must be compatible with the group as
well, either of the secure type cls or of type cls.group. Same for input b.
inversion(a, /) from builtins.type
Return @-inverse of a (written ~a).
operation(a, b, /) from builtins.type
Return a @ b.
operation2(a, /) from builtins.type
Return a @ a.
repeat(a, x) from builtins.type
Return xth @-power of a (written a^x), for any integral number x.
 
Base a is either a public or a secure group element.
Exponent x is either a public or a secure integral number.
Possibly a, x are lists (of same length)
repeat_public(a, x) from builtins.type

Data and other attributes defined here:
__annotations__ = {'group': <class 'type'>, 'sectype': <class 'type'>}
__hash__ = None
identity = None

Methods inherited from mpyc.asyncoro.SecureObject:
__array_function__(self, func, types, args, kwargs)
Redirect __array_function__ call to array class, if any.
 
To support calls like np.block([[secint(9), -1], [1, secint(7)]]).
__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
Delegate __array_ufunc__ call to corresponding operator call.
 
Provisional support for calls like np.less(secint(9), 10).
__bool__(self)
Use of secret-shared objects in Boolean expressions makes no sense.
__deepcopy__(self, memo)
Let SecureObjects behave as immutable objects.
 
Introduced for github.com/meilof/oblif.
__init__(self, value=None)
Initialize share.
 
If value is None (default), the SecureObject starts out as an empty
placeholder (implemented as a Future).
set_share(self, value)
Set share to the given value.
 
The share is set directly (or recursively, for a composite SecureObject),
using callbacks if value contains Futures that are not yet done.

Data descriptors inherited from mpyc.asyncoro.SecureObject:
share

 
class SecureQuadraticResidue(SecureFiniteGroup)
    SecureQuadraticResidue(value=None)
 
Common base class for secure (secret-shared) quadratic residues.
 
 
Method resolution order:
SecureQuadraticResidue
SecureFiniteGroup
mpyc.asyncoro.SecureObject
builtins.object

Methods defined here:
__init__(self, value=None)
Ensure value is of secure field type.
set_share(self, value)
Set share to the given value.
 
The share is set directly (or recursively, for a composite SecureObject),
using callbacks if value contains Futures that are not yet done.

Class methods defined here:
decode(M, Z, gap=128) from builtins.type
equality(a, b, /) from builtins.type
Return a == b.
inversion(a, /) from builtins.type
Return @-inverse of a (written ~a).
operation(a, b, /) from builtins.type
Return a @ b.

Data and other attributes defined here:
__annotations__ = {}

Methods inherited from SecureFiniteGroup:
__add__(self, other)
__eq__(self, other)
Return self==value.
__invert__(self)
__matmul__(self, other)
__mul__(self, other)
__ne__(self, other)
Return self!=value.
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rmatmul__(self, other)
__rmul__(self, other)
__rsub__(self, other)
__rtruediv__(self, other)
__sub__(self, other)
__truediv__(self, other)
__xor__(self, other)
inverse(self)
For ease of use.

Class methods inherited from SecureFiniteGroup:
if_else(c, a, b) from builtins.type
Secure selection based on binary condition c between group elements a and b.
 
Condition c must be of a secure number type compatible with the group,
and its value should be 0 or 1. Input a must be compatible with the group as
well, either of the secure type cls or of type cls.group. Same for input b.
operation2(a, /) from builtins.type
Return a @ a.
repeat(a, x) from builtins.type
Return xth @-power of a (written a^x), for any integral number x.
 
Base a is either a public or a secure group element.
Exponent x is either a public or a secure integral number.
Possibly a, x are lists (of same length)
repeat_public(a, x) from builtins.type

Data and other attributes inherited from SecureFiniteGroup:
__hash__ = None
identity = None

Methods inherited from mpyc.asyncoro.SecureObject:
__array_function__(self, func, types, args, kwargs)
Redirect __array_function__ call to array class, if any.
 
To support calls like np.block([[secint(9), -1], [1, secint(7)]]).
__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
Delegate __array_ufunc__ call to corresponding operator call.
 
Provisional support for calls like np.less(secint(9), 10).
__bool__(self)
Use of secret-shared objects in Boolean expressions makes no sense.
__deepcopy__(self, memo)
Let SecureObjects behave as immutable objects.
 
Introduced for github.com/meilof/oblif.

Data descriptors inherited from mpyc.asyncoro.SecureObject:
share

 
class SecureSchnorrGroupElement(SecureFiniteGroup)
    SecureSchnorrGroupElement(value=None)
 
Common base class for secure (secret-shared) Schnorr group elements.
 
 
Method resolution order:
SecureSchnorrGroupElement
SecureFiniteGroup
mpyc.asyncoro.SecureObject
builtins.object

Methods defined here:
__init__(self, value=None)
Ensure value is of secure field type.
set_share(self, value)
Set share to the given value.
 
The share is set directly (or recursively, for a composite SecureObject),
using callbacks if value contains Futures that are not yet done.

Class methods defined here:
decode(M, Z) from builtins.type
equality(a, b, /) from builtins.type
Return a == b.
inversion(a, /) from builtins.type
Return @-inverse of a (written ~a).
operation(a, b, /) from builtins.type
Return a @ b.

Data and other attributes defined here:
__annotations__ = {}

Methods inherited from SecureFiniteGroup:
__add__(self, other)
__eq__(self, other)
Return self==value.
__invert__(self)
__matmul__(self, other)
__mul__(self, other)
__ne__(self, other)
Return self!=value.
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rmatmul__(self, other)
__rmul__(self, other)
__rsub__(self, other)
__rtruediv__(self, other)
__sub__(self, other)
__truediv__(self, other)
__xor__(self, other)
inverse(self)
For ease of use.

Class methods inherited from SecureFiniteGroup:
if_else(c, a, b) from builtins.type
Secure selection based on binary condition c between group elements a and b.
 
Condition c must be of a secure number type compatible with the group,
and its value should be 0 or 1. Input a must be compatible with the group as
well, either of the secure type cls or of type cls.group. Same for input b.
operation2(a, /) from builtins.type
Return a @ a.
repeat(a, x) from builtins.type
Return xth @-power of a (written a^x), for any integral number x.
 
Base a is either a public or a secure group element.
Exponent x is either a public or a secure integral number.
Possibly a, x are lists (of same length)
repeat_public(a, x) from builtins.type

Data and other attributes inherited from SecureFiniteGroup:
__hash__ = None
identity = None

Methods inherited from mpyc.asyncoro.SecureObject:
__array_function__(self, func, types, args, kwargs)
Redirect __array_function__ call to array class, if any.
 
To support calls like np.block([[secint(9), -1], [1, secint(7)]]).
__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
Delegate __array_ufunc__ call to corresponding operator call.
 
Provisional support for calls like np.less(secint(9), 10).
__bool__(self)
Use of secret-shared objects in Boolean expressions makes no sense.
__deepcopy__(self, memo)
Let SecureObjects behave as immutable objects.
 
Introduced for github.com/meilof/oblif.

Data descriptors inherited from mpyc.asyncoro.SecureObject:
share

 
class SecureSymmetricGroupElement(SecureFiniteGroup)
    SecureSymmetricGroupElement(value=None)
 
Common base class for secure (secret-shared) symmetric group elements.
 
 
Method resolution order:
SecureSymmetricGroupElement
SecureFiniteGroup
mpyc.asyncoro.SecureObject
builtins.object

Methods defined here:
__init__(self, value=None)
Ensure all coefficients of value are of secure field type.
 
Enforce value is a tuple.
set_share(self, value)
Set share to the given value.
 
The share is set directly (or recursively, for a composite SecureObject),
using callbacks if value contains Futures that are not yet done.

Class methods defined here:
equality(p, q, /) from builtins.type
Return a == b.
inversion(p, /) from builtins.type
Return @-inverse of a (written ~a).
operation(p, q, /) from builtins.type
First p then q.

Data and other attributes defined here:
__annotations__ = {}

Methods inherited from SecureFiniteGroup:
__add__(self, other)
__eq__(self, other)
Return self==value.
__invert__(self)
__matmul__(self, other)
__mul__(self, other)
__ne__(self, other)
Return self!=value.
__neg__(self)
__pow__(self, other)
__radd__(self, other)
__rmatmul__(self, other)
__rmul__(self, other)
__rsub__(self, other)
__rtruediv__(self, other)
__sub__(self, other)
__truediv__(self, other)
__xor__(self, other)
inverse(self)
For ease of use.

Class methods inherited from SecureFiniteGroup:
if_else(c, a, b) from builtins.type
Secure selection based on binary condition c between group elements a and b.
 
Condition c must be of a secure number type compatible with the group,
and its value should be 0 or 1. Input a must be compatible with the group as
well, either of the secure type cls or of type cls.group. Same for input b.
operation2(a, /) from builtins.type
Return a @ a.
repeat(a, x) from builtins.type
Return xth @-power of a (written a^x), for any integral number x.
 
Base a is either a public or a secure group element.
Exponent x is either a public or a secure integral number.
Possibly a, x are lists (of same length)
repeat_public(a, x) from builtins.type

Data and other attributes inherited from SecureFiniteGroup:
__hash__ = None
identity = None

Methods inherited from mpyc.asyncoro.SecureObject:
__array_function__(self, func, types, args, kwargs)
Redirect __array_function__ call to array class, if any.
 
To support calls like np.block([[secint(9), -1], [1, secint(7)]]).
__array_ufunc__(self, ufunc, method, *inputs, **kwargs)
Delegate __array_ufunc__ call to corresponding operator call.
 
Provisional support for calls like np.less(secint(9), 10).
__bool__(self)
Use of secret-shared objects in Boolean expressions makes no sense.
__deepcopy__(self, memo)
Let SecureObjects behave as immutable objects.
 
Introduced for github.com/meilof/oblif.

Data descriptors inherited from mpyc.asyncoro.SecureObject:
share

 
Functions
       
SecClassGroup(Delta=None, l=None)
Call SecClassGroup(...) is equivalent to SecGrp(ClassGroup(...)),
returning secure version of ClassGroup from mpyc.fingroups.
 
ClassGroup(Delta=None, l=None):
 
Create type for class group, given (bit length l of) discriminant Delta.
 
The following conditions are imposed on discriminant Delta:
 
    - Delta < 0, only supporting class groups of imaginary quadratic field
    - Delta = 1 (mod 4), preferably Delta = 1 (mod 8)
    - -Delta is prime
 
This implies that Delta is a fundamental discriminant.
SecEllipticCurve(curvename='Ed25519', coordinates=None)
Call SecEllipticCurve(...) is equivalent to SecGrp(EllipticCurve(...)),
returning secure version of EllipticCurve from mpyc.fingroups.
 
EllipticCurve(curvename='Ed25519', coordinates=None):
 
Create elliptic curve type for a selection of built-in curves.
The default coordinates used with these curves are 'affine'.
 
The following Edwards curves and Weierstrass curves are built-in:
 
    - 'Ed25519': see https://en.wikipedia.org/wiki/EdDSA#Ed25519
    - 'Ed448': aka "Goldilocks", see https://en.wikipedia.org/wiki/Curve448
    - 'secp256k1': Bitcoin's Koblitz curve from https://www.secg.org/sec2-v2.pdf
    - 'BN256': Barreto-Naehrig curve, https://eprint.iacr.org/2010/186
    - 'BN256_twist': sextic twist of Barreto-Naehrig curve
 
These curves can be used with 'affine' (default) and 'projective' coordinates.
The Edwards curves can also be used with 'extended' coordinates, and the
Weierstrass curves with 'jacobian' coordinates.
SecGrp(group)
Secure version of given finite group.
SecQuadraticResidues(p=None, l=None)
Call SecQuadraticResidues(...) is equivalent to SecGrp(QuadraticResidues(...)),
returning secure version of QuadraticResidues from mpyc.fingroups.
 
QuadraticResidues(p=None, l=None):
 
Create type for quadratic residues group given (bit length l of) odd prime modulus p.
 
The group of quadratic residues modulo p is of order n=(p-1)/2.
Given bit length l>2, p will be chosen such that n is also an odd prime.
If l=2, the only possibility is p=3, hence n=1.
SecSchnorrGroup(p=None, q=None, g=None, l=None, n=None)
Call SecSchnorrGroup(...) is equivalent to SecGrp(SchnorrGroup(...)),
returning secure version of SchnorrGroup from mpyc.fingroups.
 
SchnorrGroup(p=None, q=None, g=None, l=None, n=None):
 
Create type for Schnorr group of odd prime order q.
 
If q is not given, q will be the largest n-bit prime, n>=2.
If p is not given, p will be the least l-bit prime, l>n, such that q divides p-1.
 
If l and/or n are not given, default bit lengths will be set (2<=n<l).
SecSymmetricGroup(n)
Call SecSymmetricGroup(...) is equivalent to SecGrp(SymmetricGroup(...)),
returning secure version of SymmetricGroup from mpyc.fingroups.
 
SymmetricGroup(n):
 
Create type for symmetric group of degree n, n>=0.
repeat_public_base_public_output(a, x) -> _asyncio.Future
Multi-exponentiation for given base(s) a and exponent(s) x.
repeat_public_base_secret_output(a, x, secgrp)
Compute a^[x]->[a^x].
repeat_secret_base_secret_output(a, x, secgrp)
Compute [a]^[x]->[a^x].

 
Data
        __annotations__ = {'SecClassGroup': <class 'type'>, 'SecEllipticCurve': <class 'type'>, 'SecQuadraticResidues': <class 'type'>, 'SecSchnorrGroup': <class 'type'>, 'SecSymmetricGroup': <class 'type'>}
runtime = None