cipher

package
v0.0.0-...-c9cba37 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2018 License: Unlicense, Unlicense Imports: 12 Imported by: 0

Documentation

Overview

Package cipher is a structure to define the key, password and IV of an encryption/decryption function to be embedded with data that is to be kept encrypted except when being used

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bench

func Bench(t time.Duration) (iter int)

Bench returns the number of iterations performed in a given time on the current hardware

func Gen

func Gen(p *passbuf.Password, iv *buf.Unsafe, iterations int) (C *buf.Fenced, IV *buf.Unsafe, err error)

Gen takes a password and a random 12 byte initialisation vector and hashes it using Blake2b-384, returning a 32 byte ciphertext and 12 byte initialisation vector from the first 32 bytes and last 12 bytes respectively, after hashing the resultant hash iterations-1 more times.

Blake2b is used because it is faster than SHA256/SHA512.

Types

type Cipher

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

Cipher has a primary embed from a buf.Unsafe type that stores the encrypted data, so loading it is simple.

func New

func New(r ...*Cipher) *Cipher

New empties a crypt or creates an empty crypt

func (*Cipher) Arm

func (r *Cipher) Arm() *Cipher

Arm generates the ciphertext from the password, uses it to decrypt the crypt into the crypt's main cyphertext, and creates the AES-GCM cipher

func (*Cipher) Cipher

func (r *Cipher) Cipher() *buf.Unsafe

Cipher returns the buf.Unsafe buffer crypt

func (*Cipher) Ciphertext

func (r *Cipher) Ciphertext() *buf.Fenced

Ciphertext returns the ciphertext stored in the crypt

func (*Cipher) Decrypt

func (r *Cipher) Decrypt(b *buf.Unsafe) *buf.Fenced

Decrypt takes an encrypted buf.Unsafe and returns the decrypted data in a buf.Fenced

func (*Cipher) Disarm

func (r *Cipher) Disarm() *Cipher

Disarm clears the ciphertext

func (*Cipher) Encrypt

func (r *Cipher) Encrypt(lb *buf.Fenced) *buf.Unsafe

Encrypt encrypts a Lockedbuffer and returns the ciphertext as buf.Unsafe

func (*Cipher) Error

func (r *Cipher) Error() string

Error returns the error stored in the crypt

func (*Cipher) Generate

func (r *Cipher) Generate(p *passbuf.Password) *Cipher

Generate creates a new crypt based on a password and a newly generated random ciphertext

func (*Cipher) IV

func (r *Cipher) IV() *buf.Unsafe

IV returns the initialisation vector stored in the crypt

func (*Cipher) IsArmed

func (r *Cipher) IsArmed() bool

IsArmed returns true if the crypt is armed

func (*Cipher) IsLoaded

func (r *Cipher) IsLoaded() bool

IsLoaded returns true if the crypt contains data

func (*Cipher) IsUnlocked

func (r *Cipher) IsUnlocked() bool

IsUnlocked returns whether the crypt is locked or not

func (*Cipher) Load

func (r *Cipher) Load(b *buf.Unsafe) *Cipher

Load moves a bytes into the crypt

func (*Cipher) Lock

func (r *Cipher) Lock() *Cipher

Lock clears the password and disarms the crypt if it is armed

func (*Cipher) MarshalJSON

func (r *Cipher) MarshalJSON() ([]byte, error)

MarshalJSON renders the struct as JSON

func (*Cipher) Null

func (r *Cipher) Null() *Cipher

Null wipes the value stored, and restores the buf.Unsafe to the same state as a newly created one (with a nil *[]byte).

func (*Cipher) Password

func (r *Cipher) Password() *passbuf.Password

Password returns the password stored in the Cipher

func (*Cipher) SetError

func (r *Cipher) SetError(s string) *Cipher

SetError sets the error in the Cipher

func (*Cipher) SetIV

func (r *Cipher) SetIV(b *buf.Unsafe) *Cipher

SetIV loads the IV with a buf.Unsafe. It must be 12 bytes long.

func (*Cipher) SetRandomIV

func (r *Cipher) SetRandomIV() *Cipher

SetRandomIV loads the IV with a random 12 buf.

func (*Cipher) String

func (r *Cipher) String() string

String prints the JSON representation of the data and structure

func (*Cipher) Unlock

func (r *Cipher) Unlock(p *passbuf.Password) *Cipher

Unlock sets the password, runs the KDF and arms the

type Crypt

type Crypt interface {
	def.Buffer
	Arm() Crypt
	Ciphertext() *buf.Fenced
	Disarm() Crypt
	IV() *buf.Unsafe
	IsArmed() bool
	IsUnlocked() bool
	IsSecure() bool
	Lock() Crypt
	Password() *passbuf.Password
	Secure(*buf.Fenced, *passbuf.Password, *buf.Unsafe) Crypt
	SetIV(b *buf.Unsafe) Crypt
	SetRandomIV() Crypt
	Unlock(p *passbuf.Password) Crypt
	Unsecure() Crypt
}

Crypt is a generic interface for a buffer that keeps data stored encrypted and decrypts it for read functions and encrypts it for write functions

Jump to

Keyboard shortcuts

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