cache

package
v0.0.0-...-1f23a7b Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2023 License: BSD-3-Clause Imports: 4 Imported by: 22

Documentation

Overview

Package cache implements a set of caching wrappers around Ed25519 signature verification to transparently accelerate repeated verification with the same public key(s).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	// Get returns a public key's corresponding expanded public key iff
	// present in the cache, or returns nil.
	Get(publicKey *curve.CompressedEdwardsY) *ed25519.ExpandedPublicKey

	// Put adds the expanded public key to the cache.
	Put(publicKey *curve.CompressedEdwardsY, expanded *ed25519.ExpandedPublicKey)
}

Cache is an expanded public key cache.

func NewLRUCache

func NewLRUCache(capacity int) Cache

NewLRUCache creates a new cache with a Least-Recently-Used replacement policy. Cache instances returned are thread-safe.

type Verifier

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

Verifier verifies signatures, storing expanded public keys in a cache for reuse by subsequent verification with the same public key.

Note: Unless there are more cache hits than misses, this will likely be a net performance loss. Integration should be followed by benchmarking.

func NewVerifier

func NewVerifier(cache Cache) *Verifier

NewVerifier creates a new Verifier instance backed by a Cache.

func (*Verifier) Add

func (v *Verifier) Add(verifier *ed25519.BatchVerifier, publicKey ed25519.PublicKey, message, sig []byte)

Add will add the signature to the batch verifier.

func (*Verifier) AddPublicKey

func (v *Verifier) AddPublicKey(publicKey ed25519.PublicKey)

AddPublicKey will expand and add the public key to the cache.

func (*Verifier) AddWithOptions

func (v *Verifier) AddWithOptions(verifier *ed25519.BatchVerifier, publicKey ed25519.PublicKey, message, sig []byte, opts *ed25519.Options)

AddWithOptions will add the signature to the batch verifier, with extra Options.

func (*Verifier) Verify

func (v *Verifier) Verify(publicKey ed25519.PublicKey, message, sig []byte) bool

Verify repors whether sig is a valid Ed25519 signature by public key.

func (*Verifier) VerifyWithOptions

func (v *Verifier) VerifyWithOptions(publicKey ed25519.PublicKey, message, sig []byte, opts *ed25519.Options) bool

VerifyWithOptions reports whether sig is a valid Ed25519 signature by publicKey, with extra Options.

Jump to

Keyboard shortcuts

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