// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package ssh

// Message authentication support

import (
	
	
	
	
	
	
	
)

type macMode struct {
	keySize int
	etm     bool
	new     func(key []byte) hash.Hash
}

// truncatingMAC wraps around a hash.Hash and truncates the output digest to
// a given size.
type truncatingMAC struct {
	length int
	hmac   hash.Hash
}

func ( truncatingMAC) ( []byte) (int, error) {
	return .hmac.Write()
}

func ( truncatingMAC) ( []byte) []byte {
	 := .hmac.Sum()
	return [:len()+.length]
}

func ( truncatingMAC) () {
	.hmac.Reset()
}

func ( truncatingMAC) () int {
	return .length
}

func ( truncatingMAC) () int { return .hmac.BlockSize() }

// macModes defines the supported MACs. MACs not included are not supported
// and will not be negotiated, even if explicitly configured. When FIPS mode is
// enabled, only FIPS-approved algorithms are included.
var macModes = map[string]*macMode{}

func init() {
	macModes[HMACSHA512ETM] = &macMode{64, true, func( []byte) hash.Hash {
		return hmac.New(sha512.New, )
	}}
	macModes[HMACSHA256ETM] = &macMode{32, true, func( []byte) hash.Hash {
		return hmac.New(sha256.New, )
	}}
	macModes[HMACSHA512] = &macMode{64, false, func( []byte) hash.Hash {
		return hmac.New(sha512.New, )
	}}
	macModes[HMACSHA256] = &macMode{32, false, func( []byte) hash.Hash {
		return hmac.New(sha256.New, )
	}}

	if fips140.Enabled() {
		defaultMACs = slices.DeleteFunc(defaultMACs, func( string) bool {
			,  := macModes[]
			return !
		})
		return
	}

	macModes[HMACSHA1] = &macMode{20, false, func( []byte) hash.Hash {
		return hmac.New(sha1.New, )
	}}
	macModes[InsecureHMACSHA196] = &macMode{20, false, func( []byte) hash.Hash {
		return truncatingMAC{12, hmac.New(sha1.New, )}
	}}
}