/rev/ea45925aa060
changeset: 1357:ea45925aa060
user: Janus Dam Nielsen <[email protected]>
date: Wed Oct 28 07:05:35 2009 +0100
summary: Merged with Marcel.
diffstat:
apps/aes.py | 6 +++---
viff/active.py | 26 +++++++++++++-------------
viff/paillier.py | 13 +++++++++++--
viff/passive.py | 2 +-
viff/runtime.py | 6 +++---
5 files changed, 31 insertions(+), 22 deletions(-)
diffs (142 lines):
diff -r c467cba12cfb -r ea45925aa060 apps/aes.py
--- a/apps/aes.py Tue Oct 27 22:24:56 2009 +0100
+++ b/apps/aes.py Wed Oct 28 07:05:35 2009 +0100
@@ -125,9 +125,9 @@
if options.active:
if options.exponentiation is False:
- max = 461
- js = [3 + i * 23 + j for i in range(20)
- for j in range(0, 14, 2) + [15]]
+ max = 621
+ js = [3 + i * 31 + j for i in range(20)
+ for j in range(0, 21, 3) + [22]]
elif options.exponentiation == 0 or options.exponentiation == 3:
max = 821
js = [1 + i * 41 + j * 3 for i in range(20) for j in range(13)]
diff -r c467cba12cfb -r ea45925aa060 viff/active.py
--- a/viff/active.py Tue Oct 27 22:24:56 2009 +0100
+++ b/viff/active.py Wed Oct 28 07:05:35 2009 +0100
@@ -19,7 +19,9 @@
from math import ceil
-from twisted.internet.defer import gatherResults, Deferred, succeed
+from gmpy import numdigits
+
+from twisted.internet.defer import gatherResults, Deferred
from viff import shamir
from viff.util import rand
@@ -419,7 +421,7 @@
result = self.generate_triples(field, quantity=1, gather=False)
return result[0]
- def generate_triples(self, field, quantity=20, gather=True):
+ def generate_triples(self, field, quantity=1, gather=True):
"""Generate *quantity* multiplication triples using PRSS.
These are random numbers *a*, *b*, and *c* such that ``c =
@@ -428,7 +430,9 @@
Returns a tuple with the number of triples generated and a
Deferred which will yield a singleton-list with a 3-tuple.
"""
- quantity = min(quantity, 20)
+
+ # This adjusted to the PRF based on SHA1 (160 bits).
+ quantity = min(quantity, max(int(160 /numdigits(field.modulus - 1,
2)), 1))
a_t = self.prss_share_random_multi(field, quantity)
b_t = self.prss_share_random_multi(field, quantity)
@@ -470,19 +474,15 @@
Preprocessing: 1 multiplication triple.
Communication: 2 openings.
"""
- assert isinstance(share_x, Share) or isinstance(share_y, Share), \
- "At least one of share_x and share_y must be a Share."
+ assert isinstance(share_x, Share), \
+ "share_x must be a Share."
- if not isinstance(share_x, Share):
- # Then share_y must be a Share => local multiplication. We
- # clone first to avoid changing share_y.
- result = share_y.clone()
- result.addCallback(lambda y: share_x * y)
- return result
if not isinstance(share_y, Share):
- # Likewise when share_y is a constant.
+ # Local multiplication. share_x always is a Share by
+ # operator overloading in Share. We clone share_x first
+ # to avoid changing it.
result = share_x.clone()
- result.addCallback(lambda x: x * share_y)
+ result.addCallback(lambda x: share_y * x)
return result
# At this point both share_x and share_y must be Share
diff -r c467cba12cfb -r ea45925aa060 viff/paillier.py
--- a/viff/paillier.py Tue Oct 27 22:24:56 2009 +0100
+++ b/viff/paillier.py Wed Oct 28 07:05:35 2009 +0100
@@ -62,10 +62,19 @@
nsq = n*n
return (pow(g, m, nsq)*pow(r, n, nsq)) % nsq
+#: Cache for ciphertext-independent factors.
+_decrypt_factors = {}
+
def decrypt(c, (n, g, lm)):
numer = L(pow(c, lm, n*n), n)
- denom = L(pow(g, lm, n*n), n)
- return (numer*gmpy.invert(denom, n)) % n
+ key = (n, g, lm)
+ try:
+ factor = _decrypt_factors[key]
+ except KeyError:
+ denom = L(pow(g, lm, n*n), n)
+ factor = gmpy.invert(denom, n)
+ _decrypt_factors[key] = factor
+ return (numer * factor) % n
class PaillierRuntime(Runtime):
diff -r c467cba12cfb -r ea45925aa060 viff/passive.py
--- a/viff/passive.py Tue Oct 27 22:24:56 2009 +0100
+++ b/viff/passive.py Wed Oct 28 07:05:35 2009 +0100
@@ -27,7 +27,7 @@
from viff.field import GF256, FieldElement
from viff.util import rand, profile
-from twisted.internet.defer import succeed, gatherResults
+from twisted.internet.defer import gatherResults
class PassiveRuntime(Runtime):
diff -r c467cba12cfb -r ea45925aa060 viff/runtime.py
--- a/viff/runtime.py Tue Oct 27 22:24:56 2009 +0100
+++ b/viff/runtime.py Wed Oct 28 07:05:35 2009 +0100
@@ -39,14 +39,14 @@
import sys
from viff.field import GF256, FieldElement
-from viff.util import wrapper, rand, deep_wait, track_memory_usage, begin, end
+from viff.util import wrapper, rand, track_memory_usage, begin, end
from viff.constants import SHARE
import viff.reactor
from twisted.internet import reactor
from twisted.internet.task import LoopingCall
from twisted.internet.error import ConnectionDone, CannotListenError
-from twisted.internet.defer import Deferred, DeferredList, gatherResults,
succeed
+from twisted.internet.defer import Deferred, DeferredList, gatherResults
from twisted.internet.defer import maybeDeferred
from twisted.internet.protocol import ReconnectingClientFactory, ServerFactory
from twisted.protocols.basic import Int16StringReceiver
@@ -950,7 +950,7 @@
# We must include at least one new-style class in bases. We
# include it last to avoid overriding __init__ from the other
# base classes.
- bases = (runtime_class,) + tuple(mixins) + (object,)
+ bases = tuple(mixins) + (runtime_class, object)
return type("ExtendedRuntime", bases, {})
def create_runtime(id, players, threshold, options=None, runtime_class=None):
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk