SHARE
TWEET

SRP Adapted for Elliptic Curves

stevenalexanderjr May 6th, 2014 159 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # SRP Adapted for Elliptic Curves - Steven M. Alexander Jr. - 5/6/2014
  2.  
  3. # NIST Parameters
  4. NIST_p = 115792089210356248762697446949407573530086143415290314195533631308867097853951
  5. NIST_r = 115792089210356248762697446949407573529996955224135760342422259061068512044369
  6. NIST_b = Integer(0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b)
  7. NIST_Px = Integer(0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296)
  8. NIST_Py = Integer(0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5)
  9. NIST_Qx = Integer(0xc97445f45cdef9f0d3e05e1e585fc297235b82b5be8ff3efca67c59852018192)
  10. NIST_Qy = Integer(0xb28ef557ba31dfcbdd21ac46e2a91e3c304f44cb87058ada2cb815151e610046)
  11.  
  12. # Construct E and Q using NIST parameters
  13. F = GF(NIST_p)
  14. E = EllipticCurve(F, [0, 0, 0, -3, NIST_b])
  15. print "E: " + str(E)
  16. print
  17. Q = E(NIST_Qx, NIST_Qy)
  18. print "Q: " + str(Q) + "\n"
  19.  
  20. # Use Alice's password hash to determine P
  21. x = Integer(0x4efa264f5ef3e1a5c95736e07544ebf0)
  22. print "MD5 Hash of \"curve\", x = " + str(x)
  23. P = x*Q
  24. print "P = x*Q = " + str(P) + "\n"
  25.  
  26. #Create Alice's public key
  27. A_a = Integer(0xd103fb3406c351a03578097503d26fa5)
  28. A_A = A_a*Q
  29. print "Alice's secret key a = " + str(A_a)
  30. print "Alice's public key A = a*Q = " + str(A_A) + "\n"
  31.  
  32. #Give Alice's key to Bob
  33. B_A = A_A
  34.  
  35. # Create Bob's public key, Bprime
  36. B_b = Integer(0x6abd98d8b311a26ab2cab394e1ecb8af)
  37. print "Bob's secret key b = " + str(B_b)
  38. B_Bprime = B_b*Q
  39. print "Bob's value of Bprime = " + str(B_Bprime) + "\n"
  40.  
  41. # Generate Tp and Tq
  42. B_r = Integer(0xdfd98dc638b36d4f86712de2e3bd37de)
  43. print "Bob's random value r = " + str(B_r)
  44. B_Tq = B_r*Q
  45. B_Tp = B_r*P
  46. print "Bob's Tq = r*Q = " + str(B_Tq)
  47. print "Bob's Tp = r*P = " + str(B_Tp)
  48.  
  49. # Mask Bob's public key using Tp
  50. B_B = B_Bprime+B_Tp
  51. print "Bob's value of B = " + str(B_B) + "\n"
  52.  
  53. # Give B and Tq to Alice
  54. A_Tq = B_Tq
  55. A_B = B_B
  56.  
  57. # Calculate Alice's Tp
  58. A_Tp = x*A_Tq
  59. A_Bprime = A_B - A_Tp
  60. print "Alice's Tp = " + str(A_Tp)
  61. print "Alice's Bprime = " + str(A_Bprime) + "\n"
  62.  
  63. # Alice's calculation of the shared key
  64. A_S = A_a*A_Bprime
  65. print "Alice's S = " + str(A_S)
  66.  
  67. # Bob's calculation of the shared key
  68. B_S = B_b*B_A
  69. print "Bob's S = " + str(B_S)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top