aboutsummaryrefslogtreecommitdiff
path: root/test/functional/test_framework/key.py
diff options
context:
space:
mode:
authorFabian Jahr <fjahr@protonmail.com>2020-06-11 14:59:08 +0200
committerFabian Jahr <fjahr@protonmail.com>2020-07-16 18:10:43 +0200
commitab30cece0e84a8b917cb9a219c2466574362f300 (patch)
tree262766be502124fd6d5dbfece2788ee4187229d8 /test/functional/test_framework/key.py
parentb33136b6ba9887f7db651c4c5264ca7f2f601df7 (diff)
test: Move modinv to util and add unit test
Diffstat (limited to 'test/functional/test_framework/key.py')
-rw-r--r--test/functional/test_framework/key.py17
1 files changed, 1 insertions, 16 deletions
diff --git a/test/functional/test_framework/key.py b/test/functional/test_framework/key.py
index 912c0ca978..adbffb7dc7 100644
--- a/test/functional/test_framework/key.py
+++ b/test/functional/test_framework/key.py
@@ -8,22 +8,7 @@ keys, and is trivially vulnerable to side channel attacks. Do not use for
anything but tests."""
import random
-def modinv(a, n):
- """Compute the modular inverse of a modulo n
-
- See https://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Modular_integers.
- """
- t1, t2 = 0, 1
- r1, r2 = n, a
- while r2 != 0:
- q = r1 // r2
- t1, t2 = t2, t1 - q * t2
- r1, r2 = r2, r1 - q * r2
- if r1 > 1:
- return None
- if t1 < 0:
- t1 += n
- return t1
+from .util import modinv
def jacobi_symbol(n, k):
"""Compute the Jacobi symbol of n modulo k