From cbf74a7082ee3dd176217298c886ef48bf4ccd9a Mon Sep 17 00:00:00 2001 From: Dusan Klinec Date: Fri, 17 Aug 2018 03:04:01 +0200 Subject: [PATCH] xmr: bp - detect which modular inversion is usable --- src/apps/monero/xmr/bulletproof.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/apps/monero/xmr/bulletproof.py b/src/apps/monero/xmr/bulletproof.py index 891f123bc..c7994c6e8 100644 --- a/src/apps/monero/xmr/bulletproof.py +++ b/src/apps/monero/xmr/bulletproof.py @@ -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. @@ -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