pub struct Ciphertext<G: Group> { /* private fields */ }
Expand description
Ciphertext for ElGamal encryption.
A ciphertext consists of 2 group elements: the random element R
and a blinded encrypted
value B
. If the ciphertext encrypts integer value v
, it holds that
R = [r]G;
B = [v]G + [r]K = [v]G + [k]R;
where:
G
is the conventional group generatorr
is a random scalar selected by the encrypting partyK
andk
are the recipient’s public and private keys, respectively.
Ciphertexts are partially homomorphic: they can be added together or multiplied by a scalar value.
§Examples
Basic usage and arithmetic for ciphertexts:
// Generate a keypair for the ciphertext receiver.
let mut rng = thread_rng();
let receiver = Keypair::<Ristretto>::generate(&mut rng);
// Create a couple of ciphertexts.
let mut enc = receiver.public().encrypt(2_u64, &mut rng);
enc += receiver.public().encrypt(3_u64, &mut rng) * 4;
// Check that the ciphertext decrypts to 2 + 3 * 4 = 14.
let lookup_table = DiscreteLogTable::new(0..20);
let decrypted = receiver.secret().decrypt(enc, &lookup_table);
assert_eq!(decrypted, Some(14));
Creating a ciphertext of a boolean value together with a proof:
// Generate a keypair for the ciphertext receiver.
let mut rng = thread_rng();
let receiver = Keypair::<Ristretto>::generate(&mut rng);
// Create and verify a boolean encryption.
let (enc, proof) =
receiver.public().encrypt_bool(false, &mut rng);
receiver.public().verify_bool(enc, &proof)?;
Creating a ciphertext of an integer value together with a range proof:
// Generate the ciphertext receiver.
let mut rng = thread_rng();
let receiver = Keypair::<Ristretto>::generate(&mut rng);
// Find the optimal range decomposition for our range
// and specialize it for the Ristretto group.
let range = RangeDecomposition::optimal(100).into();
let (ciphertext, proof) = receiver
.public()
.encrypt_range(&range, 42, &mut rng);
// Check that the the proof verifies.
receiver.public().verify_range(&range, ciphertext, &proof)?;
Implementations§
Source§impl<G: Group> Ciphertext<G>
impl<G: Group> Ciphertext<G>
Sourcepub fn non_blinded<T>(value: T) -> Self
pub fn non_blinded<T>(value: T) -> Self
Creates a non-blinded encryption of the specified scalar value
, i.e., (O, [value]G)
where O
is identity and G
is the conventional group generator.
Sourcepub fn random_element(&self) -> &G::Element
pub fn random_element(&self) -> &G::Element
Returns a reference to the random element.
Sourcepub fn blinded_element(&self) -> &G::Element
pub fn blinded_element(&self) -> &G::Element
Returns a reference to the blinded element.
Trait Implementations§
Source§impl<G: Group> Add for Ciphertext<G>
impl<G: Group> Add for Ciphertext<G>
Source§impl<G: Group> AddAssign for Ciphertext<G>
impl<G: Group> AddAssign for Ciphertext<G>
Source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
Performs the
+=
operation. Read moreSource§impl<G: Clone + Group> Clone for Ciphertext<G>
impl<G: Clone + Group> Clone for Ciphertext<G>
Source§fn clone(&self) -> Ciphertext<G>
fn clone(&self) -> Ciphertext<G>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<G: Group> Debug for Ciphertext<G>
impl<G: Group> Debug for Ciphertext<G>
Source§impl<'de, G: Group> Deserialize<'de> for Ciphertext<G>
impl<'de, G: Group> Deserialize<'de> for Ciphertext<G>
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<G: Group, V: Zeroize> From<CiphertextWithValue<G, V>> for Ciphertext<G>
impl<G: Group, V: Zeroize> From<CiphertextWithValue<G, V>> for Ciphertext<G>
Source§fn from(ciphertext: CiphertextWithValue<G, V>) -> Self
fn from(ciphertext: CiphertextWithValue<G, V>) -> Self
Converts to this type from the input type.
Source§impl<G: Group> Neg for Ciphertext<G>
impl<G: Group> Neg for Ciphertext<G>
Source§impl<G: Group> Serialize for Ciphertext<G>
impl<G: Group> Serialize for Ciphertext<G>
Source§impl<G: Group> Sub for Ciphertext<G>
impl<G: Group> Sub for Ciphertext<G>
Source§impl<G: Group> SubAssign for Ciphertext<G>
impl<G: Group> SubAssign for Ciphertext<G>
Source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
Performs the
-=
operation. Read moreimpl<G: Copy + Group> Copy for Ciphertext<G>
Auto Trait Implementations§
impl<G> Freeze for Ciphertext<G>
impl<G> RefUnwindSafe for Ciphertext<G>
impl<G> Send for Ciphertext<G>
impl<G> Sync for Ciphertext<G>
impl<G> Unpin for Ciphertext<G>
impl<G> UnwindSafe for Ciphertext<G>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)