32 lines
633 B
Go
32 lines
633 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,
|
||
|
byte(nameBytesLen>>24),
|
||
|
byte(nameBytesLen>>16),
|
||
|
byte(nameBytesLen>>8),
|
||
|
byte(nameBytesLen),
|
||
|
)
|
||
|
keySalt = append(keySalt, nameBytes...)
|
||
|
keySalt = append(keySalt,
|
||
|
byte(counter>>24),
|
||
|
byte(counter>>16),
|
||
|
byte(counter>>8),
|
||
|
byte(counter),
|
||
|
)
|
||
|
|
||
|
sign := hmac.New(sha256.New, userKey)
|
||
|
sign.Write(keySalt)
|
||
|
|
||
|
return sign.Sum(nil)
|
||
|
}
|