changeset 180:862f30985ed5

secret_ifs: now checks that the range matches before doing rewrite.
author Sigurd Meldgaard <stm@daimi.au.dk>
date Wed, 16 Dec 2009 12:51:47 +0100
parents 00836287599e
children 9b4cd7d86f1b
files pysmcl/secret_ifs.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/pysmcl/secret_ifs.py	Wed Dec 16 11:38:44 2009 +0100
+++ b/pysmcl/secret_ifs.py	Wed Dec 16 12:51:47 2009 +0100
@@ -7,6 +7,9 @@
 
 import pysmcl.ast_wrapper as ast
 import pysmcl.secret_annotator
+import pysmcl.setup
+from pysmcl.range_analysis import RangeVisitor
+
 from pysmcl.util import error
 
 
@@ -99,7 +102,10 @@
 
     def visit_If(self, node):
         self.generic_visit(node)
-        if(pysmcl.secret_annotator.expr_secret(node.test)):   
+        if(pysmcl.secret_annotator.expr_secret(node.test)):
+            range_visitor = RangeVisitor(pysmcl.setup.Zp.modulus, node.in_values["range"])
+            if range_visitor.visit(node.test) != (0,1):
+                error("The condition cannot be proven to be in the range (0, 1)", node)
             self.changed = True
             replacement = []
             r_then = self.do_body(node.body, "_then")