Documentation
¶
Overview ¶
Package crypt defines pluggable encryption and key-derivation interfaces. Implementations can swap in NACL, AES-GCM (FIPS 140), or any AEAD primitive without touching keeper internals.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrDecrypt = errors.New("decryption failed")
ErrDecrypt is returned when authenticated decryption fails.
Functions ¶
This section is empty.
Types ¶
type Argon2KDF ¶
Argon2KDF implements KDF using Argon2id — the recommended password-hashing algorithm for new systems (winner of the Password Hashing Competition).
To meet FIPS 140 requirements swap this for a PBKDF2-SHA-256 implementation that satisfies the same KDF interface.
func DefaultArgon2KDF ¶
func DefaultArgon2KDF() *Argon2KDF
DefaultArgon2KDF returns a KDF with sensible interactive defaults. Tune for your threat model: higher Time/Memory → slower but stronger.
type Cipher ¶
type Cipher interface {
// Encrypt returns authenticated ciphertext for plaintext.
// The implementation is responsible for generating and prepending a nonce.
Encrypt(plaintext []byte) ([]byte, error)
// Decrypt recovers plaintext from ciphertext produced by Encrypt.
// Returns ErrDecrypt on authentication failure or truncation.
Decrypt(ciphertext []byte) ([]byte, error)
}
Cipher is the encryption contract used throughout keeper. Any authenticated-encryption scheme (XChaCha20-Poly1305, AES-256-GCM, NaCl secretbox, …) must satisfy this interface.
type KDF ¶
type KDF interface {
// DeriveKey derives a key of keyLen bytes from password and salt.
DeriveKey(password, salt []byte, keyLen int) ([]byte, error)
}
KDF is the key-derivation contract. Swap between scrypt, Argon2id, PBKDF2, or an HSM-backed KDF without changing caller code.
type ScryptKDF ¶
type ScryptKDF struct {
// N is the CPU/memory cost parameter. Must be a power of 2 (≥2).
N int
// R is the block size parameter.
R int
// P is the parallelisation parameter.
P int
}
ScryptKDF implements KDF using scrypt. It exists solely for backward compatibility with databases that were created with scrypt-derived keys. New deployments should use DefaultArgon2KDF instead.
Recommended migration path: Open the existing database with a ScryptKDF in Config.KDF. Call Rotate with the same passphrase — this re-derives with Argon2id and
re-encrypts all secrets in one atomic operation.
Replace ScryptKDF with DefaultArgon2KDF in your Config going forward.
func DefaultScryptKDF ¶
func DefaultScryptKDF() *ScryptKDF
DefaultScryptKDF returns a ScryptKDF with the same defaults that the old keeper hard-coded (N=32768, r=8, p=1).
type XChacha20Cipher ¶
type XChacha20Cipher struct {
// contains filtered or unexported fields
}
XChacha20Cipher implements Cipher using XChaCha20-Poly1305. It is the default cipher for keeper.
func NewCipher ¶
func NewCipher(secret string) (*XChacha20Cipher, error)
NewCipher creates an XChacha20Cipher from a human-readable secret. It first tries to decode secret as standard Base64; if that fails or the decoded key is not exactly 32 bytes it hashes the string with SHA-256 to produce a 32-byte key.
func NewCipherFromKey ¶
func NewCipherFromKey(key []byte) (*XChacha20Cipher, error)
NewCipherFromKey creates an XChacha20Cipher directly from a 32-byte key.