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§
- Argon2
Params - Parameters for Argon2id key derivation.
- Encrypted
Data - Encrypted data with nonce for authenticated decryption.
- Mlocked
Box - Fixed-size memory-locked byte array.
- Mlocked
Vec - Variable-size memory-locked byte vector.
- Secret
Key - A 32-byte encryption key stored encrypted in RAM.
- Secret
Vec - 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
datakeyed bykey. 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_bytesin key/secret generation paths that can propagate aResult(#685).