1 // Copyright 2012 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
7 // Message authentication support
19 new func(key []byte) hash.Hash
22 // truncatingMAC wraps around a hash.Hash and truncates the output digest to
24 type truncatingMAC struct {
29 func (t truncatingMAC) Write(data []byte) (int, error) {
30 return t.hmac.Write(data)
33 func (t truncatingMAC) Sum(in []byte) []byte {
35 return out[:len(in)+t.length]
38 func (t truncatingMAC) Reset() {
42 func (t truncatingMAC) Size() int {
46 func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() }
48 var macModes = map[string]*macMode{
49 "hmac-sha2-256-etm@openssh.com": {32, true, func(key []byte) hash.Hash {
50 return hmac.New(sha256.New, key)
52 "hmac-sha2-256": {32, false, func(key []byte) hash.Hash {
53 return hmac.New(sha256.New, key)
55 "hmac-sha1": {20, false, func(key []byte) hash.Hash {
56 return hmac.New(sha1.New, key)
58 "hmac-sha1-96": {20, false, func(key []byte) hash.Hash {
59 return truncatingMAC{12, hmac.New(sha1.New, key)}