[viff-devel] Mental Poker

2010-08-05 Thread Jonathan Van den Schrieck
Hello,

For my master thesis at UCLouvain (www.uclouvain.be), I wrote a VIFF 
application for mental poker.
Both files are in the .zip that can be found at 
http://www.jovds.be/viff_mental_poker.zip
Usage is : python mental_poker.py [player_config_file] [number_of_players] 
[threshold]

This simulates the shuffling and the dealing of the cards to the players. Both 
Active and Passive runtimes can obviously be used. To get an idea of the 
performances, for a 10 players games with threshold 3 and Active Runtime, it 
takes less than 20 seconds on a single core of an Intel Q6600 (2.4ghz) (one 
computer per player). Each player has to send 250 KB of data (headers included).

I will soon post my thesis, I first need to write some extra's in it.

I hope maybe this could be a nice demo to illustrate the power of VIFF.

I would also like to thank everyone here for their help, and wish good luck in 
the future development of VIFF.

Best regards,

Jonathan Van den Schrieck
___
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk


Re: [viff-devel] Equality protocol : error

2010-04-12 Thread Jonathan Van den Schrieck
Yes, indeed. Nice guess :-).

Jonathan

Le 10 avr. 2010 à 23:19, Sigurd Torkel Meldgaard a écrit :

>> Thank you for your idea wich is very helpful to me since I actually work 
>> with p = 53.
>> Using this is much more efficient !
> 
> Might I guess you are implementing a card game? ; )
> 
> - Sigurd

___
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk


Re: [viff-devel] Equality protocol : error

2010-04-10 Thread Jonathan Van den Schrieck
ok, my problem is solved, the error came from the config files. I generated new 
ones and the error was gone.
I would like to thank everyone for their help in finding the solution, 
especially Mr. Keller.

Jonathan

Le 8 avr. 2010 à 23:34, Marcel Keller a écrit :

> Hi Jonathan,
> 
> I can't reproduce the error here. Can you send me your config files? The   
> error might be triggered by certain random numbers, which depend on the PRSS 
> keys. By the way, the error message is about the same every time something 
> goes wrong in a callback. This is because VIFF does not define errbacks. To 
> get a little bit more meaningful output, you can use the --deferred-debug 
> parameter.
> 
> Best regards,
> Marcel

___
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk


Re: [viff-devel] Equality protocol : error

2010-04-10 Thread Jonathan Van den Schrieck
Dear Mr. Meldgaard,

Thank you for your idea wich is very helpful to me since I actually work with p 
= 53.
Using this is much more efficient !

Regards,

Jonathan

Le 9 avr. 2010 à 01:10, Sigurd Torkel Meldgaard a écrit :

> I know this is talking around the problem but:
> 
> For very small moduli like yours, another protocol for equality is
> actually simpler, better (no risk of failing) and faster (I guess):
> 
> raise (a-b) to n-1 (with square and multiply), and if this difference
> was 0 you will get 0, otherwise you will get 1 (good old fermat), this
> result can be subtracted from 1, to turn the bit correctly.
> 
> I actually coded this once, but for some reason I never got to put it into 
> Viff
> 
> I have attached a patch you can try to apply (use hg qimport
> fermatequality, hg qpush), and play with for now.
> 
> I will try to look into the real bug later.
> 
> The best
> Sigurd
> 
> On Thu, Apr 8, 2010 at 11:34 PM, Marcel Keller  wrote:
>> Hi Jonathan,
>> 
>> I can't reproduce the error here. Can you send me your config files? The
>> error might be triggered by certain random numbers, which depend on the PRSS
>> keys. By the way, the error message is about the same every time something
>> goes wrong in a callback. This is because VIFF does not define errbacks. To
>> get a little bit more meaningful output, you can use the --deferred-debug
>> parameter.
>> 
>> Best regards,
>> Marcel
>> 
> 

___
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk


Re: [viff-devel] Equality protocol : error

2010-04-08 Thread Jonathan Van den Schrieck
Dear Ivan,

