mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-24 15:02:20 +01:00
Stub out Sha256 calls when fuzzing
This commit is contained in:
parent
d0a3d0f728
commit
ab56b81acd
7 changed files with 44 additions and 5 deletions
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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};
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -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;
|
||||
|
|
37
src/util/sha2.rs
Normal file
37
src/util/sha2.rs
Normal file
|
@ -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;
|
Loading…
Add table
Reference in a new issue