crypto

package
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package crypto holds envelope encryption for mailbox credentials and password hashing.

Index

Constants

View Source
const MinPasswordLen = 12

MinPasswordLen is the shortest admin password, for first-run setup, a change in the browser and the reset command.

Variables

View Source
var ErrDecrypt = errors.New("decrypt failed")

ErrDecrypt means a ciphertext was tampered with, moved between rows, or sealed under another key.

View Source
var ErrNoMasterKey = errors.New("no master key")

ErrNoMasterKey means no key was given, in the environment or a named file, and the data directory has no master.key yet. LoadMasterKey never makes one: whether a new key is safe depends on what the database holds, so the caller decides and calls GenerateMasterKey.

Functions

func GenerateMasterKey added in v0.1.2

func GenerateMasterKey(dataDir string) ([]byte, error)

GenerateMasterKey makes a new random key and stores it, readable only by the user, as <dataDir>/master.key. It never replaces a file that is already there.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword returns an argon2id hash in the standard encoded form.

func LoadMasterKey

func LoadMasterKey(value, keyFile, dataDir string) ([]byte, error)

LoadMasterKey returns the key-encryption key: from the base64 value, else from keyFile, else from <dataDir>/master.key. It returns ErrNoMasterKey when that file does not exist.

func MasterKeyFile added in v0.1.2

func MasterKeyFile(dataDir string) string

MasterKeyFile is where the key lives when neither the environment nor a named file gives it.

func MasterKeySource added in v0.1.2

func MasterKeySource(value, keyFile, dataDir string) string

MasterKeySource names where LoadMasterKey reads the key from, for a message to a person.

func Open

func Open(master []byte, rowID int64, secretEnc, dekEnc []byte) ([]byte, error)

Open reverses Seal. It returns ErrDecrypt for any mismatch of key, row or ciphertext.

func Seal

func Seal(master []byte, rowID int64, plaintext []byte) (secretEnc, dekEnc []byte, err error)

Seal encrypts plaintext under a fresh data key and wraps that key with the master key. rowID is bound into both ciphertexts, so they cannot be swapped between rows.

func VerifyPassword

func VerifyPassword(encoded, password string) bool

VerifyPassword reports whether password matches an encoded hash, in constant time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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