mirror of
https://github.com/Mbed-TLS/mbedtls-framework.git
synced 2026-08-06 19:27:47 +00:00
Fix documentation of bignum_common.invmod()
Python's built-in pow() always returns a positive result. Signed-off-by: Manuel Pégourié-Gonnard <[email protected]>
This commit is contained in:
@@ -19,8 +19,7 @@ T = TypeVar('T') #pylint: disable=invalid-name
|
||||
def invmod(a: int, n: int) -> int:
|
||||
"""Return inverse of a to modulo n.
|
||||
|
||||
Equivalent to pow(a, -1, n) in Python 3.8+. Implementation is equivalent
|
||||
to long_invmod() in CPython.
|
||||
Warning: the output might be negative! See invmod_positive().
|
||||
"""
|
||||
b, c = 1, 0
|
||||
while n:
|
||||
@@ -32,7 +31,10 @@ def invmod(a: int, n: int) -> int:
|
||||
raise ValueError("Not invertible")
|
||||
|
||||
def invmod_positive(a: int, n: int) -> int:
|
||||
"""Return a non-negative inverse of a to modulo n."""
|
||||
"""Return a non-negative inverse of a to modulo n.
|
||||
|
||||
Equivalent to pow(a, -1, n) in Python 3.8+.
|
||||
"""
|
||||
inv = invmod(a, n)
|
||||
return inv if inv >= 0 else inv + n
|
||||
|
||||
|
||||
Reference in New Issue
Block a user