Skip to content

Conversation

@prusnak
Copy link
Member

@prusnak prusnak commented Oct 28, 2025

What title says

The code was generated using Codex - please review meticulously!

The tests pass though.

if x1 == x2:
return None

slope = ((y2 - y1) * self._inverse_mod((x2 - x1) % self.p)) % self.p
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

% is unnecessary since it happens in _inverse_mod().

Suggested change
slope = ((y2 - y1) * self._inverse_mod((x2 - x1) % self.p)) % self.p
slope = ((y2 - y1) * self._inverse_mod(x2 - x1)) % self.p

if y == 0:
return None

slope = ((3 * x * x + self.a) * self._inverse_mod((2 * y) % self.p)) % self.p
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
slope = ((3 * x * x + self.a) * self._inverse_mod((2 * y) % self.p)) % self.p
slope = ((3 * x * x + self.a) * self._inverse_mod(2 * y)) % self.p

y3 = (slope * (x - x3) - y) % self.p
return x3, y3

def _scalar_mult(self, scalar: int, point: Tuple[int, int]) -> Point:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _scalar_mult(self, scalar: int, point: Tuple[int, int]) -> Point:
def _scalar_mult(self, scalar: int, point: Point) -> Point:

Comment on lines +205 to +206
x = int.from_bytes(data[1 : 1 + self.coordinate_size], "big")
y = int.from_bytes(data[1 + self.coordinate_size :], "big")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = int.from_bytes(data[1 : 1 + self.coordinate_size], "big")
y = int.from_bytes(data[1 + self.coordinate_size :], "big")
x = int.from_bytes(data[1 : 1 + self.coordinate_size], "big")
if (x >= self.p):
raise ValueError("Invalid x-coordinate")
y = int.from_bytes(data[1 + self.coordinate_size :], "big")
if (y >= self.p):
raise ValueError("Invalid y-coordinate")

if len(data) != self.coordinate_size + 1 or data[0] not in (2, 3):
raise ValueError("Invalid public key encoding")

x = int.from_bytes(data[1:], "big")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
x = int.from_bytes(data[1:], "big")
if (x >= self.p):
raise ValueError("Invalid x-coordinate")

Comment on lines +228 to +229
if x >= self.p:
raise ValueError("Invalid point")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if x >= self.p:
raise ValueError("Invalid point")
if self.p % 4 != 3:
raise NotImplementedError("Square root for this modulus is not implemented")

@andrewkozlik
Copy link
Collaborator

Closing in favor of #4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants