p256

package
v0.0.0-...-7685c8a Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

README

p256

This package implements the NIST P-256 curve, field, scalar, and point types.

Documentation

Overview

Package p256 implements the NIST P-256 curve, field, scalar, and point types.

See README.md for details.

Index

Constants

View Source
const (
	// CurveName is the curve name.
	CurveName = "P256"
	// Hash2CurveSuite is the hash-to-curve suite string.
	Hash2CurveSuite = "P256_XMD:SHA-256_SSWU_RO_"
	// Hash2CurveScalarSuite is the hash-to-curve scalar suite string.
	Hash2CurveScalarSuite = "P256_XMD:SHA-256_SSWU_RO_SC_"
)
View Source
const (
	// BaseFieldName is the base field name.
	BaseFieldName = "P256Fp"
)
View Source
const (
	// ScalarFieldName is the scalar field name.
	ScalarFieldName = "P256Fq"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseField

BaseField represents the curve base field.

func NewBaseField

func NewBaseField() *BaseField

NewBaseField returns the base field instance.

func (*BaseField) BitLen

func (*BaseField) BitLen() int

BitLen returns the field modulus bit length.

func (*BaseField) Characteristic

func (*BaseField) Characteristic() cardinal.Cardinal

Characteristic returns the field characteristic.

func (*BaseField) ElementSize

func (*BaseField) ElementSize() int

ElementSize returns the element size in bytes.

func (*BaseField) FromBytesBEReduce

func (f *BaseField) FromBytesBEReduce(input []byte) (*BaseFieldElement, error)

FromBytesBEReduce reduces a big-endian integer into the field.

func (*BaseField) Hash

func (*BaseField) Hash(bytes []byte) (*BaseFieldElement, error)

Hash maps input bytes to an element or point.

func (*BaseField) Name

func (*BaseField) Name() string

Name returns the name of the structure.

func (*BaseField) Order

func (*BaseField) Order() cardinal.Cardinal

Order returns the group or field order.

func (*BaseField) WideElementSize

func (*BaseField) WideElementSize() int

WideElementSize returns the wide element size in bytes.

type BaseFieldElement

BaseFieldElement represents an element of the base field.

func (*BaseFieldElement) MarshalBinary

func (fe *BaseFieldElement) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*BaseFieldElement) MarshalCBOR

func (fe *BaseFieldElement) MarshalCBOR() ([]byte, error)

MarshalCBOR implements cbor.Marshaler.

func (*BaseFieldElement) Structure

Structure returns the algebraic structure for the receiver.

func (*BaseFieldElement) UnmarshalBinary

func (fe *BaseFieldElement) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*BaseFieldElement) UnmarshalCBOR

func (fe *BaseFieldElement) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements cbor.Unmarshaler.

type Curve

type Curve struct {
	traits.PrimeCurveTrait[*p256Impl.Fp, *p256Impl.Point, *Point, Point]
}

Curve represents the elliptic curve group.

func NewCurve

func NewCurve() *Curve

NewCurve returns the curve instance.

func (*Curve) BaseField

func (*Curve) BaseField() algebra.FiniteField[*BaseFieldElement]

BaseField returns the base field.

func (*Curve) BaseStructure

func (*Curve) BaseStructure() algebra.Structure[*BaseFieldElement]

BaseStructure returns the base field structure.

func (*Curve) Cofactor

func (*Curve) Cofactor() cardinal.Cardinal

Cofactor returns the curve cofactor.

func (*Curve) ElementSize

func (*Curve) ElementSize() int

ElementSize returns the element size in bytes.

func (*Curve) FromAffine

func (*Curve) FromAffine(x, y *BaseFieldElement) (*Point, error)

FromAffine builds a point from affine coordinates.

func (*Curve) FromAffineX

func (*Curve) FromAffineX(x *BaseFieldElement, b bool) (*Point, error)

FromAffineX builds a point from an affine x-coordinate.

func (*Curve) FromBytes

func (c *Curve) FromBytes(input []byte) (*Point, error)

FromBytes decodes an element from bytes.

func (*Curve) FromCompressed

func (c *Curve) FromCompressed(input []byte) (*Point, error)

FromCompressed decodes a compressed point.

func (*Curve) FromUncompressed

func (c *Curve) FromUncompressed(input []byte) (*Point, error)

FromUncompressed decodes an uncompressed point.

func (*Curve) FromWideBytes

func (c *Curve) FromWideBytes(input []byte) (*Point, error)

FromWideBytes decodes an element from wide bytes.

func (*Curve) Hash

func (c *Curve) Hash(bytes []byte) (*Point, error)

Hash maps input bytes to an element or point.

func (*Curve) HashWithDst

func (*Curve) HashWithDst(dst string, bytes []byte) (*Point, error)

HashWithDst maps input bytes to a point with a custom DST.

func (*Curve) MultiScalarMul

func (*Curve) MultiScalarMul(scalars []*Scalar, points []*Point) (*Point, error)

MultiScalarMul computes a multiscalar multiplication.

func (*Curve) MultiScalarOp

func (c *Curve) MultiScalarOp(scalars []*Scalar, points []*Point) (*Point, error)

MultiScalarOp computes a multiscalar operation.

func (*Curve) Name

func (*Curve) Name() string

Name returns the name of the structure.

