Package viff :: Module runtime
[hide private]
[frames] | no frames]

Module runtime

source code

VIFF runtime. This is where the virtual ideal functionality is hiding! The runtime is responsible for sharing inputs, handling communication, and running the calculations.

Each player participating in the protocol will instantiate a Runtime object and use it for the calculations.

The Runtime returns Share objects for most operations, and these can be added, subtracted, and multiplied as normal thanks to overloaded arithmetic operators. The runtime will take care of scheduling things correctly behind the scenes.

Classes [hide private]
  Share
A shared number.
  ShareList
Create a share that waits on a number of other shares.
  ShareExchanger
Send and receive shares.
  SelfShareExchanger
  SelfShareExchangerFactory
Factory for creating SelfShareExchanger protocols.
  FakeTransport
  ShareExchangerFactory
Factory for creating ShareExchanger protocols.
  Runtime
Basic VIFF runtime with no crypto.
Functions [hide private]
 
gather_shares(shares)
Gather shares.
source code
 
preprocess(generator)
Track calls to this method.
source code
 
make_runtime_class(runtime_class=None, mixins=None)
Creates a new runtime class with runtime_class as a base class mixing in the mixins.
source code
 
create_runtime(id, players, threshold, options=None, runtime_class=None)
Create a Runtime and connect to the other players.
source code
Function Details [hide private]

gather_shares(shares)

source code 

Gather shares.

Roughly modelled after the Twisted gatherResults function. It takes a list of shares and returns a new Share which will be triggered with a list of values, namely the values from the initial shares:

>>> from pprint import pprint
>>> from viff.field import GF256
>>> a = Share(None, GF256)
>>> b = Share(None, GF256)
>>> shares = gather_shares([a, b])
>>> shares.addCallback(pprint)           # doctest: +ELLIPSIS
<ShareList at 0x...>
>>> a.callback(10)
>>> b.callback(20)
[10, 20]

preprocess(generator)

source code 

Track calls to this method.

The decorated method will be replaced with a proxy method which first tries to get the data needed from Runtime._pool, and if that fails it falls back to the original method.

The generator method is only used to record where the data should be generated from, the method is not actually called. This must be the name of the method (a string) and not the method itself.

make_runtime_class(runtime_class=None, mixins=None)

source code 
Creates a new runtime class with runtime_class as a base class mixing in the mixins. By default viff.passive.PassiveRuntime will be used.

create_runtime(id, players, threshold, options=None, runtime_class=None)

source code 

Create a Runtime and connect to the other players.

This function should be used in normal programs instead of instantiating the Runtime directly. This function makes sure that the Runtime is correctly connected to the other players.

The return value is a Deferred which will trigger when the runtime is ready. Add your protocol as a callback on this Deferred using code like this:

def protocol(runtime):
    a, b, c = runtime.shamir_share([1, 2, 3], Zp, input)

    a = runtime.open(a)
    b = runtime.open(b)
    c = runtime.open(c)

    dprint("Opened a: %s", a)
    dprint("Opened b: %s", b)
    dprint("Opened c: %s", c)

    runtime.wait_for(a,b,c)

pre_runtime = create_runtime(id, players, 1)
pre_runtime.addCallback(protocol)

This is the general template which VIFF programs should follow. Please see the example applications for more examples.