hunter2

package module
Version: v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2021 License: MPL-2.0 Imports: 21 Imported by: 4

README

hunter2

import via xorkevin.dev/hunter2

Documentation

Index

Constants

View Source
const (
	CipherAlgAES              = "aes"
	CipherAlgChaCha20Poly1305 = "cc20p"
)

Cipher algorithms

View Source
const (
	HashIDScrypt  = "s0"
	HashIDBlake2b = "b2b"
)

Hash IDs

View Source
const (
	// TOTPPeriodDefault is the default TOTP period
	TOTPPeriodDefault uint64 = 30
	// OTPDigitsDefault is the default OTP length
	OTPDigitsDefault = 6
)
View Source
const (
	OTPAlgSHA1   = "SHA1"
	OTPAlgSHA256 = "SHA256"
	OTPAlgSHA512 = "SHA512"
)

OTP hash algorithms

View Source
const (
	CipherAuthAlgPoly1305 = "p1305"
)

Cipher Auth algorithms

View Source
const (
	CipherStreamAlgChaCha20 = "cc20"
)

Cipher Stream algorithms

Variables

View Source
var (
	// ErrCipherNotSupported is returned when the cipher is not supported
	ErrCipherNotSupported = errors.New("Cipher not supported")
	// ErrCipherKeyInvalid is returned when the cipher key config is invalid
	ErrCipherKeyInvalid = errors.New("Cipher invalid key")
	// ErrCiphertextInvalid is returned when the ciphertext is invalid
	ErrCiphertextInvalid = errors.New("Cipher invalid ciphertext")
)
View Source
var (
	// ErrHashNotSupported is returned when the hash is unsupported
	ErrHashNotSupported = errors.New("Hash not supported")
	// ErrHashParamInvalid is returned when the hash param is invalid
	ErrHashParamInvalid = errors.New("Hash invalid param")
)
View Source
var (
	// ErrOTPInvalidOpt is returned when an invalid opt is passed to otp
	ErrOTPInvalidOpt = errors.New("OTP invalid opt")
	// ErrOTPOptUnsupported is returned when an otp opt is unsupported
	ErrOTPOptUnsupported = errors.New("OTP opt unsupported")
	// ErrOTPParamInvalid is returned when an otp param string is invalid
	ErrOTPParamInvalid = errors.New("OTP invalid param")
)
View Source
var (
	// DefaultCipherAlgs are the default supported cipher algs
	DefaultCipherAlgs = cipherAlgs{
		CipherAlgAES:              AESCipherFromParams,
		CipherAlgChaCha20Poly1305: ChaCha20Poly1305CipherFromParams,
	}
)
View Source
var (
	// DefaultOTPHashes are the hashes defined by RFC6238
	DefaultOTPHashes = otpHashes{
		OTPAlgSHA1:   crypto.SHA1.New,
		OTPAlgSHA256: crypto.SHA256.New,
		OTPAlgSHA512: crypto.SHA512.New,
	}
)
View Source
var (
	// DefaultScryptConfig is the default scrypt config
	DefaultScryptConfig = NewScryptConfig(65536, 8, 1)
)
View Source
var (
	// ErrCipherAuthInvalid is returned when the cipher auth tag is invalid
	ErrCipherAuthInvalid = errors.New("Cipher invalid auth tag")
)

Functions

func GenerateRandomCode added in v0.1.3

func GenerateRandomCode(digits int) (string, error)

GenerateRandomCode generates a random code with a specified length

func HOTP added in v0.1.2

func HOTP(secret []byte, counter uint64, alg HashConstructor, digits int) (string, error)

HOTP implements RFC4226

func NewChaCha20Stream added in v0.1.7

func NewChaCha20Stream(config ChaCha20Config) (cipher.Stream, error)

NewChaCha20Stream creates a new chacha20 stream cipher

func ParsePoly1305Tag added in v0.1.7

func ParsePoly1305Tag(s string) ([]byte, error)

ParsePoly1305Tag loads a poly1305 tag from string

func TOTP added in v0.1.2

func TOTP(secret []byte, t uint64, opts TOTPOpts) (string, error)

