1
0

poly1305.go 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. // 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. Package poly1305 implements Poly1305 one-time message authentication code as specified in http://cr.yp.to/mac/poly1305-20050329.pdf.
  6. Poly1305 is a fast, one-time authentication function. It is infeasible for an
  7. attacker to generate an authenticator for a message without the key. However, a
  8. key must only be used for a single message. Authenticating two different
  9. messages with the same key allows an attacker to forge authenticators for other
  10. messages with the same key.
  11. Poly1305 was originally coupled with AES in order to make Poly1305-AES. AES was
  12. used with a fixed key in order to generate one-time keys from an nonce.
  13. However, in this package AES isn't used and the one-time key is specified
  14. directly.
  15. */
  16. package poly1305 // import "golang.org/x/crypto/poly1305"
  17. import "crypto/subtle"
  18. // TagSize is the size, in bytes, of a poly1305 authenticator.
  19. const TagSize = 16
  20. // Verify returns true if mac is a valid authenticator for m with the given
  21. // key.
  22. func Verify(mac *[16]byte, m []byte, key *[32]byte) bool {
  23. var tmp [16]byte
  24. Sum(&tmp, m, key)
  25. return subtle.ConstantTimeCompare(tmp[:], mac[:]) == 1
  26. }