A cryptographic library for embedded devices

Hello hello,

Sorry in advance if I'm posting in the wrong place.

I've been looking into how I could test the portability of my cryptographic library on small platforms. I want to make it more robust and useful for embedded devices but have little experience programming for these. The question is: with what devices should I start and what are good tutorials on porting a library for arduino. What are the top 10 platforms I should support? Or what are the better questions I should ask myself at this stage?

The library is really experimental at the moment, and is called EmbeddedDisco: GitHub - mimoo/disco-c: A tiny C cryptographic library to encrypt sessions, authenticate messages, sign, hash, etc. based only on SHA-3 and Curve25519

It is supposed to be tiny (1000 lines of code) but able to provide session encryption (like TLS) and all of the usual primitives (encryption, authentication, hashing, derivation of keys, generation of random numbers, etc.)

mimoo:
what are good tutorials on porting a library for arduino.

Not a tutorial, but I think this is the most important information:

If you have any questions on that I'll try to answer them.

mimoo:
What are the top 10 platforms I should support?

  • AVR
  • SAMD
  • Teensy
  • ESP8266
  • ESP32
  • STM32
  • SAM

If your library works on those platforms, you'll cover 99.9% of the hardware used by the Arduino community. You could get by leaving off the last two.

Awesome! That is very useful :slight_smile: What about devices I should buy to start testing each of these chips?

Would this be a good start for the top of the list? https://www.amazon.com/Elegoo-EL-CB-001-ATmega328P-ATMEGA16U2-Arduino/dp/B01EWOE0UU/ref=sr_1_3?ie=UTF8&qid=1543077035&sr=8-3&keywords=arduino+uno

Start with an UNO. If it works on that and you didn't use any AVR-specific code then it will work on virtually all Arduinos. The UNO is the platform with the smallest memory to be considered as a proper Arduino.

The 2018 UNO WiFi has some cryptographic hardware. It might be fun to support that but very few people have those Arduinos.

The Teensy 3.x has some dedicated crypto hardware too. It has a true random number generator.

The Arduino DUE is the primary SAMD platform. It is not well-suppoted and many of the cool hardware features are disabled by design. I would not spend a lot of time on that: just get the generic code working, even if it is slow.

I think it's reasonable to only buy one board. The Uno is a reasonable choice, though I prefer the Nano. One thing you might look into before buying hardware is what sort of resources the library will require. The Uno only has 31.5 kB of flash memory and 2 kB of ram. The commonly used Nano clones have 1.5 kB less flash memory than that. While it's very desirable to support these parts, in some cases it's just not possible to optimize code down small enough to fit. During development, this might be even more difficult as your debug code uses memory too and earlier versions of the code might be less well optimized. For this reason, I will often use an Arduino Mega for development work so that I'm not so cramped for resources.

Even if you don't decide to buy the hardware for the other target architectures, you should still check that the code compiles for those boards. It's fairly common to find that code that compiles on one doesn't on another (or generates warnings), but it's usually fairly easy to fix the issues as long as you don't have architecture-specific code.

If you do want to buy boards for some of the other architectures, here are my favorites:

  • SAMD: MKR ZERO
  • Teensy: They're all nice
  • ESP8266: WeMos D1 Mini
  • ESP32: I have a NodeMCU 32S but haven't looked closely at the other options. The Adafruit Feather ESP32 looks like a nice board too.
  • STM32: No preference. You can get boards super cheap on eBay or Aliexpress. Just verify it's supported by one of the popular hardware packages: Arduino_STM32 or stm32duino.
  • SAM: Due

MorganS:
The Arduino DUE is the primary SAMD platform. It is not well-suppoted and many of the cool hardware features are disabled by design. I would not spend a lot of time on that: just get the generic code working, even if it is slow.

Due is SAM, not SAMD. The primary SAMD board has traditionally been the Zero but Arduino seems to be focusing more on the MKR boards now. The MKR ZERO has a nice price. and I like the breadboard-friendly form factor of the MKR boards. The Due does have some nice features but I agree that it's not a high priority since Arduino is not actively working on the hardware package. I still compile for that board in my CI tests.

Alright thanks. Just ordered the UNO. Will start here and report back. Thanks again.