TOTP implements RFC6238

func TOTPGenerateSecret added in v0.1.2

func TOTPGenerateSecret(secretLength int, opts TOTPURI) (string, string, error)

TOTPGenerateSecret generates an otp secret

func TOTPNow added in v0.1.2

func TOTPNow(secret []byte, opts TOTPOpts) (string, error)

TOTPNow returns the TOTP now

func TOTPVerify added in v0.1.2

func TOTPVerify(params string, code string, hashes OTPHashes) (bool, error)

TOTPVerify verifies an otp

Types

type AESCipher added in v0.1.2

type AESCipher struct {
	// contains filtered or unexported fields
}

AESCipher implements Cipher for aes

func (*AESCipher) Decrypt added in v0.1.2

func (c *AESCipher) Decrypt(ciphertext string) (string, error)

func (*AESCipher) Encrypt added in v0.1.2

func (c *AESCipher) Encrypt(plaintext string) (string, error)

Encrypt encrypts using aes

Security paramter is 2^32 random nonce uses.

func (*AESCipher) ID added in v0.1.2

func (c *AESCipher) ID() string

type AESConfig added in v0.1.2

type AESConfig struct {
	Key []byte
}

AESConfig are aes params

func NewAESConfig added in v0.1.2

func NewAESConfig() (*AESConfig, error)

NewAESConfig creates a new aes config

func ParseAESConfig added in v0.1.2

func ParseAESConfig(params string) (*AESConfig, error)

ParseAESConfig loads an aes config from params string

func (AESConfig) String added in v0.1.2

func (c AESConfig) String() string

type Blake2bHasher added in v0.1.1

type Blake2bHasher struct{}

Blake2bHasher implements Hasher for blake2b

func (*Blake2bHasher) Hash added in v0.1.1

func (h *Blake2bHasher) Hash(key string) (string, error)

func (*Blake2bHasher) ID added in v0.1.1

func (h *Blake2bHasher) ID() string

func (*Blake2bHasher) Verify added in v0.1.1

func (h *Blake2bHasher) Verify(key string, hash string) (bool, error)

type ChaCha20Config added in v0.1.7

type ChaCha20Config struct {
	Key   []byte
	Nonce []byte
}

ChaCha20Config are chacha20 params

func NewChaCha20Config added in v0.1.7

func NewChaCha20Config() (*ChaCha20Config, error)

NewChaCha20Config creates a new chacha20 config

func ParseChaCha20Config added in v0.1.7

func ParseChaCha20Config(params string) (*ChaCha20Config, error)

ParseChaCha20Config loads a chacha20 config from params string

func (ChaCha20Config) String added in v0.1.7

func (c ChaCha20Config) String() string

String returns a chacha20 config as a string

type ChaCha20Poly1305Cipher added in v0.1.2

type ChaCha20Poly1305Cipher struct {
	// contains filtered or unexported fields
}

ChaCha20Poly1305Cipher implements Cipher for chacha20-poly1305

func (*ChaCha20Poly1305Cipher) Decrypt added in v0.1.2

func (c *ChaCha20Poly1305Cipher) Decrypt(ciphertext string) (string, error)

func (*ChaCha20Poly1305Cipher) Encrypt added in v0.1.2

func (c *ChaCha20Poly1305Cipher) Encrypt(plaintext string) (string, error)

func (*ChaCha20Poly1305Cipher) ID added in v0.1.2

type ChaCha20Poly1305Config added in v0.1.2

type ChaCha20Poly1305Config struct {
	Key []byte
}

ChaCha20Poly1305Config are chacha20-poly1305 params

func NewChaCha20Poly1305Config added in v0.1.2

func NewChaCha20Poly1305Config() (*ChaCha20Poly1305Config, error)

NewChaCha20Poly1305Config creates a new chacha20 poly1305 config

func ParseChaCha20Poly1305Config added in v0.1.2

func ParseChaCha20Poly1305Config(params string) (*ChaCha20Poly1305Config, error)

ParseChaCha20Poly1305Config loads a chacha20-poly1305 config from params string

func (ChaCha20Poly1305Config) String added in v0.1.2

