Documentation
¶
Overview ¶
Package nist allows simple and abstracted operations in the NIST P-256, P-384, and P-521 groups, wrapping filippo.io/nistec.
Index ¶
- Constants
- Variables
- 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[Point]) Group() byte
- 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, error)
- func (g Group[P]) HashFunc() crypto.Hash
- func (g Group[P]) HashToGroup(input, dst []byte) (internal.Element, error)
- func (g Group[P]) HashToScalar(input, dst []byte) (internal.Scalar, error)
- func (g Group[P]) NewElement() internal.Element
- func (g Group[P]) NewScalar() internal.Scalar
- func (g Group[P]) Order() []byte
- 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(data []byte) error
- func (s *Scalar) DecodeHex(h string) error
- func (s *Scalar) DecodeWithReduction(data []byte) error
- func (s *Scalar) Encode() []byte
- func (s *Scalar) Equal(scalar internal.Scalar) int
- func (s *Scalar) Group() byte
- 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) MinusOne() internal.Scalar
- 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 is the hash-to-curve ciphersuite identifier for P-256. H2CP256 = nistP256.H2CP256 // E2CP256 is the encode-to-curve ciphersuite identifier for P-256. E2CP256 = nistP256.E2CP256 // H2CP384 is the hash-to-curve ciphersuite identifier for P-384. H2CP384 = nistP384.H2CP384 // E2CP384 is the encode-to-curve ciphersuite identifier for P-384. E2CP384 = nistP384.E2CP384 // H2CP521 is the hash-to-curve ciphersuite identifier for P-521. H2CP521 = nistP521.H2CP521 // E2CP521 is the encode-to-curve ciphersuite identifier for P-521. E2CP521 = nistP521.E2CP521 // IdentifierP256 identifies the P-256 group internally. IdentifierP256 = byte(3) // IdentifierP384 identifies the P-384 group internally. IdentifierP384 = byte(4) // IdentifierP521 identifies the P-521 group internally. IdentifierP521 = byte(5) )
Variables ¶
var ( // ErrDecodeElementP256 is returned when input data could not be decoded to a P256 element. ErrDecodeElementP256 = errors.New("invalid P256 element encoding") // ErrDecodeElementP384 is returned when input data could not be decoded to a P384 element. ErrDecodeElementP384 = errors.New("invalid P384 element encoding") // ErrDecodeElementP521 is returned when input data could not be decoded to a P521 element. ErrDecodeElementP521 = errors.New("invalid P521 element encoding") )
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[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 ¶
XCoordinate returns the encoded x coordinate of the element.
type Group ¶
type Group[Point nistECPoint[Point]] struct {
NewPoint func() Point
// contains filtered or unexported fields
}
Group exposes the prime-order API for a NIST curve backed by nistec points.
func (Group[P]) Ciphersuite ¶
Ciphersuite returns the RFC 9380 ciphersuite identifier.
func (Group[P]) ElementLength ¶
ElementLength returns the encoded element length in bytes.
func (Group[P]) EncodeToGroup ¶
EncodeToGroup encodes arbitrary input to a non-uniform group element.
func (Group[P]) HashToGroup ¶
HashToGroup hashes arbitrary input to a group element.
func (Group[P]) HashToScalar ¶
HashToScalar hashes arbitrary input to a scalar.
func (Group[P]) NewElement ¶
NewElement returns the identity element.
func (Group[P]) ScalarLength ¶
ScalarLength returns the encoded scalar length in bytes.
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 s to a big-endian byte decoding of x. If x is not a canonical encoding of s, Decode returns an error.
func (*Scalar) DecodeWithReduction ¶ added in v0.10.0
DecodeWithReduction sets s to x modulo the group order. If x is nil or not of the correct input length, DecodeWithReduction returns an error.
func (*Scalar) LessOrEqual ¶
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 ¶
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 ¶
SetUInt64 sets s to i modulo the field order, and returns an error if one occurs.