Yes I know about that. But 367 is 3 mod 4 so it should be OK. And the existing 
protocol works with 367 only if the two numbers are not equal. If they are, I 
got the error mentioned in my first message.
If I can solve the error in the existing protocol, I will be able to continue 
my work.

Thank you for your answer,

Jonathan

Le 8 avr. 2010 à 16:26, Ivan Damgård a écrit :

> Dear Jonathan,
> 
> You cannot expect the protocol to work for primes that are 1 mod 4,
> it is based on the fact that for primes p that are 3 mod 4, you can 
> deterministically
> compute a square root mod p by raising to power (p+1)/4.
> This does not work if p is 1 mod 4.
> 
> regards, Ivan
> 
> On 08/04/2010, at 14.11, Jonathan Van den Schrieck wrote:
> 
>> Hello,
>> 
>> I am trying to modify the equality protocol to make it work for primes 
>> congruent to 5 mod 8 (exists for Blum primes).
>> The problem is that I have an error with the original protocol. It works 
>> perfectly with p = 211 for example. But for p = 367, it doesn't.
>> Here is the code I'm using to test it :
>> 
>> from optparse import OptionParser
>> import viff.reactor
>> viff.reactor.install()
>> from twisted.internet import reactor
>> from viff.field import GF
>> from viff.runtime import create_runtime, gather_shares
>> from viff.passive import PassiveRuntime
>> from viff.equality_ohta import ProbabilisticEqualityMixin2
>> from viff.equality import ProbabilisticEqualityMixin
>> from viff.comparison import Toft05Runtime
>> from viff.config import load_config
>> from viff.util import rand, find_prime
>> 
>> class EqualityRuntime(PassiveRuntime, ProbabilisticEqualityMixin):
>> """Default mix of :class:`~viff.equality.ProbabilisticEqualityMixin`
>> and :class:`~viff.passive.PassiveRuntime`.
>> """
>> pass
>> 
>> class Protocol:
>> 
>> def __init__(self, runtime):
>> # Save the Runtime for later use
>> self.runtime = runtime
>> k = runtime.options.security_parameter
>> print "security parameter = ", k
>> Zp = GF(367)
>> 
>> # We must secret share our input with the other parties. They
>> # will do the same and we end up with three variables
>> # input is equal to the player id
>> 
>> rand = runtime.prss_share_random(Zp)
>> #rand1 = runtime.prss_share_random(Zp)
>> rand1 = rand
>> print "rand = ", rand, "rand1 = ", rand1
>> 
>> #open rand and rand1 to print their value
>> open_rand = runtime.open(rand)
>> open_rand1 = runtime.open(rand1)
>> temp = gather_shares([open_rand, open_rand1])
>> temp.addCallback(self.results_ready)
>> 
>> # we test if rand == rand1 by using equality protocol
>> test = (rand == rand1)
>> test_open = runtime.open(test)
>> results = gather_shares([test_open])
>> results.addCallback(self.results_ready)
>> 
>> runtime.schedule_callback(results, lambda _: runtime.synchronize())
>> runtime.schedule_callback(results, lambda _: runtime.shutdown())
>> 
>> def results_ready(self, results):
>> print "ALGO_QUAD temp results =", results
>> 
>> 
>> def mtemp(self, temp):
>>  print "local part of shares after callback ="
>>  print temp
>> 
>>   
>> # Parse command line arguments.
>> parser = OptionParser()
>> EqualityRuntime.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, EqualityRuntime)
>> pre_runtime.addCallback(Protocol)
>> 
>> # Start the Twisted event loop.
>> reactor.run()
>> 
>> as you can see, I simply generate 2 random numbers, then I test if they have 
>> the same value, and I print the result of the test.
>> This will work if rand != rand1, but if I set rand1 = rand => ERROR.
>> This error will only happen if p = 367 (and maybe with others primes, but I 
>> couldn't test them all)
>> Here is the error :
>> 
>> Unhandled error in Deferred:
>> Traceback (most recent call last):
>>

[viff-devel] Equality protocol : error

2010-04-08 Thread Jonathan Van den Schrieck
Hello,

I am trying to modify the equality protocol to make it work for primes 
congruent to 5 mod 8 (exists for Blum primes).
The problem is that I have an error with the original protocol. It works 
perfectly with p = 211 for example. But for p = 367, it doesn't.
Here is the code I'm using to test it :

from optparse import OptionParser
import viff.reactor
viff.reactor.install()
from twisted.internet import reactor
from viff.field import GF
from viff.runtime import create_runtime, gather_shares
from viff.passive import PassiveRuntime
from viff.equality_ohta import ProbabilisticEqualityMixin2
from viff.equality import ProbabilisticEqualityMixin
from viff.comparison import Toft05Runtime
from viff.config import load_config
from viff.util import rand, find_prime

class EqualityRuntime(PassiveRuntime, ProbabilisticEqualityMixin):
"""Default mix of :class:`~viff.equality.ProbabilisticEqualityMixin`
and :class:`~viff.passive.PassiveRuntime`.
"""
pass

class Protocol:

def __init__(self, runtime):
# Save the Runtime for later use
self.runtime = runtime
k = runtime.options.security_parameter
print "security parameter = ", k
Zp = GF(367)

# We must secret share our input with the other parties. They
# will do the same and we end up with three variables
# input is equal to the player id

rand = runtime.prss_share_random(Zp)
#rand1 = runtime.prss_share_random(Zp)
rand1 = rand
print "rand = ", rand, "rand1 = ", rand1

#open rand and rand1 to print their value
open_rand = runtime.open(rand)
open_rand1 = runtime.open(rand1)
temp = gather_shares([open_rand, open_rand1])
temp.addCallback(self.results_ready)

# we test if rand == rand1 by using equality protocol
test = (rand == rand1)
test_open = runtime.open(test)
results = gather_shares([test_open])
results.addCallback(self.results_ready)

runtime.schedule_callback(results, lambda _: runtime.synchronize())
runtime.schedule_callback(results, lambda _: runtime.shutdown())

def results_ready(self, results):
print "ALGO_QUAD temp results =", results


def mtemp(self, temp):
print "local part of shares after callback ="
print temp

  
# Parse command line arguments.
parser = OptionParser()
EqualityRuntime.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, EqualityRuntime)
pre_runtime.addCallback(Protocol)

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

