Files
go-i2p/lib/crypto/hmac/hmac.go

28 lines
494 B
Go
Raw Permalink Normal View History

package hmac
2016-01-28 10:16:26 -05:00
import (
"crypto/hmac"
2016-01-29 07:22:31 -05:00
"crypto/md5"
2016-01-28 10:16:26 -05:00
)
type (
HMACKey [32]byte
HMACDigest [16]byte
)
2016-01-28 10:16:26 -05:00
// I2PHMAC computes HMAC-MD5 using the provided key and data
2016-01-28 10:16:26 -05:00
func I2PHMAC(data []byte, k HMACKey) (d HMACDigest) {
// Create a new HMAC instance using MD5 hash and our key
mac := hmac.New(md5.New, k[:])
// Write data to HMAC
mac.Write(data)
// Calculate the HMAC and extract the digest
digest := mac.Sum(nil)
2016-01-29 07:22:31 -05:00
// Copy to our fixed-size return type
copy(d[:], digest)
2016-01-29 07:22:31 -05:00
return
2016-01-28 10:16:26 -05:00
}