sm2/sm9: eliminate bounds checks in the loop of Select

This commit is contained in:
Sun Yimin 2023-06-21 11:52:32 +08:00 committed by GitHub
parent 2da0a9cebc
commit 9bcbf9bae9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 13 deletions

View File

@ -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)
}
}

View File

@ -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)
}
}

View File

@ -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)
}

View File

@ -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)
}
}

View File

@ -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)
}
}