/
main.go
56 lines (43 loc) · 975 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
// This is an implemention for demonstration only.
package main
import (
"encoding/hex"
"fmt"
"hash"
"golang.org/x/crypto/sha3"
noiseHash "github.com/crypto-y/babble/hash"
)
type hashSha3 struct {
name string
h hash.Hash
}
func (s *hashSha3) BlockLen() int {
return s.New().BlockSize()
}
func (s *hashSha3) New() hash.Hash {
return sha3.New512()
}
func (s *hashSha3) HashLen() int {
return s.New().Size()
}
func (s *hashSha3) String() string {
return s.name
}
func newSha3() noiseHash.Hash {
return &hashSha3{
name: "SHA3",
h: sha3.New512(),
}
}
func main() {
// register SHA3
noiseHash.Register("SHA3", newSha3)
noiseSha3, _ := noiseHash.FromString("SHA3")
fmt.Println("sha3 block length: ", noiseSha3.BlockLen())
fmt.Println("sha3 hash length: ", noiseSha3.HashLen())
message := []byte("noise")
h := noiseSha3.New()
h.Write(message)
digest := h.Sum(nil)
fmt.Println("the output for 'noise' is: ", hex.EncodeToString(digest))
}