hash

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	AIterations    uint32 = 2
	AMemory        uint32 = 1 * 64 * 1024
	AParallelism   uint8  = 4
	AKeyLen        uint32 = 32
	HKDFKeysize    int    = 32
	Argon2Saltsize int    = 16
)

Variables

View Source
var ErrHmacSecretNil = errors.New("HMAC secret is nil")

Functions

func ReadFileContentAndHash

func ReadFileContentAndHash(algo Algorithms, path string) ([]byte, error)

func ReadFileContentAndHmac

func ReadFileContentAndHmac(algo Algorithms, path string) ([]byte, error)

Types

type Algorithms

type Algorithms interface {
	// data
	Hash([]byte) ([]byte, error)
	// plaintext, expectedHash
	ValidateHash([]byte, []byte) (bool, error)
	// data
	Hmac([]byte) ([]byte, error)
	// data, expectedHash
	ValidateHmac([]byte, []byte) (bool, error)
}

type Argon2ID

type Argon2ID struct {
	Salt        []byte
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	KeyLen      uint32
}

func (*Argon2ID) ExtractParameters

func (a *Argon2ID) ExtractParameters(input string) (Parameters, error)

func (*Argon2ID) Hash

func (a *Argon2ID) Hash(data []byte) (string, error)

func (*Argon2ID) Validate

func (a *Argon2ID) Validate(data []byte, argonString string) (bool, error)

type Blake2b256

type Blake2b256 struct {
	HmacSecret []byte
}

func (*Blake2b256) Hash

func (b *Blake2b256) Hash(data []byte) ([]byte, error)

func (*Blake2b256) Hmac

func (b *Blake2b256) Hmac(data []byte) ([]byte, error)

func (*Blake2b256) ValidateHash

func (b *Blake2b256) ValidateHash(plaintext, expectedHash []byte) (bool, error)

func (*Blake2b256) ValidateHmac

func (b *Blake2b256) ValidateHmac(data, expectedHash []byte) (bool, error)

type Blake2b384

type Blake2b384 struct {
	HmacSecret []byte
}

func (*Blake2b384) Hash

func (b *Blake2b384) Hash(data []byte) ([]byte, error)

func (*Blake2b384) Hmac

func (b *Blake2b384) Hmac(data []byte) ([]byte, error)

func (*Blake2b384) ValidateHash

func (b *Blake2b384) ValidateHash(plaintext, expectedHash []byte) (bool, error)

func (*Blake2b384) ValidateHmac

func (b *Blake2b384) ValidateHmac(data, expectedHash []byte) (bool, error)

type Blake2b512

type Blake2b512 struct {
	HmacSecret []byte
}

func (*Blake2b512) Hash

func (b *Blake2b512) Hash(data []byte) ([]byte, error)

func (*Blake2b512) Hmac

func (b *Blake2b512) Hmac(data []byte) ([]byte, error)

func (*Blake2b512) ValidateHash

func (b *Blake2b512) ValidateHash(plaintext, expectedHash []byte) (bool, error)

func (*Blake2b512) ValidateHmac

func (b *Blake2b512) ValidateHmac(data, expectedHash []byte) (bool, error)

type Hkdf

type Hkdf struct {
	Salt     []byte
	Key      []byte
	HashMode func() hash.Hash
	Encoder  generic.Hex
}

type Kdf

type Kdf interface {
	Hash([]byte) (string, error)
	Validate([]byte, string) (bool, error)
}

type Parameters added in v0.0.2

type Parameters struct {
	Algorithm   string
	Version     string
	Memory      uint32
	Iterations  uint32
	Parallelism uint8
	Salt        []byte
	Hash        []byte
}

type Sha3256

type Sha3256 struct {
	HmacSecret []byte
}

func (*Sha3256) Hash

func (s *Sha3256) Hash(data []byte) ([]byte, error)

func (*Sha3256) Hmac

func (s *Sha3256) Hmac(data []byte) ([]byte, error)

func (*Sha3256) ValidateHash

func (s *Sha3256) ValidateHash(plaintext, expectedHash []byte) (bool, error)

func (*Sha3256) ValidateHmac

func (s *Sha3256) ValidateHmac(data, expectedHash []byte) (bool, error)

type Sha3384

type Sha3384 struct {
	HmacSecret []byte
}

func (*Sha3384) Hash

func (s *Sha3384) Hash(data []byte) ([]byte, error)

func (*Sha3384) Hmac

func (s *Sha3384) Hmac(data []byte) ([]byte, error)

func (*Sha3384) ValidateHash

func (s *Sha3384) ValidateHash(plaintext, expectedHash []byte) (bool, error)

func (*Sha3384) ValidateHmac

func (s *Sha3384) ValidateHmac(data, expectedHash []byte) (bool, error)

type Sha3512

type Sha3512 struct {
	HmacSecret []byte
}

func (*Sha3512) Hash

func (s *Sha3512) Hash(data []byte) ([]byte, error)

func (*Sha3512) Hmac

func (s *Sha3512) Hmac(data []byte) ([]byte, error)

func (*Sha3512) ValidateHash

func (s *Sha3512) ValidateHash(plaintext, expectedHash []byte) (bool, error)

func (*Sha3512) ValidateHmac

func (s *Sha3512) ValidateHmac(data, expectedHash []byte) (bool, error)

type Shake128

type Shake128 struct {
	HmacSecret []byte
}

type Shake256

type Shake256 struct {
	HmacSecret []byte
}

Jump to

Keyboard shortcuts

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