Exemplo n.º 1
0
    def evaluate_all(self, expressions, weight_expressions):
        self.expressions = expressions
        self.weight_expressions = weight_expressions
        self.pre_runtime.addCallback(self.begin_MPC)

        # Start the Twisted event loop.
        reactor.run()
        return self.results
Exemplo n.º 2
0
def main():
     # Parse command line arguments.
    parser = OptionParser(usage=__doc__)

    parser.add_option("--modulus",
                     help="lower limit for modulus (can be an expression)")

    parser.set_defaults(modulus=2**65)

    Runtime.add_options(parser)

    options, args = parser.parse_args()
    if len(args)==2:
        number = int(args[1])
    else:
        number = None

    if len(args) == 0:
        parser.error("you must specify a config file")

    Zp = GF(find_prime(options.modulus, blum=True))

    # Load configuration file.
    id, players = load_config(args[0])

    runtime_class = make_runtime_class(mixins=[ComparisonToft07Mixin])
    pre_runtime = create_runtime(id, players, 1, options, runtime_class)

    def run(runtime):
        print "Connected."

        # Players 1 and 2 are doing a sharing over the field Zp.
        # Our input is number (None for other players).
        if runtime.id == 3:
            print "I have no number"
        else:
            print "My number: %d." % number
        (x, y) = runtime.shamir_share([1, 2], Zp, number)

        # Do the secret computation.
        result = divide(x, y, 10) # 10 bits for the result.

        # Now open the result so we can see it.
        dprint("The two numbers divided are: %s", runtime.open(result))

        result.addCallback(lambda _: runtime.shutdown())

    pre_runtime.addCallback(run)

    # Start the Twisted event loop.
    reactor.run()
Exemplo n.º 3
0
def main():
    # Parse command line arguments.
    parser = OptionParser(usage=__doc__)

    parser.add_option("--modulus",
                      help="lower limit for modulus (can be an expression)")

    parser.set_defaults(modulus=2**65)

    Runtime.add_options(parser)

    options, args = parser.parse_args()
    if len(args) == 2:
        number = int(args[1])
    else:
        number = None

    if len(args) == 0:
        parser.error("you must specify a config file")

    Zp = GF(find_prime(options.modulus, blum=True))

    # Load configuration file.
    id, players = load_config(args[0])

    runtime_class = make_runtime_class(mixins=[ComparisonToft07Mixin])
    pre_runtime = create_runtime(id, players, 1, options, runtime_class)

    def run(runtime):
        print "Connected."

        # Players 1 and 2 are doing a sharing over the field Zp.
        # Our input is number (None for other players).
        if runtime.id == 3:
            print "I have no number"
        else:
            print "My number: %d." % number
        (x, y) = runtime.shamir_share([1, 2], Zp, number)

        # Do the secret computation.
        result = divide(x, y, 10)  # 10 bits for the result.

        # Now open the result so we can see it.
        dprint("The two numbers divided are: %s", runtime.open(result))

        result.addCallback(lambda _: runtime.shutdown())

    pre_runtime.addCallback(run)

    # Start the Twisted event loop.
    reactor.run()
Exemplo n.º 4
0
Arquivo: main.py Projeto: njlr/Mixer
options, args = parser.parse_args()

if len(args) != 3:
    
    parser.error("Wrong number of arguments. Use config, target address, output file")

parser = OptionParser()

options, args = parser.parse_args()


id, players = load_config(args[0])

address = args[1]

out = args[2]

protocol = Protocol(id, address, random.SystemRandom().getrandbits(32), out)


pre_runtime = create_runtime(id, players, (len(players) - 1)//2, runtime_class=Toft07Runtime)

pre_runtime.addCallback(protocol.run)
pre_runtime.addErrback(errorHandler)


reactor.run()


Exemplo n.º 5
0
if options.parallel:
    benchmark = ParallelBenchmark
else:
    benchmark = SequentialBenchmark

needed_data = ""
if options.needed_data:
    needed_data = eval(open(options.needed_data).read())

if options.needed_data and options.pc:
    bases = (benchmark, NeededDataBenchmarkStrategy, operation_arity)
    options.pc = eval(options.pc)
else:
    bases = (benchmark, SelfcontainedBenchmarkStrategy, operation_arity)

print "Using the Benchmark bases:"
for b in bases:
    print "- %s" % b.__name__
benchmark = type("ExtendedBenchmark", bases, {})


def do_benchmark(runtime, operation, benchmark, field, count, *args):
    benchmark(runtime, operation, field, count).benchmark(*args)


pre_runtime.addCallback(do_benchmark, operation, benchmark, Zp, count,
                        needed_data, options.pc)

print "#### Starting reactor ###"
reactor.run()
Exemplo n.º 6
0
def run_protocol(rt, p):
    rt.addCallback(p)
    reactor.run()
Exemplo n.º 7
0
            # Millionaire 1 is largest.
            comparison = comparison + [1]
        elif not m1_ge_m2 and not m1_ge_m3:
            # Millionaire 1 is smallest.
            comparison = [1] + comparison
        else:
            # Millionaire 1 is between the others.
            comparison = [comparison[0], 1, comparison[1]]

        print "From poorest to richest:"
        for id in comparison:
            if id == self.runtime.id:
                print "  Millionaire %d (%d millions)" % (id, self.millions)
            else:
                print "  Millionaire %d" % id

# Parse command line arguments.
parser = OptionParser()
Toft05Runtime.add_options(parser)
options, args = parser.parse_args()
if len(args) == 0:
    parser.error("you must specify a config file")
else:
    id, players = load_config(args[0])
# Create a deferred Runtime and ask it to run our protocol when ready.
pre_runtime = create_runtime(id, players, 1, options, Toft05Runtime)
pre_runtime.addCallback(Protocol)

# Start the Twisted event loop.
reactor.run() #@UndefinedVariable