Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: add tests for scalarMult and parsePubKey in crypto.secp256k1.curve.KoblitzCurve #76

Merged
merged 11 commits into from
Feb 15, 2020
Merged

tests: add tests for scalarMult and parsePubKey in crypto.secp256k1.curve.KoblitzCurve #76

merged 11 commits into from
Feb 15, 2020

Conversation

teknico
Copy link
Collaborator

@teknico teknico commented Feb 14, 2020

Part of #70, based on #74.

Add tests for KoblitzCurve.scalarMult and KoblitzCurve.parsePubKey in decred/crypto/secp256k1/curve.py.

KoblitzCurve.scalarMult:

  • add two tests;
  • fix two bugs;
  • rename curve.curve to curve_obj in test_curve.py.

KoblitzCurve.parsePubKey:

  • add two tests;
  • implement PublicKey.__eq__;
  • use ValueError instead of Exception.

@@ -260,8 +270,10 @@ def scalarMult(self, Bx, By, k):
# elliptic curves states that P(x, y) = -P(x, -y), it's faster and
# simplifies the code to just make the point negative.
if k1 < 0:
k1 = -k1
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In Go, KoblitzCurve.splitK always returns absolute k1 and k2, and their signs are returned separately. Here, KoblitzCurve.splitK returns signed k1 and k2. When they are negative they cannot be converted to ByteArrays on lines 283-284 below. Their negative sign is handled explicitly here, so they can be turned into absolute values safely.

p1y, p1yNeg = p1yNeg, p1y
if k2 < 1:
if k2 < 0:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Same test as for k1 above, clearly a typo.

Copy link
Member

@buck54321 buck54321 left a comment

Choose a reason for hiding this comment

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

Good after rebase. Nice bug fixes.

- test helpers "randBytes" and "sign" removed from util/helpers.py and moved
  to a conftest.py file in the tests/ root directory, as pytest fixtures;
- test_curve.py changed to use the new fixtures;
- unit/util/test_database.py restored to its original state.
- fixed two bugs in KoblitzCurve.scalarMult;
- renamed curve.curve in test_curve.py;
- edited several docstrings in curve.py .
- implement PublicKey.__eq__;
- use ValueError instead of Exception in KoblitzCurve.parsePubKey .
@buck54321 buck54321 merged commit cb124d3 into decred:master Feb 15, 2020
@teknico teknico deleted the more-curve-tests-2 branch February 15, 2020 18:29
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.

2 participants