sign

package
v0.0.0-...-cb92b4e Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2023 License: MPL-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendPrivateKey

func AppendPrivateKey[Private any](out []byte, sch PrivateKeyScheme[Private], priv *Private) []byte

func AppendPublicKey

func AppendPublicKey[Public any](out []byte, sch PublicKeyScheme[Public], pub *Public) []byte

AppendPublicKey appends the marshaled form of pub to out, using sch to marshal the public key.

func TestScheme

func TestScheme[Priv, Pub any](t *testing.T, scheme Scheme[Priv, Pub])

Types

type Dual

type Dual[LPriv, LPub, RPriv, RPub any] struct {
	L Scheme[LPriv, LPub]
	R Scheme[RPriv, RPub]
}

Dual is a signing scheme composed of two signing schemes

func (Dual[LPriv, LPub, RPriv, RPub]) DerivePublic

func (s Dual[LPriv, LPub, RPriv, RPub]) DerivePublic(priv *DualKey[LPriv, RPriv]) DualKey[LPub, RPub]

func (Dual[LPriv, LPub, RPriv, RPub]) Generate

func (s Dual[LPriv, LPub, RPriv, RPub]) Generate(rng io.Reader) (DualKey[LPub, RPub], DualKey[LPriv, RPriv], error)

func (Dual[LPriv, LPub, RPriv, RPub]) MarshalPrivate

func (s Dual[LPriv, LPub, RPriv, RPub]) MarshalPrivate(dst []byte, x *DualKey[LPriv, RPriv])

func (Dual[LPriv, LPub, RPriv, RPub]) MarshalPublic

func (s Dual[LPriv, LPub, RPriv, RPub]) MarshalPublic(dst []byte, x *DualKey[LPub, RPub])

func (Dual[LPriv, LPub, RPriv, RPub]) ParsePrivate

func (s Dual[LPriv, LPub, RPriv, RPub]) ParsePrivate(x []byte) (DualKey[LPriv, RPriv], error)

func (Dual[LPriv, LPub, RPriv, RPub]) ParsePublic

func (s Dual[LPriv, LPub, RPriv, RPub]) ParsePublic(x []byte) (DualKey[LPub, RPub], error)

func (Dual[LPriv, LPub, RPriv, RPub]) PrivateKeySize

func (s Dual[LPriv, LPub, RPriv, RPub]) PrivateKeySize() int

func (Dual[LPriv, LPub, RPriv, RPub]) PublicKeySize

func (s Dual[LPriv, LPub, RPriv, RPub]) PublicKeySize() int

func (Dual[LPriv, LPub, RPriv, RPub]) Sign

func (s Dual[LPriv, LPub, RPriv, RPub]) Sign(dst []byte, priv *DualKey[LPriv, RPriv], input []byte)

func (Dual[LPriv, LPub, RPriv, RPub]) SignatureSize

func (s Dual[LPriv, LPub, RPriv, RPub]) SignatureSize() int

func (Dual[LPriv, LPub, RPriv, RPub]) Verify

func (s Dual[LPriv, LPub, RPriv, RPub]) Verify(pub *DualKey[LPub, RPub], input []byte, sig []byte) bool

type DualKey

type DualKey[L, R any] struct {
	L L
	R R
}

DualKey is a hybrid key made of 2 keys

type Input512

type Input512 = [64]byte

Input512 is the input to a signature in Scheme512. Input512 must be high entropy.

type PrivateKeyScheme

type PrivateKeyScheme[Private any] interface {
	MarshalPrivate(dst []byte, priv *Private)
	ParsePrivate(x []byte) (Private, error)
	PrivateKeySize() int
}

type PublicKeyScheme

type PublicKeyScheme[Public any] interface {
	// MarshalPublic marshals a public key to binary data
	// MarshalPublic panics if dst is not >= PublicKeySize()
	MarshalPublic(dst []byte, pub *Public)
	// ParsePublic attempts to parse a public key from bytes
	ParsePublic([]byte) (Public, error)
	// PublicKeySize returns the size of a public key
	PublicKeySize() int
}

type Purpose

