From 6889bbd62e8c015d9966fb347fd3d45187f77092 Mon Sep 17 00:00:00 2001 From: Daniel <dhaavi@users.noreply.github.com> Date: Fri, 8 Jul 2022 22:31:52 +0200 Subject: [PATCH] Add reference from hashtools to their labeled hash version --- hashtools/blake2.go | 6 ++++++ hashtools/hashtool.go | 12 ++++++++++++ hashtools/sha.go | 13 ++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/hashtools/blake2.go b/hashtools/blake2.go index ad4b876..a2262cd 100644 --- a/hashtools/blake2.go +++ b/hashtools/blake2.go @@ -6,6 +6,8 @@ import ( // Register BLAKE2 in Go's internal registry. _ "golang.org/x/crypto/blake2b" _ "golang.org/x/crypto/blake2s" + + "github.com/safing/jess/lhash" ) func init() { @@ -21,6 +23,7 @@ func init() { BlockSize: crypto.BLAKE2s_256.New().BlockSize(), SecurityLevel: 128, Comment: "RFC 7693, successor of SHA3 finalist, optimized for 8-32 bit software", + labeledAlg: lhash.BLAKE2s_256, })) Register(blake2bBase.With(&HashTool{ Name: "BLAKE2b-256", @@ -28,6 +31,7 @@ func init() { DigestSize: crypto.BLAKE2b_256.Size(), BlockSize: crypto.BLAKE2b_256.New().BlockSize(), SecurityLevel: 128, + labeledAlg: lhash.BLAKE2b_256, })) Register(blake2bBase.With(&HashTool{ Name: "BLAKE2b-384", @@ -35,6 +39,7 @@ func init() { DigestSize: crypto.BLAKE2b_384.Size(), BlockSize: crypto.BLAKE2b_384.New().BlockSize(), SecurityLevel: 192, + labeledAlg: lhash.BLAKE2b_384, })) Register(blake2bBase.With(&HashTool{ Name: "BLAKE2b-512", @@ -42,5 +47,6 @@ func init() { DigestSize: crypto.BLAKE2b_512.Size(), BlockSize: crypto.BLAKE2b_512.New().BlockSize(), SecurityLevel: 256, + labeledAlg: lhash.BLAKE2b_512, })) } diff --git a/hashtools/hashtool.go b/hashtools/hashtool.go index 664442c..a86fff2 100644 --- a/hashtools/hashtool.go +++ b/hashtools/hashtool.go @@ -3,6 +3,8 @@ package hashtools import ( "crypto" "hash" + + "github.com/safing/jess/lhash" ) // HashTool holds generic information about a hash tool. @@ -16,6 +18,8 @@ type HashTool struct { Comment string Author string + + labeledAlg lhash.Algorithm } // New returns a new hash.Hash instance of the hash tool. @@ -46,6 +50,14 @@ func (ht *HashTool) With(changes *HashTool) *HashTool { if changes.Author == "" { changes.Author = ht.Author } + if changes.labeledAlg == 0 { + changes.labeledAlg = ht.labeledAlg + } return changes } + +// LabeledHasher returns the corresponding labeled hashing algorithm. +func (ht *HashTool) LabeledHasher() lhash.Algorithm { + return ht.labeledAlg +} diff --git a/hashtools/sha.go b/hashtools/sha.go index eb1e947..ea16311 100644 --- a/hashtools/sha.go +++ b/hashtools/sha.go @@ -2,13 +2,14 @@ package hashtools import ( "crypto" - // Register SHA2 in Go's internal registry. _ "crypto/sha256" _ "crypto/sha512" // Register SHA3 in Go's internal registry. _ "golang.org/x/crypto/sha3" + + "github.com/safing/jess/lhash" ) func init() { @@ -24,6 +25,7 @@ func init() { BlockSize: crypto.SHA224.New().BlockSize(), SecurityLevel: 112, Author: "NSA, 2004", + labeledAlg: lhash.SHA2_224, })) Register(sha2Base.With(&HashTool{ Name: "SHA2-256", @@ -31,6 +33,7 @@ func init() { DigestSize: crypto.SHA256.Size(), BlockSize: crypto.SHA256.New().BlockSize(), SecurityLevel: 128, + labeledAlg: lhash.SHA2_256, })) Register(sha2Base.With(&HashTool{ Name: "SHA2-384", @@ -38,6 +41,7 @@ func init() { DigestSize: crypto.SHA384.Size(), BlockSize: crypto.SHA384.New().BlockSize(), SecurityLevel: 192, + labeledAlg: lhash.SHA2_384, })) Register(sha2Base.With(&HashTool{ Name: "SHA2-512", @@ -45,6 +49,7 @@ func init() { DigestSize: crypto.SHA512.Size(), BlockSize: crypto.SHA512.New().BlockSize(), SecurityLevel: 256, + labeledAlg: lhash.SHA2_512, })) Register(sha2Base.With(&HashTool{ Name: "SHA2-512-224", @@ -52,6 +57,7 @@ func init() { DigestSize: crypto.SHA512_224.Size(), BlockSize: crypto.SHA512_224.New().BlockSize(), SecurityLevel: 112, + labeledAlg: lhash.SHA2_512_224, })) Register(sha2Base.With(&HashTool{ Name: "SHA2-512-256", @@ -59,6 +65,7 @@ func init() { DigestSize: crypto.SHA512_256.Size(), BlockSize: crypto.SHA512_256.New().BlockSize(), SecurityLevel: 128, + labeledAlg: lhash.SHA2_512_256, })) // SHA3 @@ -72,6 +79,7 @@ func init() { DigestSize: crypto.SHA3_224.Size(), BlockSize: crypto.SHA3_224.New().BlockSize(), SecurityLevel: 112, + labeledAlg: lhash.SHA3_224, })) Register(sha3Base.With(&HashTool{ Name: "SHA3-256", @@ -79,6 +87,7 @@ func init() { DigestSize: crypto.SHA3_256.Size(), BlockSize: crypto.SHA3_256.New().BlockSize(), SecurityLevel: 128, + labeledAlg: lhash.SHA3_256, })) Register(sha3Base.With(&HashTool{ Name: "SHA3-384", @@ -86,6 +95,7 @@ func init() { DigestSize: crypto.SHA3_384.Size(), BlockSize: crypto.SHA3_384.New().BlockSize(), SecurityLevel: 192, + labeledAlg: lhash.SHA3_384, })) Register(sha3Base.With(&HashTool{ Name: "SHA3-512", @@ -93,5 +103,6 @@ func init() { DigestSize: crypto.SHA3_512.Size(), BlockSize: crypto.SHA3_512.New().BlockSize(), SecurityLevel: 256, + labeledAlg: lhash.SHA3_512, })) }