Package viff :: Module passive :: Class PassiveRuntime
[hide private]
[frames] | no frames]

Class PassiveRuntime

source code


The VIFF runtime.

The runtime is used for sharing values (:meth:`shamir_share` or :meth:`prss_share`) into :class:`Share` object and opening such shares (:meth:`open`) again. Calculations on shares is normally done through overloaded arithmetic operations, but it is also possible to call :meth:`add`, :meth:`mul`, etc. directly if one prefers.

Each player in the protocol uses a :class:`Runtime` object. To create an instance and connect it correctly with the other players, please use the :func:`create_runtime` function instead of instantiating a Runtime directly. The :func:`create_runtime` function will take care of setting up network connections and return a :class:`Deferred` which triggers with the :class:`Runtime` object when it is ready.

Instance Methods [hide private]
 
__init__(self, player, threshold, options=None)
Initialize runtime.
source code
 
output(self, share, receivers=None, threshold=None)
Open share to receivers (defaults to all players).
source code
 
open(self, share, receivers=None, threshold=None)
Open a secret sharing.
source code
 
add(self, share_a, share_b)
Addition of shares.
source code
 
sub(self, share_a, share_b)
Subtraction of shares.
source code
 
lin_comb(self, coefficients, shares)
Linear combination of shares.
source code
 
mul(self, share_a, share_b)
Multiplication of shares.
source code
 
pow(self, share, exponent)
Exponentation of a share to an integer by square-and-multiply.
source code
 
xor(self, share_a, share_b) source code
 
prss_key(self)
Create unique key for PRSS.
source code
 
prss_share(self, inputters, field, element=None)
Creates pseudo-random secret sharings.
source code
 
prss_share_random(self, field, binary=False)
Generate shares of a uniformly random element from the field given.
source code
 
prss_share_random_multi(self, field, quantity, binary=False)
Does the same as calling *quantity* times :meth:`prss_share_random`, but with less calls to the PRF.
source code
 
prss_share_zero(self, field, quantity)
Generate *quantity* shares of the zero element from the field given.
source code
 
prss_double_share(self, field, quantity)
Make *quantity* double-sharings using PRSS.
source code
 
prss_share_bit_double(self, field)
Share a random bit over *field* and GF256.
source code
 
prss_shamir_share_bit_double(self, field)
Shamir share a random bit over *field* and GF256.
source code
 
powerchain(self, share, max)
Returns the list [*share*, *share*^2, *share*^4, ..., *share*^(i^max)].
source code
 
prss_powerchain(self, max=7)
Generate a random secret share in GF256 and returns [*share*, *share*^2, *share*^4, ..., *share*^(i^max)].
source code
 
prss_powerchains(self, max=7, quantity=20)
Does *quantity* times the same as :meth:`prss_powerchain`.
source code
 
input(self, inputters, field, number=None, threshold=None)
Input *number* to the computation.
source code
 
shamir_share(self, inputters, field, number=None, threshold=None)
Secret share *number* over *field* using Shamir's method.
source code

Inherited from runtime.Runtime: abort, activate_reactor, add_player, fork_pc, handle_deferred_data, increment_pc, preprocess, print_transferred_data, process_deferred_queue, process_queue, schedule_callback, schedule_complex_callback, shutdown, synchronize, unfork_pc, wait_for

Static Methods [hide private]

Inherited from runtime.Runtime: add_options

Instance Variables [hide private]

Inherited from runtime.Runtime: activation_counter, deferred_queue, depth_counter, depth_limit, id, num_players, players, program_counter, protocols, threshold, using_viff_reactor

Inherited from runtime.Runtime (private): _needed_data, _pool

Method Details [hide private]

__init__(self, player, threshold, options=None)
(Constructor)

source code 

Initialize runtime.

Overrides: runtime.Runtime.__init__

output(self, share, receivers=None, threshold=None)

source code 

Open share to receivers (defaults to all players).

Returns a Share to players with IDs in receivers and None to the remaining players.

Overrides: runtime.Runtime.output
(inherited documentation)

open(self, share, receivers=None, threshold=None)

source code 

Open a secret sharing.

The *receivers* are the players that will eventually obtain the opened result. The default is to let everybody know the result. By default the :attr:`threshold` + 1 shares are reconstructed, but *threshold* can be used to override this.

