ed25519

package
v1.2.31 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2024 License: AGPL-3.0 Imports: 8 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSigInvalidPrvKey    = errors.New("private key not suitable for EdDSA")
	ErrSigNotEdDSA         = errors.New("not a EdDSA signature")
	ErrSigNotEcDSA         = errors.New("not a EcDSA signature")
	ErrSigInvalidEcDSA     = errors.New("invalid EcDSA signature")
	ErrSigHashSizeMismatch = errors.New("hash size mismatch")
	ErrSigInvalid          = errors.New("invalid signature")
)

Error codes for signing / verifying

Functions

func NewKeypair

func NewKeypair() (*PublicKey, *PrivateKey)

NewKeypair creates a new Ed25519 key pair.

Types

type Curve

type Curve struct {
	// P is the generator of the underlying field "F_p"
	// = 2^255 - 19
	P *math.Int
	// N is the order of G
	N *math.Int
	// curve D = 121665/121666
	D *math.Int
	// Gx is the x-coord of the base point
	Gx *math.Int
	// Gy is the y-coord of the base point
	Gy *math.Int
	// Ox is the x-coord of the identity point (Infinity)
	Ox *math.Int
	// Oy is the y-coord of the identity point (Infinity)
	Oy *math.Int
	// contains filtered or unexported fields
}

Curve is the Ed25519 elliptic curve (twisted Edwards curve):

a x^2 + y^2 = 1 + d x^2 y^2,  d = -121665/121666, a = -1

func GetCurve

func GetCurve() *Curve

GetCurve returns the singleton curve instance

func (*Curve) BasePoint

func (c *Curve) BasePoint() *Point

BasePoint returns the base Point of the curve

func (*Curve) Inf

func (c *Curve) Inf() *Point

Inf returns the identity point (infinity)

func (*Curve) MultBase

func (c *Curve) MultBase(k *math.Int) *Point

MultBase multiplies the base Point of the curve with a scalar value k

func (*Curve) SolveX

func (c *Curve) SolveX(y *math.Int) *math.Int

SolveX returns the positive solution of the curve equation for given y-coordinate

type EcSignature

type EcSignature struct {
	R *math.Int
	S *math.Int
}

EcSignature is a ECDSA signature

func NewEcSignatureFromBytes

func NewEcSignatureFromBytes(data []byte) (*EcSignature, error)

NewEcSignatureFromBytes creates a ECDSA signature from its binary representation.

func (*EcSignature) Bytes

func (s *EcSignature) Bytes() []byte

Bytes returns the binary representation of a ECDSA signature.

type EdSignature

type EdSignature struct {
	R *Point
	S *math.Int
}

EdSignature is a EdDSA signature

func NewEdSignatureFromBytes

func NewEdSignatureFromBytes(data []byte) (*EdSignature, error)

NewEdSignatureFromBytes builds a EdDSA signature from its binary representation.

func (*EdSignature) Bytes

func (s *EdSignature) Bytes() []byte

Bytes returns the binary representation of an EdDSA signature

type Point

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

Point (x,y) on the curve

func NewPoint

func NewPoint(a, b *math.Int) *Point

NewPoint instaniates a new Point

func NewPointFromBytes

func NewPointFromBytes(b []byte) (p *Point, err error)

NewPointFromBytes reconstructs a Point from binary representation.

func (*Point) Add

func (p *Point) Add(q *Point) *Point

Add two Points on the curve

func (*Point) Bytes

func (p *Point) Bytes() []byte

Bytes returns a byte representation of Point (compressed or uncompressed).

func (*Point) Double

func (p *Point) Double() *Point

Double a Point on the curve

func (*Point) Equals

func (p *Point) Equals(q *Point) bool

Equals checks if two Points are equal

func (*Point) IsInf

func (p *Point) IsInf() bool

IsInf checks if a Point is at infinity

func (*Point) IsOnCurve

func (p *Point) IsOnCurve() bool

IsOnCurve checks if a Point (x,y) is on the curve

func (*Point) Mult

func (p *Point) Mult(k *math.Int) *Point

Mult multiplies a Point on the curve with a scalar value k using a Montgomery multiplication approach

func (*Point) Neg

func (p *Point) Neg() *Point

Neg returns -P for the point P.

func (*Point) String

func (p *Point) String() string

String returns a human-readable representation of a point.

func (*Point) X

func (p *Point) X() *math.Int

X returns the x-coordinate of a point.

func (*Point) Y

func (p *Point) Y() *math.Int

Y returns the y-coordinate of a point.

type PrivateKey

type PrivateKey struct {
	PublicKey

	Nonce []byte    // 32-byte nonce
	D     *math.Int // private scalar
}

PrivateKey is a Ed25519 private key.

func NewPrivateKeyFromD

func NewPrivateKeyFromD(d *math.Int) *PrivateKey

NewPrivateKeyFromD returns a private key for a given factor. The 'nonce' value (generated from the seed in the "standard case") is now generated by hashing the key material itself.

func NewPrivateKeyFromSeed

func NewPrivateKeyFromSeed(seed []byte) *PrivateKey

NewPrivateKeyFromSeed returns a private key for a given seed. If the seed has no matching length, no key is returned

func (*PrivateKey) Bytes

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

Bytes returns the binary representation of a private key.

func (*PrivateKey) EcSign

func (prv *PrivateKey) EcSign(msg []byte) (*EcSignature, error)

EcSign creates an EcDSA signature for a message.

func (*PrivateKey) EdSign

func (prv *PrivateKey) EdSign(msg []byte) (*EdSignature, error)

EdSign creates an EdDSA signature (R,S) for a message

func (*PrivateKey) Mult

func (prv *PrivateKey) Mult(n *math.Int) *PrivateKey

Mult returns a new private key with d' = n*d mod N

func (*PrivateKey) Public

func (prv *PrivateKey) Public() *PublicKey

Public returns the public key for a private key.

type PublicKey

type PublicKey struct {
	Q *Point
}

PublicKey is a point on the Ed25519 curve.

func NewPublicKeyFromBytes

func NewPublicKeyFromBytes(data []byte) *PublicKey

NewPublicKeyFromBytes creates a new public key from a binary representation.

func (*PublicKey) Bytes

func (pub *PublicKey) Bytes() []byte

Bytes returns the binary representation of a public key.

func (*PublicKey) EcVerify

func (pub *PublicKey) EcVerify(msg []byte, sig *EcSignature) (bool, error)

EcVerify checks a EcDSA signature of a message.

func (*PublicKey) EdVerify

func (pub *PublicKey) EdVerify(msg []byte, sig *EdSignature) (bool, error)

EdVerify checks an EdDSA signature of a message.

func (*PublicKey) Mult

func (pub *PublicKey) Mult(n *math.Int) *PublicKey

Mult returns P = n*Q

Jump to

Keyboard shortcuts

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