func (f *fieldVal) Equals(val *fieldVal) bool {
	bits := (f.n[0] ^ val.n[0]) | (f.n[1] ^ val.n[1]) | (f.n[2] ^ val.n[2]) |
		(f.n[3] ^ val.n[3]) | (f.n[4] ^ val.n[4]) | (f.n[5] ^ val.n[5]) |
		(f.n[6] ^ val.n[6]) | (f.n[7] ^ val.n[7]) | (f.n[8] ^ val.n[8]) |
		(f.n[9] ^ val.n[9])
	return bits == 0
}
Equals returns whether or not the two field values are the same.  Both
field values being compared must be normalized for this function to return
the correct result.
package btcec
import (
	"encoding/hex"
)
const (
	twoBitsMask   = 0x3
	fourBitsMask  = 0xf
	sixBitsMask   = 0x3f
	eightBitsMask = 0xff
)
const (
	fieldWords = 10
	fieldBase = 26
	fieldOverflowBits = 32 - fieldBase
	fieldBaseMask = (1 << fieldBase) - 1
	fieldMSBBits = 256 - (fieldBase * (fieldWords - 1))
	fieldMSBMask = (1 << fieldMSBBits) - 1
	fieldPrimeWordZero = 0x3fffc2f
	fieldPrimeWordOne = 0x3ffffbf
	primeLowBits = 0xffffefffffc2f
)
type fieldVal struct {
	n [10]uint32
}
func (f fieldVal) String() string {
	t := new(fieldVal).Set(&f).Normalize()
	return hex.EncodeToString(t.Bytes()[:])
}
func (f *fieldVal) Zero() {
	f.n[0] = 0
	f.n[1] = 0
	f.n[2] = 0
	f.n[3] = 0
	f.n[4] = 0
	f.n[5] = 0
	f.n[6] = 0
	f.n[7] = 0
	f.n[8] = 0
	f.n[9] = 0
}
func (f *fieldVal) Set(val *fieldVal) *fieldVal {
	*f = *val
	return f
}
func (f *fieldVal) SetInt(ui uint) *fieldVal {
	f.Zero()
	f.n[0] = uint32(ui)
	return f
}
func (f *fieldVal) SetBytes(b *[32]byte) *fieldVal {
	f.n[0] = uint32(b[31]) | uint32(b[30])<<8 | uint32(b[29])<<16 |
		(uint32(b[28])&twoBitsMask)<<24
	f.n[1] = uint32(b[28])>>2 | uint32(b[27])<<6 | uint32(b[26])<<14 |
		(uint32(b[25])&fourBitsMask)<<22
	f.n[2] = uint32(b[25])>>4 | uint32(b[24])<<4 | uint32(b[23])<<12 |
		(uint32(b[22])&sixBitsMask)<<20
	f.n[3] = uint32(b[22])>>6 | uint32(b[21])<<2 | uint32(b[20])<<10 |
		uint32(b[19])<<18
	f.n[4] = uint32(b[18]) | uint32(b[17])<<8 | uint32(b[16])<<16 |
		(uint32(b[15])&twoBitsMask)<<24
	f.n[5] = uint32(b[15])>>2 | uint32(b[14])<<6 | uint32(b[13])<<14 |
		(uint32(b[12])&fourBitsMask)<<22
	f.n[6] = uint32(b[12])>>4 | uint32(b[11])<<4 | uint32(b[10])<<12 |
		(uint32(b[9])&sixBitsMask)<<20
	f.n[7] = uint32(b[9])>>6 | uint32(b[8])<<2 | uint32(b[7])<<10 |
		uint32(b[6])<<18
	f.n[8] = uint32(b[5]) | uint32(b[4])<<8 | uint32(b[3])<<16 |
		(uint32(b[2])&twoBitsMask)<<24
	f.n[9] = uint32(b[2])>>2 | uint32(b[1])<<6 | uint32(b[0])<<14
	return f
}
func (f *fieldVal) SetByteSlice(b []byte) *fieldVal {
	var b32 [32]byte
	for i := 0; i < len(b); i++ {
		if i < 32 {
			b32[i+(32-len(b))] = b[i]
		}
	}
	return f.SetBytes(&b32)
}
func (f *fieldVal) SetHex(hexString string) *fieldVal {
	if len(hexString)%2 != 0 {
		hexString = "0" + hexString
	}
	bytes, _ := hex.DecodeString(hexString)
	return f.SetByteSlice(bytes)
}
func (f *fieldVal) Normalize() *fieldVal {
	m := f.n[0]
	t0 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[1]
	t1 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[2]
	t2 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[3]
	t3 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[4]
	t4 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[5]
	t5 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[6]
	t6 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[7]
	t7 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[8]
	t8 := m & fieldBaseMask
	m = (m >> fieldBase) + f.n[9]
	t9 := m & fieldMSBMask
	m = m >> fieldMSBBits
	r := t0 + m*977
	t0 = r & fieldBaseMask
	r = (r >> fieldBase) + t1 + m*64
	t1 = r & fieldBaseMask
	r = (r >> fieldBase) + t2
	t2 = r & fieldBaseMask
	r = (r >> fieldBase) + t3
	t3 = r & fieldBaseMask
	r = (r >> fieldBase) + t4
	t4 = r & fieldBaseMask
	r = (r >> fieldBase) + t5
	t5 = r & fieldBaseMask
	r = (r >> fieldBase) + t6
	t6 = r & fieldBaseMask
	r = (r >> fieldBase) + t7
	t7 = r & fieldBaseMask
	r = (r >> fieldBase) + t8
	t8 = r & fieldBaseMask
	r = (r >> fieldBase) + t9
	t9 = r & fieldMSBMask
	var mask int32
	lowBits := uint64(t1)<<fieldBase | uint64(t0)
	if lowBits < primeLowBits {
		mask |= -1
	} else {
		mask |= 0
	}
	if t2 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t3 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t4 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t5 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t6 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t7 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t8 < fieldBaseMask {
		mask |= -1
	} else {
		mask |= 0
	}
	if t9 < fieldMSBMask {
		mask |= -1
	} else {
		mask |= 0
	}
	lowBits -= ^uint64(mask) & primeLowBits
	t0 = uint32(lowBits & fieldBaseMask)
	t1 = uint32((lowBits >> fieldBase) & fieldBaseMask)
	t2 = t2 & uint32(mask)
	t3 = t3 & uint32(mask)
	t4 = t4 & uint32(mask)
	t5 = t5 & uint32(mask)
	t6 = t6 & uint32(mask)
	t7 = t7 & uint32(mask)
	t8 = t8 & uint32(mask)
	t9 = t9 & uint32(mask)
	f.n[0] = t0
	f.n[1] = t1
	f.n[2] = t2
	f.n[3] = t3
	f.n[4] = t4
	f.n[5] = t5
	f.n[6] = t6
	f.n[7] = t7
	f.n[8] = t8
	f.n[9] = t9
	return f
}
func (f *fieldVal) PutBytes(b *[32]byte) {
	b[31] = byte(f.n[0] & eightBitsMask)
	b[30] = byte((f.n[0] >> 8) & eightBitsMask)
	b[29] = byte((f.n[0] >> 16) & eightBitsMask)
	b[28] = byte((f.n[0]>>24)&twoBitsMask | (f.n[1]&sixBitsMask)<<2)
	b[27] = byte((f.n[1] >> 6) & eightBitsMask)
	b[26] = byte((f.n[1] >> 14) & eightBitsMask)
	b[25] = byte((f.n[1]>>22)&fourBitsMask | (f.n[2]&fourBitsMask)<<4)
	b[24] = byte((f.n[2] >> 4) & eightBitsMask)
	b[23] = byte((f.n[2] >> 12) & eightBitsMask)
	b[22] = byte((f.n[2]>>20)&sixBitsMask | (f.n[3]&twoBitsMask)<<6)
	b[21] = byte((f.n[3] >> 2) & eightBitsMask)
	b[20] = byte((f.n[3] >> 10) & eightBitsMask)
	b[19] = byte((f.n[3] >> 18) & eightBitsMask)
	b[18] = byte(f.n[4] & eightBitsMask)
	b[17] = byte((f.n[4] >> 8) & eightBitsMask)
	b[16] = byte((f.n[4] >> 16) & eightBitsMask)
	b[15] = byte((f.n[4]>>24)&twoBitsMask | (f.n[5]&sixBitsMask)<<2)
	b[14] = byte((f.n[5] >> 6) & eightBitsMask)
	b[13] = byte((f.n[5] >> 14) & eightBitsMask)
	b[12] = byte((f.n[5]>>22)&fourBitsMask | (f.n[6]&fourBitsMask)<<4)
	b[11] = byte((f.n[6] >> 4) & eightBitsMask)
	b[10] = byte((f.n[6] >> 12) & eightBitsMask)
	b[9] = byte((f.n[6]>>20)&sixBitsMask | (f.n[7]&twoBitsMask)<<6)
	b[8] = byte((f.n[7] >> 2) & eightBitsMask)
	b[7] = byte((f.n[7] >> 10) & eightBitsMask)
	b[6] = byte((f.n[7] >> 18) & eightBitsMask)
	b[5] = byte(f.n[8] & eightBitsMask)
	b[4] = byte((f.n[8] >> 8) & eightBitsMask)
	b[3] = byte((f.n[8] >> 16) & eightBitsMask)
	b[2] = byte((f.n[8]>>24)&twoBitsMask | (f.n[9]&sixBitsMask)<<2)
	b[1] = byte((f.n[9] >> 6) & eightBitsMask)
	b[0] = byte((f.n[9] >> 14) & eightBitsMask)
}
func (f *fieldVal) Bytes() *[32]byte {
	b := new([32]byte)
	f.PutBytes(b)
	return b
}
func (f *fieldVal) IsZero() bool {
	bits := f.n[0] | f.n[1] | f.n[2] | f.n[3] | f.n[4] |
		f.n[5] | f.n[6] | f.n[7] | f.n[8] | f.n[9]
	return bits == 0
}
func (f *fieldVal) IsOdd() bool {
	return f.n[0]&1 == 1
}