internal

package
v0.0.0-...-02f8a93 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2023 License: BSD-3-Clause, MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SM2BytesLengthUncompressed = 1 + 2*SM2ElementLength
View Source
const SM2ElementLength = 32

Variables

This section is empty.

Functions

func GetN

func GetN() *big.Int

func GetZBytes

func GetZBytes() []byte

func Sm2CheckOnCurve

func Sm2CheckOnCurve(x, y *fiat.SM2Element) error

func TransformPrecomputed

func TransformPrecomputed(precomputed *[]*SM2Point, width int) [][]*[4]uint64

Types

type SM2Point

type SM2Point struct {
	// contains filtered or unexported fields
}

SM2Point is a SM2 point. The zero value is NOT valid.

func NewFromXY

func NewFromXY(xx, yy *[4]uint64) *SM2Point

func NewSM2Generator

func NewSM2Generator() *SM2Point

NewSM2Generator returns a new SM2Point set to the canonical generator.

func NewSM2Point

func NewSM2Point() *SM2Point

NewSM2Point returns a new SM2Point representing the point at infinity point.

func ScalarBaseMult

func ScalarBaseMult(k []byte) (*SM2Point, error)

ScalarBaseMult scalar base multiplication, return [k]G when no error k is big endian and its integer value should lie in range of [1, n-1] ***secure implementation***, this could be used for sign or key generation, all sensitive operations

func ScalarMixedMult_Unsafe

func ScalarMixedMult_Unsafe(gScalar []byte, P *SM2Point, scalar []byte) (*SM2Point, error)

ScalarMixedMult_Unsafe mixed scalar multiplication, returns [gScalar]G + [scalar]P when no error gScalar and scalar are big endian and their integer values should lie in range of [1, n-1] usually used for signature verification and not sensitive This is an internal function. Do NOT use it out of this library. Use sm2.* functions instead.

func ScalarMult

func ScalarMult(P *SM2Point, scalar []byte) (*SM2Point, error)

ScalarMult Scalar multiplication, returns [scalar]P when no error. scalar is big endian and its integer value should lie in range of [1, n-1] ***secure implementation***, this could be used for ECDH with unsigned 4-NAF

func (*SM2Point) Add

func (q *SM2Point) Add(p1, p2 *SM2Point) *SM2Point

Add sets q = p1 + p2, and returns q. The points may overlap.

func (*SM2Point) Bytes

func (p *SM2Point) Bytes() []byte

Bytes returns the uncompressed or infinity encoding of p. Note that the encoding of the point at infinity is shorter than all other encodings. This is the SAFE version, could be used for ECDH purpose for example.

func (*SM2Point) Bytes_Unsafe

func (p *SM2Point) Bytes_Unsafe() []byte

Bytes_Unsafe returns the uncompressed or infinity encoding of p. Note that the encoding of the point at infinity is shorter than all other encodings. This is the unsafe version.

func (*SM2Point) Double

func (q *SM2Point) Double(p *SM2Point) *SM2Point

Double sets q = p + p, and returns q. The points may overlap.

func (*SM2Point) GetAffineX

func (p *SM2Point) GetAffineX() *big.Int

GetAffineX return X in Affine as big integer. It saves some costs by avoiding the calculation of Y. This is a safe version for the case that the affine coordinates must be extracted safely. Returns big integer. If returned is 0, callers, if in such needs, MUST determine if this is due to a zero point, or a valid point (0, some_y). Usually if the point results from scalar multiplication with scalar in range [1, n-1], the latter will not happen.

func (*SM2Point) GetAffineX_Unsafe

func (p *SM2Point) GetAffineX_Unsafe() *big.Int

GetAffineX_Unsafe functions the same as GetAffineX. It uses a faster yet non-constant time algorithm to calculate the inverse of z.

func (*SM2Point) MultiSelectXY

func (q *SM2Point) MultiSelectXY(precomputed *[][]*[4]uint64, width int, bits byte) *SM2Point

MultiSelectXY select from multiple options based on the bits. We should be able to cut roughly half of selection cost compared to if we select the point one-by-one in a loop.

func (*SM2Point) MultiSelectXYZ

func (q *SM2Point) MultiSelectXYZ(precomputed *[][]*[4]uint64, width int, bits byte) *SM2Point

MultiSelectXYZ select from multiple options based on the bits. We should be able to cut roughly half of selection cost compared to if we select the point one-by-one in a loop.

func (*SM2Point) Negate

func (q *SM2Point) Negate(p *SM2Point) *SM2Point

func (*SM2Point) Select

func (q *SM2Point) Select(p1, p2 *SM2Point, cond int) *SM2Point

Select sets q to p1 if cond == 1, and to p2 if cond == 0.

func (*SM2Point) Set

func (p *SM2Point) Set(q *SM2Point) *SM2Point

Set sets p = q and returns p.

func (*SM2Point) SetBytes

func (p *SM2Point) SetBytes(b []byte) (*SM2Point, error)

SetBytes sets p to the compressed, uncompressed, or infinity value encoded in b, as specified in SEC 1, Version 2.0, Section 2.3.4. If the point is not on the curve, it returns nil and an error, and the receiver is unchanged. Otherwise, it returns p.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL