Skip to content

Commit

Permalink
xmr: bp - detect which modular inversion is usable
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Aug 17, 2018
1 parent f895fa6 commit cbf74a7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/apps/monero/xmr/bulletproof.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ def mul_inverse(x, n):
return pow(x, n - 2, n)


mul_inverse_used = mul_inverse_egcd
try:
pow(2, 5, 7)
mul_inverse_used = mul_inverse_egcd
except NotImplementedError:
pass


def invert(dst, x):
"""
Modular inversion mod curve order.
Expand All @@ -104,7 +112,7 @@ def invert(dst, x):
dst = _ensure_dst_key(dst)
xint = 0
xint = xint.from_bytes(x, "little")
xinv = mul_inverse(xint, ED25519_ORD)
xinv = mul_inverse_used(xint, ED25519_ORD)
buff = xinv.to_bytes(32, "little")
copy_key(dst, buff)
return dst
Expand Down

0 comments on commit cbf74a7

Please sign in to comment.