func (c ChaCha20Poly1305Config) String() string

type Cipher added in v0.1.2

type Cipher interface {
	ID() string
	Encrypt(plaintext string) (string, error)
	Decrypt(ciphertext string) (string, error)
}

Cipher is an encryption interface

func AESCipherFromParams added in v0.1.2

func AESCipherFromParams(params string) (Cipher, error)

AESCipherFromParams creates an aes cipher from params

func ChaCha20Poly1305CipherFromParams added in v0.1.2

func ChaCha20Poly1305CipherFromParams(params string) (Cipher, error)

ChaCha20Poly1305CipherFromParams creates a chacha20-poly1305 cipher from params

func CipherFromParams added in v0.1.4

func CipherFromParams(params string, ciphers CipherAlgs) (Cipher, error)

CipherFromParams creates a cipher from params

func NewAESCipher added in v0.1.2

func NewAESCipher(config AESConfig) (Cipher, error)

NewAESCipher creates a new aes cipher

func NewChaCha20Poly1305Cipher added in v0.1.2

func NewChaCha20Poly1305Cipher(config ChaCha20Poly1305Config) (Cipher, error)

NewChaCha20Poly1305Cipher creates a new chacha20-poly1305 cipher

type CipherAlgs added in v0.1.4

type CipherAlgs interface {
	Get(id string) (CipherConstructor, bool)
}

CipherAlgs are a map of valid ciphers

type CipherConstructor added in v0.1.4

type CipherConstructor = func(params string) (Cipher, error)

CipherConstructor constructs a new cipher from params

type DecStreamReader added in v0.1.7

type DecStreamReader struct {
	S cipher.Stream
	H io.Writer
	R io.Reader
}

func NewDecStreamReader added in v0.1.7

func NewDecStreamReader(s cipher.Stream, h io.Writer, r io.Reader) *DecStreamReader

func (*DecStreamReader) Read added in v0.1.7

func (r *DecStreamReader) Read(dst []byte) (int, error)

type DecStreamWriter added in v0.1.7

type DecStreamWriter struct {
	S cipher.Stream
	H io.Writer
	W io.Writer
}

func NewDecStreamWriter added in v0.1.7

func NewDecStreamWriter(s cipher.Stream, h io.Writer, w io.Writer) *DecStreamWriter

func (*DecStreamWriter) Close added in v0.1.7

func (w *DecStreamWriter) Close() error

func (*DecStreamWriter) Write added in v0.1.7

func (w *DecStreamWriter) Write(src []byte) (int, error)

type Decrypter added in v0.1.2

type Decrypter struct {
	// contains filtered or unexported fields
}

Decrypter decrypts ciphertext

func NewDecrypter added in v0.1.2

func NewDecrypter() *Decrypter

NewDecrypter creates a new decrypter

func (*Decrypter) Decrypt added in v0.1.2

func (d *Decrypter) Decrypt(ciphertext string) (string, error)

Decrypt finds the cipher by id and returns plaintext

func (*Decrypter) RegisterCipher added in v0.1.2

func (d *Decrypter) RegisterCipher(cipher Cipher)

RegisterCipher registers a Cipher

type EncStreamReader added in v0.1.7

type EncStreamReader struct {
	S cipher.Stream
	H io.Writer
	R io.Reader
}

func NewEncStreamReader added in v0.1.7

func NewEncStreamReader(s cipher.Stream, h io.Writer, r io.Reader) *EncStreamReader

func (*EncStreamReader) Read added in v0.1.7

func (r *EncStreamReader) Read(dst []byte) (int, error)

type EncStreamWriter added in v0.1.7

type EncStreamWriter struct {
	S cipher.Stream
	H io.Writer
	W io.Writer
}

func NewEncStreamWriter added in v0.1.7

func NewEncStreamWriter(s cipher.Stream, h io.Writer, w io.Writer) *EncStreamWriter

func (*EncStreamWriter) Close added in v0.1.7

func (w *EncStreamWriter) Close() error

func (*EncStreamWriter) Write added in v0.1.7

func (w *EncStreamWriter) Write(src []byte) (int, error)

