dkg_ecdsa.sage 929 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # https://eprint.iacr.org/2021/060.pdf
  2. from hashlib import sha256
  3. t = 3 # Threshold
  4. n = 5 # Participants
  5. # secp256k1
  6. p = 2^256-2^32-977
  7. q = 0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141
  8. Fp = GF(p)
  9. Fq = GF(q)
  10. Ep = EllipticCurve(Fp, [0, 7])
  11. Ep.set_order(q)
  12. # Base point
  13. g = Ep([
  14. 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798,
  15. 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8,
  16. ])
  17. # Key Generation
  18. # ==============
  19. xi = []
  20. Xi = []
  21. Xi_proofs = []
  22. for i in range(n):
  23. x_i = Fq.random_element()
  24. X_i = g * x_i
  25. xi.append(x_i)
  26. Xi.append(X_i)
  27. # Schnorr proof of knowledge
  28. k = Fq.random_element()
  29. R = k * g
  30. hasher = sha256()
  31. hasher.update(str(X_i.xy()))
  32. hasher.update(str(R.xy()))
  33. e = Fq(int(hasher.hexdigest(), 16))
  34. s = k + e * x_i
  35. Xi_proofs.append((R, s))
  36. # Verifier computes: e = hash(X || r), s*g == R+e*X