ed521

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContextMaxSize is the maximum length (in bytes) allowed for context.
	ContextMaxSize = 255
	// PublicKeySize is the size, in bytes, of public keys as used in this package.
	PublicKeySize = 66
	// PrivateKeySize is the size, in bytes, of private keys as used in this package.
	PrivateKeySize = 132
	// SignatureSize is the size, in bytes, of signatures generated and verified by this package.
	SignatureSize = 132
	// SeedSize is the size, in bytes, of private key seeds.
	SeedSize = 66
)

Variables

View Source
var (
	ErrInvalidASN1 = errors.New("go-cryptobin/ed521: invalid ASN.1 encoding")
)

Functions

func MarshalPrivateKey

func MarshalPrivateKey(priv *PrivateKey) ([]byte, error)

Marshal PrivateKey to der

func MarshalPublicKey

func MarshalPublicKey(pub *PublicKey) ([]byte, error)

Marshal PublicKey to der

func PrivateKeyTo

func PrivateKeyTo(key *PrivateKey) []byte

return PrivateKey data

func PublicKeyTo

func PublicKeyTo(key *PublicKey) []byte

return PublicKey data

func Sign

func Sign(rand io.Reader, priv *PrivateKey, msg []byte) ([]byte, error)

sign data and return marshal plain data

func Verify

func Verify(pub *PublicKey, msg, signature []byte) (bool, error)

Verify marshaled plain data

func VerifyWithOptions

func VerifyWithOptions(publicKey *PublicKey, message, sig []byte, opts crypto.SignerOpts) error

VerifyWithOptions reports whether sig is a valid signature of message by publicKey.

Types

type Options

type Options struct {
	// Hash must be crypto.Hash(0) for both Ed521 and Ed521Ph.
	Hash crypto.Hash

	// Context is an optional domain separation string for signing.
	// Its length must be less or equal than 255 bytes.
	Context string

	// Scheme is an identifier for choosing a signature scheme.
	Scheme SchemeID
}

Options implements crypto.SignerOpts and augments with parameters that are specific to the Ed521 signature schemes.

func (*Options) HashFunc

func (o *Options) HashFunc() crypto.Hash

HashFunc returns o.Hash.

type PrivateKey

type PrivateKey struct {
	PublicKey

	D *big.Int
}

func GenerateKey

func GenerateKey(rand io.Reader) (*PrivateKey, error)

GenerateKey returns Ed521 PrivateKey

func NewKeyFromBytes

func NewKeyFromBytes(bytes []byte) (*PrivateKey, error)

New a private key from bytes

func NewKeyFromSeed

func NewKeyFromSeed(seed []byte) (*PrivateKey, error)

New a private key from seed bytes

func NewPrivateKey

func NewPrivateKey(d []byte) (*PrivateKey, error)

New a private key from key data bytes

func ParsePrivateKey

func ParsePrivateKey(der []byte) (*PrivateKey, error)

Parse PrivateKey der

func (*PrivateKey) Bytes

func (priv *PrivateKey) Bytes() []byte

func (*PrivateKey) Equal

func (priv *PrivateKey) Equal(x crypto.PrivateKey) bool

Equal reports whether priv and x have the same value.

func (*PrivateKey) Public

func (priv *PrivateKey) Public() crypto.PublicKey

Public returns the public key corresponding to priv.

func (*PrivateKey) Seed

func (priv *PrivateKey) Seed() []byte

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(rand io.Reader, message []byte, opts crypto.SignerOpts) ([]byte, error)

Sign creates a signature for message

type PublicKey

type PublicKey struct {
	elliptic.Curve

	X, Y *big.Int
}

func NewPublicKey

func NewPublicKey(data []byte) (*PublicKey, error)

New a PublicKey from publicKey data

func ParsePublicKey

func ParsePublicKey(derBytes []byte) (pub *PublicKey, err error)

Parse PublicKey der

func (*PublicKey) Equal

func (pub *PublicKey) Equal(x crypto.PublicKey) bool

Equal reports whether pub and x have the same value.

func (*PublicKey) Verify

func (pub *PublicKey) Verify(message, sig []byte) bool

Verify verifies the signature of message for a given public key

type SchemeID

type SchemeID uint

SchemeID is an identifier for each signature scheme.

const (
	ED521 SchemeID = iota
	ED521Ph
)

Jump to

Keyboard shortcuts

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