Skip to main content

Module crypto

Module crypto 

Source
Expand description

Cryptographic primitives for encryption, key derivation, and hashing. Cryptographic primitives for key derivation, encryption, and hashing.

This module provides:

  • Argon2id key derivation with configurable parameters
  • XChaCha20-Poly1305 authenticated encryption
  • Blake2b-256 hashing
  • Memory-locked types for sensitive data

Modules§

nip04
NIP-04 encryption using a raw ECDH shared secret.
nip44
NIP-44 encryption using a raw ECDH shared secret.

Structs§

Argon2Params
Parameters for Argon2id key derivation.
EncryptedData
Encrypted data with nonce for authenticated decryption.
MlockedBox
Fixed-size memory-locked byte array.
MlockedVec
Variable-size memory-locked byte vector.
SecretKey
A 32-byte encryption key stored encrypted in RAM.
SecretVec
Variable-length secret stored encrypted in RAM.

Constants§

KEY_SIZE
Encryption key size.
NONCE_SIZE
XChaCha20-Poly1305 nonce size.
SALT_SIZE
Salt size for key derivation.
TAG_SIZE
Authentication tag size.

Functions§

blake2b_256
Compute Blake2b-256 hash of data.
decrypt
Decrypt ciphertext using XChaCha20-Poly1305.
decrypt_with_aad
Decrypt ciphertext using XChaCha20-Poly1305 with additional authenticated data.
derive_key
Derive an encryption key from a password using Argon2id.
derive_subkey
Derive a subkey from a master key using domain separation.
disable_mlock
Globally disable memory locking for the process.
encrypt
Encrypt plaintext using XChaCha20-Poly1305.
encrypt_with_aad
Encrypt plaintext using XChaCha20-Poly1305 with additional authenticated data.
hmac_sha256
HMAC-SHA256 of data keyed by key. Keyed so the output is a MAC (forgeable only with the key), used for tamper-evident hash chains such as the NIP-55 signing-audit log. Accepts a key of any length (HMAC pads/hashes as needed).
random_bytes
Generate cryptographically secure random bytes.
try_random_bytes
Generate cryptographically secure random bytes, returning an error instead of panicking if the RNG health check fails. Preferred over random_bytes in key/secret generation paths that can propagate a Result (#685).