nist

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package nist allows simple and abstracted operations in the NIST P-256, P-384, and P-521 groups.

Index

Constants

View Source
const (
	// H2CP256 represents the hash-to-curve string identifier for P256.
	H2CP256 = "P256_XMD:SHA-256_SSWU_RO_"

	// E2CP256 represents the encode-to-curve string identifier for P256.
	E2CP256 = "P256_XMD:SHA-256_SSWU_NU_"

	// H2CP384 represents the hash-to-curve string identifier for P384.
	H2CP384 = "P384_XMD:SHA-384_SSWU_RO_"

	// E2CP384 represents the encode-to-curve string identifier for P384.
	E2CP384 = "P384_XMD:SHA-384_SSWU_NU_"

	// H2CP521 represents the hash-to-curve string identifier for P521.
	H2CP521 = "P521_XMD:SHA-512_SSWU_RO_"

	// E2CP521 represents the encode-to-curve string identifier for P521.
	E2CP521 = "P521_XMD:SHA-512_SSWU_NU_"
)

Variables

This section is empty.

Functions

func P256

func P256() internal.Group

P256 returns the single instantiation of the P256 Group.

func P384

func P384() internal.Group

P384 returns the single instantiation of the P384 Group.

func P521

func P521() internal.Group

P521 returns the single instantiation of the P521 Group.

Types

type Element

type Element[Point nistECPoint[Point]] struct {
	// contains filtered or unexported fields
}

Element implements the Element interface for group elements over NIST curves.

func (*Element[Point]) Add

func (e *Element[Point]) Add(element internal.Element) internal.Element

Add sets the receiver to the sum of the input and the receiver, and returns the receiver.

func (*Element[Point]) Base

func (e *Element[Point]) Base() internal.Element

Base sets the element to the group's base point a.k.a. canonical generator.

func (*Element[P]) Copy

func (e *Element[P]) Copy() internal.Element

Copy returns a copy of the receiver.

func (*Element[P]) Decode

func (e *Element[P]) Decode(data []byte) error

Decode sets the receiver to a decoding of the input data, and returns an error on failure.

func (*Element[Point]) Double

func (e *Element[Point]) Double() internal.Element

Double sets the receiver to its double, and returns it.

func (*Element[P]) Encode

func (e *Element[P]) Encode() []byte

Encode returns the compressed byte encoding of the element.

func (*Element[Point]) Equal

func (e *Element[Point]) Equal(element internal.Element) int

Equal returns 1 if the elements are equivalent, and 0 otherwise.

func (*Element[Point]) Identity

func (e *Element[Point]) Identity() internal.Element

Identity sets the element to the point at infinity of the Group's underlying curve.

func (*Element[P]) IsIdentity

func (e *Element[P]) IsIdentity() bool

IsIdentity returns whether the Element is the point at infinity of the Group's underlying curve.

func (*Element[P]) MarshalBinary

func (e *Element[P]) MarshalBinary() ([]byte, error)

MarshalBinary returns the compressed byte encoding of the element.

func (*Element[P]) Multiply

func (e *Element[P]) Multiply(scalar internal.Scalar) internal.Element

Multiply sets the receiver to the scalar multiplication of the receiver with the given Scalar, and returns it.

func (*Element[P]) Negate

func (e *Element[P]) Negate() internal.Element

Negate sets the receiver to its negation, and returns it.

func (*Element[P]) Set

func (e *Element[P]) Set(element internal.Element) internal.Element

Set sets the receiver to the value of the argument, and returns the receiver.

func (*Element[P]) Subtract

func (e *Element[P]) Subtract(element internal.Element) internal.Element

Subtract subtracts the input from the receiver, and returns the receiver.

func (*Element[P]) UnmarshalBinary

func (e *Element[P]) UnmarshalBinary(data []byte) error

UnmarshalBinary sets e to the decoding of the byte encoded element.

func (*Element[P]) XCoordinate added in v0.4.0

func (e *Element[P]) XCoordinate() []byte

XCoordinate returns the encoded x coordinate of the element.

type Group

type Group[Point nistECPoint[Point]] struct {
	// contains filtered or unexported fields
}

Group represents the prime-order group over the P256 curve. It exposes a prime-order group API with hash-to-curve operations.

func (Group[P]) Base

func (g Group[P]) Base() internal.Element

Base returns the group's base point a.k.a. canonical generator.

func (Group[P]) Ciphersuite

func (g Group[P]) Ciphersuite() string

