hash

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: May 9, 2024 License: BSD-3-Clause Imports: 13 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 ErrBlake2s128Key = errors.New("blake2s: a key is required for a 128-bit hash")
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 {
	Hash(plaintext []byte) ([]byte, error)
	ValidateHash(plaintext []byte, expectedHash []byte) (bool, error)
	Hmac(plaintext []byte) ([]byte, error)
	ValidateHmac(plaintext []byte, expectedHash []byte) (bool, error)
	SetEncoder(encoder generic.Encoder)
	GetEncoder() generic.Encoder
}

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
	Encoder    generic.Encoder
}

func (*Blake2b256) GetEncoder added in v0.1.1

func (b *Blake2b256) GetEncoder() generic.Encoder

func (*Blake2b256) Hash

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

func (*Blake2b256) Hmac

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

func (*Blake2b256) SetEncoder added in v0.1.1

func (b *Blake2b256) SetEncoder(encoder generic.Encoder)

func (*Blake2b256) ValidateHash

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

func (*Blake2b256) ValidateHmac

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

type Blake2b384

type Blake2b384 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Blake2b384) GetEncoder added in v0.1.1

func (b *Blake2b384) GetEncoder() generic.Encoder

func (*Blake2b384) Hash

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

func (*Blake2b384) Hmac

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

func (*Blake2b384) SetEncoder added in v0.1.1

func (b *Blake2b384) SetEncoder(encoder generic.Encoder)

func (*Blake2b384) ValidateHash

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

func (*Blake2b384) ValidateHmac

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

type Blake2b512

type Blake2b512 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Blake2b512) GetEncoder added in v0.1.1

func (b *Blake2b512) GetEncoder() generic.Encoder

func (*Blake2b512) Hash

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

func (*Blake2b512) Hmac

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

func (*Blake2b512) SetEncoder added in v0.1.1

func (b *Blake2b512) SetEncoder(encoder generic.Encoder)

func (*Blake2b512) ValidateHash

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

func (*Blake2b512) ValidateHmac

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

type Blake2s128 added in v0.1.1

type Blake2s128 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Blake2s128) GetEncoder added in v0.1.1

func (b *Blake2s128) GetEncoder() generic.Encoder

func (*Blake2s128) Hash added in v0.1.1

func (b *Blake2s128) Hash(plaintext []byte) ([]byte, error)

func (*Blake2s128) Hmac added in v0.1.1

func (b *Blake2s128) Hmac(plaintext []byte) ([]byte, error)

func (*Blake2s128) SetEncoder added in v0.1.1

func (b *Blake2s128) SetEncoder(encoder generic.Encoder)

func (*Blake2s128) ValidateHash added in v0.1.1

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

func (*Blake2s128) ValidateHmac added in v0.1.1

func (b *Blake2s128) ValidateHmac(plaintext, expectedHash []byte) (bool, error)

type Blake2s256 added in v0.1.1

type Blake2s256 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Blake2s256) GetEncoder added in v0.1.1

func (b *Blake2s256) GetEncoder() generic.Encoder

func (*Blake2s256) Hash added in v0.1.1

func (b *Blake2s256) Hash(plaintext []byte) ([]byte, error)

func (*Blake2s256) Hmac added in v0.1.1

func (b *Blake2s256) Hmac(plaintext []byte) ([]byte, error)

func (*Blake2s256) SetEncoder added in v0.1.1

func (b *Blake2s256) SetEncoder(encoder generic.Encoder)

func (*Blake2s256) ValidateHash added in v0.1.1

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

func (*Blake2s256) ValidateHmac added in v0.1.1

func (b *Blake2s256) ValidateHmac(plaintext, 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 Sha2256 added in v0.1.1

type Sha2256 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha2256) GetEncoder added in v0.1.1

func (s *Sha2256) GetEncoder() generic.Encoder

func (*Sha2256) Hash added in v0.1.1

func (s *Sha2256) Hash(plaintext []byte) ([]byte, error)

func (*Sha2256) Hmac added in v0.1.1

func (s *Sha2256) Hmac(plaintext []byte) ([]byte, error)

func (*Sha2256) SetEncoder added in v0.1.1

func (s *Sha2256) SetEncoder(encoder generic.Encoder)

