pc

package
v3.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package pc provides crypto functions for use by secman. The purpose of pc is to provide safe interfaces that factor confusing and common programming errors away from programmers.

Index

Constants

View Source
const (
	MaxPwLength = 2048
)

Variables

View Source
var (
	// DigitLowerBound is the ascii digit lower bound.
	DigitLowerBound = 48
	// DigitUpperBound is the ascii digit upper bound.
	DigitUpperBound = 57
	// UpperCaseLowerBound is the ascii upper case lower bound.
	UpperCaseLowerBound = 65
	// UpperCaseUpperBound is the ascii upper case upper bound.
	UpperCaseUpperBound = 90
	// LowerCaseLowerBound is the ascii lower case lower bound.
	LowerCaseLowerBound = 97
	// LowerCaseUpperBound is the ascii lower case upper bound.
	LowerCaseUpperBound = 122

	// SymbolGrp1LowerBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp1LowerBound = 33
	// SymbolGrp1UpperBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp1UpperBound = 47
	// SymbolGrp2LowerBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp2LowerBound = 58
	// SymbolGrp2UpperBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp2UpperBound = 64
	// SymbolGrp3LowerBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp3LowerBound = 91
	// SymbolGrp3UpperBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp3UpperBound = 96
	// SymbolGrp4LowerBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp4LowerBound = 123
	// SymbolGrp4UpperBound is the ascii lowerbound of the first symbol grp.
	SymbolGrp4UpperBound = 126
)

Functions

func GenHexString

func GenHexString() (string, error)

GenHexString will generate a random 32 character hex string.

func GeneratePassword

func GeneratePassword(specs *PasswordSpecs, passlen int) (pass string, err error)

GeneratePassword is used to generate a password like string securely. GeneratePassword has no upper limit to the length of a password that it can generate, but is restricted by the size of int. It requires generation of a string password that has a upper case letter, a lower case letter, a symbol, and a number.

It works by reading a big block of randomness from the crypto rand package and searching for printable characters. It will continue to read chunks of randomness until it has found a password that meets the specifications of the PasswordSpec passed in to the func.

func GetMasterKey

func GetMasterKey() (masterPrivKey [32]byte)

GetMasterKey is used to prompt user's for their password, read the user's secman config file and decrypt the master private key.

func Open

func Open(key *[32]byte, ciphertext []byte) (message []byte, err error)

Open wraps the AEAD interface secretbox.Open

func OpenAsym

func OpenAsym(ciphertext []byte, pub, priv *[32]byte) (out []byte, err error)

OpenAsym wraps the AEAD interface box.Open

func Scrypt

func Scrypt(pass, salt []byte) (key [32]byte, err error)

Scrypt is a wrapper around scrypt.Key that performs the Scrypt algorithm on the input with opinionated defaults.

func Seal

func Seal(key *[32]byte, message []byte) ([]byte, error)

Seal wraps that AEAD interface secretbox Seal and safely generates a random nonce for developers. This change to seal eliminates the risk of programmers reusing nonces.

func SealAsym

func SealAsym(message []byte, pub *[32]byte, priv *[32]byte) (out []byte, err error)

SealAsym wraps that AEAD interface box.Seal and safely generates a random nonce for developers. This change to seal eliminates the risk of programmers reusing nonces.

Types

type PasswordSpecs

type PasswordSpecs struct {
	NeedsUpper  bool
	NeedsLower  bool
	NeedsSymbol bool
	NeedsDigit  bool
}

PasswordSpecs indicates specifications for a desired generated password.

func (*PasswordSpecs) MeetsSpecs

func (specs *PasswordSpecs) MeetsSpecs(pass string) bool

Jump to

Keyboard shortcuts

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