changeset 328:c92e686a49a2

Now we handle random and random_bit as we claim
author Sigurd Meldgaard <stm@daimi.au.dk>
date Mon, 05 Jul 2010 12:45:16 +0200
parents 255072c0714d
children c3a826ce9a0c
files pysmcl/functions.py pysmcl/runtime_sugar.py pysmcl/secret_annotator.py
diffstat 3 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/functions.py	Wed Jun 30 13:23:39 2010 +0200
+++ b/pysmcl/functions.py	Mon Jul 05 12:45:16 2010 +0200
@@ -28,8 +28,10 @@
     return runtime.id
 
 def random(runtime):
-    # TODO: what is the right thing here?
-    return runtime.prss_share_random()
+    return runtime.prss_share_random(pysmcl.setup.Zp)
+
+def random_bit(runtime):
+    return runtime.prss_share_random(pysmcl.setup.Zp, True)
 
 def result(x):
     """Just the id function, marks results for the verifier"""
--- a/pysmcl/runtime_sugar.py	Wed Jun 30 13:23:39 2010 +0200
+++ b/pysmcl/runtime_sugar.py	Mon Jul 05 12:45:16 2010 +0200
@@ -49,7 +49,9 @@
                 yield_exp = ast.Yield(value=node)
                 ast.copy_location(yield_exp, node)
                 return yield_exp
-            if(node.func.id == "input"):
+            if(node.func.id == "input" or
+               node.func.id == "random" or
+               node.func.id == "random_bit"):
                 node.args.insert(0, runtime)
             if(node.func.id in pysmcl.secret_annotator.annotated_functions):
                 node.args.insert(0, runtime)
--- a/pysmcl/secret_annotator.py	Wed Jun 30 13:23:39 2010 +0200
+++ b/pysmcl/secret_annotator.py	Mon Jul 05 12:45:16 2010 +0200
@@ -2,9 +2,10 @@
 import pysmcl.flow
 
 non_compromising_functions = set(["len", "output", "result",
-                                  "invariant", "precondition"])
+                                  "invariant", "precondition",
+                                  "random", "random_bit"])
 
-secret_functions = set(["input"])
+secret_functions = set(["input", "random", "random_bit"])
 
 annotated_functions = {}