// 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() }

var macModes = map[string]*macMode{
	"hmac-sha2-512-etm@openssh.com": {64, true, func( []byte) hash.Hash {
		return hmac.New(sha512.New, )
	}},
	"hmac-sha2-256-etm@openssh.com": {32, true, func( []byte) hash.Hash {
		return hmac.New(sha256.New, )
	}},
	"hmac-sha2-512": {64, false, func( []byte) hash.Hash {
		return hmac.New(sha512.New, )
	}},
	"hmac-sha2-256": {32, false, func( []byte) hash.Hash {
		return hmac.New(sha256.New, )
	}},
	"hmac-sha1": {20, false, func( []byte) hash.Hash {
		return hmac.New(sha1.New, )
	}},
	"hmac-sha1-96": {20, false, func( []byte) hash.Hash {
		return truncatingMAC{12, hmac.New(sha1.New, )}
	}},
}