|
| 1 | +use ssh_cipher::Cipher; |
| 2 | + |
| 3 | +#[test] |
| 4 | +fn round_trip() { |
| 5 | + const MSG: &[u8] = b"Testing 1 2 3..."; |
| 6 | + const CIPHERS: &[Cipher] = &[ |
| 7 | + #[cfg(feature = "aes-cbc")] |
| 8 | + Cipher::Aes128Cbc, |
| 9 | + #[cfg(feature = "aes-cbc")] |
| 10 | + Cipher::Aes192Cbc, |
| 11 | + #[cfg(feature = "aes-cbc")] |
| 12 | + Cipher::Aes256Cbc, |
| 13 | + #[cfg(feature = "aes-ctr")] |
| 14 | + Cipher::Aes128Ctr, |
| 15 | + #[cfg(feature = "aes-ctr")] |
| 16 | + Cipher::Aes192Ctr, |
| 17 | + #[cfg(feature = "aes-ctr")] |
| 18 | + Cipher::Aes256Ctr, |
| 19 | + #[cfg(feature = "aes-gcm")] |
| 20 | + Cipher::Aes128Gcm, |
| 21 | + #[cfg(feature = "aes-gcm")] |
| 22 | + Cipher::Aes256Gcm, |
| 23 | + #[cfg(feature = "chacha20poly1305")] |
| 24 | + Cipher::ChaCha20Poly1305, |
| 25 | + #[cfg(feature = "tdes")] |
| 26 | + Cipher::TDesCbc, |
| 27 | + ]; |
| 28 | + |
| 29 | + for &cipher in CIPHERS { |
| 30 | + let (key_len, iv_len) = cipher.key_and_iv_size().unwrap(); |
| 31 | + |
| 32 | + // TODO(tarcieri): randomize keys? |
| 33 | + let key = vec![0; key_len]; |
| 34 | + let iv = vec![0; iv_len]; |
| 35 | + let mut buffer = Vec::from(MSG); |
| 36 | + |
| 37 | + let tag = cipher.encrypt(&key, &iv, &mut buffer).unwrap(); |
| 38 | + assert_ne!(buffer, MSG); |
| 39 | + |
| 40 | + cipher.decrypt(&key, &iv, &mut buffer, tag).unwrap(); |
| 41 | + assert_eq!(buffer, MSG); |
| 42 | + } |
| 43 | +} |
0 commit comments