Documentation
¶
Index ¶
- Constants
- type SM2Element
- func (e *SM2Element) Add(t1, t2 *SM2Element) *SM2Element
- func (e *SM2Element) Bytes() []byte
- func (e *SM2Element) Equal(t *SM2Element) int
- func (e *SM2Element) GetRaw() *[4]uint64
- func (z *SM2Element) Invert(x *SM2Element) *SM2Element
- func (e *SM2Element) IsZero() int
- func (e *SM2Element) Mul(t1, t2 *SM2Element) *SM2Element
- func (v *SM2Element) MultiSelect(precomputed *[]*[4]uint64, width int, bits byte, fallback *SM2Element, ...)
- func (e *SM2Element) One() *SM2Element
- func (e *SM2Element) Opp(t *SM2Element) *SM2Element
- func (v *SM2Element) Select(a, b *SM2Element, cond int) *SM2Element
- func (e *SM2Element) Set(t *SM2Element) *SM2Element
- func (e *SM2Element) SetBytes(v []byte) (*SM2Element, error)
- func (e *SM2Element) SetRaw(raw [4]uint64) *SM2Element
- func (e *SM2Element) Square(t *SM2Element) *SM2Element
- func (e *SM2Element) Sub(t1, t2 *SM2Element) *SM2Element
- func (e *SM2Element) ToBigInt() *big.Int
- type SM2ScalarElement
- func (e *SM2ScalarElement) Add(t1, t2 *SM2ScalarElement) *SM2ScalarElement
- func (e *SM2ScalarElement) Bytes() []byte
- func (e *SM2ScalarElement) Equal(t *SM2ScalarElement) int
- func (z *SM2ScalarElement) Invert(x *SM2ScalarElement) *SM2ScalarElement
- func (e *SM2ScalarElement) IsZero() int
- func (e *SM2ScalarElement) Mul(t1, t2 *SM2ScalarElement) *SM2ScalarElement
- func (e *SM2ScalarElement) One() *SM2ScalarElement
- func (v *SM2ScalarElement) Select(a, b *SM2ScalarElement, cond int) *SM2ScalarElement
- func (e *SM2ScalarElement) Set(t *SM2ScalarElement) *SM2ScalarElement
- func (e *SM2ScalarElement) SetBytes(v []byte) (*SM2ScalarElement, error)
- func (e *SM2ScalarElement) Square(t *SM2ScalarElement) *SM2ScalarElement
- func (e *SM2ScalarElement) Sub(t1, t2 *SM2ScalarElement) *SM2ScalarElement
- func (e *SM2ScalarElement) ToBigInt() *big.Int
Constants ¶
const ITERATIONS = ((49 * LEN_PRIME) + 57) / 17
const LEN_PRIME = 256
const LIMBS = 4
const SAT_LIMBS = LIMBS + 1 /* we might need 2 more bits to represent m in twos complement */
const SM2ElementLen = 32
const SM2ScalarElementLen = 32
const WORD_SIZE = 64
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type SM2Element ¶
type SM2Element struct {
// contains filtered or unexported fields
}
SM2Element is an integer modulo 2^256 - 2^224 - 2^96 + 2^64 - 1.
The zero value is a valid zero element.
func (*SM2Element) Add ¶
func (e *SM2Element) Add(t1, t2 *SM2Element) *SM2Element
Add sets e = t1 + t2, and returns e.
func (*SM2Element) Bytes ¶
func (e *SM2Element) Bytes() []byte
Bytes returns the 32-byte big-endian encoding of e.
func (*SM2Element) Equal ¶
func (e *SM2Element) Equal(t *SM2Element) int
Equal returns 1 if e == t, and zero otherwise.
func (*SM2Element) GetRaw ¶
func (e *SM2Element) GetRaw() *[4]uint64
GetRaw returns reference to internal state so that data could be manipulated. Use with caution as this violates encapsulation.
func (*SM2Element) Invert ¶
func (z *SM2Element) Invert(x *SM2Element) *SM2Element
func (*SM2Element) IsZero ¶
func (e *SM2Element) IsZero() int
IsZero returns 1 if e == 0, and zero otherwise.
func (*SM2Element) Mul ¶
func (e *SM2Element) Mul(t1, t2 *SM2Element) *SM2Element
Mul sets e = t1 * t2, and returns e.
func (*SM2Element) MultiSelect ¶
func (v *SM2Element) MultiSelect(precomputed *[]*[4]uint64, width int, bits byte, fallback *SM2Element, fallbackCond int)
func (*SM2Element) Opp ¶
func (e *SM2Element) Opp(t *SM2Element) *SM2Element
func (*SM2Element) Select ¶
func (v *SM2Element) Select(a, b *SM2Element, cond int) *SM2Element
Select sets v to a if cond == 1, and to b if cond == 0.
func (*SM2Element) Set ¶
func (e *SM2Element) Set(t *SM2Element) *SM2Element
Set sets e = t, and returns e.
func (*SM2Element) SetBytes ¶
func (e *SM2Element) SetBytes(v []byte) (*SM2Element, error)
SetBytes sets e = v, where v is a big-endian 32-byte encoding, and returns e. If v is not 32 bytes or it encodes a value higher than 2^256 - 2^224 - 2^96 + 2^64 - 1, SetBytes returns nil and an error, and e is unchanged.
func (*SM2Element) SetRaw ¶
func (e *SM2Element) SetRaw(raw [4]uint64) *SM2Element
SetRaw copies data from raw array into element internal data structure directly, bypassing any potential conversion and sanity checks
func (*SM2Element) Square ¶
func (e *SM2Element) Square(t *SM2Element) *SM2Element
Square sets e = t * t, and returns e.
func (*SM2Element) Sub ¶
func (e *SM2Element) Sub(t1, t2 *SM2Element) *SM2Element
Sub sets e = t1 - t2, and returns e.
func (*SM2Element) ToBigInt ¶
func (e *SM2Element) ToBigInt() *big.Int
type SM2ScalarElement ¶
type SM2ScalarElement struct {
// contains filtered or unexported fields
}
SM2ScalarElement is an integer modulo n (0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123).
The zero value is a valid zero element.
func (*SM2ScalarElement) Add ¶
func (e *SM2ScalarElement) Add(t1, t2 *SM2ScalarElement) *SM2ScalarElement
Add sets e = t1 + t2, and returns e.
func (*SM2ScalarElement) Bytes ¶
func (e *SM2ScalarElement) Bytes() []byte
Bytes returns the 32-byte big-endian encoding of e.
func (*SM2ScalarElement) Equal ¶
func (e *SM2ScalarElement) Equal(t *SM2ScalarElement) int
Equal returns 1 if e == t, and zero otherwise.
func (*SM2ScalarElement) Invert ¶
func (z *SM2ScalarElement) Invert(x *SM2ScalarElement) *SM2ScalarElement
func (*SM2ScalarElement) IsZero ¶
func (e *SM2ScalarElement) IsZero() int
IsZero returns 1 if e == 0, and zero otherwise.
func (*SM2ScalarElement) Mul ¶
func (e *SM2ScalarElement) Mul(t1, t2 *SM2ScalarElement) *SM2ScalarElement
Mul sets e = t1 * t2, and returns e.
func (*SM2ScalarElement) One ¶
func (e *SM2ScalarElement) One() *SM2ScalarElement
One sets e = 1, and returns e.
func (*SM2ScalarElement) Select ¶
func (v *SM2ScalarElement) Select(a, b *SM2ScalarElement, cond int) *SM2ScalarElement
Select sets v to a if cond == 1, and to b if cond == 0.
func (*SM2ScalarElement) Set ¶
func (e *SM2ScalarElement) Set(t *SM2ScalarElement) *SM2ScalarElement
Set sets e = t, and returns e.
func (*SM2ScalarElement) SetBytes ¶
func (e *SM2ScalarElement) SetBytes(v []byte) (*SM2ScalarElement, error)
SetBytes sets e = v, where v is a big-endian 32-byte encoding, and returns e. If v is not 32 bytes or it encodes a value higher than n (0xFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123), SetBytes returns nil and an error, and e is unchanged.
func (*SM2ScalarElement) Square ¶
func (e *SM2ScalarElement) Square(t *SM2ScalarElement) *SM2ScalarElement
Square sets e = t * t, and returns e.
func (*SM2ScalarElement) Sub ¶
func (e *SM2ScalarElement) Sub(t1, t2 *SM2ScalarElement) *SM2ScalarElement
Sub sets e = t1 - t2, and returns e.
func (*SM2ScalarElement) ToBigInt ¶
func (e *SM2ScalarElement) ToBigInt() *big.Int