Skip to content

Commit 110408a

Browse files
Rust wrapper: restrict RNG generic type parameters to be integers
Fixes F-3350
1 parent 09c7fac commit 110408a

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wrapper/rust/wolfssl-wolfcrypt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ aead = { version = "0.5", optional = true, default-features = false }
2727
cipher = { version = "0.5", optional = true, default-features = false }
2828
digest = { version = "0.11", optional = true, default-features = false, features = ["block-api"] }
2929
signature = { version = "2.2", optional = true, default-features = false }
30+
num-traits = { version = "0.2", default-features = false }
3031
zeroize = { version = "1.3", default-features = false, features = ["derive"] }
3132
password-hash = { version = "0.6.1", optional = true, default-features = false }
3233
kem = { version = "0.3", optional = true, default-features = false }

wrapper/rust/wolfssl-wolfcrypt/src/random.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ rng.generate_block(&mut buffer).expect("Failed to generate a block");
4646

4747
use crate::sys;
4848
use core::mem::{size_of_val, MaybeUninit};
49+
use num_traits::PrimInt;
4950

5051
/// A cryptographically secure random number generator based on the wolfSSL
5152
/// library.
@@ -127,7 +128,7 @@ impl RNG {
127128
///
128129
/// A Result which is Ok(RNG) on success or an Err containing the wolfSSL
129130
/// library return code on failure.
130-
pub fn new_with_nonce<T>(nonce: &mut [T]) -> Result<Self, i32> {
131+
pub fn new_with_nonce<T: PrimInt>(nonce: &mut [T]) -> Result<Self, i32> {
131132
RNG::new_with_nonce_ex(nonce, None, None)
132133
}
133134

@@ -146,7 +147,7 @@ impl RNG {
146147
///
147148
/// A Result which is Ok(RNG) on success or an Err containing the wolfSSL
148149
/// library return code on failure.
149-
pub fn new_with_nonce_ex<T>(nonce: &mut [T], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
150+
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> {
150151
#[cfg(fips)]
151152
{
152153
let rc = unsafe {
@@ -338,7 +339,7 @@ impl RNG {
338339
///
339340
/// A `Result` which is `Ok(())` on success or an `Err` with the wolfssl
340341
/// library return code on failure.
341-
pub fn generate_block<T>(&mut self, buf: &mut [T]) -> Result<(), i32> {
342+
pub fn generate_block<T: PrimInt>(&mut self, buf: &mut [T]) -> Result<(), i32> {
342343
let ptr = buf.as_mut_ptr() as *mut u8;
343344
let size = crate::buffer_len_to_u32(size_of_val(buf))?;
344345
let rc = unsafe { sys::wc_RNG_GenerateBlock(&mut self.wc_rng, ptr, size) };

0 commit comments

Comments
 (0)