...
Source file src/pkg/vendor/golang.org/x/crypto/poly1305/sum_amd64.go
1
2
3
4
5
6
7 package poly1305
8
9
10 func initialize(state *[7]uint64, key *[32]byte)
11
12
13 func update(state *[7]uint64, msg []byte)
14
15
16 func finalize(tag *[TagSize]byte, state *[7]uint64)
17
18
19
20
21 func Sum(out *[16]byte, m []byte, key *[32]byte) {
22 h := newMAC(key)
23 h.Write(m)
24 h.Sum(out)
25 }
26
27 func newMAC(key *[32]byte) (h mac) {
28 initialize(&h.state, key)
29 return
30 }
31
32 type mac struct {
33 state [7]uint64
34
35 buffer [TagSize]byte
36 offset int
37 }
38
39 func (h *mac) Write(p []byte) (n int, err error) {
40 n = len(p)
41 if h.offset > 0 {
42 remaining := TagSize - h.offset
43 if n < remaining {
44 h.offset += copy(h.buffer[h.offset:], p)
45 return n, nil
46 }
47 copy(h.buffer[h.offset:], p[:remaining])
48 p = p[remaining:]
49 h.offset = 0
50 update(&h.state, h.buffer[:])
51 }
52 if nn := len(p) - (len(p) % TagSize); nn > 0 {
53 update(&h.state, p[:nn])
54 p = p[nn:]
55 }
56 if len(p) > 0 {
57 h.offset += copy(h.buffer[h.offset:], p)
58 }
59 return n, nil
60 }
61
62 func (h *mac) Sum(out *[16]byte) {
63 state := h.state
64 if h.offset > 0 {
65 update(&state, h.buffer[:h.offset])
66 }
67 finalize(out, &state)
68 }
69
View as plain text