X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Futil%2Fchacha20poly1305rfc.rs;h=1d3af1ea32072b4622756dcb8ef292921293904b;hb=f0bcb7dba0360f04afacfff63ec2598d39bddc5f;hp=1aeaf61d21a4054502cd3ec1e076b67a1bf24c96;hpb=3db5798246a9bfdcabee60d27740ba8783b27e22;p=rust-lightning diff --git a/src/util/chacha20poly1305rfc.rs b/src/util/chacha20poly1305rfc.rs index 1aeaf61d..1d3af1ea 100644 --- a/src/util/chacha20poly1305rfc.rs +++ b/src/util/chacha20poly1305rfc.rs @@ -12,19 +12,15 @@ #[cfg(not(feature = "fuzztarget"))] mod real_chachapoly { - use crypto::aead::{AeadEncryptor,AeadDecryptor}; - use crypto::symmetriccipher::SynchronousStreamCipher; - use crypto::poly1305::Poly1305; - use crypto::mac::Mac; - use crypto::util::fixed_time_eq; - - pub use crypto::chacha20::ChaCha20; + use util::chacha20::ChaCha20; + use util::poly1305::Poly1305; + use bitcoin_hashes::cmp::fixed_time_eq; use util::byte_utils; #[derive(Clone, Copy)] pub struct ChaCha20Poly1305RFC { - cipher : ChaCha20, + cipher: ChaCha20, mac: Poly1305, finished: bool, data_len: usize, @@ -62,10 +58,8 @@ mod real_chachapoly { aad_len: aad.len() as u64, } } - } - impl AeadEncryptor for ChaCha20Poly1305RFC { - fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) { + pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) { assert!(input.len() == output.len()); assert!(self.finished == false); self.cipher.process(input, output); @@ -77,10 +71,8 @@ mod real_chachapoly { self.mac.input(&byte_utils::le64_to_array(self.data_len as u64)); self.mac.raw_result(out_tag); } - } - impl AeadDecryptor for ChaCha20Poly1305RFC { - fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool { + pub fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool { assert!(input.len() == output.len()); assert!(self.finished == false); @@ -105,13 +97,10 @@ mod real_chachapoly { } } #[cfg(not(feature = "fuzztarget"))] -pub use self::real_chachapoly::{ChaCha20Poly1305RFC, ChaCha20}; +pub use self::real_chachapoly::ChaCha20Poly1305RFC; #[cfg(feature = "fuzztarget")] mod fuzzy_chachapoly { - use crypto::aead::{AeadEncryptor,AeadDecryptor}; - use crypto::symmetriccipher::SynchronousStreamCipher; - #[derive(Clone, Copy)] pub struct ChaCha20Poly1305RFC { tag: [u8; 16], @@ -133,10 +122,8 @@ mod fuzzy_chachapoly { finished: false, } } - } - impl AeadEncryptor for ChaCha20Poly1305RFC { - fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) { + pub fn encrypt(&mut self, input: &[u8], output: &mut [u8], out_tag: &mut [u8]) { assert!(input.len() == output.len()); assert!(self.finished == false); @@ -144,10 +131,8 @@ mod fuzzy_chachapoly { out_tag.copy_from_slice(&self.tag); self.finished = true; } - } - impl AeadDecryptor for ChaCha20Poly1305RFC { - fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool { + pub fn decrypt(&mut self, input: &[u8], output: &mut [u8], tag: &[u8]) -> bool { assert!(input.len() == output.len()); assert!(self.finished == false); @@ -157,22 +142,6 @@ mod fuzzy_chachapoly { true } } - - pub struct ChaCha20 {} - - impl ChaCha20 { - pub fn new(key: &[u8], nonce: &[u8]) -> ChaCha20 { - assert!(key.len() == 16 || key.len() == 32); - assert!(nonce.len() == 8 || nonce.len() == 12); - Self {} - } - } - - impl SynchronousStreamCipher for ChaCha20 { - fn process(&mut self, input: &[u8], output: &mut [u8]) { - output.copy_from_slice(input); - } - } } #[cfg(feature = "fuzztarget")] -pub use self::fuzzy_chachapoly::{ChaCha20Poly1305RFC, ChaCha20}; +pub use self::fuzzy_chachapoly::ChaCha20Poly1305RFC;