Debian Codegraph @

siphash/sum_amd64.go

raw symbols SCIP
1 // Use of this source code is governed by a license
2 // that can be found in the LICENSE file.
3
4 // +build amd64, !cgo, !appengine
5
6 package siphash
7
8 import (
9 "hash"
10 "unsafe"
11 )
12
13 // New returns a hash.Hash64 computing the SipHash checksum with a 128 bit key.
14 func New(key *[16]byte) hash.Hash64 {
15 h := new(hashFunc)
16 h.key[0] = *(*uint64)(unsafe.Pointer(&key[0]))
17 h.key[1] = *(*uint64)(unsafe.Pointer(&key[8]))
18 h.Reset()
19 return h
20 }
21
22 // Sum generates an authenticator for msg with a 128 bit key
23 // and puts the 64 bit result into out.
24 func Sum(out *[TagSize]byte, msg []byte, key *[16]byte) {
25 (*[1]uint64)(unsafe.Pointer(&out[0]))[0] = Sum64(msg, key)
26 }
27
28 // Sum64 generates and returns the 64 bit authenticator
29 // for msg with a 128 bit key.
30 func Sum64(msg []byte, key *[16]byte) uint64 {
31 k0 := *(*uint64)(unsafe.Pointer(&key[0]))
32 k1 := *(*uint64)(unsafe.Pointer(&key[8]))
33
34 var hVal [4]uint64
35 hVal[0] = k0 ^ c0
36 hVal[1] = k1 ^ c1
37 hVal[2] = k0 ^ c2
38 hVal[3] = k1 ^ c3
39
40 n := len(msg)
41 ctr := byte(n)
42
43 if n >= TagSize {
44 n &= (^(TagSize - 1))
45 core(&hVal, msg[:n])
46 msg = msg[n:]
47 }
48
49 var block [TagSize]byte
50 for i, v := range msg {
51 block[i] = v
52 }
53 block[7] = ctr
54
55 return finalize(&hVal, &block)
56 }