sm2c

package
v0.0.0-...-4631c66 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sm2c implements the SM2 Prime elliptic curves.

This package uses fiat-crypto or specialized assembly and Go code for its backend field arithmetic (not math/big) and exposes constant-time, heap allocation-free, byte slice-based safe APIs. Group operations use modern and safe complete addition formulas where possible. The point at infinity is handled and encoded according to SEC 1, Version 2.0, and invalid curve points can't be represented.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

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 SM2P256

func SM2P256() elliptic.Curve

Types

type P256Point

type P256Point 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 NewP256Point

func NewP256Point() *P256Point

NewP256Point returns a new P256Point representing the point at infinity.

func (*P256Point) Add

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

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

func (*P256Point) Bytes

func (p *P256Point) 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 (*P256Point) BytesCompressed

func (p *P256Point) 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 (*P256Point) Double

func (q *P256Point) Double(p *P256Point) *P256Point

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

func (*P256Point) ScalarBaseMult

func (r *P256Point) ScalarBaseMult(scalar []byte) (*P256Point, 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 (*P256Point) ScalarMult

func (r *P256Point) ScalarMult(q *P256Point, scalar []byte) (*P256Point, 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 (*P256Point) Select

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

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

func (*P256Point) Set

func (p *P256Point) Set(q *P256Point) *P256Point

Set sets p = q and returns p.

func (*P256Point) SetBytes

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

func (p *P256Point) SetGenerator() *P256Point

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