-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
@@ -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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 .
Part of #70, based on #74.
Add tests for
KoblitzCurve.scalarMult
andKoblitzCurve.parsePubKey
indecred/crypto/secp256k1/curve.py
.KoblitzCurve.scalarMult
:curve.curve
tocurve_obj
intest_curve.py
.KoblitzCurve.parsePubKey
:PublicKey.__eq__
;