-
Notifications
You must be signed in to change notification settings - Fork 1
/
hash-builtin.go
56 lines (51 loc) · 1.11 KB
/
hash-builtin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Copyright © 2014, 2015, 2016 Lawrence E. Bakst. All rights reserved.
// +build !noaes
package cuckoo
import (
"errors"
"hash"
"leb.io/aeshash"
"leb.io/cuckoo/internal/jenkins264"
"leb.io/cuckoo/internal/jenkins3"
)
// Set hash function used
func (c *Cuckoo) setHash(hashName string) (int, error) {
switch hashName {
case "":
fallthrough
case "aes":
c.hf64 = aeshash.Hash64
c.hf32 = aeshash.Hash32
c.hfb = aeshash.Hash
c.hf = aeshash.NewAES(0)
return aes, nil
case "j364":
c.hf64 = nil
c.hf32 = nil
c.hfb = jenkins3.HashBytes
c.hf = jenkins3.New(uint32(0))
return j364, nil
case "j264":
c.hf64 = nil
c.hf32 = nil
c.hfb = jenkins264.Hash
return j264, nil
default:
// fallthrough generated bad error messaage Go bug
}
return 0, errors.New("cuckoo: invalid hash name")
}
// Get a hash function with a specific seed
func (c *Cuckoo) getHash(hashName string, seed uint64) hash.Hash64 {
switch hashName {
case "":
fallthrough
case "aes":
return aeshash.NewAES(seed)
case "j264":
return jenkins264.New(seed)
case "j364":
return jenkins3.New(uint32(seed))
}
panic("getHash")
}