Documentation ¶
Overview ¶
Package nist allows simple and abstracted operations in the NIST P-256, P-384, and P-521 groups.
Index ¶
- Constants
- func P256() internal.Group
- func P384() internal.Group
- func P521() internal.Group
- type Element
- func (e *Element[Point]) Add(element internal.Element) internal.Element
- func (e *Element[Point]) Base() internal.Element
- func (e *Element[P]) Copy() internal.Element
- func (e *Element[P]) Decode(data []byte) error
- func (e *Element[P]) DecodeHex(h string) error
- func (e *Element[Point]) Double() internal.Element
- func (e *Element[P]) Encode() []byte
- func (e *Element[Point]) Equal(element internal.Element) int
- func (e *Element[P]) Hex() string
- func (e *Element[Point]) Identity() internal.Element
- func (e *Element[P]) IsIdentity() bool
- func (e *Element[P]) Multiply(scalar internal.Scalar) internal.Element
- func (e *Element[P]) Negate() internal.Element
- func (e *Element[P]) Set(element internal.Element) internal.Element
- func (e *Element[P]) Subtract(element internal.Element) internal.Element
- func (e *Element[P]) XCoordinate() []byte
- type Group
- func (g Group[P]) Base() internal.Element
- func (g Group[P]) Ciphersuite() string
- func (g Group[P]) ElementLength() int
- func (g Group[P]) EncodeToGroup(input, dst []byte) internal.Element
- func (g Group[P]) HashFunc() crypto.Hash
- func (g Group[P]) HashToGroup(input, dst []byte) internal.Element
- func (g Group[P]) HashToScalar(input, dst []byte) internal.Scalar
- func (g Group[P]) NewElement() internal.Element
- func (g Group[P]) NewScalar() internal.Scalar
- func (g Group[P]) Order() string
- func (g Group[P]) ScalarLength() int
- type Scalar
- func (s *Scalar) Add(scalar internal.Scalar) internal.Scalar
- func (s *Scalar) Copy() internal.Scalar
- func (s *Scalar) Decode(in []byte) error
- func (s *Scalar) DecodeHex(h string) error
- func (s *Scalar) Encode() []byte
- func (s *Scalar) Equal(scalar internal.Scalar) int
- func (s *Scalar) Hex() string
- func (s *Scalar) Invert() internal.Scalar
- func (s *Scalar) IsZero() bool
- func (s *Scalar) LessOrEqual(scalar internal.Scalar) int
- func (s *Scalar) Multiply(scalar internal.Scalar) internal.Scalar
- func (s *Scalar) One() internal.Scalar
- func (s *Scalar) Pow(scalar internal.Scalar) internal.Scalar
- func (s *Scalar) Random() internal.Scalar
- func (s *Scalar) Set(scalar internal.Scalar) internal.Scalar
- func (s *Scalar) SetUInt64(i uint64) internal.Scalar
- func (s *Scalar) Subtract(scalar internal.Scalar) internal.Scalar
- func (s *Scalar) UInt64() (uint64, error)
- func (s *Scalar) Zero() internal.Scalar
Constants ¶
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 ¶
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 ¶
Add sets the receiver to the sum of the input and the receiver, and returns the receiver.
func (*Element[Point]) Base ¶
Base sets the element to the group's base point a.k.a. canonical generator.
func (*Element[P]) Decode ¶
Decode sets the receiver to a decoding of the input data, and returns an error on failure.
func (*Element[P]) DecodeHex ¶ added in v0.7.0
DecodeHex sets e to the decoding of the hex encoded element.
func (*Element[Point]) Identity ¶
Identity sets the element to the point at infinity of the Group's underlying curve.
func (*Element[P]) IsIdentity ¶
IsIdentity returns whether the Element is the point at infinity of the Group's underlying curve.
func (*Element[P]) Multiply ¶
Multiply sets the receiver to the scalar multiplication of the receiver with the given Scalar, and returns it.
func (*Element[P]) Set ¶
Set sets the receiver to the value of the argument, and returns the receiver.
func (*Element[P]) Subtract ¶
Subtract subtracts the input from the receiver, and returns the receiver.
func (*Element[P]) XCoordinate ¶ added in v0.4.0
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]) Ciphersuite ¶
Ciphersuite returns the hash-to-curve ciphersuite identifier.
func (Group[P]) ElementLength ¶
ElementLength returns the byte size of an encoded element.
func (Group[P]) EncodeToGroup ¶
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]) HashFunc ¶ added in v0.7.1
HashFunc returns the RFC9380 associated hash function of the group.
func (Group[P]) HashToGroup ¶
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 ¶
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 ¶
NewElement returns the identity element (point at infinity).
func (Group[P]) ScalarLength ¶
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 ¶
Add sets the receiver to the sum of the input and the receiver, and returns the receiver.
func (*Scalar) Decode ¶
Decode sets the receiver to a decoding of the input data, and returns an error on failure.
func (*Scalar) DecodeHex ¶ added in v0.7.0
DecodeHex sets s to the decoding of the hex encoded scalar.
func (*Scalar) LessOrEqual ¶ added in v0.3.4
LessOrEqual returns 1 if s <= scalar, and 0 otherwise.
func (*Scalar) Multiply ¶
Multiply multiplies the receiver with the input, and returns the receiver.
func (*Scalar) Pow ¶ added in v0.3.4
Pow sets s to s**scalar modulo the group order, and returns s. If scalar is nil, it returns 1.
func (*Scalar) Random ¶
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 ¶
Set sets the receiver to the value of the argument scalar, and returns the receiver.
func (*Scalar) SetUInt64 ¶ added in v0.7.0
SetUInt64 sets s to i modulo the field order, and returns an error if one occurs.