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 ¶
- func Bench(t time.Duration) (iter int)
- func Gen(p *passbuf.Password, iv *buf.Unsafe, iterations int) (C *buf.Fenced, IV *buf.Unsafe, err error)
- type Cipher
- func (r *Cipher) Arm() *Cipher
- func (r *Cipher) Cipher() *buf.Unsafe
- func (r *Cipher) Ciphertext() *buf.Fenced
- func (r *Cipher) Decrypt(b *buf.Unsafe) *buf.Fenced
- func (r *Cipher) Disarm() *Cipher
- func (r *Cipher) Encrypt(lb *buf.Fenced) *buf.Unsafe
- func (r *Cipher) Error() string
- func (r *Cipher) Generate(p *passbuf.Password) *Cipher
- func (r *Cipher) IV() *buf.Unsafe
- func (r *Cipher) IsArmed() bool
- func (r *Cipher) IsLoaded() bool
- func (r *Cipher) IsUnlocked() bool
- func (r *Cipher) Load(b *buf.Unsafe) *Cipher
- func (r *Cipher) Lock() *Cipher
- func (r *Cipher) MarshalJSON() ([]byte, error)
- func (r *Cipher) Null() *Cipher
- func (r *Cipher) Password() *passbuf.Password
- func (r *Cipher) SetError(s string) *Cipher
- func (r *Cipher) SetIV(b *buf.Unsafe) *Cipher
- func (r *Cipher) SetRandomIV() *Cipher
- func (r *Cipher) String() string
- func (r *Cipher) Unlock(p *passbuf.Password) *Cipher
- type Crypt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Bench ¶
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 (*Cipher) Arm ¶
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) Encrypt ¶
func (r *Cipher) Encrypt(lb *buf.Fenced) *buf.Unsafe
Encrypt encrypts a Lockedbuffer and returns the ciphertext as buf.Unsafe
func (*Cipher) Generate ¶
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) IsUnlocked ¶
IsUnlocked returns whether the crypt is locked or not
func (*Cipher) MarshalJSON ¶
MarshalJSON renders the struct as JSON
func (*Cipher) Null ¶
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) SetRandomIV ¶
SetRandomIV loads the IV with a random 12 buf.
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