eddilithium2

package
v0.0.0-...-ac9c40d Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package eddilithium2 implements the hybrid signature scheme Ed25519-Dilithium2.

Example
package main

import (
	"fmt"

	"github.com/JI-0/circl/sign/eddilithium2"
)

func main() {
	// Generates a keypair.
	pk, sk, err := eddilithium2.GenerateKey(nil)
	if err != nil {
		panic(err)
	}

	// (Alternatively one can derive a keypair from a seed,
	// see NewKeyFromSeed().)

	// Packs public and private key
	var packedSk [eddilithium2.PrivateKeySize]byte
	var packedPk [eddilithium2.PublicKeySize]byte
	sk.Pack(&packedSk)
	pk.Pack(&packedPk)

	// Load it again
	var sk2 eddilithium2.PrivateKey
	var pk2 eddilithium2.PublicKey
	sk2.Unpack(&packedSk)
	pk2.Unpack(&packedPk)

	// Creates a signature on our message with the generated private key.
	msg := []byte("Some message")
	var signature [eddilithium2.SignatureSize]byte
	eddilithium2.SignTo(&sk2, msg, signature[:])

	// Checks whether a signature is correct
	if !eddilithium2.Verify(&pk2, msg, signature[:]) {
		panic("incorrect signature")
	}

	fmt.Printf("O.K.")

}
Output:

O.K.

Index

Examples

Constants

View Source
const (
	// SeedSize is the length of the seed for NewKeyFromSeed
	SeedSize = mode2.SeedSize // = ed25519.SeedSize = 32

	// PublicKeySize is the length in bytes of the packed public key.
	PublicKeySize = mode2.PublicKeySize + ed25519.PublicKeySize

	// PrivateKeySize is the length in bytes of the packed public key.
	PrivateKeySize = mode2.PrivateKeySize + ed25519.SeedSize

	// SignatureSize is the length in bytes of the signatures.
	SignatureSize = mode2.SignatureSize + ed25519.SignatureSize
)

Variables

This section is empty.

Functions

func GenerateKey

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

GenerateKey generates a public/private key pair using entropy from rand. If rand is nil, crypto/rand.Reader will be used.

func NewKeyFromSeed

func NewKeyFromSeed(seed *[SeedSize]byte) (*PublicKey, *PrivateKey)

NewKeyFromSeed derives a public/private key pair using the given seed.

func Scheme

func Scheme() sign.Scheme

Scheme returns a signature interface.

func SignTo

func SignTo(sk *PrivateKey, msg []byte, signature []byte)

SignTo signs the given message and writes the signature into signature. It will panic if signature is not of length at least SignatureSize.

func Verify

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

Verify checks whether the given signature by pk on msg is valid.

Types

type PrivateKey

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

PrivateKey is the type of an EdDilithium2 private key.

func (*PrivateKey) Bytes

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

Bytes packs the private key.

func (*PrivateKey) Equal

func (sk *PrivateKey) Equal(other crypto.PrivateKey) bool

func (*PrivateKey) MarshalBinary

func (sk *PrivateKey) MarshalBinary() ([]byte, error)

MarshalBinary packs the private key.

func (*PrivateKey) Pack

func (sk *PrivateKey) Pack(buf *[PrivateKeySize]byte)

Pack packs the private key into buf.

func (*PrivateKey) Public

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

Public computes the public key corresponding to this private key.

Returns a *PublicKey. The type crypto.PublicKey is used to make PrivateKey implement the crypto.Signer interface.

func (*PrivateKey) Scheme

func (sk *PrivateKey) Scheme() sign.Scheme

func (*PrivateKey) Sign

func (sk *PrivateKey) Sign(
	rand io.Reader, msg []byte, opts crypto.SignerOpts,
) (signature []byte, err error)

Sign signs the given message.

opts.HashFunc() must return zero, which can be achieved by passing crypto.Hash(0) for opts. rand is ignored. Will only return an error if opts.HashFunc() is non-zero.

This function is used to make PrivateKey implement the crypto.Signer interface. The package-level SignTo function might be more convenient to use.

func (*PrivateKey) UnmarshalBinary

func (sk *PrivateKey) UnmarshalBinary(data []byte) error

UnmarshalBinary unpacks the private key from data.

func (*PrivateKey) Unpack

func (sk *PrivateKey) Unpack(buf *[PrivateKeySize]byte)

Unpack sets sk to the private key encoded in buf.

type PublicKey

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

PublicKey is the type of an EdDilithium2 public key.

func (*PublicKey) Bytes

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

Bytes packs the public key.

func (*PublicKey) Equal

func (pk *PublicKey) Equal(other crypto.PublicKey) bool

func (*PublicKey) MarshalBinary

func (pk *PublicKey) MarshalBinary() ([]byte, error)

MarshalBinary packs the public key.

func (*PublicKey) Pack

func (pk *PublicKey) Pack(buf *[PublicKeySize]byte)

Pack packs the public key into buf.

func (*PublicKey) Scheme

func (pk *PublicKey) Scheme() sign.Scheme

func (*PublicKey) UnmarshalBinary

func (pk *PublicKey) UnmarshalBinary(data []byte) error

UnmarshalBinary the public key from data.

func (*PublicKey) Unpack

func (pk *PublicKey) Unpack(buf *[PublicKeySize]byte)

Unpack unpacks pk to the public key encoded in buf.

Jump to

Keyboard shortcuts

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