common

package
Version: v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2018 License: BSD-3-Clause Imports: 3 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSaltPrefix = errors.New("invalid magic prefix")
	ErrSaltFormat = errors.New("invalid salt format")
	ErrSaltRounds = errors.New("invalid rounds")
)

Functions

func Base64_24Bit

func Base64_24Bit(src []byte) (hash []byte)

Base64_24Bit is a variant of Base64 encoding, commonly used with password hashing algorithms to encode the result of their checksum output.

The algorithm operates on up to 3 bytes at a time, encoding the following 6-bit sequences into up to 4 hash64 ASCII bytes.

1. Bottom 6 bits of the first byte
2. Top 2 bits of the first byte, and bottom 4 bits of the second byte.
3. Top 4 bits of the second byte, and bottom 2 bits of the third byte.
4. Top 6 bits of the third byte.

This encoding method does not emit padding bytes as Base64 does.

Types

type Salt

type Salt struct {
	MagicPrefix []byte

	SaltLenMin int
	SaltLenMax int

	RoundsMin     int
	RoundsMax     int
	RoundsDefault int
}

Salt represents a salt.

func (*Salt) Generate

func (s *Salt) Generate(length int) []byte

Generate generates a random salt of a given length.

The length is set thus:

length > SaltLenMax: length = SaltLenMax
length < SaltLenMin: length = SaltLenMin

func (*Salt) GenerateWRounds

func (s *Salt) GenerateWRounds(length, rounds int) []byte

GenerateWRounds creates a random salt with the random bytes being of the length provided, and the rounds parameter set as specified.

The parameters are set thus:

length > SaltLenMax: length = SaltLenMax
length < SaltLenMin: length = SaltLenMin

rounds < 0: rounds = RoundsDefault
rounds < RoundsMin: rounds = RoundsMin
rounds > RoundsMax: rounds = RoundsMax

If rounds is equal to RoundsDefault, then the "rounds=" part of the salt is removed.

Source Files

Jump to

Keyboard shortcuts

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