Skip to content

Commit 6889bbd

Browse files
committed
Add reference from hashtools to their labeled hash version
1 parent 9dffde4 commit 6889bbd

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

Diff for: hashtools/blake2.go

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
// Register BLAKE2 in Go's internal registry.
77
_ "golang.org/x/crypto/blake2b"
88
_ "golang.org/x/crypto/blake2s"
9+
10+
"github.com/safing/jess/lhash"
911
)
1012

1113
func init() {
@@ -21,26 +23,30 @@ func init() {
2123
BlockSize: crypto.BLAKE2s_256.New().BlockSize(),
2224
SecurityLevel: 128,
2325
Comment: "RFC 7693, successor of SHA3 finalist, optimized for 8-32 bit software",
26+
labeledAlg: lhash.BLAKE2s_256,
2427
}))
2528
Register(blake2bBase.With(&HashTool{
2629
Name: "BLAKE2b-256",
2730
Hash: crypto.BLAKE2b_256,
2831
DigestSize: crypto.BLAKE2b_256.Size(),
2932
BlockSize: crypto.BLAKE2b_256.New().BlockSize(),
3033
SecurityLevel: 128,
34+
labeledAlg: lhash.BLAKE2b_256,
3135
}))
3236
Register(blake2bBase.With(&HashTool{
3337
Name: "BLAKE2b-384",
3438
Hash: crypto.BLAKE2b_384,
3539
DigestSize: crypto.BLAKE2b_384.Size(),
3640
BlockSize: crypto.BLAKE2b_384.New().BlockSize(),
3741
SecurityLevel: 192,
42+
labeledAlg: lhash.BLAKE2b_384,
3843
}))
3944
Register(blake2bBase.With(&HashTool{
4045
Name: "BLAKE2b-512",
4146
Hash: crypto.BLAKE2b_512,
4247
DigestSize: crypto.BLAKE2b_512.Size(),
4348
BlockSize: crypto.BLAKE2b_512.New().BlockSize(),
4449
SecurityLevel: 256,
50+
labeledAlg: lhash.BLAKE2b_512,
4551
}))
4652
}

Diff for: hashtools/hashtool.go

+12
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package hashtools
33
import (
44
"crypto"
55
"hash"
6+
7+
"github.com/safing/jess/lhash"
68
)
79

810
// HashTool holds generic information about a hash tool.
@@ -16,6 +18,8 @@ type HashTool struct {
1618

1719
Comment string
1820
Author string
21+
22+
labeledAlg lhash.Algorithm
1923
}
2024

2125
// New returns a new hash.Hash instance of the hash tool.
@@ -46,6 +50,14 @@ func (ht *HashTool) With(changes *HashTool) *HashTool {
4650
if changes.Author == "" {
4751
changes.Author = ht.Author
4852
}
53+
if changes.labeledAlg == 0 {
54+
changes.labeledAlg = ht.labeledAlg
55+
}
4956

5057
return changes
5158
}
59+
60+
// LabeledHasher returns the corresponding labeled hashing algorithm.
61+
func (ht *HashTool) LabeledHasher() lhash.Algorithm {
62+
return ht.labeledAlg
63+
}

Diff for: hashtools/sha.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ package hashtools
22

33
import (
44
"crypto"
5-
65
// Register SHA2 in Go's internal registry.
76
_ "crypto/sha256"
87
_ "crypto/sha512"
98

109
// Register SHA3 in Go's internal registry.
1110
_ "golang.org/x/crypto/sha3"
11+
12+
"github.com/safing/jess/lhash"
1213
)
1314

1415
func init() {
@@ -24,41 +25,47 @@ func init() {
2425
BlockSize: crypto.SHA224.New().BlockSize(),
2526
SecurityLevel: 112,
2627
Author: "NSA, 2004",
28+
labeledAlg: lhash.SHA2_224,
2729
}))
2830
Register(sha2Base.With(&HashTool{
2931
Name: "SHA2-256",
3032
Hash: crypto.SHA256,
3133
DigestSize: crypto.SHA256.Size(),
3234
BlockSize: crypto.SHA256.New().BlockSize(),
3335
SecurityLevel: 128,
36+
labeledAlg: lhash.SHA2_256,
3437
}))
3538
Register(sha2Base.With(&HashTool{
3639
Name: "SHA2-384",
3740
Hash: crypto.SHA384,
3841
DigestSize: crypto.SHA384.Size(),
3942
BlockSize: crypto.SHA384.New().BlockSize(),
4043
SecurityLevel: 192,
44+
labeledAlg: lhash.SHA2_384,
4145
}))
4246
Register(sha2Base.With(&HashTool{
4347
Name: "SHA2-512",
4448
Hash: crypto.SHA512,
4549
DigestSize: crypto.SHA512.Size(),
4650
BlockSize: crypto.SHA512.New().BlockSize(),
4751
SecurityLevel: 256,
52+
labeledAlg: lhash.SHA2_512,
4853
}))
4954
Register(sha2Base.With(&HashTool{
5055
Name: "SHA2-512-224",
5156
Hash: crypto.SHA512_224,
5257
DigestSize: crypto.SHA512_224.Size(),
5358
BlockSize: crypto.SHA512_224.New().BlockSize(),
5459
SecurityLevel: 112,
60+
labeledAlg: lhash.SHA2_512_224,
5561
}))
5662
Register(sha2Base.With(&HashTool{
5763
Name: "SHA2-512-256",
5864
Hash: crypto.SHA512_256,
5965
DigestSize: crypto.SHA512_256.Size(),
6066
BlockSize: crypto.SHA512_256.New().BlockSize(),
6167
SecurityLevel: 128,
68+
labeledAlg: lhash.SHA2_512_256,
6269
}))
6370

6471
// SHA3
@@ -72,26 +79,30 @@ func init() {
7279
DigestSize: crypto.SHA3_224.Size(),
7380
BlockSize: crypto.SHA3_224.New().BlockSize(),
7481
SecurityLevel: 112,
82+
labeledAlg: lhash.SHA3_224,
7583
}))
7684
Register(sha3Base.With(&HashTool{
7785
Name: "SHA3-256",
7886
Hash: crypto.SHA3_256,
7987
DigestSize: crypto.SHA3_256.Size(),
8088
BlockSize: crypto.SHA3_256.New().BlockSize(),
8189
SecurityLevel: 128,
90+
labeledAlg: lhash.SHA3_256,
8291
}))
8392
Register(sha3Base.With(&HashTool{
8493
Name: "SHA3-384",
8594
Hash: crypto.SHA3_384,
8695
DigestSize: crypto.SHA3_384.Size(),
8796
BlockSize: crypto.SHA3_384.New().BlockSize(),
8897
SecurityLevel: 192,
98+
labeledAlg: lhash.SHA3_384,
8999
}))
90100
Register(sha3Base.With(&HashTool{
91101
Name: "SHA3-512",
92102
Hash: crypto.SHA3_512,
93103
DigestSize: crypto.SHA3_512.Size(),
94104
BlockSize: crypto.SHA3_512.New().BlockSize(),
95105
SecurityLevel: 256,
106+
labeledAlg: lhash.SHA3_512,
96107
}))
97108
}

0 commit comments

Comments
 (0)