MCPcopy Create free account
hub / github.com/DNSCrypt/encrypted-dns-server / decrypt

Method decrypt

src/crypto.rs:215–240  ·  view source on GitHub ↗
(&self, nonce: &[u8], encrypted: &[u8])

Source from the content-addressed store, hash-verified

213 }
214
215 pub fn decrypt(&self, nonce: &[u8], encrypted: &[u8]) -> Result<Vec<u8>, Error> {
216 let encrypted_len = encrypted.len();
217 ensure!(
218 encrypted_len >= crypto_box_curve25519xchacha20poly1305_MACBYTES as usize,
219 "Unable to decrypt"
220 );
221 let mut decrypted =
222 vec![0u8; encrypted_len - crypto_box_curve25519xchacha20poly1305_MACBYTES as usize];
223 let res = unsafe {
224 libsodium_sys::crypto_box_curve25519xchacha20poly1305_open_easy_afternm(
225 decrypted.as_mut_ptr(),
226 encrypted.as_ptr(),
227 encrypted_len as _,
228 nonce.as_ptr(),
229 self.0.as_ptr(),
230 )
231 };
232 ensure!(res == 0, "Unable to decrypt");
233 let idx = decrypted
234 .iter()
235 .rposition(|x| *x != 0x00)
236 .ok_or_else(|| anyhow!("Padding error"))?;
237 ensure!(decrypted[idx] == 0x80, "Padding error");
238 decrypted.truncate(idx);
239 Ok(decrypted)
240 }
241
242 pub fn encrypt_into(
243 &self,

Callers 3

decryptFunction · 0.80
decrypt_pq_ciphertextFunction · 0.80
decrypt_pq_resumedFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected