aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/key.py
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2023-04-27 18:08:20 +0100
committerFabian Jahr <fjahr@protonmail.com>2023-04-28 14:19:18 +0200
commitdc14ba08e6e502f3e31d935bcd053a287c6610ca (patch)
tree51cf477c0f1c5818ab21716e9f33487769e513b2 /test/functional/test_framework/key.py
parentd89aca1bdbe52406f000e3fa8dda12c46dca9bdd (diff)
test: remove modinv python util helper function
Diffstat (limited to 'test/functional/test_framework/key.py')
-rw-r--r--test/functional/test_framework/key.py8
1 files changed, 3 insertions, 5 deletions
diff --git a/test/functional/test_framework/key.py b/test/functional/test_framework/key.py
index ad305ce1ef..efb4934ff0 100644
--- a/test/functional/test_framework/key.py
+++ b/test/functional/test_framework/key.py
@@ -13,8 +13,6 @@ import os
import random
import unittest
-from .util import modinv
-
# Point with no known discrete log.
H_POINT = "50929b74c1a04954b78b4b6035e97a5e078a5a0f28ec96d547bfee9ace803ac0"
@@ -78,7 +76,7 @@ class EllipticCurve:
x1, y1, z1 = p1
if z1 == 0:
return None
- inv = modinv(z1, self.p)
+ inv = pow(z1, -1, self.p)
inv_2 = (inv**2) % self.p
inv_3 = (inv_2 * inv) % self.p
return ((inv_2 * x1) % self.p, (inv_3 * y1) % self.p, 1)
@@ -319,7 +317,7 @@ class ECPubKey():
z = int.from_bytes(msg, 'big')
# Run verifier algorithm on r, s
- w = modinv(s, SECP256K1_ORDER)
+ w = pow(s, -1, SECP256K1_ORDER)
u1 = z*w % SECP256K1_ORDER
u2 = r*w % SECP256K1_ORDER
R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, u1), (self.p, u2)]))
@@ -397,7 +395,7 @@ class ECKey():
k = random.randrange(1, SECP256K1_ORDER)
R = SECP256K1.affine(SECP256K1.mul([(SECP256K1_G, k)]))
r = R[0] % SECP256K1_ORDER
- s = (modinv(k, SECP256K1_ORDER) * (z + self.secret * r)) % SECP256K1_ORDER
+ s = (pow(k, -1, SECP256K1_ORDER) * (z + self.secret * r)) % SECP256K1_ORDER
if low_s and s > SECP256K1_ORDER_HALF:
s = SECP256K1_ORDER - s
# Represent in DER format. The byte representations of r and s have