1
2
3
4
5
6
7 package poly1305
8
9 import (
10 "golang.org/x/sys/cpu"
11 )
12
13
14
15
16
17
18 func updateVX(state *macState, msg []byte)
19
20
21
22
23
24
25
26
27 type mac struct {
28 macState
29
30 buffer [16 * TagSize]byte
31 offset int
32 }
33
34 func (h *mac) Write(p []byte) (int, error) {
35 nn := len(p)
36 if h.offset > 0 {
37 n := copy(h.buffer[h.offset:], p)
38 if h.offset+n < len(h.buffer) {
39 h.offset += n
40 return nn, nil
41 }
42 p = p[n:]
43 h.offset = 0
44 if cpu.S390X.HasVX {
45 updateVX(&h.macState, h.buffer[:])
46 } else {
47 updateGeneric(&h.macState, h.buffer[:])
48 }
49 }
50
51 tail := len(p) % len(h.buffer)
52 body := len(p) - tail
53 if body > 0 {
54 if cpu.S390X.HasVX {
55 updateVX(&h.macState, p[:body])
56 } else {
57 updateGeneric(&h.macState, p[:body])
58 }
59 }
60 h.offset = copy(h.buffer[:], p[body:])
61 return nn, nil
62 }
63
64 func (h *mac) Sum(out *[TagSize]byte) {
65 state := h.macState
66 remainder := h.buffer[:h.offset]
67
68
69
70 if cpu.S390X.HasVX && len(remainder) > 2*TagSize {
71 updateVX(&state, remainder)
72 } else if len(remainder) > 0 {
73 updateGeneric(&state, remainder)
74 }
75 finalize(out, &state.h, &state.s)
76 }
77
View as plain text