Ciphersuite returns the hash-to-curve ciphersuite identifier.

func (Group[P]) ElementLength

func (g Group[P]) ElementLength() int

ElementLength returns the byte size of an encoded element.

func (Group[P]) EncodeToGroup

func (g Group[P]) EncodeToGroup(input, dst []byte) internal.Element

EncodeToGroup returns a non-uniform mapping of the arbitrary input to an Element in the Group. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func (Group[P]) HashToGroup

func (g Group[P]) HashToGroup(input, dst []byte) internal.Element

HashToGroup returns a safe mapping of the arbitrary input to an Element in the Group. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func (Group[P]) HashToScalar

func (g Group[P]) HashToScalar(input, dst []byte) internal.Scalar

HashToScalar returns a safe mapping of the arbitrary input to a Scalar. The DST must not be empty or nil, and is recommended to be longer than 16 bytes.

func (Group[P]) NewElement

func (g Group[P]) NewElement() internal.Element

NewElement returns the identity element (point at infinity).

func (Group[P]) NewScalar

func (g Group[P]) NewScalar() internal.Scalar

NewScalar returns a new scalar set to 0.

func (Group[P]) Order added in v0.3.3

func (g Group[P]) Order() string

Order returns the order of the canonical group of scalars.

func (Group[P]) ScalarLength

func (g Group[P]) ScalarLength() int

ScalarLength returns the byte size of an encoded element.

type Scalar

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

Scalar implements the Scalar interface for group scalars.

func (*Scalar) Add

func (s *Scalar) Add(scalar internal.Scalar) internal.Scalar

Add sets the receiver to the sum of the input and the receiver, and returns the receiver.

func (*Scalar) Copy

func (s *Scalar) Copy() internal.Scalar

Copy returns a copy of the Scalar.

func (*Scalar) Decode

func (s *Scalar) Decode(in []byte) error

Decode sets the receiver to a decoding of the input data, and returns an error on failure.

func (*Scalar) Encode

func (s *Scalar) Encode() []byte

Encode returns the compressed byte encoding of the scalar.

func (*Scalar) Equal

func (s *Scalar) Equal(scalar internal.Scalar) int

Equal returns 1 if the scalars are equal, and 0 otherwise.

func (*Scalar) Invert

func (s *Scalar) Invert() internal.Scalar

Invert sets the receiver to its modular inverse ( 1 / s ), and returns it.

func (*Scalar) IsZero

func (s *Scalar) IsZero() bool

IsZero returns whether the scalar is 0.

func (*Scalar) LessOrEqual added in v0.3.4

func (s *Scalar) LessOrEqual(scalar internal.Scalar) int

LessOrEqual returns 1 if s <= scalar, and 0 otherwise.

func (*Scalar) MarshalBinary

func (s *Scalar) MarshalBinary() ([]byte, error)

MarshalBinary returns the compressed byte encoding of the scalar.

func (*Scalar) Multiply

func (s *Scalar) Multiply(scalar internal.Scalar) internal.Scalar

Multiply multiplies the receiver with the input, and returns the receiver.

func (*Scalar) One

func (s *Scalar) One() internal.Scalar

One sets s to 1, and returns it.

func (*Scalar) Pow added in v0.3.4

func (s *Scalar) Pow(scalar internal.Scalar) internal.Scalar

Pow sets s to s**scalar modulo the group order, and returns s. If scalar is nil, it returns 1.

func (*Scalar) Random

func (s *Scalar) Random() internal.Scalar

Random sets s to a new random scalar and returns it. The random source is crypto/rand, and this functions is guaranteed to return a non-zero scalar.

func (*Scalar) Set

func (s *Scalar) Set(scalar internal.Scalar) internal.Scalar

Set sets the receiver to the value of the argument scalar, and returns the receiver.

func (*Scalar) SetInt added in v0.3.5

func (s *Scalar) SetInt(i *big.Int) error

SetInt sets s to i modulo the field order, and returns an error if one occurs.

func (*Scalar) Subtract

func (s *Scalar) Subtract(scalar internal.Scalar) internal.Scalar

Subtract subtracts the input from the receiver, and returns the receiver.

func (*Scalar) UnmarshalBinary

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

UnmarshalBinary sets e to the decoding of the byte encoded scalar.

func (*Scalar) Zero

func (s *Scalar) Zero() internal.Scalar

Zero sets s to 0, and returns it.

Jump to

Keyboard shortcuts

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