You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

  1. import unittest, operator
  2. load("ring-signatures.sage")
  3. # A Rust implementation of this scheme can be found at:
  4. # https://github.com/arnaucube/ring-signatures-rs
  5. # ethereum elliptic curve
  6. p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
  7. a = 0
  8. b = 7
  9. F = GF(p)
  10. E = EllipticCurve(F, [a,b])
  11. GX = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798
  12. GY = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8
  13. g = E(GX,GY)
  14. n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141
  15. h = 1
  16. q = g.order()
  17. assert is_prime(p)
  18. assert is_prime(q)
  19. assert g * q == 0
  20. class TestRingSignatures(unittest.TestCase):
  21. def test_bLSAG_ring_of_5(self):
  22. test_bLSAG(5, 3)
  23. def test_bLSAG_ring_of_20(self):
  24. test_bLSAG(20, 14)
  25. def test_bLSAG(ring_size, pi):
  26. print(f"[bLSAG] Testing with a ring of {ring_size} keys")
  27. prover = Prover(F, g)
  28. n = ring_size
  29. R = [None] * n
  30. # generate prover's key pair
  31. K_pi = prover.new_key()
  32. # generate other n public keys
  33. for i in range(0, n):
  34. R[i] = g * i
  35. # set K_pi
  36. R[pi] = K_pi
  37. # sign m
  38. m = 1234
  39. print("sign")
  40. sig = prover.sign(m, R)
  41. print("verify")
  42. key_image = prover.w * hashToPoint(prover.K)
  43. verify(g, R, m, key_image, sig)
  44. if __name__ == '__main__':
  45. unittest.main()