/rev/d325a4ee6625
changeset: 1216:d325a4ee6625
user: Martin Geisler <[email protected]>
date: Fri Sep 18 16:14:20 2009 +0200
summary: Merge with Marcel.
diffstat:
apps/aes.py | 11 ++++++++++-
viff/active.py | 2 +-
viff/aes.py | 33 ++++++++++++++++++++++++++-------
viff/runtime.py | 15 ++++++++++++++-
4 files changed, 51 insertions(+), 10 deletions(-)
diffs (137 lines):
diff -r f2fce145b9e1 -r d325a4ee6625 apps/aes.py
--- a/apps/aes.py Fri Sep 18 15:48:52 2009 +0200
+++ b/apps/aes.py Fri Sep 18 16:14:20 2009 +0200
@@ -55,6 +55,8 @@
parser.add_option("-c", "--count", action="store", type="int",
help="Number of blocks to encrypt. Defaults to 1.")
parser.set_defaults(count=1)
+parser.add_option("-a", "--active", action="store_true", help="Use actively "
+ "secure runtime. Default is only passive security.")
# Add standard VIFF options.
Runtime.add_options(parser)
@@ -101,7 +103,14 @@
s = rt.synchronize()
rt.schedule_complex_callback(s, encrypt, rt, key)
-rt = create_runtime(id, players, 1, options)
+if options.active:
+ from viff.active import ActiveRuntime
+ runtime_class = ActiveRuntime
+else:
+ from viff.passive import PassiveRuntime
+ runtime_class = PassiveRuntime
+
+rt = create_runtime(id, players, 1, options, runtime_class)
rt.addCallback(share_key)
reactor.run()
diff -r f2fce145b9e1 -r d325a4ee6625 viff/active.py
--- a/viff/active.py Fri Sep 18 15:48:52 2009 +0200
+++ b/viff/active.py Fri Sep 18 16:14:20 2009 +0200
@@ -507,7 +507,7 @@
# This is the Deferred we will do processing on.
triple = self.get_triple(share_x.field)
triple.addCallback(gather_shares)
- self.schedule_callback(triple, finish_mul)
+ triple = self.schedule_complex_callback(triple, finish_mul)
# We add the result to the chains in triple.
triple.chainDeferred(result)
return result
diff -r f2fce145b9e1 -r d325a4ee6625 viff/aes.py
--- a/viff/aes.py Fri Sep 18 15:48:52 2009 +0200
+++ b/viff/aes.py Fri Sep 18 16:14:20 2009 +0200
@@ -107,6 +107,8 @@
self.invert = lambda byte: byte ** 254
elif (use_exponentiation == "shortest_chain_with_least_rounds"):
self.invert = self.invert_by_exponentiation_with_less_rounds
+ elif (use_exponentiation == "chain_with_least_rounds"):
+ self.invert = self.invert_by_exponentiation_with_least_rounds
else:
self.invert = self.invert_by_exponentiation
else:
@@ -117,7 +119,8 @@
exponentiation_variants = ["standard_square_and_multiply",
"shortest_sequential_chain",
- "shortest_chain_with_least_rounds"]
+ "shortest_chain_with_least_rounds",
+ "chain_with_least_rounds"]
def invert_by_masking(self, byte):
bits = bit_decompose(byte)
@@ -172,13 +175,29 @@
byte_4 = byte_2 * byte_2
byte_8 = byte_4 * byte_4
byte_9 = byte_8 * byte
+ byte_18 = byte_9 * byte_9
+ byte_19 = byte_18 * byte
+ byte_36 = byte_18 * byte_18
+ byte_55 = byte_36 * byte_19
+ byte_72 = byte_36 * byte_36
+ byte_127 = byte_72 * byte_55
+ byte_254 = byte_127 * byte_127
+ return byte_254
+
+ def invert_by_exponentiation_with_least_rounds(self, byte):
+ byte_2 = byte * byte
+ byte_3 = byte_2 * byte
+ byte_4 = byte_2 * byte_2
+ byte_7 = byte_4 * byte_3
+ byte_8 = byte_4 * byte_4
+ byte_15 = byte_8 * byte_7
byte_16 = byte_8 * byte_8
- byte_25 = byte_16 * byte_9
- byte_50 = byte_25 * byte_25
- byte_54 = byte_50 * byte_4
- byte_100 = byte_50 * byte_50
- byte_200 = byte_100 * byte_100
- byte_254 = byte_200 * byte_54
+ byte_31 = byte_16 * byte_15
+ byte_32 = byte_16 * byte_16
+ byte_63 = byte_32 * byte_31
+ byte_64 = byte_32 * byte_32
+ byte_127 = byte_64 * byte_63
+ byte_254 = byte_127 * byte_127
return byte_254
# matrix for byte_sub, the last column is the translation vector
diff -r f2fce145b9e1 -r d325a4ee6625 viff/runtime.py
--- a/viff/runtime.py Fri Sep 18 15:48:52 2009 +0200
+++ b/viff/runtime.py Fri Sep 18 16:14:20 2009 +0200
@@ -288,6 +288,9 @@
#: Data expected to be received in the future.
self.incoming_data = {}
self.waiting_deferreds = {}
+ #: Statistics
+ self.sent_packets = 0
+ self.sent_bytes = 0
def connectionMade(self):
self.sendString(str(self.factory.runtime.id))
@@ -362,7 +365,10 @@
data_size = len(data)
fmt = "!HHB%dI%ds" % (pc_size, data_size)
t = (pc_size, data_size, data_type) + program_counter + (data,)
- self.sendString(struct.pack(fmt, *t))
+ packet = struct.pack(fmt, *t)
+ self.sendString(packet)
+ self.sent_packets += 1
+ self.sent_bytes += len(packet)
def sendShare(self, program_counter, share):
"""Send a share.
@@ -842,6 +848,13 @@
self.depth_counter -= 1
self.activation_counter = 0
+ def print_transferred_data():
+ """Print the amount of transferred data for all connections."""
+
+ for protocol in self.protocols.itervalues():
+ print "Transfer to peer %d: %d bytes in %d packets" % \
+ (protocol.peer_id, protocol.sent_bytes,
protocol.sent_packets)
+
def make_runtime_class(runtime_class=None, mixins=None):
"""Creates a new runtime class with *runtime_class* as a base
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk