Documentation
¶
Overview ¶
Package scrypt provides helpful abstractions for an implementation of RFC7914 and implements github.com/go-crypt/crypt interfaces.
This implementation is loaded by crypt.NewDefaultDecoder and crypt.NewDecoderAll.
Index ¶
- Constants
- func Decode(encodedDigest string) (digest algorithm.Digest, err error)
- func DecodeVariant(v Variant) func(encodedDigest string) (digest algorithm.Digest, err error)
- func RegisterDecoder(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderScrypt(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderYescrypt(r algorithm.DecoderRegister) (err error)
- type Digest
- func (d *Digest) Encode() string
- func (d *Digest) Match(password string) (match bool)
- func (d *Digest) MatchAdvanced(password string) (match bool, err error)
- func (d *Digest) MatchBytes(passwordBytes []byte) (match bool)
- func (d *Digest) MatchBytesAdvanced(passwordBytes []byte) (match bool, err error)
- func (d *Digest) String() string
- type Hasher
- func (h *Hasher) Hash(password string) (digest algorithm.Digest, err error)
- func (h *Hasher) HashWithSalt(password string, salt []byte) (digest algorithm.Digest, err error)
- func (h *Hasher) MustHash(password string) (digest algorithm.Digest)
- func (h *Hasher) Validate() (err error)
- func (h *Hasher) WithOptions(opts ...Opt) (err error)
- type KeyFunc
- type Opt
- func WithBlockSize(r int) Opt
- func WithK(k int) Opt
- func WithKeyLength(k int) Opt
- func WithLN(ln int) Opt
- func WithP(p int) Opt
- func WithParallelism(p int) Opt
- func WithR(r int) Opt
- func WithS(s int) Opt
- func WithSaltLength(s int) Opt
- func WithVariant(variant Variant) Opt
- func WithVariantName(identifier string) Opt
- type Variant
Constants ¶
const ( // EncodingFmt is the format of the encoded digest. EncodingFmt = "$%s$ln=%d,r=%d,p=%d$%s$%s" // EncodingFmtYescrypt is the format of the encoded digest. EncodingFmtYescrypt = "$%s$%s$%s$%s" // AlgName is the name for this algorithm. AlgName = "scrypt" // AlgNameYescrypt is the name for this algorithm's yescrypt variant. AlgNameYescrypt = "yescrypt" // KeyLengthMin is the minimum key length accepted. KeyLengthMin = 1 // SaltLengthMin is the minimum salt length accepted. SaltLengthMin = 8 // SaltLengthMax is the maximum salt length accepted. SaltLengthMax = 1024 // IterationsMin is the minimum number of iterations accepted. IterationsMin = 1 // IterationsMax is the maximum number of iterations accepted. IterationsMax = 58 // IterationsDefault is the default number of iterations. IterationsDefault = 16 // BlockSizeMin is the minimum block size accepted. BlockSizeMin = 1 // BlockSizeMax is the maximum block size accepted. BlockSizeMax = math.MaxInt / 256 // BlockSizeDefault is the default block size. BlockSizeDefault = 8 // ParallelismMin is the minimum parallelism factor accepted. ParallelismMin = 1 // ParallelismMax is the maximum parallelism factor accepted. // // Equation is based on the following text from RFC: // // The parallelization parameter p // ("parallelizationParameter") is a positive integer less than or equal // to ((2^32-1) * 32) / (128 * r). // // When r has a minimum of 1, this makes the equation ((2^32-1) * 32) / 128. ParallelismMax = 1073741823 // ParallelismDefault is the default parallelism factor. ParallelismDefault = ParallelismMin )
const ( AlgIdentifier = AlgName AlgIdentifierYescrypt = "y" )
const ( // KeyLengthMax is the maximum key size accepted. KeyLengthMax = math.MaxUint32 * 32 )
Variables ¶
This section is empty.
Functions ¶
func DecodeVariant ¶ added in v0.4.0
DecodeVariant the encoded digest into a algorithm.Digest provided it matches the provided scrypt.Variant. If scrypt.VariantNone is used all variants can be decoded.
func RegisterDecoder ¶
func RegisterDecoder(r algorithm.DecoderRegister) (err error)
RegisterDecoder the decoder with the algorithm.DecoderRegister.
func RegisterDecoderScrypt ¶ added in v0.4.0
func RegisterDecoderScrypt(r algorithm.DecoderRegister) (err error)
RegisterDecoderScrypt the scrypt decoder with the algorithm.DecoderRegister.
func RegisterDecoderYescrypt ¶ added in v0.4.0
func RegisterDecoderYescrypt(r algorithm.DecoderRegister) (err error)
RegisterDecoderYescrypt the yescrypt decoder with the algorithm.DecoderRegister.
Types ¶
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is a scrypt.Digest which handles scrypt hashes.
func (*Digest) MatchAdvanced ¶
MatchAdvanced is the same as Match except if there is an error it returns that as well.
func (*Digest) MatchBytes ¶
MatchBytes returns true if the []byte passwordBytes matches the current scrypt.Digest.
func (*Digest) MatchBytesAdvanced ¶
MatchBytesAdvanced is the same as MatchBytes except if there is an error it returns that as well.
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher is a crypt.Hash for scrypt which can be initialized via New using a functional options pattern.
func NewYescrypt ¶ added in v0.4.0
func (*Hasher) HashWithSalt ¶
HashWithSalt overloads the Hash method allowing the user to provide a salt. It's recommended instead to configure the salt size and let this be a random value generated using crypto/rand.
func (*Hasher) MustHash ¶
MustHash overloads the Hash method and panics if the error is not nil. It's recommended if you use this option to utilize the Validate method first or handle the panic appropriately.
func (*Hasher) Validate ¶
Validate checks the settings/parameters for this Hash and returns an error.
func (*Hasher) WithOptions ¶
WithOptions defines the options for this scrypt.Hasher.
type KeyFunc ¶ added in v0.4.0
type KeyFunc func(password []byte, salt []byte, N int, r int, p int, keyLen int) (key []byte, err error)
KeyFunc represents the KeyFunc used by scrypt implementations.
type Opt ¶
Opt describes the functional option pattern for the scrypt.Hasher.
func WithK ¶
WithK adjusts the key length of the resulting scrypt.Digest. Minimum is 1, Maximum is 137438953440. Default is 32.
func WithLN ¶
WithLN sets the ln parameter (logN) of the resulting scrypt.Digest. Minimum is 1, Maximum is 58. Default is 16.
func WithP ¶
WithP sets the p parameter (parallelism factor) of the resulting scrypt.Digest. Minimum is 1, Maximum is 1073741823. Default is 1.
func WithR ¶
WithR sets the r parameter (block size) of the resulting scrypt.Digest. Minimum is 1, Maximum is math.MaxInt / 256. Default is 8.
func WithS ¶
WithS adjusts the salt length of the resulting scrypt.Digest. Minimum is 8, Maximum is 1024. Default is 16.
func WithVariant ¶ added in v0.4.0
WithVariant configures the scrypt.Variant of the resulting scrypt.Digest. Default is scrypt.VariantScrypt.
func WithVariantName ¶ added in v0.4.0
WithVariantName uses the variant name or identifier to configure the scrypt.Variant of the resulting scrypt.Digest. Default is scrypt.VariantScrypt.
type Variant ¶ added in v0.4.0
type Variant int
Variant is a variant of the scrypt.Digest.
func NewVariant ¶ added in v0.4.0
NewVariant converts an identifier string to a scrypt.Variant.