type HashConstructor added in v0.1.2

type HashConstructor = func() hash.Hash

HashConstructor constructs a new hash

type Hasher

type Hasher interface {
	ID() string
	Hash(key string) (string, error)
	Verify(key string, hash string) (bool, error)
}

Hasher is a hash interface

func NewBlake2bHasher added in v0.1.1

func NewBlake2bHasher() Hasher

NewBlake2bHasher creates a new blake2b hasher

func NewScryptHasher

func NewScryptHasher(hashlen, saltlen int, config ScryptConfig) Hasher

NewScryptHasher creates a new scrypt hasher

type OTPHashes added in v0.1.2

type OTPHashes interface {
	Get(id string) (HashConstructor, bool)
}

OTPHashes are a map of valid hashes

type Poly1305Auth added in v0.1.7

type Poly1305Auth struct {
	// contains filtered or unexported fields
}

Poly1305Auth computes a poly1305 auth tag

func NewPoly1305Auth added in v0.1.7

func NewPoly1305Auth(c ChaCha20Config) (*Poly1305Auth, error)

NewPoly1305Auth creates a new poly1305 hash to authenticate a cipher stream

func (*Poly1305Auth) Auth added in v0.1.7

func (a *Poly1305Auth) Auth(s string) error

Auth authenticates ciphertext with an auth tag

func (*Poly1305Auth) String added in v0.1.7

func (a *Poly1305Auth) String() string

String returns a string auth tag

func (*Poly1305Auth) Sum added in v0.1.7

func (a *Poly1305Auth) Sum(b []byte) []byte

Sum returns the poly1305 hash of the input

func (*Poly1305Auth) Write added in v0.1.7

func (a *Poly1305Auth) Write(src []byte) (int, error)

Write implements io.Writer

func (*Poly1305Auth) WriteCount added in v0.1.7

func (a *Poly1305Auth) WriteCount() error

WriteCount writes the number of bytes of the input to the hash and should be called after writing all the input. This prevents length extension attacks.

type ScryptConfig

type ScryptConfig struct {
	WorkFactor     int
	MemBlocksize   int
	ParallelFactor int
}

ScryptConfig are scrypt params

func NewScryptConfig

func NewScryptConfig(workFactor, memBlocksize, parallelFactor int) ScryptConfig

NewScryptConfig creates a new scrypt config

func (*ScryptConfig) String

func (c *ScryptConfig) String() string

type ScryptHasher

type ScryptHasher struct {
	// contains filtered or unexported fields
}

ScryptHasher implements Hasher for scrypt

func (*ScryptHasher) Hash

func (h *ScryptHasher) Hash(key string) (string, error)

func (*ScryptHasher) ID

func (h *ScryptHasher) ID() string

func (*ScryptHasher) Verify

func (h *ScryptHasher) Verify(key string, hash string) (bool, error)

type TOTPConfig added in v0.1.2

type TOTPConfig struct {
	Secret []byte
	Alg    string
	Digits int
	Period uint64
	Leeway uint64
}

TOTPConfig are opts for TOTP

func (TOTPConfig) String added in v0.1.2

func (c TOTPConfig) String() string

type TOTPOpts added in v0.1.2

type TOTPOpts struct {
	Alg    HashConstructor
	Digits int
	Period uint64
}

TOTPOpts are opts for TOTP

type TOTPURI added in v0.1.2

type TOTPURI struct {
	TOTPConfig
	Issuer      string
	AccountName string
}

TOTPURI are opts for OTP apps

func (TOTPURI) String added in v0.1.2

func (c TOTPURI) String() string

type Verifier

type Verifier struct {
	// contains filtered or unexported fields
}

Verifier verifies hashes

func NewVerifier

func NewVerifier() *Verifier

NewVerifier creates a new verifier

func (*Verifier) RegisterHash

func (v *Verifier) RegisterHash(hasher Hasher)

RegisterHash registers a Hasher

func (*Verifier) Verify

func (v *Verifier) Verify(key string, hash string) (bool, error)

Verify checks to see if the hash of the given key matches the provided keyhash

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL