Documentation ¶
Index ¶
- Variables
- func Compare(ctx context.Context, password []byte, hash []byte) error
- func CompareArgon2i(_ context.Context, password []byte, hash []byte) error
- func CompareArgon2id(_ context.Context, password []byte, hash []byte) error
- func CompareBcrypt(_ context.Context, password []byte, hash []byte) error
- func ComparePbkdf2(_ context.Context, password []byte, hash []byte) error
- func IsArgon2iHash(hash []byte) bool
- func IsArgon2idHash(hash []byte) bool
- func IsBcryptHash(hash []byte) bool
- func IsPbkdf2Hash(hash []byte) bool
- type Argon2
- type Argon2Config
- type Argon2Configurator
- type BCryptConfig
- type BCryptConfigurator
- type Bcrypt
- type HashProvider
- type Hasher
- type PBKDF2
- type PBKDF2Config
- type PBKDF2Configurator
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidHash = errors.New("the encoded hash is not in the correct format") ErrIncompatibleVersion = errors.New("incompatible version of argon2") ErrMismatchedHashAndPassword = errors.New("passwords do not match") )
var ErrBcryptPasswordLengthReached = errors.Errorf("passwords are limited to a maximum length of 72 characters")
ErrBcryptPasswordLengthReached is returned when the password is longer than 72 bytes.
var ErrUnknownHashAlgorithm = errors.New("unknown hash algorithm")
Functions ¶
func IsArgon2iHash ¶
func IsArgon2idHash ¶
func IsBcryptHash ¶
func IsPbkdf2Hash ¶
Types ¶
type Argon2 ¶
type Argon2 struct {
// contains filtered or unexported fields
}
Argon2 is a hasher that uses the Argon2 algorithm.
func NewHasherArgon2 ¶
func NewHasherArgon2(c Argon2Configurator) *Argon2
func (*Argon2) Understands ¶
Understands checks if the given hash is in the correct format.
type Argon2Config ¶
type Argon2Config struct { // Memory is the amount of memory to use. Memory bytesize.ByteSize `json:"memory"` // Iterations is the number of iterations to use. Iterations uint32 `json:"iterations"` // Parallelism is the number of threads to use. Parallelism uint8 `json:"parallelism"` // SaltLength is the length of the salt to use. SaltLength uint32 `json:"salt_length"` // KeyLength is the length of the key to use. KeyLength uint32 `json:"key_length"` // ExpectedDuration is the expected duration of the hash. ExpectedDuration time.Duration `json:"expected_duration"` // ExpectedDeviation is the expected deviation of the hash. ExpectedDeviation time.Duration `json:"expected_deviation"` // DedicatedMemory is the amount of dedicated memory to use. DedicatedMemory bytesize.ByteSize `json:"dedicated_memory"` }
Argon2Config is the configuration for a Argon2 hasher.
type Argon2Configurator ¶
type Argon2Configurator interface {
HasherArgon2Config(ctx context.Context) *Argon2Config
}
Argon2Configurator is a function that returns the Argon2 configuration.
type BCryptConfig ¶
type BCryptConfig struct {
Cost uint32 `json:"cost"`
}
BCryptConfig is the configuration for the bcrypt hasher.
type BCryptConfigurator ¶
type BCryptConfigurator interface {
HasherBcryptConfig(ctx context.Context) *BCryptConfig
}
BCryptConfigurator is the interface that must be implemented by a configuration provider for the bcrypt hasher.
type Bcrypt ¶
type Bcrypt struct {
// contains filtered or unexported fields
}
Bcrypt is a hasher that uses the bcrypt algorithm.
func NewHasherBcrypt ¶
func NewHasherBcrypt(c BCryptConfigurator) *Bcrypt
func (*Bcrypt) Understands ¶
Understands checks if the given hash is in the correct format.
type HashProvider ¶
type HashProvider interface {
Hasher() Hasher
}
type Hasher ¶
type Hasher interface { // Generate returns a hash derived from the password or an error if the hash method failed. Generate(ctx context.Context, password []byte) ([]byte, error) // Understands returns whether the given hash can be understood by this hasher. Understands(hash []byte) bool }
Hasher provides methods for generating and comparing password hashes.
type PBKDF2 ¶
type PBKDF2 struct {
// contains filtered or unexported fields
}
PBKDF2 is a PBKDF2 hasher.
func NewHasherPBKDF2 ¶
func NewHasherPBKDF2(c PBKDF2Configurator) *PBKDF2
NewHasherPBKDF2 creates a new PBKDF2 hasher.
func (*PBKDF2) Understands ¶
Understands checks if the given hash is in the correct format.
type PBKDF2Config ¶
type PBKDF2Config struct { // Algorithm can be one of sha1, sha224, sha256, sha384, sha512 Algorithm string // Iterations is the number of iterations to use. Iterations uint32 // KeyLength is the length of the salt. SaltLength uint32 // KeyLength is the length of the key. KeyLength uint32 }
PBKDF2Config is the configuration for a PBKDF2 hasher.
type PBKDF2Configurator ¶
type PBKDF2Configurator interface {
HasherPBKDF2Config(ctx context.Context) *PBKDF2Config
}
PBKDF2Configurator is a configurator for a PBKDF2 hasher.