Communication cost: every player sends one share to each receiving player.

add(self, share_a, share_b)

source code 

Addition of shares.

Communication cost: none.

Decorators:
  • @profile
Overrides: runtime.Runtime.add

sub(self, share_a, share_b)

source code 

Subtraction of shares.

Communication cost: none.

lin_comb(self, coefficients, shares)

source code 

Linear combination of shares.

Communication cost: none. Saves the construction of unnecessary shares compared to using add() and mul().

Decorators:
  • @profile

mul(self, share_a, share_b)

source code 

Multiplication of shares.

Communication cost: 1 Shamir sharing.

Decorators:
  • @profile
Overrides: runtime.Runtime.mul

prss_key(self)

source code 

Create unique key for PRSS.

This increments the program counter and returns it as a tuple. Each straight-line program (typically a callback attached to some :class:`Deferred`) is executed in a context with unique starting program counter. This ensures that consequetive calls to PRSS-related methods will use unique program counters.

prss_share(self, inputters, field, element=None)

source code 

Creates pseudo-random secret sharings.

This protocol creates a secret sharing for each player in the subset of players specified in *inputters*. Each inputter provides an integer. The result is a list of shares, one for each inputter.

The protocol uses the pseudo-random secret sharing technique described in the paper "Share Conversion, Pseudorandom Secret-Sharing and Applications to Secure Computation" by Ronald Cramer, Ivan Damgård, and Yuval Ishai in Proc. of TCC 2005, LNCS 3378. `Download <http://www.cs.technion.ac.il/~yuvali/pubs/CDI05.ps>`__

Communication cost: Each inputter does one broadcast.

prss_share_random(self, field, binary=False)

source code 

Generate shares of a uniformly random element from the field given.

If binary is True, a 0/1 element is generated. No player learns the value of the element.

Communication cost: none if binary=False, 1 open otherwise.

prss_share_random_multi(self, field, quantity, binary=False)

source code 

Does the same as calling *quantity* times :meth:`prss_share_random`, but with less calls to the PRF. Sampling of a binary element is only possible if the field is :class:`GF256`.

Communication cost: none.

prss_share_zero(self, field, quantity)

source code 

Generate *quantity* shares of the zero element from the field given.

Communication cost: none.

prss_double_share(self, field, quantity)

source code 

Make *quantity* double-sharings using PRSS.

The pair of shares will have degree t and 2t where t is the default threshold for the runtime.

prss_share_bit_double(self, field)

source code 

Share a random bit over *field* and GF256.

The protocol is described in "Efficient Conversion of Secret-shared Values Between Different Fields" by Ivan Damgård and Rune Thorbek available as `Cryptology ePrint Archive, Report 2008/221 <http://eprint.iacr.org/2008/221>`__.

prss_powerchain(self, max=7)

source code 

Generate a random secret share in GF256 and returns [*share*, *share*^2, *share*^4, ..., *share*^(i^max)].

Decorators:
  • @preprocess("prss_powerchains")

prss_powerchains(self, max=7, quantity=20)

source code 

Does *quantity* times the same as :meth:`prss_powerchain`. Used for preprocessing.

input(self, inputters, field, number=None, threshold=None)

source code 

Input *number* to the computation.

The input is shared using the :meth:`shamir_share` method.

Overrides: runtime.Runtime.input

shamir_share(self, inputters, field, number=None, threshold=None)

source code 

Secret share *number* over *field* using Shamir's method.

The number is shared using polynomial of degree *threshold* (defaults to :attr:`threshold`). Returns a list of shares unless there is only one inputter in which case the share is returned directly.

In code it is used like this:

   a, b, c = runtime.shamir_share([1, 2, 3], Zp, x)

where ``Zp`` is a field and ``x`` is a Python integer holding the input of each player (three inputs in total).

If only a subset of the players provide input it looks like this:

   if runtime.id == 1:
       a = runtime.shamir_share([1], Zp, x)
   else:
       a = runtime.shamir_share([1], Zp)

Instead of branching when calling :meth:`shamir_share`, one can give ``None`` as input:

   if runtime.id == 1:
       x = int(raw_input("Input x: "))
   else:
       x = None
   a = runtime.shamir_share([1], Zp, x)

which might be practical in some cases.

Communication cost: n elements transmitted.