Skip to content

Commit ab56b81

Browse files
committed
Stub out Sha256 calls when fuzzing
1 parent d0a3d0f commit ab56b81

File tree

7 files changed

+44
-5
lines changed

7 files changed

+44
-5
lines changed

src/ln/chan_utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use secp256k1::Secp256k1;
77
use secp256k1;
88

99
use crypto::digest::Digest;
10-
use crypto::sha2::Sha256;
1110
use crypto::ripemd160::Ripemd160;
1211

12+
use util::sha2::Sha256;
13+
1314
// Various functions for key derivation and transaction creation for use within channels. Primarily
1415
// used in Channel and ChannelMonitor.
1516

src/ln/channel.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use secp256k1;
1313

1414
use crypto::digest::Digest;
1515
use crypto::hkdf::{hkdf_extract,hkdf_expand};
16-
use crypto::sha2::Sha256;
1716

1817
use ln::msgs;
1918
use ln::msgs::{HandleError, MsgEncodable};
@@ -23,6 +22,7 @@ use ln::chan_utils::{TxCreationKeys,HTLCOutputInCommitment};
2322
use ln::chan_utils;
2423
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
2524
use util::{transaction_utils,rng};
25+
use util::sha2::Sha256;
2626

2727
use std::default::Default;
2828
use std::cmp;

src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ use ln::router::Route;
1818
use ln::msgs;
1919
use ln::msgs::{HandleError,ChannelMessageHandler,MsgEncodable,MsgDecodable};
2020
use util::{byte_utils, events, internal_traits, rng};
21+
use util::sha2::Sha256;
2122

2223
use crypto::mac::{Mac,MacResult};
2324
use crypto::hmac::Hmac;
2425
use crypto::digest::Digest;
25-
use crypto::sha2::Sha256;
2626
use crypto::symmetriccipher::SynchronousStreamCipher;
2727
use crypto::chacha20::ChaCha20;
2828

src/ln/channelmonitor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use bitcoin::blockdata::script::Script;
44
use bitcoin::util::hash::Sha256dHash;
55
use bitcoin::util::bip143;
66

7-
use crypto::sha2::Sha256;
87
use crypto::digest::Digest;
98

109
use secp256k1::{Secp256k1,Message,Signature};
@@ -14,6 +13,7 @@ use ln::msgs::HandleError;
1413
use ln::chan_utils;
1514
use ln::chan_utils::HTLCOutputInCommitment;
1615
use chain::chaininterface::{ChainListener, ChainWatchInterface, BroadcasterInterface};
16+
use util::sha2::Sha256;
1717

1818
use std::collections::HashMap;
1919
use std::sync::{Arc,Mutex};

src/ln/peer_channel_encryptor.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ use secp256k1::ecdh::SharedSecret;
77

88
use crypto::digest::Digest;
99
use crypto::hkdf::{hkdf_extract,hkdf_expand};
10-
use crypto::sha2::Sha256;
1110

1211
use crypto::aead::{AeadEncryptor, AeadDecryptor};
1312

1413
use util::chacha20poly1305rfc::ChaCha20Poly1305RFC;
1514
use util::{byte_utils,rng};
15+
use util::sha2::Sha256;
1616

1717
// Sha256("Noise_XK_secp256k1_ChaChaPoly_SHA256")
1818
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];

src/util/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub(crate) mod byte_utils;
55
pub(crate) mod chacha20poly1305rfc;
66
pub(crate) mod internal_traits;
77
pub(crate) mod rng;
8+
pub(crate) mod sha2;
89

910
#[cfg(test)]
1011
pub(crate) mod test_utils;

src/util/sha2.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#[cfg(not(feature = "fuzztarget"))]
2+
pub use crypto::sha2::Sha256;
3+
4+
#[cfg(feature = "fuzztarget")]
5+
mod fuzzy_sha {
6+
use crypto::digest::Digest;
7+
use crypto::sha2;
8+
9+
#[derive(Clone, Copy)]
10+
pub struct Sha256 {
11+
state: sha2::Sha256,
12+
}
13+
14+
impl Sha256 {
15+
pub fn new() -> Sha256 {
16+
Sha256 {
17+
state: sha2::Sha256::new(),
18+
}
19+
}
20+
}
21+
22+
impl Digest for Sha256 {
23+
fn result(&mut self, data: &mut [u8]) {
24+
self.state.result(data);
25+
for i in 1..32 {
26+
data[i] = 0;
27+
}
28+
}
29+
30+
fn input(&mut self, data: &[u8]) { self.state.input(data); }
31+
fn reset(&mut self) { self.state.reset(); }
32+
fn output_bits(&self) -> usize { self.state.output_bits() }
33+
fn block_size(&self) -> usize { self.state.block_size() }
34+
}
35+
}
36+
#[cfg(feature = "fuzztarget")]
37+
pub use self::fuzzy_sha::Sha256;

0 commit comments

Comments
 (0)