nist

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2023 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package nist implements nist's curves prime-order group

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 nistECGenericPoint[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]) MarshalText

func (e *Element[P]) MarshalText() (text []byte, err error)

MarshalText implements the encoding.MarshalText interface.

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 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]) UnmarshalText

func (e *Element[P]) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.UnmarshalText interface.

type Group

type Group[Point nistECGenericPoint[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() uint

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, empty, scalar.

func (Group[Point]) RandomElement

func (g Group[Point]) RandomElement() internal.Element

RandomElement returns randomly generated element.

func (Group[Point]) RandomScalar

func (g Group[Point]) RandomScalar() internal.Scalar

RandomScalar returns randomly generated scalar.

func (Group[P]) ScalarLength

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

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 returns the sum of the scalars, and does not change 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(data []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 returns the scalar's modular inverse ( 1 / scalar ), and does not change the receiver.

func (*Scalar) IsZero

func (s *Scalar) IsZero() bool

IsZero returns whether the scalar is 0.

func (*Scalar) MarshalBinary

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

MarshalBinary returns the compressed byte encoding of the scalar.

func (*Scalar) MarshalText

func (s *Scalar) MarshalText() (text []byte, err error)

MarshalText implements the encoding.MarshalText interface.

func (*Scalar) Multiply

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

Multiply returns the multiplication of the scalars, and does not change the receiver.

func (*Scalar) One

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

One sets the scalar to 1, and returns it.

func (*Scalar) Random

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

Random sets the current scalar 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) Subtract

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

Subtract returns the difference between the scalars, and does not change 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) UnmarshalText

func (s *Scalar) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.UnmarshalText interface.

func (*Scalar) Zero

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

Zero sets the scalar to 0, and returns it.

Jump to

Keyboard shortcuts

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