func (*Curve) Order

func (*Curve) Order() cardinal.Cardinal

Order returns the group or field order.

func (*Curve) ScalarBaseMul

func (c *Curve) ScalarBaseMul(sc *Scalar) *Point

ScalarBaseMul multiplies the generator by a scalar.

func (*Curve) ScalarBaseOp

func (c *Curve) ScalarBaseOp(sc *Scalar) *Point

ScalarBaseOp adds a scalar multiple of the generator.

func (*Curve) ScalarField

func (*Curve) ScalarField() algebra.PrimeField[*Scalar]

ScalarField returns the scalar field.

func (*Curve) ScalarRing

func (*Curve) ScalarRing() algebra.ZModLike[*Scalar]

ScalarRing returns the scalar ring.

func (*Curve) ScalarStructure

func (*Curve) ScalarStructure() algebra.Structure[*Scalar]

ScalarStructure returns the scalar structure.

func (*Curve) ToElliptic

func (*Curve) ToElliptic() elliptic.Curve

ToElliptic returns the standard library elliptic.Curve adapter.

func (*Curve) WideElementSize

func (*Curve) WideElementSize() int

WideElementSize returns the wide element size in bytes.

type Point

Point represents a curve point.

func (*Point) AffineX

func (p *Point) AffineX() (*BaseFieldElement, error)

AffineX returns the affine x-coordinate.

func (*Point) AffineY

func (p *Point) AffineY() (*BaseFieldElement, error)

AffineY returns the affine y-coordinate.

func (*Point) Bytes

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

Bytes returns the canonical byte encoding.

func (*Point) HashCode

func (p *Point) HashCode() base.HashCode

HashCode returns a hash code for the receiver.

func (*Point) IsTorsionFree

func (*Point) IsTorsionFree() bool

IsTorsionFree reports whether the point is torsion-free.

func (*Point) MarshalBinary

func (p *Point) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Point) MarshalCBOR

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

MarshalCBOR implements cbor.Marshaler.

func (*Point) ScalarMul

func (p *Point) ScalarMul(actor *Scalar) *Point

ScalarMul multiplies the point by a scalar.

func (*Point) ScalarOp

func (p *Point) ScalarOp(sc *Scalar) *Point

ScalarOp adds a scalar multiple of q to the receiver.

func (*Point) String

func (p *Point) String() string

String returns the string form of the receiver.

func (*Point) Structure

func (*Point) Structure() algebra.Structure[*Point]

Structure returns the algebraic structure for the receiver.

func (*Point) ToCompressed

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

ToCompressed encodes the point in compressed form.

func (*Point) ToUncompressed

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

ToUncompressed encodes the point in uncompressed form.

func (*Point) UnmarshalBinary

func (p *Point) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Point) UnmarshalCBOR

func (p *Point) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements cbor.Unmarshaler.

type Scalar

Scalar represents a scalar field element.

func (*Scalar) MarshalBinary

func (fe *Scalar) MarshalBinary() (data []byte, err error)

MarshalBinary implements encoding.BinaryMarshaler.

func (*Scalar) MarshalCBOR

func (fe *Scalar) MarshalCBOR() ([]byte, error)

MarshalCBOR implements cbor.Marshaler.

func (*Scalar) Structure

func (*Scalar) Structure() algebra.Structure[*Scalar]

Structure returns the algebraic structure for the receiver.

func (*Scalar) UnmarshalBinary

func (fe *Scalar) UnmarshalBinary(data []byte) error

UnmarshalBinary implements encoding.BinaryUnmarshaler.

func (*Scalar) UnmarshalCBOR

func (fe *Scalar) UnmarshalCBOR(data []byte) error

UnmarshalCBOR implements cbor.Unmarshaler.

type ScalarField

type ScalarField struct {
	traits.PrimeFieldTrait[*p256Impl.Fq, *Scalar, Scalar]
}

ScalarField represents the scalar field.

func NewScalarField

func NewScalarField() *ScalarField

NewScalarField returns the scalar field instance.

func (*ScalarField) BitLen

func (*ScalarField) BitLen() int

BitLen returns the field modulus bit length.

func (*ScalarField) Characteristic

func (*ScalarField) Characteristic() cardinal.Cardinal

Characteristic returns the field characteristic.

func (*ScalarField) ElementSize

func (*ScalarField) ElementSize() int

ElementSize returns the element size in bytes.

func (*ScalarField) FromBytesBEReduce

func (f *ScalarField) FromBytesBEReduce(input []byte) (*Scalar, error)

FromBytesBEReduce reduces a big-endian integer into the field.

func (*ScalarField) Hash

func (*ScalarField) Hash(bytes []byte) (*Scalar, error)

Hash maps input bytes to an element or point.

func (*ScalarField) Name

func (*ScalarField) Name() string

Name returns the name of the structure.

func (*ScalarField) Order

func (*ScalarField) Order() cardinal.Cardinal

Order returns the group or field order.

func (*ScalarField) WideElementSize

func (*ScalarField) WideElementSize() int

WideElementSize returns the wide element size in bytes.

Directories

Path Synopsis
Package impl contains low-level P-256 field arithmetic and point operations.
Package impl contains low-level P-256 field arithmetic and point operations.

Jump to

Keyboard shortcuts

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