Test: Internal counter overflow
@@ -243,6 +243,23 @@ fn test_err_on_empty_pt() {
chacha20_encrypt(&[0u8; 32], &[0u8; 12], 0, &[0u8; 0], &mut dst).unwrap();
}
+#[test]
+#[should_panic]
+fn test_panic_on_inital_counter_overflow() {
+
+ let mut dst = [0u8; 65];
+
+ chacha20_encrypt(&[0u8; 32], &[0u8; 12], 4294967295, &[0u8; 65], &mut dst).unwrap();
+}
+
+#[test]
+fn test_pass_on_one_iter_max_initial_counter() {
+
+ let mut dst = [0u8; 64];
+ // Should pass because only one iteration is completed, so block_counter will not increase
+ chacha20_encrypt(&[0u8; 32], &[0u8; 12], 4294967295, &[0u8; 64], &mut dst).unwrap();
+}
+
#[cfg(test)]
// Convenience function for testing.
fn init(key: &[u8], nonce: &[u8]) -> Result<InternalState, UnknownCryptoError> {
