scrypt

package
v0.0.0-...-1ee5a75 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2015 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package scrypt implements a password encoding mechanism for the mcf framework

Index

Constants

View Source
const (
	DefaultKeyLen  = 32
	DefaultSaltLen = 16
	DefaultN       = 1 << 16
	DefaultR       = 10
	DefaultP       = 2
)

Circa 2014 work factors. These are exported to show default values. See GetConfig and SetConfig(...) to change them.

Variables

View Source
var SaltMine mcf.SaltMiner = nil

Custom source of salt, normally unset. Set this if you need to override the user of rand.Reader and use a custom salt producer. Also useful for testing.

Functions

func SetConfig

func SetConfig(config Config) error

SetConfig sets the default encoding parameters, salt length or key length. It is best to modify a copy of the default configuration unless all parameters are changed.

Here is an example that doubles the default work factor.

config := scrypt.GetConfig()
config.N *= 2
scrypt.SetConfig(config)

Types

type Config

type Config struct {
	KeyLen  int //Key output size in bytes.
	SaltLen int // Length of salt in bytes.

	N int // CPU/Memory cost. Must be a power of two.
	R int // block size parameter.
	P int // parallelization parameter.
}

Config contains the scrypt algorithm parameters and other associated values. Use the GetConfig() and SetConfig() combination to change any desired parameters.

func GetConfig

func GetConfig() Config

Config returns the default configuration used to create new scrypt password hashes. The return value can be modified and used as a parameter to SetConfig

func (*Config) AtLeast

func (c *Config) AtLeast(current_imp bridge.Implementer) bool

AtLeast returns true if the parameters used to generate the encoded password are at least as good as those currently in use.

func (*Config) Key

func (c *Config) Key(plaintext []byte, salt []byte) (b []byte, err error)

Key returns an scrypt digest of password and salt using the algorithm parameters: N, r, and p. The returned value is of length KeyLen.

func (*Config) Params

func (c *Config) Params() string

Params returns the current digest algorithm parameters.

func (*Config) Salt

func (c *Config) Salt() ([]byte, error)

Salt produces SaltLen bytes of random data.

func (*Config) SetParams

func (c *Config) SetParams(s string) error

SetParams sets the parameters for the digest algorithm.

type ErrInvalidParameter

type ErrInvalidParameter struct {
	Name  string
	Value int
}

ErrInvalidParameter is returned by SetConfig if any of the provided parameters fail validation. The error message contains the name and value of the faulty parameter to aid in resolving the problem.

func (ErrInvalidParameter) Error

func (e ErrInvalidParameter) Error() string

Jump to

Keyboard shortcuts

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