Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python2
- import hashlib, getpass, random, argparse, json, sys
- p = 0xD34E833410143D2582BF1F863E468A19DDDEBF15648402111C49414418A3256C6E3AA7B2FAC164DD1F5113D4E45E6D24D605F7D580E5F8233119C9D6103F6F2ED75C4D4CA7E9B73090260CB0D80029C194C2A81AE71732C393ACF6B2B10BC612CDF1C02F1F522B25633E26EB0AEE97D8086FF2397CADE66017213D6D2E9E441E939B888089E9C5EE8D4B797E5F5D5C2B35149C23138130E046174625F1449A481493A4C45BD8D508102E891E68141B4469E0624F4A6D615427C13FAAC8E2AE203E4631DFD368A83838A201716CEFC811EE0CB17C9C0B5464C654FFE97B1CCC868D71080EA0AD57709FE89DD39BA314B82E687AED27498377D2049891F14FDF03
- prompt = getpass.getpass
- # If you want the password prompt to be in the clear, uncomment this next line.
- #prompt = raw_input
- try:
- import gmpy
- assert gmpy.is_prime(p) and gmpy.is_prime(p // 2)
- except:
- print "Couldn't verify primality!"
- if len(sys.argv) != 2 or sys.argv[1] not in ("1", "2"):
- print "Usage: %s [1|2]" % sys.argv[0]
- print
- print "For the first phase of SPEKE, run with argument 1."
- print "This will write out a file ./secrets"
- print "For the second phase, run with the path to ./secrets as an argument."
- exit(1)
- if sys.argv[1] == "1":
- password = prompt(" Entropy: ")
- password2 = prompt("Entropy (again): ")
- assert password == password2
- g = int(hashlib.sha512(password).hexdigest(), 16)
- a = random.SystemRandom().randint(1, p)
- with open("secrets", "w") as f:
- print >>f, json.dumps({"g": g, "a": a}, indent=2)
- ga = pow(g, a, p)
- print
- print "g^a = 0x%x" % ga
- else:
- with open("secrets") as f:
- secrets = json.load(f)
- gb = input("Other party's g^a: ")
- gab = pow(gb, secrets["a"], p)
- symmetric_secret = hashlib.sha512(str(gab)).hexdigest()[:32]
- confirmation = hashlib.sha512(symmetric_secret).hexdigest()[:32]
- print "Symmetric secret:", symmetric_secret
- print "Confirmation:", confirmation
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement