-
Notifications
You must be signed in to change notification settings - Fork 5
/
lsh512.go
63 lines (51 loc) · 1.73 KB
/
lsh512.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
58
59
60
61
62
63
// Package lsh512 implements the LSH-512, LSH-384, LSH-512-256, LSH-512-224 hash algorithms as defined in KS X 3262
package lsh512
import (
"hash"
)
var (
newContext func(size int) hash.Hash = newContextGo
sum func(size int, data []byte) [Size]byte = sumGo
)
const (
// The size of a LSH-512 checksum in bytes.
Size = 64
// The size of a LSH-384 checksum in bytes.
Size384 = 48
// The size of a LSH-512-256 checksum in bytes.
Size256 = 32
// The size of a LSH-512-224 checksum in bytes.
Size224 = 28
// The blocksize of LSH-512, LSH-384, LSH-512-256 and LSH-512-224 in bytes.
BlockSize = 256
)
// New returns a new hash.Hash computing the LSH-512 checksum.
func New() hash.Hash { return newContext(Size) }
// New384 returns a new hash.Hash computing the LSH-384 checksum.
func New384() hash.Hash { return newContext(Size384) }
// New256 returns a new hash.Hash computing the LSH-512-256 checksum.
func New256() hash.Hash { return newContext(Size256) }
// New224 returns a new hash.Hash computing the LSH-512-224 checksum.
func New224() hash.Hash { return newContext(Size224) }
// Sum512 returns the LSH-512 checksum of the data.
func Sum512(data []byte) (sum512 [Size]byte) {
return sum(Size, data)
}
// Sum384 returns the LSH-384 checksum of the data.
func Sum384(data []byte) (sum384 [Size384]byte) {
sum := sum(Size384, data)
copy(sum384[:], sum[:Size384])
return
}
// Sum256 returns the LSH-512-256 checksum of the data.
func Sum256(data []byte) (sum256 [Size256]byte) {
sum := sum(Size256, data)
copy(sum256[:], sum[:Size256])
return
}
// Sum224 returns the LSH-512-224 checksum of the data.
func Sum224(data []byte) (sum224 [Size224]byte) {
sum := sum(Size224, data)
copy(sum224[:], sum[:Size224])
return
}