blob: 4a5f826f7a693307722cf3552e5edd3001b28351 [file] [log] [blame]
Adam Langley6814ed32012-09-08 14:24:19 -04001// Copyright 2012 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5/*
6Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
7
8Poly1305 is a fast, one-time authentication function. It is infeasible for an
9attacker to generate an authenticator for a message without the key. However, a
10key must only be used for a single message. Authenticating two different
11messages with the same key allows an attacker to forge authenticators for other
12messages with the same key.
13
14Poly1305 was originally coupled with AES in order to make Poly1305-AES. AES was
15used with a fixed key in order to generate one-time keys from an nonce.
16However, in this package AES isn't used and the one-time key is specified
17directly.
18*/
David Symonds1fbbd622014-12-09 13:38:15 +110019package poly1305 // import "golang.org/x/crypto/poly1305"
Adam Langley6814ed32012-09-08 14:24:19 -040020
21import "crypto/subtle"
22
23// TagSize is the size, in bytes, of a poly1305 authenticator.
24const TagSize = 16
25
26// Verify returns true if mac is a valid authenticator for m with the given
27// key.
28func Verify(mac *[16]byte, m []byte, key *[32]byte) bool {
29 var tmp [16]byte
30 Sum(&tmp, m, key)
31 return subtle.ConstantTimeCompare(tmp[:], mac[:]) == 1
32}