bcrypt

package
v0.0.0-...-aae4de3 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2019 License: MIT Imports: 8 Imported by: 0

README

This folder contains a fork of golang.org/x/crypto/bcrypt.  The fork was made on 2018-12-29.
All modifications are in patch.go (and patch_test.go).  bcrypt.go remains unmodified and can
be kept in sync with upstream changes.

The patch merely adds a new function (GenerateFromPasswordAndSalt) which allows salt to be
passed in to the bcrypt calculation as opposed to using random salt.

Documentation

Overview

Package bcrypt implements Provos and Mazières's bcrypt adaptive hashing algorithm. See http://www.usenix.org/event/usenix99/provos/provos.pdf

Index

Constants

View Source
const (
	MinCost     int = 4  // the minimum allowable cost as passed in to GenerateFromPassword
	MaxCost     int = 31 // the maximum allowable cost as passed in to GenerateFromPassword
	DefaultCost int = 10 // the cost that will actually be set if a cost below MinCost is passed into GenerateFromPassword
)

Variables

View Source
var ErrHashTooShort = errors.New("crypto/bcrypt: hashedSecret too short to be a bcrypted password")

The error returned from CompareHashAndPassword when a hash is too short to be a bcrypt hash.

View Source
var ErrMismatchedHashAndPassword = errors.New("crypto/bcrypt: hashedPassword is not the hash of the given password")

The error returned from CompareHashAndPassword when a password and hash do not match.

Functions

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword, password []byte) error

CompareHashAndPassword compares a bcrypt hashed password with its possible plaintext equivalent. Returns nil on success, or an error on failure.

func Cost

func Cost(hashedPassword []byte) (int, error)

Cost returns the hashing cost used to create the given hashed password. When, in the future, the hashing cost of a password system needs to be increased in order to adjust for greater computational power, this function allows one to establish which passwords need to be updated.

func GenerateFromPassword

func GenerateFromPassword(password []byte, cost int) ([]byte, error)

GenerateFromPassword returns the bcrypt hash of the password at the given cost. If the cost given is less than MinCost, the cost will be set to DefaultCost, instead. Use CompareHashAndPassword, as defined in this package, to compare the returned hashed password with its cleartext version.

func GenerateFromPasswordAndSalt

func GenerateFromPasswordAndSalt(password, rawSalt []byte, cost int) ([]byte, error)

This function is necessary because mbcrypt needs to control the salt (like you can with other KDFs). All other bcrypt source remains unmodified from the original x/crypto/bcrypt.

Types

type HashVersionTooNewError

type HashVersionTooNewError byte

The error returned from CompareHashAndPassword when a hash was created with a bcrypt algorithm newer than this implementation.

func (HashVersionTooNewError) Error

func (hv HashVersionTooNewError) Error() string

type InvalidCostError

type InvalidCostError int

func (InvalidCostError) Error

func (ic InvalidCostError) Error() string

type InvalidHashPrefixError

type InvalidHashPrefixError byte

The error returned from CompareHashAndPassword when a hash starts with something other than '$'

func (InvalidHashPrefixError) Error

func (ih InvalidHashPrefixError) Error() string

Jump to

Keyboard shortcuts

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