mirror of
https://github.com/emmansun/gmsm.git
synced 2025-04-27 04:36:19 +08:00
internal/bigmod: disable race detector on tight loops #285
This commit is contained in:
parent
14087e2665
commit
fcd1aa22d2
@ -247,6 +247,8 @@ func (x *Nat) SetUint(y uint, m *Modulus) *Nat {
|
|||||||
// Equal returns 1 if x == y, and 0 otherwise.
|
// Equal returns 1 if x == y, and 0 otherwise.
|
||||||
//
|
//
|
||||||
// Both operands must have the same announced length.
|
// Both operands must have the same announced length.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) Equal(y *Nat) choice {
|
func (x *Nat) Equal(y *Nat) choice {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -261,6 +263,8 @@ func (x *Nat) Equal(y *Nat) choice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsZero returns 1 if x == 0, and 0 otherwise.
|
// IsZero returns 1 if x == 0, and 0 otherwise.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) IsZero() choice {
|
func (x *Nat) IsZero() choice {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -274,6 +278,8 @@ func (x *Nat) IsZero() choice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsOne returns 1 if x == 1, and 0 otherwise.
|
// IsOne returns 1 if x == 1, and 0 otherwise.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) IsOne() choice {
|
func (x *Nat) IsOne() choice {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -294,6 +300,8 @@ func (x *Nat) IsOne() choice {
|
|||||||
//
|
//
|
||||||
// The length of x must be the same as the modulus. x must already be reduced
|
// The length of x must be the same as the modulus. x must already be reduced
|
||||||
// modulo m.
|
// modulo m.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) IsMinusOne(m *Modulus) choice {
|
func (x *Nat) IsMinusOne(m *Modulus) choice {
|
||||||
minusOne := m.Nat()
|
minusOne := m.Nat()
|
||||||
minusOne.SubOne(m)
|
minusOne.SubOne(m)
|
||||||
@ -301,6 +309,8 @@ func (x *Nat) IsMinusOne(m *Modulus) choice {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsOdd returns 1 if x is odd, and 0 otherwise.
|
// IsOdd returns 1 if x is odd, and 0 otherwise.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) IsOdd() choice {
|
func (x *Nat) IsOdd() choice {
|
||||||
if len(x.limbs) == 0 {
|
if len(x.limbs) == 0 {
|
||||||
return no
|
return no
|
||||||
@ -326,6 +336,8 @@ func (x *Nat) TrailingZeroBitsVarTime() uint {
|
|||||||
// CmpGeq returns 1 if x >= y, and 0 otherwise.
|
// CmpGeq returns 1 if x >= y, and 0 otherwise.
|
||||||
//
|
//
|
||||||
// Both operands must have the same announced length.
|
// Both operands must have the same announced length.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) CmpGeq(y *Nat) choice {
|
func (x *Nat) CmpGeq(y *Nat) choice {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -344,6 +356,8 @@ func (x *Nat) CmpGeq(y *Nat) choice {
|
|||||||
// assign sets x <- y if on == 1, and does nothing otherwise.
|
// assign sets x <- y if on == 1, and does nothing otherwise.
|
||||||
//
|
//
|
||||||
// Both operands must have the same announced length.
|
// Both operands must have the same announced length.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) assign(on choice, y *Nat) *Nat {
|
func (x *Nat) assign(on choice, y *Nat) *Nat {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -360,6 +374,8 @@ func (x *Nat) assign(on choice, y *Nat) *Nat {
|
|||||||
// add computes x += y and returns the carry.
|
// add computes x += y and returns the carry.
|
||||||
//
|
//
|
||||||
// Both operands must have the same announced length.
|
// Both operands must have the same announced length.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) add(y *Nat) (c uint) {
|
func (x *Nat) add(y *Nat) (c uint) {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -375,6 +391,8 @@ func (x *Nat) add(y *Nat) (c uint) {
|
|||||||
// sub computes x -= y. It returns the borrow of the subtraction.
|
// sub computes x -= y. It returns the borrow of the subtraction.
|
||||||
//
|
//
|
||||||
// Both operands must have the same announced length.
|
// Both operands must have the same announced length.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) sub(y *Nat) (c uint) {
|
func (x *Nat) sub(y *Nat) (c uint) {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -390,6 +408,8 @@ func (x *Nat) sub(y *Nat) (c uint) {
|
|||||||
// ShiftRightVarTime sets x = x >> n.
|
// ShiftRightVarTime sets x = x >> n.
|
||||||
//
|
//
|
||||||
// The announced length of x is unchanged.
|
// The announced length of x is unchanged.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) ShiftRightVarTime(n uint) *Nat {
|
func (x *Nat) ShiftRightVarTime(n uint) *Nat {
|
||||||
// Eliminate bounds checks in the loop.
|
// Eliminate bounds checks in the loop.
|
||||||
size := len(x.limbs)
|
size := len(x.limbs)
|
||||||
@ -596,6 +616,8 @@ func (x *Nat) shiftIn(y uint, m *Modulus) *Nat {
|
|||||||
// shiftIn calculates x = x << _W + y mod m.
|
// shiftIn calculates x = x << _W + y mod m.
|
||||||
//
|
//
|
||||||
// This assumes that x is already reduced mod m, and that y < 2^_W.
|
// This assumes that x is already reduced mod m, and that y < 2^_W.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func (x *Nat) shiftInNat(y uint, m *Nat) *Nat {
|
func (x *Nat) shiftInNat(y uint, m *Nat) *Nat {
|
||||||
d := NewNat().reset(len(m.limbs))
|
d := NewNat().reset(len(m.limbs))
|
||||||
|
|
||||||
@ -902,6 +924,8 @@ func (x *Nat) montgomeryMul(a *Nat, b *Nat, m *Modulus) *Nat {
|
|||||||
// addMulVVW multiplies the multi-word value x by the single-word value y,
|
// addMulVVW multiplies the multi-word value x by the single-word value y,
|
||||||
// adding the result to the multi-word value z and returning the final carry.
|
// adding the result to the multi-word value z and returning the final carry.
|
||||||
// It can be thought of as one row of a pen-and-paper column multiplication.
|
// It can be thought of as one row of a pen-and-paper column multiplication.
|
||||||
|
//
|
||||||
|
//go:norace
|
||||||
func addMulVVW(z, x []uint, y uint) (carry uint) {
|
func addMulVVW(z, x []uint, y uint) (carry uint) {
|
||||||
_ = x[len(z)-1] // bounds check elimination hint
|
_ = x[len(z)-1] // bounds check elimination hint
|
||||||
for i := range z {
|
for i := range z {
|
||||||
@ -1170,6 +1194,7 @@ func (x *Nat) InverseVarTime(a *Nat, m *Modulus) (*Nat, bool) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:norace
|
||||||
func rshift1(a *Nat, carry uint) {
|
func rshift1(a *Nat, carry uint) {
|
||||||
size := len(a.limbs)
|
size := len(a.limbs)
|
||||||
aLimbs := a.limbs[:size]
|
aLimbs := a.limbs[:size]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user