From: Matt Corallo Date: Fri, 14 Dec 2018 20:48:05 +0000 (-0500) Subject: Drop rust-crypto trait usage X-Git-Tag: v0.0.12~253^2~2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=202c0aedcb25b3e5ea2e4d748dd0de0cad5649da;p=rust-lightning Drop rust-crypto trait usage --- diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index ae931538d..e7214427c 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -40,7 +40,6 @@ use util::errors::APIError; use util::errors; use crypto; -use crypto::symmetriccipher::SynchronousStreamCipher; use std::{cmp, ptr, mem}; use std::collections::{HashMap, hash_map, HashSet}; diff --git a/src/ln/peer_channel_encryptor.rs b/src/ln/peer_channel_encryptor.rs index 2c4f5cedf..fbb8c737e 100644 --- a/src/ln/peer_channel_encryptor.rs +++ b/src/ln/peer_channel_encryptor.rs @@ -9,8 +9,6 @@ use secp256k1::key::{PublicKey,SecretKey}; use secp256k1::ecdh::SharedSecret; use secp256k1; -use crypto::aead::{AeadEncryptor, AeadDecryptor}; - use util::chacha20poly1305rfc::ChaCha20Poly1305RFC; use util::{byte_utils,rng}; diff --git a/src/util/chacha20.rs b/src/util/chacha20.rs index 7bab9c1e3..dd90b20f6 100644 --- a/src/util/chacha20.rs +++ b/src/util/chacha20.rs @@ -13,7 +13,6 @@ mod real_chacha { use std::cmp; use util::byte_utils::{slice_to_le32, le32_to_array}; - use crypto::symmetriccipher::SynchronousStreamCipher; #[derive(Clone, Copy, PartialEq, Eq)] #[allow(non_camel_case_types)] @@ -224,10 +223,8 @@ mod real_chacha { self.offset = 0; } - } - impl SynchronousStreamCipher for ChaCha20 { - fn process(&mut self, input: &[u8], output: &mut [u8]) { + pub fn process(&mut self, input: &[u8], output: &mut [u8]) { assert!(input.len() == output.len()); let len = input.len(); let mut i = 0; @@ -258,8 +255,6 @@ pub use self::real_chacha::ChaCha20; #[cfg(feature = "fuzztarget")] mod fuzzy_chacha { - use crypto::symmetriccipher::SynchronousStreamCipher; - pub struct ChaCha20 {} impl ChaCha20 { @@ -268,10 +263,8 @@ mod fuzzy_chacha { assert!(nonce.len() == 8 || nonce.len() == 12); Self {} } - } - impl SynchronousStreamCipher for ChaCha20 { - fn process(&mut self, input: &[u8], output: &mut [u8]) { + pub fn process(&mut self, input: &[u8], output: &mut [u8]) { output.copy_from_slice(input); } } @@ -284,7 +277,6 @@ mod test { use std::iter::repeat; use super::ChaCha20; - use crypto::symmetriccipher::SynchronousStreamCipher; #[test] fn test_chacha20_256_tls_vectors() { diff --git a/src/util/chacha20poly1305rfc.rs b/src/util/chacha20poly1305rfc.rs index 4f8d0b926..ae1b069ac 100644 --- a/src/util/chacha20poly1305rfc.rs +++ b/src/util/chacha20poly1305rfc.rs @@ -15,9 +15,6 @@ mod real_chachapoly { use util::chacha20::ChaCha20; use util::poly1305::Poly1305; - use crypto::aead::{AeadEncryptor,AeadDecryptor}; - use crypto::symmetriccipher::SynchronousStreamCipher; - use crypto::mac::Mac; use crypto::util::fixed_time_eq; use util::byte_utils; @@ -62,10 +59,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 +72,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); @@ -109,8 +102,6 @@ pub use self::real_chachapoly::ChaCha20Poly1305RFC; #[cfg(feature = "fuzztarget")] mod fuzzy_chachapoly { - use crypto::aead::{AeadEncryptor,AeadDecryptor}; - #[derive(Clone, Copy)] pub struct ChaCha20Poly1305RFC { tag: [u8; 16], @@ -132,10 +123,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); @@ -143,10 +132,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); diff --git a/src/util/poly1305.rs b/src/util/poly1305.rs index 5e6241471..541c398ba 100644 --- a/src/util/poly1305.rs +++ b/src/util/poly1305.rs @@ -10,8 +10,6 @@ use std::cmp::min; use util::byte_utils::{slice_to_le32, le32_to_array}; -use crypto::mac::{Mac, MacResult}; - #[derive(Clone, Copy)] pub struct Poly1305 { r : [u32; 5], @@ -93,7 +91,7 @@ impl Poly1305 { self.h[4] = h4; } - fn finish(&mut self) { + pub fn finish(&mut self) { if self.leftover > 0 { self.buffer[self.leftover] = 1; for i in self.leftover+1..16 { @@ -158,10 +156,8 @@ impl Poly1305 { self.h[2] = h2; self.h[3] = h3; } -} -impl Mac for Poly1305 { - fn input(&mut self, data: &[u8]) { + pub fn input(&mut self, data: &[u8]) { assert!(!self.finalized); let mut m = data; @@ -195,19 +191,7 @@ impl Mac for Poly1305 { self.leftover = m.len(); } - fn reset(&mut self) { - self.h = [0u32; 5]; - self.leftover = 0; - self.finalized = false; - } - - fn result(&mut self) -> MacResult { - let mut mac = [0u8; 16]; - self.raw_result(&mut mac); - MacResult::new(&mac[..]) - } - - fn raw_result(&mut self, output: &mut [u8]) { + pub fn raw_result(&mut self, output: &mut [u8]) { assert!(output.len() >= 16); if !self.finalized{ self.finish(); @@ -217,8 +201,6 @@ impl Mac for Poly1305 { output[8..12].copy_from_slice(&le32_to_array(self.h[2])); output[12..16].copy_from_slice(&le32_to_array(self.h[3])); } - - fn output_bytes(&self) -> usize { 16 } } #[cfg(test)] @@ -226,7 +208,6 @@ mod test { use std::iter::repeat; use util::poly1305::Poly1305; - use crypto::mac::Mac; fn poly1305(key: &[u8], msg: &[u8], mac: &mut [u8]) { let mut poly = Poly1305::new(key);