aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet/crypto/hash.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet/crypto/hash.go')
-rw-r--r--src/gnunet/crypto/hash.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/gnunet/crypto/hash.go b/src/gnunet/crypto/hash.go
index bc715d4..049a8ef 100644
--- a/src/gnunet/crypto/hash.go
+++ b/src/gnunet/crypto/hash.go
@@ -19,6 +19,7 @@
19package crypto 19package crypto
20 20
21import ( 21import (
22 "bytes"
22 "crypto/sha512" 23 "crypto/sha512"
23 24
24 "gnunet/util" 25 "gnunet/util"
@@ -29,11 +30,20 @@ type HashCode struct {
29 Bits []byte `size:"64"` 30 Bits []byte `size:"64"`
30} 31}
31 32
32// NewHashCode creates a new, uninitalized hash value 33// Equals tests if two hash results are equal.
33func NewHashCode() *HashCode { 34func (hc *HashCode) Equals(n *HashCode) bool {
34 return &HashCode{ 35 return bytes.Equal(hc.Bits, n.Bits)
36}
37
38// NewHashCode creates a new (initalized) hash value
39func NewHashCode(buf []byte) *HashCode {
40 hc := &HashCode{
35 Bits: make([]byte, 64), 41 Bits: make([]byte, 64),
36 } 42 }
43 if buf != nil {
44 util.CopyAlignedBlock(hc.Bits, buf)
45 }
46 return hc
37} 47}
38 48
39// Hash returns the SHA-512 hash value of a given blob 49// Hash returns the SHA-512 hash value of a given blob