Drop rust-crypto trait usage
authorMatt Corallo <git@bluematt.me>
Fri, 14 Dec 2018 20:48:05 +0000 (15:48 -0500)
committerMatt Corallo <git@bluematt.me>
Thu, 20 Dec 2018 01:02:36 +0000 (20:02 -0500)
src/ln/channelmanager.rs
src/ln/peer_channel_encryptor.rs
src/util/chacha20.rs
src/util/chacha20poly1305rfc.rs
src/util/poly1305.rs

index ae931538de82028cfb5003ed9b33d243374497e6..e7214427cd3448a8b28a895342fa4b8c59ec8317 100644 (file)
@@ -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};
index 2c4f5cedfd68acb5141f2ad683708c01142bdc6e..fbb8c737ec6afa3b40f2d9a80b4324ebaee89327 100644 (file)
@@ -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};
 
index 7bab9c1e386d7d96b5ff4c0416feac0c7a1e2a75..dd90b20f694587f754e1f6e7fe16ecc13db4892d 100644 (file)
@@ -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() {
index 4f8d0b92661115d9c21010531061357468c734b5..ae1b069ac13b658236b6e778f123182bab58b125 100644 (file)
@@ -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);
 
index 5e62414711607cf9fddfb6499b1e5222123622b6..541c398baec8457e4d54e0a5e1548daefd49f5e9 100644 (file)
@@ -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);