-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (47 loc) · 919 Bytes
/
main.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
57
package main
import (
"crypto"
"hash"
"log"
)
func main() {
log.SetFlags(log.LstdFlags | log.Lshortfile)
cryptoTest()
}
type localhash struct {
data []byte
hash []byte
}
func (h *localhash) Write(b []byte) (int, error) {
h.data = b
return len(b), nil
}
func (h *localhash) Sum(b []byte) []byte {
h.data = b
h.hash = b
return b
}
func (h *localhash) Reset() {
h.data = []byte{}
h.hash = []byte{}
}
func (h *localhash) Size() int {
return len(h.data)
}
func (h *localhash) BlockSize() int {
return len(h.hash)
}
func cryptoTest() {
for i := 1; i < 10; i++ { // 不能是0, 否则会报错 panic: crypto: requested hash function #0 is unavailable
var h = crypto.Hash(i)
if h.Available() {
log.Println(h.HashFunc(), h.New(), h.Size())
}
crypto.RegisterHash(h, func() hash.Hash {
return &localhash{}
})
if h.Available() {
log.Println(h.HashFunc(), h.New(), h.Size())
}
}
}