scrypt

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: MIT Imports: 7 Imported by: 0

README

go-scrypt

Go Doc Coverage Status

scrypt password hashing and verification for Go.

Install

go get github.com/isayme/go-scrypt

Usage

Hash a password
hashed, err := scrypt.Hash("your plain password", scrypt.DefaultParams)
if err != nil {
    log.Fatal(err)
}
Verify a password
ok, err := scrypt.Verify("your plain password", hashed)
if err != nil {
    log.Fatal(err)
}
if !ok {
    log.Fatal("invalid password")
}
Custom params
params := scrypt.Params{
    N:      16384,
    R:      8,
    P:      1,
    KeyLen: 32,
}

hashed, err := scrypt.Hash("password", params)

Hash format

$scrypt$n=<N>,r=<R>,p=<P>$<salt>$<key>
Field Description
N CPU/memory cost parameter
r Block size parameter
p Parallelization parameter
salt Random salt (base64 encoded)
key Derived key (base64 encoded)

Test

go test -v ./...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultParams = Params{
	N:       16384,
	R:       8,
	P:       1,
	SaltLen: 8,
	KeyLen:  32,
}

DefaultParams returns the recommended default scrypt parameters. N=16384, R=8, P=1, KeyLen=32

Functions

func Hash

func Hash(password string, params Params) (string, error)

Hash generates a scrypt hash of the password with the given parameters. The hash format is $scrypt$n=<N>,r=<R>,p=<P>$<salt>$<key>.

func Verify

func Verify(password, hashed string) (bool, error)

Verify checks if the password matches the hashed value. It uses constant-time comparison to prevent timing attacks.

Types

type Params

type Params struct {
	// N is the CPU/memory cost parameter.
	N int
	// R is the block size parameter.
	R int
	// P is the parallelization parameter.
	P int

	// SaltLen is the length of the salt.
	SaltLen int

	// KeyLen is the length of the derived key.
	KeyLen int
}

Params defines the scrypt algorithm parameters.

Jump to

Keyboard shortcuts

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