hash

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2022 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Argon2I is the argon2i function constant
	Argon2I = "argon2i"
	// Argon2ID is the argon2id function constant
	Argon2ID = "argon2id"
)

Variables

This section is empty.

Functions

func MatchesAfterHash

func MatchesAfterHash(data string, matchInfo Info) bool

MatchesAfterHash generates hash info for the provided data, and then compares to the provided match info.

Types

type Config

type Config struct {
	Function   string `json:"function,omitempty" toml:"function"`     // Function is the name of the function to create the hash.
	Iterations uint32 `json:"iterations.omitempty" toml:"iterations"` // Iterations is the number of passes over hashing memory should occur.
	KeySize    uint32 `json:"key_size,omitempty" toml:"key_size"`     // KeySize is the size, in bytes, the returned derived key should be. Must be a multiple of 32.
	Memory     uint32 `json:"memory,omitempty" toml:"memory"`         // Memory is the size of memory, in kilobytes, to be used in iteration during hashing.
	SaltSize   uint32 `json:"salt_size,omitempty" toml:"salt_size"`   // SaltSize is the size, in bytes, that randomly generated salt to be used for hashing should be. Must be a multiple of 16.
	Threads    uint8  `json:"threads,omitempty" toml:"threads"`       // Threads is the number of threads to be used in the hashing process.
	Version    int    `json:"version,omitempty" toml:"version"`       // Version is the default version fo the argon hashing algorithms to use for hashing.
}

Config holds the default configuration values for the hash module.

func GetConfigDefaults

func GetConfigDefaults() Config

GetConfigDefaults returns sane defaults to be used with the argon hashing algorithms.

hashing parameters arrived at via recommendations from https://tools.ietf.org/html/draft-irtf-cfrg-argon2-04#section-4

type Info

type Info struct {
	Config // Config is an embedded config struct

	Encoded string // Encoded the full encoded form of the hash. Usually used in storage.
	Hash    []byte // Hash is the hashed data itself.
	Salt    []byte // Salt is the salt used in creating this hash.
}

Info holds information about a hash

func Decode

func Decode(data string) (Info, error)

Decode decodes the provided hash

When an error is encountered, a newly instantiated blank Info struct is returned to try to prevent as much data leakage as possible.

func Generate

func Generate(data string, defaults Config) (Info, error)

Generate hashes the provided data and creates an encoded string for storage, returning all information used to create the hash.

If an error is encountered, an uninitialized Info struct is returned to prevent leaking of data to the caller.

Jump to

Keyboard shortcuts

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