type Purpose[Private, Public, XOF any] struct {
	Scheme  Scheme512[Private, Public]
	Purpose string
	XOF     xof.Scheme[XOF]
}

Purpose allows keys to sign with multiple contexts

func NewPurpose

func NewPurpose[Private, Public, XOF any](s Scheme512[Private, Public], xofSch xof.Scheme[XOF], purpose string) Purpose[Private, Public, XOF]

func (Purpose[Private, Public, XOF]) DerivePublic

func (s Purpose[Private, Public, XOF]) DerivePublic(priv *Private) Public

func (Purpose[Private, Public, XOF]) Generate

func (s Purpose[Private, Public, XOF]) Generate(rng io.Reader) (Public, Private, error)

func (Purpose[Private, Public, XOF]) MarshalPrivate

func (s Purpose[Private, Public, XOF]) MarshalPrivate(dst []byte, priv *Private)

func (Purpose[Private, Public, XOF]) MarshalPublic

func (s Purpose[Private, Public, XOF]) MarshalPublic(dst []byte, pub *Public)

func (Purpose[Private, Public, XOF]) ParsePrivate

func (s Purpose[Private, Public, XOF]) ParsePrivate(data []byte) (Private, error)

func (Purpose[Private, Public, XOF]) ParsePublic

func (s Purpose[Private, Public, XOF]) ParsePublic(data []byte) (Public, error)

func (Purpose[Private, Public, XOF]) PrivateKeySize

func (s Purpose[Private, Public, XOF]) PrivateKeySize() int

func (Purpose[Private, Public, XOF]) PublicKeySize

func (s Purpose[Private, Public, XOF]) PublicKeySize() int

func (Purpose[Private, Public, XOF]) Sign

func (s Purpose[Private, Public, XOF]) Sign(dst []byte, priv *Private, msg []byte)

func (Purpose[Private, Public, XOF]) Sign512

func (s Purpose[Private, Public, XOF]) Sign512(dst []byte, priv *Private, input *Input512)

func (Purpose[Private, Public, XOF]) SignatureSize

func (s Purpose[Private, Public, XOF]) SignatureSize() int

func (Purpose[Private, Public, XOF]) Verify

func (s Purpose[Private, Public, XOF]) Verify(pub *Public, msg, sig []byte) bool

func (Purpose[Private, Public, XOF]) Verify512

func (s Purpose[Private, Public, XOF]) Verify512(pub *Public, input *Input512, sig []byte) bool

type Scheme

type Scheme[Private, Public any] interface {
	// Generate creates a public and private key
	Generate(rng io.Reader) (pub Public, priv Private, err error)
	// DerivePublic derives the Public key which corresponds to the private key
	DerivePublic(*Private) Public

	// Sign uses priv to produce a signature for msg and writes it to dst.
	// dst must be at least SignatureSize
	Sign(dst []byte, priv *Private, msg []byte)
	// Verify checks if sig is a valid signature produced by pub for msg
	Verify(pub *Public, msg []byte, sig []byte) bool
	// SignatureSize returns the size of a public key
	SignatureSize() int

	PublicKeyScheme[Public]
	PrivateKeyScheme[Private]
}

Scheme is a scheme for digital signatures with variable length inputs

type Scheme512

type Scheme512[Private, Public any] interface {
	// Generate creates a public and private key
	Generate(rng io.Reader) (pub Public, priv Private, err error)
	// DerivePublic derives the Public key which corresponds to the private key
	DerivePublic(*Private) Public

	// Sign512 uses priv to produce a signature for msg and writes it to dst.
	// dst must be at least SignatureSize
	Sign512(dst []byte, priv *Private, input *Input512)
	// Verify512 checks if sig is a valid signature produced by pub for msg
	Verify512(pub *Public, input *Input512, sig []byte) bool
	// SignatureSize returns the size of a public key
	SignatureSize() int

	PublicKeyScheme[Public]
	PrivateKeyScheme[Private]
}

Scheme512 is a scheme for digital signatures on 512 bits of input. Schemes implementing Scheme512 can have a maximum security of 256 bits against signature collisions. Forging signatures for a given input can have a maximum of 512 bits of security, but most implementations typically provide less.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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