Documentation
¶
Overview ¶
Package streamcrypt provides streaming symmetric encryption using XChaCha20 or AES256-CTR for encryption, SHAKE256 for message authentication, and Argon2 for key derivation.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadChecksum = errors.New("bad checksum") ErrClosed = errors.New("already closed") )
var ( ErrUnsupportedMode = errors.New("incorrect or unsupported encryption mode") ErrHeaderParamsOutOfRange = errors.New("header params out of range") )
Functions ¶
Types ¶
type Decryptor ¶
type Decryptor struct {
// contains filtered or unexported fields
}
Decryptor is returned by NewDecryptor. See it's documentation for details.
Decryptor implements io.ReadCloser.
func NewDecryptor ¶
func NewDecryptor( src io.Reader, passFunc PasswordFunc, options ...Option, ) *Decryptor
NewDecryptor returns a Decryptor which is an io.ReadCloser that reads ciphertext from src and retrieves the plaintext.
The encryption password is retrieved using passFunc during the first read. The []byte that passFunc returns is zeroed after use, so return a copy of it if it's in use elsewhere.
The authentication of the ciphertext is checked upon reaching EOF or calling Decryptor.Close. Therefore, calling Close after reaching EOF is unnecessary.
After either reaching EOF or calling Close, calls to Read will result in an ErrClosed error, and calls to Close will be a no-op.
The following options can be used to configure the decryption behavior:
- WithArgonTimeMax (default: 10)
- WithArgonMemoryMax (default: 64*1024)
- WithArgonThreadsMax (default: 64)
type Encryptor ¶
type Encryptor struct {
// contains filtered or unexported fields
}
Encryptor is returned by NewEncryptor. See it's documentation for details.
Encryptor implements io.WriteCloser.
func NewEncryptor ¶
NewEncryptor returns an Encryptor which is an io.WriteCloser that encrypts plaintext and writes the ciphertext to dest.
Encryptor.Close must be called after all writes are concluded in order to write the authentication bytes to dest.
The password is not retained by this function.
The following options can be used to configure the encryption behavior:
- WithMode (default: ModeXChaCha20)
- WithArgonTime (default: 3)
- WithArgonMemory (default: 16*1024)
- WithArgonThreads (default: 8)
type Option ¶
type Option func(*config)
func WithArgonMemory ¶
func WithArgonMemoryMax ¶
func WithArgonThreads ¶
func WithArgonThreadsMax ¶
func WithArgonTime ¶
func WithArgonTimeMax ¶
type PasswordFunc ¶
PasswordFunc is used by NewDecryptor. See it's documentation for details.
The returned []byte is zeroed after use, so return a copy of it if it's in use elsewhere.