poly1305

package
v0.0.0-...-8b7e99e Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2023 License: LGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.

Poly1305 is a fast, one-time authentication function. It is infeasible for an attacker to generate an authenticator for a message without the key. However, a key must only be used for a single message. Authenticating two different messages with the same key allows an attacker to forge authenticators for other messages with the same key.

Poly1305 was originally coupled with AES in order to make Poly1305-AES. AES was used with a fixed key in order to generate one-time keys from an nonce. However, in this package AES isn't used and the one-time key is specified directly.

Index

Constants

View Source
const TagSize = 16

The size of the poly1305 authentication tag in bytes.

Variables

This section is empty.

Functions

func Sum

func Sum(out *[TagSize]byte, msg []byte, key *[32]byte)

Sum generates an authenticator for msg using a one-time key and puts the 16-byte result into out. Authenticating two different messages with the same key allows an attacker to forge messages at will.

func Verify

func Verify(mac *[TagSize]byte, msg []byte, key *[32]byte) bool

Verify returns true if and only if the mac is a valid authenticator for msg with the given key.

Types

type Hash

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

Hash implements a Poly1305 writer interface. Poly1305 cannot used like common hash.Hash implementations, beause of using a Poly1305 key twice breaks its security. So poly1305.Hash does not support some kind of reset.

func New

func New(key *[32]byte) *Hash

New returns a hash.Hash computing the poly1305 sum. Notice that Poly1305 is inseure if one key is used twice.

func (*Hash) Sum

func (p *Hash) Sum(out *[TagSize]byte)

Sum computes the Poly1305 checksum of the prevouisly processed data and writes it to out. It is legal to call this function more than one time.

func (*Hash) Write

func (p *Hash) Write(msg []byte) (int, error)

Write adds more data to the running Poly1305 hash. This function returns an non-nil error, if a call to Write happens after the hash's Sum function was called. So it's not possible to compute the checksum and than add more data.

Jump to

Keyboard shortcuts

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