argon2

package
v0.0.0-...-caadfb4 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2020 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package argon2 wraps the x/crypto/argon2 package to provide password-hashing functionality along with secure checking of hashes.

Index

Constants

View Source
const (
	// Version is the Argon2 version implemented by the wrapped x/crypto/argon2
	// package.
	Version = argon2.Version
	// SaltLen is the number of bytes used in generating salts. It is defined
	// purely for documentary purposes.
	SaltLen = 16
)

Variables

This section is empty.

Functions

func Compare

func Compare(hash, password []byte) (bool, error)

Compare hashes password and returns true i.f.f. it results in hash.

func Hash

func Hash(password []byte) ([]byte, error)

Hash hashes the password with the default Config for argon2i. According to x/crypto/argon2 docs, argon2i is the preferred method for password hashing.

Types

type Config

type Config struct {
	Time, Memory uint32
	Threads      uint8
	// HashLen corresponds to keyLen in the crypto/argon2 function parameters.
	HashLen uint32
	// contains filtered or unexported fields
}

Config carries parameters to be propagated to crypto/argon2 functions. Do not instantiate Config directly—rather use Function.Config() as it provides secure-by-default values.

func (*Config) Hash

func (c *Config) Hash(password []byte) ([]byte, error)

Hash returns a hashed password using the Config and a salt generated from crypto/rand.

type Error

type Error int

Error implements the error interface.

const (
	ErrUnknown Error = iota
	ErrInvalidMode
	ErrInvalidPrefix
	ErrInvalidVersion
	ErrInvalidConfig
	ErrSaltTooShort
)

Pre-defined errors.

func (Error) Error

func (e Error) Error() string

type Mode

type Mode string

A Mode corresponds to an Argon2 Mode.

const (
	ID Mode = "argon2id"
	I  Mode = "argon2i"
)

Supported Argon2 Modes.

func (Mode) Config

func (m Mode) Config() *Config

Config returns a default Config for the Mode, as recommended in the crypto/argon2 documentation.

Jump to

Keyboard shortcuts

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