mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 04:36:19 +08:00
sm2/sm9: eliminate bounds checks in the loop of Select
This commit is contained in:
parent
2da0a9cebc
commit
9bcbf9bae9
@ -322,9 +322,9 @@ func (table *sm2p256Table) Select(p *SM2P256Point, n uint8) {
|
|||||||
panic("sm2ec: internal error: sm2p256Table called with out-of-bounds value")
|
panic("sm2ec: internal error: sm2p256Table called with out-of-bounds value")
|
||||||
}
|
}
|
||||||
p.Set(NewSM2P256Point())
|
p.Set(NewSM2P256Point())
|
||||||
for i := uint8(1); i < 16; i++ {
|
for i, f := range table {
|
||||||
cond := subtle.ConstantTimeByteEq(i, n)
|
cond := subtle.ConstantTimeByteEq(uint8(i+1), n)
|
||||||
p.Select(table[i-1], p, cond)
|
p.Select(f, p, cond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,8 +270,8 @@ func (table *curvePointTable) Select(p *curvePoint, n uint8) {
|
|||||||
panic("sm9: internal error: curvePointTable called with out-of-bounds value")
|
panic("sm9: internal error: curvePointTable called with out-of-bounds value")
|
||||||
}
|
}
|
||||||
p.SetInfinity()
|
p.SetInfinity()
|
||||||
for i := uint8(1); i < 16; i++ {
|
for i, f := range table {
|
||||||
cond := subtle.ConstantTimeByteEq(i, n)
|
cond := subtle.ConstantTimeByteEq(uint8(i+1), n)
|
||||||
p.Select(table[i-1], p, cond)
|
p.Select(f, p, cond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ func gfpNeg(c, a *gfP) {
|
|||||||
for i, pi := range p2 {
|
for i, pi := range p2 {
|
||||||
c[i], carry = bits.Sub64(pi, a[i], carry)
|
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)
|
gfpCarry(c, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,9 +211,9 @@ func (table *GTFieldTable) Select(p *GT, n uint8) {
|
|||||||
panic("sm9: internal error: GTFieldTable called with out-of-bounds value")
|
panic("sm9: internal error: GTFieldTable called with out-of-bounds value")
|
||||||
}
|
}
|
||||||
p.p.SetOne()
|
p.p.SetOne()
|
||||||
for i := uint8(1); i < 16; i++ {
|
for i, f := range table {
|
||||||
cond := subtle.ConstantTimeByteEq(i, n)
|
cond := subtle.ConstantTimeByteEq(uint8(i+1), n)
|
||||||
p.p.Select(table[i-1].p, p.p, cond)
|
p.p.Select(f.p, p.p, cond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,9 +262,9 @@ func (table *twistPointTable) Select(p *twistPoint, n uint8) {
|
|||||||
panic("sm9: internal error: twistPointTable called with out-of-bounds value")
|
panic("sm9: internal error: twistPointTable called with out-of-bounds value")
|
||||||
}
|
}
|
||||||
p.SetInfinity()
|
p.SetInfinity()
|
||||||
for i := uint8(1); i < 16; i++ {
|
for i, f := range table {
|
||||||
cond := subtle.ConstantTimeByteEq(i, n)
|
cond := subtle.ConstantTimeByteEq(uint8(i+1), n)
|
||||||
p.Select(table[i-1], p, cond)
|
p.Select(f, p, cond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user