Skip to main content

void_crypto/
lib.rs

1//! void-crypto: Cryptographic primitives and key management for void.
2//!
3//! This crate is the **sole custodian** of repository encryption key material.
4//! It provides:
5//!
6//! - AES-256-GCM authenticated encryption with AAD
7//! - HKDF-SHA256 key derivation with purpose separation
8//! - Per-commit envelope encryption (VD01 format)
9//! - `KeyVault`: an opaque vault that holds the root key and provides operations
10//! - `CommitReader`: a per-commit handle for decrypting metadata and shards
11//! - Scoped access tokens for limited read access
12//!
13//! # Security Architecture
14//!
15//! The root key never leaves this crate. External crates interact with key material
16//! only through:
17//! - `KeyVault` methods (open_commit, seal_commit, derived key accessors)
18//! - `CommitReader` methods (decrypt_metadata, decrypt_shard)
19//! - `SecretKey` references (derived keys for index/stash/staged)
20//!
21//! Raw `[u8; 32]` key parameters are `pub(crate)` only — the crate boundary
22//! is the enforcement mechanism.
23
24#![warn(clippy::all)]
25// void-crypto IS the crypto implementation layer — raw key access is
26// expected internally.  The disallowed_methods lint protects *consumers*
27// (void-core, void-cli) from bypassing the vault, not us.
28#![allow(clippy::disallowed_methods)]
29
30mod aead;
31mod blob_types;
32mod cid_types;
33pub mod ecies;
34mod envelope;
35pub mod identity;
36mod kdf;
37mod keys;
38pub mod pin;
39pub mod reader;
40mod scoped_keyring;
41pub mod seed;
42pub mod vault;
43
44// Re-export error types
45pub use error::{CryptoError, CryptoResult};
46mod error;
47
48// Re-export AEAD primitives (needed by void-core for low-level operations)
49pub use aead::{
50    decrypt, decrypt_and_parse, decrypt_to_vec, encrypt, unwrap_shard_key, wrap_shard_key,
51    AAD_COMMIT, AAD_INDEX, AAD_MANIFEST, AAD_METADATA, AAD_REPO_MANIFEST, AAD_SHARD,
52    AAD_SHARD_KEY, AAD_STAGED, AAD_STASH,
53};
54
55// Re-export envelope primitives
56pub use envelope::{decrypt_envelope, encrypt_with_envelope, generate_key_nonce, MAGIC_V1};
57
58// Re-export KDF types and functions
59pub use kdf::{
60    derive_key, derive_key_for_purpose, derive_scoped_key, generate_key, AeadNonce, ContentKey,
61    IdentitySeed, KeyNonce, KeyPurpose, KeyRing, Nonce, NostrSecretKey, RecipientSecretKey,
62    RepoSecret, SecretKey, ShareKey, SigningSecretKey,
63};
64
65// Re-export reader types
66pub use reader::{
67    decrypt_object, decrypt_object_parse, decrypt_object_raw, decrypt_shard_data, CommitReader,
68};
69
70// Re-export encrypted blob newtypes
71pub use blob_types::{
72    EncryptedBlob, EncryptedCommit, EncryptedIndex, EncryptedManifest, EncryptedMetadata,
73    EncryptedRepoManifest, EncryptedShard, EncryptedStaged, EncryptedStash,
74};
75
76// Re-export CID newtypes
77pub use cid_types::{CommitCid, ManifestCid, MetadataCid, RepoManifestCid, ShardCid};
78
79// Re-export public key types and manifest key newtypes
80pub use keys::{
81    CommitSignature, ContributorId, NostrPubKey, ParseError, RecipientPubKey, RepoKey,
82    SigningPubKey, WrappedKey,
83};
84
85// Re-export identity types
86pub use identity::{
87    derive_repo_owner_signing_key, ecies_unwrap_key, ecies_wrap_key, Identity, IdentityError,
88    ParsedIdentity,
89};
90
91// Re-export ECIES types
92pub use ecies::EciesError;
93
94// Re-export seed types
95pub use seed::{
96    derive_nostr_key, derive_recipient_key, derive_repo_owner_key, derive_signing_key,
97    generate_mnemonic, mnemonic_to_seed, SeedError,
98};
99
100// Re-export PIN types
101pub use pin::{decrypt_identity_keys, encrypt_identity_keys, PinError};
102
103// Re-export scoped keyring
104pub use scoped_keyring::{ScopedAccessToken, ScopedKeyRing};
105
106// Re-export vault
107pub use vault::KeyVault;