func (*Sha2256) ValidateHash added in v0.1.1

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

func (*Sha2256) ValidateHmac added in v0.1.1

func (s *Sha2256) ValidateHmac(plaintext, expectedHash []byte) (bool, error)

type Sha2384 added in v0.1.1

type Sha2384 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha2384) GetEncoder added in v0.1.1

func (s *Sha2384) GetEncoder() generic.Encoder

func (*Sha2384) Hash added in v0.1.1

func (s *Sha2384) Hash(plaintext []byte) ([]byte, error)

func (*Sha2384) Hmac added in v0.1.1

func (s *Sha2384) Hmac(plaintext []byte) ([]byte, error)

func (*Sha2384) SetEncoder added in v0.1.1

func (s *Sha2384) SetEncoder(encoder generic.Encoder)

func (*Sha2384) ValidateHash added in v0.1.1

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

func (*Sha2384) ValidateHmac added in v0.1.1

func (s *Sha2384) ValidateHmac(plaintext, expectedHash []byte) (bool, error)

type Sha2512 added in v0.1.1

type Sha2512 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha2512) GetEncoder added in v0.1.1

func (s *Sha2512) GetEncoder() generic.Encoder

func (*Sha2512) Hash added in v0.1.1

func (s *Sha2512) Hash(plaintext []byte) ([]byte, error)

func (*Sha2512) Hmac added in v0.1.1

func (s *Sha2512) Hmac(plaintext []byte) ([]byte, error)

func (*Sha2512) SetEncoder added in v0.1.1

func (s *Sha2512) SetEncoder(encoder generic.Encoder)

func (*Sha2512) ValidateHash added in v0.1.1

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

func (*Sha2512) ValidateHmac added in v0.1.1

func (s *Sha2512) ValidateHmac(plaintext, expectedHash []byte) (bool, error)

type Sha3224 added in v0.1.1

type Sha3224 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha3224) GetEncoder added in v0.1.1

func (s *Sha3224) GetEncoder() generic.Encoder

func (*Sha3224) Hash added in v0.1.1

func (s *Sha3224) Hash(plaintext []byte) ([]byte, error)

func (*Sha3224) Hmac added in v0.1.1

func (s *Sha3224) Hmac(plaintext []byte) ([]byte, error)

func (*Sha3224) SetEncoder added in v0.1.1

func (s *Sha3224) SetEncoder(encoder generic.Encoder)

func (*Sha3224) ValidateHash added in v0.1.1

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

func (*Sha3224) ValidateHmac added in v0.1.1

func (s *Sha3224) ValidateHmac(plaintext, expectedHash []byte) (bool, error)

type Sha3256

type Sha3256 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha3256) GetEncoder added in v0.1.1

func (s *Sha3256) GetEncoder() generic.Encoder

func (*Sha3256) Hash

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

func (*Sha3256) Hmac

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

func (*Sha3256) SetEncoder added in v0.1.1

func (s *Sha3256) SetEncoder(encoder generic.Encoder)

func (*Sha3256) ValidateHash

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

func (*Sha3256) ValidateHmac

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

type Sha3384

type Sha3384 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha3384) GetEncoder added in v0.1.1

func (s *Sha3384) GetEncoder() generic.Encoder

func (*Sha3384) Hash

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

func (*Sha3384) Hmac

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

func (*Sha3384) SetEncoder added in v0.1.1

func (s *Sha3384) SetEncoder(encoder generic.Encoder)

func (*Sha3384) ValidateHash

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

func (*Sha3384) ValidateHmac

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

type Sha3512

type Sha3512 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

func (*Sha3512) GetEncoder added in v0.1.1

func (s *Sha3512) GetEncoder() generic.Encoder

func (*Sha3512) Hash

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

func (*Sha3512) Hmac

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

func (*Sha3512) SetEncoder added in v0.1.1

func (s *Sha3512) SetEncoder(encoder generic.Encoder)

func (*Sha3512) ValidateHash

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

func (*Sha3512) ValidateHmac

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

type Shake128

type Shake128 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

type Shake256

type Shake256 struct {
	HmacSecret []byte
	Encoder    generic.Encoder
}

Jump to

Keyboard shortcuts

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