hashingHelper

package
v1.0.4 Latest Latest
Warning

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

Go to latest
Published: May 23, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UnsupportedHashTypeError    = errors.New("Unsupported hash type")
	UnsupportedHashVersionError = errors.New("Unsupported hash version")
)
View Source
var (

	// DefaultHashParams are the default parameters for the hashing algorithm
	DefaultHashParams = HashParams{
		Time:       2,
		Memory:     256 * 1024,
		Threads:    4,
		KeyLen:     32,
		SaltLength: 32,
		Type:       Argon2id,
		Version:    argon2.Version,
	}
)
View Source
var (
	InvalidEncodedHashError = errors.New("Invalid encoded hash")
)
View Source
var SaltGenerationError = errors.New("Failed to generate salt")

Functions

func VerifyHash

func VerifyHash(ctx context.Context, encodedHash, password string) (bool, error)

VerifyHash compares the provided password with the encoded hash

Types

type Argon2Type

type Argon2Type uint8
const (
	Argon2d Argon2Type = iota
	Argon2i
	Argon2id
)

Argon2 types according to the RFC

func (Argon2Type) String

func (t Argon2Type) String() string

String method for Argon2Type

type HashParams

type HashParams struct {
	Time       uint32     // Number of iterations/passes over the memory (-> time) used by the algorithm
	Memory     uint32     // Amount of memory used by the algorithm in KiB (minimum: 8*Threads)
	Threads    uint8      // Parallelism factor determines how many independent (but synchronizing) computational chains (lanes) can be run
	KeyLen     uint32     // Length of the generated hash (key) in bytes. Recommended: 16 or more
	SaltLength uint32     // Length of the random salt in bytes. Recommended: 16 or more
	Type       Argon2Type // Type of the algorithm: 0 = Argon2d, 1 = Argon2i, 2 = Argon2id
	Version    uint32     // Version of the algorithm
}

HashParams are the parameters for the hashing algorithm. Description according to RFC-9106.

func DecodeHash

func DecodeHash(ctx context.Context, encodedHash string) (HashParams, []byte, []byte, error)

DecodeHash decodes the hash, parameters and salt from the encoded hash

func (*HashParams) EncodeHash

func (params *HashParams) EncodeHash(ctx context.Context, hash []byte, salt []byte) string

EncodeHash encodes the hash and salt using the provided parameters

func (*HashParams) GenerateSalt

func (params *HashParams) GenerateSalt(ctx context.Context) ([]byte, error)

GenerateSalt generates a random salt with the length specified in the HashParams struct

func (*HashParams) HashPassword

func (params *HashParams) HashPassword(ctx context.Context, password string) (string, error)

HashPassword generates a salt and hashes the provided password using the Argon2id algorithm

Jump to

Keyboard shortcuts

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