-
Notifications
You must be signed in to change notification settings - Fork 1.1k
group: Avoid using infinity field directly in other modules #1764
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
base: master
Are you sure you want to change the base?
group: Avoid using infinity field directly in other modules #1764
Conversation
hebasto
left a comment
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.
Concept ACK.
Some other places still remain:
$ git grep -e "\.infinity" -- src ':(exclude)src/group_impl.h'
src/ecmult_const_impl.h: p.infinity = 0;
src/tests.c: SECP256K1_CHECKMEM_CHECK(&ge.infinity, sizeof(ge.infinity));
src/tests_exhaustive.c: zless_gej.infinity = groupj[j].infinity;
src/tests_exhaustive.c: CHECK(group[i].infinity == 0);
src/tests_exhaustive.c: CHECK(generated.infinity == 0);
|
Concept ACK |
46c7c8f to
2f73e52
Compare
|
Updated. There are three lines left in the tests, but all of them are justified. Check: By the way, one could think that this PR is a bit arbitrary because we also access the x, y, z fields everywhere. Perhaps this could also be improved. And this would actually have an immediate benefit because we could check that they're only accessed if the point is not infinity. But this should go to a separate PR, I think. |
I still think that Lines 3653 to 3654 in 2f73e52
If I'm wrong, maybe add an explanatory comment there? |
| break; | ||
| } | ||
| } while(1); | ||
| ge->infinity = 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.
Why is it correct to drop this line?
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.
secp256k1_ge_set_xo_var sets this already.
Line 355 in c8206b1
| r->infinity = 0; |
| secp256k1_fe z2, z3; | ||
| testutil_random_fe_non_zero_test(&gej->z); | ||
| secp256k1_fe_sqr(&z2, &gej->z); | ||
| secp256k1_fe_mul(&z3, &z2, &gej->z); | ||
| secp256k1_fe_mul(&gej->x, &ge->x, &z2); | ||
| secp256k1_fe_mul(&gej->y, &ge->y, &z3); | ||
| gej->infinity = ge->infinity; | ||
| secp256k1_fe z; | ||
| testutil_random_fe_non_zero_test(&z); | ||
| secp256k1_gej_set_ge(gej, ge); | ||
| secp256k1_gej_rescale(gej, &z); |
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.
I had a hard time following these changes. Could you shed a bit more light on them?
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.
What this function does is take a ge and convert it to a gej with a random z coordinate. This can be done in two steps:
- convert ge to gej
- rescale the gej
More details:
- ge is a "normal" affine point with x and y coordinates. gej (Jacobian coordinates) represent
ge.xandge.yasgej.xgej.ygej.zwithThus, the canonical way toge.x = gej.x / gej.z^2 ge.y = gej.y / gej.z^3getogejis to setgej.z = 1and then justgej.x = ge.xandgej.y = ge.ybecausez^2 = 1andz^3 = 1 - Rescaling a gej means changing the representation without changing the effective x and y. This can be multiplying the existing z coordinate with a given field element. To accommodate, we'll need to multiply x with z^2 and y with z^3.
Or another answer: If you look into secp256k1_gej_set_ge and secp256k1_gej_rescale you'll be able to check that there are no semantic changes.
Yeah, it could be used. My thinking is that |
Indeed. I was looking for
That sounds good.
Agreed. |
hebasto
left a comment
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.
ACK 2f73e52, I have reviewed the code and it looks OK.
Minor refactoring to make the abstraction cleaner