hasherx

package
v1.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 2, 2022 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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.

View Source
var ErrUnknownHashAlgorithm = errors.New("unknown hash algorithm")

Functions

func Compare

func Compare(ctx context.Context, password []byte, hash []byte) error

Compare the given password with the given hash.

func CompareArgon2i

func CompareArgon2i(_ context.Context, password []byte, hash []byte) error

func CompareArgon2id

func CompareArgon2id(_ context.Context, password []byte, hash []byte) error

func CompareBcrypt

func CompareBcrypt(_ context.Context, password []byte, hash []byte) error

func ComparePbkdf2

func ComparePbkdf2(_ context.Context, password []byte, hash []byte) error

func IsArgon2iHash

func IsArgon2iHash(hash []byte) bool

func IsArgon2idHash

func IsArgon2idHash(hash []byte) bool

func IsBcryptHash

func IsBcryptHash(hash []byte) bool

func IsPbkdf2Hash

func IsPbkdf2Hash(hash []byte) bool

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) Generate

func (h *Argon2) Generate(ctx context.Context, password []byte) ([]byte, error)

Generate generates a hash for the given password.

func (*Argon2) Understands

func (h *Argon2) Understands(hash []byte) bool

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) Generate

func (h *Bcrypt) Generate(ctx context.Context, password []byte) ([]byte, error)

Generate generates a hash for the given password.

func (*Bcrypt) Understands

func (h *Bcrypt) Understands(hash []byte) bool

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) Generate

func (h *PBKDF2) Generate(ctx context.Context, password []byte) ([]byte, error)

Generate generates a hash for the given password.

func (*PBKDF2) Understands

func (h *PBKDF2) Understands(hash []byte) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL