chie_crypto/
lib.rs

1//! Cryptographic primitives for CHIE Protocol.
2//!
3//! This crate provides:
4//! - Content encryption using ChaCha20-Poly1305
5//! - Digital signatures using Ed25519
6//! - Aggregate signatures for multi-peer coordination
7//! - Fast hashing using BLAKE3
8//! - Key derivation using HKDF
9//! - Constant-time comparison utilities
10//! - Streaming encryption for large content
11//! - Key serialization (PEM, hex, base64)
12//! - Key rotation and management utilities
13//! - HSM/TPM integration for enterprise deployments
14//! - PKCS#11 provider interface for hardware security modules
15//! - Multi-party key generation ceremony orchestration
16//! - Certificate management and key revocation (CRL/OCSP-like)
17//! - Secure key storage with encryption at rest
18//! - Cryptographic commitments and proof-of-possession
19//! - Verifiable Random Functions (VRF) for unpredictable challenges
20//! - Blind signatures for privacy-preserving tokens
21//! - Shamir's secret sharing for key backup and recovery
22//! - Merkle trees for efficient content verification
23//! - Zero-knowledge range proofs for privacy-preserving verification
24//! - X25519 key exchange for secure P2P channels
25//! - Pedersen commitments for homomorphic bandwidth aggregation
26//! - HMAC-based authentication for message integrity
27//! - Cryptographic accumulators for efficient set membership
28//! - Ring signatures for anonymous signing within a group
29//! - Ring CT (Confidential Transactions) for privacy-preserving value transfers
30//! - Linkable ring signatures for double-spend prevention
31//! - Time-lock encryption for scheduled content release
32//! - Onion encryption for privacy-preserving P2P routing
33//! - Proof of Storage for verifiable content retention
34//! - Bulletproofs for efficient range proofs
35//! - Distributed Key Generation (DKG) for decentralized setup
36//! - Polynomial commitments for batch verification
37//! - Verifiable Delay Functions (VDF) for time-based proofs
38//! - BLS signatures for superior signature aggregation
39//! - BBS+ signatures for selective disclosure and privacy-preserving credentials
40//! - Schnorr signatures for simplicity and provable security
41//! - ElGamal encryption for homomorphic operations
42//! - Paillier homomorphic encryption for privacy-preserving aggregation
43//! - Proxy re-encryption for delegated decryption
44//! - Oblivious transfer for private information retrieval
45//! - Post-quantum key encapsulation with CRYSTALS-Kyber
46//! - Post-quantum signatures with CRYSTALS-Dilithium
47//! - Stateless hash-based signatures with SPHINCS+
48//! - Private Set Intersection (PSI) for privacy-preserving P2P discovery
49//! - Forward-Secure Signatures for key evolution and retroactive security
50//! - FROST (Flexible Round-Optimized Schnorr Threshold) signatures for efficient threshold signing
51//! - Functional Encryption (FE) with Inner Product support for privacy-preserving computation
52//! - Differential Privacy mechanisms for privacy-preserving data analysis
53//! - Anonymous Credentials (Idemix-style) for privacy-preserving authentication
54//! - Searchable Encryption for encrypted content indexing
55//! - Certified Deletion for provable data removal
56//! - Garbled Circuits for secure two-party computation
57//! - SPAKE2 password-authenticated key exchange
58//! - SRP (Secure Remote Password) protocol for password-based authentication
59//! - OPRF (Oblivious Pseudorandom Function) for private protocols
60//! - Identity-Based Encryption (IBE) for simplified key management
61//! - Aggregate MAC for efficient multi-message authentication
62//! - Advanced commitment schemes with opening proofs
63//! - MuSig2 multi-signature aggregation for efficient multi-party signing
64//! - Adaptor signatures for atomic swaps and scriptless scripts
65//! - Threshold ECDSA for distributed signature generation
66//! - Zero-knowledge proof composition framework for complex protocols
67//! - OpenPGP key format compatibility for Ed25519 keys
68//! - OpenSSH key format support for SSH key import/export
69//! - TLS 1.3 key schedule support (RFC 8446)
70//! - WebCrypto API compatibility layer for browser interoperability
71//! - Attribute-Based Encryption (ABE) for fine-grained access control
72//! - Cryptographic operation audit logging for compliance and forensics
73//! - FIPS 140-3 compliance reporting and self-tests
74//! - Key usage policy enforcement for access control and compliance
75//! - Entropy quality monitoring for RNG health and security
76//! - Side-channel resistance verification for timing attack detection
77//! - Formal verification helpers for property-based testing
78//! - Utility functions for file encryption and message handling
79//! - Zeroizing wrappers for sensitive data
80
81pub mod abe;
82pub mod accumulator;
83pub mod adaptor;
84pub mod advanced_commitment;
85pub mod aggregate;
86pub mod aggregate_mac;
87pub mod anonymous_credentials;
88pub mod audit_log;
89pub mod bbs_plus;
90pub mod blind;
91pub mod bls;
92pub mod bulletproof;
93pub mod cache_timing;
94pub mod cert_manager;
95pub mod certified_deletion;
96mod codec;
97pub mod commitment;
98pub mod compliance;
99pub mod ct;
100pub mod ct_audit;
101pub mod differential_privacy;
102pub mod dilithium;
103pub mod dkg;
104pub mod elgamal;
105pub mod encryption;
106pub mod entropy;
107pub mod formal_verify;
108pub mod forward_secure;
109pub mod frost;
110pub mod functional_encryption;
111pub mod garbled_circuit;
112pub mod hash;
113pub mod hmac;
114pub mod hsm;
115pub mod ibe;
116pub mod kdf;
117pub mod key_backup;
118pub mod key_formats;
119pub mod key_policy;
120pub mod key_rotation_scheduler;
121pub mod keyexchange;
122pub mod keygen_ceremony;
123pub mod keyserde;
124pub mod keystore;
125pub mod kyber;
126pub mod linkable_ring;
127pub mod merkle;
128pub mod musig2;
129pub mod onion;
130pub mod openpgp;
131pub mod openssh;
132pub mod oprf;
133pub mod ot;
134pub mod paillier;
135pub mod pbkdf;
136pub mod pedersen;
137pub mod pkcs11;
138pub mod polycommit;
139pub mod pos;
140pub mod proxy_re;
141pub mod psi;
142pub mod rangeproof;
143pub mod ring;
144pub mod ringct;
145pub mod rotation;
146pub mod schnorr;
147pub mod searchable;
148pub mod shamir;
149pub mod sidechannel;
150pub mod signing;
151pub mod simd;
152pub mod spake2;
153pub mod sphincs;
154pub mod srp;
155pub mod streaming;
156pub mod threshold;
157pub mod threshold_ecdsa;
158pub mod timelock;
159pub mod tls13;
160pub mod utils;
161pub mod vdf_delay;
162pub mod vrf;
163pub mod webcrypto;
164pub mod zeroizing;
165pub mod zkproof;
166
167pub use abe::{
168    AbeAuthority, AbeCiphertext, AbeError, AbeResult, AccessPolicy, MasterSecretKey, PolicyNode,
169    UserSecretKey,
170};
171pub use accumulator::{
172    AccumulatorDigest, AccumulatorError, AccumulatorResult, BloomAccumulator, CompactAccumulator,
173    HashAccumulator, MembershipProof, hash_element,
174};
175pub use adaptor::{
176    AdaptorError, AdaptorPoint, AdaptorPublicKey, AdaptorResult, AdaptorSecret, AdaptorSecretKey,
177    AdaptorSignature, AdaptorSigner, PreSignature, complete_signature, extract_secret,
178    verify_adaptor_signature, verify_pre_signature,
179};
180pub use advanced_commitment::{
181    AdvancedCommitmentError, AdvancedCommitmentResult, ExtractableCom, ExtractableCommitment,
182    ExtractableOpening, Trapdoor, TrapdoorCom, TrapdoorCommitment, TrapdoorOpening, VectorCom,
183    VectorCommitment, VectorOpening,
184};
185pub use aggregate::{
186    AggregateError, AggregateResult, AggregateSignature, SignatureAggregator, verify_batch,
187};
188pub use aggregate_mac::{
189    AggregateMacBuilder, AggregateMacError, AggregateMacKey, AggregateMacResult, AggregateTag,
190    MacTag,
191};
192pub use anonymous_credentials::{
193    AnonCredError, AnonCredResult, AnonymousCredential, CredentialPresentation, CredentialRequest,
194    Issuer, IssuerPublicKey, User,
195};
196pub use audit_log::{AuditEntry, AuditLog, AuditStatistics, OperationType, SeverityLevel};
197pub use bbs_plus::{
198    BbsPlusError, BbsPlusKeypair, BbsPlusProof, BbsPlusPublicKey, BbsPlusResult, BbsPlusSecretKey,
199    BbsPlusSignature, create_proof as bbs_create_proof, sign_messages as bbs_sign_messages,
200    verify_proof as bbs_verify_proof, verify_signature as bbs_verify_signature,
201};
202pub use blind::{
203    BlindError, BlindPublicKey, BlindResult, BlindSignatureProtocol, BlindSigner, BlindingFactor,
204    RedeemableToken, SignedCommitment, TokenCommitment, UnlinkableToken,
205};
206pub use bls::{
207    BlsError, BlsKeypair, BlsPublicKey, BlsResult, BlsSecretKey, BlsSignature,
208    aggregate_signatures, verify_aggregated as verify_bls_aggregated,
209};
210pub use bulletproof::{
211    AggregatedBulletproof, BulletproofCommitment, BulletproofError, BulletproofParams,
212    BulletproofRangeProof, BulletproofResult, prove_range, prove_range_aggregated,
213    verify_aggregated, verify_range,
214};
215pub use cache_timing::{
216    ByteLookup, CacheAligned, CacheTimingError, CacheTimingResult, ConstantTimeLookup,
217    conditional_swap, constant_time_clamp_index, constant_time_memcmp, prefetch_array,
218    prefetch_read,
219};
220pub use certified_deletion::{
221    BatchDeletion, CertifiedDeletion, CertifiedDeletionError, CertifiedDeletionResult,
222    DeletionCertificate, EncryptedWithWitness,
223};
224pub use commitment::{
225    BandwidthProofCommitment, ChunkChallenge, ChunkPossessionProof, Commitment, CommitmentError,
226    CommitmentOpening, KeyPossessionProof, commit, generate_challenge, verify_commitment,
227};
228pub use compliance::{
229    ComplianceAlgorithm, ComplianceChecker, ComplianceIssue, ComplianceReport, ComplianceStatus,
230    IssueSeverity, SecurityLevel, SelfTestResult, SelfTestResults,
231};
232pub use ct::*;
233pub use ct_audit::{
234    CtAuditError, CtAuditResult, CtAuditor, OperationBenchmark, TimingStatistics, measure_average,
235    measure_once,
236};
237pub use differential_privacy::{
238    DPError, DPResult, ExponentialMechanism, GaussianMechanism, LaplaceMechanism, PrivacyBudget,
239};
240pub use dilithium::{
241    Dilithium2, Dilithium2PublicKey, Dilithium2SecretKey, Dilithium2Signature, Dilithium3,
242    Dilithium3PublicKey, Dilithium3SecretKey, Dilithium3Signature, Dilithium5, Dilithium5PublicKey,
243    Dilithium5SecretKey, Dilithium5Signature, DilithiumError, DilithiumResult,
244};
245pub use dkg::{
246    DkgCommitments, DkgError, DkgParams, DkgParticipant, DkgResult, DkgShare, aggregate_public_key,
247};
248pub use elgamal::{
249    ElGamalCiphertext, ElGamalError, ElGamalKeypair, ElGamalPublicKey, ElGamalResult,
250    ElGamalSecretKey, decrypt as elgamal_decrypt, encrypt as elgamal_encrypt,
251};
252pub use encryption::*;
253pub use entropy::{EntropyError, EntropyMonitor, EntropyQuality, EntropyResult, EntropySource};
254pub use formal_verify::{
255    Invariant, PostCondition, PreCondition, PropertyCheckResult, PropertyChecker, PropertyResult,
256    StateMachine, VerificationCondition, check_invariant, check_postcondition, check_precondition,
257};
258pub use forward_secure::{
259    ForwardSecureBuilder, ForwardSecureError, ForwardSecureKeypair, ForwardSecurePublicKey,
260    ForwardSecureResult, ForwardSecureSignature,
261};
262pub use frost::{
263    FrostError, FrostKeygen, FrostNonceCommitment, FrostResult, FrostSecretShare, FrostSigner,
264    PartialSignature as FrostPartialSignature, aggregate_frost_signatures, verify_frost_signature,
265};
266pub use functional_encryption::{
267    FunctionalEncryptionError, FunctionalEncryptionResult, IpfeCiphertext, IpfeFunctionalKey,
268    IpfeMasterPublicKey, IpfeMasterSecretKey, MultiClientIpfe, ipfe_decrypt, ipfe_encrypt,
269    ipfe_keygen, ipfe_setup,
270};
271pub use garbled_circuit::{
272    Circuit, GarbledCircuit, GarbledCircuitError, GarbledCircuitResult, Gate, GateType, WireLabel,
273};
274pub use hash::*;
275pub use hmac::{
276    AuthenticatedMessage, HmacError, HmacKey, HmacResult, HmacTag, compute_hmac,
277    compute_hmac_blake3, compute_hmac_sha256, compute_tagged_hmac, verify_hmac, verify_hmac_blake3,
278    verify_hmac_sha256, verify_tagged_hmac,
279};
280pub use hsm::{
281    HsmError, HsmManager, HsmManagerBuilder, HsmResult, KeyId, KeyMetadata, Pkcs11Config,
282    Pkcs11Provider, SigningProvider, SoftwareProvider, TpmConfig, TpmHierarchy, TpmProvider,
283};
284pub use ibe::{IbeCiphertext, IbeError, IbeMaster, IbeParams, IbeResult, IbeSecretKey};
285pub use kdf::*;
286pub use key_backup::{
287    BackupConfig, BackupError, BackupResult, BackupShare, EncryptedBackup,
288    KeyType as BackupKeyType, backup_key_encrypted, backup_key_shamir, backup_secret_encrypted,
289    backup_secret_shamir, recover_key_encrypted, recover_key_shamir, recover_secret_encrypted,
290    recover_secret_shamir,
291};
292pub use key_formats::{DerKey, JwkKey, KeyFormatError, KeyFormatResult};
293pub use key_policy::{KeyPolicy, KeyUsagePolicy, Operation, PolicyEngine, PolicyViolation};
294pub use key_rotation_scheduler::{
295    KeyMetadata as RotationKeyMetadata, KeyRotationPolicy, KeyRotationScheduler,
296};
297pub use keyexchange::{
298    KeyExchange, KeyExchangeError, KeyExchangeKeypair, KeyExchangeResult, SharedSecret,
299    ephemeral_keypair, exchange_and_derive,
300};
301pub use keyserde::*;
302pub use keystore::{
303    KeyMetadata as KeyStoreMetadata, KeyStoreError, KeyStoreResult, KeyType, SecureKeyStore,
304};
305pub use kyber::{
306    Kyber512, Kyber512Ciphertext, Kyber512PublicKey, Kyber512SecretKey, Kyber512SharedSecret,
307    Kyber768, Kyber768Ciphertext, Kyber768PublicKey, Kyber768SecretKey, Kyber768SharedSecret,
308    Kyber1024, Kyber1024Ciphertext, Kyber1024PublicKey, Kyber1024SecretKey, Kyber1024SharedSecret,
309    KyberError, KyberResult,
310};
311pub use linkable_ring::{
312    KeyImageDb, LinkableRingError, LinkableRingResult, LinkableRingSignature, check_double_sign,
313    sign_linkable, verify_linkable,
314};
315pub use merkle::{
316    IncrementalMerkleBuilder, MerkleError, MerkleProof, MerkleResult, MerkleTree, MultiProof,
317};
318pub use musig2::{
319    MuSig2Error, MuSig2Nonce, MuSig2PublicKey, MuSig2Result, MuSig2SecretKey, MuSig2Signature,
320    MuSig2Signer, NonceCommitment, PartialSignature, SigningNonce, aggregate_nonces,
321    aggregate_partial_signatures, aggregate_partial_signatures_with_nonce, aggregate_public_keys,
322    verify_musig2,
323};
324pub use onion::{
325    OnionBuilder, OnionError, OnionLayer, OnionPacket, OnionResult, OnionRoute, create_onion,
326};
327pub use openpgp::{OpenPgpError, OpenPgpPublicKey, OpenPgpResult, OpenPgpSecretKey};
328pub use openssh::{SshKeyError, SshKeyResult, SshPrivateKey, SshPublicKey};
329pub use oprf::{
330    BatchOprfClient, BlindedInput, BlindedOutput, OprfClient, OprfError, OprfOutput, OprfResult,
331    OprfServer,
332};
333pub use ot::{OTError, OTReceiver, OTRequest, OTResponse, OTResult, OTSender};
334pub use paillier::{
335    PaillierCiphertext, PaillierKeypair, PaillierPrivateKey, PaillierPublicKey,
336    decrypt as paillier_decrypt, encrypt as paillier_encrypt,
337};
338pub use pbkdf::*;
339pub use pedersen::{PedersenCommitment, PedersenError, PedersenOpening, PedersenResult};
340pub use pkcs11::{Pkcs11MockProvider, Pkcs11Session, SessionState};
341pub use polycommit::{
342    BatchEvaluationProof, EvaluationProof, PolyBlinding, PolyCommitError, PolyCommitParams,
343    PolyCommitResult, PolyCommitment, commit_polynomial, prove_batch_evaluations, prove_evaluation,
344    verify_batch_evaluations, verify_evaluation,
345};
346pub use pos::{
347    AuditSession, Challenge, DEFAULT_CHUNK_SIZE, PosResult, ProofOfStorageError, StorageProof,
348    StorageProver, StorageVerifier,
349};
350pub use proxy_re::{
351    ProxyReCiphertext, ProxyReError, ProxyReKeypair, ProxyRePublicKey, ProxyReReKey, ProxyReResult,
352    ProxyReSecretKey, decrypt as proxy_re_decrypt, encrypt as proxy_re_encrypt, generate_re_key,
353    re_encrypt,
354};
355pub use psi::{
356    BloomPsiClient, BloomPsiMessage, BloomPsiServer, PsiClient, PsiError, PsiResult, PsiServer,
357    PsiServerMessage,
358};
359pub use rangeproof::{BatchRangeProof, RangeProof, RangeProofError, RangeProofResult};
360pub use ring::{
361    RingError, RingResult, RingSignature, RingSignatureBuilder, sign_ring, verify_ring,
362};
363pub use ringct::{
364    RingCtBuilder, RingCtError, RingCtInput, RingCtOutput, RingCtResult, RingCtTransaction,
365};
366pub use rotation::{
367    EncryptedKey, EncryptionKeyRing, KeyVersion, ReEncryptor, RotationError, RotationPolicy,
368    SigningKeyRing,
369};
370pub use schnorr::{
371    SchnorrError, SchnorrKeypair, SchnorrPublicKey, SchnorrResult, SchnorrSecretKey,
372    SchnorrSignature, batch_verify as schnorr_batch_verify,
373};
374pub use searchable::{
375    DocumentId, EncryptedIndex, EncryptedIndexBuilder, MultiKeywordSearch, SearchableEncryption,
376    SearchableError, SearchableResult,
377};
378pub use shamir::{
379    ShamirError, ShamirResult, Share, reconstruct, reconstruct_key_32, split, split_key_32,
380};
381pub use sidechannel::{
382    SideChannelAnalysis, SideChannelAnalyzer, TimingTest, Vulnerability, VulnerabilitySeverity,
383};
384pub use signing::*;
385pub use simd::{
386    SimdError, SimdResult, batch_constant_time_eq, constant_time_eq, parallel_hash,
387    parallel_hash_with_threads, secure_copy, secure_zero as simd_secure_zero, xor_buffers,
388    xor_keystream,
389};
390pub use spake2::{
391    Spake2, Spake2Error, Spake2Message, Spake2Result, Spake2SharedSecret, Spake2Side,
392};
393pub use sphincs::{
394    SphincsError, SphincsResult, SphincsSHAKE128f, SphincsSHAKE128fPublicKey,
395    SphincsSHAKE128fSecretKey, SphincsSHAKE128fSignature, SphincsSHAKE192f,
396    SphincsSHAKE192fPublicKey, SphincsSHAKE192fSecretKey, SphincsSHAKE192fSignature,
397    SphincsSHAKE256f, SphincsSHAKE256fPublicKey, SphincsSHAKE256fSecretKey,
398    SphincsSHAKE256fSignature,
399};
400pub use srp::{
401    SrpClient, SrpError, SrpPublicKey, SrpResult, SrpServer, SrpSessionKey, SrpVerifier,
402};
403pub use streaming::*;
404pub use threshold::{
405    MultiSig, MultiSigBuilder, ThresholdCoordinator, ThresholdError, ThresholdSig,
406};
407pub use threshold_ecdsa::{
408    NonceShare, PublicNonceShare, PublicShare, SecretShare, ThresholdEcdsaError,
409    ThresholdEcdsaResult, ThresholdEcdsaSignature, ThresholdEcdsaSigner, ThresholdPartialSignature,
410    aggregate_threshold_public_key, aggregate_threshold_signatures, generate_threshold_keys,
411    verify_threshold_ecdsa,
412};
413pub use timelock::{
414    TimeLockCiphertext, TimeLockError, TimeLockPuzzle, TimeLockResult, TimeParams,
415    timelock_decrypt, timelock_encrypt, timelock_encrypt_with_puzzle,
416};
417pub use tls13::{Tls13Error, Tls13KeySchedule, Tls13Result, derive_traffic_keys};
418pub use utils::{
419    EncryptedAndSigned, EncryptedMessage, SignedMessage, UtilError, UtilResult, decrypt_file,
420    encrypt_file, generate_and_save_key, load_key,
421};
422pub use vdf_delay::{
423    VdfError, VdfOutput, VdfParams, VdfProof, VdfResult, vdf_compute, vdf_randomness_beacon,
424    vdf_verify,
425};
426pub use vrf::{
427    VrfError, VrfProof, VrfPublicKey, VrfResult, VrfSecretKey, generate_bandwidth_challenge,
428    verify_bandwidth_challenge,
429};
430pub use webcrypto::{
431    Algorithm, KeyType as WebCryptoKeyType, KeyUsage, WebCryptoError, WebCryptoKey,
432    WebCryptoKeyPair, WebCryptoResult,
433};
434pub use zeroizing::{
435    SecureBuffer, ZeroizingKey, secure_move, secure_zero, zeroizing_key_32, zeroizing_nonce,
436};
437pub use zkproof::{
438    AndProof, OrProof, ZkProof, ZkProofBuilder, ZkProofError, ZkProofResult, ZkProvable,
439    create_binding,
440};