Involved Source Filesbits_go1.13.go
Package poly1305 implements Poly1305 one-time message authentication code as
specified in https://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.
sum_amd64.gosum_generic.gosum_amd64.s
Package-Level Type Names (total 5, in which 1 are exported)
/* sort exporteds by: | */
MAC is an io.Writer computing an authentication tag
of the data written to it.
MAC cannot be used like common hash.Hash implementations,
because using a poly1305 key twice breaks its security.
Therefore writing data to a running MAC after calling
Sum or Verify causes it to panic.
finalizedbool
// platform-dependent implementation
mac.macGenericmacGenericmac.macGeneric.buffer[16]bytemac.macGeneric.macStatemacState
h is the main accumulator. It is to be interpreted modulo 2¹³⁰ - 5, but
can grow larger during and after rounds. It must, however, remain below
2 * (2¹³⁰ - 5).
r and s are the private key components.
mac.macGeneric.macState.s[2]uint64mac.macGeneric.offsetint
Size returns the number of bytes Sum will return.
Sum computes the authenticator of all data written to the
message authentication code.
Verify returns whether the authenticator of all data written to
the message authentication code matches the expected value.
Write adds more data to the running message authentication code.
It never returns an error.
It must not be called after the first call of Sum or Verify.
*T : io.Writer
func New(key *[32]byte) *MAC
func vendor/golang.org/x/crypto/chacha20poly1305.writeUint64(p *MAC, n int)
func vendor/golang.org/x/crypto/chacha20poly1305.writeWithPadding(p *MAC, b []byte)
mac is a wrapper for macGeneric that redirects calls that would have gone to
updateGeneric to update.
Its Write and Sum methods are otherwise identical to the macGeneric ones, but
using function pointers would carry a major performance cost.
macGenericmacGenericmacGeneric.buffer[16]bytemacGeneric.macStatemacState
h is the main accumulator. It is to be interpreted modulo 2¹³⁰ - 5, but
can grow larger during and after rounds. It must, however, remain below
2 * (2¹³⁰ - 5).
r and s are the private key components.
macGeneric.macState.s[2]uint64macGeneric.offsetint(*T) Sum(out *[16]byte)(*T) Write(p []byte) (int, error)
*T : io.Writer
buffer[16]bytemacStatemacState
h is the main accumulator. It is to be interpreted modulo 2¹³⁰ - 5, but
can grow larger during and after rounds. It must, however, remain below
2 * (2¹³⁰ - 5).
r and s are the private key components.
macState.s[2]uint64offsetint
Sum flushes the last incomplete chunk from the buffer, if any, and generates
the MAC output. It does not modify its state, in order to allow for multiple
calls to Sum, even if no Write is allowed after Sum.
Write splits the incoming message into TagSize chunks, and passes them to
update. It buffers incomplete chunks.
*T : io.Writer
func newMACGeneric(key *[32]byte) macGeneric
macState holds numbers in saturated 64-bit little-endian limbs. That is,
the value of [x0, x1, x2] is x[0] + x[1] * 2⁶⁴ + x[2] * 2¹²⁸.
h is the main accumulator. It is to be interpreted modulo 2¹³⁰ - 5, but
can grow larger during and after rounds. It must, however, remain below
2 * (2¹³⁰ - 5).
r and s are the private key components.
s[2]uint64
func initialize(key *[32]byte, m *macState)
func update(state *macState, msg []byte)
func updateGeneric(state *macState, msg []byte)
uint128 holds a 128-bit number as two 64-bit limbs, for use with the
bits.Mul64 and bits.Add64 intrinsics.
hiuint64louint64
func add128(a, b uint128) uint128
func mul64(a, b uint64) uint128
func shiftRightBy2(a uint128) uint128
func add128(a, b uint128) uint128
func shiftRightBy2(a uint128) uint128
Package-Level Functions (total 16, in which 3 are exported)
New returns a new MAC computing an authentication
tag of all data written to it with the given key.
This allows writing the message progressively instead
of passing it as a single slice. Common users should use
the Sum function instead.
The key must be unique for each message, as authenticating
two different messages with the same key allows an attacker
to forge messages at will.
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.
Verify returns true if mac is a valid authenticator for m with the given key.
updateGeneric absorbs msg into the state.h accumulator. For each chunk m of
128 bits of message, it computes
h₊ = (h + m) * r mod 2¹³⁰ - 5
If the msg length is not a multiple of TagSize, it assumes the last
incomplete chunk is the final one.
Package-Level Constants (total 8, in which 1 are exported)
TagSize is the size, in bytes, of a poly1305 authenticator.
[rMask0, rMask1] is the specified Poly1305 clamping mask in little-endian. It
clears some bits of the secret coefficient to make it possible to implement
multiplication more efficiently.
[rMask0, rMask1] is the specified Poly1305 clamping mask in little-endian. It
clears some bits of the secret coefficient to make it possible to implement
multiplication more efficiently.
The pages are generated with Goldsv0.4.2. (GOOS=darwin GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds.