scrypt

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: 10 Imported by: 0

Documentation

Overview

Package scrypt provides salt generation, hashing and verification for x/crypto/scrypt.

Index

Constants

View Source
const (
	Identifier       = "scrypt"
	Identifier_Linux = "7"
	Prefix           = "$" + Identifier + "$"
	Prefix_Linux     = "$" + Identifier_Linux + "$"
)

Identifiers and prefixes that describe and scrypt encoded hash string.

View Source
const (
	DefaultMinLN = 14
	DefaultMaxLN = 20
	DefaultMinR  = 8
	DefaultMaxR  = 32
	DefaultMinP  = 1
	DefaultMaxP  = 16
)

Defaults for scrypt validation options.

View Source
const Format = "$%s$ln=%d,r=%d,p=%d$%s$%s"

Format of the Modular Crypt Format, as used by passlib. See https://passlib.readthedocs.io/en/stable/lib/passlib.hash.scrypt.html#format-algorithm

Variables

View Source
var DefaultValidationOpts = &ValidationOpts{
	MinLN: DefaultMinLN,
	MaxLN: DefaultMaxLN,
	MinR:  DefaultMinR,
	MaxR:  DefaultMaxR,
	MinP:  DefaultMinP,
	MaxP:  DefaultMaxP,
}
View Source
var (
	ErrRxPTooLarge = errors.New("scrypt: r*p value larger than 2^30")
)
View Source
var (
	RecommendedParams = Params{
		LN:      15,
		R:       8,
		P:       1,
		KeyLen:  32,
		SaltLen: 16,
	}
)

Functions

This section is empty.

Types

type Hasher

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

func New

func New(p Params, opts *ValidationOpts) *Hasher

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 Params

type Params struct {
	LN int // log2 of N, the CPU/memory cost parameter
	R  int
	P  int

	// Lengths for key output and desired salt.
	KeyLen  int
	SaltLen uint32
}

Params holds the cost parameters for scrypt hashing. See scrypt.Key

type ValidationOpts added in v0.12.0

type ValidationOpts struct {
	MinLN int // log2 of N, the CPU/memory cost parameter
	MaxLN int // log2 of N, the CPU/memory cost parameter
	MinR  int
	MaxR  int
	MinP  int
	MaxP  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 scrypt parameters to verify password against its hash. Either the result of Fail or OK is returned, or an error if parsing fails.

Jump to

Keyboard shortcuts

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