package ssh
import (
"crypto/fips140"
"crypto/hmac"
"crypto/sha1"
"crypto/sha256"
"crypto/sha512"
"hash"
"slices"
)
type macMode struct {
keySize int
etm bool
new func (key []byte ) hash .Hash
}
type truncatingMAC struct {
length int
hmac hash .Hash
}
func (t truncatingMAC ) Write (data []byte ) (int , error ) {
return t .hmac .Write (data )
}
func (t truncatingMAC ) Sum (in []byte ) []byte {
out := t .hmac .Sum (in )
return out [:len (in )+t .length ]
}
func (t truncatingMAC ) Reset () {
t .hmac .Reset ()
}
func (t truncatingMAC ) Size () int {
return t .length
}
func (t truncatingMAC ) BlockSize () int { return t .hmac .BlockSize () }
var macModes = map [string ]*macMode {}
func init() {
macModes [HMACSHA512ETM ] = &macMode {64 , true , func (key []byte ) hash .Hash {
return hmac .New (sha512 .New , key )
}}
macModes [HMACSHA256ETM ] = &macMode {32 , true , func (key []byte ) hash .Hash {
return hmac .New (sha256 .New , key )
}}
macModes [HMACSHA512 ] = &macMode {64 , false , func (key []byte ) hash .Hash {
return hmac .New (sha512 .New , key )
}}
macModes [HMACSHA256 ] = &macMode {32 , false , func (key []byte ) hash .Hash {
return hmac .New (sha256 .New , key )
}}
if fips140 .Enabled () {
defaultMACs = slices .DeleteFunc (defaultMACs , func (algo string ) bool {
_ , ok := macModes [algo ]
return !ok
})
return
}
macModes [HMACSHA1 ] = &macMode {20 , false , func (key []byte ) hash .Hash {
return hmac .New (sha1 .New , key )
}}
macModes [InsecureHMACSHA196 ] = &macMode {20 , false , func (key []byte ) hash .Hash {
return truncatingMAC {12 , hmac .New (sha1 .New , key )}
}}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .