X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Futil%2Fchacha20poly1305rfc.rs;h=1aeaf61d21a4054502cd3ec1e076b67a1bf24c96;hb=e86e10b87d8e0fe8631558dd61aee4cc77f50bde;hp=9c86d44b4949e24e86abcc043d5c2de885cef7c1;hpb=511c5319f1b50438ed21e5c922c0c9ef0b258cac;p=rust-lightning diff --git a/src/util/chacha20poly1305rfc.rs b/src/util/chacha20poly1305rfc.rs index 9c86d44b..1aeaf61d 100644 --- a/src/util/chacha20poly1305rfc.rs +++ b/src/util/chacha20poly1305rfc.rs @@ -13,12 +13,13 @@ #[cfg(not(feature = "fuzztarget"))] mod real_chachapoly { use crypto::aead::{AeadEncryptor,AeadDecryptor}; - use crypto::chacha20::ChaCha20; 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::byte_utils; #[derive(Clone, Copy)] @@ -104,11 +105,12 @@ mod real_chachapoly { } } #[cfg(not(feature = "fuzztarget"))] -pub use self::real_chachapoly::ChaCha20Poly1305RFC; +pub use self::real_chachapoly::{ChaCha20Poly1305RFC, ChaCha20}; #[cfg(feature = "fuzztarget")] mod fuzzy_chachapoly { use crypto::aead::{AeadEncryptor,AeadDecryptor}; + use crypto::symmetriccipher::SynchronousStreamCipher; #[derive(Clone, Copy)] pub struct ChaCha20Poly1305RFC { @@ -155,6 +157,22 @@ 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; +pub use self::fuzzy_chachapoly::{ChaCha20Poly1305RFC, ChaCha20};