as you can see, I simply generate 2 random numbers, then I test if they have 
the same value, and I print the result of the test.
This will work if rand != rand1, but if I set rand1 = rand => ERROR.
This error will only happen if p = 367 (and maybe with others primes, but I 
couldn't test them all)
Here is the error :

Unhandled error in Deferred:
Traceback (most recent call last):
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/internet/defer.py",
 line 328, in _runCallbacks
self.result = callback(self.result, *args, **kw)
  File "/Users/jonathanvds/opt/lib/python/viff/runtime.py", line 239, in 
_callback_fired
self.callback(self.results)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/internet/defer.py",
 line 243, in callback
self._startRunCallbacks(result)
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/internet/defer.py",
 line 312, in _startRunCallbacks
self._runCallbacks()
---  ---
  File 
"/System/Library/Frameworks/Python.framework/Versions/2.5/Extras/lib/python/twisted/internet/defer.py",
 line 328, in _runCallbacks
self.result = callback(self.result, *args, **kw)
  File "/Users/jonathanvds/opt/lib/python/viff/passive.py", line 211, in 

result.addCallback(lambda (a, b): a * b)
exceptions.TypeError: unsupported operand type(s) for *: 'instance' and 
'GFElement'

I can't find where the problem comes from since I only have the error with p = 
367 (and I have the same error with my new protocol for p = 5 mod 8, but I'm 
guessing that if I can solve the problem in the existing protocol, I'll be able 
to do the same with my implementation).

Thank you for your help,

Jonathan Van den Schrieck


___
viff-devel mailing list (http://viff.dk/)
viff-devel@viff.dk
http://lists.viff.dk/listinfo.cgi/viff-devel-viff.dk