jumphasher

package
v0.0.0-...-477d896 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2017 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HashStoreTypeMem = iota
)

we could extend this with alternative hash stores

View Source
const (
	HashTypeSHA512 = iota
)

we could extend this with more hashing algorithms

Variables

View Source
var ErrNilJobID error = errors.New("encountered nil job ID")
View Source
var ErrNilPassword error = errors.New("encountered a nil password")

Functions

This section is empty.

Types

type AtomicFlag

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

Golang implementation of std::atomic_flag from C++11

Used for lock-free coordination between workers for shutdown

func (*AtomicFlag) Clear

func (a *AtomicFlag) Clear()

Atomically clears AtomicFlag and sets it to false

func (*AtomicFlag) Test

func (a *AtomicFlag) Test() bool

Atomically checks AtomicFlag

func (*AtomicFlag) TestAndSet

func (a *AtomicFlag) TestAndSet() bool

Atomically sets AtomicFlag to true and returns its previous value

type HashStore

type HashStore interface {
	Store(id *UUID, h []byte) error
	Load(id *UUID) ([]byte, error)
}

Implements a generic way to store and load job IDs and their corresponding hashes Lets us easily swap out backends, eg; in-memory, RDBMS like Postgres, NoSQL store Underlying type *must be thread safe*

type HashingEngine

type HashingEngine interface {
	Hash(password []byte) ([]byte, error)
}

Generic hashing interface allows us to swap out hashing algorithms Not thread-safe! Use 1 per worker

type MemHashStore

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

In-memory hash store using granular locking to prevent contention

Items are routed to a bucket based on first 4 bytes of job ID

Ideally, we size this to the hardware concurrency of the machine

func NewMemHashStore

func NewMemHashStore(size int) *MemHashStore

Creates a new MemHashStore object

func (*MemHashStore) Load

func (m *MemHashStore) Load(id *UUID) ([]byte, error)

Load a hash given a job ID

If it cannot be found, we return a nil slice

func (*MemHashStore) Store

func (m *MemHashStore) Store(id *UUID, h []byte) error

Store a hash given a job ID

type SHA512Engine

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

func NewSHA512Engine

func NewSHA512Engine() *SHA512Engine

func (*SHA512Engine) Hash

func (e *SHA512Engine) Hash(password []byte) ([]byte, error)

Generates SHA512 checksum of password

type UUID

type UUID [16]byte //use a fixed size array so it's hashable (i.e. usable as map[UUID]interface{})

func UUIDv4

func UUIDv4() (*UUID, error)

Generates an RFC 4122 compliant UUIDv4.

Returns a 128 bit byte slice containing the UUID

Note: uses crypto/rand for secure entropy so it will be slow if the underlying CPU doesn't support the RDRAND instruction. Since we only need low collision probability and even distribution, hashing the output of a faster PRNG (eg; mersenne-twister) through something like 64 bit xxhash twice (to get 16 bytes) will be considerably less CPU intensive.

func (*UUID) Equals

func (a *UUID) Equals(b *UUID) bool

Convenience function to compare two UUIDs

Will return false if either input is nil

func (*UUID) MarshalText

func (u *UUID) MarshalText() string

Outputs a UUID in unhyphenated hex

Technically, this isn't the standard format but it's easier to deal with than hyphenated variants

Implements encoding.TextMarshaler interface which allows easy usage with JSON

func (*UUID) UnmarshalText

func (u *UUID) UnmarshalText(s string) error

Parses a UUID from string using unhyphenated hex format.

Input is expected to be a lowercase 32 character alphanumeric string

Implements encoding.TextUnmarshaler interface which allows easy usage with JSON

Jump to

Keyboard shortcuts

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