mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-05 12:10:51 +02:00
Rust wrapper: restrict RNG generic type parameters to be integers
Fixes F-3350
This commit is contained in:
+16
@@ -22,6 +22,12 @@ dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
||||
|
||||
[[package]]
|
||||
name = "base64ct"
|
||||
version = "1.8.3"
|
||||
@@ -262,6 +268,15 @@ dependencies = [
|
||||
"minimal-lexical",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "password-hash"
|
||||
version = "0.6.1"
|
||||
@@ -478,6 +493,7 @@ dependencies = [
|
||||
"digest",
|
||||
"hybrid-array",
|
||||
"kem",
|
||||
"num-traits",
|
||||
"password-hash",
|
||||
"rand_core 0.10.0",
|
||||
"regex",
|
||||
|
||||
@@ -27,6 +27,7 @@ aead = { version = "0.5", optional = true, default-features = false }
|
||||
cipher = { version = "0.5", optional = true, default-features = false }
|
||||
digest = { version = "0.11", optional = true, default-features = false, features = ["block-api"] }
|
||||
signature = { version = "2.2", optional = true, default-features = false }
|
||||
num-traits = { version = "0.2", default-features = false }
|
||||
zeroize = { version = "1.3", default-features = false, features = ["derive"] }
|
||||
password-hash = { version = "0.6.1", optional = true, default-features = false }
|
||||
kem = { version = "0.3", optional = true, default-features = false }
|
||||
|
||||
@@ -46,6 +46,7 @@ rng.generate_block(&mut buffer).expect("Failed to generate a block");
|
||||
|
||||
use crate::sys;
|
||||
use core::mem::{size_of_val, MaybeUninit};
|
||||
use num_traits::PrimInt;
|
||||
|
||||
/// A cryptographically secure random number generator based on the wolfSSL
|
||||
/// library.
|
||||
@@ -127,7 +128,7 @@ impl RNG {
|
||||
///
|
||||
/// A Result which is Ok(RNG) on success or an Err containing the wolfSSL
|
||||
/// library return code on failure.
|
||||
pub fn new_with_nonce<T>(nonce: &mut [T]) -> Result<Self, i32> {
|
||||
pub fn new_with_nonce<T: PrimInt>(nonce: &mut [T]) -> Result<Self, i32> {
|
||||
RNG::new_with_nonce_ex(nonce, None, None)
|
||||
}
|
||||
|
||||
@@ -146,7 +147,7 @@ impl RNG {
|
||||
///
|
||||
/// A Result which is Ok(RNG) on success or an Err containing the wolfSSL
|
||||
/// library return code on failure.
|
||||
pub fn new_with_nonce_ex<T>(nonce: &mut [T], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
|
||||
pub fn new_with_nonce_ex<T: PrimInt>(nonce: &mut [T], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
|
||||
#[cfg(fips)]
|
||||
{
|
||||
let rc = unsafe {
|
||||
@@ -338,7 +339,7 @@ impl RNG {
|
||||
///
|
||||
/// A `Result` which is `Ok(())` on success or an `Err` with the wolfssl
|
||||
/// library return code on failure.
|
||||
pub fn generate_block<T>(&mut self, buf: &mut [T]) -> Result<(), i32> {
|
||||
pub fn generate_block<T: PrimInt>(&mut self, buf: &mut [T]) -> Result<(), i32> {
|
||||
let ptr = buf.as_mut_ptr() as *mut u8;
|
||||
let size = crate::buffer_len_to_u32(size_of_val(buf))?;
|
||||
let rc = unsafe { sys::wc_RNG_GenerateBlock(&mut self.wc_rng, ptr, size) };
|
||||
|
||||
Reference in New Issue
Block a user