-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add indentityHash for algos that don't need hashing (#1340)
This adds hash.go and creates a identityHash that is used for algorithms that do their own hashing (ED25519) for instance. This unifies the hash variable naming between dnssec and sig(0) signing and removes the special casing that existed for ED25519. This unifies the variable naming between sig(0) and dnssec signing and verifying. I didn't want to used crypto.RegisterHash as not to fiddle with the global namespaces of hashes, so the value of '0' from AlgorithmsToHash is handled specially in dnssec and sig(0) code. Note that ED448 isn't implemented at all. Signed-off-by: Miek Gieben <[email protected]>
- Loading branch information
Showing
4 changed files
with
78 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package dns | ||
|
||
import ( | ||
"bytes" | ||
"crypto" | ||
"hash" | ||
) | ||
|
||
// identityHash will not hash, it only buffers the data written into it and returns it as-is. | ||
type identityHash struct { | ||
b *bytes.Buffer | ||
} | ||
|
||
// Implement the hash.Hash interface. | ||
|
||
func (i identityHash) Write(b []byte) (int, error) { return i.b.Write(b) } | ||
func (i identityHash) Size() int { return i.b.Len() } | ||
func (i identityHash) BlockSize() int { return 1024 } | ||
func (i identityHash) Reset() { i.b.Reset() } | ||
func (i identityHash) Sum(b []byte) []byte { return append(b, i.b.Bytes()...) } | ||
|
||
func hashFromAlgorithm(alg uint8) (hash.Hash, crypto.Hash, error) { | ||
hashnumber, ok := AlgorithmToHash[alg] | ||
if !ok { | ||
return nil, 0, ErrAlg | ||
} | ||
if hashnumber == 0 { | ||
return identityHash{b: &bytes.Buffer{}}, hashnumber, nil | ||
} | ||
return hashnumber.New(), hashnumber, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters