internal/radix51: define a mask64Bits constant

This commit is contained in:
Filippo Valsorda 2019-01-28 09:54:14 -05:00 committed by George Tankersley
parent 032d7f64e8
commit 6b0cdf071a
1 changed files with 3 additions and 1 deletions

View File

@ -359,10 +359,12 @@ func (v *FieldElement) Equal(u *FieldElement) int {
return subtle.ConstantTimeCompare(sa[:], sv[:])
}
const mask64Bits uint64 = (1 << 64) - 1
// Select sets v to a if cond == 1, and to b if cond == 0.
// v, a and b are allowed to overlap.
func (v *FieldElement) Select(a, b *FieldElement, cond int) *FieldElement {
m := uint64(cond) * 0xffffffffffffffff
m := uint64(cond) * mask64Bits
v[0] = (m & a[0]) | (^m & b[0])
v[1] = (m & a[1]) | (^m & b[1])
v[2] = (m & a[2]) | (^m & b[2])