Skip to content

Commit 9d72337

Browse files
authored
Merge pull request #9273 from holtrop/rust-wc-rsa
Rust wrapper: add wolfssl::wolfcrypt::rsa module
2 parents 1d67e55 + 4fba5f8 commit 9d72337

9 files changed

Lines changed: 1273 additions & 6 deletions

File tree

doc/dox_comments/header_files/rsa.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,7 @@ int wc_RsaDirect(const byte* in, word32 inLen, byte* out, word32* outSz,
185185
to out in outLen.
186186
187187
\return Success Upon successfully encrypting the input message, returns
188-
0 for success and less than zero for failure. Also returns the number
189-
bytes written to out by storing the value in outLen
188+
the number of bytes written on success and less than zero for failure.
190189
\return BAD_FUNC_ARG Returned if any of the input parameters are invalid
191190
\return RSA_BUFFER_E Returned if the output buffer is too small to store
192191
the ciphertext
@@ -1514,7 +1513,7 @@ int wc_RsaKeyToPublicDer_ex(RsaKey* key, byte* output, word32 inLen,
15141513
\param e exponent parameter to use for generating the key. A secure
15151514
choice is 65537
15161515
\param rng pointer to an RNG structure to use for random number generation
1517-
while making the ke
1516+
while making the key
15181517
15191518
_Example_
15201519
\code

wrapper/rust/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ Run tests with:
1818
| --- | --- |
1919
| `/wrapper/rust` | Top level container for all Rust wrapper functionality. |
2020
| `/wrapper/rust/wolfssl` | Top level for the `wolfssl` library crate. This crate contains high-level Rust sources that use the bindings from the `wolfssl-sys` crate. |
21+
| `/wrapper/rust/wolfssl/src` | Source directory for `wolfssl` crate top-level modules. |
22+
| `/wrapper/rust/wolfssl/src/wolfcrypt` | Source directory for submodules of `wolfssl::wolfcrypt` module. |
2123
| `/wrapper/rust/wolfssl-sys` | Top level for the `wolfssl-sys` library crate. This crate contains only automatically generated bindings to the `wolfssl` C library. |

wrapper/rust/include.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@ EXTRA_DIST += wrapper/rust/wolfssl/src/lib.rs
1818
EXTRA_DIST += wrapper/rust/wolfssl/src/wolfcrypt.rs
1919
EXTRA_DIST += wrapper/rust/wolfssl/src/wolfcrypt/aes.rs
2020
EXTRA_DIST += wrapper/rust/wolfssl/src/wolfcrypt/random.rs
21+
EXTRA_DIST += wrapper/rust/wolfssl/src/wolfcrypt/rsa.rs
2122
EXTRA_DIST += wrapper/rust/wolfssl/tests/test_aes.rs
2223
EXTRA_DIST += wrapper/rust/wolfssl/tests/test_random.rs
24+
EXTRA_DIST += wrapper/rust/wolfssl/tests/test_rsa.rs

wrapper/rust/wolfssl/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1+
/*
2+
* Copyright (C) 2025 wolfSSL Inc.
3+
*
4+
* This file is part of wolfSSL.
5+
*
6+
* wolfSSL is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfSSL is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
19+
*/
20+
121
pub mod wolfcrypt;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,23 @@
1+
/*
2+
* Copyright (C) 2025 wolfSSL Inc.
3+
*
4+
* This file is part of wolfSSL.
5+
*
6+
* wolfSSL is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfSSL is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
19+
*/
20+
121
pub mod aes;
222
pub mod random;
23+
pub mod rsa;

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
/*
2+
* Copyright (C) 2025 wolfSSL Inc.
3+
*
4+
* This file is part of wolfSSL.
5+
*
6+
* wolfSSL is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfSSL is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
19+
*/
20+
121
/*!
2-
This crate provides a Rust wrapper for the wolfCrypt library's Advanced
22+
This module provides a Rust wrapper for the wolfCrypt library's Advanced
323
Encryption Standard (AES) functionality.
424
525
It leverages the `wolfssl-sys` crate for low-level FFI bindings, encapsulating

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,25 @@
1+
/*
2+
* Copyright (C) 2025 wolfSSL Inc.
3+
*
4+
* This file is part of wolfSSL.
5+
*
6+
* wolfSSL is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation; either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* wolfSSL is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program; if not, write to the Free Software
18+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
19+
*/
20+
121
/*!
2-
This crate provides a Rust wrapper for the wolfCrypt library's random number
22+
This module provides a Rust wrapper for the wolfCrypt library's random number
323
generator (RNG).
424
525
It leverages the `wolfssl-sys` crate for low-level FFI bindings, encapsulating
@@ -38,7 +58,7 @@ use std::mem::{size_of, MaybeUninit};
3858
/// ensures that the underlying wolfSSL RNG context is correctly freed when the
3959
/// `RNG` struct goes out of scope, preventing memory leaks.
4060
pub struct RNG {
41-
wc_rng: ws::WC_RNG,
61+
pub(crate) wc_rng: ws::WC_RNG,
4262
}
4363

4464
impl RNG {

0 commit comments

Comments
 (0)