You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
499 B

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)
}