-
Notifications
You must be signed in to change notification settings - Fork 4
Remove explicit rand
dependency
#151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -234,10 +234,10 @@ impl fmt::Display for Error { | |
"Packet size exceeds maximum 4MiB size for automatic allocation." | ||
), | ||
Error::NoGarbageTerminator => { | ||
write!(f, "More than 4095 bytes of garbage recieved in the handshake before a terminator was sent.") | ||
write!(f, "More than 4095 bytes of garbage received in the handshake before a terminator was sent.") | ||
} | ||
Error::SecretGeneration(e) => write!(f, "Cannot generate secrets: {e:?}."), | ||
Error::Decryption(e) => write!(f, "Decrytion error: {e:?}."), | ||
Error::Decryption(e) => write!(f, "Decryption error: {e:?}."), | ||
Error::V1Protocol => write!(f, "The remote peer is communicating on the V1 protocol."), | ||
Error::TooMuchGarbage => write!( | ||
f, | ||
|
@@ -376,7 +376,7 @@ impl SessionKeyMaterial { | |
hk.expand(garbage_info, &mut garbage)?; | ||
let initiator_garbage_terminator: [u8; 16] = garbage[..16] | ||
.try_into() | ||
.expect("first 16 btyes of expanded garbage"); | ||
.expect("first 16 bytes of expanded garbage"); | ||
let responder_garbage_terminator: [u8; 16] = garbage[16..] | ||
.try_into() | ||
.expect("last 16 bytes of expanded garbage"); | ||
|
@@ -783,15 +783,41 @@ impl CipherSession { | |
} | ||
} | ||
|
||
/// Fill a slice with random bytes. This trait _should_ be cryptographically secure; however, a | ||
/// psuedo-random number generator may be sufficient depending on your security model. | ||
pub trait FillBytes { | ||
/// Fill a 32 byte slice with random data. | ||
fn fill_bytes(&mut self, dest: &mut [u8; 32]); | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
macro_rules! impl_fill_bytes { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
($rng:ident) => { | ||
impl FillBytes for $rng { | ||
fn fill_bytes(&mut self, dest: &mut [u8; 32]) { | ||
use bitcoin::secp256k1::rand::RngCore; | ||
RngCore::fill_bytes(self, dest); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
#[cfg(feature = "std")] | ||
use bitcoin::secp256k1::rand::rngs::{StdRng, ThreadRng}; | ||
#[cfg(feature = "std")] | ||
impl_fill_bytes!(StdRng); | ||
#[cfg(feature = "std")] | ||
impl_fill_bytes!(ThreadRng); | ||
|
||
#[cfg(all(test, feature = "std"))] | ||
mod tests { | ||
|
||
use super::*; | ||
use bitcoin::secp256k1::ellswift::{ElligatorSwift, ElligatorSwiftParty}; | ||
use bitcoin::secp256k1::rand::Rng; | ||
use bitcoin::secp256k1::SecretKey; | ||
use core::str::FromStr; | ||
use hex::prelude::*; | ||
use rand::Rng; | ||
use std::vec; | ||
use std::vec::Vec; | ||
|
||
|
@@ -972,7 +998,7 @@ mod tests { | |
|
||
#[test] | ||
fn test_fuzz_packets() { | ||
let mut rng = rand::thread_rng(); | ||
let mut rng = bitcoin::secp256k1::rand::thread_rng(); | ||
let alice = | ||
SecretKey::from_str("61062ea5071d800bbfd59e2e8b53d47d194b095ae5a4df04936b49772ef0d4d7") | ||
.unwrap(); | ||
|
@@ -1039,7 +1065,7 @@ mod tests { | |
|
||
#[test] | ||
fn test_additional_authenticated_data() { | ||
let mut rng = rand::thread_rng(); | ||
let mut rng = bitcoin::secp256k1::rand::thread_rng(); | ||
let alice = | ||
SecretKey::from_str("61062ea5071d800bbfd59e2e8b53d47d194b095ae5a4df04936b49772ef0d4d7") | ||
.unwrap(); | ||
|
@@ -1088,7 +1114,7 @@ mod tests { | |
|
||
#[test] | ||
fn test_vector_1() { | ||
let mut rng = rand::thread_rng(); | ||
let mut rng = bitcoin::secp256k1::rand::thread_rng(); | ||
let alice = | ||
SecretKey::from_str("61062ea5071d800bbfd59e2e8b53d47d194b095ae5a4df04936b49772ef0d4d7") | ||
.unwrap(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.