- Modified the multinsl generator to also be able to generate bke
variants (--protocol bke).
This commit is contained in:
parent
aab5328a9b
commit
00e49601eb
@ -19,6 +19,23 @@
|
||||
# assuming full type flaws.
|
||||
#
|
||||
import sys
|
||||
from optparse import OptionParser
|
||||
|
||||
def parseArgs():
|
||||
usage = "usage: %s [opts]" % sys.argv[0]
|
||||
parser = OptionParser(usage=usage)
|
||||
parser.add_option('-p','--protocol', dest='protocol',
|
||||
help='Generate another protocol', default="nsl",
|
||||
action='store')
|
||||
(opts, args) = parser.parse_args()
|
||||
if len(args) != 2:
|
||||
parser.print_help()
|
||||
sys.exit(0)
|
||||
if opts.protocol not in ["nsl","bke"]:
|
||||
print "I don't know the %s protocol." % (opts.protocol)
|
||||
sys.exit(0)
|
||||
return (opts,args)
|
||||
|
||||
|
||||
def variablerole (r, inrole):
|
||||
if r == inrole or inrole == 0:
|
||||
@ -31,6 +48,12 @@ def role (r,inrole):
|
||||
|
||||
return "r%i" % (r % P)
|
||||
|
||||
def zeroconst ():
|
||||
|
||||
""" This is 0 or some other stupid constant """
|
||||
|
||||
return "zeroconst"
|
||||
|
||||
def nonce (r,inrole):
|
||||
global P
|
||||
|
||||
@ -94,8 +117,9 @@ def message1 (label,inrole):
|
||||
))
|
||||
|
||||
def message2 (label,inrole):
|
||||
global P,variant
|
||||
global P,variant,opts
|
||||
|
||||
if opts.protocol == "nsl":
|
||||
noncelist = []
|
||||
for i in range (((label + 1) % P),P):
|
||||
noncelist.append(nonce(i,inrole))
|
||||
@ -106,9 +130,24 @@ def message2 (label,inrole):
|
||||
False,
|
||||
False
|
||||
))
|
||||
elif opts.protocol == "bke":
|
||||
noncelist = []
|
||||
for i in range (((label + 1) % P) + 1,P):
|
||||
noncelist.append(nonce(i,inrole))
|
||||
if len(noncelist) == 0:
|
||||
noncelist.append(zeroconst())
|
||||
|
||||
return ",".join(weavel(noncelist,[],
|
||||
(variant & 16 != 0),
|
||||
False,
|
||||
False,
|
||||
False
|
||||
))
|
||||
else:
|
||||
print "Hmm, I don't know how to create the final message for protocol %s" % (opts.protocol)
|
||||
|
||||
def message (label,inrole):
|
||||
global P
|
||||
global P,opts
|
||||
|
||||
s = "{ "
|
||||
if label < P:
|
||||
@ -116,6 +155,9 @@ def message (label,inrole):
|
||||
else:
|
||||
s = s + message2 (label,inrole)
|
||||
|
||||
if opts.protocol == "bke" and not (label < P):
|
||||
s = s + " }" + nonce((label+1) % P, inrole)
|
||||
else:
|
||||
s = s + " }pk(%s)" % role(label+1,inrole)
|
||||
return s
|
||||
|
||||
@ -191,18 +233,25 @@ def roledef (r):
|
||||
return s
|
||||
|
||||
|
||||
def protocol (pset,vset):
|
||||
global P,variant
|
||||
def protocol (args):
|
||||
global P,variant,opts
|
||||
|
||||
P = pset
|
||||
variant = vset
|
||||
P = int(args[0])
|
||||
variant = int(args[1])
|
||||
|
||||
s = ""
|
||||
s += "// Generalized Needham-Schroeder-Lowe for %i parties\n\n" % P
|
||||
s += "// Generalized %s protocol for %i parties\n\n" % (opts.protocol,P)
|
||||
s += "// " + str(opts) + "\n\n"
|
||||
s += "// Variant %i\n" % variant
|
||||
s += "const pk: Function;\n"
|
||||
s += "secret sk: Function;\n"
|
||||
s += "inversekeys (pk,sk);\n\n"
|
||||
s += "inversekeys (pk,sk);\n"
|
||||
|
||||
if opts.protocol == "bke":
|
||||
s += "usertype Globalconstant;\n"
|
||||
s += "const %s: Globalconstant;\n" % (zeroconst())
|
||||
|
||||
s += "\n"
|
||||
|
||||
s += "protocol mnsl%iv%i(" % (P,variant)
|
||||
for i in range (0,P):
|
||||
@ -227,16 +276,11 @@ def protocol (pset,vset):
|
||||
return s
|
||||
|
||||
def main():
|
||||
if len(sys.argv) < 3:
|
||||
print "We need at least 2 arguments: number of parties, and variant"
|
||||
print "Note that variant is in [0..31]"
|
||||
print ""
|
||||
print "E.g. './multinsl-generator.py 2 0' yields a default NSL protocol"
|
||||
else:
|
||||
print protocol(int (sys.argv[1]), int(sys.argv[2]))
|
||||
global opts
|
||||
|
||||
(opts,args) = parseArgs()
|
||||
print protocol(args)
|
||||
|
||||
# Only if main stuff
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
else:
|
||||
print protocol (2,0)
|
||||
|
@ -29,7 +29,7 @@ def tuplingchoice(variant,P,runs,latupling):
|
||||
s += " | scyther -a -r%i -m2 --summary %s" % (runs, extraflags)
|
||||
#s += " | scyther -a -r%i --summary" % runs
|
||||
#print s
|
||||
s += " | grep \"failed:\""
|
||||
s += " | grep \"complete_proof\""
|
||||
out = commands.getoutput(s)
|
||||
if out == "":
|
||||
#print "Okay"
|
||||
|
Loading…
Reference in New Issue
Block a user