yubihsm-go/authkey/authkey.go

34 lines
735 B
Go
Raw Normal View History

package authkey
2018-09-02 05:46:37 -07:00
import (
"crypto/sha256"
2018-09-02 05:46:37 -07:00
"golang.org/x/crypto/pbkdf2"
)
type (
// AuthKey is a key to authenticate with the HSM
AuthKey []byte
)
const (
authKeyLength = 32
authKeyIterations = 10000
yubicoSeed = "Yubico"
)
// NewFromPassword derives an AuthKey using pkdf2 as specified in the HSM documentation
func NewFromPassword(password string) AuthKey {
2018-09-02 05:46:37 -07:00
return pbkdf2.Key([]byte(password), []byte(yubicoSeed), authKeyIterations, authKeyLength, sha256.New)
}
// GetEncKey returns the EncryptionKey part of the AuthKey
func (k AuthKey) GetEncKey() []byte {
return k[:authKeyLength/2]
2018-09-02 05:46:37 -07:00
}
// GetMacKey returns the MACKey part of the AuthKey
2018-09-02 05:46:37 -07:00
func (k AuthKey) GetMacKey() []byte {
return k[authKeyLength/2:]
2018-09-02 05:46:37 -07:00
}