sha2

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package sha2 provides hashing and verification of SHA-256 and SHA-512 encoded passwords with salt based on crypt(3). [The algorithm](https://www.akkadia.org/drepper/SHA-crypt.txt) builds hashes through multiple digest iterations with shuffles of password and salt.

Index

Constants

View Source
const (
	Sha256Identifier = "$5$"
	Sha512Identifier = "$6$"
	SaltLenMin       = 1
	SaltLenMax       = 16
	RoundsMin        = 1000
	RoundsMax        = 999999999
	RoundsDefault    = 5000
)

Variables

View Source
var DefaultValidationOpts = &ValidationOpts{
	MinSha256Rounds: RoundsMin,
	MaxSha256Rounds: RoundsMax,
	MinSha512Rounds: RoundsMin,
	MaxSha512Rounds: RoundsMax,
}

Functions

This section is empty.

Types

type Hasher

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

Hasher hashes and verifies crypt(3) style SHA256 and SHA512 passwords.

func New256

func New256(rounds int, opts *ValidationOpts) *Hasher

New256 creates a new Hasher for SHA-256 with the given rounds and validation options. If rounds == 0, the default rounds value of 5000 is used.

func New512

func New512(rounds int, opts *ValidationOpts) *Hasher

New512 creates a new Hasher for SHA-512 with the given rounds and validation options. If rounds == 0, the default rounds value of 5000 is used.

func (*Hasher) Hash

func (h *Hasher) Hash(password string) (string, error)

Hash implements passwap.Hasher.

func (*Hasher) Validate added in v0.12.0

func (h *Hasher) Validate(encoded string) (verifier.Result, error)

func (*Hasher) Verify

func (h *Hasher) Verify(encoded, password string) (verifier.Result, error)

Verify implements passwap.Verifier

type ValidationOpts added in v0.12.0

type ValidationOpts struct {
	MinSha256Rounds int
	MaxSha256Rounds int
	MinSha512Rounds int
	MaxSha512Rounds int
}

type Verifier

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

func NewVerifier added in v0.12.0

func NewVerifier(opts *ValidationOpts) *Verifier

func (*Verifier) Validate added in v0.12.0

func (v *Verifier) Validate(encoded string) (verifier.Result, error)

func (*Verifier) Verify added in v0.12.0

func (v *Verifier) Verify(encoded, password string) (verifier.Result, error)

Verify parses encoded and uses its parameters to verify password against its hash.

Jump to

Keyboard shortcuts

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