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 RegisterDecoder(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 Opt
Constants ¶
const ( // EncodingFormat is the format of the encoded digest. EncodingFormat = "$%s$ln=%d,r=%d,p=%d$%s$%s" // AlgName is the name for this algorithm. AlgName = "scrypt" // 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 ( // KeyLengthMax is the maximum key size accepted. KeyLengthMax = math.MaxUint32 * 32 )
Variables ¶
This section is empty.
Functions ¶
func RegisterDecoder ¶
func RegisterDecoder(r algorithm.DecoderRegister) (err error)
RegisterDecoder the 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 (*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 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.