-
Notifications
You must be signed in to change notification settings - Fork 3
/
sha.go
34 lines (29 loc) · 918 Bytes
/
sha.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
// Copyright (c) 2015 Mute Communications Ltd.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package cipher
import (
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
)
// SHA1 computes the SHA1 hash of the given buffer.
// In Mute SHA1 is only used for tokens.
func SHA1(buffer []byte) []byte {
hash := sha1.Sum(buffer)
return hash[:]
}
// SHA256 computes the SHA256 hash of the given buffer.
// In Mute SHA256 is only used for hash chain operations.
func SHA256(buffer []byte) []byte {
hash := sha256.Sum256(buffer)
return hash[:]
}
// SHA512 computes the SHA512 hash of the given buffer.
// In Mute SHA512 is used for everything except tokens and hash chain
// operations. For example, key material is hashed with SHA512 and message
// authentication uses SHA512.
func SHA512(buffer []byte) []byte {
hash := sha512.Sum512(buffer)
return hash[:]
}