hash

package
v0.0.14 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: BSD-2-Clause Imports: 26 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 CryptDecoder = NewCryptDecoder()
View Source
var ErrUnknownHashAlgorithm = errors.New("unknown hash algorithm")

Functions

func Compare

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

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 CompareFirebaseScrypt

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

func CompareMD5

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

func CompareMD5Crypt

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

func ComparePbkdf2

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

func CompareSHA

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

func CompareSHA256Crypt

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

func CompareSHA512Crypt

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

func CompareSSHA

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

func CompareScrypt

func CompareScrypt(_ 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 IsFirebaseScryptHash

func IsFirebaseScryptHash(hash []byte) bool

func IsMD5CryptHash

func IsMD5CryptHash(hash []byte) bool

func IsMD5Hash

func IsMD5Hash(hash []byte) bool

func IsPbkdf2Hash

func IsPbkdf2Hash(hash []byte) bool

func IsSHA256CryptHash

func IsSHA256CryptHash(hash []byte) bool

func IsSHA512CryptHash

func IsSHA512CryptHash(hash []byte) bool

func IsSHAHash

func IsSHAHash(hash []byte) bool

func IsSSHAHash

func IsSSHAHash(hash []byte) bool

func IsScryptHash

func IsScryptHash(hash []byte) bool

func IsSip24Hash

func IsSip24Hash(hash []byte) bool

func IsValidHashFormat

func IsValidHashFormat(hash []byte) bool

func NewCryptDecoder

func NewCryptDecoder() *crypt.Decoder

Types

type Argon2

type Argon2 struct {
	// contains filtered or unexported fields
}

func NewHasherArgon2

func NewHasherArgon2(c *Argon2Configuration) *Argon2

func (*Argon2) Generate

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

func (*Argon2) Understands

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

type Argon2Configuration

type Argon2Configuration struct {
	Parallelism uint8
	Memory      bytesize.ByteSize
	Iterations  uint32
	SaltLength  uint8
	KeyLength   uint32
}

type Bcrypt

type Bcrypt struct {
	// contains filtered or unexported fields
}

func NewHasherBcrypt

func NewHasherBcrypt(c *BcryptConfiguration) *Bcrypt

func (*Bcrypt) Generate

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

func (*Bcrypt) Understands

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

type BcryptConfiguration

type BcryptConfiguration struct {
	Cost int
}

type HashProvider

type HashProvider interface {
	Hasher(ctx context.Context) Hasher
}

type Hasher

type Hasher interface {
	// Generate returns a hash derived from the secret or an error if the hash method failed.
	Generate(ctx context.Context, secret []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 secret hashes.

type Pbkdf2

type Pbkdf2 struct {
	Algorithm  string
	Iterations uint32
	SaltLength uint32
	KeyLength  uint32
}

func (*Pbkdf2) Generate

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

func (*Pbkdf2) Understands

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

type Scrypt

type Scrypt struct {
	// contains filtered or unexported fields
}

func NewHasherScrypt

func NewHasherScrypt(c *ScryptConfiguration) *Scrypt

func (*Scrypt) Generate

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

func (*Scrypt) Understands

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

type ScryptConfiguration

type ScryptConfiguration struct {
	Cost            uint32
	Block           uint32
	Parallelization uint32
	SaltLength      uint32
	KeyLength       uint32
}

type SipHash24

type SipHash24 struct {
	// contains filtered or unexported fields
}

func NewHasherSipHash24

func NewHasherSipHash24(c *SipHashConfiguration) *SipHash24

func (*SipHash24) Generate

func (h *SipHash24) Generate(ctx context.Context, data []byte) ([]byte, error)

func (*SipHash24) Understands

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

type SipHashConfiguration

type SipHashConfiguration struct {
	Key string
}

Jump to

Keyboard shortcuts

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