diff --git a/ciphers/src/subtle/chacha20poly1305_ietf_libcrux.rs b/ciphers/src/subtle/chacha20poly1305_ietf_libcrux.rs index ccf9735..08082dd 100644 --- a/ciphers/src/subtle/chacha20poly1305_ietf_libcrux.rs +++ b/ciphers/src/subtle/chacha20poly1305_ietf_libcrux.rs @@ -1,3 +1,4 @@ +use std::fmt::format; use rosenpass_to::ops::copy_slice; use rosenpass_to::To; @@ -101,12 +102,18 @@ pub fn decrypt( let (ciphertext, mac) = ciphertext.split_at(ciphertext.len() - TAG_LEN); use libcrux::aead as C; - let crux_key = C::Key::Chacha20Poly1305(C::Chacha20Key(key.try_into().unwrap())); - let crux_iv = C::Iv(nonce.try_into().unwrap()); - let crux_tag = C::Tag::from_slice(mac).unwrap(); + let crux_key = C::Key::Chacha20Poly1305(C::Chacha20Key(key.try_into()?)); + let crux_iv = C::Iv(nonce.try_into()?); + let crux_tag = match C::Tag::from_slice(mac) { + Ok(tag) => tag, + Err(err) => return Err(anyhow::anyhow!(format!("{:?}", err))), + }; copy_slice(ciphertext).to(plaintext); - libcrux::aead::decrypt(&crux_key, plaintext, crux_iv, ad, &crux_tag).unwrap(); + let dec_res = libcrux::aead::decrypt(&crux_key, plaintext, crux_iv, ad, &crux_tag); + if dec_res.is_err() { + return Err(anyhow::anyhow!("Decryption failed {:?}", dec_res.err())); + } match crux_key { C::Key::Chacha20Poly1305(mut k) => k.0.zeroize(),