Stub out Sha256 calls when fuzzing
authorMatt Corallo <git@bluematt.me>
Tue, 20 Mar 2018 00:34:27 +0000 (20:34 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Mar 2018 17:16:24 +0000 (13:16 -0400)
src/ln/chan_utils.rs
src/ln/channel.rs
src/ln/channelmanager.rs
src/ln/channelmonitor.rs
src/ln/peer_channel_encryptor.rs
src/util/mod.rs
src/util/sha2.rs [new file with mode: 0644]

index dd5515c88046ac18b0686e7a810d5cfdeed65c3e..eb85c0e1f3e1a985d39be9161c3d9e670ed50a4e 100644 (file)
@@ -7,9 +7,10 @@ use secp256k1::Secp256k1;
 use secp256k1;
 
 use crypto::digest::Digest;
-use crypto::sha2::Sha256;
 use crypto::ripemd160::Ripemd160;
 
+use util::sha2::Sha256;
+
 // Various functions for key derivation and transaction creation for use within channels. Primarily
 // used in Channel and ChannelMonitor.
 
index 3c32cd39b5d289c6967105a1ce2f0b1e7980352b..6c6dacc84c3821c2285b0156a62498dc068b6a49 100644 (file)
@@ -13,7 +13,6 @@ use secp256k1;
 
 use crypto::digest::Digest;
 use crypto::hkdf::{hkdf_extract,hkdf_expand};
-use crypto::sha2::Sha256;
 
 use ln::msgs;
 use ln::msgs::{HandleError, MsgEncodable};
@@ -23,6 +22,7 @@ use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment};
 use ln::chan_utils;
 use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
 use util::{transaction_utils,rng};
+use util::sha2::Sha256;
 
 use std::default::Default;
 use std::cmp;
index b492f3b3839823815f33a9aa1f31c6cccf491ac2..3d70b1d379a4391461b3c5a756e126716d8d701d 100644 (file)
@@ -18,11 +18,11 @@ use ln::router::Route;
 use ln::msgs;
 use ln::msgs::{HandleError,ChannelMessageHandler,MsgEncodable,MsgDecodable};
 use util::{byte_utils, events, internal_traits, rng};
+use util::sha2::Sha256;
 
 use crypto::mac::{Mac,MacResult};
 use crypto::hmac::Hmac;
 use crypto::digest::Digest;
-use crypto::sha2::Sha256;
 use crypto::symmetriccipher::SynchronousStreamCipher;
 use crypto::chacha20::ChaCha20;
 
index d5529af9c99e579d7f169446cf50f4022b151c70..5ac9a6b0ab01cd93eb276b7a68ff29e2b7763298 100644 (file)
@@ -4,7 +4,6 @@ use bitcoin::blockdata::script::Script;
 use bitcoin::util::hash::Sha256dHash;
 use bitcoin::util::bip143;
 
-use crypto::sha2::Sha256;
 use crypto::digest::Digest;
 
 use secp256k1::{Secp256k1,Message,Signature};
@@ -14,6 +13,7 @@ use ln::msgs::HandleError;
 use ln::chan_utils;
 use ln::chan_utils::HTLCOutputInCommitment;
 use chain::chaininterface::{ChainListener, ChainWatchInterface, BroadcasterInterface};
+use util::sha2::Sha256;
 
 use std::collections::HashMap;
 use std::sync::{Arc,Mutex};
index a20e77a17f3a7989053de518236245a20df629fd..67b0a14cb168910bc97e472dce26ba2c95e4645f 100644 (file)
@@ -7,12 +7,12 @@ use secp256k1::ecdh::SharedSecret;
 
 use crypto::digest::Digest;
 use crypto::hkdf::{hkdf_extract,hkdf_expand};
-use crypto::sha2::Sha256;
 
 use crypto::aead::{AeadEncryptor, AeadDecryptor};
 
 use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
 use util::{byte_utils,rng};
+use util::sha2::Sha256;
 
 // Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")
 const NOISE_CK: [u8; 32] = [0x26, 0x40, 0xf5, 0x2e, 0xeb, 0xcd, 0x9e, 0x88, 0x29, 0x58, 0x95, 0x1c, 0x79, 0x42, 0x50, 0xee, 0xdb, 0x28, 0x00, 0x2c, 0x05, 0xd7, 0xdc, 0x2e, 0xa0, 0xf1, 0x95, 0x40, 0x60, 0x42, 0xca, 0xf1];
index 31f4f698ecdc4c5b7ce75953643a929166b4160a..b7578bce407caca84ef77d675edcb4ac8135208e 100644 (file)
@@ -5,6 +5,7 @@ pub(crate) mod byte_utils;
 pub(crate) mod chacha20poly1305rfc;
 pub(crate) mod internal_traits;
 pub(crate) mod rng;
+pub(crate) mod sha2;
 
 #[cfg(test)]
 pub(crate) mod test_utils;
diff --git a/src/util/sha2.rs b/src/util/sha2.rs
new file mode 100644 (file)
index 0000000..31616f5
--- /dev/null
@@ -0,0 +1,37 @@
+#[cfg(not(feature = "fuzztarget"))]
+pub use crypto::sha2::Sha256;
+
+#[cfg(feature = "fuzztarget")]
+mod fuzzy_sha {
+       use crypto::digest::Digest;
+       use crypto::sha2;
+
+       #[derive(Clone, Copy)]
+       pub struct Sha256 {
+               state: sha2::Sha256,
+       }
+
+       impl Sha256 {
+               pub fn new() -> Sha256 {
+                       Sha256 {
+                               state: sha2::Sha256::new(),
+                       }
+               }
+       }
+
+       impl Digest for Sha256 {
+               fn result(&mut self, data: &mut [u8]) {
+                       self.state.result(data);
+                       for i in 1..32 {
+                               data[i] = 0;
+                       }
+               }
+
+               fn input(&mut self, data: &[u8]) { self.state.input(data); }
+               fn reset(&mut self) { self.state.reset(); }
+               fn output_bits(&self) -> usize { self.state.output_bits() }
+               fn block_size(&self) -> usize { self.state.block_size() }
+       }
+}
+#[cfg(feature = "fuzztarget")]
+pub use self::fuzzy_sha::Sha256;