2025-03-25 19:08:47 -04:00
|
|
|
package hmac
|
2016-01-28 10:16:26 -05:00
|
|
|
|
|
|
|
import (
|
2025-03-27 21:56:23 -04:00
|
|
|
"crypto/hmac"
|
2016-01-29 07:22:31 -05:00
|
|
|
"crypto/md5"
|
2016-01-28 10:16:26 -05:00
|
|
|
)
|
|
|
|
|
2024-08-25 23:22:21 -04:00
|
|
|
type (
|
|
|
|
HMACKey [32]byte
|
|
|
|
HMACDigest [16]byte
|
|
|
|
)
|
2016-01-28 10:16:26 -05:00
|
|
|
|
2025-03-27 21:56:23 -04: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) {
|
2025-03-27 21:56:23 -04:00
|
|
|
// 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
|
|
|
|
2025-03-27 21:56:23 -04: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
|
|
|
}
|