github.com/technosophos/deis@v1.7.1-0.20150915173815-f9005256004b/Godeps/_workspace/src/golang.org/x/crypto/ssh/mac.go (about) 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. 4 5 package ssh 6 7 // Message authentication support 8 9 import ( 10 "crypto/hmac" 11 "crypto/sha1" 12 "hash" 13 ) 14 15 type macMode struct { 16 keySize int 17 new func(key []byte) hash.Hash 18 } 19 20 // truncatingMAC wraps around a hash.Hash and truncates the output digest to 21 // a given size. 22 type truncatingMAC struct { 23 length int 24 hmac hash.Hash 25 } 26 27 func (t truncatingMAC) Write(data []byte) (int, error) { 28 return t.hmac.Write(data) 29 } 30 31 func (t truncatingMAC) Sum(in []byte) []byte { 32 out := t.hmac.Sum(in) 33 return out[:len(in)+t.length] 34 } 35 36 func (t truncatingMAC) Reset() { 37 t.hmac.Reset() 38 } 39 40 func (t truncatingMAC) Size() int { 41 return t.length 42 } 43 44 func (t truncatingMAC) BlockSize() int { return t.hmac.BlockSize() } 45 46 var macModes = map[string]*macMode{ 47 "hmac-sha1": {20, func(key []byte) hash.Hash { 48 return hmac.New(sha1.New, key) 49 }}, 50 "hmac-sha1-96": {20, func(key []byte) hash.Hash { 51 return truncatingMAC{12, hmac.New(sha1.New, key)} 52 }}, 53 }