Advertisement
Guest User

Untitled

a guest
Aug 8th, 2020
379
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. nistp256r1_order = 0xFFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E84F3B9CAC2FC632551
  2. nistp256r1_modulus = 2**224 * (2**32 - 1) + 2**192 + 2**96 - 1
  3. nistp256r1_a = 0xFFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC
  4. nistp256r1_b = 0x5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B
  5.  
  6. nistp256r1_field = GF(nistp256r1_modulus)
  7. nistp256r1 = EllipticCurve(nistp256r1_field, [0,0,0,nistp256r1_a,nistp256r1_b])
  8.  
  9. nistp256r1_base_x = 0x6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296
  10. nistp256r1_base_y = 0x4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5
  11. nistp256r1_gen = nistp256r1(nistp256r1_base_x, nistp256r1_base_y, 1)
  12.  
  13. curve = nistp256r1
  14. curve_order = nistp256r1_order
  15. curve_gen = nistp256r1_gen
  16.  
  17. CG = Zmod(curve_order)
  18.  
  19. ### these are "inputs" to the system. Only pubkey is known
  20. privkey = CG.random_element()
  21. Q = curve(ZZ(privkey) * curve_gen)
  22.  
  23. ### we generates the necessary malicious generator
  24.  
  25. kprime = CG.random_element()
  26. kprimeinv = kprime.inverse_of_unit()
  27.  
  28. Gprime = ZZ(kprimeinv) * Q
  29.  
  30. ### We can now verify that the we knows a private key corresponding
  31. ### to the public key under their generator
  32. newpoint = curve(ZZ(kprime) * curve_gen)
  33. Qprime = curve(ZZ(kprime) * Gprime)
  34. print("Q==Q'", Qprime == Q)
  35. print(Qprime.xy())
  36. print(Q.xy())
  37. print(newpoint)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement