Skip to content

Commit f26b565

Browse files
authored
crypto/bn256: add documentation on subgroup checks for G2 (#32066)
This PR improves the IsOnCurve methods for BN254 G2 points by: * Clarifying its behavior the docstring, making it explicit that it verifies both the point being on the curve and in the correct subgroup. * Adding an in-line comment explaining the subgroup membership check (c.Mul(Order)). * Minor wording adjustments for readability and consistency.
1 parent 6723388 commit f26b565

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

crypto/bn256/cloudflare/twist.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (c *twistPoint) Set(a *twistPoint) {
4343
c.t.Set(&a.t)
4444
}
4545

46-
// IsOnCurve returns true iff c is on the curve.
46+
// IsOnCurve returns true iff c is on the curve and is in the correct subgroup.
4747
func (c *twistPoint) IsOnCurve() bool {
4848
c.MakeAffine()
4949
if c.IsInfinity() {
@@ -57,6 +57,8 @@ func (c *twistPoint) IsOnCurve() bool {
5757
if *y2 != *x3 {
5858
return false
5959
}
60+
// Subgroup check: multiply the point by the group order and
61+
// verify that it becomes the point at infinity.
6062
cneg := &twistPoint{}
6163
cneg.Mul(c, Order)
6264
return cneg.z.IsZero()

crypto/bn256/google/twist.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (c *twistPoint) Set(a *twistPoint) {
6767
c.t.Set(a.t)
6868
}
6969

70-
// IsOnCurve returns true iff c is on the curve where c must be in affine form.
70+
// IsOnCurve returns true iff c is on the curve and is in the correct subgroup, where c must be in affine form.
7171
func (c *twistPoint) IsOnCurve() bool {
7272
pool := new(bnPool)
7373
yy := newGFp2(pool).Square(c.y, pool)
@@ -80,6 +80,8 @@ func (c *twistPoint) IsOnCurve() bool {
8080
if yy.x.Sign() != 0 || yy.y.Sign() != 0 {
8181
return false
8282
}
83+
// Subgroup check: multiply the point by the group order and
84+
// verify that it becomes the point at infinity.
8385
cneg := newTwistPoint(pool)
8486
cneg.Mul(c, Order, pool)
8587
return cneg.z.IsZero()

0 commit comments

Comments
 (0)