poly1305

package
Version: v0.0.1-0...-b0a97bd Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: CC0-1.0 Imports: 6 Imported by: 0

README

poly1305: Go Poly1305

Yawning Angel (yawning at schwanenlied dot me)

Poly1305 implements the Poly1305 MAC algorithm, exposing a saner interface than the one provided by golang.org/x/crypto/poly1305. In particular it exposes a object that implements a hash.Hash interface.

The implementation is based on the Public Domain poly1305-donna by Andrew Moon.

Implementation 64 byte 1024 byte
go.crypto (ref) 94.51 MB/s 187.67 MB/s
go.crypto (amd64) 540.68 MB/s 909.97 MB/s
go poly1305-donna-32 425.40 MB/s 715.23 MB/s

Note: All numbers on a i5-4250U, and to be taken with a huge grain of salt.

Documentation

Overview

Package poly1305 is a Poly1305 MAC implementation. It is different from the golang.org/x/crypto implementation in that it exports a hash.Hash interface to support incremental updates.

The implementation is based on Andrew Moon's poly1305-donna.

Index

Constants

View Source
const (
	// KeySize is the Poly1305 key size in bytes.
	KeySize = 32

	// Size is the Poly1305 MAC size in bytes.
	Size = 16

	// BlockSize is the Poly1305 block size in bytes.
	BlockSize = 16
)

Variables

View Source
var (
	// ErrInvalidKeySize is the error returned when an invalid sized key is
	// encountered.
	ErrInvalidKeySize = errors.New("poly1305: invalid key size")

	// ErrInvalidMacSize is the error returned when an invalid sized MAC is
	// encountered.
	ErrInvalidMacSize = errors.New("poly1305: invalid mac size")
)

Functions

func Sum

func Sum(mac *[Size]byte, m []byte, key *[KeySize]byte)

Sum does exactly what golang.org/x/crypto/poly1305.Sum() does.

func Verify

func Verify(mac *[Size]byte, m []byte, key *[KeySize]byte) bool

Verify does exactly what golang.org/x/crypto/poly1305.Verify does.

Types

type Poly1305

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

Poly1305 is an instance of the Poly1305 MAC algorithm.

func New

func New(key []byte) (*Poly1305, error)

New returns a new Poly1305 instance keyed with the supplied key.

func (*Poly1305) BlockSize

func (st *Poly1305) BlockSize() int

BlockSize returns the hash's underlying block size.

func (*Poly1305) Clear

func (st *Poly1305) Clear()

Clear purges the sensitive material in hash's internal state.

func (*Poly1305) Init

func (st *Poly1305) Init(key []byte)

Init (re-)initializes the hash instance with a given key.

func (*Poly1305) Reset

func (st *Poly1305) Reset()

Reset clears the internal hash state and panic()s, because calling this is a sign that the user is doing something unadvisable.

func (*Poly1305) Size

func (st *Poly1305) Size() int

Size returns the number of bytes Sum will return.

func (*Poly1305) Sum

func (st *Poly1305) Sum(b []byte) []byte

Sum appends the current hash to b and returns the resulting slice. It does not change the underlying hash state.

func (*Poly1305) Write

func (st *Poly1305) Write(p []byte) (n int, err error)

Write adds more data to the running hash. It never returns an error.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL