snacl

package
v0.0.2-0...-1c7e8a7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// Overhead const here expose secretbox's for convenience.
	Overhead  = secretbox.Overhead
	KeySize   = 32
	NonceSize = 24
	DefaultN  = 16384 // 2^14
	DefaultR  = 8
	DefaultP  = 1
)

Various constants needed for encryption scheme.

Variables

View Source
var (
	ErrInvalidPassword = errors.New("invalid password")
	ErrMalformed       = errors.New("malformed data")
	ErrDecryptFailed   = errors.New("unable to decrypt")
)

Functions

func Check

func Check(err error) bool

func Debug

func Debug(a ...interface{})

func Debugc

func Debugc(fn func() string)

func Debugf

func Debugf(format string, a ...interface{})

func Debugs

func Debugs(a interface{})

func Error

func Error(a ...interface{})

func Errorc

func Errorc(fn func() string)

func Errorf

func Errorf(format string, a ...interface{})

func Errors

func Errors(a interface{})

func Fatal

func Fatal(a ...interface{})

func Fatalc

func Fatalc(fn func() string)

func Fatalf

func Fatalf(format string, a ...interface{})

func Fatals

func Fatals(a interface{})

func Info

func Info(a ...interface{})

func Infoc

func Infoc(fn func() string)

func Infof

func Infof(format string, a ...interface{})

func Infos

func Infos(a interface{})

func Trace

func Trace(a ...interface{})

func Tracec

func Tracec(fn func() string)

func Tracef

func Tracef(format string, a ...interface{})

func Traces

func Traces(a interface{})

func Warn

func Warn(a ...interface{})

func Warnc

func Warnc(fn func() string)

func Warnf

func Warnf(format string, a ...interface{})

func Warns

func Warns(a interface{})

Types

type CryptoKey

type CryptoKey [KeySize]byte

CryptoKey represents a secret key which can be used to encrypt and decrypt data.

func GenerateCryptoKey

func GenerateCryptoKey() (*CryptoKey, error)

GenerateCryptoKey generates a new crypotgraphically random key.

func (*CryptoKey) Decrypt

func (ck *CryptoKey) Decrypt(in []byte) ([]byte, error)

Decrypt decrypts the passed data. The must be the output of the Encrypt function.

func (*CryptoKey) Encrypt

func (ck *CryptoKey) Encrypt(in []byte) ([]byte, error)

Encrypt encrypts the passed data.

func (*CryptoKey) Zero

func (ck *CryptoKey) Zero()

Zero clears the key by manually zeroing all memory. This is for security conscience application which wish to zero the memory after they've used it rather than waiting until it's reclaimed by the garbage collector. The key is no longer usable after this call.

type Parameters

type Parameters struct {
	Salt   [KeySize]byte
	Digest [sha256.Size]byte
	N      int
	R      int
	P      int
}

Parameters are not secret and can be stored in plain text.

type SecretKey

type SecretKey struct {
	Key        *CryptoKey
	Parameters Parameters
}

SecretKey houses a crypto key and the parameters needed to derive it from a passphrase. It should only be used in memory.

func NewSecretKey

func NewSecretKey(password *[]byte, N, r, p int) (*SecretKey, error)

NewSecretKey returns a SecretKey structure based on the passed parameters.

func (*SecretKey) Decrypt

func (sk *SecretKey) Decrypt(in []byte) ([]byte, error)

Decrypt takes in a JSON blob and returns it's decrypted form.

func (*SecretKey) DeriveKey

func (sk *SecretKey) DeriveKey(password *[]byte) error

DeriveKey derives the underlying secret key and ensures it matches the expected digest.

This should only be called after previously calling the Zero function or on an initial Unmarshal.

func (*SecretKey) Encrypt

func (sk *SecretKey) Encrypt(in []byte) ([]byte, error)

Encrypt encrypts in bytes and returns a JSON blob.

func (*SecretKey) Marshal

func (sk *SecretKey) Marshal() []byte

Marshal returns the Parameters field marshalled into a format suitable for storage.

This result of this can be stored in clear text.

func (*SecretKey) Unmarshal

func (sk *SecretKey) Unmarshal(marshalled []byte) error

Unmarshal unmarshalls the parameters needed to derive the secret key from a passphrase into sk.

func (*SecretKey) Zero

func (sk *SecretKey) Zero()

Zero zeroes the underlying secret key while leaving the parameters intact.

This effectively makes the key unusable until it is derived again via the DeriveKey function.

Jump to

Keyboard shortcuts

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