argon2

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package argon2 implements the Argon2 hashing algorithm for crypt(3).

Index

Examples

Constants

View Source
const (
	MinSaltLength     = 11
	DefaultSaltLength = MinSaltLength
)
View Source
const (
	MinTime     = 1
	DefaultTime = 3
)
View Source
const (
	MinMemory     = 8
	DefaultMemory = 1 << 12
)
View Source
const (
	MinThreads     = 1
	DefaultThreads = MinThreads
)
View Source
const (
	Prefix2d  = "$argon2d$"
	Prefix2i  = "$argon2i$"
	Prefix2id = "$argon2id$"
)
View Source
const (
	Version10 = 0x10
	Version13 = 0x13
)

Variables

This section is empty.

Functions

func Check

func Check(hash, password string) error

Check compares the given crypt(3) Argon2 hash with a new hash derived from the password. Returns nil on success, or an error on failure.

Example
package main

import (
	"fmt"

	"github.com/sergeymakinen/go-crypt/argon2"
)

func main() {
	hash := "$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho"
	fmt.Println(argon2.Check(hash, "password"))
	fmt.Println(argon2.Check(hash, "test"))
}
Output:

<nil>
hash and password mismatch

func Key

func Key(password, salt []byte, memory, time uint32, threads uint8, opts *CompatibilityOptions) ([]byte, error)

Key returns an Argon2 key derived from the password, salt, memory and time costs, threads and compatibility options.

The opts parameter is optional. If nil, default options are used.

Example
package main

import (
	"encoding/base64"
	"fmt"

	"github.com/sergeymakinen/go-crypt/argon2"
)

func main() {
	salt, memory, time, threads, opts, _ := argon2.Params("$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho")
	fmt.Println(string(salt))
	fmt.Println(memory)
	fmt.Println(time)
	fmt.Println(threads)

	key, _ := argon2.Key([]byte("password"), salt, memory, time, threads, opts)
	fmt.Println(base64.RawStdEncoding.EncodeToString(key))
}
Output:

qXMlAYBABLl
512
3
1
/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho

func NewHash

func NewHash(password string, memory, time uint32) (string, error)

NewHash returns the crypt(3) Argon2 hash of the password, memory and time costs.

Types

type CompatibilityOptions

type CompatibilityOptions struct {
	Prefix  string
	Version int
}

CompatibilityOptions are the key derivation parameters required to produce keys from old/non-standard hashes.

func Params

func Params(hash string) (salt []byte, memory, time uint32, threads uint8, opts *CompatibilityOptions, err error)

Params returns the hashing salt, memory and time costs, threads and compatibility options used to create the given crypt(3) Argon2 hash.

Example
package main

import (
	"fmt"

	"github.com/sergeymakinen/go-crypt/argon2"
)

func main() {
	salt, memory, time, threads, _, _ := argon2.Params("$argon2id$v=19$m=512,t=3,p=1$qXMlAYBABLl$/OuG+qcZ1ntdTRfhUGFVp2YMcTPJ7aH3e4j7KIEnRho")
	fmt.Println(string(salt))
	fmt.Println(memory)
	fmt.Println(time)
	fmt.Println(threads)
}
Output:

qXMlAYBABLl
512
3
1

type InvalidMemoryError

type InvalidMemoryError uint32

InvalidMemoryError values describe errors resulting from an invalid memory cost.

func (InvalidMemoryError) Error

func (e InvalidMemoryError) Error() string

type InvalidSaltError

type InvalidSaltError byte

InvalidSaltError values describe errors resulting from an invalid character in a hash string.

func (InvalidSaltError) Error

func (e InvalidSaltError) Error() string

type InvalidSaltLengthError

type InvalidSaltLengthError int

InvalidSaltLengthError values describe errors resulting from an invalid length of a salt.

func (InvalidSaltLengthError) Error

func (e InvalidSaltLengthError) Error() string

type InvalidThreadsError

type InvalidThreadsError uint32

InvalidThreadsError values describe errors resulting from an invalid thread count

func (InvalidThreadsError) Error

func (e InvalidThreadsError) Error() string

type InvalidTimeError

type InvalidTimeError uint32

InvalidTimeError values describe errors resulting from an invalid time cost.

func (InvalidTimeError) Error

func (e InvalidTimeError) Error() string

type UnsupportedPrefixError

type UnsupportedPrefixError string

UnsupportedPrefixError values describe errors resulting from an unsupported prefix string.

func (UnsupportedPrefixError) Error

func (e UnsupportedPrefixError) Error() string

type UnsupportedVersionError

type UnsupportedVersionError int

UnsupportedVersionError values describe errors resulting from an unsupported version.

func (UnsupportedVersionError) Error

func (e UnsupportedVersionError) Error() string

Directories

Path Synopsis
Package argon2crypto provides low-level access to Argon2 cryptography functions.
Package argon2crypto provides low-level access to Argon2 cryptography functions.

Jump to

Keyboard shortcuts

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