cryptutil: use bytes for hmac (#2067)

This commit is contained in:
Caleb Doxsey 2021-04-07 14:57:24 -06:00 committed by GitHub
parent a935c1ba30
commit a51c7140ea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 28 additions and 28 deletions

View file

@ -20,15 +20,15 @@ var (
)
// GenerateHMAC produces a symmetric signature using a shared secret key.
func GenerateHMAC(data []byte, key string) []byte {
h := hmac.New(sha512.New512_256, []byte(key))
func GenerateHMAC(data, key []byte) []byte {
h := hmac.New(sha512.New512_256, key)
h.Write(data)
return h.Sum(nil)
}
// CheckHMAC securely checks the supplied MAC against a message using the
// shared secret key.
func CheckHMAC(data, suppliedMAC []byte, key string) bool {
func CheckHMAC(data, suppliedMAC, key []byte) bool {
expectedMAC := GenerateHMAC(data, key)
return hmac.Equal(expectedMAC, suppliedMAC)
}