bchwallet: github.com/gcash/bchwallet/snacl Index | Files

package snacl

import "github.com/gcash/bchwallet/snacl"

Index

Package Files

snacl.go

Constants

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

Various constants needed for encryption scheme.

Variables

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

Error types and messages.

type CryptoKey Uses

type CryptoKey [KeySize]byte

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

func GenerateCryptoKey Uses

func GenerateCryptoKey() (*CryptoKey, error)

GenerateCryptoKey generates a new crypotgraphically random key.

func (*CryptoKey) Decrypt Uses

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 Uses

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

Encrypt encrypts the passed data.

func (*CryptoKey) Zero Uses

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 Uses

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 Uses

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 Uses

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

NewSecretKey returns a SecretKey structure based on the passed parameters.

func (*SecretKey) Decrypt Uses

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

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

func (*SecretKey) DeriveKey Uses

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 Uses

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

Encrypt encrypts in bytes and returns a JSON blob.

func (*SecretKey) Marshal Uses

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 Uses

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 Uses

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.

Package snacl imports 10 packages (graph) and is imported by 2 packages. Updated 2018-10-08. Refresh now. Tools for package owners.