Documentation ¶
Overview ¶
Package argon2 provides helpful abstractions for an implementation of RFC9106 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 RegisterDecoderArgon2d(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderArgon2i(r algorithm.DecoderRegister) (err error)
- func RegisterDecoderArgon2id(r algorithm.DecoderRegister) (err error)
- type Digest
- func (d *Digest) Encode() (encodedHash 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) Clone() *Hasher
- func (h *Hasher) Copy(hasher *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) Merge(hash *Hasher)
- func (h *Hasher) MustHash(password string) (hashed algorithm.Digest)
- func (h *Hasher) Validate() (err error)
- func (h *Hasher) WithOptions(opts ...Opt) (err error)
- type Opt
- func WithIterations(t int) Opt
- func WithK(k int) Opt
- func WithKeyLength(k int) Opt
- func WithM(m uint32) Opt
- func WithMemoryInKiB(m uint32) Opt
- func WithP(p int) Opt
- func WithParallelism(p int) Opt
- func WithProfileRFC9106LowMemory() Opt
- func WithProfileRFC9106Recommended() Opt
- func WithS(s int) Opt
- func WithSaltLength(s int) Opt
- func WithT(t int) Opt
- func WithTagLength(k int) Opt
- func WithVariant(variant Variant) Opt
- func WithVariantD() Opt
- func WithVariantI() Opt
- func WithVariantID() Opt
- func WithVariantName(identifier string) Opt
- type Profile
- type Variant
Constants ¶
const ( // EncodingFmt is the encoding format for this algorithm. EncodingFmt = "$%s$v=%d$m=%d,t=%d,p=%d$%s$%s" // AlgName is the name for this algorithm. AlgName = "argon2" // AlgIdentifierVariantI is the identifier used in encoded argon2i variants of this algorithm. AlgIdentifierVariantI = argon2i // AlgIdentifierVariantD is the identifier used in encoded argon2d variants of this algorithm. AlgIdentifierVariantD = argon2d // AlgIdentifierVariantID is the identifier used in encoded argon2id variants of this algorithm. AlgIdentifierVariantID = argon2id // KeyLengthMin is the minimum tag length output. KeyLengthMin = 4 // KeyLengthMax is the maximum tag length output. KeyLengthMax = math.MaxInt32 // KeyLengthDefault is the default key length. KeyLengthDefault = 32 // SaltLengthMin is the minimum salt length input/output. SaltLengthMin = 1 // SaltLengthMax is the maximum salt length input/output. SaltLengthMax = math.MaxInt32 // IterationsMin is the minimum number of passes input. IterationsMin = 1 // IterationsMax is the maximum number of passes input. IterationsMax = math.MaxInt32 // IterationsDefault is the default number of passes. IterationsDefault = IterationsMin // ParallelismMin is the minimum parallelism factor input. ParallelismMin = 1 // ParallelismMax is the maximum parallelism factor input. ParallelismMax = 16777215 // ParallelismDefault is the default parallelism factor. ParallelismDefault = 4 // MemoryMinParallelismMultiplier is the parallelism multiplier which determines the minimum memory. MemoryMinParallelismMultiplier = 8 // MemoryRoundingParallelismMultiplier is the parallelism multiplier which determines the actual memory value. The // value is the closest multiple of this multiplied by the parallelism input. MemoryRoundingParallelismMultiplier = 4 // MemoryMin is the minimum input for memory. MemoryMin = ParallelismMin * MemoryMinParallelismMultiplier // MemoryMax is the maximum input for memory. MemoryMax uint32 = math.MaxUint32 // MemoryDefault represents the default memory value. MemoryDefault = 2 * 1024 * 1024 // PasswordInputSizeMax is the maximum input for the password content. PasswordInputSizeMax = math.MaxInt32 )
Variables ¶
This section is empty.
Functions ¶
func DecodeVariant ¶
DecodeVariant the encoded digest into a algorithm.Digest provided it matches the provided argon2.Variant. If argon2.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 RegisterDecoderArgon2d ¶
func RegisterDecoderArgon2d(r algorithm.DecoderRegister) (err error)
RegisterDecoderArgon2d registers specifically the argon2d decoder variant with the algorithm.DecoderRegister.
func RegisterDecoderArgon2i ¶
func RegisterDecoderArgon2i(r algorithm.DecoderRegister) (err error)
RegisterDecoderArgon2i registers specifically the argon2i decoder variant with the algorithm.DecoderRegister.
func RegisterDecoderArgon2id ¶
func RegisterDecoderArgon2id(r algorithm.DecoderRegister) (err error)
RegisterDecoderArgon2id registers specifically the argon2id decoder variant with the algorithm.DecoderRegister.
Types ¶
type Digest ¶
type Digest struct {
// contains filtered or unexported fields
}
Digest is a digest which handles Argon2 hashes like Argon2id, Argon2i, and Argon2d.
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 argon2.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 Argon2 which can be initialized via argon2.New using a functional options pattern.
func (*Hasher) Hash ¶
Hash performs the hashing operation and returns either a argon2.Digest or an error.
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) Merge ¶
Merge copies all parameters from this argon2.Hasher to another *argon2.Hasher where the parameters are unset.
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 argon2.Hasher and returns an error.
func (*Hasher) WithOptions ¶
WithOptions applies the provided functional options provided as an argon2.Opt to the argon2.Hasher.
type Opt ¶
Opt describes the functional option pattern for the argon2.Hasher.
func WithK ¶
WithK satisfies the argon2.Opt type for the argon2.Hasher and sets input 'T' known as the tag length.
Tag length T MUST be an integer number of bytes from 4 to 2^(32)-1. The Argon2 output, or "tag", is a string T bytes long.
Minimum is 4, Maximum is 2147483647. Default is 32.
RFC9106 section 3.1 "Argon2 Inputs and Outputs" https://www.rfc-editor.org/rfc/rfc9106.html#name-argon2-inputs-and-outputs.
func WithM ¶
WithM satisfies the argon2.Opt type for the argon2.Hasher and sets input 'm' known as the memory size.
Memory size m MUST be an integer number of kibibytes from 8*p to 2^(32)-1. The actual number of blocks is m', which is m rounded down to the nearest multiple of 4*p.
Minimum is 8, Maximum is 4294967295. Default is 2097152.
RFC9106 section 3.1 "Argon2 Inputs and Outputs" https://www.rfc-editor.org/rfc/rfc9106.html#name-argon2-inputs-and-outputs.
func WithP ¶
WithP satisfies the argon2.Opt type for the argon2.Hasher and sets input 'p' known as the degree of parallelism.
Degree of parallelism p determines how many independent (but synchronizing) computational chains (lanes) can be run. It MUST be an integer value from 1 to 2^(24)-1.
Minimum is 1, Maximum is 16777215. Default is 4.
RFC9106 section 3.1 "Argon2 Inputs and Outputs" https://www.rfc-editor.org/rfc/rfc9106.html#name-argon2-inputs-and-outputs.
func WithProfileRFC9106LowMemory ¶
func WithProfileRFC9106LowMemory() Opt
WithProfileRFC9106LowMemory is the recommended low memory RFC9106 profile.
RFC9106 section 4.0 "Parameter Choice" https://www.rfc-editor.org/rfc/rfc9106.html#name-parameter-choice
func WithProfileRFC9106Recommended ¶
func WithProfileRFC9106Recommended() Opt
WithProfileRFC9106Recommended is the recommended standard RFC9106 profile.
RFC9106 section 4.0 "Parameter Choice" https://www.rfc-editor.org/rfc/rfc9106.html#name-parameter-choice
func WithS ¶
WithS satisfies the argon2.Opt type for the argon2.Hasher and sets the length of input 'S' known as the salt length.
Nonce S, which is a salt for password hashing applications. It MUST have a length not greater than 2^(32)-1 bytes. 16 bytes is RECOMMENDED for password hashing. The salt SHOULD be unique for each password.
Minimum is 1, Maximum is 2147483647. Default is 16.
RFC9106 section 3.1 "Argon2 Inputs and Outputs" https://www.rfc-editor.org/rfc/rfc9106.html#name-argon2-inputs-and-outputs.
func WithT ¶
WithT satisfies the argon2.Opt type for the argon2.Hasher and sets input 't' known as the number of passes.
Number of passes t (used to tune the running time independently of the memory size) MUST be an integer number from 1 to 2^(32)-1.
Minimum is 1, Maximum is 2147483647. Default is 1.
RFC9106 section 3.1 "Argon2 Inputs and Outputs" https://www.rfc-editor.org/rfc/rfc9106.html#name-argon2-inputs-and-outputs.
func WithVariant ¶
WithVariant is used to configure the argon2.Variant of the resulting argon2.Digest. Default is argon2.VariantID.
func WithVariantD ¶
func WithVariantD() Opt
WithVariantD satisfies the argon2.Opt type and sets the variant as argon2.VariantD.
func WithVariantI ¶
func WithVariantI() Opt
WithVariantI satisfies the argon2.Opt type and sets the variant as argon2.VariantI.
func WithVariantID ¶
func WithVariantID() Opt
WithVariantID satisfies the argon2.Opt type and sets the variant as argon2.VariantID.
func WithVariantName ¶
WithVariantName uses the variant name or identifier to configure the argon2.Variant of the resulting argon2.Digest. Default is argon2.VariantID.
type Variant ¶
type Variant int
Variant is a variant of the argon2.Digest.
const ( // VariantNone is a variant of the argon2.Digest which is unknown. VariantNone Variant = iota // VariantD is the argon2d variant of the argon2.Digest. VariantD // VariantI is the argon2i variant of the argon2.Digest. VariantI // VariantID is the argon2id variant of the argon2.Digest. VariantID )
func NewVariant ¶
NewVariant converts an identifier string to a argon2.Variant.
func (Variant) KeyFunc ¶
KeyFunc returns the argon2.KeyFunc key derivation function of this argon2.Variant.