Rust crypto library for Cortex M


I am building a Rust application to run on my dev board which has a Cortex M4. And I want to generate a certificate and validate a signature with it. I looked it up on the web and found Rust based like Ring and rustls, but Ring failed to compile when I set my target to thumbv7em-none-eabi. Then I tried to build my application with openssl crate but it failed cargo check with error[E0463]: can't find crate for std.

Has anyone had any experience with Rust crypto library for Cortex M processor? I am not sure what has been supported on this particular processor.


What algorithms do you need?
Some no std can be found here:

In this project the chacha20poly1305 is used:

I definitely wouldn't expect OpenSSL to work on microcontrollers (in general, in a no_std environment). It being C also complicates things.

The pure-rust crypto implementations under tend to work fine though. There's hashes as well as digital signatures. And lots of other things.

Mainly PKI related stuff. I don't expect Cortex-M4 can work well enough for RSA key, but I want to find Rust base crypto library for EC key at least.

Thanks for the information. I looked into then I added it into my cargo.toml as below:

panic-halt = "0.2.0"
cortex-m-rt = "0.6.12"
rsa = "0.3.0"

But I ran into another compilation error which looks like rsa crate require std package.

C:\Users\yu\nrf-rs\myapp>cargo check
Updating index
Checking regex-syntax v0.6.18
Checking base64 v0.12.3
Checking opaque-debug v0.3.0
Checking smallvec v1.4.0
Checking once_cell v1.4.0
error[E0463]: can't find crate for std
--> C:\Users\leeyuc.cargo\registry\src\\smallvec-1.4.0\
72 | extern crate std;
| ^^^^^^^^^^^^^^^^^ can't find crate
= note: the thumbv7em-none-eabi target may not be installed

Please let me know if you think I did anything wrong here.

Right now RSA no_std support is work in progress. You can play with code from the PR using the following configuration:

git = ""
branch = "nostd"
default-features = false
features = ["alloc"]

But note that you will need to define a global allocator. No-heap support is tracked in this issue.

I think dalek crates support no_std, so check them out as well.

1 Like

at this moment for crypto on embedded devices, I use mbedtls (pure C library.

I also found few rust libs which some of the pure rust, some of it is wrappers but not tested it yet.

This is a list:

sodiumoxide would theoretically be really nice for interoperability with other libsodium things but, i have yet to solve the compiling-on-arm problems in libsodium-sys sodiumoxide#363. If you just need elliptic curve things you might also be interested in dalek-cryptography/ed25519-dalek

Thanks for all the feedback. Since I do need RSA functionality in no_std environment, I will try to build with C base mbedtls library first.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.