go-bananas/internal/auth/hmac.go

21 lines
561 B
Go
Raw Normal View History

2026-10-07 15:11:35 +02:00
package auth
import (
"crypto/hmac"
"crypto/sha256"
)
// sha256HMAC computes an HMAC-SHA256 tag.
//
// It is a thin wrapper so that the session store and the OIDC state store
// cannot accidentally diverge on how they sign. The stdlib hmac package already
// performs a constant-time internal comparison; the constant-time requirement
// in this codebase is about how *we* compare the resulting tags.
func sha256HMAC(key, body []byte) [32]byte {
mac := hmac.New(sha256.New, key)
mac.Write(body)
var out [32]byte
copy(out[:], mac.Sum(nil))
return out
}