sm2curve

package
v1.0.3009 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RR = &p256OrdElement{0x901192af7c114f20, 0x3464504ade6fa2fa, 0x620fc84c3affe0d4, 0x1eb5e412a22b3d3b}

This code operates in the Montgomery domain where R = 2²⁵⁶ mod n and n is the order of the scalar field. Elements in the Montgomery domain take the form a×R and p256OrdMul calculates (a × b × R⁻¹) mod n. RR is R in the domain, or R×R mod n, thus p256OrdMul(x, RR) gives x×R, i.e. converts x into the Montgomery domain.

Functions

func ImplicitSig

func ImplicitSig(sPriv, ePriv, t []byte) ([]byte, error)

func Marshal

func Marshal(curve elliptic.Curve, x, y *big.Int) []byte

Marshal converts a point on the curve into the uncompressed

func MarshalCompressed

func MarshalCompressed(curve elliptic.Curve, x, y *big.Int) []byte

MarshalCompressed converts a point on the curve into the compressed form specified in SEC 1, Version 2.0, Section 2.3.3. If the point is not on the curve (or is the conventional point at infinity), the behavior is undefined.

func P256

func P256() elliptic.Curve

func P256OrdInverse

func P256OrdInverse(k []byte) ([]byte, error)

P256OrdInverse, sets out to in⁻¹ mod org(G). If in is zero, out will be zero. n-2 = 1111111111111111111111111111111011111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111111111111 0111001000000011110111110110101100100001110001100000010100101011 0101001110111011111101000000100100111001110101010100000100100001

func P256OrdMul

func P256OrdMul(in1, in2 []byte) ([]byte, error)

P256OrdMul multiplication modulo org(G).

func Unmarshal

func Unmarshal(curve elliptic.Curve, data []byte) (x, y *big.Int)

Unmarshal converts a point, serialized by Marshal, into an x, y pair. It is an error if the point is not in uncompressed form, is not on the curve, or is the point at infinity. On error, x = nil.

func UnmarshalCompressed

func UnmarshalCompressed(curve elliptic.Curve, data []byte) (x, y *big.Int)

UnmarshalCompressed converts a point, serialized by MarshalCompressed, into an x, y pair. It is an error if the point is not in compressed form, is not on the curve, or is the point at infinity. On error, x = nil.

Types

type Point

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

P256Point is a P-256 point. The zero value should not be assumed to be valid (although it is in this implementation).

func NewPoint

func NewPoint() *Point

NewPoint returns a new Point representing the point at infinity.

func (*Point) Add

func (q *Point) Add(r1, r2 *Point) *Point

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

func (*Point) Bytes

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

Bytes returns the uncompressed or infinity encoding of p, as specified in SEC 1, Version 2.0, Section 2.3.3. Note that the encoding of the point at infinity is shorter than all other encodings.

func (*Point) BytesCompressed

func (p *Point) BytesCompressed() []byte

BytesCompressed returns the compressed or infinity encoding of p, as specified in SEC 1, Version 2.0, Section 2.3.3. Note that the encoding of the point at infinity is shorter than all other encodings.

func (*Point) BytesX

func (p *Point) BytesX() ([]byte, error)

BytesX returns the encoding of the x-coordinate of p, as specified in SEC 1, Version 2.0, Section 2.3.5, or an error if p is the point at infinity.

func (*Point) Double

func (q *Point) Double(p *Point) *Point

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

func (*Point) ScalarBaseMult

func (r *Point) ScalarBaseMult(scalar []byte) (*Point, error)

ScalarBaseMult sets r = scalar * generator, where scalar is a 32-byte big endian value, and returns r. If scalar is not 32 bytes long, ScalarBaseMult returns an error and the receiver is unchanged.

func (*Point) ScalarMult

func (r *Point) ScalarMult(q *Point, scalar []byte) (*Point, error)

ScalarMult sets r = scalar * q, where scalar is a 32-byte big endian value, and returns r. If scalar is not 32 bytes long, ScalarBaseMult returns an error and the receiver is unchanged.

func (*Point) Select

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

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

func (*Point) Set

func (p *Point) Set(q *Point) *Point

Set sets p = q and returns p.

func (*Point) SetBytes

func (p *Point) SetBytes(b []byte) (*Point, 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.

func (*Point) SetGenerator

func (p *Point) SetGenerator() *Point

SetGenerator sets p to the canonical generator and returns p.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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