Skip to content

Commit 42ac260

Browse files
committed
rand: Clarify sealing of SecureRandom.
1 parent 579f64f commit 42ac260

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

src/ec/suite_b/ecdsa/signing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ impl core::fmt::Debug for NonceRandom<'_> {
300300
}
301301

302302
impl rand::sealed::SecureRandom for NonceRandom<'_> {
303-
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
303+
fn fill_impl(&self, dest: &mut [u8], _: crate::sealed::Arg) -> Result<(), error::Unspecified> {
304304
// Use the same digest algorithm that will be used to digest the
305305
// message. The digest algorithm's output is exactly the right size;
306306
// this is checked below.

src/rand.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ where
3131
{
3232
#[inline(always)]
3333
fn fill(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
34-
self.fill_impl(dest)
34+
self.fill_impl(dest, crate::sealed::Arg)
3535
}
3636
}
3737

@@ -64,7 +64,11 @@ pub(crate) mod sealed {
6464

6565
pub trait SecureRandom: core::fmt::Debug {
6666
/// Fills `dest` with random bytes.
67-
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified>;
67+
fn fill_impl(
68+
&self,
69+
dest: &mut [u8],
70+
_: crate::sealed::Arg,
71+
) -> Result<(), error::Unspecified>;
6872
}
6973

7074
pub trait RandomlyConstructable: Sized {
@@ -159,7 +163,7 @@ impl SystemRandom {
159163
))]
160164
impl sealed::SecureRandom for SystemRandom {
161165
#[inline(always)]
162-
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
166+
fn fill_impl(&self, dest: &mut [u8], _: crate::sealed::Arg) -> Result<(), error::Unspecified> {
163167
getrandom::getrandom(dest).map_err(|_| error::Unspecified)
164168
}
165169
}

src/testutil.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,11 @@ pub mod rand {
478478
}
479479

480480
impl rand::sealed::SecureRandom for FixedByteRandom {
481-
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
481+
fn fill_impl(
482+
&self,
483+
dest: &mut [u8],
484+
_: crate::sealed::Arg,
485+
) -> Result<(), error::Unspecified> {
482486
dest.fill(self.byte);
483487
Ok(())
484488
}
@@ -493,7 +497,11 @@ pub mod rand {
493497
}
494498

495499
impl rand::sealed::SecureRandom for FixedSliceRandom<'_> {
496-
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
500+
fn fill_impl(
501+
&self,
502+
dest: &mut [u8],
503+
_: crate::sealed::Arg,
504+
) -> Result<(), error::Unspecified> {
497505
dest.copy_from_slice(self.bytes);
498506
Ok(())
499507
}
@@ -516,7 +524,11 @@ pub mod rand {
516524
}
517525

518526
impl rand::sealed::SecureRandom for FixedSliceSequenceRandom<'_> {
519-
fn fill_impl(&self, dest: &mut [u8]) -> Result<(), error::Unspecified> {
527+
fn fill_impl(
528+
&self,
529+
dest: &mut [u8],
530+
_: crate::sealed::Arg,
531+
) -> Result<(), error::Unspecified> {
520532
let current = unsafe { *self.current.get() };
521533
let bytes = self.bytes[current];
522534
dest.copy_from_slice(bytes);

0 commit comments

Comments
 (0)