crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// CanaryPlaintext is the known value encrypted in the canary record to
	// validate the master password without storing the password itself.
	CanaryPlaintext = "psst:canary:valid:v1"
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(key, nonce, ciphertext []byte) ([]byte, error)

Decrypt decrypts ciphertext with AES-256-GCM. GCM authentication ensures integrity; a wrong key or tampered ciphertext returns an error.

func DeriveKey

func DeriveKey(password, salt []byte) []byte

DeriveKey derives a 32-byte AES key from password+salt using Argon2id. The call is intentionally slow to resist brute-force attacks.

func Encrypt

func Encrypt(key, plaintext []byte) (ciphertext, nonce []byte, err error)

Encrypt encrypts plaintext with AES-256-GCM using the provided 32-byte key. Returns (ciphertext, nonce, error). The nonce is randomly generated and must be stored alongside the ciphertext for decryption.

func GenerateSalt

func GenerateSalt() ([]byte, error)

GenerateSalt returns 16 cryptographically random bytes.

func PromptPassword

func PromptPassword(prompt string) ([]byte, error)

PromptPassword writes prompt to stderr and reads a password with echo suppressed. Returns an error if the password is empty.

func PromptPasswordConfirm

func PromptPasswordConfirm(prompt, confirmPrompt string) ([]byte, error)

PromptPasswordConfirm prompts twice and returns an error unless both entries match (compared in constant time to avoid timing leaks).

func VerifyCanary

func VerifyCanary(password, salt, nonce, encryptedCanary []byte) bool

VerifyCanary derives the key from password+salt and attempts to decrypt the canary ciphertext, comparing the result against CanaryPlaintext in constant time. Returns true only if the password is correct.

func ZeroBytes

func ZeroBytes(b []byte)

ZeroBytes overwrites a byte slice with zeroes to limit the time sensitive material lives in process memory.

Types

This section is empty.

Jump to

Keyboard shortcuts

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