solana_zk_sdk/encryption/mod.rs
1//! Collection of encryption-related data structures and algorithms used in the Solana zk-token
2//! protocol.
3//!
4//! The module contains implementations of the following cryptographic objects:
5//! - Pedersen commitments that uses the prime-order Ristretto representation of Curve25519.
6//! [curve25519-dalek](https://docs.rs/curve25519-dalek/latest/curve25519_dalek/ristretto/index.html)
7//! is used for the Ristretto group implementation.
8//! - The twisted ElGamal scheme, which converts Pedersen commitments into a public-key encryption
9//! scheme.
10//! - Basic type-wrapper around the AES-GCM-SIV symmetric authenticated encryption scheme
11//! implemented by [aes-gcm-siv](https://docs.rs/aes-gcm-siv/latest/aes_gcm_siv/) crate.
12
13use crate::{RISTRETTO_POINT_LEN, SCALAR_LEN};
14
15#[cfg(not(target_os = "solana"))]
16#[macro_use]
17pub(crate) mod macros;
18#[cfg(not(target_os = "solana"))]
19pub mod auth_encryption;
20#[cfg(not(target_os = "solana"))]
21pub mod discrete_log;
22#[cfg(not(target_os = "solana"))]
23pub mod elgamal;
24#[cfg(not(target_os = "solana"))]
25pub mod grouped_elgamal;
26#[cfg(not(target_os = "solana"))]
27pub mod pedersen;
28pub mod pod;
29
30/// Byte length of an authenticated encryption secret key
31pub const AE_KEY_LEN: usize = 16;
32
33/// Byte length of a complete authenticated encryption ciphertext component that includes the
34/// ciphertext and nonce components
35pub const AE_CIPHERTEXT_LEN: usize = 36;
36
37/// Byte length of a decrypt handle
38pub const DECRYPT_HANDLE_LEN: usize = RISTRETTO_POINT_LEN;
39
40/// Byte length of an ElGamal ciphertext
41pub const ELGAMAL_CIPHERTEXT_LEN: usize = PEDERSEN_COMMITMENT_LEN + DECRYPT_HANDLE_LEN;
42
43/// Byte length of an ElGamal public key
44pub const ELGAMAL_PUBKEY_LEN: usize = RISTRETTO_POINT_LEN;
45
46/// Byte length of an ElGamal secret key
47pub const ELGAMAL_SECRET_KEY_LEN: usize = SCALAR_LEN;
48
49/// Byte length of an ElGamal keypair
50pub const ELGAMAL_KEYPAIR_LEN: usize = ELGAMAL_PUBKEY_LEN + ELGAMAL_SECRET_KEY_LEN;
51
52/// Byte length of a Pedersen opening.
53pub const PEDERSEN_OPENING_LEN: usize = SCALAR_LEN;
54
55/// Byte length of a Pedersen commitment.
56pub const PEDERSEN_COMMITMENT_LEN: usize = RISTRETTO_POINT_LEN;