Embedded and IoT

Can a microcontroller run end-to-end encrypted mesh messaging?

Yes, within limits. The building blocks of end-to-end encryption, such as elliptic-curve key agreement, signatures and authenticated encryption, can run on microcontrollers. The device also needs a real entropy source, constant-time code, storage that keeps key state safe through power loss, and enough memory and energy for the protocol around the cryptography. Group protocols such as MLS are heavier, so one approach is to let a phone or other capable device manage the group while the microcontroller takes part as a member.

TL;DR

A microcontroller can run end-to-end encrypted messaging given real entropy, constant-time code, careful storage, trusted time at pairing and a clear choice of group manager. The primitives are usually the easy part; protocol state grows with peers and must survive power cuts. In offline-protocol-leaf, a phone or Linux host runs the MLS group and the microcontroller joins as a member.

Learning objectives

After reading this article you will be able to:

  • List the parts of an end-to-end encryption stack a microcontroller must fit
  • Explain why entropy, constant-time code and power-safe key storage matter on devices
  • Compare how Meshtastic and Offline Protocol divide encryption work between devices

Microcontroller requirements for end-to-end encryption

End-to-end encryption on a microcontroller is a whole stack, and all of it has to fit in a small device. A microcontroller runs firmware directly, often with no operating system, a small amount of RAM and flash, and a radio that shares both with everything else. The stack covers:

  • Primitives. Key agreement (such as X25519), signatures (such as Ed25519) and authenticated encryption (such as AES-GCM or ChaCha20-Poly1305).
  • Protocol state. Keys for each conversation or group, counters, and the state that lets keys change over time.
  • The network around it. Framing, routing, retries and the radio driver.

The primitives are usually the easy part. The protocol state grows with the number of peers and groups, and it has to be written to storage as well as held in RAM. Memory figures depend on the part, the library and the protocol, so measure on the device you will ship rather than trusting a general number.

For parts where standard algorithms are too slow or too large, NIST ran a lightweight cryptography process for constrained environments. It selected the Ascon family in 2023 and published SP 800-232, covering authenticated encryption, hashing and extendable-output functions, on August 13, 2025.

Randomness and entropy on microcontrollers

Every key a device generates is only as unpredictable as its random numbers. RFC 4086 warns that an attacker may find it easier to reproduce the environment that produced a secret than to search for the secret directly. A microcontroller that seeds its generator from a clock, a serial number or a fixed value is exposed to exactly that.

Use the part’s hardware random number generator, and check how its vendor says it must be configured. NIST SP 800-90B sets out design principles and validation tests for entropy sources, which is useful when choosing or qualifying one.

Timing, power and physical access risks

A device whose running time depends on secret data can leak that data. BearSSL’s documentation traces timing attacks back to Paul Kocher’s 1996 attack on RSA implementations and notes that many have since been demonstrated in lab conditions against symmetric and asymmetric systems. An embedded device can end up in an attacker’s hands, which makes measurement easier, so use libraries written to run in constant time.

Physical access also means keys can be read out of flash. Meshtastic’s documentation, for example, advises against configuring private channels on unattended nodes because it is easy to gain physical access and extract the channel key.

Energy is the other budget. A protocol that sends extra messages to change keys costs airtime and battery, and a device that sleeps for long periods misses group changes and must catch up when it wakes.

Key storage and trusted time

Key state changes as messages are sent and received. If power is cut halfway through saving it, the device can come back with an older state and reuse a nonce. RFC 9420 adds a random reuse_guard value to each encrypted MLS message to avoid nonce reuse in exactly that case of state loss or corruption. Make writes atomic and test what happens when power drops at every step.

Many protocols also check time. In MLS, a key package carries a lifetime with not_before and not_after values, and RFC 9420 requires a client to check that the current time is within that range in some cases. A device with no real-time clock needs to be given the time from somewhere it trusts.

Meshtastic and Offline Protocol encryption split

Projects make different trade-offs about which device does the encryption work. Meshtastic’s documentation (the version 2.8 docs) describes AES256-CTR encryption of packet payloads with a key per channel, packet headers sent unencrypted so that nodes can relay packets they cannot decrypt, and, since firmware 2.5, public key encryption and signatures for direct messages. The same page lists perfect forward secrecy as missing and says channel messages are not checked for integrity.

Another approach keeps the heavy group operations off the microcontroller. In Offline Protocol, offline-protocol-leaf is a Rust firmware component that builds without the standard library and takes part in MLS as a member that never issues commits. A full peer, such as a phone or a Linux host, creates the group and performs membership changes. Two leaves cannot set up a session with each other, so each one pairs with a full peer over a radio path the firmware supplies. In version 0.33.0 its CI compiles it for Cortex-M0, the RISC-V ESP32 chips and WASI as well as Cortex-M33; for those newer targets, compiling is all the gate shows so far.

The answer to the question is yes, with conditions: a source of real entropy, constant-time code, careful storage, a trusted time at pairing, and a clear decision about which device manages the group. For the group protocol itself, see using MLS for group messaging on mobile, and for the ways encrypted messaging fails in practice, see what can go wrong with mesh messaging encryption. If the device needs to reach a phone directly, sending data from an ESP32 to a phone covers the links.

Frequently asked questions

Is lightweight cryptography required on a microcontroller?

Not necessarily. NIST's lightweight cryptography work, which produced the Ascon standard SP 800-232, targets constrained environments where the performance of its existing standards is not acceptable. If standard algorithms such as AES, X25519 and Ed25519 fit your part's budget, they remain an option.

Can a microcontroller take part in MLS group messaging?

Yes, as a member. Group protocols such as MLS are heavier, so one approach is for a full peer such as a phone or Linux host to create the group and perform membership changes, while the microcontroller joins as a member that never issues commits.

Why should a microcontroller use a hardware random number generator for keys?

Every key a device generates is only as unpredictable as its random numbers. A generator seeded from a clock, a serial number or a fixed value lets an attacker reproduce the environment that produced a secret, which RFC 4086 warns may be easier than searching for the secret directly.

What happens if a device loses power while saving its encryption state?

It can come back with an older state and reuse a nonce. RFC 9420 adds a random reuse_guard value to each encrypted MLS message for this case, and firmware should make writes atomic and test power loss at every step.

Does Meshtastic have perfect forward secrecy?

No. Meshtastic's documentation (the version 2.8 docs) lists perfect forward secrecy as missing and says channel messages are not checked for integrity.

Which targets does offline-protocol-leaf compile for?

In version 0.33.0 its CI compiles it for Cortex-M33, Cortex-M0, the RISC-V ESP32 chips and WASI. For the targets other than Cortex-M33, compiling is all the gate shows so far.

Sources

Build it with Offline Protocol

The Offline Protocol embedded docs describe `offline-protocol-leaf`, a Rust component for constrained devices that joins MLS sessions set up by a full peer such as a phone. They list what the firmware must supply, from radio I/O and entropy to durable storage and authorisation.

Read the Rust and constrained devices docs