diff options
Diffstat (limited to '')
-rw-r--r-- | third_party/rust/neqo-crypto/src/aead_null.rs | 2 | ||||
-rw-r--r-- | third_party/rust/neqo-crypto/src/agentio.rs | 2 | ||||
-rw-r--r-- | third_party/rust/neqo-crypto/src/constants.rs | 2 | ||||
-rw-r--r-- | third_party/rust/neqo-crypto/src/p11.rs | 26 |
4 files changed, 25 insertions, 7 deletions
diff --git a/third_party/rust/neqo-crypto/src/aead_null.rs b/third_party/rust/neqo-crypto/src/aead_null.rs index 2d5656de73..6fcb72871f 100644 --- a/third_party/rust/neqo-crypto/src/aead_null.rs +++ b/third_party/rust/neqo-crypto/src/aead_null.rs @@ -4,8 +4,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg(feature = "disable-encryption")] - use std::fmt; use crate::{ diff --git a/third_party/rust/neqo-crypto/src/agentio.rs b/third_party/rust/neqo-crypto/src/agentio.rs index 7c57a0ef45..3beede5c12 100644 --- a/third_party/rust/neqo-crypto/src/agentio.rs +++ b/third_party/rust/neqo-crypto/src/agentio.rs @@ -29,7 +29,7 @@ const PR_FAILURE: PrStatus = prio::PRStatus::PR_FAILURE; /// Convert a pinned, boxed object into a void pointer. pub fn as_c_void<T: Unpin>(pin: &mut Pin<Box<T>>) -> *mut c_void { - (Pin::into_inner(pin.as_mut()) as *mut T).cast() + (std::ptr::from_mut::<T>(Pin::into_inner(pin.as_mut()))).cast() } /// A slice of the output. diff --git a/third_party/rust/neqo-crypto/src/constants.rs b/third_party/rust/neqo-crypto/src/constants.rs index 76db972290..daef3d3c56 100644 --- a/third_party/rust/neqo-crypto/src/constants.rs +++ b/third_party/rust/neqo-crypto/src/constants.rs @@ -27,7 +27,7 @@ pub const TLS_EPOCH_APPLICATION_DATA: Epoch = 3_u16; macro_rules! remap_enum { { $t:ident: $s:ty { $( $n:ident = $v:path ),+ $(,)? } } => { pub type $t = $s; - $( pub const $n: $t = $v as $t; )+ + $(#[allow(clippy::cast_possible_truncation)] pub const $n: $t = $v as $t; )+ }; { $t:ident: $s:ty => $e:ident { $( $n:ident = $v:ident ),+ $(,)? } } => { remap_enum!{ $t: $s { $( $n = $e::$v ),+ } } diff --git a/third_party/rust/neqo-crypto/src/p11.rs b/third_party/rust/neqo-crypto/src/p11.rs index 5552882e2e..c235bb869c 100644 --- a/third_party/rust/neqo-crypto/src/p11.rs +++ b/third_party/rust/neqo-crypto/src/p11.rs @@ -13,7 +13,7 @@ use std::{ cell::RefCell, mem, ops::{Deref, DerefMut}, - os::raw::{c_int, c_uint}, + os::raw::c_uint, ptr::null_mut, }; @@ -290,14 +290,31 @@ impl Item { } } +#[cfg(feature = "disable-random")] +thread_local! { + static CURRENT_VALUE: std::cell::Cell<u8> = const { std::cell::Cell::new(0) }; +} + +#[cfg(feature = "disable-random")] +/// Fill a buffer with a predictable sequence of bytes. +pub fn randomize<B: AsMut<[u8]>>(mut buf: B) -> B { + let m_buf = buf.as_mut(); + for v in m_buf.iter_mut() { + *v = CURRENT_VALUE.get(); + CURRENT_VALUE.set(v.wrapping_add(1)); + } + buf +} + /// Fill a buffer with randomness. /// /// # Panics /// /// When `size` is too large or NSS fails. +#[cfg(not(feature = "disable-random"))] pub fn randomize<B: AsMut<[u8]>>(mut buf: B) -> B { let m_buf = buf.as_mut(); - let len = c_int::try_from(m_buf.len()).unwrap(); + let len = std::os::raw::c_int::try_from(m_buf.len()).unwrap(); secstatus_to_res(unsafe { PK11_GenerateRandom(m_buf.as_mut_ptr(), len) }).unwrap(); buf } @@ -359,10 +376,13 @@ mod test { use test_fixture::fixture_init; use super::RandomCache; - use crate::{random, randomize}; + use crate::random; + #[cfg(not(feature = "disable-random"))] #[test] fn randomness() { + use crate::randomize; + fixture_init(); // If any of these ever fail, there is either a bug, or it's time to buy a lottery ticket. assert_ne!(random::<16>(), randomize([0; 16])); |