changeset 1357:ea45925aa060

Merged with Marcel.
author Janus Dam Nielsen Wed, 28 Oct 2009 07:05:35 +0100 c467cba12cfb eb9f159eea68 712cbf4c2e1b 5 files changed, 31 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
```--- 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)]```
```--- 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))

@@ -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
+            # 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```
```--- 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):```
```--- 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):```
```--- 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.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