Skip to content

Commit 940ac70

Browse files
authored
Merge pull request #9808 from holtrop-wolfssl/rust-no-std
Rust wrapper: fix no_std support
2 parents 0c19fb1 + 3da3e12 commit 940ac70

18 files changed

Lines changed: 117 additions & 90 deletions

File tree

wrapper/rust/wolfssl-wolfcrypt/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ fn generate_bindings() -> Result<()> {
5555
.header("headers.h")
5656
.clang_arg(format!("-I{}", wolfssl_base_dir()?))
5757
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
58+
.use_core()
5859
.generate()
5960
.map_err(|_| io::Error::other("Failed to generate bindings"))?;
6061

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Encryption Standard (AES) functionality.
2626
#![cfg(aes)]
2727

2828
use crate::sys;
29-
use std::mem::{size_of_val, MaybeUninit};
29+
use core::mem::{size_of_val, MaybeUninit};
3030

3131
#[cfg(aes_wc_block_size)]
3232
pub const AES_BLOCK_SIZE: usize = sys::WC_AES_BLOCK_SIZE as usize;
@@ -88,7 +88,7 @@ impl CBC {
8888
///
8989
/// A Result which is Ok(CBC) on success or an Err containing the wolfSSL
9090
/// library return code on failure.
91-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
91+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
9292
let ws_aes = new_ws_aes(heap, dev_id)?;
9393
let cbc = CBC {ws_aes};
9494
Ok(cbc)
@@ -292,7 +292,7 @@ impl CCM {
292292
///
293293
/// A Result which is Ok(CCM) on success or an Err containing the wolfSSL
294294
/// library return code on failure.
295-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
295+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
296296
let ws_aes = new_ws_aes(heap, dev_id)?;
297297
let ccm = CCM {ws_aes};
298298
Ok(ccm)
@@ -487,7 +487,7 @@ impl CFB {
487487
///
488488
/// A Result which is Ok(CFB) on success or an Err containing the wolfSSL
489489
/// library return code on failure.
490-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
490+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
491491
let ws_aes = new_ws_aes(heap, dev_id)?;
492492
let cfb = CFB {ws_aes};
493493
Ok(cfb)
@@ -794,7 +794,7 @@ impl CTR {
794794
///
795795
/// A Result which is Ok(CTR) on success or an Err containing the wolfSSL
796796
/// library return code on failure.
797-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
797+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
798798
let ws_aes = new_ws_aes(heap, dev_id)?;
799799
let ctr = CTR {ws_aes};
800800
Ok(ctr)
@@ -1075,7 +1075,7 @@ impl ECB {
10751075
///
10761076
/// A Result which is Ok(ECB) on success or an Err containing the wolfSSL
10771077
/// library return code on failure.
1078-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
1078+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
10791079
let ws_aes = new_ws_aes(heap, dev_id)?;
10801080
let ecb = ECB {ws_aes};
10811081
Ok(ecb)
@@ -1276,7 +1276,7 @@ impl GCM {
12761276
///
12771277
/// A Result which is Ok(GCM) on success or an Err containing the wolfSSL
12781278
/// library return code on failure.
1279-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
1279+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
12801280
let ws_aes = new_ws_aes(heap, dev_id)?;
12811281
let gcm = GCM {ws_aes};
12821282
Ok(gcm)
@@ -1499,7 +1499,7 @@ impl GCMStream {
14991499
///
15001500
/// A Result which is Ok(GCMStream) on success or an Err containing the
15011501
/// wolfSSL library return code on failure.
1502-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
1502+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
15031503
let ws_aes = new_ws_aes(heap, dev_id)?;
15041504
let gcmstream = GCMStream {ws_aes};
15051505
Ok(gcmstream)
@@ -1751,7 +1751,7 @@ impl OFB {
17511751
///
17521752
/// A Result which is Ok(OFB) on success or an Err containing the wolfSSL
17531753
/// library return code on failure.
1754-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
1754+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
17551755
let ws_aes = new_ws_aes(heap, dev_id)?;
17561756
let ofb = OFB {ws_aes};
17571757
Ok(ofb)
@@ -1945,7 +1945,7 @@ impl XTS {
19451945
///
19461946
/// A Result which is Ok(XTS) on success or an Err containing the wolfSSL
19471947
/// library return code on failure.
1948-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
1948+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
19491949
let ws_xtsaes = new_ws_xtsaes(heap, dev_id)?;
19501950
let xts = XTS {ws_xtsaes};
19511951
Ok(xts)
@@ -2307,7 +2307,7 @@ impl XTSStream {
23072307
///
23082308
/// A Result which is Ok(XTSStream) on success or an Err containing the
23092309
/// wolfSSL library return code on failure.
2310-
pub fn new_ex(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
2310+
pub fn new_ex(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
23112311
let ws_xtsaes = new_ws_xtsaes(heap, dev_id)?;
23122312
let ws_xtsaesstreamdata: MaybeUninit<sys::XtsAesStreamData> = MaybeUninit::uninit();
23132313
let ws_xtsaesstreamdata = unsafe { ws_xtsaesstreamdata.assume_init() };
@@ -2533,7 +2533,7 @@ impl Drop for XTSStream {
25332533
}
25342534
}
25352535

2536-
fn new_ws_aes(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<sys::Aes, i32> {
2536+
fn new_ws_aes(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<sys::Aes, i32> {
25372537
let heap = match heap {
25382538
Some(heap) => heap,
25392539
None => core::ptr::null_mut(),
@@ -2554,7 +2554,7 @@ fn new_ws_aes(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> R
25542554
}
25552555

25562556
#[cfg(any(aes_xts, aes_xts_stream))]
2557-
fn new_ws_xtsaes(heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<sys::XtsAes, i32> {
2557+
fn new_ws_xtsaes(heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<sys::XtsAes, i32> {
25582558
let heap = match heap {
25592559
Some(heap) => heap,
25602560
None => core::ptr::null_mut(),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ functionality.
2626
#![cfg(any(blake2b, blake2s))]
2727

2828
use crate::sys;
29-
use std::mem::MaybeUninit;
29+
use core::mem::MaybeUninit;
3030

3131
/// Context for BLAKE2b computation.
3232
#[cfg(blake2b)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ ChaCha20-Poly1305 functionality.
2626
#![cfg(chacha20_poly1305)]
2727

2828
use crate::sys;
29-
use std::mem::MaybeUninit;
29+
use core::mem::MaybeUninit;
3030

3131
pub struct ChaCha20Poly1305 {
3232
wc_ccp: sys::ChaChaPoly_Aead,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Message Authentication Code (CMAC) functionality.
2626
#![cfg(cmac)]
2727

2828
use crate::sys;
29-
use std::mem::MaybeUninit;
29+
use core::mem::MaybeUninit;
3030

3131
/// The `CMAC` struct manages the lifecycle of a wolfSSL `Cmac` object.
3232
///
@@ -133,7 +133,7 @@ impl CMAC {
133133
/// ];
134134
/// let mut cmac = CMAC::new_ex(&key, None, None).expect("Error with new_ex()");
135135
/// ```
136-
pub fn new_ex(key: &[u8], heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
136+
pub fn new_ex(key: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
137137
let key_size = key.len() as u32;
138138
let mut ws_cmac: MaybeUninit<sys::Cmac> = MaybeUninit::uninit();
139139
let typ = sys::CmacType_WC_CMAC_AES as i32;
@@ -242,7 +242,7 @@ impl CMAC {
242242
/// }
243243
/// ```
244244
#[cfg(aes)]
245-
pub fn generate_ex(&mut self, key: &[u8], data: &[u8], dout: &mut [u8], heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<(), i32> {
245+
pub fn generate_ex(&mut self, key: &[u8], data: &[u8], dout: &mut [u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<(), i32> {
246246
let key_size = key.len() as u32;
247247
let data_size = data.len() as u32;
248248
let mut dout_size = dout.len() as u32;
@@ -384,7 +384,7 @@ impl CMAC {
384384
/// }
385385
/// ```
386386
#[cfg(aes)]
387-
pub fn verify_ex(&mut self, key: &[u8], data: &[u8], check: &[u8], heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<bool, i32> {
387+
pub fn verify_ex(&mut self, key: &[u8], data: &[u8], check: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<bool, i32> {
388388
let key_size = key.len() as u32;
389389
let data_size = data.len() as u32;
390390
let check_size = check.len() as u32;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ functionality.
2828
#[cfg(random)]
2929
use crate::random::RNG;
3030
use crate::sys;
31-
use std::mem::MaybeUninit;
31+
use core::mem::MaybeUninit;
3232

3333
pub struct Curve25519Key {
3434
wc_key: sys::curve25519_key,

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ wolfSSL `DhKey` object. It ensures proper initialization and deallocation.
3131
use crate::sys;
3232
#[cfg(random)]
3333
use crate::random::RNG;
34-
use std::mem::{MaybeUninit};
34+
use core::mem::{MaybeUninit};
3535

3636
pub struct DH {
3737
wc_dhkey: sys::DhKey,
@@ -218,7 +218,7 @@ impl DH {
218218
/// }
219219
/// ```
220220
#[cfg(all(dh_keygen, random))]
221-
pub fn generate_ex(rng: &mut RNG, modulus_size: i32, heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
221+
pub fn generate_ex(rng: &mut RNG, modulus_size: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
222222
let mut wc_dhkey: MaybeUninit<sys::DhKey> = MaybeUninit::uninit();
223223
let heap = match heap {
224224
Some(heap) => heap,
@@ -345,7 +345,7 @@ impl DH {
345345
/// let mut dh = DH::new_named_ex(DH::FFDHE_2048, None, None).expect("Error with new_named_ex()");
346346
/// }
347347
/// ```
348-
pub fn new_named_ex(name: i32, heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
348+
pub fn new_named_ex(name: i32, heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
349349
let mut wc_dhkey: MaybeUninit<sys::DhKey> = MaybeUninit::uninit();
350350
let heap = match heap {
351351
Some(heap) => heap,
@@ -555,7 +555,7 @@ impl DH {
555555
/// let dh = DH::new_from_pg_ex(&p, &g, None, None).expect("Error with new_from_pg_ex()");
556556
/// }
557557
/// ```
558-
pub fn new_from_pg_ex(p: &[u8], g: &[u8], heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
558+
pub fn new_from_pg_ex(p: &[u8], g: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
559559
let p_size = p.len() as u32;
560560
let g_size = g.len() as u32;
561561
let mut wc_dhkey: MaybeUninit<sys::DhKey> = MaybeUninit::uninit();
@@ -783,7 +783,7 @@ impl DH {
783783
/// let dh = DH::new_from_pgq_ex(&p, &g, &q, None, None).expect("Error with new_from_pgq_ex()");
784784
/// }
785785
/// ```
786-
pub fn new_from_pgq_ex(p: &[u8], g: &[u8], q: &[u8], heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
786+
pub fn new_from_pgq_ex(p: &[u8], g: &[u8], q: &[u8], heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
787787
let p_size = p.len() as u32;
788788
let g_size = g.len() as u32;
789789
let q_size = q.len() as u32;
@@ -1023,7 +1023,7 @@ impl DH {
10231023
/// }
10241024
/// ```
10251025
#[cfg(random)]
1026-
pub fn new_from_pgq_with_check_ex(p: &[u8], g: &[u8], q: &[u8], trusted: i32, rng: &mut RNG, heap: Option<*mut std::os::raw::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
1026+
pub fn new_from_pgq_with_check_ex(p: &[u8], g: &[u8], q: &[u8], trusted: i32, rng: &mut RNG, heap: Option<*mut core::ffi::c_void>, dev_id: Option<i32>) -> Result<Self, i32> {
10271027
let p_size = p.len() as u32;
10281028
let g_size = g.len() as u32;
10291029
let q_size = q.len() as u32;

0 commit comments

Comments
 (0)