MCPcopy Create free account
hub / github.com/docknetwork/crypto / encrypt

Method encrypt

saver/src/encryption.rs:169–186  ·  view source on GitHub ↗

Encrypt a message `m` in exponent-Elgamal after breaking it into chunks of `chunk_bit_size` bits. Returns the ciphertext, commitment and randomness created for encryption. This is "Enc" from algorithm 2 in the paper Ciphertext vector contains commitment `psi` as the last element

(
        rng: &mut R,
        message: &E::ScalarField,
        ek: &EncryptionKey<E>,
        g_i: &[E::G1Affine],
        chunk_bit_size: u8,
    )

Source from the content-addressed store, hash-verified

167 /// 2 in the paper
168 /// Ciphertext vector contains commitment `psi` as the last element
169 pub fn encrypt<R: RngCore>(
170 rng: &mut R,
171 message: &E::ScalarField,
172 ek: &EncryptionKey<E>,
173 g_i: &[E::G1Affine],
174 chunk_bit_size: u8,
175 ) -> crate::Result<(Ciphertext<E>, E::ScalarField)> {
176 let decomposed = utils::decompose(message, chunk_bit_size)?;
177 let (mut ct, r) = Self::encrypt_decomposed_message(rng, decomposed, ek, g_i)?;
178 Ok((
179 Ciphertext {
180 X_r: ct.remove(0),
181 commitment: ct.remove(ct.len() - 1),
182 enc_chunks: ct,
183 },
184 r,
185 ))
186 }
187
188 /// Return the encryption and Groth16 proof
189 pub fn encrypt_with_proof<R: RngCore>(

Callers

nothing calls this directly

Calls 3

decomposeFunction · 0.70
removeMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected