8000 Merge pull request #146 from tomato42/ecdsa-test-cov · tlsfuzzer/python-ecdsa@8a4a1f9 · GitHub
[go: up one dir, main page]

8000
Skip to content

Commit 8a4a1f9

Browse files
authored
Merge pull request #146 from tomato42/ecdsa-test-cov
better test coverage for internal modules
2 parents fa7655c + 89fe31d commit 8a4a1f9

File tree

3 files changed

+657
-467
lines changed

3 files changed

+657
-467
lines changed

src/ecdsa/numbertheory.py

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,15 @@ class NegativeExponentError(Error):
3535
pass
3636

3737

38-
def modular_exp(base, exponent, modulus):
39-
"Raise base to exponent, reducing by modulus"
40-
if exponent < 0:
41-
raise NegativeExponentError("Negative exponents (%d) not allowed" \
42-
% exponent)
43-
return pow(base, exponent, modulus)
44-
# result = 1L
45-
# x = exponent
46-
# b = base + 0L
47-
# while x > 0:
48-
# if x % 2 > 0: result = (result * b) % modulus
49-
# x = x // 2
50-
# b = (b * b) % modulus
51-
# return result
38+
def modular_exp(base, exponent, modulus): # pragma: no cover
39+
"""Raise base to exponent, reducing by modulus"""
40+
# deprecated in 0.14
41+
warnings.warn("Function is unused in library code. If you use this code, "
42+
"change to pow() builtin.", DeprecationWarning)
43+
if exponent < 0:
44+
raise NegativeExponentError("Negative exponents (%d) not allowed"
45+
% exponent)
46+
return pow(base, exponent, modulus)
5247

5348

5449
def polynomial_reduce_mod(poly, polymod, p):
@@ -182,14 +177,14 @@ def square_root_mod_prime(a, p):
182177
% (a, p))
183178

184179
if p % 4 == 3:
185-
return modular_exp(a, (p + 1) // 4, p)
180+
return pow(a, (p + 1) // 4, p)
186181

187182
if p % 8 == 5:
188-
d = modular_exp(a, (p - 1) // 4, p)
183+
d = pow(a, (p - 1) // 4, p)
189184
if d == 1:
190-
return modular_exp(a, (p + 3) // 8, p)
185+
return pow(a, (p + 3) // 8, p)
191186
if d == p - 1:
192-
return (2 * a * modular_exp(4 * a, (p - 5) // 8, p)) % p
187+
return (2 * a * pow(4 * a, (p - 5) // 8, p)) % p
193188
raise RuntimeError("Shouldn't get here.")
194189

195190
if PY3:
@@ -524,11 +519,11 @@ def is_prime(n):
524519
r = r // 2
525520
for i in xrange(t):
526521
a = smallprimes[i]
527-
y = modular_exp(a, r, n)
522+
y = pow(a, r, n)
528523
if y != 1 and y != n - 1:
529524
j = 1
530525
while j <= s - 1 and y != n - 1:
531-
y = modular_exp(y, 2, n)
526+
y = pow(y, 2, n)
532527
if y == 1:
533528
miller_rabin_test_count = i + 1
534529
return False

0 commit comments

Comments
 (0)
0