crypto

package
v0.30.0 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package crypto provides end-to-end encryption primitives for td-sync. It includes X25519 key exchange, AES-256-GCM encryption, ECDH+HKDF key wrapping, and Argon2id passphrase-based key derivation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

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

Decrypt decrypts ciphertext produced by Encrypt.

func DeriveKeyFromPassphrase

func DeriveKeyFromPassphrase(passphrase string) (key, salt []byte, err error)

DeriveKeyFromPassphrase derives a 256-bit key from a passphrase using Argon2id. Returns the derived key and the salt used (32 bytes random salt).

func DeriveKeyFromPassphraseWithSalt

func DeriveKeyFromPassphraseWithSalt(passphrase string, salt []byte) ([]byte, error)

DeriveKeyFromPassphraseWithSalt derives a key using a known salt (for recovery).

func Encrypt

func Encrypt(key, plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext using AES-256-GCM with a 256-bit key. Returns nonce || ciphertext (nonce is prepended).

func GenerateDEK

func GenerateDEK() ([]byte, error)

GenerateDEK generates a random 256-bit data encryption key.

func GenerateKeyPair

func GenerateKeyPair() (*ecdh.PrivateKey, *ecdh.PublicKey, error)

GenerateKeyPair generates an X25519 keypair for key exchange.

func UnwrapKey

func UnwrapKey(recipientPriv *ecdh.PrivateKey, senderPub *ecdh.PublicKey, wrappedDEK []byte) ([]byte, error)

UnwrapKey unwraps a data encryption key.

func WrapKey

func WrapKey(senderPriv *ecdh.PrivateKey, recipientPub *ecdh.PublicKey, dek []byte) ([]byte, error)

WrapKey wraps a data encryption key using ECDH shared secret + HKDF. senderPriv + recipientPub -> shared secret -> HKDF-derived AES key -> encrypt DEK.

Types

This section is empty.

Jump to

Keyboard shortcuts

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