mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-01 12:13:35 -04:00
28 lines
494 B
Go
28 lines
494 B
Go
package hmac
|
|
|
|
import (
|
|
"crypto/hmac"
|
|
"crypto/md5"
|
|
)
|
|
|
|
type (
|
|
HMACKey [32]byte
|
|
HMACDigest [16]byte
|
|
)
|
|
|
|
// I2PHMAC computes HMAC-MD5 using the provided key and data
|
|
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)
|
|
|
|
// Copy to our fixed-size return type
|
|
copy(d[:], digest)
|
|
return
|
|
}
|