github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/builder/azure/pkcs12/mac.go (about) 1 package pkcs12 2 3 import ( 4 "crypto/hmac" 5 "crypto/sha1" 6 "crypto/x509/pkix" 7 "encoding/asn1" 8 ) 9 10 var ( 11 oidSha1Algorithm = asn1.ObjectIdentifier{1, 3, 14, 3, 2, 26} 12 ) 13 14 type macData struct { 15 Mac digestInfo 16 MacSalt []byte 17 Iterations int `asn1:"optional,default:1"` 18 } 19 20 // from PKCS#7: 21 type digestInfo struct { 22 Algorithm pkix.AlgorithmIdentifier 23 Digest []byte 24 } 25 26 func computeMac(message []byte, iterations int, salt, password []byte) []byte { 27 key := pbkdf(sha1Sum, 20, 64, salt, password, iterations, 3, 20) 28 29 mac := hmac.New(sha1.New, key) 30 mac.Write(message) 31 32 return mac.Sum(nil) 33 }