package hash import ( "crypto/rand" "crypto/subtle" "encoding/base64" "errors" "fmt" "golang.org/x/crypto/scrypt" ) // Version is the hashing format version const Version = 1 const hashFormat = "$%d:%x:%d:%d:%d:%s" // SCrypt contains all of the variables needed for scrypt hashing type SCrypt struct { N int R int P int KeyLen int SaltLen int } // NewSCrypt returns a scrypt hasher with recommended default values func NewSCrypt() Hasher { return SCrypt{ N: 15, R: 8, P: 1, KeyLen: 64, SaltLen: 8, } } // CreateHash will return a hashed version of the secretKey, or an error func (s SCrypt) CreateHash(secretKey string) (string, error) { salt := make([]byte, s.SaltLen) _, err := rand.Read(salt) if err != nil { return "", err } dk, err := scrypt.Key([]byte(secretKey), salt, 1<