Skip to content

Commit

Permalink
Fix montgomery prod/inv calculations + pylint/mypy
Browse files Browse the repository at this point in the history
  • Loading branch information
fpapa250 committed Oct 17, 2024
1 parent d8ba6d3 commit d09e500
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions qualtran/_infra/data_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ def montgomery_inverse(self, xm: int, p: int) -> int:
xm: An integer in montgomery form.
p: The modulus of the finite field.
"""
return ((pow(xm, p - 2, p)) * pow(2, 2 * self.bitsize, p)) % p
return ((pow(xm, -1, p)) * pow(2, 2 * self.bitsize, p)) % p

def montgomery_product(self, xm: int, ym: int, p: int) -> int:
"""Returns the modular product of two integers in montgomery form.
Expand All @@ -832,7 +832,7 @@ def montgomery_product(self, xm: int, ym: int, p: int) -> int:
ym: The second montgomery form integer for the product.
p: The modulus of the finite field.
"""
return (xm * ym * pow(2, self.bitsize * (p - 2), p)) % p
return (xm * ym * pow(2, -self.bitsize, p)) % p

def montgomery_to_uint(self, xm: int, p: int) -> int:
"""Converts an integer in montgomery form to a normal form integer.
Expand All @@ -841,16 +841,16 @@ def montgomery_to_uint(self, xm: int, p: int) -> int:
xm: An integer in montgomery form.
p: The modulus of the finite field.
"""
return (xm * pow(2, self.bitsize * (p - 2), p)) % p
return (xm * pow(2, -self.bitsize, p)) % p

def uint_to_montgomery(self, x: int, p: int) -> int:
"""Converts an integer into montgomery form.
Args:
xm: An integer.
x: An integer.
p: The modulus of the finite field.
"""
return (x * pow(2, self.bitsize, p)) % p
return (x * pow(2, int(self.bitsize), p)) % p


@attrs.frozen
Expand Down

0 comments on commit d09e500

Please sign in to comment.