go-spectre/site_key.go

21 lines
499 B
Go

package spectre
import (
"crypto/hmac"
"crypto/sha256"
)
func siteKey(userKey []byte, scoper Scoper, siteName string, counter int, scope Scope) []byte {
nameBytes := []byte(siteName)
scopeBytes := []byte(scoper.Scope(scope))
nameBytesLen := len(nameBytes)
keySalt := append(scopeBytes, bigEndian(nameBytesLen)...)
keySalt = append(keySalt, nameBytes...)
keySalt = append(keySalt, bigEndian(counter)...)
sign := hmac.New(sha256.New, userKey)
sign.Write(keySalt)
return sign.Sum(nil)
}