Skip to content

Commit

Permalink
Eliminate bounds checks in the loop.
Browse files Browse the repository at this point in the history
  • Loading branch information
emmansun authored Jun 21, 2023
1 parent 92957b5 commit 36a3768
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions bn256/curve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions bn256/gt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
6 changes: 3 additions & 3 deletions bn256/twist.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 36a3768

Please sign in to comment.