- Modified the multinsl generator to also be able to generate bke

variants (--protocol bke).
This commit is contained in:
ccremers 2005-12-21 18:44:34 +00:00
parent aab5328a9b
commit 00e49601eb
2 changed files with 219 additions and 175 deletions

View File

@ -19,6 +19,23 @@
# assuming full type flaws. # assuming full type flaws.
# #
import sys 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): def variablerole (r, inrole):
if r == inrole or inrole == 0: if r == inrole or inrole == 0:
@ -31,6 +48,12 @@ def role (r,inrole):
return "r%i" % (r % P) return "r%i" % (r % P)
def zeroconst ():
""" This is 0 or some other stupid constant """
return "zeroconst"
def nonce (r,inrole): def nonce (r,inrole):
global P global P
@ -94,8 +117,9 @@ def message1 (label,inrole):
)) ))
def message2 (label,inrole): def message2 (label,inrole):
global P,variant global P,variant,opts
if opts.protocol == "nsl":
noncelist = [] noncelist = []
for i in range (((label + 1) % P),P): for i in range (((label + 1) % P),P):
noncelist.append(nonce(i,inrole)) noncelist.append(nonce(i,inrole))
@ -106,9 +130,24 @@ def message2 (label,inrole):
False, False,
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): def message (label,inrole):
global P global P,opts
s = "{ " s = "{ "
if label < P: if label < P:
@ -116,6 +155,9 @@ def message (label,inrole):
else: else:
s = s + message2 (label,inrole) 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) s = s + " }pk(%s)" % role(label+1,inrole)
return s return s
@ -191,18 +233,25 @@ def roledef (r):
return s return s
def protocol (pset,vset): def protocol (args):
global P,variant global P,variant,opts
P = pset P = int(args[0])
variant = vset variant = int(args[1])
s = "" 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 += "// Variant %i\n" % variant
s += "const pk: Function;\n" s += "const pk: Function;\n"
s += "secret sk: 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) s += "protocol mnsl%iv%i(" % (P,variant)
for i in range (0,P): for i in range (0,P):
@ -227,16 +276,11 @@ def protocol (pset,vset):
return s return s
def main(): def main():
if len(sys.argv) < 3: global opts
print "We need at least 2 arguments: number of parties, and variant"
print "Note that variant is in [0..31]" (opts,args) = parseArgs()
print "" print protocol(args)
print "E.g. './multinsl-generator.py 2 0' yields a default NSL protocol"
else:
print protocol(int (sys.argv[1]), int(sys.argv[2]))
# Only if main stuff # Only if main stuff
if __name__ == '__main__': if __name__ == '__main__':
main() main()
else:
print protocol (2,0)

View File

@ -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 -m2 --summary %s" % (runs, extraflags)
#s += " | scyther -a -r%i --summary" % runs #s += " | scyther -a -r%i --summary" % runs
#print s #print s
s += " | grep \"failed:\"" s += " | grep \"complete_proof\""
out = commands.getoutput(s) out = commands.getoutput(s)
if out == "": if out == "":
#print "Okay" #print "Okay"