diff --git a/bn256/curve.go b/bn256/curve.go index c16aef8..46382b4 100644 --- a/bn256/curve.go +++ b/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/bn256/gt.go b/bn256/gt.go index 94ab190..d187b19 100644 --- a/bn256/gt.go +++ b/bn256/gt.go @@ -216,9 +216,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/bn256/twist.go b/bn256/twist.go index c42eb16..b5cb9f7 100644 --- a/bn256/twist.go +++ b/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) } }