diff --git a/src/aead/algorithm.rs b/src/aead/algorithm.rs index ee8e4da1c..2f1690292 100644 --- a/src/aead/algorithm.rs +++ b/src/aead/algorithm.rs @@ -12,7 +12,11 @@ // OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -use crate::{constant_time, cpu, error, hkdf}; +use crate::{ + constant_time, cpu, + error::{self, InputTooLongError}, + hkdf, +}; use core::ops::RangeFrom; use super::{ @@ -246,6 +250,7 @@ fn chacha20_poly1305_seal( _ => unreachable!(), }; chacha20_poly1305::seal(key, nonce, aad, in_out, cpu_features) + .map_err(error::erase::) } fn chacha20_poly1305_open( @@ -262,4 +267,5 @@ fn chacha20_poly1305_open( }; let in_out = Overlapping::new(in_out, src).map_err(error::erase::)?; chacha20_poly1305::open(key, nonce, aad, in_out, cpu_features) + .map_err(error::erase::) } diff --git a/src/aead/chacha20_poly1305.rs b/src/aead/chacha20_poly1305.rs index 2e84612a0..cb4e839ba 100644 --- a/src/aead/chacha20_poly1305.rs +++ b/src/aead/chacha20_poly1305.rs @@ -17,7 +17,8 @@ use super::{ poly1305, Aad, Nonce, Tag, }; use crate::{ - cpu, error, + cpu, + error::InputTooLongError, polyfill::{u64_from_usize, usize_from_u64_saturated}, }; @@ -43,11 +44,11 @@ pub(super) fn seal( aad: Aad<&[u8]>, in_out: &mut [u8], cpu_features: cpu::Features, -) -> Result { +) -> Result { let Key(chacha20_key) = key; if in_out.len() > MAX_IN_OUT_LEN { - return Err(error::Unspecified); + return Err(InputTooLongError::new(in_out.len())); } /// RFC 8439 Section 2.8 says the maximum AAD length is 2**64 - 1, which is /// never larger than usize::MAX, so we don't need an explicit length @@ -127,11 +128,11 @@ pub(super) fn open( aad: Aad<&[u8]>, in_out: Overlapping<'_>, cpu_features: cpu::Features, -) -> Result { +) -> Result { let Key(chacha20_key) = key; if in_out.len() > MAX_IN_OUT_LEN { - return Err(error::Unspecified); + return Err(InputTooLongError::new(in_out.len())); } // RFC 8439 Section 2.8 says the maximum AAD length is 2**64 - 1, which is // never larger than usize::MAX, so we don't need an explicit length