diff --git a/internal/sm2ec/sm2p256.go b/internal/sm2ec/sm2p256.go index 122e207..cbd5638 100644 --- a/internal/sm2ec/sm2p256.go +++ b/internal/sm2ec/sm2p256.go @@ -322,9 +322,9 @@ func (table *sm2p256Table) Select(p *SM2P256Point, n uint8) { panic("sm2ec: internal error: sm2p256Table called with out-of-bounds value") } p.Set(NewSM2P256Point()) - for i := uint8(1); i < 16; i++ { - cond := subtle.ConstantTimeByteEq(i, n) - p.Select(table[i-1], p, cond) + for i, f := range table { + cond := subtle.ConstantTimeByteEq(uint8(i+1), n) + p.Select(f, p, cond) } } diff --git a/sm9/bn256/curve.go b/sm9/bn256/curve.go index c16aef8..46382b4 100644 --- a/sm9/bn256/curve.go +++ b/sm9/bn256/curve.go @@ -270,8 +270,8 @@ func (table *curvePointTable) Select(p *curvePoint, n uint8) { panic("sm9: internal error: curvePointTable called with out-of-bounds value") } p.SetInfinity() - for i := uint8(1); i < 16; i++ { - cond := subtle.ConstantTimeByteEq(i, n) - p.Select(table[i-1], p, cond) + for i, f := range table { + cond := subtle.ConstantTimeByteEq(uint8(i+1), n) + p.Select(f, p, cond) } } diff --git a/sm9/bn256/gfp_generic.go b/sm9/bn256/gfp_generic.go index 58505da..e8b7451 100644 --- a/sm9/bn256/gfp_generic.go +++ b/sm9/bn256/gfp_generic.go @@ -30,7 +30,7 @@ func gfpNeg(c, a *gfP) { for i, pi := range p2 { c[i], carry = bits.Sub64(pi, a[i], carry) } - // required for "zero", bn256 treat infinity point as valid + // required for "zero", bn256 treats infinity point as valid gfpCarry(c, 0) } diff --git a/sm9/bn256/gt.go b/sm9/bn256/gt.go index 004acbe..bf46060 100644 --- a/sm9/bn256/gt.go +++ b/sm9/bn256/gt.go @@ -211,9 +211,9 @@ func (table *GTFieldTable) Select(p *GT, n uint8) { panic("sm9: internal error: GTFieldTable called with out-of-bounds value") } p.p.SetOne() - for i := uint8(1); i < 16; i++ { - cond := subtle.ConstantTimeByteEq(i, n) - p.p.Select(table[i-1].p, p.p, cond) + for i, f := range table { + cond := subtle.ConstantTimeByteEq(uint8(i+1), n) + p.p.Select(f.p, p.p, cond) } } diff --git a/sm9/bn256/twist.go b/sm9/bn256/twist.go index c42eb16..b5cb9f7 100644 --- a/sm9/bn256/twist.go +++ b/sm9/bn256/twist.go @@ -262,9 +262,9 @@ func (table *twistPointTable) Select(p *twistPoint, n uint8) { panic("sm9: internal error: twistPointTable called with out-of-bounds value") } p.SetInfinity() - for i := uint8(1); i < 16; i++ { - cond := subtle.ConstantTimeByteEq(i, n) - p.Select(table[i-1], p, cond) + for i, f := range table { + cond := subtle.ConstantTimeByteEq(uint8(i+1), n) + p.Select(f, p, cond) } }